Преглед изворни кода

Merge branch 'zengjun' of ssh://was.baoshi56.com:10022/var/git/bswas

LD пре 5 година
родитељ
комит
96e129d313

+ 11 - 10
app/Http/Controllers/OrderTrackingController.php

@@ -77,17 +77,18 @@ class OrderTrackingController extends Controller
             return ['success'=>false,'fail_info'=>'没有对应权限'];
         try {
             $logistic = Logistic::query()->where('name',$request['value'])->first();
-            $order = Order::query()->whereHas('packages.commodities.orderTracking',function($query)use($request){
-                $query->where('id',$request['id']);
-            })->first();
-            $order->update(['logistic_id'=>$logistic->id]);
-            app('LogService')->log(__METHOD__, __FUNCTION__, '更新成功' . json_encode($request->getContent()));
-            return ['success'=>true];
+            $bool = OrderTracking::query()->where('id',$request['id'])->update(['logistic_id'=>$logistic['id']]);
+            if($bool){
+                app('LogService')->log(__METHOD__, __FUNCTION__, '更新成功' . json_encode($request->getContent()));
+                return ['success'=>true];
+            }else{
+                app('LogService')->log(__METHOD__, __FUNCTION__, '更新失败' . json_encode($request->getContent()));
+                return  ['success'=>false,'fail_info'=>'修改失败'];
+            }
         } catch (\Exception $e) {
             app('LogService')->log(__METHOD__, __FUNCTION__, '更新失败' . json_encode($request->getContent()) .'||'.$e->getMessage().'||'.$e->getTraceAsString());
             return ['success' => false,'fail_info'=>$e->getMessage()];
         }
-
     }
 
     public function upload(Request $request)
