Forráskód Böngészése

分拔墙的条码寻货重构

LD 5 éve
szülő
commit
0e5c2c369b

+ 0 - 41
app/Commodity.php

@@ -36,48 +36,7 @@ class Commodity extends Model
         return $this->owner['code']??'';
     }
 
-    static function newCommodityBy_BarcodeOwnerIdNameSku($barcode,$ownerId,$name,$sku){
-        $barcodes=rtrim($barcode,',');
-        $barcodes=explode(',',$barcodes);
-        foreach ($barcodes as $k=>$barcode){
-            if(!trim($barcode)) unset($barcodes[$k]);
-        }
-
-        $commodities=[];
-        foreach ($barcodes as $barcode){
-            if(!trim($barcode))continue;
-            $commodity=Commodity::whereHas('barcodes', function (Builder $query)use($barcode){
-                $query->where('code',$barcode);
-            })->where('name',$name)->where('owner_id',$ownerId)->first();
-            if($commodity)$commodities[]=$commodity;
-        }
-
-        if(count($barcodes)==count($commodities)&&count($commodities)>0){//筛选掉仅有一个条码相等的。
-            $commodity=$commodities[0];
-        }else{
-            $commodity=null;
-        }
 
-        if(!$commodity){
-            $commodity=new Commodity(['name'=>$name,'sku'=>$sku,'owner_id'=>$ownerId]);
-            $commodity->save();
-        }else{
-            if(!isset($commodity['name'])||(!isset($commodity['sku'])||$sku)){
-                $commodity['name']=$name;
-                $commodity['sku']=$sku;
-                $commodity->save();
-            }
-        }
-        foreach ($barcodes as $barcode){
-            if(!trim($barcode))continue;
-            $commodityBarcode=CommodityBarcode::where('code',$barcode)->where('commodity_id',$commodity['id'])->first();
-            if(!$commodityBarcode){
-                $commodityBarcode=new CommodityBarcode(['code'=>$barcode,'commodity_id'=>$commodity['id']]);
-                $commodityBarcode->save();
-            }
-        }
-        return $commodity;
-    }
 
     public function newBarcode($barcode){
         $barcodeModel = $this->barcodes()->where('code', $barcode)->first();

+ 6 - 1
app/Http/Controllers/RejectedBillController.php

@@ -150,9 +150,14 @@ class RejectedBillController extends Controller
     {
         $mobileShouldBeRequired = 'required';
         $logistic=Logistic::find($data['id_logistic_return']);
-        if($logistic){if(strstr($logistic['name'],'顺丰')){
+        if($logistic){if(
+            strstr($logistic['name'],'顺丰')
+        ){
             $mobileShouldBeRequired = 'nullable';
         }}
+        if($data['id_owner']=='4'){
+            $mobileShouldBeRequired = 'nullable';
+        }
         $mobileDigits = '';
         if($data['mobile_sender']&&$data['mobile_sender'][0]=='1'){
             $mobileDigits = 'digits:11';

+ 1 - 0
app/Http/Controllers/RejectedBillItemController.php

@@ -363,6 +363,7 @@ class RejectedBillItemController extends Controller
         }
         $rejectedBillItem = RejectedBillItem::find($request->input('id'));
         $rejectedBillItem->forceDelete();
+        app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($rejectedBillItem),Auth::user()['id']);
         return ['success'=>'true','id'=>$request->input('id')];
     }
 

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 5 - 0
app/Http/Controllers/TestController.php


+ 19 - 15
app/Http/Controllers/api/thirdPart/flux/SortingController.php

@@ -10,7 +10,8 @@ use App\Order;
 use App\OrderBin;
 use App\OrderCommodity;
 use App\Owner;
-use App\Services\OrderService;
+//use App\Services\OrderService;
+use App\Services\CommodityService;
 use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Validator;
@@ -19,11 +20,11 @@ use Zttp\Zttp;
 class SortingController extends Controller
 {
 
-    /** @var OrderService orderService */
-    private $orderService;
-    public function __construct(){
-        $this->orderService=app('OrderService');
-    }
+//    /** @var OrderService orderService */
+//    private $orderService;
+//    public function __construct(){
+//        $this->orderService=app('OrderService');
+//    }
 
     /**
      * 新增被通知的波次列表(一个以上的波次),并且保存在本地数据库,供get波次使用
@@ -44,12 +45,14 @@ class SortingController extends Controller
         $requestBatches = $requestArr['request']?? '';
         foreach ($requestBatches as $requestBatch){
             $requestBatch['edittime']&&strpos(trim($requestBatch['edittime']),' ')?$editTimeFormat='Y-m-d H:i:s':$editTimeFormat='YmdHis';
-            $batch=new Batch([
-                'code' => $requestBatch['waveno'],
-                'wms_type' => $requestBatch['batch_type']??'',
-                'wms_status' => $requestBatch['docstatus']??'',
-                'status' => '未处理',
-                'wms_created_at' => $requestBatch['edittime']?Carbon::createFromFormat($editTimeFormat,$requestBatch['edittime']):'',
+            $batch=Batch::query()->firstOrCreate(['code' => $requestBatch['waveno']]);
+            if(!$batch)$batch=new Batch();
+            $batch->fill([
+                    'code' => $requestBatch['waveno'],
+                    'wms_type' => $requestBatch['batch_type']??'',
+                    'wms_status' => $requestBatch['docstatus']??'',
+                    'status' => '未处理',
+                    'wms_created_at' => $requestBatch['edittime']?Carbon::createFromFormat($editTimeFormat,$requestBatch['edittime']):'',
             ]);
             $batch->save();
             $oracleAlloactions=OracleActAllocationDetails::query()->where('waveno',$requestBatch['waveno'])->get();
@@ -57,7 +60,6 @@ class SortingController extends Controller
                 $owner=Owner::query()->where('code',$requestOrder['customerid'])->first();
                 $order=Order::query()->where('code',$requestOrder['docno'])->first();
                 if(!$order){
-                    $this->orderService->
                     $order=new Order([
                         'batch_id' => $batch['id'],
                         'code' => $requestOrder['docno'],
@@ -80,7 +82,9 @@ class SortingController extends Controller
                     $orderCommodity=OrderCommodity::query()
                         ->where('order_id',$order['id'])->where('wms_ptltaskid',$requestBarcode['ptltaskid'])->first();
                     if(!$orderCommodity){
-                        $commodity=Commodity::newCommodityBy_BarcodeOwnerIdNameSku($requestBarcode['alternate_sku1'],$owner['id'],$requestBarcode['descr_c'],$requestBarcode['sku']);
+                        /** @var CommodityService $commodityService */
+                        $commodityService=app('CommodityService');
+                        $commodity=$commodityService->syncBarcodes($requestBarcode['alternate_sku1'],$owner['id'],$requestBarcode['sku']);
                         $orderCommodity = new OrderCommodity([
                             'order_id' => $order['id'],
                             'commodity_id' => $commodity['id'],
@@ -103,7 +107,7 @@ class SortingController extends Controller
     {
         return Validator::make($data, [
             'request' => ['required', 'array', 'min:1'],
-            'request.*.waveno' => ['required', 'string', 'max:191','unique:batches,code'],
+            'request.*.waveno' => ['required', 'string', 'max:191'],
             'request.*.taskprocess' => ['nullable', 'string', 'max:191'],
             'request.*.edittime' => ['nullable', 'string', 'max:191'],
             'request.*.batch_type' => ['nullable', 'string', 'max:191'],

+ 29 - 21
app/Http/Controllers/api/thirdPart/weight/PackageController.php

@@ -226,10 +226,14 @@ class PackageController extends Controller
                 $logisticNumberController = new LogisticNumberFeatureController();
                 if (!$package->order){
                     $package->order = new Order();
-                }
-                if (!$package->order->logistic){
-                    $package->order->logistic = $logisticNumberController->getLogisticByFeatures($package->logistic_number);
-                    $package->order->save();
+                    $logistic=$logisticNumberController->getLogisticByFeatures($package->logistic_number);
+                    $package->order->logistic = $logistic;
+                }else{
+                    if(!$package->order->logistic){
+                        $logistic=$logisticNumberController->getLogisticByFeatures($package->logistic_number);
+                        $package->order->logistic_id = $logistic['id'];
+                        $package->order->save();
+                    }
                 }
             }catch (\Exception $e){
                 $response=["msg"=>"称重下发修改时发生错误!".json_encode($e),"code"=>500,"data"=>null];
@@ -261,18 +265,22 @@ class PackageController extends Controller
             $package->fetchAllFromOracle();
             $package->fetchPaperBox();
             try{
+                $package->save();
                 $package->load(['order'=>function($query){
                     $query->with('owner','logistic');
                 },'paperBox','measuringMachine']);
                 $logisticNumberController = new LogisticNumberFeatureController();
                 if (!$package->order){
                     $package->order = new Order();
+                    $logistic=$logisticNumberController->getLogisticByFeatures($package->logistic_number);
+                    $package->order->logistic = $logistic;
+                }else{
+                    if(!$package->order->logistic){
+                        $logistic=$logisticNumberController->getLogisticByFeatures($package->logistic_number);
+                        $package->order->logistic_id = $logistic['id'];
+                        $package->order->save();
+                    }
                 }
-                if (!$package->order->logistic){
-                    $package->order->logistic = $logisticNumberController->getLogisticByFeatures($package->logistic_number);
-                    $package->order->save();
-                }
-                $package->save();
             }catch (\Exception $e){
                 $response=["msg"=>$e->getMessage(),"code"=>500,"data"=>$e->getTraceAsString()];
                 app('LogService')->log(__METHOD__,'weightApi(ERROR)'.__FUNCTION__,json_encode($request).'||'.json_encode($response).'||'.$e->getTraceAsString(),null);
@@ -289,18 +297,18 @@ class PackageController extends Controller
         }
         if(!empty($package->order))
             Waybill::setWeightByOrderCode($package->order->code,$package->weight);
-            event(new WeighedEvent($package));
-            $response=["msg"=>"保存成功",
-                "code"=>200,
-                "data"=>true,
-                "serverMsg"=>null,
-                "requestor"=>[
-                    "requestor"=>"1",
-                    "eventCode"=>"0",
-                    "reqDate"=>$reqDate,
-                    "resDate"=>Carbon::now()]
-            ];
-            app('LogService')->log(__METHOD__,__FUNCTION__,"下发写入包裹成功:".json_encode($request).'|'.json_encode($response),null);
+        event(new WeighedEvent($package));
+        $response=["msg"=>"保存成功",
+            "code"=>200,
+            "data"=>true,
+            "serverMsg"=>null,
+            "requestor"=>[
+                "requestor"=>"1",
+                "eventCode"=>"0",
+                "reqDate"=>$reqDate,
+                "resDate"=>Carbon::now()]
+        ];
+        app('LogService')->log(__METHOD__,__FUNCTION__,"下发写入包裹成功:".json_encode($request).'|'.json_encode($response),null);
         return json_encode($response,JSON_UNESCAPED_UNICODE);
     }
 

+ 4 - 0
app/Order.php

@@ -28,6 +28,10 @@ class Order extends Model
         'amount',
         'commodityPackages'
     ];
+    public function cancel(){
+        $this['status'] = '取消';
+        $this->update();
+    }
 
     public function logistic()
     {

+ 29 - 0
app/Services/CommodityBarcodeService.php

@@ -3,6 +3,7 @@
 namespace App\Services;
 
 use App\CommodityBarcode;
+use Illuminate\Support\Collection;
 
 Class CommodityBarcodeService
 {
@@ -44,4 +45,32 @@ Class CommodityBarcodeService
     {
         return CommodityBarcode::query()->create($params);
     }
+
+    /**
+     * @param array $commoditiesAndBarcodesPacks 格式:[['commodity_id'=>id, barcodes=[str,str,str]], [......]]
+     * @return bool
+     */
+    public function insertMany_onCommodities(array $commoditiesAndBarcodesPacks)
+    {
+        $commodityBarcodes=[];
+        foreach ($commoditiesAndBarcodesPacks as $commoditiesAndBarcodesPack){
+            $commodity_id=$commoditiesAndBarcodesPack['commodity_id'];
+            $barcodes=$commoditiesAndBarcodesPack['barcodes'];
+            foreach ($barcodes as $barcode){
+                $commodityBarcodes[]=[
+                    'commodity_id'=>$commodity_id,
+                    'code'=>$barcode,
+                ];
+            }
+        }
+        if(empty($commodityBarcodes))return false;
+        return CommodityBarcode::query()->insert($commodityBarcodes);
+    }
+    public function destroyCollections(Collection $commodityBarcodes)
+    {
+        $ids=$commodityBarcodes->map(function($commodityBarcode){
+            return $commodityBarcode['id'];
+        });
+        return CommodityBarcode::destroy($ids);
+    }
 }

+ 45 - 1
app/Services/CommodityService.php

@@ -3,15 +3,17 @@
 namespace App\Services;
 
 use App\Commodity;
+use App\CommodityBarcode;
 use App\OracleBasSKU;
 use App\Owner;
 use App\Services\common\BatchUpdateService;
 use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
 
 Class CommodityService
 {
-    public function firstOrCreate($param,$column = null){
+    public function firstOrCreate($param,$column = null):Commodity{
         if ($column) return Commodity::query()->firstOrCreate($param,$column);
         return Commodity::query()->firstOrCreate($param);
     }
@@ -214,4 +216,46 @@ Class CommodityService
         $params["type"] = "临时";
         return Commodity::query()->create($params);
     }
+
+
+
+    public function syncBarcodes($barcodesStr,$ownerId,$sku):Commodity
+    {
+        $barcodes=(function()use($barcodesStr){
+            $barcodes=rtrim($barcodesStr,',');
+            $barcodes=explode(',',$barcodes);
+            foreach ($barcodes as $k=>$barcode){
+                if(!trim($barcode)) unset($barcodes[$k]);
+            }
+            return $barcodes;
+        })();
+        $commodity=$this->firstOrCreate(['owner_id'=>$ownerId,'sku'=>$sku]);
+        $commodityBarcodes=$commodity['barcodes']??new Collection();
+
+
+        /** @var CommodityBarcodeService $commodityBarcodeService */
+        $commodityBarcodeService=app('CommodityBarcodeService');
+        $redundantCommodityBarcodes=new Collection();
+        foreach($commodityBarcodes as $commodityBarcode){//清除数组中 已经在商品有的条码,清除商品条码中,不在数组中的条码
+            $hasMatch=false;
+            for($i=0;$i<count($barcodes);$i++){
+                if($barcodes[$i]==$commodityBarcode['code']){
+                    $hasMatch=true;
+                    unset($barcodes[$i]);
+                    break;
+                }
+            }
+            if(!$hasMatch){
+                $redundantCommodityBarcodes->push($commodityBarcode);
+            }
+        }
+        if(!empty($redundantCommodityBarcodes)){
+            $commodityBarcodeService->destroyCollections($redundantCommodityBarcodes);
+        }
+        if(!empty($barcodes)){
+            $commodityBarcodeService->insertMany_onCommodities([['commodity_id'=>$commodity['id'],'barcodes'=>$barcodes]]);
+        }
+        return $commodity;
+    }
+
 }

+ 1 - 5
public/t.php

@@ -1,7 +1,3 @@
 <?php
 
-
-$str = '货号:yw2020110877入正品仓';
-$result=[];
-preg_match("/[a-zA-Z]{0,5}\d{6,20}/", $str, $result);
-var_dump($result);
+echo ($a=3);

+ 1 - 1
resources/views/inventory/stockInventory/mission.blade.php

@@ -77,7 +77,7 @@
                     <td >@{{ inventory.total }}</td>
                     <td >@{{ inventory.processed }}</td>
                     <td >@{{ inventory.surplus }}</td>
-                    <td >@{{ inventory.ignored }}</td>
+                    <td >@{{ inventory.ignored?inventory.ignored:0 }}</td>
                     <td>@{{ inventory.difference }}</td>
                     <td>@{{ inventory.returned }}</td>
                     <td v-if="inventory.processed">@{{ inventory.processed }}/@{{ inventory.total }}</td>

+ 0 - 0
tests/Services/CacheService/GetOrExecuteTest/GetOrExecuteTest.php → tests/Services/CacheService/GetOrExecuteTest.php


+ 60 - 0
tests/Services/CommodityBarcodeService/DestroyTest.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace Tests\Services\CacheService\GetOrExecuteTest;
+
+use App\Commodity;
+use App\CommodityBarcode;
+use App\Services\CacheService;
+use App\Services\CommodityBarcodeService;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Cache;
+use Tests\TestCase;
+
+class InsertMany_onCommoditiesTest extends TestCase
+{
+
+    /** @var CommodityBarcodeService $service */
+    public $service;
+    public $data=[];
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('CommodityBarcodeService');
+        ($this->data['commodity']=(new Commodity()))->save();
+        $this->data['barcodes']=['A1','B1','C2'];
+        $inserts=(function(){
+            $targets=[];
+            foreach ($this->data['barcodes'] as $barcode) {
+                $targets[]=['commodity_id'=>$this->data['commodity']['id'],'code'=>$barcode];
+            }
+            return $targets;
+        })();
+        CommodityBarcode::query()->insert($inserts);
+        $this->data['commodityBarcodes']=CommodityBarcode::query()
+            ->where('commodity_id',$this->data['commodity']['id'])
+            ->whereIn('code',$this->data['barcodes'])
+            ->get();
+    }
+
+    public function testDeleted(){
+        $this->assertGreaterThan(0,$this->data['commodityBarcodes']->count());
+        $destroyIds = $this->data['commodityBarcodes']->map(function ($commodityBarcode) {
+            return $commodityBarcode['id'];
+        });
+        $commodityBarcodes = CommodityBarcode::query()->whereIn('id', $destroyIds)->get();
+        $this->service->destroyCollections($commodityBarcodes);
+
+        $commodityBarcodesResult = CommodityBarcode::query()->whereIn('id', $destroyIds)->get();
+        $this->assertEquals(0, $commodityBarcodesResult->count());
+    }
+
+
+    public function tearDown(): void
+    {
+        $this->data['commodity']->delete();
+        CommodityBarcode::destroy($this->data['commodityBarcodes']->map(function ($commodityBarcode){
+            return $commodityBarcode['id'];
+        }));
+        parent::tearDown();
+    }
+}

+ 65 - 0
tests/Services/CommodityBarcodeService/InsertMany_onCommoditiesTest.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace Tests\Services\CacheService\GetOrExecuteTest;
+
+use App\Commodity;
+use App\CommodityBarcode;
+use App\Services\CacheService;
+use App\Services\CommodityBarcodeService;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Cache;
+use Tests\TestCase;
+
+class InsertMany_onCommoditiesTest extends TestCase
+{
+
+    /** @var CommodityBarcodeService $service */
+    public $service;
+    public $data=[];
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('CommodityBarcodeService');
+        ($this->data['commodity']=(new Commodity()))->save();
+        $this->data['barcodes']=['A1','B1','C2'];
+        $this->data['commodityBarcodes']=new Collection();
+    }
+
+    public function testInsert(){
+        $inputs=[
+            'commodity_id'=>$this->data['commodity']['id'],
+            'barcodes'=>$this->data['barcodes']
+        ];
+        $this->service->insertMany_onCommodities([$inputs]);
+        $this->data['commodityBarcodes']=CommodityBarcode::query()
+            ->where('commodity_id',$this->data['commodity']['id'])
+            ->whereIn('code',$this->data['barcodes'])
+            ->get();
+        $resultArr=$this->data['commodityBarcodes']->map(function ($commodityBarcode){
+            return [$commodityBarcode['commodity_id'],$commodityBarcode['code']];
+        });
+        $expectArr = (function () {
+            $arr=[];
+            foreach ($this->data['barcodes'] as $barcode) {
+                $arr[]=[
+                    $this->data['commodity']['id'],$barcode
+                ];
+            }
+            return $arr;
+        })();
+        $this->assertEquals(json_encode($expectArr),json_encode($resultArr));
+
+        $result=$this->service->insertMany_onCommodities([]);
+        $this->assertEquals(false,$result);
+    }
+
+
+    public function tearDown(): void
+    {
+        $this->data['commodity']->delete();
+        CommodityBarcode::destroy($this->data['commodityBarcodes']->map(function ($commodityBarcode){
+            return $commodityBarcode['id'];
+        }));
+        parent::tearDown();
+    }
+}

+ 47 - 0
tests/Services/CommodityService/SyncBarcodesTest.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace Tests\Services\CacheService\GetOrExecuteTest;
+
+use App\Commodity;
+use App\CommodityBarcode;
+use App\Services\CacheService;
+use App\Services\CommodityBarcodeService;
+use App\Services\CommodityService;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Cache;
+use Tests\TestCase;
+
+class InsertMany_onCommoditiesTest extends TestCase
+{
+
+    /** @var CommodityService $service */
+    public $service;
+    public $data=[];
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('CommodityService');
+        ($this->data['commodity']=(new Commodity(['owner_id'=>1,'sku'=>md5(microtime(true))])))->save();
+        $this->data['barcodes']=['A1','B1','C2'];
+        $this->data['commodityBarcodes']=new Collection();
+        $inputs=[
+            'commodity_id'=>$this->data['commodity']['id'],
+            'barcodes'=>$this->data['barcodes']
+        ];
+        $this->service->insertMany_onCommodities([$inputs]);
+    }
+
+    public function testInsert(){
+
+    }
+
+
+    public function tearDown(): void
+    {
+        $this->data['commodity']->delete();
+        CommodityBarcode::destroy($this->data['commodityBarcodes']->map(function ($commodityBarcode){
+            return $commodityBarcode['id'];
+        }));
+        parent::tearDown();
+    }
+}

+ 0 - 2
tests/Services/OracleDOCOrderHeaderService/GetWmsOrderOnStartDateCreateTest/GetWmsOrderOnstartDateCreateTest.php

@@ -23,9 +23,7 @@ class GetWmsOrderOnstartDateCreateTest extends TestCase
     public function testGetWmsOrderOnstartDateCreate()
     {
         $carbon =Carbon::now()->subHours(10);
-        var_dump(Carbon::now());
         $orderHeaders = $this->service->getWmsOrderOnStartDateCreate($carbon);
-        var_dump(Carbon::now());
         $this->assertNotNull($orderHeaders);
         $orderHeader = $orderHeaders->first();
         if($orderHeaders->count() == 0){

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 1
tests/sortingFluxNewBatch.http


+ 3 - 1
文档/WAS项目规范.md

@@ -78,7 +78,9 @@
 	每个需求修改提交一个commit
 ##测试
     每个Service方法均需写一个对应的测试
-    每个Service在Tests,Services文夹下,建立对应对名文件夹,一个方法对应一个测试文件
+    每个Service在Tests,Services文夹下,建立对应名文件夹,一个方法对应一个测试文件
+    每个方法可以超过一个文件,如果N个是在基镜中需要配置相同假数据的,可以放在一个文件,不需要或其他假数据的,可以再做一个文件
+    同方法的多文件,在后缀Test之前用下划线_标注区分
     windwos下调用测试,在命令行运行phpunit.bat ,空格后跟要测试的目标包(包可以phpunit.xml定义)
 ##缓存
     缓存在service层以上使用,模型层内不使用

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott