|
|
@@ -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;
|
|
|
@@ -954,55 +956,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()
|
|
|
- ->select('id')
|
|
|
- ->where('code',$code_repeating)
|
|
|
- ->orderByDesc('updated_at')
|
|
|
+
|
|
|
+ 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();
|
|
|
- $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();
|
|
|
+ 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'];});
|
|
|
})();
|
|
|
- dd();
|
|
|
+ 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);
|
|
|
- })();
|
|
|
- });
|
|
|
-
|
|
|
- dd(11);
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
}
|