Browse Source

ASN同步及测试,商品同步

haozi 5 years ago
parent
commit
eba1eda455
25 changed files with 932 additions and 44 deletions
  1. 2 0
      app/Console/Commands/SyncWmsCommoditiesInformation.php
  2. 6 3
      app/Http/Controllers/TestController.php
  3. 218 0
      app/Services/CommodityBarcodeService.php
  4. 69 19
      app/Services/CommodityService.php
  5. 1 0
      app/Services/RejectedBillService.php
  6. 12 3
      app/Services/StoreItemService.php
  7. 14 10
      app/Services/StoreService.php
  8. 55 0
      tests/Services/CommodityBarcodeService/CreateBarcodeByWmsTest.php
  9. 55 0
      tests/Services/CommodityBarcodeService/GetByWmsTest.php
  10. 39 0
      tests/Services/CommodityService/GetAsnSyncAtTest.php
  11. 45 0
      tests/Services/CommodityService/GetParamsByBasSkusTest.php
  12. 52 0
      tests/Services/CommodityService/SetAsnSyncAtTest.php
  13. 75 0
      tests/Services/CommodityService/SyncCommodityCreatedTest.php
  14. 102 0
      tests/Services/CommodityService/SyncCommodityUpdatedTest.php
  15. 75 0
      tests/Services/CommodityService/SyncCreateCommodityByBasSkusTest.php
  16. 102 0
      tests/Services/CommodityService/SyncUpdateCommodityBasSkusTest.php
  17. 2 1
      tests/Services/RejectedBillService/SyncLoadedStatusByAsnHeaderTest.php
  18. 1 1
      tests/Services/StoreItemService/GetAsnDetailsByAsnHerderTest.php
  19. 1 1
      tests/Services/StoreItemService/GetByWmsTest.php
  20. 1 1
      tests/Services/StoreItemService/GetParamsByAsnDetailsTest.php
  21. 1 1
      tests/Services/StoreService/GetAsnSyncAtTest.php
  22. 1 1
      tests/Services/StoreService/SetAsnSyncAtTest.php
  23. 1 1
      tests/Services/StoreService/SetLastRecordsByRedisTest.php
  24. 1 1
      tests/Services/StoreService/SyncStoreCreateByWmsTest.php
  25. 1 1
      tests/Services/StoreService/SyncStoreUpdateByWmsTest.php

+ 2 - 0
app/Console/Commands/SyncWmsCommoditiesInformation.php

@@ -46,5 +46,7 @@ class SyncWmsCommoditiesInformation extends Command
     public function SyncWmsCommoditiesInformation(){
         /** @var CommodityService $commodityService */
         $commodityService  = app(CommodityService::class);
+        $commodityService->syncCommodityCreated();
+        $commodityService->syncCommodityUpdated();
     }
 }

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

@@ -1010,8 +1010,9 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         var_dump('end',Carbon::now());
     }
     public  function  testSyncAsn(){
-        $startDate=Carbon::parse('2020-11-12 17:48:00')->subSeconds(65)->format('Y-m-d H:i:s');
-        app(StoreService::class)->syncWmsAsnData($startDate);
+
+        app(StoreService::class)->storeCreateByWms();
+        app(StoreService::class)->storeUpdateByWms();
     }
 
     public function changeOrder()
@@ -1214,13 +1215,15 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         dump(11);
     }
 
-    public function testCommodity(){
+    public function testSyncCommodity(){
         /**
          * @var CommodityService $commodityService
          */
         $commodityService=app(CommodityService::class);
+        dump('start',(string)Carbon::now());
         $commodityService->syncCommodityCreated();
         $commodityService->syncCommodityUpdated();
+        dump('end',(string)Carbon::now());
     }
 
     public function reNewBatches3()

+ 218 - 0
app/Services/CommodityBarcodeService.php

@@ -2,8 +2,11 @@
 
 namespace App\Services;
 
+use App\Commodity;
 use App\CommodityBarcode;
+use App\Services\common\DataHandlerService;
 use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Cache;
 
 Class CommodityBarcodeService
 {
@@ -73,4 +76,219 @@ Class CommodityBarcodeService
         });
         return CommodityBarcode::destroy($ids);
     }
