Jelajahi Sumber

Merge branch 'LD'

# Conflicts:
#	app/Http/Controllers/TestController.php
LD 5 tahun lalu
induk
melakukan
4214f39447

+ 2 - 0
app/Http/Controllers/OrderIssueController.php

@@ -69,6 +69,7 @@ class OrderIssueController extends Controller
         if (!Gate::allows('订单管理-订单问题件生成')) {
             return redirect(url('/'));
         }
+        /** @var OrderIssueService $orderIssueService */
         $orderIssueService = app('OrderIssueService');
         $orderIssueService->validatorCreate($request)->validate();
         $orderIssue = null;
@@ -275,6 +276,7 @@ class OrderIssueController extends Controller
         if (!$request->filled('clientCode')) {
             return ['success' => false, 'fail_info' => '缺少对应的参数或条件'];
         }
+        /** @var $orderService OrderService*/
         $orderService = app('OrderService');
         $clientCode = $request->input('clientCode');
         $order = Order::query()->where('client_code', $clientCode)->first();

+ 60 - 49
app/Http/Controllers/TestController.php

@@ -26,6 +26,8 @@ use App\OracleDOCOrderHeader;
 use App\OracleDocOrderPackingSummary;
 use App\OracleDOCWaveDetails;
 use App\Order;
+use App\OrderBin;
+use App\OrderCommodity;
 use App\OrderIssue;
 use App\OrderPackage;
 use App\OrderPackageCommodities;
