Bladeren bron

盘点--生成盘点任务时商品重复问题

haozi 5 jaren geleden
bovenliggende
commit
548367960b
2 gewijzigde bestanden met toevoegingen van 50 en 30 verwijderingen
  1. 14 11
      app/Services/InventoryAccountService.php
  2. 36 19
      resources/views/inventory/stockInventory/mission.blade.php

+ 14 - 11
app/Services/InventoryAccountService.php

@@ -4,6 +4,7 @@
 namespace App\Services;
 
 use App\Commodity;
+use App\Http\Controllers\CommodityController;
 use App\Http\Controllers\Controller;
 use App\InventoryAccount;
 use App\InventoryAccountMission;
@@ -240,20 +241,24 @@ class InventoryAccountService
         Controller::logS(__METHOD__,"创建盘点任务__".__FUNCTION__,json_encode($request),Auth::user()['id']);
         return $inventory;
     }
-
+    //同步商品信息
+    public function syncOwnerCommodities($ownerId){
+        $ownerCode=Owner::query()->where('id',$ownerId)->value('code');
+        $commodityController = new CommodityController();
+        $commodityController->syncOwnerCommodities($ownerId, $ownerCode, null,null);
+    }
     //创建盘点记录任务
     public function createInventoryAccountMissionRecord($ownerId,$inventoryAccountId,$wmsInventories){
-        ini_set('memory_limit','300M');
+        ini_set('memory_limit','1526M');
         $commodities=Commodity::query()
             ->select('id','owner_id','name','sku')
-            ->with('barcodes')
             ->where('owner_id',$ownerId)
-            ->whereNotNull(['sku','name'])
             ->get();
         $commoditiesArr=[];
         foreach ($commodities as $commodity){
             $commoditiesArr[$commodity['name'].'|'.$commodity['sku']]=$commodity;
         }
+        $commodityArrBarcode=[];
         $commodityArr=[];
         $inventoryAccountMissions=[];
         foreach ($wmsInventories as $wmsInventory){
@@ -264,6 +269,8 @@ class InventoryAccountService
                 $commodity->sku=$wmsInventory->产品编码;
                 $commodity->name=$wmsInventory->商品名称;
                 $commodity->save();
+                $commoditiesArr[$wmsInventory->商品名称.'|'.$wmsInventory->产品编码]=$commodity;
+                array_push($commodityArr,$commodity);
             }
             if ($wmsInventory->产品条码1){
                 $commodity->newBarcode($wmsInventory->产品条码1);
@@ -295,7 +302,7 @@ class InventoryAccountService
                     'barcode'=>$wmsInventory->产品条码3,
                 ];
             }
-            array_push($commodityArr,$arr);
+            array_push($commodityArrBarcode,$arr);
             if($wmsInventory->质量状态=='ZP') $quality='正品';
             if ($wmsInventory->质量状态=='CC') $quality='残次';
             if ($wmsInventory->质量状态=='XS') $quality='箱损';
@@ -321,7 +328,8 @@ class InventoryAccountService
 
         $inventoryAccountMissions=InventoryAccountMission::query()->insert($inventoryAccountMissions);
         if ($commodityArr){
-            Controller::logS(__METHOD__,"插入was中没有的商品信息__".__FUNCTION__,json_encode($commodityArr));
+            Controller::logS(__METHOD__,"插入was中商品信息__".__FUNCTION__,json_encode($commodityArr));
+            Controller::logS(__METHOD__,"插入was中商品信息的条码信息__".__FUNCTION__,json_encode($commodityArrBarcode));
         }
         Controller::logS(__METHOD__,"批量插入盘点记录__".__FUNCTION__,json_encode($inventoryAccountMissions));
 
@@ -337,11 +345,6 @@ class InventoryAccountService
             'inventoryId'=>$inventoryAccountId,
         ];
         Controller::logS(__METHOD__,"盘点__".__FUNCTION__,json_encode($request));
-//        $inventoryAccountMission=InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])->whereHas('commodity',function($query)use($barcode){
-//            $query->whereHas('barcodes',function($sql)use($barcode){
-//                $sql->where('code','=',$barcode);
-//            });
-//        })->where('location',$location)->where('inventory_account_id',$inventoryAccountId)->first();
         $inventoryAccountMission=InventoryAccountMission::with(['commodity.barcodes','stockInventoryPersons'])->find($id);
         return $inventoryAccountMission;
     }

+ 36 - 19
resources/views/inventory/stockInventory/mission.blade.php

