Browse Source

Merge branch 'Haozi'

zhouzhendong 4 years ago
parent
commit
88542dc184

+ 1 - 1
app/Console/Commands/AccordingToOwnersManualBack.php

@@ -52,7 +52,7 @@ class AccordingToOwnersManualBack extends Command
         $ownerCodes=[];
         foreach ($owners as $owner){
             $intervalTime=Carbon::parse($now)->diffInMinutes(Carbon::parse($owner->last_manual_back_time));
-            if ($intervalTime>18*60 || !$owner->last_manual_back_time){ // 隔天回传情况 或者 货主上次回传时间为null
+            if ($intervalTime>16*60 || !$owner->last_manual_back_time){ // 隔天回传情况 或者 货主上次回传时间为null
                 $manualBackTime=$sys_last_manual_back_time;
                 $ownerCodes=array_unique(data_get($owners,'*.code'));
                 break;

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

@@ -68,6 +68,7 @@ use App\Station;
 use App\StationTask;
 use App\StationTaskMaterialBox;
 use App\Store;
+use App\StoreItem;
 use App\TaskTransaction;
 use App\Unit;
 use App\User;
@@ -523,8 +524,122 @@ sql;
         ]);
     }
 
-    public function teset12313(){
-        dd(route("discharge.storeApi"));
+    public function init_在途异常()
+    {
+        $logistic_numbers = OrderPackage::query()
+            ->select('logistic_number')
+            ->where('exception_status', 5)
+            ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
+            ->pluck('logistic_number');
+        /** @var OrderPackageReceivedSyncService $service */
+        $service = app('OrderPackageReceivedSyncService');
+        $service->syncLogisticRoute(false, $logistic_numbers);
+
+
+//        $logistic_numbers = OrderPackage::query()
+//            ->select(['logistic_number', 'order_id', 'id'])
+//            ->whereIn('order_id', function ($query) {
+//                $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
+//                    $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
+//                });
+//            })
+//            ->where('exception_status', 5)
+//            ->where('created_at', '>=', now()->subDays(20)->toDateTimeString())
+//            ->pluck('logistic_number');
+//        $service->syncLogisticRouteByAliJiSu($logistic_numbers);
+    }
+
+    public function store()
+    {
+        ini_set('max_execution_time', 0);
+        ini_set('memory_limit', '1024M');
+//        $now = Carbon::now();
+//        $startDate = $this->getDate();
+        $startDate = '2021-09-25 13:23:14';
+        $diffDay = 1; // 天数
+        for($i = 0;$i<=$diffDay;$i++){
+            $endDate = Carbon::parse($startDate)->addDays(1)->toDateTimeString();
+            $doc_asn_headers = $this->getDocAsnHeader($startDate,$endDate);
+//            if (count($doc_asn_headers)>0){
+//                $this->syncStores($doc_asn_headers);
+//                $this->syncDate($endDate);
+//            }
+            dump($startDate,$endDate);
+            $startDate = $endDate;
+        }
+        $this->clearCache();
+//        ValueStore::query()->updateOrCreate([
+//            'name' => 'last_asn_sync_task_end_at',
+//        ], [
+//            'name' => 'last_asn_sync_task_end_at',
+//            'value' => $now,
+//        ]);
+    }
+
+
+
+    public function getDocAsnHeader($startDate,$endDate)
+    {
+        return OracleDOCASNHeader::query()
+            ->with(['asnType', 'asnStatus'])
+            ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3','asnreference2')
+            ->where('EditTime', '>=', $startDate)
+            ->where('EditTime', '<=', $endDate)
+            ->whereColumn('EditTime', '<>', 'addTime')
+            ->orderByDesc('EditTime')
+            ->get();
+    }
+
+    public function getDate(){
+        return ValueStore::query()->where('name','asn_last_updated_sync_at')->value('value');
+    }
+
+    public function syncStores($doc_asn_headers){
+        $service = new StoreService();
+        $service->createStore($doc_asn_headers,"update");
+        $service->updateStore($doc_asn_headers);
+        $service->createStoreRejected($doc_asn_headers);
+        unset($doc_asn_headers);
+    }
+
+    public function syncDate($date)
+    {
+        // 同步更新时间
+        ValueStore::query()->updateOrCreate([
+            'name' => 'asn_last_updated_sync_at',
+        ], [
+            'name' => 'asn_last_updated_sync_at',
+            'value' => $date,
+        ]);
+    }
+    public function clearCache()
+    {
+        $service = new StoreService();
+        $update_set = config('sync.asn_sync.cache_prefix.update_set');
+        $update_keys = config('sync.asn_sync.cache_prefix.update_keys');
+        $service->deleteCacheKey($update_set, $update_keys);
+        // 清空保存 ans  号的栈
+        // 清除 更新时间 开始 结束
+    }
+    public function updateStoreItem()
+    {
+        ini_set('max_execution_time', 0);
+        ini_set('memory_limit', '1024M');
+        $storeIds = Store::query()
+            ->where('updated_at', '>=', '2021-09-25 13:21:26')
+            ->whereColumn('updated_at', '<>', 'created_at')
+            ->pluck('id');
+
+        $storeItemMaxIds = StoreItem::query()
+            ->selectRaw('max(id) as max_id')
+            ->whereIn('store_id', $storeIds)
+            ->groupBy(['store_id', 'asn_line_code'])
+            ->get();
+//        dd($storeItemMaxIds->count());
+        $storeItems = StoreItem::query()
+            ->whereIn('store_id', $storeIds)
+            ->whereNotIn('id', $storeItemMaxIds)
+            ->delete();
     }
 
     public function init_SettlementBillReportTask()

+ 7 - 2
app/Services/StoreItemService.php

@@ -72,10 +72,15 @@ class StoreItemService
         $commodityService = app(CommodityService::class);
         $ownerService = app(OwnerService::class);
         $owners = $ownerService->getOwnerByCodes(array_unique(data_get($asnDetails,'*.customerid')));
+        $stores = Store::query()->whereIn('asn_code', array_unique(data_get($asnDetails, '*.asnno')))->get();
         $owner_map=[];
+        $store_map=[];
         foreach ($owners as $owner){
             $owner_map[$owner->code]=$owner->id;
         }
+        foreach ($stores as $store){
+            $store_map[$store->asn_code]=$store->id;
+        }
         $maps = [];
         foreach ($asnDetails as $asnDetail) {
             $value = [
@@ -87,13 +92,13 @@ class StoreItemService
         $commodities=$commodityService->getCommoditiesByMaps($maps);
         $commodities_map= $dataHandlerService->dataHeader(['owner_id','sku'], $commodities);
         $storeItems = $this->getByWms($asnDetails);
-        $storeItem_map = $dataHandlerService->dataHeader(['store_asn_code', 'asn_line_code', 'commodity_id'], $storeItems);
+        $storeItem_map = $dataHandlerService->dataHeader(['store_id', 'asn_line_code', 'commodity_id'], $storeItems);
         $params = [];
         foreach ($asnDetails as $asnDetail) {
             $commodity=$dataHandlerService->getKeyValue(['owner_id'=>$owner_map[$asnDetail->customerid],'sku'=>$asnDetail->sku],$commodities_map);
             if (!$commodity)continue;
             $storeItem = $dataHandlerService
-                ->getKeyValue(['store_asn_code' => $asnDetail->asnno, 'asn_line_code' => $asnDetail->asnlineno, 'commodity_id' => $commodity->id], $storeItem_map);
+                ->getKeyValue(['store_id' => $store_map[$asnDetail->asnno], 'asn_line_code' => $asnDetail->asnlineno, 'commodity_id' => $commodity->id], $storeItem_map);
             if ($storeItem ?? false) continue;
             $status = null;
             if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c == '完全收货') $status = '已入库';

+ 1 - 1
app/Services/StoreService.php

@@ -92,7 +92,7 @@ class StoreService
         if (count($asnHerders)<1) return;
         $last_time = $asnHerders->first()['edittime'];
         $last_records = $asnHerders->where('edittime', $last_time);
-        $this->createStore($asnHerders,"update");
+//        $this->createStore($asnHerders,"update");
         $this->updateStore($asnHerders);
         $this->createStoreRejected($asnHerders);
         $this->deleteCacheKey($update_set, $update_keys);