@@ -998,56 +1000,65 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         return view('test');
     }
     public function cleanOrderRepeat(){
-        $orders_repeating=Order::query()
-            ->selectRaw('count(*) as count, code')
-            ->whereNotNull('code')
-            ->groupBy('code')
-            ->having('count', '>', 1)
-            ->limit(10)
-            ->get();
-        $orderCodes=$orders_repeating->each(function ($order){
-            $code_repeating=$order['code'];
-            $orders_toCombine=Order::query()
-                ->where('code',$code_repeating)
-                ->orderByDesc('updated_at')
-                ->get();
-            $orderId_unique=(function()use($orders_toCombine){
-                $order_toLive=$orders_toCombine->first();
-                foreach($orders_toCombine as $key=>$order_toEliminate){
-                    if($key==0)continue;
-                    if(!$order_toLive['batch_id'])$order_toLive['batch_id']=$order_toEliminate['batch_id'];
-                    if(!$order_toLive['owner_id'])$order_toLive['owner_id']=$order_toEliminate['owner_id'];
-                    if(!$order_toLive['status'])$order_toLive['status']=$order_toEliminate['status'];
-                    if(!$order_toLive['created_at'])$order_toLive['created_at']=$order_toEliminate['created_at'];
-                    if(!$order_toLive['code'])$order_toLive['code']=$order_toEliminate['code'];
-                    if(!$order_toLive['shop_id'])$order_toLive['shop_id']=$order_toEliminate['shop_id'];
-                    if(!$order_toLive['owner_id'])$order_toLive['owner_id']=$order_toEliminate['owner_id'];
-                    if(!$order_toLive['client_code'])$order_toLive['client_code']=$order_toEliminate['client_code'];
-                    if(!$order_toLive['logistic_id'])$order_toLive['logistic_id']=$order_toEliminate['logistic_id'];
-                    if(!$order_toLive['consignee_name'])$order_toLive['consignee_name']=$order_toEliminate['consignee_name'];
-                    if(!$order_toLive['consignee_phone'])$order_toLive['consignee_phone']=$order_toEliminate['consignee_phone'];
-                    if(!$order_toLive['province'])$order_toLive['province']=$order_toEliminate['province'];
-                    if(!$order_toLive['city'])$order_toLive['city']=$order_toEliminate['city'];
-                    if(!$order_toLive['district'])$order_toLive['district']=$order_toEliminate['district'];
-                    if(!$order_toLive['address'])$order_toLive['address']=$order_toEliminate['address'];
-                    if(!$order_toLive['wms_status'])$order_toLive['wms_status']=$order_toEliminate['wms_status'];
-                    if(!$order_toLive['status'])$order_toLive['status']=$order_toEliminate['status'];
-                    if(!$order_toLive['warehouse_id'])$order_toLive['warehouse_id']=$order_toEliminate['warehouse_id'];
-                    if(!$order_toLive['wms_edittime'])$order_toLive['wms_edittime']=$order_toEliminate['wms_edittime'];
-                }
-                $order_toLive->save();
-                return $order_toLive['id'];
-            })();
-            $orderIds_toRemove=(function()use($orders_toCombine){
-                $orders_toCombine->shift();
-                return $orders_toCombine->map(function($order){return $order['id'];})->toArray();
-            })();
-//            $orderPackages_toChange=OrderPackage::query()->orWhere
-
-            Order::destroy($orderIds_toRemove);
-        });
 
-        dd(11);
+        ini_set('max_execution_time',2500);
+        ini_set('memory_limit','1526M');
+        for($i=0;true;$i++){
+            $orders_repeating=Order::query()
+                ->selectRaw('count(*) as count, code, id')
+                ->whereNotNull('code')
+                ->groupBy('code')
+                ->having('count', '>', 1)
+                ->limit(100)
+                ->get();
+            if($orders_repeating->count()==0)break;
+            $orders_repeating->each(function ($order){
+                $code_repeating=$order['code'];
+                $orders_toCombine=Order::query()
+                    ->where('code',$code_repeating)
+                    ->orderByDesc('updated_at')
+                    ->get();
+                $orderId_unique=(function()use($orders_toCombine){
+                    $order_toLive=$orders_toCombine->first();
+                    foreach($orders_toCombine as $key=>$order_toEliminate){
+                        if($key==0)continue;
+                        if(!$order_toLive['batch_id'])$order_toLive['batch_id']=$order_toEliminate['batch_id'];
+                        if(!$order_toLive['owner_id'])$order_toLive['owner_id']=$order_toEliminate['owner_id'];
+                        if(!$order_toLive['status'])$order_toLive['status']=$order_toEliminate['status'];
+                        if(!$order_toLive['created_at'])$order_toLive['created_at']=$order_toEliminate['created_at'];
+                        if(!$order_toLive['code'])$order_toLive['code']=$order_toEliminate['code'];
+                        if(!$order_toLive['shop_id'])$order_toLive['shop_id']=$order_toEliminate['shop_id'];
+                        if(!$order_toLive['owner_id'])$order_toLive['owner_id']=$order_toEliminate['owner_id'];
+                        if(!$order_toLive['client_code'])$order_toLive['client_code']=$order_toEliminate['client_code'];
+                        if(!$order_toLive['logistic_id'])$order_toLive['logistic_id']=$order_toEliminate['logistic_id'];
+                        if(!$order_toLive['consignee_name'])$order_toLive['consignee_name']=$order_toEliminate['consignee_name'];
+                        if(!$order_toLive['consignee_phone'])$order_toLive['consignee_phone']=$order_toEliminate['consignee_phone'];
+                        if(!$order_toLive['province'])$order_toLive['province']=$order_toEliminate['province'];
+                        if(!$order_toLive['city'])$order_toLive['city']=$order_toEliminate['city'];
+                        if(!$order_toLive['district'])$order_toLive['district']=$order_toEliminate['district'];
+                        if(!$order_toLive['address'])$order_toLive['address']=$order_toEliminate['address'];
+                        if(!$order_toLive['wms_status'])$order_toLive['wms_status']=$order_toEliminate['wms_status'];
+                        if(!$order_toLive['status'])$order_toLive['status']=$order_toEliminate['status'];
+                        if(!$order_toLive['warehouse_id'])$order_toLive['warehouse_id']=$order_toEliminate['warehouse_id'];
+                        if(!$order_toLive['wms_edittime'])$order_toLive['wms_edittime']=$order_toEliminate['wms_edittime'];
+                    }
+                    $order_toLive->save();
+                    return $order_toLive['id'];
+                })();
+                $orderIds_toRemove=(function()use($orders_toCombine){
+                    $orders_toCombine->shift();
+                    return $orders_toCombine->map(function($order){return $order['id'];});
+                })();
+                OrderPackage::query()->whereIn('order_id',$orderIds_toRemove)->update(['order_id'=>$orderId_unique]);
+                OrderIssue::query()->whereIn('order_id',$orderIds_toRemove)->update(['order_id'=>$orderId_unique]);
+                OrderCommodity::query()->whereIn('order_id',$orderIds_toRemove)->update(['order_id'=>$orderId_unique]);
+                OrderBin::query()->whereIn('order_id',$orderIds_toRemove)->update(['order_id'=>$orderId_unique]);
+                Order::destroy($orderIds_toRemove);
+                app('LogService')->log(__METHOD__,__FUNCTION__,'orders_toCombine:'.json_encode($orderIds_toRemove).'|toBe OrderId: '.json_encode($orderId_unique));
+            });
+            app('LogService')->log(__METHOD__,__FUNCTION__,'orders_repeating:'.$orders_repeating->toJson());
+        }
+        echo $i;
     }
 
 }

