|
@@ -1120,4 +1120,168 @@ class ProductService extends Service
|
|
|
|
|
|
return $return;
|
|
|
}
|
|
|
+
|
|
|
+ public function productGroupByList($data,$user){
|
|
|
+ $model = Product::ProductClear($user,$data);
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
+ ->where('item_code','<>',"")
|
|
|
+ ->select('title','id','product_category_id','product_category','retail_price','product_attribute','item_code')
|
|
|
+ ->where('is_use', Product::is_use_one)
|
|
|
+ ->groupBy('item_code')
|
|
|
+ ->orderby('product_attribute', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['title_t'])) {
|
|
|
+ // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
|
|
|
+ $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
|
|
|
+ // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
|
|
|
+ $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
|
|
|
+ ->orWhere('code', 'LIKE', '%'.$data['title_t'].'%')
|
|
|
+ ->orWhere('size', 'LIKE', '%'.$data['title_t'].'%');
|
|
|
+ }
|
|
|
+ if(! empty($data['title'])){
|
|
|
+ // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
|
|
|
+ $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title']));
|
|
|
+ // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
|
|
|
+ $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%']);
|
|
|
+// $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
+ }
|
|
|
+ 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'].'%')
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $model->whereIn('product_category_id',array_unique(array_column($product_category,'id')));
|
|
|
+ }
|
|
|
+ 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]);
|
|
|
+ $model->where('crt_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+ if(! empty($data['product_id'])) $model->whereIn('id',$data['product_id']);
|
|
|
+
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->productGroupByListData($list,$user,$data);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function productGroupByListData($data, $user, $search){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ $type = $search['type'] ?? 0;
|
|
|
+ $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
|
|
|
+ ->select('title','id')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $category = array_column($category,null,'id');
|
|
|
+ $basic_map = BasicType::where('type',BasicType::type_22)
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ //产品使用价格
|
|
|
+ $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] ?? [];
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $arr = json_decode($value['product_category'], true);
|
|
|
+ $arr = array_flip($arr);
|
|
|
+ if (isset($arr[112])) {
|
|
|
+ $data['data'][$key]['is_roll'] = true;
|
|
|
+ }else{
|
|
|
+ $data['data'][$key]['is_roll'] = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['data'][$key]['img'] = $img[$value['id']] ?? "";
|
|
|
+ $tmp = $this->fillProductPrice($detail_map, $value, $top_depart,$basic_map);
|
|
|
+ $data['data'][$key]['product_price'] = $tmp;
|
|
|
+ $category_tmp = $category[$value['product_category_id']] ?? [];
|
|
|
+ $data['data'][$key]['product_category_name'] = $category_tmp['title'] ?? '';
|
|
|
+ $data['data'][$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function productGroupByListDetail($data, $user){
|
|
|
+ if(empty($data['item_code'])) return [false, '商品编码不能为空'];
|
|
|
+ $type = $data['type'] ?? 0;
|
|
|
+
|
|
|
+ //获取相同itemCode的产品
|
|
|
+ $product = $this->getProductByItemCode([$data['item_code']], $user);
|
|
|
+
|
|
|
+ $category = ProductCategory::whereIn('id',array_unique(array_column($product,'product_category_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $basic_map = BasicType::where('type',BasicType::type_22)
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ //产品使用价格
|
|
|
+ $product_id = array_column($product,'id');
|
|
|
+ $detail_map = $this->getProductPrice($product_id, $type);
|
|
|
+
|
|
|
+ //获取产品图片
|
|
|
+ $img = $this->getProductImg($product_id);
|
|
|
+
|
|
|
+ //当前门店
|
|
|
+ $top_depart = $user['depart_top'][0] ?? [];
|
|
|
+
|
|
|
+ foreach ($product as $key => $value){
|
|
|
+ $tmp = $this->fillProductPrice($detail_map, $value, $top_depart,$basic_map);
|
|
|
+ $product[$key]['product_price'] = $tmp;
|
|
|
+ $product[$key]['img'] = $img[$value['id']] ?? "";
|
|
|
+ $product[$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
|
|
|
+ $product[$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
|
|
|
+ $product[$key]['stock'] = "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $product];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getProductByItemCode($item_code,$user){
|
|
|
+ if(empty($item_code)) return [];
|
|
|
+
|
|
|
+ $model = Product::ProductClear($user,[]);
|
|
|
+ $product = $model->where('del_time',0)
|
|
|
+ ->whereIn('item_code', $item_code)
|
|
|
+ ->where('is_use', Product::is_use_one)
|
|
|
+ ->select('title','id','product_category_id','retail_price','product_attribute','item_code','size')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ return $product;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillProductPrice($detail_map, $value, $top_depart,$basic_map){
|
|
|
+ $tmp = [];
|
|
|
+ if(isset($detail_map[$value['id']])){
|
|
|
+ $d = $detail_map[$value['id']];
|
|
|
+ foreach ($d as $v){
|
|
|
+ if($top_depart['basic_type_id'] != $v['basic_type_id']) continue;
|
|
|
+ $tmp = [
|
|
|
+ 'basic_type_id' => $v['basic_type_id'],
|
|
|
+ 'basic_type_title' => $basic_map[$v['basic_type_id']] ?? '',
|
|
|
+ 'price' => $v['price']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(empty($tmp)) $tmp = (object)$tmp;
|
|
|
+
|
|
|
+ return $tmp;
|
|
|
+ }
|
|
|
}
|