cqp 3 months ago
parent
commit
ca02038d5f

+ 26 - 0
app/Http/Controllers/Api/ProductController.php

@@ -140,6 +140,32 @@ class ProductController extends BaseController
         }
     }
 
+    public function productGroupByList(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productGroupByList($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function productGroupByListDetail(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productGroupByListDetail($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function batchUploadImg(Request $request)
     {
         $service = new ProductService();

+ 7 - 1
app/Model/Inventory.php

@@ -23,5 +23,11 @@ class Inventory extends UseScopeBaseModel
     ];
 
     const range_function = '';
-    const is_check_function = '';
+    const is_check_function = 'inventoryCheck';
+
+    public static $wait_check = [
+        self::State_minus_one,
+        self::STATE_ZERO,
+        self::STATE_ONE,
+    ];
 }

+ 16 - 23
app/Service/ImportService.php

@@ -1409,9 +1409,9 @@ class ImportService extends Service
             $rowData = array_filter($value);
             if (empty($rowData)) {
                 unset($array[$key]);
-            } elseif(empty($value[0]) || empty($value[1]) || empty($value[2])) {
+            } elseif(empty($value[0]) || empty($value[1])) {
                 if($key != 1){
-                    if(empty($value[2])) return [false, '带*号的字段项必填'];
+                    if(empty($value[1])) return [false, '带*号的字段项必填'];
                 } else{
                     return [false, '带*号的字段项必填'];
                 }
@@ -1420,13 +1420,12 @@ class ImportService extends Service
                     $value[$k] = trim($v);
                 }
                 if($shop_name && ! in_array($value[0],$shop_name)) $shop_name[] = $value[0];
-                if($counted_number && ! in_array($value[1],$counted_number)) $counted_number[] = $value[1];
-                if(! in_array($value[2],$product_code)) {
-                    $product_code[] = $value[2];
+                if(! in_array($value[1],$product_code)) {
+                    $product_code[] = $value[1];
                 }else{
-                    return [false, '产品编号:' . $value[2] .'已存在'];
+                    return [false, '产品编号:' . $value[1] .'已存在'];
                 }
-                if(! is_numeric($value[3])) return [false, '* 盘点数量请填写正确的数值'];
+                if(! is_numeric($value[2])) return [false, '* 盘点数量请填写正确的数值'];
             }
         }
         if(count($shop_name) != 1) return [false, '只允许单门店盘点'];
@@ -1446,13 +1445,9 @@ class ImportService extends Service
             ->pluck('id','top_depart_id')
             ->toArray();
 
-        $employee = Employee::where('del_time',0)
-            ->whereIn('number',$counted_number)
-            ->pluck('number','id')
-            ->toArray();
         $time = time();
 
-        $top_depart_id = $storehouse_id = $employee_id = 0;
+        $top_depart_id = $storehouse_id = 0;
         $product_submit = $product_id = $sub = [];
         foreach ($array as $value){
             if($value[0]){
@@ -1462,30 +1457,24 @@ class ImportService extends Service
                 $storehouse_tmp = $storehouse_map[$depart_tmp] ?? 0;
                 if(! $storehouse_id) $storehouse_id = $storehouse_tmp;
             }
-            if($value[1]){
-                $emp_tmp = $employee[$value[1]] ?? 0;
-                if(! $emp_tmp) return [false, "工号:" . $value[1] . "不存在或已被删除"];
-                if(! $employee_id) $employee_id = $emp_tmp;
-            }
-            $product_tmp = $product_map[$value[2]] ?? 0;
-            if($product_tmp <= 0) return [false, "产品编码:" . $value[2] . "不存在或已被删除"];
-
+            $product_tmp = $product_map[$value[1]] ?? 0;
+            if($product_tmp <= 0) return [false, "产品编码:" . $value[1] . "不存在或已被删除"];
             if(! $storehouse_id) return [false, '门店下仓库信息未找到'];
 
             $key = $product_tmp . ',' . $storehouse_id;
             if(! isset($product_submit[$key])) $product_submit[$key] = 0;
 
             //总的产品id
-            $product_id[] = $value['product_id'];
+            $product_id[] = $product_tmp;
 
             $sub[] = [
                 'product_id' => $product_tmp,
                 'storehouse_id' => $storehouse_id,
                 'order_number' => "",
-                'counted_num' => $value[3],
+                'counted_num' => $value[2],
                 'book_num' => 0,
                 'final_num' => 0,
-                'inventory_id' => $employee_id
+                'inventory_id' => 0
             ];
         }
 
@@ -1548,6 +1537,10 @@ class ImportService extends Service
             $inventory_model->crt_id = $user['id'];
             $inventory_model->save();
 
+            foreach ($sub as $key => $value){
+                $sub[$key]['inventory_id'] = $inventory_model->id;
+            }
+
             //写入数据
             InventorySub::insert($sub);
 

+ 35 - 5
app/Service/InventoryService.php

@@ -5,6 +5,7 @@ namespace App\Service;
 use App\Model\Employee;
 use App\Model\Inventory;
 use App\Model\InventorySub;
+use App\Model\OrderInventoryStock;
 use App\Model\Product;
 use App\Model\Storehouse;
 use Illuminate\Support\Facades\DB;
@@ -43,7 +44,10 @@ class InventoryService extends Service
                 }
                 InventorySub::insert($sub);
 
-                ProductInventoryService::changeLockNumber($user,$msg[0],$msg[1]);
+                $is_check_stock = OrderInventoryStock::where('order_number', $data['order_number'])
+                    ->where('del_time',0)
+                    ->value('is_check_stock') ?? 0;
+                ProductInventoryService::changeLockNumber($user,$msg[0],$msg[1],$is_check_stock);
             }
 
             DB::commit();