@@ -162,7 +163,7 @@ class OrderTrackingController extends Controller
         $order_client_code_temp = '';
         $row_count = 0;
         foreach ($orderTrackings as $index=> $orderTracking) {
-            $logistic =  $orderTracking->commodities->package->order->logistic->name ?? '';
+            $logistic =  $orderTracking->logistic->name ?? '';
             if($order_client_code_temp==''){
                 $order_client_code_temp=$orderTracking->order_client_code;
                 $row_count=1;
@@ -192,7 +193,7 @@ class OrderTrackingController extends Controller
             $planning_sent_at=str_split($orderTracking->planning_sent_at,10)[0];
             $signed_at=str_split($orderTracking->signed_at,10)[0];
             $logistic_number =$orderTracking->commodities->package->logistic_number;
-            if($logistic=='新杰物流'||$logistic=='新杰物流到付'){
+            if($logistic=='新杰物流'||$logistic->name=='新杰物流到付'){
                 $logistic_number = $orderTracking->order_client_code;
             }
             if(str_starts_with('null',$logistic_number)){
@@ -212,7 +213,7 @@ class OrderTrackingController extends Controller
                 $orderTracking->gross_weight,
                 $orderTracking->bulk,
                 $orderTracking->pallet_total,
-                $orderTracking->commodities->package->order->logistic->name ??'',
+                $logistic,
                 $logistic_number,
                 $orderTracking->commodities->package->order->city ?? '',
                 $planning_sent_at=='0000-00-00'?'':$planning_sent_at,

+ 85 - 67
app/Http/Controllers/TestController.php

@@ -1090,14 +1090,8 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         $orderTrackingService = app('OrderTrackingService');
         /** @var OrderService $orderService */
         $orderService = app(OrderService::class);
-        /*$owners = app(OrderTrackingOwnerService::class)->getTrackingOrderOwner();*/
-        /*$startDate = \Illuminate\Support\Carbon::parse('2020-10-28 00:00:00')->toDateTimeString();*/
-        $orderNos = ['SO201205001735', 'SO201204003891', 'SO201204003706', 'SO201204002877', 'SO201203003771'];
-        $orderHeaders = OracleDOCOrderHeader::query()->with(['oracleDOCOrderDetails', 'actAllocationDetails', 'oracleBASCode'])
-            ->whereIn('orderno', $orderNos)
-            ->get();
-        $orderService->updateByWmsOrders($orderHeaders);
-        $orderTrackingService->createByWmsOrderHeader($orderHeaders);
+        $date = Carbon::parse('2020-12-15 00:00:00');
+        $orderTrackingService->trackingWmsOrderOnCreate($date);
     }
 
     public function testSyncOrderTask()
@@ -1300,70 +1294,94 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
 
     public function syncOrderTask()
     {
-        $start_data = Carbon::parse('2020-12-10 00:00:00');
-        $orderHeaders = OracleDOCOrderHeader::query()->selectRaw(implode(',', OracleDOCOrderHeaderService::$columns))
-            ->with(['oracleBASCustomer' => function ($query) {
-                $query->selectRaw('BAS_CUSTOMER.CustomerID,BAS_CUSTOMER.Customer_Type,BAS_CUSTOMER.Descr_C,BAS_CUSTOMER.Active_Flag');
-            }, 'oracleDOCOrderDetails' => function ($query) {
-                $query->selectRaw('doc_order_details.orderNo,doc_order_details.customerid,doc_order_details.sku,doc_order_details.QtyOrdered,doc_order_details.Location');
-            }, 'actAllocationDetails' => function ($query) {
-                $query->selectRaw('ACT_Allocation_Details.AllocationDetailsID,ACT_Allocation_Details.OrderNo,ACT_Allocation_Details.Qty_Each,ACT_Allocation_Details.PickToTraceID,ACT_Allocation_Details.CustomerID,ACT_Allocation_Details.Sku,ACT_Allocation_Details.Location');
-            }, 'oracleBASCode' => function ($query) {
-                $query->selectRaw('BAS_Codes.CodeID,BAS_Codes.CodeName_C,BAS_Codes.Code');
-            }, 'orderType' => function ($query) {
-                $query->selectRaw('BAS_Codes.CodeID,BAS_Codes.CodeName_C,BAS_Codes.Code');
-            }])->where('DOC_Order_Header.AddTime', '>', $start_data)
-            ->get();
         $service = new OrderService();
-        $service->syncOrder($orderHeaders);
+        $start_data = Carbon::parse('2020-12-10 00:00:00');
+        $end_data = Carbon::parse('2020-12-11 00:00:00');
+        $orderNos = OracleDOCOrderHeader::query()->selectRaw('orderno')
+            ->where('addTime', '>=', $start_data)
+            ->where('addTime', '<=', $end_data)
+            ->get()->map(function($orderHeader){
+                return $orderHeader->orderno;
+            });
+        $order_no_list = $orderNos->chunk(3000);
+        foreach ($order_no_list as $order_nos) {
+            $orderHeaders = OracleDOCOrderHeader::query()->selectRaw(implode(',', OracleDOCOrderHeaderService::$columns))
+                ->with(['oracleBASCustomer' => function ($query) {
+                    $query->selectRaw('BAS_CUSTOMER.CustomerID,BAS_CUSTOMER.Customer_Type,BAS_CUSTOMER.Descr_C,BAS_CUSTOMER.Active_Flag');
+                }, 'oracleDOCOrderDetails' => function ($query) {
+                    $query->selectRaw('doc_order_details.orderNo,doc_order_details.customerid,doc_order_details.sku,doc_order_details.QtyOrdered,doc_order_details.Location');
+                }, 'actAllocationDetails' => function ($query) {
+                    $query->selectRaw('ACT_Allocation_Details.AllocationDetailsID,ACT_Allocation_Details.OrderNo,ACT_Allocation_Details.Qty_Each,ACT_Allocation_Details.PickToTraceID,ACT_Allocation_Details.CustomerID,ACT_Allocation_Details.Sku,ACT_Allocation_Details.Location');
+                }, 'oracleBASCode' => function ($query) {
+                    $query->selectRaw('BAS_Codes.CodeID,BAS_Codes.CodeName_C,BAS_Codes.Code');
+                }, 'orderType' => function ($query) {
+                    $query->selectRaw('BAS_Codes.CodeID,BAS_Codes.CodeName_C,BAS_Codes.Code');
+                }])
+                ->whereIn('DOC_Order_Header.OrderNo', $order_nos)
+                ->get();
+            $service->syncOrder($orderHeaders);
+            unset($orderHeaders);
+        }
     }
-    public function cleanOrderIssueRepeat()
+
+    public function editOrderTrackingClientNo()
     {
-        ini_set('max_execution_time', 6500);
-        ini_set('memory_limit', '1526M');
-        for ($i = 0; true; $i++) {
-            $orderIssue_unique = \App\OrderIssue::withTrashed()
-                ->selectRaw('count(1) as count,id,order_id')
-                ->whereNotNull('order_id')
-                ->orderByDesc('created_at')
-                ->groupBy('order_id')
-                ->having('count', '>', 1)
-                ->limit(100)
+        $maxId = OrderTracking::query()->orderByDesc('id')->first()->id;
+        for ($i = 0;$i<=$maxId;$i+=100){
+            $orderTrackings = OrderTracking::query()->with('commodities.package.order')
+                ->where('id','>=',$i)
+                ->where('id','<',$i)
                 ->get();
-            if ($orderIssue_unique->count() == 0) return;
-            foreach ($orderIssue_unique as $item) {
-                $orderIssue_delete = OrderIssue::withTrashed()->where('order_id', $item->order_id)->get();
-                /** @var OrderIssue $order_issue_unique */
-                $order_issue_unique = $orderIssue_delete->whereNull('deleted_at')->first();
-                if(!$order_issue_unique) $order_issue_unique = $orderIssue_delete->first();
-                $ids = [];
-                foreach ($orderIssue_delete as $key => $order_issue) {
-                    if ($order_issue->id == $order_issue_unique->id) continue;
-                    $ids[] = $order_issue->id;
-                    if ($order_issue['rejecting_status'] != '未退回') $order_issue_unique['rejecting_status'] = $order_issue['rejecting_status'];
-                    if ($order_issue['situation_explain']) $order_issue_unique['situation_explain'] = $order_issue['situation_explain'];
-                    if ($order_issue['order_issue_type_id']) $order_issue_unique['order_issue_type_id'] = $order_issue['order_issue_type_id'];
-                    if ($order_issue['second_order_id']) $order_issue_unique['second_order_id'] = $order_issue['second_order_id'];
-                    if ($order_issue['is_new_rejecting'] != '无') $order_issue_unique['is_new_rejecting'] = $order_issue['is_new_rejecting'];
-                    if ($order_issue['second_client_no']) $order_issue_unique['second_client_no'] = $order_issue['second_client_no'];
-                    if ($order_issue['final_status']) $order_issue_unique['final_status'] = $order_issue['final_status'];
-                    if ($order_issue['logistic_indemnity_money']) $order_issue_unique['logistic_indemnity_money'] = $order_issue['logistic_indemnity_money'];
-                    if ($order_issue['logistic_express_remission']) $order_issue_unique['logistic_express_remission'] = $order_issue['logistic_express_remission'];
-                    if ($order_issue['baoshi_indemnity_money']) $order_issue_unique['baoshi_indemnity_money'] = $order_issue['baoshi_indemnity_money'];
-                    if ($order_issue['baoshi_express_remission']) $order_issue_unique['baoshi_express_remission'] = $order_issue['baoshi_express_remission'];
-                    if ($order_issue['user_workgroup_id']) $order_issue_unique['user_workgroup_id'] = $order_issue['user_workgroup_id'];
-                    if ($order_issue['custom_code']) $order_issue_unique['custom_code'] = $order_issue['custom_code'];
-                    if ($order_issue['imported_status']) $order_issue_unique['imported_status'] = $order_issue['imported_status'];
-                }
-                if ($order_issue_unique['deleted_at']) $order_issue_unique['deleted_at'] = null;
-                $order_issue_unique->save();
-                $order_issue_unique->同步退单状态();
-                OrderIssue:: withTrashed()->whereIn('id', $ids)->forceDelete();
-                app('LogService')->log(__METHOD__, __FUNCTION__, 'orders_toCombine:' . json_encode($order_issue_unique) . '|toBe OrderId: ' . json_encode($order_issue_unique->id));
-                $orderIssueProcessLogs = \App\OrderIssueProcessLog::query()->whereIn('order_issue_id', $ids)->get();
-                app('LogService')->log(__METHOD__, __FUNCTION__, 'delete order_issue processLogs:' . json_encode($orderIssueProcessLogs));
-                \App\OrderIssueProcessLog::query()->whereIn('order_issue_id', $ids)->forceDelete();
+            $orderTrackings->each(function($orderTracking){
+                if((bool)mb_stristr($orderTracking->clinet,'天猫'))$orderTracking->client = '天猫';
+
+            });
+        }
+    }
+
+    public function testMbStrPos()
+    {
+        $string = '天猫旗舰店';
+        dd((bool)mb_stristr('天猫旗舰店','天猫'));
+    }
+
+    public function orderByDesc()
+    {
+        dd(Owner::query()->orderByDesc('id')->first()->id);
+    }
+
+    public function testOrderissue()
+    {
+        $orderIssue_unique = \App\OrderIssue::withTrashed()
+            ->selectRaw('count(1) as count,id,order_id')
+            ->whereNotNull('order_id')
+            ->orderByDesc('created_at')
+            ->groupBy('order_id')
+            ->having('count', '>', 1)
+            ->limit(100)
+            ->get();
+        if ($orderIssue_unique->count() == 0) return;
+        foreach ($orderIssue_unique as $item) {
+            $orderIssue_delete = OrderIssue::withTrashed()->where('order_id', $item->order_id)->get();
+            /** @var OrderIssue $order_issue_unique */
+            $order_issue_unique = $orderIssue_delete->whereNull('deleted_at')->first();
+            if (!$order_issue_unique) $order_issue_unique = $orderIssue_delete->first();
+            $ids = [];
+            foreach ($orderIssue_delete as $key => $order_issue) {
+                if ($order_issue->id == $order_issue_unique->id) continue;
+                $ids[] = $order_issue->id;
+                if($order_issue['logistic_number_return'])$order_issue_unique['logistic_number_return'] =$order_issue['logistic_number_return'];
+                if($order_issue['rejecting_status']!='未退回')$order_issue_unique['rejecting_status'] =$order_issue['rejecting_status'];
+                if($order_issue['is_new_rejecting']!='无')$order_issue_unique['is_new_rejecting'] =$order_issue['is_new_rejecting'];
+                if($order_issue['user_workgroup_id'])$order_issue_unique['user_workgroup_id'] =$order_issue['user_workgroup_id'];
+                if($order_issue['imported_status']!='正常')$order_issue_unique['imported_status'] =$order_issue['imported_status'];
+                if($order_issue['custom_code'])$order_issue_unique['custom_code'] =$order_issue['custom_code'];
             }
+            $order_issue_unique->save();
+            app('LogService')->log(__METHOD__, __FUNCTION__, '修改OrderIssue:' . json_encode($order_issue_unique));
+            $orderIssues = OrderIssue::query()->whereIn('id',$ids)->get();
+            $bool = OrderIssue::query()->whereIn('id',$ids)->forceDelete();
+            if($bool)app('LogService')->log(__METHOD__, __FUNCTION__, '删除OrderIssue:' . json_encode($orderIssues));
         }
     }
 }

+ 10 - 7
app/Imports/OrderIssueImport.php

@@ -9,6 +9,7 @@ use App\OrderIssue;
 use App\OrderIssueProcessLog;
 use App\OrderIssueType;
 use App\OrderPackage;
+use App\Services\OrderService;
 use App\Services\RejectedService;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Auth;
@@ -25,6 +26,9 @@ class OrderIssueImport implements ToCollection, WithHeadingRow, WithMultipleShee
 
     public function Collection(Collection $collection)
     {
+        /** @var OrderService $orderService */
+        $orderService = app('OrderService');
+
         $endIS = false;
         $headerRow =  $collection->toArray()[0];
         if (!isset($headerRow['原始运单号']) || !isset($headerRow['情况说明']) || !isset($headerRow['问题类别'])) {
@@ -34,7 +38,6 @@ class OrderIssueImport implements ToCollection, WithHeadingRow, WithMultipleShee
         }
         $exception = [];
         $sum = 2;
-        $orderService = app('OrderService');
         $rejectedService = new RejectedService();
         if ($endIS) {
             foreach ($collection as $row) {
@@ -75,20 +78,20 @@ class OrderIssueImport implements ToCollection, WithHeadingRow, WithMultipleShee
                         }
                     }
                 }
-                $client_no = null;$order_no = null;
+                $client_no = null;
+                $order_nos = [];
                 if ($count) {
                     $orderHeader = OracleDOCOrderHeader::query()->where('soreference5', $logistic_number)->first();
                     $client_no = $orderHeader['soreference1'];
-                    $order_no = $orderHeader['orderno'];
+                    $order_nos[] = $orderHeader['orderno'];
                 } else if ($detailCount) {
                     $detail = OracleActAllocationDetails::query()->where('picktotraceid', $logistic_number)->first();
                     $orderHeader = OracleDOCOrderHeader::query()->where('orderno', $detail['orderno'])->first();
                     $client_no = $orderHeader['soreference1'];
-                    $order_no = $orderHeader['orderno'];
+                    $order_nos[] = $orderHeader['orderno'];
                 }
-                $order = null;
-                if($order_no)$order = Order::query()->where('code',$order_no)->first();
-                if(!$order)$order = $orderService->findOrCreateByClientCode($client_no);
+                $orderService->syncOrderInfoByWmsOrderNos($order_nos);
+                $order = Order::query()->where('code',$order_nos[0])->first();
                 $orderIssue = OrderIssue::query()->where('order_id', $order['id'])->first();
                 $rejectedBill = $rejectedService->getRejectedByClientNo($client_no);
                 if ($orderIssue) {

+ 5 - 1
app/OrderTracking.php

@@ -10,7 +10,8 @@ class OrderTracking extends ModelExtended
 
     use ModelTimeFormat;
     protected $fillable = [
-        'order_package_commodity_id','owner_id','web_order_number',
+        'order_package_commodity_id','owner_id','logistic_id',
+        'web_order_number',
         'pick_up_at','sale','client','order_client_code',
         'order_remark','pallet_total','planning_sent_at',
         'is_on_duty_shift','is_arrival','signed_at',
@@ -45,6 +46,9 @@ class OrderTracking extends ModelExtended
     public function owner(){
         return $this->hasOne(Owner::class,'id','owner_id');
     }
+    public function logistic(){
+        return $this->hasOne(Logistic::class,'id','logistic_id');
+    }
     public function uploadFile()
     {
         return $this->hasOne(UploadFile::class,'table_id','order_client_code')->where('table_name','order_trackings');

+ 6 - 8
app/Services/OrderService.php

@@ -363,8 +363,7 @@ class OrderService
     {
         /** @var OrderPackageService $orderPackageService */
         $orderPackageService = app('OrderPackageService');
-        $order = Order::with('packages.commodities.commodity')->where('client_code', $clientCode)->first();
-        if($order)return $order;
+        $order = Order::query()->where('client_code', $clientCode)->first();
         $orderHeader = app('OracleDocOrderHeaderService')->first(['SOReference1'=> $clientCode]);
         if ($orderHeader == null) {
             return null;
@@ -862,7 +861,6 @@ class OrderService
         $update_order = $this->getUpdateOrderModelByWMSOrderHeaders($orderHeaders,$orders,$warehouses,$owners,$logistics,$shops,$batches);
 
         unset($owners,$logistics,$shops,$warehouses,$batches);
-
         // 转换插入 3s
         if(count($created_params) > 0){
             collect($created_params)->chunk(3500)->each(function($inner_params){
@@ -1220,16 +1218,16 @@ class OrderService
     {
         if(empty($orderNos))return ;
         if(count($orderNos)==0)return;
-        $orderHeaders = $this->oracleDOCOrderHeaderService->getOrderInfoByOrderNos($orderNos);
+        $orderHeaders = app('OracleDocOrderHeaderService')->getOrderInfoByOrderNos($orderNos);
         $this->syncOrderInfoByWMSOrderHeaders($orderHeaders);
     }
 
     public function syncOrderInfoByWMSOrderHeaders($orderHeaders){
-        if(empty($orderNos))return ;
-        if(count($orderNos)==0)return;
+        if(empty($orderHeaders))return ;
+        if(count($orderHeaders)==0)return;
         $this->syncOrderByWMSOrderHeaders($orderHeaders);
-        $this->orderCommodityService->syncOrderCommodities($orderHeaders);
-        $this->packageService->syncOrderPackage($orderHeaders);
+        app('OrderPackageService')->syncOrderPackage($orderHeaders);
+        app("OrderPackageCommoditiesService")->syncOrderPackageCommodities($orderHeaders);
     }
 
     public function update(array $params, array $values)

+ 20 - 17
app/Services/OrderTrackingService.php

@@ -33,10 +33,10 @@ class OrderTrackingService
             $ownerids = explode(",", $params['owner_id']);
             $owner_ids = array_intersect($owner_ids, $ownerids);
         }
-        $query = OrderTracking::query()->with(['owner','uploadFile', 'commodities' => function ($query) {
+        $query = OrderTracking::query()->with(['logistic','owner','uploadFile', 'commodities' => function ($query) {
             $query->with(['commodity'=>function($query){
                 $query->with('barcodes');
-            }, 'package.order.logistic']);
+            }, 'package.order']);
         },])->whereHas('owner', function ($query) use ($owner_ids) {
             $query->whereIn('id', $owner_ids); //货主
         });
@@ -68,17 +68,14 @@ class OrderTrackingService
                 if($params['client_code'] ?? false){
                     $query->where('client_code','like', $params['client_code']);
                 }
-                if(isset($params['logistic_id']) ){
-                    $query->where('logistic_id',$params['logistic_id']);
-                }
             });
         }
 
-        if ($params['client'] ?? false)  // 客户
-            $query->where('client', 'like', $params['client']);
+        if(isset($params['logistic_id']))$query->where('logistic_id',$params['logistic_id']);   // 快递
+
+        if ($params['client'] ?? false) $query->where('client', 'like', $params['client']);  // 客户
 
-        if(!empty($params['web_order_number']))
-            $query->where('web_order_number', 'like', $params['web_order_number'].'%');
+        if(!empty($params['web_order_number'])) $query->where('web_order_number', 'like', $params['web_order_number'].'%'); // web+订单好
 
         if ($params['sku'] ?? false) {
             $query->whereHas('commodities.commodity', function ($query) use ($params) {
@@ -166,7 +163,7 @@ class OrderTrackingService
         $orderService = app(OrderService::class);
         /** @var Collection $orderHeaders */
         $orderHeaders = app(OracleDOCOrderHeaderService::class)->getWmsOrderOnStartDateCreate($startData);
-        $this->customizedOperation($orderHeaders);
+       // $this->customizedOperation($orderHeaders);
         $orderService->createByWmsOrder($orderHeaders);
         $this->createByWmsOrderHeader($orderHeaders);
     }
@@ -176,7 +173,7 @@ class OrderTrackingService
         $orderService = app(OrderService::class);
         /** @var Collection $orderHeaders */
         $orderHeaders = app(OracleDOCOrderHeaderService::class)->getWmsOrderOnStartDateEdit($startData);
-        $this->customizedOperation($orderHeaders);
+       // $this->customizedOperation($orderHeaders);
         $orderService->updateByWmsOrders($orderHeaders);
         $this->updateByWmsOrderHeaders($orderHeaders);
     }
@@ -281,6 +278,7 @@ class OrderTrackingService
             $params[] =[
                 'order_package_commodity_id' => $item->id,
                 'owner_id' => $order->owner_id,
+                'logistic_id' => $param['logistic_id'],
                 'order_client_code' =>$order_client_code,
                 'sale' => $param['sale'],
                 'client' => $param['client'],
@@ -438,6 +436,8 @@ class OrderTrackingService
      */
     public function getParamsByOrderHeaderAndOrder($orderHeader,$order)
     {
+        /** @var LogisticService $logisticService */
+        $logisticService = app('LogisticService');
         $client = $orderHeader['issuepartyname'] ?? '';
         $order_remark = $orderHeader['notes'] ?? '';
         $web_order_number = null;
@@ -446,11 +446,13 @@ class OrderTrackingService
         }
         $pick_up_at = $orderHeader->lastshipmenttime;
         $planning_sent_at = null;
+
+        // 快递方式
+        $logistic = $logisticService->getLogisticByCode($orderHeader['userdefine1']);
+        if($orderHeader['userdefine1'] =='ZT') $logistic = $logisticService->getLogisticByCode('XJWL'); // 自提转新杰物流
         if(isset($pick_up_at)){
-             $logisticTiming = app(LogisticTimingService::class)->findByParams($orderHeader['c_city']??'',$orderHeader['c_province']??'',$order->logistic_id);
-             if($logisticTiming){
-                 $planning_sent_at = Carbon::parse((string)$pick_up_at)->addDays($logisticTiming->days_at_working);
-             }
+             $logisticTiming = app(LogisticTimingService::class)->findByParams($orderHeader['c_city']??'',$orderHeader['c_province']??'',$logistic['id']);
+             if($logisticTiming)$planning_sent_at = Carbon::parse((string)$pick_up_at)->addDays($logisticTiming->days_at_working); // 预期到货时间
         }
         if(stristr($order_remark,'[')){
             $items = [];
@@ -458,10 +460,11 @@ class OrderTrackingService
             $client = $items[1][0];
             $order_remark = $items[3][0];
         }
-        if(stristr($client,'天猫'))$client='天猫';
-        if(stristr($client,'京东'))$client='京东';
+        if(mb_strpos($client,'天猫')!=false)$client='天猫';
+        if(mb_strpos($client,'京东')!=false)$client='京东';
         return [
             'owner_id' => $order->owner_id,
+            'logistic_id' => $logistic['id'],
             'client' => $client,
             'sale' => $orderHeader['issuepartyname'] ?? '',
             'created_at' => $order->created_at,

+ 69 - 0
database/migrations/2020_12_22_143202_change_column_order_id_to_order_issues.php

@@ -0,0 +1,69 @@
+<?php
+
+use App\OrderIssue;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeColumnOrderIdToOrderIssues extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        $this->cleanOrderIssueRepeat();
+        Schema::table('order_issues', function (Blueprint $table) {
+            $table->integer('order_id')->unique('order_issues_order_id_unique')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('order_issues', function (Blueprint $table) {
+            $table->dropUnique('order_issues_order_id_unique');
+        });
+    }
+
+    public function cleanOrderIssueRepeat()
+    {
+        $orderIssue_unique = \App\OrderIssue::withTrashed()
+            ->selectRaw('count(1) as count,id,order_id')
+            ->whereNotNull('order_id')
+            ->orderByDesc('created_at')
+            ->groupBy('order_id')
+            ->having('count', '>', 1)
+            ->limit(100)
+            ->get();
+        if ($orderIssue_unique->count() == 0) return;
+        foreach ($orderIssue_unique as $item) {
+            $orderIssue_delete = OrderIssue::withTrashed()->where('order_id', $item->order_id)->get();
+            /** @var OrderIssue $order_issue_unique */
+            $order_issue_unique = $orderIssue_delete->whereNull('deleted_at')->first();
+            if (!$order_issue_unique) $order_issue_unique = $orderIssue_delete->first();
+            $ids = [];
+            foreach ($orderIssue_delete as $key => $order_issue) {
+                if ($order_issue->id == $order_issue_unique->id) continue;
+                $ids[] = $order_issue->id;
+                if($order_issue['logistic_number_return'])$order_issue_unique['logistic_number_return'] =$order_issue['logistic_number_return'];
+                if($order_issue['rejecting_status']!='未退回')$order_issue_unique['rejecting_status'] =$order_issue['rejecting_status'];
+                if($order_issue['is_new_rejecting']!='无')$order_issue_unique['is_new_rejecting'] =$order_issue['is_new_rejecting'];
+                if($order_issue['user_workgroup_id'])$order_issue_unique['user_workgroup_id'] =$order_issue['user_workgroup_id'];
+                if($order_issue['imported_status']!='正常')$order_issue_unique['imported_status'] =$order_issue['imported_status'];
+                if($order_issue['custom_code'])$order_issue_unique['custom_code'] =$order_issue['custom_code'];
+            }
+            $order_issue_unique->save();
+            app('LogService')->log(__METHOD__, __FUNCTION__, '修改OrderIssue:' . json_encode($order_issue_unique));
+            $orderIssues = OrderIssue::query()->whereIn('id',$ids)->get();
+            $bool = OrderIssue::query()->whereIn('id',$ids)->forceDelete();
+            if($bool)app('LogService')->log(__METHOD__, __FUNCTION__, '删除OrderIssue:' . json_encode($orderIssues));
+        }
+    }
+}

+ 62 - 0
database/migrations/2020_12_23_174008_add_column_logistic_id_to_order_trackings.php

@@ -0,0 +1,62 @@
+<?php
+
+use App\Services\OrderTrackingService;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddColumnLogisticIdToOrderTrackings extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('order_trackings', function (Blueprint $table) {
+            $table->integer('logistic_id')->index()->comment('快递');
+        });
+        $this->migrationLogistic();
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('order_trackings', function (Blueprint $table) {
+            $table->dropColumn('logistic_id');
+        });
+    }
+
+    public function migrationLogistic()
+    {
+        /** @var OrderTrackingService $service */
+        $service = app(OrderTrackingService::class);
+        $maxId= \App\OrderTracking::query()->orderByDesc('id')->first()->id;
+        $logistic = \App\Logistic::query()->where('name','新杰物流')->first();
+        $logistic_zt = \App\Logistic::query()->where('name','自提')->first();
+        for ($i=0;$i<= $maxId;$i+=100){
+            $orderTrackings = \App\OrderTracking::query()
+                ->where('id','>=',$i)
+                ->where('id','<=',$i+100)
+                ->get();
+            if($orderTrackings->count() ==0) return;
+            $update_params = [['id','logistic_id']];
+            $orderTrackings->each(function($orderTracking,$logistic_zt,$logistic,&$update_params){
+                $order =$orderTracking->commodities->package->order;
+                $logistic_id = $order->logistic_id;
+                if($order->logistic_id == $logistic_zt->id)$logistic_id = $logistic->id;
+                $update_params[] = [
+                    'id' => $orderTracking->id,
+                    'logistic_id' => $logistic_id,
+                ];
+            });
+            $service->batchUpdate($update_params);
+            unset($service);
+        }
+    }
+}

+ 10 - 10
resources/views/order/tracking/index.blade.php

@@ -143,13 +143,13 @@
                             @endcan
                         </td>
                         <td class="td-yellow">
-                            <span v-if="['新杰物流','新杰物流到付'].includes(trackOrder.packageLogistic)">
+                            <span v-if="['新杰物流','新杰物流到付'].includes(trackOrder.logistic.name)">
                                 <button class="btn btn-md btn-outline-primary m-0 text-nowrap" @click="changeLogistic(trackOrder,$event)">
-                                    @{{ trackOrder.packageLogistic }}
+                                    @{{ trackOrder.logistic.name }}
                                 </button>
                             </span>
                             <span v-else>
-                                @{{ trackOrder.packageLogistic }}
+                                @{{ trackOrder.logistic.name }}
                             </span>
                         </td>
                         <td class="td-yellow">
@@ -512,19 +512,19 @@
                     }else if(value==='新杰物流到付'){
                         value='新杰物流'
                     }
-                    let data = {id:tackOrder.id,param:'packageLogistic',value:value}
+                    let data = {id:tackOrder.id,param:'logistic_id',value:value}
                     let _this = this
                     axios.post('{{url('apiLocal/order/tracking/updateLogisticId')}}',data).then(function (response) {
-                        tempTip.setDuration(2000)
+                        tempTip.setDuration(2000);
                         if(response.data.success){
-                            tempTip.showSuccess('需改成功')
-                            _this.modifyOrderTracking('packageLogistic',value,tackOrder);
+                            tempTip.showSuccess('修改成功');
+                            tackOrder.logistic.name = value;
                         }else{
-                            tempTip.show(response.data.fail_info)
+                            tempTip.show(response.data.fail_info);
                         }
                     }).catch(function (error) {
-                        tempTip.setDuration(200)
-                        tempTip.show(error)
+                        tempTip.setDuration(200);
+                        tempTip.show(error);
                     })
                 },
                 certiimg(id){