|
@@ -107,6 +107,39 @@ class ProductService extends Service
|
|
|
return [200, ['data' => $list,'tree' => $list_tree]];
|
|
|
}
|
|
|
|
|
|
+ public function productCategoryList2($data,$user){
|
|
|
+ $head_top_depart_id = $user['head']['id'] ?? 0;
|
|
|
+ $now_top_depart_id = $this->getDepart($user);
|
|
|
+
|
|
|
+ //总社分类
|
|
|
+ $head = ProductCategory::where('del_time',0)
|
|
|
+ ->where('top_depart_id', $head_top_depart_id)
|
|
|
+ ->select('title','id','parent_id')
|
|
|
+ ->orderby('id','asc')
|
|
|
+ ->get()->toArray();
|
|
|
+ $head_tree = [];
|
|
|
+ if(! empty($head)) {
|
|
|
+ $head_tree = $this->makeTree(0,$head);
|
|
|
+ $head_tree = $this->set_sort_circle($head_tree);
|
|
|
+ }
|
|
|
+
|
|
|
+ //我的
|
|
|
+ $my_tree = [];
|
|
|
+ if($head_top_depart_id != $now_top_depart_id){
|
|
|
+ $model = ProductCategory::TopClear($user,$data);
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
+ ->select('title','id','parent_id')
|
|
|
+ ->orderby('id','asc');
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ if(! empty($list)) {
|
|
|
+ $my_tree = $this->makeTree(0,$list);
|
|
|
+ $my_tree = $this->set_sort_circle($my_tree);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [200, ['head_tree' => $head_tree, 'my_tree' => $my_tree]];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 产品分类参数规则
|
|
|
* @param $data
|
|
@@ -537,6 +570,10 @@ class ProductService extends Service
|
|
|
if(isset($data['state'])) $model->where('state', $data['state']);
|
|
|
if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
|
|
|
if(! empty($data['product_category_id'])) $model->where('product_category_id', $data['product_category_id']);
|
|
|
+ if(! empty($data['category'])){
|
|
|
+ $id = $this->getProductCateGory($data['category']);
|
|
|
+ $model->whereIn('product_category_id', $id);
|
|
|
+ }
|
|
|
if(! empty($data['product_category'])) {
|
|
|
$product_category = ProductCategory::where('del_time',0)
|
|
|
->where('title', 'LIKE', '%'.$data['product_category'].'%')
|
|
@@ -546,6 +583,7 @@ class ProductService extends Service
|
|
|
}
|
|
|
if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
|
|
|
if(! empty($data['bar_code'])) $model->where('bar_code', 'LIKE', '%'.$data['bar_code'].'%');
|
|
|
+ if(! empty($data['size'])) $model->where('size', 'LIKE', '%'.$data['size'].'%');
|
|
|
if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
$return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
$model->where('crt_time','>=',$return[0]);
|
|
@@ -665,7 +703,11 @@ class ProductService extends Service
|
|
|
$depart_map = Depart::whereIn('id',array_unique(array_column($data['data'],'top_depart_id')))->pluck('title','id')->toArray();
|
|
|
|
|
|
//产品使用价格
|
|
|
- $detail_map = $this->getProductPrice(array_column($data['data'],'id'), $type);
|
|
|
+ $product_id = array_column($data['data'],'id');
|
|
|
+ $detail_map = $this->getProductPrice($product_id, $type);
|
|
|
+
|
|
|
+ //获取产品图片
|
|
|
+ $img = $this->getProductImg($product_id);
|
|
|
|
|
|
//当前门店
|
|
|
$top_depart = $user['depart_top'][0] ?? [];
|
|
@@ -697,6 +739,7 @@ class ProductService extends Service
|
|
|
$data['data'][$key]['unit_name'] = $basic_map[$value['unit']] ?? '';
|
|
|
$data['data'][$key]['belong_to'] = $depart_map[$value['top_depart_id']] ?? '';
|
|
|
$data['data'][$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
|
|
|
+ $data['data'][$key]['img'] = $img[$value['id']] ?? "";
|
|
|
|
|
|
//成本隐藏
|
|
|
$price = "******";
|
|
@@ -707,6 +750,31 @@ class ProductService extends Service
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ public function getProductCateGory($category){
|
|
|
+ $product_category = ProductCategory::where('del_time',0)
|
|
|
+ ->select('id','parent_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = array_merge($this->getAllDescendants($product_category,$category),[$category]);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getProductImg($product_id = []){
|
|
|
+ if(empty($product_id)) return [];
|
|
|
+
|
|
|
+ $img = [];
|
|
|
+ $customer_info = ProductInfo::where('del_time',0)
|
|
|
+ ->whereIn('product_id',$product_id)
|
|
|
+ ->where('type',ProductInfo::type_one)
|
|
|
+ ->select('product_id','file','type','name')
|
|
|
+ ->get()->toArray();
|
|
|
+ foreach ($customer_info as $value){
|
|
|
+ if(isset($img[$value['product_id']])) continue;
|
|
|
+ $img[$value['product_id']] = $value['file'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $img;
|
|
|
+ }
|
|
|
+
|
|
|
//获取产品字典
|
|
|
public function getProductDetail($product_id = []){
|
|
|
if(empty($product_id)) return [];
|