@@ -52,6 +56,16 @@ class InventoryService extends Service
             return [false,$e->getMessage()];
         }
 
+        if(! empty($data['check'])) {
+            list($status,$msg) = (new CheckService())->checkAll([
+                "id" => $inventory_model->id,
+                "order_number" => $data['order_number'],
+                "opt_case" => CheckService::fourteen,
+                "menu_id" => $data['menu_id']
+            ],$user);
+//            if(! $status) return [true, '保存成功,施工单确认失败,异常信息:' . $msg];
+        }
+
         return [true, ''];
     }
 
@@ -102,6 +116,16 @@ class InventoryService extends Service
             return [false,$exception->getMessage()];
         }
 
+        if(! empty($data['check'])) {
+            list($status,$msg) = (new CheckService())->checkAll([
+                "id" => $inventory_model->id,
+                "order_number" => $data['order_number'],
+                "opt_case" => CheckService::fourteen,
+                "menu_id" => $data['menu_id']
+            ],$user);
+//            if(! $status) return [true, '保存成功,施工单确认失败,异常信息:' . $msg];
+        }
+
         return [true, ''];
     }
 
@@ -121,6 +145,7 @@ class InventoryService extends Service
         if(empty($inventory)) return [false,'盘点单不存在或已被删除'];
         $inventory = $inventory->toArray();
         $inventory['state_title'] = Inventory::$name[$inventory['state']] ?? '';
+        $inventory['storehouse_title'] = Storehouse::where('id',$inventory['storehouse_id'])->value('title');
 
         $emp_map = Employee::whereIn('id', [$inventory['crt_id'], $inventory['counted_id']])
             ->pluck('emp_name','id')
@@ -132,13 +157,14 @@ class InventoryService extends Service
 
         $sub = InventorySub::where('del_time',0)
             ->where('inventory_id', $data['id'])
-            ->select('product_id','counted_num','final_num','price')
+            ->select('product_id','counted_num','final_num','price','book_num')
             ->get()->toArray();
         $map = (new ProductService())->getProductDetail(array_column($sub,'product_id'));
         foreach ($sub as $key => $value){
             $tmp = $map[$value['product_id']] ?? [];
             $sub[$key]['title'] = $tmp['title'] ?? "";
             $sub[$key]['code'] = $tmp['code'] ?? "";
+            $sub[$key]['size'] = $tmp['size'] ?? "";
         }
         $inventory['sub'] = $sub;
 
