소스 검색

盘收一体-前端文件选择默认三种:csv,xlsx,xls
导入和扫码时未匹配到商品录入一份
商品表增加type字段,非常规商品录入为临时商品
导入取消一些限制,商品增加接口

Zhouzhendong 5 년 전
부모
커밋
dca47e1822

+ 1 - 1
app/Commodity.php

@@ -9,7 +9,7 @@ use App\Traits\ModelTimeFormat;
 class Commodity extends Model
 {
     use ModelTimeFormat;
-    protected $fillable=['name','sku','owner_id','created_at','length','width','height','volumn'];
+    protected $fillable=['name','sku','owner_id','created_at','length','width','height','volumn',"type"];
     protected $appends=['barcode'];
 //    protected $appends=['barcode','owner_name','owner_code'];
 

+ 3 - 2
app/Http/Controllers/CommodityController.php

@@ -176,11 +176,12 @@ class CommodityController extends Controller
         return ['success'=>true];
     }
 
-
-    public function syncOwnerCommodities($owner_id,$owner_code,$sku = null){
+    //通过货主与SKU同步 WMS商品至本地 有则比对修正,无则录入
+    public function syncOwnerCommodities($owner_id,$owner_code,$sku = null, $barcode = null){
         ini_set('max_execution_time', '0');
         $params = ['customerid' => $owner_code];
         if ($sku) $params['sku'] = $sku;
+        if ($barcode) $params['alternate_sku1'] = $barcode;
 
         /** @var OracleBasSkuService $oracleBasSkuService */
         $oracleBasSkuService = app('oracleBasSkuService');

+ 28 - 6
app/Http/Controllers/StoreCheckingReceiveController.php

@@ -63,7 +63,7 @@ class StoreCheckingReceiveController extends Controller
     }
 
     public function insertItem(Request $request){
-        if(!Gate::allows('入库管理-盘收一体-盘收-查看')){ return ['success'=>false, 'data'=>'无权操作!'];  }
+        if(!Gate::allows('入库管理-盘收一体-盘收-编辑')){ return ['success'=>false, 'data'=>'无权操作!'];  }
         $mission_id = $request->mission_id ?? false;
         $goods = $request->goods ?? false;
         if (!($goods["amount"] ?? false))$goods["amount"] = 1;
@@ -135,14 +135,36 @@ class StoreCheckingReceiveController extends Controller
             }
             return ['success'=>true, 'type'=>"update", 'data'=>$item];
         }