+
+    public function createBarcodeByWms($bas_skus)
+    {
+
+        if (count($bas_skus)<1)return;
+        $owner_sku_map = [];
+        $sku = [];
+        $bas_skus->each(function ($addBasSku) use (&$owner_sku_map, &$sku) {
+            if (!empty($addBasSku['customerid']) && !empty($addBasSku['sku'])) {
+                $key = "owner_code_{$addBasSku['customerid']}_sku_{$addBasSku['sku']}";
+                $owner_sku_map[$key] = ['owner_code' => $addBasSku['customerid'], 'sku' => $addBasSku['sku']];
+                $sku[] = $addBasSku['sku'];
+            }
+        });
+        /**
+         * @var OwnerService $ownerService
+         * @var DataHandlerService $dataHandlerService
+         */
+        $ownerService = app(OwnerService::class);
+        $dataHandlerService=app(DataHandlerService::class);
+        $owner_codes = (function () use ($owner_sku_map) {
+            $owner_codes = [];
+            if (count($owner_sku_map) == 0) return $owner_codes;
+            foreach ($owner_sku_map as $item) {
+                $owner_codes[$item['owner_code']] = $item['owner_code'];
+            }
+            return $owner_codes;
+        })();
+        $owner_map = (function () use ($ownerService, $owner_codes) {
+            $owners = $ownerService->getOwnerByCodes($owner_codes);
+            $map = [];
+            $owners->each(function ($owner) use (&$map) {
+                $map[$owner['code']] = $owner['id'];
+            });
+            return $map;
+        })();
+        $owner_id = (function () use ($ownerService, $owner_codes) {
+            $owners = $ownerService->getOwnerByCodes($owner_codes);
+            $map = [];
+            $owners->each(function ($owner) use (&$map) {
+                $map[] = $owner['id'];
+            });
+            return $map;
+        })();
+        $commodityBarcodes=$this->getByWms($bas_skus);
+        $commodityBarcodes_map=$dataHandlerService->dataHeader(['commodity_id','code'], $commodityBarcodes);
+        $insert_params=$this->getInsertParams($bas_skus, $commodityBarcodes_map,$owner_id,$sku,$owner_map);
+        if (count($insert_params)>0) {
+            foreach (array_chunk($insert_params, 1000) as $item) {
+                try {
+                    $bool = $this->insert($item);
+                    if ($bool) {
+                        app('LogService')->log(__METHOD__, __FUNCTION__, "批量添加 CommodityBarcode Success " . count($insert_params) . ' || ' . json_encode($insert_params));
+                    } else app('LogService')->log(__METHOD__, __FUNCTION__, "批量添加 CommodityBarcode FAILED " . ' || ' . json_encode($insert_params));
+                } catch (\Exception $e) {
+                    app('LogService')->log(__METHOD__, __FUNCTION__, "批量添加 CommodityBarcode ERROR " . ' || ' . json_encode($insert_params) . ' || ' . json_encode($e->getMessage()) . ' || ' . json_encode($e->getTraceAsString()));
+                }
+            }
+        }
+
+    }
+    public function getInsertParams($bas_skus, $commodityBarcodes_map,$owner_id,$sku,$owner_map)
+    {
+        /**
+         * @var DataHandlerService $dataHandlerService
+         */
+        $dataHandlerService = app(DataHandlerService::class);
+        $commodities = Commodity::query()
+            ->whereIn('owner_id', array_unique($owner_id))
+            ->whereIn('sku', array_unique($sku))
+            ->groupBy('owner_id', 'sku')
+            ->get();
+        $commodities_map = $dataHandlerService->dataHeader(['owner_id','sku'], $commodities);
+        $params = [];
+        foreach ($bas_skus as $bas_sku) {
+            $commodity = Cache::get("owner_code_{$bas_sku['customerid']}_sku_{$bas_sku['sku']}");
+            if (!$commodity) {
+                $commodity = $dataHandlerService->getKeyValue(['owner_id' => $owner_map[$bas_sku['customerid']], 'sku' => $bas_sku['sku']], $commodities_map);
+                if (!$commodity) continue;
+            }
+            if ($bas_sku->alternate_sku1){
+                $commodityBarcode1 = $dataHandlerService->getKeyValue(['commodity_id' => $commodity->id, 'code' => $bas_sku->alternate_sku1], $commodityBarcodes_map);
+                if(!$commodityBarcode1) $params[]=[
+                    'code'=>$bas_sku->alternate_sku1,
+                    'commodity_id' => $commodity->id,
+                    'created_at'=>$bas_sku->addtime,
+                    'updated_at'=>$bas_sku->edittime,
+                ];
+            }
+            if ($bas_sku->alternate_sku2){
+                $commodityBarcode2 = $dataHandlerService->getKeyValue(['commodity_id' => $commodity->id, 'code' => $bas_sku->alternate_sku2], $commodityBarcodes_map);
+                if(!$commodityBarcode2) $params[]=[
+                    'code'=>$bas_sku->alternate_sku2,
+                    'commodity_id' => $commodity->id,
+                    'created_at'=>$bas_sku->addtime,
+                    'updated_at'=>$bas_sku->edittime,
+                ];
+            }
+            if ($bas_sku->alternate_sku3){
+                $commodityBarcode3 = $dataHandlerService->getKeyValue(['commodity_id' => $commodity->id, 'code' => $bas_sku->alternate_sku3], $commodityBarcodes_map);
+                if(!$commodityBarcode3) $params[]=[
+                    'code'=>$bas_sku->alternate_sku3,
+                    'commodity_id' => $commodity->id,
+                    'created_at'=>$bas_sku->addtime,
+                    'updated_at'=>$bas_sku->edittime,
+                ];
+            }
+        }
+        return $params;
+    }
+    public function updateBarcodeByWms($bas_skus)
+    {
+        if (!$bas_skus || $bas_skus->count() == 0) return;
+        $this->createBarcodeByWms($bas_skus);
+        $owner_sku_map = [];
+        $sku = [];
+        $bas_skus->each(function ($addBasSku) use (&$owner_sku_map, &$sku) {
+            if (!empty($addBasSku['customerid']) && !empty($addBasSku['sku'])) {
+                $key = "owner_code_{$addBasSku['customerid']}_sku_{$addBasSku['sku']}";
+                $owner_sku_map[$key] = ['owner_code' => $addBasSku['customerid'], 'sku' => $addBasSku['sku']];
+                $sku[] = $addBasSku['sku'];
+            }
+        });
+        /**
+         * @var OwnerService $ownerService
+         * @var DataHandlerService $dataHandlerService
+         */
+        $ownerService = app(OwnerService::class);
+        $dataHandlerService=app(DataHandlerService::class);
+        $owner_codes = (function () use ($owner_sku_map) {
+            $owner_codes = [];
+            if (count($owner_sku_map) == 0) return $owner_codes;
+            foreach ($owner_sku_map as $item) {
+                $owner_codes[$item['owner_code']] = $item['owner_code'];
+            }
+            return $owner_codes;
+        })();
+        $owner_map = (function () use ($ownerService, $owner_codes) {
+            $owners = $ownerService->getOwnerByCodes($owner_codes);
+            $map = [];
+            $owners->each(function ($owner) use (&$map) {
+                $map[$owner['id']] = $owner['code'];
+            });
+            return $map;
+        })();
+        $commodityBarcodes=$this->getByWms($bas_skus);
+        $bas_skus_map_one = $dataHandlerService->dataHeader(['customerid', 'sku','alternate_sku1',], $bas_skus);
+        $bas_skus_map_two = $dataHandlerService->dataHeader(['customerid', 'sku','alternate_sku2',], $bas_skus);
+        $bas_skus_map_three = $dataHandlerService->dataHeader(['customerid', 'sku','alternate_sku3',], $bas_skus);
+        $delete_Items = [];
+        foreach ($commodityBarcodes as $commodityBarcode) {
+            $bas_sku_one = $dataHandlerService
+                ->getKeyValue(['customerid'=>$owner_map[$commodityBarcode->commodity['owner_id']],'sku'=>$commodityBarcode->commodity['sku'],'alternate_sku1'=>$commodityBarcode->code], $bas_skus_map_one);
+            if ($bas_sku_one) continue;
+            $bas_sku_two = $dataHandlerService
+                ->getKeyValue(['customerid'=>$owner_map[$commodityBarcode->commodity['owner_id']],'sku'=>$commodityBarcode->commodity['sku'],'alternate_sku2'=>$commodityBarcode->code], $bas_skus_map_two);
+            if ($bas_sku_two) continue;
+            $bas_sku_three = $dataHandlerService
+                ->getKeyValue(['customerid'=>$owner_map[$commodityBarcode->commodity['owner_id']],'sku'=>$commodityBarcode->commodity['sku'],'alternate_sku3'=>$commodityBarcode->code], $bas_skus_map_three);
+            if ($bas_sku_three) continue;
+            if (!$bas_sku_one&& !$bas_sku_two&& !$bas_sku_three){
+                $delete_Items[]=$commodityBarcode;
+            }
+        }
+        if (count($delete_Items)>0) $this->deleteStoreItem($delete_Items);
+    }
+    public function getByWms($bas_skus)
+    {
+        if (!$bas_skus) return null;
+        $owner_sku_map = [];
+        $sku = [];
+        $bas_skus->each(function ($addBasSku) use (&$owner_sku_map, &$sku) {
+            if (!empty($addBasSku['customerid']) && !empty($addBasSku['sku'])) {
+                $key = "owner_code_{$addBasSku['customerid']}_sku_{$addBasSku['sku']}";
+                $owner_sku_map[$key] = ['owner_code' => $addBasSku['customerid'], 'sku' => $addBasSku['sku']];
+                $sku[] = $addBasSku['sku'];
+            }
+        });
+        /**
+         * @var OwnerService $ownerService
+         */
+        $ownerService = app(OwnerService::class);
+        $owner_codes = (function () use ($owner_sku_map) {
+            $owner_codes = [];
+            if (count($owner_sku_map) == 0) return $owner_codes;
+            foreach ($owner_sku_map as $item) {
+                $owner_codes[$item['owner_code']] = $item['owner_code'];
+            }
+            return $owner_codes;
+        })();
+        $owner_id = (function () use ($ownerService, $owner_codes) {
+            $owners = $ownerService->getOwnerByCodes($owner_codes);
+            $map = [];
+            $owners->each(function ($owner) use (&$map) {
+                $map[] = $owner['id'];
+            });
+            return $map;
+        })();
+        return CommodityBarcode::query()->with('commodity')->whereHas('commodity', function ($query) use ($owner_id,$sku) {
+            $query->whereIn('owner_id', array_unique($owner_id))->whereIn('sku',array_unique($sku));
+        })->get();
+    }
+    public function deleteStoreItem(array $delete_Items)
+    {
+        $itemIds = [];
+        foreach ($delete_Items as $item) {
+            array_push($storeItemIds, $item->id);
+        }
+        try {
+            CommodityBarcode::query()->whereIn('id', $itemIds)->delete();
+            LogService::log(__METHOD__, __FUNCTION__, '删除多余StoreItems ' . count($delete_Items) . json_encode($delete_Items), null);
+        } catch (\Exception $e) {
+            LogService::log(__METHOD__, __FUNCTION__, '删除多余StoreItems error' . count($delete_Items) . json_encode($delete_Items) . $e->getMessage() . $e->getTraceAsString(), null);
+        }
+    }
 }

