LD 5 лет назад
Родитель
Сommit
61bdc4d85a

+ 40 - 0
app/Http/Controllers/InventoryCompareController.php

@@ -2,8 +2,14 @@
 
 namespace App\Http\Controllers;
 
+use App\Imports\InventoryCompareImport;
 use App\InventoryCompare;
+use App\Services\OwnerService;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Gate;
+use Maatwebsite\Excel\Facades\Excel;
 
 class InventoryCompareController extends Controller
 {
@@ -82,4 +88,38 @@ class InventoryCompareController extends Controller
     {
         //
     }
+    function inventoryCompare(Request $request,OwnerService $ownerService){
+        if (!Gate::allows('库存管理-库存-库存对比')){return redirect(url('/')); }
+        $owners = $ownerService->getSelection();
+        $inventoryCompares=app('InventoryCompareService')->getInventoryCompare($request->all());
+        $param = $request->input();
+        return view('inventory.statement.inventoryCompare',compact('owners','inventoryCompares','param'));
+    }
+    function importExcel(Request $request){
+        if (!Gate::allows('库存管理-库存-库存对比')){return redirect(url('/')); }
+        $owner_id=$request->owner_id;
+        if(!$owner_id) return '<h1 class="text-danger">导入Excel失败<br><p style="color: red">您还未选择相应货主!</p></h1>';
+        $fileSuffix = $request->file()['file']->getClientOriginalExtension();
+        if (in_array($fileSuffix, ['xlsx', 'xlsm', 'xltx', 'xltm', 'xls', 'xlt', 'ods', 'ots', 'slk', 'xml', 'gnumeric', 'htm', 'html', 'csv', 'tsv','txt'])) {
+            ini_set('max_execution_time', 2100);
+            ini_set('memory_limit', '512M');
+            $extension = $request->file()['file']->getClientOriginalExtension();
+            $extension[0] = strtoupper($extension[0]);
+            Excel::import(new InventoryCompareImport($owner_id), $request->file('file')->path(), null, $extension);
+            if (Cache::has('error')) {
+                return '<h1 class="text-danger">导入Excel失败<br><p style="color: red">' . Cache::pull('error') . '</p></h1>';
+            } else {
+                $exception = Cache::get('exception');
+                $a = '';
+                for ($i = 0; $i < count($exception); $i++) {
+                    $a .= implode(',', $exception[$i]) . '&#10';
+                };
+                $this->log(__METHOD__, __FUNCTION__, json_encode($request->toArray()), Auth::user()['id']);
+                return '<h1 class="text-danger">导入Excel成功<br><textarea style="width: 50%;height: 50%">' . $a . '</textarea></h1>';
+
+            }
+        } else {
+            return '<h1 class="text-danger">失败<br><p style="color: red">不支持该文件类型</p></h1>';
+        }
+    }
 }

+ 0 - 34
app/Http/Controllers/InventoryController.php

@@ -274,38 +274,4 @@ class InventoryController extends Controller
         return ['success'=>true,'data'=>$loggingOwner->owner_id];
     }
 
-    function inventoryCompare(Request $request,OwnerService $ownerService){
-        if (!Gate::allows('库存管理-库存-库存对比')){return redirect(url('/')); }
-        $owners = $ownerService->getSelection();
-        $inventoryCompares=app('inventoryCompareService')->getInventoryCompare($request->all());
-        $param = $request->input();
-        return view('inventory.statement.inventoryCompare',compact('owners','inventoryCompares','param'));
-    }
-    function importExcel(Request $request){
-        if (!Gate::allows('库存管理-库存-库存对比')){return redirect(url('/')); }
-        $owner_id=$request->owner_id;
-        if(!$owner_id) return '<h1 class="text-danger">导入Excel失败<br><p style="color: red">您还未选择相应货主!</p></h1>';
-        $fileSuffix = $request->file()['file']->getClientOriginalExtension();
-        if (in_array($fileSuffix, ['xlsx', 'xlsm', 'xltx', 'xltm', 'xls', 'xlt', 'ods', 'ots', 'slk', 'xml', 'gnumeric', 'htm', 'html', 'csv', 'tsv','txt'])) {
-            ini_set('max_execution_time', 2100);
-            ini_set('memory_limit', '512M');
-            $extension = $request->file()['file']->getClientOriginalExtension();
-            $extension[0] = strtoupper($extension[0]);
-            Excel::import(new InventoryCompareImport($owner_id), $request->file('file')->path(), null, $extension);
-            if (Cache::has('error')) {
-                return '<h1 class="text-danger">导入Excel失败<br><p style="color: red">' . Cache::pull('error') . '</p></h1>';
-            } else {
-                $exception = Cache::get('exception');
-                $a = '';
-                for ($i = 0; $i < count($exception); $i++) {
-                    $a .= implode(',', $exception[$i]) . '&#10';
-                };
-                $this->log(__METHOD__, __FUNCTION__, json_encode($request->toArray()), Auth::user()['id']);
-                return '<h1 class="text-danger">导入Excel成功<br><textarea style="width: 50%;height: 50%">' . $a . '</textarea></h1>';
-
-            }
-        } else {
-            return '<h1 class="text-danger">失败<br><p style="color: red">不支持该文件类型</p></h1>';
-        }
-    }
 }

