|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
+use App\Model\BasicType;
|
|
|
|
+use App\Model\Depart;
|
|
use App\Model\Employee;
|
|
use App\Model\Employee;
|
|
use App\Model\Product;
|
|
use App\Model\Product;
|
|
use App\Model\ProductCategory;
|
|
use App\Model\ProductCategory;
|
|
@@ -133,7 +135,7 @@ class ProductService extends Service
|
|
$model->title = $data['title'];
|
|
$model->title = $data['title'];
|
|
$model->code = $data['code'] ?? '';
|
|
$model->code = $data['code'] ?? '';
|
|
$model->size = $data['size'] ?? '';
|
|
$model->size = $data['size'] ?? '';
|
|
- $model->unit = $data['unit'] ?? '';
|
|
|
|
|
|
+ $model->unit = $data['unit'] ?? 0;
|
|
$model->bar_code = $data['bar_code'] ?? '';
|
|
$model->bar_code = $data['bar_code'] ?? '';
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
$model->mark = $data['mark'] ?? '';
|
|
$model->mark = $data['mark'] ?? '';
|
|
@@ -225,7 +227,7 @@ class ProductService extends Service
|
|
$model->title = $data['title'];
|
|
$model->title = $data['title'];
|
|
$model->code = $data['code'] ?? '';
|
|
$model->code = $data['code'] ?? '';
|
|
$model->size = $data['size'] ?? '';
|
|
$model->size = $data['size'] ?? '';
|
|
- $model->unit = $data['unit'] ?? '';
|
|
|
|
|
|
+ $model->unit = $data['unit'] ?? 0;
|
|
$model->bar_code = $data['bar_code'] ?? '';
|
|
$model->bar_code = $data['bar_code'] ?? '';
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
$model->retail_price = $data['retail_price'] ?? 0;
|
|
$model->mark = $data['mark'] ?? '';
|
|
$model->mark = $data['mark'] ?? '';
|
|
@@ -332,6 +334,9 @@ class ProductService extends Service
|
|
->first();
|
|
->first();
|
|
if(empty($customer)) return [false,'产品不存在或已被删除'];
|
|
if(empty($customer)) return [false,'产品不存在或已被删除'];
|
|
$customer = $customer->toArray();
|
|
$customer = $customer->toArray();
|
|
|
|
+ //单位
|
|
|
|
+ $title = BasicType::where('id',$customer['unit'])->value('title');
|
|
|
|
+ $customer['unit_name'] = $title;
|
|
//库存
|
|
//库存
|
|
$customer['product_inventory'] = [];
|
|
$customer['product_inventory'] = [];
|
|
$depart_id = array_column($user['rule_depart'],'depart_id');
|
|
$depart_id = array_column($user['rule_depart'],'depart_id');
|
|
@@ -359,17 +364,29 @@ class ProductService extends Service
|
|
->where('product_id',$customer['id'])
|
|
->where('product_id',$customer['id'])
|
|
->select('id','product_id','depart_id','type','employee_id')
|
|
->select('id','product_id','depart_id','type','employee_id')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
+ $emp_map = Employee::whereIn('id',array_unique(array_merge_recursive([$customer['crt_id']],array_column($customer_range,'employee_id'))))
|
|
|
|
+ ->pluck('emp_name','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ $depart_map = Depart::whereIn('id',array_unique(array_column($customer_range,'depart_id')))
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
foreach ($customer_range as $value){
|
|
foreach ($customer_range as $value){
|
|
if($value['type'] == ProductRange::type_one){
|
|
if($value['type'] == ProductRange::type_one){
|
|
- $customer['depart'][] = [
|
|
|
|
- $value['depart_id']
|
|
|
|
|
|
+ $tmp = [
|
|
|
|
+ 'id' => $value['depart_id'],
|
|
|
|
+ 'name' => $depart_map[$value['depart_id']],
|
|
];
|
|
];
|
|
|
|
+ $customer['depart'][] = $tmp;
|
|
}elseif ($value['type'] == ProductRange::type_two){
|
|
}elseif ($value['type'] == ProductRange::type_two){
|
|
- $customer['employee'][] = [
|
|
|
|
- $value['employee_id']
|
|
|
|
|
|
+ $tmp = [
|
|
|
|
+ 'id' => $value['employee_id'],
|
|
|
|
+ 'name' => $emp_map[$value['employee_id']],
|
|
];
|
|
];
|
|
|
|
+ $customer['employee'][] = $tmp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ $customer['crt_name'] = $emp_map[$customer['crt_id']] ?? '';
|
|
|
|
+ $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
|
|
|
|
|
|
return [true, $customer];
|
|
return [true, $customer];
|
|
}
|
|
}
|
|
@@ -433,12 +450,16 @@ class ProductService extends Service
|
|
$category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
|
|
$category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
|
|
->pluck('title','id')
|
|
->pluck('title','id')
|
|
->toArray();
|
|
->toArray();
|
|
|
|
+ $basic = BasicType::where('id',array_unique(array_column($data['data'],'unit')))
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
|
|
foreach ($data['data'] as $key => $value){
|
|
foreach ($data['data'] as $key => $value){
|
|
$data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
$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]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
$data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
|
|
$data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
|
|
$data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
|
|
$data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
|
|
|
|
+ $data['data'][$key]['unit_name'] = $basic[$value['unit']] ?? '';
|
|
}
|
|
}
|
|
|
|
|
|
return $data;
|
|
return $data;
|