+ 69 - 19
app/Services/CommodityService.php

@@ -353,16 +353,17 @@ Class CommodityService
         return false;
     }
 
+
     public function pushCommodityToCache()
     {
         $amount = 1000;
         $commodity = Commodity::query()->orderByDesc('id')->first();
-        $sum=$commodity->id;
+        $sum = $commodity->id;
         $number = ceil($sum / $amount);
         for ($i = 0; $i < $number; $i++) {
-            if ($i<41) continue;
+            if ($i < 41) continue;
             $commodities = $this->getPiece(($i * $amount), $amount);
-            if (count($commodities)<1) continue;
+            if (count($commodities) < 1) continue;
             $this->pushToCache($commodities);
         }
     }
@@ -371,7 +372,7 @@ Class CommodityService
     {
         $commodities = Commodity::query()->with(['owner', 'barcodes'])
             ->where('id', '>=', $start)
-            ->where('id', '<', ($start+$amount))
+            ->where('id', '<', ($start + $amount))
             ->get();
         return $commodities;
     }
@@ -387,6 +388,7 @@ Class CommodityService
         }
     }
 
+
     public function syncCommodityCreated()
     {
         $created_at = config('sync.commodity_sync.created_at');
@@ -426,7 +428,6 @@ Class CommodityService
         $addBasSkus = $this->getLastRecordsByRedis($update_set, $update_key, $basSkus);
         //if (count($addBasSkus) > 0) $addBasSkus = $this->filterByCommodityCache($addBasSkus); //从缓存中过滤
         if (count($addBasSkus) > 0) {
-            $this->syncCreateCommodity($addBasSkus);
             $this->syncUpdateCommodity($addBasSkus);
             $this->deleteCacheKey($update_set, $update_keys);
             $this->setLastRecordsByRedis($update_key, $update_set, $update_keys, $last_records);
@@ -438,7 +439,19 @@ Class CommodityService
     public function syncCreateCommodity($addBasSkus)
     {
         if (count($addBasSkus) < 1) return null;
-        $insert_params = $this->getParamsByOwnerSkuMap($addBasSkus);
+        $insert_params = $this->getParamsByBasSkus($addBasSkus);
+        if (!$insert_params) return;
+        $this->insertCommodities($insert_params);
+        /**
+         * @var CommodityBarcodeService $commodityBarcodeService
+         */
+        $commodityBarcodeService = app(CommodityBarcodeService::class);
+        $commodityBarcodeService->createBarcodeByWms($addBasSkus);
+    }
+
+    public function insertCommodities($insert_params)
+    {
+
         foreach (array_chunk($insert_params, 1000) as $item) {
             try {
                 $bool = Commodity::query()->insert($item);
@@ -451,16 +464,10 @@ Class CommodityService
                 app('LogService')->log(__METHOD__, __FUNCTION__, "批量添加 Commodity ERROR " . ' || ' . json_encode($insert_params) . ' || ' . json_encode($e->getMessage()) . ' || ' . json_encode($e->getTraceAsString()));
             }
         }
-        //同步商品条码
-//        /**
-//         * @var CommodityBarcodeService $commodityBarcodeService
-//         */
-//        $commodityBarcodeService = app(CommodityBarcodeService::class);
-//        $commodityBarcodeService->createBarcodeByWms($addBasSkus);
     }
 
     // TODO
-    public function getParamsByOwnerSkuMap($addBasSkus)
+    public function getParamsByBasSkus($addBasSkus)
     {
         $owner_sku_map = [];
         $sku = [];
@@ -506,7 +513,6 @@ Class CommodityService
             ->whereIn('sku', array_unique($sku))
             ->groupBy('owner_id', 'sku')
             ->get();
-
         $unexists = [];
         foreach ($owner_sku_map as $item) {
             $commodity = Cache::get("owner_code_{$item['owner_code']}_sku_{$item['sku']}");
@@ -540,7 +546,7 @@ Class CommodityService
                     'volumn' => $basSku->cube,
                     'created_at' => $basSku->addtime,
                     'updated_at' => $basSku->edittime,
-                    'pack_spec' => $basSku->pickid,
+                    'pack_spec' => $basSku->packid == 'STANDARD' ? 0 : explode("/", $basSku->packid)[1],
                 ];
             });
             return $map;
@@ -554,7 +560,7 @@ Class CommodityService
     {
         $owner_sku_map = [];
         $sku = [];
-        $addBasSkus->each(function ($addBasSku) use (&$owner_sku_map, &$sku, &$owner_code) {
+        $addBasSkus->each(function ($addBasSku) use (&$owner_sku_map, &$sku) {
             if (!empty($addBasSku['customerid']) && !empty($addBasSku['sku'])) {
                 $key = "owner_code_{$addBasSku['customerid']}_sku_{$addBasSku['sku']}";
                 $owner_sku_map[$key] = ['owner_code' => $addBasSku['customerid'], 'sku' => $addBasSku['sku']];
@@ -600,11 +606,26 @@ Class CommodityService
         $updateParams = [[
             'id', 'name', 'sku', 'owner_id', 'length', 'width', 'height', 'volumn', 'pack_spec', 'updated_at', 'created_at'
         ]];
+        $insert_params = [];
         foreach ($addBasSkus as $basSku) {
             $commodity = Cache::get("owner_code_{$basSku['customerid']}_sku_{$basSku['sku']}");
             if (!$commodity) {
                 $commodity = $dataHandlerService->getKeyValue(['owner_id' => $owner_map[$basSku['customerid']], 'sku' => $basSku['sku']], $commodities_map);
-                if (!$commodity) continue;
+                if (!$commodity) {
+                    $insert_params[] = [
+                        'owner_id' => $owner_map[$basSku['customerid']] ?? '',
+                        'sku' => $basSku->sku,
+                        'name' => $basSku->descr_c,
+                        'length' => $basSku->skulength,
+                        'width' => $basSku->skuwidth,
+                        'height' => $basSku->skuhigh,
+                        'volumn' => $basSku->cube,
+                        'created_at' => $basSku->addtime,
+                        'updated_at' => $basSku->edittime,
+                        'pack_spec' => $basSku->packid == 'STANDARD' ? 0 : explode("/", $basSku->packid)[1],
+                    ];
+                    continue;
+                };
             }
             if ($commodity->sku != $basSku->sku ||
                 $commodity->name != $basSku->descr_c ||
@@ -626,13 +647,19 @@ Class CommodityService
                     'volumn' => $basSku->cube,
                     'created_at' => $basSku->addtime,
                     'updated_at' => $basSku->edittime,
-                    'pack_spec' => $basSku->pickid,
+                    'pack_spec' => $basSku->packid == 'STANDARD' ? 0 : explode("/", $basSku->packid)[1],
                 ];
             }
         }
-        if (count($updateParams) > 1) $this->batchUpdate($updateParams);
+        if (count($insert_params) > 0) $this->insertCommodities($insert_params);
+        if (count($updateParams) > 0) $this->batchUpdate($updateParams);
         $commodities = Commodity::query()->with('owner')->whereIn('owner_id', data_get($updateParams, '*.owner_id'))->whereIn('sku', data_get($updateParams, '*.sku'))->get();
         $this->pushToCache($commodities);
+        /**
+         * @var CommodityBarcodeService $commodityBarcodeService
+         */
+        $commodityBarcodeService = app(CommodityBarcodeService::class);
+        $commodityBarcodeService->updateBarcodeByWms($addBasSkus);
     }
 
     public function getAsnLastSyncAt($key, $type)
@@ -707,4 +734,27 @@ Class CommodityService
         }
         return $addBasSkus;
     }
+
+//    function get_($paginate = 100, $page = 1, $ownerIds, $skus, $barcodes)
+//    {
+        //$paginate小于100,或取余数100不为0,异常 //取余函数fmod()
+//        for (; $page <= $paginate / 100; $page++) {
+//            switch () {
+//                case 只有货主条件:
+//                    sort($ownerIds);
+//                    $md5 = md5(json_encode([$ownerIds, $paginate, $page]));
+//                    return Cache::remember('commodity_' . $md5)
+//            case 有SKU:
+//                $md5 = md5(json_encode([$skus, $paginate, $page]));
+//                return Cache::remember('commodity_' . $md5, 'time', function () {
+//                    在取出的记录用 $ownerIds和$barcodes筛选
+//                })
+//            case 有条码没SKU:
+//                $md5 = md5(json_encode([$barcodes, $paginate, $page]));
+//                return Cache::remember('commodity_' . $md5, 'time', function () {
+//                    在取出的记录用 $ownerIds
+//                })
+//            }
+//        }
+//    }
 }

+ 1 - 0
app/Services/RejectedBillService.php

@@ -71,6 +71,7 @@ Class RejectedBillService
     public function syncLoadedStatusByAsnHerder($asnHerders)
     {
         $updateParams=$this->getNeedUpdateLoadedStatusByWms($asnHerders);
+        if (!$updateParams)return;
         if (count($updateParams) > 1) {
             $this->batchUpdate($updateParams);
         }

+ 12 - 3
app/Services/StoreItemService.php

@@ -23,9 +23,12 @@ Class StoreItemService
         $this->createStoreItem($asnDetails);
     }
 
-    public function storeItemUpdateByWms($asnHerders)
+    public function storeItemUpdateByWms($asnHerders,$KSRK)
     {
         if (!$asnHerders) return null;
+        if (count($KSRK)>0) $asnHerders=$asnHerders->filter(function ($asnHerder)use($KSRK){
+            return !in_array($asnHerder->asnno,$KSRK);
+        });
         $asnDetails = $this->getAsnDetailsByAsnHerder($asnHerders);
         $this->updateStoreItem($asnDetails);
     }
@@ -69,6 +72,9 @@ Class StoreItemService
             $storeItem = $dataHandlerService
                 ->getKeyValue(['store_asn_code' => $asnDetail->asnno, 'asn_line_code' => $asnDetail->asnlineno, 'sku' => $asnDetail->sku], $storeItem_map);
             if ($storeItem ?? false) continue;
+            $status=null;
+            if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c=='完全收货') $status='已入库';
+            if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c=='订单创建') $status='未入库';
             //if (empty($store_asn_code_map[$asnDetail->asnno])) continue;
             $params[] = [
                 'store_id' => $store_asn_code_map[$asnDetail->asnno]['id'],
@@ -78,7 +84,7 @@ Class StoreItemService
                 'barcode' => $asnDetail->basSku ? $asnDetail->basSku->alternate_sku1 : '',
                 'amount' => $asnDetail->receivedqty ?? 0,
                 'quality' => $asnDetail->qualityStatus ? $asnDetail->qualityStatus->codename_c : '',
-                'status' => $asnDetail->lineStatus ? $asnDetail->lineStatus->codename_c : '',
+                'status' => $status ? $status :$asnDetail->lineStatus->codename_c,
                 'created_at' => $asnDetail->addtime ?? null,
                 'updated_at' => $asnDetail->edittime ?? null,
             ];
