|
|
@@ -639,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();
|
|
|
- $orderChucked = $orders->chunk(1000);
|
|
|
- foreach ($orderChucked as $orders) {
|
|
|
- $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);
|
|
|
- }
|
|
|
+ ->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);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -677,24 +675,22 @@ class NewOrderCountingRecordService
|
|
|
->whereBetween('date_target', [$startDate, $endDate])
|
|
|
->where('counting_unit', '日')
|
|
|
->groupBy('owner_id', 'warehouse_id', 'logistic_id', 'month', 'date_target')
|
|
|
- ->get();
|
|
|
- $recordChucked = $records->chunk(1000);
|
|
|
- foreach ($recordChucked as $records) {
|
|
|
- $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);
|
|
|
- }
|
|
|
+ ->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 = '年')
|