|
|
@@ -602,6 +602,8 @@ class NewOrderCountingRecordService
|
|
|
*/
|
|
|
public function recordOrder(string $start, $end = null, string $unit = '日')
|
|
|
{
|
|
|
+ ini_set('max_execution_time', 2 * 60 * 60);
|
|
|
+ ini_set('memory_limit', '1024M');
|
|
|
switch ($unit) {
|
|
|
case '日':
|
|
|
$this->recordByDay($start, $end, $unit);
|
|
|
@@ -637,29 +639,27 @@ class NewOrderCountingRecordService
|
|
|
$end = now()->subDay()->endOfDay();
|
|
|
}
|
|
|
$endDateTime = Carbon::parse($end)->endOfDay()->toDateTimeString();
|
|
|
- $orders = Order::query()
|
|
|
+ Order::query()
|
|
|
->selectRaw("owner_id,warehouse_id,logistic_id,count(1) as amounts ,DATE_FORMAT(updated_at,'%Y-%m-%d') as date_target")
|
|
|
->whereBetween('updated_at', [$startDateTime, $endDateTime])
|
|
|
->where('wms_status', '订单完成')
|
|
|
->groupBy('owner_id', 'warehouse_id', 'logistic_id', 'date_target')
|
|
|
- ->get();
|
|
|
- $insertData = [];
|
|
|
- foreach ($orders as $order) {
|
|
|
- $insertData[] = [
|
|
|
- 'owner_id' => $order->owner_id,
|
|
|
- 'warehouse_id' => $order->warehouse_id,
|
|
|
- 'logistic_id' => $order->logistic_id,
|
|
|
- 'date_target' => $order->date_target,
|
|
|
- 'counting_unit' => $unit,
|
|
|
- 'amount' => $order->amounts ?? 0,
|
|
|
- 'year' => Carbon::parse($order->date_target)->year,
|
|
|
- 'month' => Carbon::parse($order->date_target)->year . '-' . Carbon::parse($order->date_target)->month,
|
|
|
- ];
|
|
|
- }
|
|
|
- $insertDataChunked = array_chunk($insertData, 2000);
|
|
|
- foreach ($insertDataChunked as $items) {
|
|
|
- OrderCountingRecord::query()->insertOrIgnore($items);
|
|
|
- }
|
|
|
+ ->chunk(1000, function ($orders) use ($unit) {
|
|
|
+ $insertData = [];
|
|
|
+ foreach ($orders as $order) {
|
|
|
+ $insertData[] = [
|
|
|
+ 'owner_id' => $order->owner_id,
|
|
|
+ 'warehouse_id' => $order->warehouse_id,
|
|
|
+ 'logistic_id' => $order->logistic_id,
|
|
|
+ 'date_target' => $order->date_target,
|
|
|
+ 'counting_unit' => $unit,
|
|
|
+ 'amount' => $order->amounts ?? 0,
|
|
|
+ 'year' => Carbon::parse($order->date_target)->year,
|
|
|
+ 'month' => Carbon::parse($order->date_target)->year . '-' . Carbon::parse($order->date_target)->month,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ OrderCountingRecord::query()->insert($insertData);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -670,26 +670,27 @@ class NewOrderCountingRecordService
|
|
|
$end = now()->subMonth()->endOfDay();
|
|
|
}
|
|
|
$endDate = Carbon::parse($end)->endOfDay()->toDateString();
|
|
|
- $orderCountingRecords = OrderCountingRecord::query()
|
|
|
+ $records = OrderCountingRecord::query()
|
|
|
->selectRaw("owner_id,warehouse_id,logistic_id,sum(amount) as amount_sum,month,year,date_target")
|
|
|
->whereBetween('date_target', [$startDate, $endDate])
|
|
|
->where('counting_unit', '日')
|
|
|
->groupBy('owner_id', 'warehouse_id', 'logistic_id', 'month', 'date_target')
|
|
|
- ->get();
|
|
|
- $insertData = [];
|
|
|
- foreach ($orderCountingRecords as $orderCountingRecord) {
|
|
|
- $insertData[] = [
|
|
|
- 'owner_id' => $orderCountingRecord->owner_id,
|
|
|
- 'warehouse_id' => $orderCountingRecord->warehouse_id,
|
|
|
- 'logistic_id' => $orderCountingRecord->logistic_id,
|
|
|
- 'counting_unit' => $unit,
|
|
|
- 'date_target' => Carbon::parse($orderCountingRecord->date_target)->startOfMonth()->toDateString(),
|
|
|
- 'amount' => $orderCountingRecord->amount_sum,
|
|
|
- 'year' => $orderCountingRecord->year,
|
|
|
- 'month' => $orderCountingRecord->month,
|
|
|
- ];
|
|
|
- }
|
|
|
- OrderCountingRecord::query()->insertOrIgnore($insertData);
|
|
|
+ ->chunk(1000, function ($records) use ($unit) {
|
|
|
+ $insertData = [];
|
|
|
+ foreach ($records as $record) {
|
|
|
+ $insertData[] = [
|
|
|
+ 'owner_id' => $record->owner_id,
|
|
|
+ 'warehouse_id' => $record->warehouse_id,
|
|
|
+ 'logistic_id' => $record->logistic_id,
|
|
|
+ 'counting_unit' => $unit,
|
|
|
+ 'date_target' => Carbon::parse($record->date_target)->startOfMonth()->toDateString(),
|
|
|
+ 'amount' => $record->amount_sum,
|
|
|
+ 'year' => $record->year,
|
|
|
+ 'month' => $record->month,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ OrderCountingRecord::query()->insertOrIgnore($insertData);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
public function recordByYear(string $start, $end = null, $unit = '年')
|