|
@@ -174,7 +174,6 @@ class ProductService extends Service
|
|
|
$model->unit = $data['unit'] ?? 0;
|
|
|
$model->bar_code = $data['bar_code'] ?? '';
|
|
|
$model->cost = $data['cost'] ?? 0;
|
|
|
- $model->depart_price = $data['depart_price'] ?? 0;
|
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
|
$model->mark = $data['mark'] ?? '';
|
|
|
$model->state = $data['state'] ?? 0;
|
|
@@ -264,7 +263,7 @@ class ProductService extends Service
|
|
|
$insert[] = [
|
|
|
'product_id' => $model->id,
|
|
|
'basic_type_id' => $value['basic_type_id'],
|
|
|
- 'grade' => $value['grade'],
|
|
|
+ 'price' => $value['price'],
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
@@ -301,7 +300,6 @@ class ProductService extends Service
|
|
|
$model->unit = $data['unit'] ?? 0;
|
|
|
$model->bar_code = $data['bar_code'] ?? '';
|
|
|
$model->cost = $data['cost'] ?? 0;
|
|
|
- $model->depart_price = $data['depart_price'] ?? 0;
|
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
|
$model->mark = $data['mark'] ?? '';
|
|
|
$model->state = $data['state'] ?? 0;
|
|
@@ -379,7 +377,7 @@ class ProductService extends Service
|
|
|
$insert[] = [
|
|
|
'product_id' => $model->id,
|
|
|
'basic_type_id' => $value['basic_type_id'],
|
|
|
- 'grade' => $value['grade'],
|
|
|
+ 'price' => $value['price'],
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
@@ -442,7 +440,6 @@ class ProductService extends Service
|
|
|
*/
|
|
|
public function productDetail($data,$user){
|
|
|
if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
-
|
|
|
$customer = Product::where('del_time',0)
|
|
|
->where('id',$data['id'])
|
|
|
->first();
|
|
@@ -459,17 +456,24 @@ class ProductService extends Service
|
|
|
|
|
|
$detail = ProductPriceDetail::where('del_time',0)
|
|
|
->where('product_id',$data['id'])
|
|
|
- ->select('product_id','basic_type_id','grade')
|
|
|
+ ->select('product_id','basic_type_id','price')
|
|
|
->get()->toArray();
|
|
|
$title_map = BasicType::whereIn('id',array_column($detail,'basic_type_id'))
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
+ //是否总公司
|
|
|
+ $is_main = EmployeeService::isMain($user['id']);
|
|
|
$customer['product_price'] = [];
|
|
|
+ //展示金额
|
|
|
foreach ($detail as $value){
|
|
|
+ if(! $is_main){
|
|
|
+ $top_depart = $user['depart_top'][0] ?? [];
|
|
|
+ if($top_depart['basic_type_id'] != $value['basic_type_id']) continue;
|
|
|
+ }
|
|
|
$customer['product_price'][] = [
|
|
|
'basic_type_id' => $value['basic_type_id'],
|
|
|
'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
|
|
|
- 'grade' => $value['grade'],
|
|
|
+ 'price' => $value['price'],
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -534,7 +538,7 @@ class ProductService extends Service
|
|
|
public function productList($data,$user){
|
|
|
$model = new Product(['userData' => $user]);
|
|
|
$model = $model->where('del_time',0)
|
|
|
- ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','depart_price','state','crt_id','crt_time','mark','depart_id','top_depart_id')
|
|
|
+ ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id')
|
|
|
->orderby('id', 'desc');
|
|
|
|
|
|
//getALL传入后无视设置范围
|
|
@@ -553,7 +557,7 @@ class ProductService extends Service
|
|
|
if(isset($data['state'])) $model->where('state', $data['state']);
|
|
|
|
|
|
$list = $this->limit($model,'',$data);
|
|
|
- $list = $this->fillData($list);
|
|
|
+ $list = $this->fillData($list,$user);
|
|
|
|
|
|
return [true, $list];
|
|
|
}
|
|
@@ -571,9 +575,6 @@ class ProductService extends Service
|
|
|
if(empty($data['cost'])) return [false,'成本不能为空'];
|
|
|
$res = $this->checkNumber($data['cost']);
|
|
|
if(! $res) return [false,'成本请输入不超过两位小数并且大于0的数值'];
|
|
|
- if(empty($data['depart_price'])) return [false,'分社价格不能为空'];
|
|
|
- $res = $this->checkNumber($data['depart_price']);
|
|
|
- if(! $res) return [false,'分社价格请输入不超过两位小数并且大于0的数值'];
|
|
|
if(empty($data['retail_price'])) return [false,'零售价不能为空'];
|
|
|
$res = $this->checkNumber($data['retail_price']);
|
|
|
if(! $res) return [false,'零售价格请输入不超过两位小数并且大于0的数值'];
|
|
@@ -603,7 +604,7 @@ class ProductService extends Service
|
|
|
* @param $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function fillData($data){
|
|
|
+ public function fillData($data, $user){
|
|
|
if(empty($data['data'])) return $data;
|
|
|
|
|
|
$emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
|
|
@@ -612,11 +613,36 @@ class ProductService extends Service
|
|
|
$category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
- $basic_map = BasicType::whereIn('id',array_unique(array_column($data['data'],'unit')))
|
|
|
+ $detail = ProductPriceDetail::where('del_time',0)
|
|
|
+ ->where('product_id',array_unique(array_column($data['data'],'id')))
|
|
|
+ ->select('product_id','basic_type_id','price')
|
|
|
+ ->get()->toArray();
|
|
|
+ $basic_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($data['data'],'unit'),array_column($detail,'basic_type_id'))))
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
+ $detail_map = [];
|
|
|
+ foreach ($detail as $value){
|
|
|
+ $detail_map[$value['product_id']] = $value;
|
|
|
+ }
|
|
|
|
|
|
+ //是否总公司
|
|
|
+ $is_main = EmployeeService::isMain($user['id']);
|
|
|
+ $top_depart = $user['depart_top'][0] ?? [];
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
+ $tmp = [];
|
|
|
+ if(isset($detail_map[$value['id']])){
|
|
|
+ $d = $detail_map[$value['id']];
|
|
|
+ foreach ($d as $v){
|
|
|
+ //不是总公司 不是公司设置的金额 就不展示
|
|
|
+ if(! $is_main && ($top_depart['basic_type_id'] != $v['basic_type_id'])) continue;
|
|
|
+ $tmp[] = [
|
|
|
+ 'basic_type_id' => $value['basic_type_id'],
|
|
|
+ 'basic_type_title' => $basic_map[$value['basic_type_id']] ?? '',
|
|
|
+ 'price' => $value['price'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['data'][$key]['product_price'] = $tmp;
|
|
|
$data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
$data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
$data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
|