+ 1 - 2
app/Http/Controllers/api/thirdPart/weight/PackageController.php

@@ -165,7 +165,6 @@ class PackageController extends Controller
 
     public function new_(Request $requestInitial){
         $request=[];
-        app('LogService')->log(__METHOD__,'cczdelme'.__FUNCTION__,json_encode($requestInitial->all()),null);
         foreach ($requestInitial->all() as $k=>$v){
             $request[strtolower($k)]=$v;
         }
@@ -177,7 +176,7 @@ class PackageController extends Controller
             return json_encode(["msg"=>$errors,"code"=>500,"data"=>null]);
         }
 
-        $id = $request['id']??'00C66186389';
+        $id = $request['id']??'无ID设备';
         $measuringMachine=MeasuringMachine::query()->firstOrCreate(['code'=> $id]);
         $measuringMachine->turnOn();
         $measuringMachine->turnOffInMinutes(30);

+ 4 - 1
app/Services/OrderIssueService.php

@@ -15,6 +15,7 @@ use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Validator;
+use Ramsey\Uuid\Uuid;
 
 class OrderIssueService
 {
@@ -435,7 +436,9 @@ class OrderIssueService
 
     public function createByLogisticNumber(array $arr)
     {
-        $order = Order::query()->create($arr);
+        $order = new Order($arr);
+        $order['code']='null_'.Uuid::uuid4();
+        $order->save();
         app('LogService')->log(__METHOD__,__FUNCTION__,'创建 Order'.json_encode($order));
         $orderIssue = OrderIssue::query()->create($arr);
         $orderIssue['order_id'] = $order['id'];

+ 20 - 16
app/Services/OrderService.php

@@ -470,22 +470,26 @@ class OrderService
         $wareHouse = Warehouse::query()->firstOrCreate(['code'=>$orderHeader->warehouseid],
             ['name'=>$orderHeader->warehouseid,'code'=>$orderHeader->warehouseid]);
 
-         $order =  Order::query()->create([
-            'warehouse_id'=> $wareHouse->id ?? '',
-            'code' => $orderHeader->orderno,
-            'owner_id' => $owner ? $owner->id : null,
-            'wms_status' => $orderHeader->oracleBASCode ? $orderHeader->oracleBASCode->codename_c : null,
-            'created_at' => $orderHeader->addtime,
-            'logistic_id' => $logistics ? $logistics->id : null,
-            'shop_id' => $shop ? $shop->id : null,
-            'consignee_name' => $orderHeader->c_contact,
-            'consignee_phone' => empty($orderHeader->c_tel2)?$orderHeader->c_tel1:$orderHeader->c_tel2,
-            'province' => $orderHeader->c_province,
-            'city' => $orderHeader->c_city,
-            'district' => $orderHeader->c_district,
-            'address' => $orderHeader->c_address1,
-            'client_code' => $orderHeader->soreference1,
-        ]);
+        try{
+            $order =  Order::query()->create([
+                'warehouse_id'=> $wareHouse->id ?? '',
+                'code' => $orderHeader->orderno,
+                'owner_id' => $owner ? $owner->id : null,
+                'wms_status' => $orderHeader->oracleBASCode ? $orderHeader->oracleBASCode->codename_c : null,
+                'created_at' => $orderHeader->addtime,
+                'logistic_id' => $logistics ? $logistics->id : null,
+                'shop_id' => $shop ? $shop->id : null,
+                'consignee_name' => $orderHeader->c_contact,
+                'consignee_phone' => empty($orderHeader->c_tel2)?$orderHeader->c_tel1:$orderHeader->c_tel2,
+                'province' => $orderHeader->c_province,
+                'city' => $orderHeader->c_city,
+                'district' => $orderHeader->c_district,
+                'address' => $orderHeader->c_address1,
+                'client_code' => $orderHeader->soreference1,
+            ]);
+        }catch (\Exception $e){
+            return $this->first(['code'=>$orderHeader->orderno]);
+        }
         app('LogService')->log(__METHOD__,__FUNCTION__,'创建 Order '.json_encode($order));
         return $order;
     }