+ 1 - 1
app/Http/Controllers/OrderIssueController.php

@@ -449,7 +449,7 @@ class OrderIssueController extends Controller
                 return ['success' => true, 'order' => $order, 'rejectedBill' => $rejectedBill];
             }
         } else {
-            return ['success' => true, 'meg' => '没有对应的退回单号,但仍可以录入'];
+            return ['success' => true, 'meg' => '没有对应的退回单号,不与WMS同步'];
         }
     }
 

+ 6 - 2
app/Http/Controllers/TestController.php

@@ -23,6 +23,7 @@ use App\ProcessStatistic;
 use App\Rejected;
 use App\RejectedBill;
 use App\RejectedBillItem;
+use App\Services\InventoryCompareService;
 use App\Unit;
 use App\UploadFile;
 use App\User;
@@ -90,8 +91,11 @@ class TestController extends Controller
     { //x        $packagesBatch=Package::where('batch_number',$batch_number)->first();
 
 
-        $hasSku = OracleBasSKU::query()->where('sku', "2140100024")->where('customerid', "ONKYO")->first();
-        dd($hasSku);
+        $inventoryCompareService = new InventoryCompareService();
+        echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
+        echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
+        echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
+        echo ($inventoryCompareService)->getCreatingMissionCode('安桥主品');
 
     }
 

+ 3 - 1
app/Imports/InventoryCompareImport.php

@@ -82,7 +82,9 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
                     $owner=Owner::find($this->owner_id);
                     $commodityInWMS = OracleBasSKU::query()->where('sku', "$row[$skuName]")->where('customerid', "$owner->code")->first();
                     $commodity=Commodity::query()->firstOrCreate(['owner_id'=>$this->owner_id,'sku'=>$row[$skuName],'name'=>$commodityInWMS['descr_c'],'length'=>$commodityInWMS['skulength'],'width'=>$commodityInWMS['skuwidth'],'height'=>$commodityInWMS['skuhigh'],'volumn'=>$commodityInWMS['skulength']*$commodityInWMS['skuwidth']*$commodityInWMS['skuhigh']]);
