|
|
@@ -956,5 +956,57 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
|
|
|
public function view(){
|
|
|
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);
|
|
|
+ }
|
|
|
|
|
|
}
|