@@ -117,6 +123,9 @@ Class StoreItemService
                 array_push($delete_storeItems, $storeItem);
                 continue;
             }
+            $status=null;
+            if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c=='完全收货') $status='已入库';
+            if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c=='订单创建') $status='未入库';
             if ($storeItem->asn_line_code != $asnDetail['asnlineno'] ||
                 $storeItem->name != $asnDetail['skudescrc'] ||
                 $storeItem->sku != $asnDetail['sku'] ||
@@ -135,7 +144,7 @@ Class StoreItemService
                     'barcode' => $asnDetail['basSku'] ? $asnDetail['basSku']['alternate_sku1'] : '',
                     'amount' => $asnDetail['receivedqty'] ?? 0,
                     'quality' => $asnDetail['qualityStatus'] ? $asnDetail['qualityStatus']['codename_c'] : '',
-                    'status' => $asnDetail['lineStatus'] ? $asnDetail['lineStatus']['codename_c'] : '',
+                    'status' => $status ? $status :$asnDetail['lineStatus']['codename_c'],
                     'created_at' => $asnDetail['addtime'] ?? null,
                     'updated_at' => $asnDetail['edittime'],
                 ];

+ 14 - 10
app/Services/StoreService.php

@@ -96,8 +96,6 @@ Class StoreService
          */
         $ownerService = app(OwnerService::class);
         $wareHouseService = app(WarehouseService::class);