@@ -11,11 +11,16 @@
         <form class="form-inline mt-2">
             <span class="form-inline ml-5">
                  <span class="btn btn-sm btn-outline-secondary tooltipTarget" @click="syncOwners">同步货主</span>
-                <select class="form-control form-control-sm tooltipTarget" name="owner_id" id="owner_id" style="width: 150px;position: relative" title="选择指定货主">
-                    <option value="">货主</option>
-                    <option v-for="owner in fakeOwners" :value="owner.id">@{{ owner.name }}</option>
-                </select>
-                <input placeholder="定位货主" id="ownerName" autocomplete="off" class="form-control form-control-sm tooltipTarget" style="width: 100px" @input="定位货主()" title="输入关键字定位货主">
+{{--                <select class="form-control form-control-sm tooltipTarget" name="owner_id" id="owner_id" style="width: 150px;position: relative" title="选择指定货主">--}}
+{{--                    <option value="">货主</option>--}}
+{{--                    <option v-for="owner in fakeOwners" :value="owner.id">@{{ owner.name }}</option>--}}
+{{--                </select>--}}
+{{--                <input placeholder="定位货主" id="ownerName" autocomplete="off" class="form-control form-control-sm tooltipTarget" style="width: 100px" @input="定位货主()" title="输入关键字定位货主">--}}
+                <select class="form-control form-control-sm tooltipTarget" name="owner_id" id="owner_id" style="width: 150px;position: relative" title="选择指定货主" v-model="owner_id">
+                                        <option value="">货主</option>
+                                        <option v-for="owner in owners" :value="owner.id">@{{ owner.name }}</option>
+                                    </select>
+                <input placeholder="定位货主" id="ownerName" autocomplete="off" @input="定位货主($event)" class="form-control form-control-sm tooltipTarget" style="width: 100px" title="输入关键字定位货主" >
             </span>
             <span class="form-inline">
                 <input type="date" @change="hasDateStart" class="form-control form-control-sm ml-5 tooltipTarget" name="date_start" id="date_start"  title="选择创建日期的开始时间" style="width: 150px">
@@ -120,6 +125,7 @@
                 // formData:{},
                 date_end:'',location:'',barcode:'', date_start:'',
                 fakeOwners:'',
+                owner_id:'',
             },
             mounted: function () {
                 $(".tooltipTarget").tooltip({'trigger': 'hover'});
@@ -205,10 +211,10 @@
                     let _this=this;
                     const date_end=document.getElementById('date_end').value;
                     const date_start=document.getElementById('date_start').value;
-                    const owner_id=$('#owner_id').val();
+                    //const owner_id=$('#owner_id').val();
+                    const owner_id=_this.owner_id;
                     const location=$('#location').val().trim();
                     const barcode=$('#barcode').val();
-                    //console.log(location)
                     if(owner_id===''){
                         tempTip.setDuration(2000);
                         tempTip.show('生成盘点任务失败'+'   '+'请先选择货主!');
@@ -303,21 +309,32 @@
                         tempTip.show('同步货主失败,网络链接错误!'+err);
                     })
                 },
-                定位货主(){
-                    let target = $('#ownerName').val();
-                    if(target === ''){
-                        this.fakeOwners = this.owners;
-                        $('#owner_id').attr('size','1');
-                    }else{
-                        this.fakeOwners = this.owners.filter(function(map){
-                            return map.name.includes(target) ;
-                        })
-                        if (this.fakeOwners.length>=1){
-                            //$("#owner_id option[value='"+this.fakeOwners[0].id+"']").attr("selected","selected");
-                            $('#owner_id').attr('size','2');
+                定位货主(e){
+                    this.owners.some(owner => {
+                        if (owner.name.indexOf(e.target.value) !== -1){
+                            this.owner_id = owner.id;
+                            return true;
                         }
+                    });
+                    if (e.target.value=== ''||e.target.value===null||e.target.value===undefined) {
+                        this.owner_id='';
                     }
                 },
+                // 定位货主(){
+                //     let target = $('#ownerName').val();
+                //     if(target === ''){
+                //         this.fakeOwners = this.owners;
+                //         $('#owner_id').attr('size','1');
+                //     }else{
+                //         this.fakeOwners = this.owners.filter(function(map){
+                //             return map.name.includes(target) ;
+                //         })
+                //         if (this.fakeOwners.length>=1){
+                //             //$("#owner_id option[value='"+this.fakeOwners[0].id+"']").attr("selected","selected");
+                //             $('#owner_id').attr('size','2');
+                //         }
+                //     }
+                // },
                 hasDateStart(){
                     this.date_start=document.getElementById('date_start').value;
                 },