-        $commodity_barcode = app('commodityBarcodeService')->first([
-            'code' => $goods['barcode'],
-        ]);
-        if (!$commodity_barcode) return ['success'=>false, 'data'=>'该条码未找到对应商品'];
+        $commodity = app('commodityService')->ownerBarcodeSeekCommodityFirst(['id'=>$storeCheckingReceive->owner_id], $goods['barcode']);
+        if (!$commodity) {
+            if (!$storeCheckingReceive->owner) return ['success'=>false, 'data'=>'未找到货主'];
+            $basSku = app('oracleBasSkuService')->first(['customerid'=>$storeCheckingReceive->owner->code, "barcode"=>$goods['barcode']]);
+            if ($basSku){
+                $commodity = app('commodityService')->firstOrCreate(['owner_id'=>$storeCheckingReceive->owner_id, 'sku'=>$basSku->sku],[
+                    "name"=>$basSku->descr_c,
+                    "sku"=>$basSku->sku,
+                    "owner_id"=>$storeCheckingReceive->owner_id,
+                    'length' => $basSku->skulength,
+                    'width' => $basSku->skuwidth,
+                    'height' => $basSku->skuhigh,
+                    'volumn' => $basSku->cube
+                ]);
+                if ($commodity) app('commodityBarcodeService')->firstOrCreate(['commodity_id'=>$commodity->id, 'code'=>$goods['barcode']]);
+            }else{
+                $commodity = app('commodityService')->createTemporaryCommodity([
+                    "sku"=>$goods['barcode'],
+                    "owner_id"=>$storeCheckingReceive->owner_id,
+                ]);
+                app('commodityBarcodeService')->create([
+                    "commodity_id"=>$commodity->id,
+                    "code" => $goods['barcode'],
+                ]);
+            }
+        };
         $item = app('storeCheckingReceiveItemService')->create([
             'store_checking_receive_id' => $mission_id,
             'bin_number' => $goods['bin_number'],
-            'commodity_id' => $commodity_barcode->commodity_id,
+            'commodity_id' => $commodity->id,
             'imported_amount' => 0,
             'imported_diff_amount' => $goods['amount'],
             'produced_at' => $goods['produce_date'],

+ 3 - 34
app/Http/Controllers/TestController.php

@@ -523,40 +523,9 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
     }
 
     public function test2(){
-        ini_set('max_execution_time',2500);
-        ini_set('memory_limit','1526M');
-        $logs = Log::query()
-        ->where('created_at','<','2020-09-30 18:00:36')
-        ->where('operation','App\Services\common\BatchUpdateService::batchUpdateItself')
-        ->where('id','9865536')->get();
-        $arr = [];
-        foreach ($logs as $log){
-            $str1 = mb_strlen("批量更新失败 SQL:(");
-            $str2 = mb_strripos($log->description,") 堆栈:");
-            $str = mb_substr($log->description,$str1,$str2-$str1);
-            dd($str);
-            $sign = "END WHERE commodity_id IN (";
-            $str3 = mb_strripos($str,$sign);
-            $str = substr($str,$str3+strlen($sign));
-            $str = substr($str,0,strlen($str)-1);
-            $arr = array_merge($arr,explode(',',$str));
-            /*try{
-                DB::select(DB::raw($str));
-                LogService::log(__METHOD__,"纠正商品-SQL执行BUG",$str);
-            }catch(\Exception $e){
-                LogService::log(__METHOD__,"纠正商品-SQL执行BUG-失败",$str." | 堆栈:". $e->getMessage() . $e->getTraceAsString());
-            }*/
-        }
-        $comId = [];
-        $logs = Log::query()
-            ->where('type','纠正商品-删除无用商品')->get();
-        foreach ($logs as $log){
-            $comId = array_merge($comId,explode(',',substr($log->description,1,strlen($log->description)-2)));
-        }
-        dd(array_diff($comId,$arr));
-        $si = [276705,277352,252318,313660,313687,313500,258354];
-
-        dd($arr);
+        $a = ["测试","TEST","123","测试TEST123"];
+        $b = ["测试"];
+        dd(array_diff($a,$b));
     }
 
     /*1*/

+ 7 - 5
app/Http/Controllers/api/thirdPart/haiq/StorageController.php

@@ -19,18 +19,20 @@ class StorageController
             "qty" => 9,//数量
         ];
         $bin = [
-            "taskCode" => "TEST-BS2010100001",//任务编号
+            "taskCode" => "TEST-BS2010100001",//任务编号 全局唯一
             "binCode" => "TEST-BIN01",//料箱编码
+            "toWorkStation" => "TEST-HQ01",//出库工作站
+            "fromWorkStation" => "TEST-HQ01",//回库工作站
             "fromLocCode" => "TEST-J04-058-3",//源库位编码
             "toLocCode" => "TEST-J24-128-7",//目标库位编码 出库填多个,表示这些库位都可以支持
             "sequence" => -1,//出库顺序 -1表示没有顺序,只有移库出库时需要指定顺序,其他可为-1
             "stockInfo" => [$stockInfo],//商品信息
         ];
         $this->request = [[
-            "groupCode" => 1,//组号/波次号 决定了出库的顺序,越大优先级越高
-            "taskMode" => 1,//任务模式 1(拣货出库) 2(入库指定料箱出库) 3(盘点出库) 4(移库出库) 5(入库不指定料箱出库)
-            "priority" => 99,//优先级 1-100 1最低
-            "sequenceFlag" => -1,//出库顺序 -1表示没有顺序,只有移库出库时需要指定顺序,其他可为-1
+            "groupCode" => 1,//组号/波次号 一组任务需要一起完成,再开始下一组任务;没有组任务的限制默认传-1或空
+            "taskMode" => 1,//任务模式 值 1 (输送线入库)值 2 (输送线出库)值 3(货架到缓存货架)值4(货架到流利货架)
+            "priority" => 99,//优先级 1-2147483647 1最低
+            "sequenceFlag" => -1,//是否需要有序 1:需要有序 0:不需要有序
             "bins" => [$bin],//可执行货箱任务
         ]];
     }

+ 125 - 91
app/Imports/StoreCheckingReceiveImport.php

@@ -2,6 +2,8 @@
 
 namespace App\Imports;
 
+use App\Http\Controllers\CommodityController;
+use App\Services\CommodityBarcodeService;
 use App\Services\CommodityService;
 use App\Services\LogService;
 use Carbon\Carbon;