-//        $owners = $ownerService->getByWmsOrders($asnHerders);
-//        $warehouses = $wareHouseService->getByWmsOrders($asnHerders);
         $owner_codes = [];
         $warehouse_codes = [];
         foreach ($asnHerders as $asnHerder) {
@@ -139,13 +137,16 @@ Class StoreService
             if ($store_asn_code_map[$asnHerder->asnno] ?? false) continue;
             $owner = $owners_code_map[$asnHerder->customerid] ?? null;
             $warehouse = $warehouses_code_map[$asnHerder->warehouseid] ?? null;
+            $status=null;
+            if ($asnHerder->asnStatus && $asnHerder->asnStatus->codename_c=='完全收货') $status='已入库';
+            if ($asnHerder->asnStatus && $asnHerder->asnStatus->codename_c=='订单创建') $status='未入库';
             $params[] = [
                 'asn_code' => $asnHerder->asnno,
                 'warehouse_id' => $warehouse->id ?? null,
                 'owner_id' => $owner->id ?? null,
                 'stored_method' => $asnHerder->asnType ? $asnHerder->asnType->codename_c : '',
-                'status' => $asnHerder->asnStatus ? $asnHerder->asnStatus->codename_c : '',
-                'remark' => $asnHerder->notes ?? '1111',
+                'status' => $status ? $status : $asnHerder->asnStatus->codename_c,
+                'remark' => $asnHerder->notes ?? null,
                 'created_at' => $asnHerder->addtime ?? null,
                 'updated_at' => $asnHerder->edittime ?? null,
             ];
@@ -187,23 +188,26 @@ Class StoreService
         }
         $owners = $ownerService->getOwnerByCodes($owner_codes);
         $warehouses = $wareHouseService->getWareHouseByCode($warehouse_codes);
-//        $owners = app(OwnerService::class)->getByWmsOrders($asnHerders);
-//        $warehouses = app(WarehouseService::class)->getByWmsOrders($asnHerders);
         $owner_code_map = $dataHandlerService->dataHeader(['code'], $owners);
         $warehouses_map = $dataHandlerService->dataHeader(['code'], $warehouses);
         $updateParams = [[
             'id', 'asn_code', 'warehouse_id', 'owner_id', 'stored_method', 'status', 'remark', 'updated_at'
         ]];
