|
|
@@ -11,6 +11,7 @@ use App\Warehouse;
|
|
|
use Carbon\Carbon;
|
|
|
use DateTime;
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use App\User;
|
|
|
use Illuminate\Support\Str;
|
|
|
@@ -45,24 +46,27 @@ class OrderCountingRecordService
|
|
|
return $resultByCache['resultOrders'];
|
|
|
}
|
|
|
|
|
|
- public function orderCountingRecords($start, $end, $unit = '日')
|
|
|
+ public function orderCountingRecords($start, $end, $ownerIds = null, $unit = '日', $user = null)
|
|
|
{
|
|
|
- $orders = $this->get($start, $end, null, $unit, null);
|
|
|
- $dataList = collect();
|
|
|
- $orders->groupBy('date_target')->each(function ($items) use (&$dataList, $unit) {
|
|
|
- $counter = $items->reduce(function ($sum, $item) {
|
|
|
- return $sum + $item->amount;
|
|
|
- }, 0);
|
|
|
- $date_target = $items[0]->date_target;
|
|
|
- if ($unit == '周') {
|
|
|
- $date_target = (new DateTime())->setISODate(Str::of($date_target)->explode('-')[0], Str::of($date_target)->explode('-')[1])->format('yy-m-d');
|
|
|
- }
|
|
|
- $dataList->push([
|
|
|
- 'counter' => $counter,
|
|
|
- 'date_target' => $date_target,
|
|
|
- ]);
|
|
|
+ $key = 'orderCountingRecords_' . $start . '_' . $end . '_' . $unit . '_' . Auth::user()->id;
|
|
|
+ return Cache::remember($key, 600, function () use ($start, $end, $unit, $ownerIds, $user) {
|
|
|
+ $orders = $this->get($start, $end, null, $unit, null);
|
|
|
+ $dataList = collect();
|
|
|
+ $orders->groupBy('date_target')->each(function ($items) use (&$dataList, $unit) {
|
|
|
+ $counter = $items->reduce(function ($sum, $item) {
|
|
|
+ return $sum + $item->amount;
|
|
|
+ }, 0);
|
|
|
+ $date_target = $items[0]->date_target;
|
|
|
+ if ($unit == '周') {
|
|
|
+ $date_target = (new DateTime())->setISODate(Str::of($date_target)->explode('-')[0], Str::of($date_target)->explode('-')[1])->format('yy-m-d');
|
|
|
+ }
|
|
|
+ $dataList->push([
|
|
|
+ 'counter' => $counter,
|
|
|
+ 'date_target' => $date_target,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+ return $dataList->sortBy("date_target");
|
|
|
});
|
|
|
- return $dataList->sortBy("date_target");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -74,51 +78,71 @@ class OrderCountingRecordService
|
|
|
*/
|
|
|
public function logisticsCountingRecords($start, $end, $ownerIds = null, $user = null)
|
|
|
{
|
|
|
- $dataList = collect();
|
|
|
- $resultOrders = $this->get($start, $end, $ownerIds, '日', $user);
|
|
|
- $resultOrders->groupBy('logistic_id')->each(function ($item) use (&$dataList) {
|
|
|
- $counter = $item->reduce(function ($sum, $item) {
|
|
|
- return $sum + $item->amount;
|
|
|
- }, 0);
|
|
|
- $dataList->push([
|
|
|
- 'value' => $counter,
|
|
|
- 'logistic_id' => $item[0]->logistic_id,
|
|
|
- ]);
|
|
|
- });
|
|
|
- $map = [];
|
|
|
- $logistics = Logistic::query()->whereIn('id',data_get($dataList,'*.logistic_id'))->get();
|
|
|
- $logistics->each(function($logistic)use(&$map){
|
|
|
- $map[$logistic->id] = $logistic;
|
|
|
- });
|
|
|
- return $dataList->map(function (&$item)use($map){
|
|
|
- $logistic = $map[$item['logistic_id']] ?? '';
|
|
|
- $item['name'] = $logistic->name ??'';
|
|
|
- return $item;
|
|
|
+ $key = 'logisticsCountingRecords_' . $start . '_' . $end . '_' . Auth::user()->id;
|
|
|
+ return Cache::remember($key, 600, function () use ($start, $end, $ownerIds, $user) {
|
|
|
+ $dataList = collect();
|
|
|
+ $resultOrders = $this->get($start, $end, $ownerIds, '日', $user);
|
|
|
+ $resultOrders->groupBy('logistic_id')->each(function ($item) use (&$dataList) {
|
|
|
+ $counter = $item->reduce(function ($sum, $item) {
|
|
|
+ return $sum + $item->amount;
|
|
|
+ }, 0);
|
|
|
+ $dataList->push([
|
|
|
+ 'value' => $counter,
|
|
|
+ 'logistic_id' => $item[0]->logistic_id,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+ $map = [];
|
|
|
+ $logistics = Logistic::query()->whereIn('id', data_get($dataList, '*.logistic_id'))->get();
|
|
|
+ $logistics->each(function ($logistic) use (&$map) {
|
|
|
+ $map[$logistic->id] = $logistic;
|
|
|
+ });
|
|
|
+ return $dataList->map(function (&$item) use ($map) {
|
|
|
+ $logistic = $map[$item['logistic_id']] ?? '';
|
|
|
+ $item['name'] = $logistic->name ?? '';
|
|
|
+ return $item;
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public function warehouseCountingRecords($start, $end, $ownerIds = null, $user = null)
|
|
|
{
|
|
|
- $dataList = collect();
|
|
|
- $resultOrders = $this->get($start, $end, $ownerIds, '日', $user);
|
|
|
- $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['name'] = $warehouse->name ??'';
|
|
|
- return $item;
|
|
|
+ $key = 'warehouseCountingRecords_' . $start . '_' . $end . '_' . Auth::user()->id;
|
|
|
+ return Cache::remember($key, 600, function () use ($start, $end, $ownerIds, $user) {
|
|
|
+ $dataList = collect();
|
|
|
+ $resultOrders = $this->get($start, $end, $ownerIds, '日', $user);
|
|
|
+ $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;
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -264,7 +288,7 @@ class OrderCountingRecordService
|
|
|
}
|
|
|
return Cache::remember(
|
|
|
'PermittingOwnerIds' . '_' . auth()->user()->id . '_' . implode('_', $ownerIds),
|
|
|
- config('cache.rarelyChange'), function () use ($ownerIds, $permittingOwnerIds) {
|
|
|
+ 600, function () use ($ownerIds, $permittingOwnerIds) {
|
|
|
/** @var User $user */
|
|
|
return array_intersect($ownerIds, $permittingOwnerIds);
|
|
|
});
|