@@ -40,7 +42,7 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
         //去重 筛选 错误
         foreach ($collection as $index => $item){
             if (!$owner_name && $item["货主"]) $owner_name = $item["货主"];
-            if (!$item["条码"] || !$item["数量"] || !is_numeric($item["数量"])){
+            if (!$item["条码"] || !is_numeric($item["数量"])){
                 array_push($errors,($index+2)." 行:条码或数量不存在");
                 continue;
             }
@@ -72,13 +74,18 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
             }
             $isUniqueCommodity = isset($commodities[$item["条码"]]);
             if ($isUniqueCommodity){
-                $line = &$items[$commodities[$item["条码"]]];
-                if ($line["produced_at"] == $item["生产日期"] && $line["invalid_at"] == $item["失效日期"]
-                    && $line["batch_code"] == $item["批号"] && $line["unique_code"] == $item["唯一码"]) {
-                    $line["imported_amount"] += $item["数量"];
-                    array_push($errors, ($index + 2) . " 行:重复数据已合并数量");
-                    continue;
+                $sign = false;
+                foreach ($commodities[$item["条码"]] as $i){
+                    $line = &$items[$i];
+                    if ($line["produced_at"] == $item["生产日期"] && $line["invalid_at"] == $item["失效日期"]
+                        && $line["batch_code"] == $item["批号"] && $line["unique_code"] == $item["唯一码"]) {
+                        $line["imported_amount"] += $item["数量"];
+                        array_push($errors, ($index + 2) . " 行:重复数据已合并数量");
+                        $sign = true;
+                        break;
+                    }
                 }
+                if ($sign) continue;
             }
             array_push($items,[
                 "imported_amount" => $item["数量"],
@@ -92,13 +99,13 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
                 "lineno" => $index+2,
             ]);
             if ($isUniqueCommodity){
-                if (is_array($commodities[$item["条码"]])) array_push($commodities[$item["条码"]], count($items)-1);
-                else $commodities[$item["条码"]] = [$commodities[$item["条码"]], count($items)-1];
+                array_push($commodities[$item["条码"]], count($items)-1);
             }else{
-                $commodities[$item["条码"]] = count($items)-1 ;
+                $commodities[$item["条码"]] = [count($items)-1] ;
                 array_push($barcodes,$item["条码"]);
             }
         }
+
         //不存在货主
         if (!$owner_name){
             Cache::put("storeCheckingReceive",["success"=>false, "data"=>"货主为空,不允许录入,至少为一行标明货主!"],86400);
@@ -106,12 +113,15 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
         }
         $owner = app('ownerService')->firstOrCreate(["name"=>$owner_name],["name"=>$owner_name, "code"=>$owner_name]);
 
-        //使用条码获取商品ID
-        $commodityBarCodes = app('commodityBarcodeService')->getCommodities($barcodes, $owner->id);
+        //使用条码同步
+        $commodityController = new CommodityController();
+        $commodityController->syncOwnerCommodities($owner->id, $owner->code, null,$barcodes);
+
+        //使用条码获取商品ID,筛选出需要录入条码项
+        /** @var CommodityBarcodeService $commodityBarcodeService */
+        $commodityBarcodeService = app('commodityBarcodeService');
+        $commodityBarCodes = $commodityBarcodeService->getCommodities($barcodes, $owner->id);
         foreach ($commodityBarCodes as $barcode){
-            if (!is_array($commodities[$barcode->code])){
-                $commodities[$barcode->code] = [$commodities[$barcode->code]];
-            }
             foreach ($commodities[$barcode->code] as $index){
                 $items[$index]["commodity_id"] = $barcode->commodity_id;
                 unset($items[$index]["SKU"]);
@@ -122,91 +132,115 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
             unset($commodities[$barcode->code]);
         }
 
-        //填充商品ID,未找到项流转下一步,空SKU删除该行并返回错误
-        $skus = [];
-        $skuParam = [];
-        foreach ($commodities as $key => $value){
-            if (!is_array($value)){
-                $value = [$value];
+        if (count($commodities) > 0){
+            //获取SKU,将已存在的商品补录条码
+            $skus = [];
+            $skuMap = [];
+            foreach ($commodities as $arr){
+                foreach ($arr as $index){
+                    $item = $items[$index];
+                    if ($item['SKU']){
+                        $skus[] = $item['SKU'];
+                        //sku对应多个条码
+                        if (isset($skuMap[$item['SKU']]))$skuMap[$item['SKU']][] = $item['条码'];
+                        else $skuMap[$item['SKU']] = [$item['条码']];
+                    } else {
+                        $skus[] = $item['条码'];
+                        //sku对应多个条码
+                        if (isset($skuMap[$item['条码']]))$skuMap[$item['SKU']][] = $item['条码'];
+                        else $skuMap[$item['条码']] = [$item['条码']];
+                    }
+                }
             }
-            foreach ($value as $i => $index){
-                if (!$items[$index]["SKU"]){
-                    array_push($errors, ($items[$index]["lineno"]) . " 行:条码未找到商品时SKU不得为空");
-                    unset($items[$index]);
-                    if ($i == count($value)-1) unset($commodities[$key]);
-                    continue;
+            $commoditiesTem = app('commodityService')->get(['owner_id'=>$owner->id, 'sku'=>$skus]);
+
+            if (count($commoditiesTem) > 0){
+                $barcodes = [];
+                $date = Carbon::now();
+                foreach ($commoditiesTem as $item){
+                    //对比本地与导入的存在商品中条码差异 补充数据库
+                    foreach (array_unique(array_diff($skuMap[$item->sku], $item->barcodes)) as $code){
+                        $barcodes[] = [
+                            'commodity_id' => $item->id,
+                            'code' => $code,
+                            'created_at' => $date,
+                        ];
+                        foreach ($commodities[$code] as $index){
+                            $items[$index]["commodity_id"] = $item->id;
+                            unset($items[$index]["SKU"]);
+                            unset($items[$index]["商品名称"]);
+                            unset($items[$index]["条码"]);
+                            unset($items[$index]["lineno"]);
+                        }
+                        unset($commodities[$code]);
+                    }
                 }
-                if (isset($skus[$items[$index]["SKU"]])) array_push($skus, $index);
-                else{
-                    $skus[$items[$index]["SKU"]] = [$index];
-                    array_push($skuParam,$items[$index]["SKU"]);
+                if (count($barcodes) > 0){
+                    $commodityBarcodeService->insert($barcodes);
+                    LogService::log(__METHOD__,"盘收导入补录条码",json_encode($barcodes));
                 }
             }
-        }
 
-        //使用货主+SKU获取商品ID,将条码补录
-        $barcodes = [];
-        /** @var CommodityService $commodityService */
-        $commodityService = app('commodityService');
-        if (count($skuParam) > 0)$commodities = $commodityService->get(["owner_id"=>$owner->id,"sku"=>$skuParam]);
-        foreach ($commodities as $commodity){
-            foreach ($skus[$commodity->sku] as $i => $index){
-                $items[$index]["commodity_id"] = $commodity->id;
-                if ($i == 0){
-                    array_push($barcodes,[
-                        "code" => $items[$index]["条码"],
-                        "commodity_id" => $commodity->id,
-                        "created_at" => date('Y-m-d H:i:s')
-                    ]);
+            //WMS与本地皆不存在的商品 录入为临时商品
+            if (count($commodities) > 0){
+                $createCommodities = [];
+                $skus = [];
+                $skuMap = [];
+                $date = Carbon::now();
+                foreach ($commodities as $arr){
+                    foreach ($arr as $index){
+                        $item = $items[$index];
+                        if ($item["SKU"]) $sku = $item["SKU"];
+                        else $sku = $item["条码"];
+
+                        if (isset($skuMap[$sku])) $skuMap[$sku][] = $index;
+                        else {
+                            $skuMap[$sku] = [$index];
+                            $skus = $sku;
+
+                            $commodity = [
+                                "name" => $item["商品名称"],
+                                "sku" => $sku,
+                                "owner_id" => $owner->id,
+                                "type" => "临时",
+                                "created_at" => $date,
+                            ];
+                            $createCommodities[] = $commodity;
+                        }
+                    }
                 }
-                unset($items[$index]["SKU"]);
-                unset($items[$index]["商品名称"]);
-                unset($items[$index]["条码"]);
-                unset($items[$index]["lineno"]);
-            }
-            unset($skus[$commodity->sku]);
-        }
-        if (count($barcodes) > 0) app('commodityBarcodeService')->insert($barcodes);
 
-        //未找到商品录入商品
-        $commodities = [];
-        $skuParam = [];
-        $barcodes = [];
-        foreach ($skus as $sku => $arr){
-            $data = &$items[$arr[0]];
-            array_push($commodities,[
-                "name" => $data["商品名称"],
-                "sku" => $data["SKU"],
-                "owner_id" => $owner->id,
-                "created_at" => date('Y-m-d H:i:s'),
-            ]);
-            array_push($skuParam, $sku);
-        }
-        if (count($commodities) > 0){
-            $commodityService->insert($commodities);
-            LogService::log(__METHOD__,"导入盘收任务-批量录入商品",json_encode($commodities,JSON_UNESCAPED_UNICODE));
-        }
-        if (count($skuParam) > 0)$commodities = $commodityService->get(["owner_id"=>$owner->id,"sku"=>$skuParam]);
-        foreach ($commodities as $commodity){
-            foreach ($skus[$commodity->sku] as $i => $index){
-                $items[$index]["commodity_id"] = $commodity->id;
-                if ($i == 0){
-                    array_push($barcodes,[
-                        "code" => $items[$index]["条码"],
-                        "commodity_id" => $commodity->id,
-                        "created_at" => date('Y-m-d H:i:s')
-                    ]);
+                //录入商品
+                if (count($createCommodities) > 0){
+                    /** @var CommodityService $commodityService */
+                    $commodityService = app('commodityService');
+                    $commodityService->insert($createCommodities);
+                    LogService::log(__METHOD__,"盘收录入临时商品",json_encode($createCommodities,JSON_UNESCAPED_UNICODE));
+
+                    //拿到商品ID录入条码
+                    $barcodes = [];
+                    $date = Carbon::now();
+                    $commoditiesTem = $commodityService->get(['owner_id'=>$owner->id, 'sku'=>$skus]);
+                    foreach ($commoditiesTem as $item){
+                        foreach ($skuMap[$item->sku] as $index){
+                            $barcodes[] = [
+                                'commodity_id' => $item->id,
+                                'code' => $items[$index]["条码"],
+                                'created_at' => $date,
+                            ];
+                            $items[$index]["commodity_id"] = $item->id;
+                            unset($items[$index]["SKU"]);
+                            unset($items[$index]["商品名称"]);
+                            unset($items[$index]["条码"]);
+                            unset($items[$index]["lineno"]);
+                        }
+                    }
+                    if (count($barcodes) > 0){
+                        $commodityBarcodeService->insert(array_unique($barcodes));
+                        LogService::log(__METHOD__,"盘收导入录入条码",json_encode($barcodes));
+                    }
                 }
-                unset($items[$index]["SKU"]);
-                unset($items[$index]["商品名称"]);
-                unset($items[$index]["条码"]);
-                unset($items[$index]["lineno"]);
             }
-            unset($skus[$commodity->sku]);
-        }
-        if (count($barcodes) > 0){
-            app('commodityBarcodeService')->insert($barcodes);
-            LogService::log(__METHOD__,"导入盘收任务-批量录入商品条码",json_encode($barcodes,JSON_UNESCAPED_UNICODE));
         }
 
         if (count($items) < 1){

+ 5 - 0
app/Services/CommodityBarcodeService.php

@@ -39,4 +39,9 @@ Class CommodityBarcodeService
         if (!$value)$value = $params;
         return CommodityBarcode::query()->firstOrCreate($params,$value);
     }
+
+    public function create(array $params)
+    {
+        return CommodityBarcode::query()->create($params);
+    }
 }

+ 21 - 6
app/Services/CommodityService.php

@@ -20,8 +20,18 @@ Class CommodityService
         return Commodity::query()->updateOrCreate($param);
     }
 
+    public function first(array $params, $with = null){
+        $commodity = Commodity::query();
+        if ($with)$commodity->with($with);
+        foreach ($params as $column => $value){
+            if (!is_array($value))$commodity->where($column,$value);
+            else $commodity->whereIn($column,$value);
+        }
+        return $commodity->first();
+    }
+
     public function get(array $params){
-        $query = Commodity::query();
+        $query = Commodity::query()->with('barcodes');
         if ($params["owner_id"] ?? false){
             $query->where("owner_id", $params["owner_id"]);
         }
@@ -137,10 +147,8 @@ Class CommodityService
     public function getOwnerCommodities(array $params){
         $query = Commodity::query();
         foreach ($params as $column => $value){
-            if (!is_array($value)){
-                $value = [$value];
-            }
-            $query->whereIn($column,$value);
+            if (!is_array($value)) $query->where($column,$value);
+            else $query->whereIn($column,$value);
         }
         return $query->get();
     }
@@ -163,8 +171,9 @@ Class CommodityService
         });
         return $query;
     }
-    public function ownerBarcodeSeekCommodityFirst(array $ownerParam, $barcode){
+    public function ownerBarcodeSeekCommodityFirst(array $ownerParam, $barcode, $with = null){
         $commodity = Commodity::query();
+        if ($with) $commodity->with($with);
         $commodity = $this->ownerBarcodeSeekCommodityQuery($commodity, $ownerParam, $barcode);
         return $commodity->first();
     }
@@ -296,4 +305,10 @@ Class CommodityService
             ->whereIn('sku',data_get($params,'*.sku'))
             ->get();
     }
+
+    public function createTemporaryCommodity(array $params)
+    {
+        $params["type"] = "临时";
+        return Commodity::query()->create($params);
+    }
 }