+        $KSRK=[];
         foreach ($asnHerders as $asnHerder) {
             $store = $dataHandlerService->getKeyValue(['asn_code' => $asnHerder->asnno], $store_asn_code_map);
-            if (!$store) {
+            if (!$store) continue;
+            if ($store&&$store->stored_method=='快速入库'){
+                array_push($KSRK,$store['asn_code']);
                 continue;
             }
             $owner = $dataHandlerService->getKeyValue(['code' => $asnHerder->customerid], $owner_code_map);
             $warehouse = $dataHandlerService->getKeyValue(['code' => $asnHerder->warehouseid], $warehouses_map);
             $owner_id = $owner->id ?? null;
             $warehouse_id = $warehouse->id ?? null;
-
+            $status=null;
+            if ($asnHerder->asnStatus && $asnHerder->asnStatus->codename_c=='完全收货') $status='已入库';
+            if ($asnHerder->asnStatus && $asnHerder->asnStatus->codename_c=='订单创建') $status='未入库';
             if ($store->asn_code != $asnHerder->asnno ||
                 $store->warehouse_id != $warehouse_id ||
                 $store->owner_id != $owner_id ||
@@ -216,7 +220,7 @@ Class StoreService
                     'warehouse_id' => $warehouse_id,
                     'owner_id' => $owner_id,
                     'stored_method' => $asnHerder->asnType ? $asnHerder->asnType->codename_c : '',
-                    'status' => $asnHerder->asnStatus ? $asnHerder->asnStatus->codename_c : '',
+                    'status' => $status ? $status : $asnHerder->asnStatus->codename_c,
                     'remark' => $asnHerder->notes,
                     'updated_at' => $asnHerder->edittime,
                 ];
@@ -225,7 +229,7 @@ Class StoreService
         if (count($updateParams) > 1) $this->batchUpdate($updateParams);
         /** @var StoreItemService $storeItemService */
         $storeItemService = app(StoreItemService::class);
-        $storeItemService->storeItemUpdateByWms($asnHerders);
+        $storeItemService->storeItemUpdateByWms($asnHerders,$KSRK);
         /** @var RejectedBillService $rejectedBillService */
         $rejectedBillService = app(RejectedBillService::class);
         $rejectedBillService->syncLoadedStatusByAsnHerder($asnHerders);

+ 55 - 0
tests/Services/CommodityBarcodeService/CreateBarcodeByWmsTest.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace Tests\Services\CommodityBarcodeService;
+
+
+use App\OracleBasSKU;
+use App\Services\CommodityBarcodeService;
+use App\ValueStore;
+use Tests\TestCase;
+
+class CreateBarcodeByWmsTest extends TestCase
+{
+
+    /**
+     * @var CommodityBarcodeService $service
+     */
+    public $service;
+    public $bas_skus;
+    public $created_at;
+    public $commodityBarcodes;
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->created_at = config('sync.commodity_sync.created_at');
+        $last_time = ValueStore::query()->where('name', $this->created_at)->value('value');
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(65);
+        $this->service = app(CommodityBarcodeService::class);
+        $this->bas_skus = OracleBasSKU::query()
+            ->select('customerid', 'sku', 'descr_c', 'alternate_sku1', 'alternate_sku2', 'alternate_sku3', 'skulength', 'skuwidth', 'skuhigh', 'cube', 'packid', 'addtime', 'edittime')
+            ->where('addTime', '>=', $last_time ?? $startDate)
+            ->orderByDesc('addtime')
+            ->get();
+
+    }
+
+    public function testCreateBarcodeByWms()
+    {
+
+        if ($this->bas_skus->isEmpty()) {
+            $this->assertEmpty($this->bas_skus);
+            return;
+        }
+        $this->service->createBarcodeByWms($this->bas_skus);
+        $this->commodityBarcodes=$this->service->getByWms($this->bas_skus);
+        if ($this->commodityBarcodes) $this->assertNotNull($this->commodityBarcodes);
+    }
+
+
+    public function tearDown(): void
+    {
+
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 55 - 0
tests/Services/CommodityBarcodeService/GetByWmsTest.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace Tests\Services\CommodityBarcodeService;
+
+
+use App\OracleBasSKU;
+use App\Services\CommodityBarcodeService;
+use App\ValueStore;
+use Tests\TestCase;
+
+class GetByWmsTest extends TestCase
+{
+
+    /**
+     * @var CommodityBarcodeService $service
+     */
+    public $service;
+    public $bas_skus;
+    public $created_at;
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->created_at = config('sync.commodity_sync.created_at');
+        $last_time = ValueStore::query()->where('name',$this->created_at)->value('value');
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(65);
+        $this->service = app(CommodityBarcodeService::class);
+        $this->bas_skus = OracleBasSKU::query()
+            ->select('customerid', 'sku', 'descr_c', 'alternate_sku1', 'alternate_sku2', 'alternate_sku3', 'skulength', 'skuwidth', 'skuhigh', 'cube', 'packid', 'addtime', 'edittime')
+            ->where('addTime', '>=', $last_time??$startDate)
+            ->orderByDesc('addtime')
+            ->get();
+    }
+
+
+    public function testGetByWms()
+    {
+        if ($this->bas_skus->isEmpty()) {
+            $this->assertEmpty($this->bas_skus);
+            return;
+        }
+        $commodities=$this->service->getByWms($this->bas_skus);
+        if ($commodities) {
+            $this->assertNotNull($commodities);
+        }else{
+            $this->assertNull($commodities);
+        }
+    }
+
+
+    public function tearDown(): void
+    {
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 39 - 0
tests/Services/CommodityService/GetAsnSyncAtTest.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Services\CommodityService;
+use Tests\TestCase;
+
+class GetAsnSyncAtTest extends TestCase
+{
+    /**
+     * @var CommodityService $service
+     */
+    private $service;
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app(CommodityService::class);
+    }
+
+    /**
+     * @test
+     */
+    public function getCreatedAsnSyncAt()
+    {
+        $key = config('sync.asn_sync.created_at');
+        $data = $this->service->getAsnLastSyncAt($key,'create');
+        $this->assertNotEmpty($data);
+    }
+
+    /**
+     * @test
+     */
+    public function getUpdatedAsnSyncAt()
+    {
+        $key = config('sync.asn_sync.updated_at');
+        $data = $this->service->getAsnLastSyncAt($key,'update');
+        $this->assertNotEmpty($data);
+    }
+}

+ 45 - 0
tests/Services/CommodityService/GetParamsByBasSkusTest.php

@@ -0,0 +1,45 @@
+<?php
+
+
+namespace Tests\Services\CommodityService;
+
+
+use App\OracleBasSKU;
+use App\Services\CommodityService;
+use App\Services\OwnerService;
+use App\Store;
+use Tests\TestCase;
+
+class GetParamsByBasSkusTest extends TestCase
+{
+    /**
+     * @var CommodityService $service
+     * @var OwnerService $ownerService
+     *
+     */
+    public $service;
+    public $bas_skus;
+    public $ownerService;
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
+        $this->service=app(CommodityService::class);
+        $this->ownerService=app(OwnerService::class);
+        $this->bas_skus=OracleBasSKU::query()
+            ->select('customerid','sku','descr_c','alternate_sku1','alternate_sku2','alternate_sku3','skulength','skuwidth','skuhigh','cube','packid','addtime','edittime')
+            ->where('addTime', '>=', $startDate)
+            ->orderByDesc('addtime')
+            ->get();
+    }
+    public function testGetParamsByBasSkus(){
+        if ($this->bas_skus->isEmpty()) {
+            $this->assertEmpty($this->bas_skus);
+            $insert_params=$this->service->getParamsByBasSkus($this->bas_skus);
+            $this->assertNull($insert_params);
+        }else{
+            $insert_params=$this->service->getParamsByBasSkus($this->bas_skus);
+            $this->assertNotNull($insert_params);
+        }
+    }
+}

+ 52 - 0
tests/Services/CommodityService/SetAsnSyncAtTest.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Services\OrderService;
+use App\Services\StoreService;
+use App\ValueStore;
+use Carbon\Carbon;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Illuminate\Support\Str;
+use Tests\TestCase;
+
+class SetAsnSyncAtTest extends TestCase
+{
+    /** @var StoreService $service */
+    private $service;
+    private $created_at;
+    private $original_value;
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app(StoreService::class);
+        $this->created_at = config('sync.asn_sync.created_at');
+    }
+
+    /**
+     * @test
+     */
+    public function testSetAsnSyncAt()
+    {
+        /** @var Carbon $time */
+
+        $data = Carbon::now();
+        $this->original_value=ValueStore::query()->where('name',$this->created_at)->value('value');
+
+        $this->service->setAsnLastSyncAt($this->created_at,$data);
+        $value=ValueStore::query()->where('name',$this->created_at)->value('value');
+        $this->assertEquals((string)$data,(string)$value);
+    }
+
+    public function tearDown(): void
+    {
+        ValueStore::query()->updateOrCreate([
+            'name' => $this->created_at,
+        ], [
+            'name' => $this->created_at,
+            'value' => $this->original_value,
+        ]);
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 75 - 0
tests/Services/CommodityService/SyncCommodityCreatedTest.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Services\CommodityService;
+use App\Services\OwnerService;
+use App\ValueStore;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class SyncCommodityCreatedTest extends TestCase
+{
+    /**
+     * @var CommodityService $service
+     */
+    public $service;
+    public $bas_skus;
+    public $created_at;
+    public $last_time;
+    public $insert_params;
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->service=app(CommodityService::class);
+    }
+
+    /**
+     * @test
+     */
+    public function testSyncCommodityCreated()
+    {
+        $this->created_at = config('sync.commodity_sync.created_at');
+        $this->last_time = ValueStore::query()->where('name',$this->created_at)->value('value');
+        if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
+        $this->bas_skus=OracleBasSKU::query()
+            ->select('customerid','sku','descr_c','alternate_sku1','alternate_sku2','alternate_sku3','skulength','skuwidth','skuhigh','cube','packid','addtime','edittime')
+            ->where('addTime', '>=', $this->last_time??$time)
+            ->orderByDesc('addtime')
+            ->get();
+        $this->insert_params=$this->service->getParamsByBasSkus($this->bas_skus);
+        $this->service->syncCommodityCreated();
+        if ($this->insert_params) $this->assertNotNull($this->insert_params);
+        if ($this->insert_params)$this->assertEquals(count($this->insert_params),count($this->bas_skus));
+        if (!$this->insert_params)$this->assertNull($this->insert_params);
+    }
+
+    public function tearDown(): void
+    {
+        ValueStore::query()->updateOrCreate([
+            'name' => $this->created_at,
+        ], [
+            'name' => $this->created_at,
+            'value' => $this->last_time,
+        ]);
+        $sku=[];
+        $owner_id=[];
+        if (!$this->insert_params) return;
+        foreach ($this->insert_params as $insert_param){
+            $owner_id[]=$insert_param['owner_id'];
+            $sku[]=$insert_param['sku'];
+        }
+        $commodities=Commodity::query()->whereIn('owner_id',$owner_id)->whereIn('sku',$sku)->get();
+        $commodity_id=[];
+        foreach ($commodities as $commodity){
+            $commodity_id[]=$commodity->id;
+        }
+        DB::table('commodities')->whereIn('id',$commodity_id)->delete();
+        DB::table('commodity_barcodes')->whereIn('commodity_id',$commodity_id)->delete();
+        cache()->flush();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 102 - 0
tests/Services/CommodityService/SyncCommodityUpdatedTest.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Services\CommodityService;
+use App\Services\common\DataHandlerService;
+use App\Services\OwnerService;
+use App\ValueStore;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class SyncCommodityUpdatedTest extends TestCase
+{
+    /**
+     * @var CommodityService $service
+     */
+    public $service;
+    public $bas_skus;
+    public $updated_at;
+    public $last_time;
+    public $commodities;
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->service=app(CommodityService::class);
+    }
+
+    /**
+     * @test
+     */
+    public function testSyncCommodityUpdated()
+    {
+        $this->updated_at = config('sync.commodity_sync.updated_at');
+        $this->last_time = ValueStore::query()->where('name',$this->updated_at)->value('value');
+        if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
+        $this->bas_skus= OracleBasSKU::query()
+            ->select('customerid','sku','descr_c','alternate_sku1','alternate_sku2','alternate_sku3','skulength','skuwidth','skuhigh','cube','packid','addtime','edittime')
+            ->where('EditTime', '>=', $this->last_time??$time)
+            ->whereColumn('EditTime', '<>', 'addTime')
+            ->orderByDesc('EditTime')
+            ->get();
+
+        $this->service->syncCommodityUpdated();
+        $owner_sku_map = [];
+        $sku = [];
+        $this->bas_skus->each(function ($addBasSku) use (&$owner_sku_map, &$sku) {
+            if (!empty($addBasSku['customerid']) && !empty($addBasSku['sku'])) {
+                $key = "owner_code_{$addBasSku['customerid']}_sku_{$addBasSku['sku']}";
+                $owner_sku_map[$key] = ['owner_code' => $addBasSku['customerid'], 'sku' => $addBasSku['sku']];
+                $sku[] = $addBasSku['sku'];
+            }
+        });
+        /**
+         * @var OwnerService $ownerService
+         */
+        $ownerService = app(OwnerService::class);
+        $owner_codes = (function () use ($owner_sku_map) {
+            $owner_codes = [];
+            if (count($owner_sku_map) == 0) return $owner_codes;
+            foreach ($owner_sku_map as $item) {
+                $owner_codes[$item['owner_code']] = $item['owner_code'];
+            }
+            return $owner_codes;
+        })();
+        $owner_id = (function () use ($ownerService, $owner_codes) {
+            $owners = $ownerService->getOwnerByCodes($owner_codes);
+            $map = [];
+            $owners->each(function ($owner) use (&$map) {
+                $map[] = $owner['id'];
+            });
+            return $map;
+        })();
+        $this->commodities = Commodity::query()
+            ->whereIn('owner_id', array_unique($owner_id))
+            ->whereIn('sku', array_unique($sku))
+            ->groupBy('owner_id', 'sku')
+            ->get();
+        $this->assertNotNull($this->commodities);
+        $this->assertEquals(count($this->bas_skus),count($this->commodities));
+    }
+
+    public function tearDown(): void
+    {
+        ValueStore::query()->updateOrCreate([
+            'name' => $this->updated_at,
+        ], [
+            'name' => $this->updated_at,
+            'value' => $this->last_time,
+        ]);
+        $commodityIds=[];
+        foreach ($this->commodities as $commodity){
+            array_push($commodityIds,$commodity->id);
+        }
+        DB::table('commodities')->whereIn('id',$commodityIds)->delete();
+        DB::table('commodity_barcodes')->whereIn('commodity_id',$commodityIds)->delete();
+        cache()->flush();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 75 - 0
tests/Services/CommodityService/SyncCreateCommodityByBasSkusTest.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Services\CommodityService;
+use App\Services\OwnerService;
+use App\ValueStore;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class SyncCreateCommodityByBasSkusTest extends TestCase
+{
+    /**
+     * @var CommodityService $service
+     */
+    public $service;
+    public $bas_skus;
+    public $created_at;
+    public $last_time;
+    public $insert_params;
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->service=app(CommodityService::class);
+    }
+
+    /**
+     * @test
+     */
+    public function testSyncCreateCommodityByBasSkus()
+    {
+        $this->created_at = config('sync.commodity_sync.created_at');
+        $this->last_time = ValueStore::query()->where('name',$this->created_at)->value('value');
+        if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
+        $this->bas_skus=OracleBasSKU::query()
+            ->select('customerid','sku','descr_c','alternate_sku1','alternate_sku2','alternate_sku3','skulength','skuwidth','skuhigh','cube','packid','addtime','edittime')
+            ->where('addTime', '>=', $this->last_time??$time)
+            ->orderByDesc('addtime')
+            ->get();
+        $this->insert_params=$this->service->getParamsByBasSkus($this->bas_skus);
+        $this->service->syncCreateCommodity($this->bas_skus);
+        if ($this->insert_params) $this->assertNotNull($this->insert_params);
+        if ($this->insert_params)$this->assertEquals(count($this->insert_params),count($this->bas_skus));
+        if (!$this->insert_params)$this->assertNull($this->insert_params);
+    }
+
+    public function tearDown(): void
+    {
+        ValueStore::query()->updateOrCreate([
+            'name' => $this->created_at,
+        ], [
+            'name' => $this->created_at,
+            'value' => $this->last_time,
+        ]);
+        $sku=[];
+        $owner_id=[];
+        if (!$this->insert_params) return;
+        foreach ($this->insert_params as $insert_param){
+            $owner_id[]=$insert_param['owner_id'];
+            $sku[]=$insert_param['sku'];
+        }
+        $commodities=Commodity::query()->whereIn('owner_id',$owner_id)->whereIn('sku',$sku)->get();
+        $commodity_id=[];
+        foreach ($commodities as $commodity){
+            $commodity_id[]=$commodity->id;
+        }
+        DB::table('commodities')->whereIn('id',$commodity_id)->delete();
+        DB::table('commodity_barcodes')->whereIn('commodity_id',$commodity_id)->delete();
+        cache()->flush();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 102 - 0
tests/Services/CommodityService/SyncUpdateCommodityBasSkusTest.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Services\CommodityService;
+use App\Services\common\DataHandlerService;
+use App\Services\OwnerService;
+use App\ValueStore;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
+use Tests\TestCase;
+
+class SyncUpdateCommodityBasSkusTest extends TestCase
+{
+    /**
+     * @var CommodityService $service
+     */
+    public $service;
+    public $bas_skus;
+    public $updated_at;
+    public $last_time;
+    public $commodities;
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->service=app(CommodityService::class);
+    }
+
+    /**
+     * @test
+     */
+    public function testSyncCommodityUpdated()
+    {
+        $this->updated_at = config('sync.commodity_sync.updated_at');
+        $this->last_time = ValueStore::query()->where('name',$this->updated_at)->value('value');
+        if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
+        $this->bas_skus= OracleBasSKU::query()
+            ->select('customerid','sku','descr_c','alternate_sku1','alternate_sku2','alternate_sku3','skulength','skuwidth','skuhigh','cube','packid','addtime','edittime')
+            ->where('EditTime', '>=', $this->last_time??$time)
+            ->whereColumn('EditTime', '<>', 'addTime')
+            ->orderByDesc('EditTime')
+            ->get();
+        $this->service->syncUpdateCommodity($this->bas_skus);
+
+        $owner_sku_map = [];
+        $sku = [];
+        $this->bas_skus->each(function ($addBasSku) use (&$owner_sku_map, &$sku) {
+            if (!empty($addBasSku['customerid']) && !empty($addBasSku['sku'])) {
+                $key = "owner_code_{$addBasSku['customerid']}_sku_{$addBasSku['sku']}";
+                $owner_sku_map[$key] = ['owner_code' => $addBasSku['customerid'], 'sku' => $addBasSku['sku']];
+                $sku[] = $addBasSku['sku'];
+            }
+        });
+        /**
+         * @var OwnerService $ownerService
+         */
+        $ownerService = app(OwnerService::class);
+        $owner_codes = (function () use ($owner_sku_map) {
+            $owner_codes = [];
+            if (count($owner_sku_map) == 0) return $owner_codes;
+            foreach ($owner_sku_map as $item) {
+                $owner_codes[$item['owner_code']] = $item['owner_code'];
+            }
+            return $owner_codes;
+        })();
+        $owner_id = (function () use ($ownerService, $owner_codes) {
+            $owners = $ownerService->getOwnerByCodes($owner_codes);
+            $map = [];
+            $owners->each(function ($owner) use (&$map) {
+                $map[] = $owner['id'];
+            });
+            return $map;
+        })();
+        $this->commodities = Commodity::query()
+            ->whereIn('owner_id', array_unique($owner_id))
+            ->whereIn('sku', array_unique($sku))
+            ->groupBy('owner_id', 'sku')
+            ->get();
+        $this->assertNotNull($this->commodities);
+        $this->assertEquals(count($this->bas_skus),count($this->commodities));
+    }
+
+    public function tearDown(): void
+    {
+        ValueStore::query()->updateOrCreate([
+            'name' => $this->updated_at,
+        ], [
+            'name' => $this->updated_at,
+            'value' => $this->last_time,
+        ]);
+        $commodityIds=[];
+        foreach ($this->commodities as $commodity){
+            array_push($commodityIds,$commodity->id);
+        }
+        DB::table('commodities')->whereIn('id',$commodityIds)->delete();
+        DB::table('commodity_barcodes')->whereIn('commodity_id',$commodityIds)->delete();
+        cache()->flush();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 2 - 1
tests/Services/RejectedBillService/SyncLoadedStatusByAsnHeaderTest.php

@@ -27,7 +27,7 @@ class SyncLoadedStatusByAsnHeaderTest extends TestCase
     public function setUp(): void
     {
         parent::setUp(); // TODO: Change the autogenerated stub
-        $startDate = \Illuminate\Support\Carbon::parse('2020-11-09 17:59:00')->subSeconds(300);
+        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
         $this->service=app(RejectedBillService::class);
         $this->asnHeaders=OracleDOCASNHeader::query()
             ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
@@ -71,6 +71,7 @@ class SyncLoadedStatusByAsnHeaderTest extends TestCase
     }
     public function tearDown(): void
     {
+        if (!$this->params)return;
         $rejectBills=RejectedBill::query()->whereIn('logistic_number_return', $this->params)->get();
         foreach ($rejectBills as $rejectBill){
             $rejectBill->is_loaded=0;

+ 1 - 1
tests/Services/StoreItemService/GetAsnDetailsByAsnHerderTest.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace Tests\Services\StoreService;
+namespace Tests\Services\StoreItemService;
 
 
 use App\OracleDOCASNHeader;

+ 1 - 1
tests/Services/StoreItemService/GetByWmsTest.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace Tests\Services\StoreService;
+namespace Tests\Services\StoreItemService;
 
 
 use App\OracleDOCASNHeader;

+ 1 - 1
tests/Services/StoreItemService/GetParamsByAsnDetailsTest.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace Tests\Services\StoreService;
+namespace Tests\Services\StoreItemService;
 
 
 use App\OracleDOCASNHeader;

+ 1 - 1
tests/Services/StoreService/GetAsnSyncAtTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Services\OrderService;
+namespace Tests\Services\StoreService;
 
 use App\Services\OrderService;
 use App\Services\StoreService;

+ 1 - 1
tests/Services/StoreService/SetAsnSyncAtTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Services\OrderService;
+namespace Tests\Services\StoreService;
 
 use App\Services\OrderService;
 use App\Services\StoreService;

+ 1 - 1
tests/Services/StoreService/SetLastRecordsByRedisTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Services\OrderService;
+namespace Tests\Services\StoreService;
 
 use App\OracleDOCASNHeader;
 use App\Services\StoreService;

+ 1 - 1
tests/Services/StoreService/SyncStoreCreateByWmsTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Services\OrderService\SyncOrderTest;
+namespace Tests\Services\StoreService;
 
 use App\Logistic;
 use App\OracleDOCASNHeader;

+ 1 - 1
tests/Services/StoreService/SyncStoreUpdateByWmsTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Services\OrderService\SyncOrderTest;
+namespace Tests\Services\StoreService;
 
 use App\Logistic;
 use App\OracleDOCASNHeader;