-                    $commodity->newBarcode($commodityInWMS['alternate_sku1']);
+                    $barcode = $commodityInWMS['alternate_sku1']??$commodityInWMS['alternate_sku2']??$commodityInWMS['alternate_sku3'];
+                    if($barcode)
+                        $commodity->newBarcode($barcode);
                 }
                 if (!$commodityInWMS){
                     array_push($exception, ['该货主下不存在产品编号:'.$row[$skuName]]);

+ 2 - 0
app/Providers/AppServiceProvider.php

@@ -3,6 +3,7 @@
 namespace App\Providers;
 
 use App\Http\Controllers\Controller;
+use App\Services\InventoryCompareService;
 use App\Services\OrderIssuePerformanceService;
 use Illuminate\Queue\Events\JobFailed;
 use Illuminate\Support\Facades\Queue;
@@ -23,6 +24,7 @@ class AppServiceProvider extends ServiceProvider
     {
         //
         app()->singleton('orderIssuePerformanceService',OrderIssuePerformanceService::class);
+        app()->singleton('InventoryCompareService',InventoryCompareService::class);
     }
 
     /**

+ 21 - 25
app/Services/InventoryCompareService.php

@@ -9,12 +9,14 @@ use App\InventoryCompare;
 use App\Owner;
 use App\Services\common\QueryService;
 use Carbon\Carbon;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Overtrue\Pinyin\Pinyin;
 use Ramsey\Uuid\Uuid;
 
 class InventoryCompareService
 {
+    static private $missionCode;
     private function conditionQuery($SKU,$LotAtt05,$descr_c){
         $sql='select * from (select result.*,rownum rn from (';
         $sql.=' select customer.Descr_C as 货主,storeStatus.CUSTOMERID 客户,storeStatus.LocationID 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
@@ -37,10 +39,19 @@ class InventoryCompareService
     }
 
 
-
+    public function getCreatingMissionCode($ownerName=''){
+        if(self::$missionCode)return self::$missionCode;
+        $sequence=Cache::get('InventoryCompareMissionSequence');
+        if(!$sequence||$sequence>998)$sequence=0;
+        $sequence++;
+        Cache::put('InventoryCompareMissionSequence',$sequence,300);
+        $pinyin=new Pinyin();
+        $ownerFirstLetter=strtoupper($pinyin->abbr($ownerName));
+        self::$missionCode= $ownerFirstLetter.date ("ymd").'KCBD'.str_pad($sequence,3,"0",STR_PAD_LEFT);
+        return self::$missionCode;
+    }
     public function createInventoryCompare_underImport($SKU, $customLocation, $amount, $ownerId){
         $owner=Owner::find($ownerId);
-        $ownerName=$owner['name'];
         $request=[
             '产品编码'=>$SKU,
             '属性仓'=>$customLocation,
@@ -51,8 +62,7 @@ class InventoryCompareService
         $ccAmount=0;
         $amountTotal=0;
 
-        $pinyin=new Pinyin();
-        $owner=strtoupper($pinyin->abbr($ownerName));
+        $creatingMissionCode = $this->getCreatingMissionCode($owner['name']);
         $commodityId=Commodity::where('sku',$SKU)->where('owner_id',$ownerId)->value('id');
         $inventoryCompare=new InventoryCompare();
         $inventoryCompare->owner_id=$ownerId;
@@ -64,11 +74,9 @@ class InventoryCompareService
         $inventoryCompare->amount_in_sys=0;
         $inventoryCompare->amount_in_compare=$amount;
         $inventoryCompare->differ=0-$amount;
+        $inventoryCompare->mission_code= $creatingMissionCode;
         $inventoryCompare->save();
-        Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
-        $mission_code =$owner.date ("ymd").'KCBD'.str_pad($inventoryCompare['id']>99999?$inventoryCompare['id']%99999:$inventoryCompare['id'],4,"0",STR_PAD_LEFT);
-        $inventoryCompare->update(['mission_code' => $mission_code ]);
-        Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($mission_code));
+        Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($creatingMissionCode));
         return $inventoryCompare;
     }
     public function createInventoryCompare($SKU,$LotAtt05,$amount,$ownerId){
@@ -102,8 +110,7 @@ class InventoryCompareService
             }
         }
         $unknownStatusAmount=$amountTotal-$ccAmount-$zpAmount;
-        $pinyin=new Pinyin();
-        $owner=strtoupper($pinyin->abbr($ownerName));
+        $creatingMissionCode = $this->getCreatingMissionCode($ownerName);
         $commodityId=Commodity::where('sku',$SKU)->where('owner_id',$ownerId)->value('id');
         $inventoryCompare=new InventoryCompare();
         $inventoryCompare->owner_id=$ownerId;
@@ -111,35 +118,24 @@ class InventoryCompareService
         $inventoryCompare->mission_code=Uuid::uuid1();
         $inventoryCompare->custom_location=$LotAtt05;
         $inventoryCompare->created_at=Carbon::now()->format('Y-m-d H:i:s');
+        $inventoryCompare->mission_code=$creatingMissionCode;
         if ($zpAmount!=0){
             $inventoryCompare->quality='正品';
             $inventoryCompare->amount_in_sys=$zpAmount;
             $inventoryCompare->amount_in_compare=$amount;
             $inventoryCompare->differ=$zpAmount-$amount;
-            $inventoryCompare->save();
-            Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
-            $mission_code =$owner.date ("ymd").'KCBD'.str_pad($inventoryCompare['id']>99999?$inventoryCompare['id']%99999:$inventoryCompare['id'],4,"0",STR_PAD_LEFT);
-            $inventoryCompare->update(['mission_code' => $mission_code ]);
-            Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($mission_code));
         }
         if ($ccAmount!=0){
             $inventoryCompare->quality='次品';
             $inventoryCompare['amount_in_sys']=$ccAmount;
-            $inventoryCompare->save();
-            Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
-            $mission_code =$owner.date ("ymd").'KCBD'.str_pad($inventoryCompare['id']>99999?$inventoryCompare['id']%99999:$inventoryCompare['id'],4,"0",STR_PAD_LEFT);
-            $inventoryCompare->update(['mission_code' => $mission_code ]);
-            Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($mission_code));
         }
         if ($unknownStatusAmount!=0){
             $inventoryCompare->quality='未知';
             $inventoryCompare->amount_in_sys=$unknownStatusAmount;
-            $inventoryCompare->save();
-            Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
-            $mission_code =$owner.date ("ymd").'KCBD'.str_pad($inventoryCompare['id']>99999?$inventoryCompare['id']%99999:$inventoryCompare['id'],4,"0",STR_PAD_LEFT);
-            $inventoryCompare->update(['mission_code' => $mission_code ]);
-            Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($mission_code));
         }
+        $inventoryCompare->save();
+        Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
+        Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($creatingMissionCode));
         return $inventoryCompare;
     }
 

+ 2 - 2
routes/web.php

@@ -322,9 +322,9 @@ Route::group(['prefix'=>'inventory'],function (){
     Route::post('searchStockInventoryRecord','InventoryAccountController@searchStockInventoryRecord');
 
     //库存对比
-    Route::get('statement/inventoryCompare','InventoryController@inventoryCompare');
+    Route::get('statement/inventoryCompare','InventoryCompareController@inventoryCompare');
     //库存对比批量导入
-    Route::post('inventoryCompare/import/excel','InventoryController@importExcel');
+    Route::post('inventoryCompare/import/excel','InventoryCompareController@importExcel');
 
     Route::post('statement/dailyLog/addLoggingOwner','InventoryController@addLoggingOwner');
 });