@@ -161,12 +187,16 @@ class InventoryService extends Service
                 'del_time'=> $time
             ]);
 
-            InventorySub::where('del_time',0)->whereIn('inventory_id',$data['id'])->update([
+            InventorySub::where('del_time',0)->where('inventory_id',$data['id'])->update([
                 'del_time'=> $time
             ]);
 
+            $is_check_stock = OrderInventoryStock::where('order_number', $data['order_number'])
+                    ->where('del_time',0)
+                    ->value('is_check_stock') ?? 0;
+
             //锁定库存释放
-            if(! empty($product_save)) ProductInventoryService::changeLockNumber($user,[],$product_save);
+            if(! empty($product_save)) ProductInventoryService::changeLockNumber($user,[],$product_save,$is_check_stock);
 
             DB::commit();
         }catch (\Exception $exception){
@@ -180,7 +210,7 @@ class InventoryService extends Service
     public function getList($data,$user){
         $model = Inventory::Clear($user,$data);
         $model = $model->where('del_time',0)
-            ->select('order_number','id','storehouse_id','state','counted_id','counted_time','inventory_id','crt_time')
+            ->select('order_number','id','storehouse_id','state','counted_id','counted_time','crt_time')
             ->orderby('id', 'desc');
         if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
         if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');

+ 12 - 2
app/Service/OutBoundOrderService.php

@@ -4,6 +4,7 @@ namespace App\Service;
 
 use App\Model\Depart;
 use App\Model\Employee;
+use App\Model\OrderInventoryStock;
 use App\Model\OutBoundOrder;
 use App\Model\OutBoundOrderInfo;
 use App\Model\ReturnExchangeOrder;
@@ -49,8 +50,12 @@ class OutBoundOrderService extends Service
                 }
                 OutBoundOrderInfo::insert($sub);
 
+                $is_check_stock = OrderInventoryStock::where('order_number', $data['order_number'])
+                        ->where('del_time',0)
+                        ->value('is_check_stock') ?? 0;
+
                 //锁定库存
-                ProductInventoryService::changeLockNumber($user, $msg[0],$msg[1]);
+                ProductInventoryService::changeLockNumber($user, $msg[0],$msg[1],$is_check_stock);
             }
 
             DB::commit();
@@ -191,8 +196,13 @@ class OutBoundOrderService extends Service
                 'del_time'=>time()
             ]);
 //            (new RangeService())->RangeDelete($order['id'],SeeRange::type_three);
+
+            $is_check_stock = OrderInventoryStock::where('order_number', $data['order_number'])
+                    ->where('del_time',0)
+                    ->value('is_check_stock') ?? 0;
+
             //锁定库存释放
-            ProductInventoryService::changeLockNumber($user,[],$product_save);
+            ProductInventoryService::changeLockNumber($user,[],$product_save,$is_check_stock);
 
             DB::commit();
         }catch (\Throwable $e){

+ 9 - 3
app/Service/ProductInventoryService.php

@@ -68,9 +68,15 @@ class ProductInventoryService extends Service
 
     //更新锁定库存
     //$user 当前登录人的信息
-    //$submit_total (提交的数据)  $save_total(保存过的数据)
-    public static function changeLockNumber($user, $submit_total = [], $save_total = []){
-        if($user['is_check_stock'] == ProductInventorySet::type_two) return; //不校验库存
+    //$submit_total (提交的数据)  $save_total(保存过的数据) todo
+    public static function changeLockNumber($user, $submit_total = [], $save_total = [], $is_check_stock = 0){
+        //如果外部传来则按照外部
+        if($is_check_stock){
+            if($is_check_stock == ProductInventorySet::type_two) return;
+        }else{
+            //外部没有传递 则根据当前用户
+            if($user['is_check_stock'] == ProductInventorySet::type_two) return; //不校验库存
+        }
         if(empty($submit_total) && empty($save_total)) return;
 
         //产品数扣减

+ 164 - 0
app/Service/ProductService.php

@@ -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;
+    }
 }

+ 46 - 0
app/Service/RangeService.php

@@ -9,6 +9,7 @@ use App\Model\Customer;
 use App\Model\CustomerInfo;
 use App\Model\Depart;
 use App\Model\Employee;
+use App\Model\Inventory;
 use App\Model\InvoiceOrder;
 use App\Model\OaOrder;
 use App\Model\OaOrderSub;
@@ -936,6 +937,51 @@ class RangeService extends Service
         return [$status, $msg];
     }
 
