|
|
@@ -86,41 +86,22 @@ class NewOrderCountingRecordService
|
|
|
{
|
|
|
$key = 'warehouseCountingRecords_' . $start . '_' . $end . '_' . json_encode($ownerIds);
|
|
|
return Cache::remember($key, config('cache.expirations.warehouseCountingRecords'), function () use ($start, $end, $ownerIds) {
|
|
|
- $dataList = collect();
|
|
|
- $resultOrders = $this->get($start, $end, '日', $ownerIds);
|
|
|
- $resultOrders->groupBy('warehouse_id')->each(function ($item) use (&$dataList) {
|
|
|
- $counter = $item->reduce(function ($sum, $item) {
|
|
|
- return $sum + $item->amount;
|
|
|
- }, 0);
|
|
|
- $dataList->push([
|
|
|
- 'value' => $counter,
|
|
|
- 'warehouse_id' => $item[0]->warehouse_id,
|
|
|
- ]);
|
|
|
- });
|
|
|
- $map = [];
|
|
|
- $logistics = Warehouse::query()->whereIn('id', data_get($dataList, '*.warehouse_id'))->get();
|
|
|
- $logistics->each(function ($warehouse) use (&$map) {
|
|
|
- $map[$warehouse->id] = $warehouse;
|
|
|
- });
|
|
|
- return $dataList->map(function (&$item) use ($map) {
|
|
|
- $warehouse = $map[$item['warehouse_id']] ?? '';
|
|
|
- $item['code'] = $warehouse->name ?? '';
|
|
|
- switch ($item['code']) {
|
|
|
- case 'WH01':
|
|
|
- $item['name'] = '松江一仓';
|
|
|
- break;
|
|
|
- case 'WH02':
|
|
|
- $item['name'] = '松江二仓';
|
|
|
- break;
|
|
|
- case 'WH03':
|
|
|
- $item['name'] = '嘉定一仓';
|
|
|
- break;
|
|
|
- default:
|
|
|
- $item['name'] = '仓库为空';
|
|
|
- break;
|
|
|
- }
|
|
|
- return $item;
|
|
|
- });
|
|
|
+ $dataList = collect();
|
|
|
+ $resultOrders = $this->get($start, $end, '日', $ownerIds);
|
|
|
+ $resultOrders->groupBy('warehouse_id')->each(function ($item) use (&$dataList) {
|
|
|
+ $counter = $item->reduce(function ($sum, $item) {
|
|
|
+ return $sum + $item->amount;
|
|
|
+ }, 0);
|
|
|
+ $warehouse = Warehouse::query()->find($item[0]->warehouse_id);
|
|
|
+
|
|
|
+ $dataList->push([
|
|
|
+ 'value' => $counter,
|
|
|
+ 'warehouse_id' => $item[0]->warehouse_id,
|
|
|
+ 'name' => $warehouse ? $warehouse->name : '仓库为空',
|
|
|
+ 'code' => $warehouse ? $warehouse->code : 'NULL',
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+ return $dataList;
|
|
|
});
|
|
|
}
|
|
|
|