+    public static function inventoryCheck($user,$search){
+        $args = "";
+        if($search['is_check'] == 1) {
+            list($status, $id) = self::getWaitForinventoryCheck($user,$search);
+
+            //待审核
+            $check = implode(",", Inventory::$wait_check);
+            $args = "(state IN (" . $check ."))";
+
+            if($status) {
+                $wait_for_me = $search['wait_for_me'] ?? 0;
+
+                $check_2 = implode(',', array_diff(Inventory::$wait_check, [Inventory::STATE_ONE]));
+                $id = implode(",", $id);
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
+                }
+            }
+        }elseif($search['is_check'] == 2){
+            //已审
+            $args = "(state >= ". Inventory::STATE_TWO . ")";
+        }
+
+        return $args;
+    }
+
+    private static function getWaitForinventoryCheck($user, $search){
+        if(! isset($search['wait_for_me'])) return [false, []];
+
+        //获取待审核数据
+        $args = "(state = " . Inventory::STATE_ONE . ")";
+        $data = Inventory::where('del_time',0)
+            ->whereRaw($args)
+            ->select('order_number','id')
+            ->get()->toArray();
+        if(empty($data)) return [true, []];
+
+        list($status,$msg) = self::getWaitCommon($data,$user);
+        return [$status, $msg];
+    }
+
     private static function getWaitCommon($data,$user){
         $data_map = array_column($data,'id','order_number');
         //查找对应审批流数据

+ 0 - 4
config/excel/inventory.php

@@ -11,10 +11,6 @@ return [
         'value' => '* 门店名称',
     ],
     [
-        'key' => 'counted_number',
-        'value' => '* 盘点人工号',
-    ],
-    [
         'key' => 'code',
         'value' => '* 产品编码',
     ],

+ 3 - 0
config/morequery.php

@@ -2,6 +2,9 @@
 
 return [
     "menu" => [
+        "api/inventoryAdd" => 56,
+        "api/inventoryEdit" => 56,
+        "api/inventoryList" => 56,
         "api/outBoundOrderList" => 55,
         "api/outBoundOrderEdit" => 55,
         "api/outBoundOrderAdd" => 55,

+ 6 - 0
config/oa.php

@@ -505,5 +505,11 @@ return [
             ],
         ]
     ],
+    [
+        'menu_id' => 55,
+        'menu_title' => '出库单',
+        'children' => [
+        ]
+    ],
 ];
 

+ 2 - 0
routes/api.php

@@ -158,6 +158,8 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //产品名称
     $route->any('productListIndex', 'Api\ProductController@productListIndex');//列表页
     $route->any('productList', 'Api\ProductController@productList');//选择列表页
+    $route->any('productGroupByList', 'Api\ProductController@productGroupByList');//选择列表页
+    $route->any('productGroupByListDetail', 'Api\ProductController@productGroupByListDetail');//选择列表页详情
     $route->any('productEdit', 'Api\ProductController@productEdit')->middleware('OssFileDeal');
     $route->any('productAdd', 'Api\ProductController@productAdd')->middleware('OssFileDeal');
     $route->any('productDel', 'Api\ProductController@productDel')->middleware('OssFileDeal');