|
|
@@ -36,9 +36,9 @@ class ControlPanelController extends Controller
|
|
|
{
|
|
|
$ownerIds = $this->getCountingOwnerIds(null);
|
|
|
$menus = app(CheckActiveMenuService::class)->activeMenus();
|
|
|
- $owners=Owner::query()->whereIn('id',$ownerIds)->get();
|
|
|
+ $owners = Owner::query()->whereIn('id', $ownerIds)->get();
|
|
|
$warehousesOrders = app(RealtimePendingOrdersService::class)->warehousesOrders();
|
|
|
- return view('control.panel', compact('owners','menus', 'warehousesOrders'));
|
|
|
+ return view('control.panel', compact('owners', 'menus', 'warehousesOrders'));
|
|
|
}
|
|
|
|
|
|
public function orderCountingRecordsApi(Request $request)
|
|
|
@@ -49,8 +49,8 @@ class ControlPanelController extends Controller
|
|
|
$orderCountingRecordService = app(NewOrderCountingRecordService::class);
|
|
|
$start = Carbon::parse($request->start)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->start;
|
|
|
$end = Carbon::parse($request->end)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->end;
|
|
|
- $ownerIds=$request->owner_ids;
|
|
|
- if (!$ownerIds || in_array('all',$ownerIds)) $ownerIds = $this->getCountingOwnerIds(null);
|
|
|
+ $ownerIds = $request->owner_ids;
|
|
|
+ if (!$ownerIds || in_array('all', $ownerIds)) $ownerIds = $this->getCountingOwnerIds(null);
|
|
|
$orderCountingRecords = $orderCountingRecordService->getOrderCountingRecordsApi($start, $end, $request->unit, $ownerIds);
|
|
|
return compact('orderCountingRecords');
|
|
|
}
|
|
|
@@ -63,8 +63,8 @@ class ControlPanelController extends Controller
|
|
|
$orderCountingRecordService = app(NewOrderCountingRecordService::class);
|
|
|
$start = Carbon::parse($request->start)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->start;
|
|
|
$end = Carbon::parse($request->end)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->end;
|
|
|
- $ownerIds=$request->input('owner_ids');
|
|
|
- if (!$ownerIds || in_array('all',$ownerIds)) $ownerIds = $this->getCountingOwnerIds(null);
|
|
|
+ $ownerIds = $request->input('owner_ids');
|
|
|
+ if (!$ownerIds || in_array('all', $ownerIds)) $ownerIds = $this->getCountingOwnerIds(null);
|
|
|
$logisticsCountingRecords = $orderCountingRecordService->getLogisticRecordsApi($start, $end, $ownerIds);
|
|
|
return compact('logisticsCountingRecords');
|
|
|
}
|
|
|
@@ -112,12 +112,8 @@ class ControlPanelController extends Controller
|
|
|
if (!$ownerIds) {
|
|
|
return $permittingOwnerIds;
|
|
|
}
|
|
|
- return Cache::remember(
|
|
|
- 'PermittingOwnerIds' . '_' . auth()->user()->id . '_' . implode('_', $ownerIds),
|
|
|
- 600, function () use ($ownerIds, $permittingOwnerIds) {
|
|
|
- /** @var User $user */
|
|
|
- return array_intersect($ownerIds, $permittingOwnerIds);
|
|
|
- });
|
|
|
+ //去掉缓存
|
|
|
+ return array_intersect($ownerIds, $permittingOwnerIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -127,12 +123,12 @@ class ControlPanelController extends Controller
|
|
|
{
|
|
|
//转化为Carbon
|
|
|
$start = Carbon::parse(request("start"));
|
|
|
- $end = Carbon::parse(request("end"));
|
|
|
+ $end = Carbon::parse(request("end"));
|
|
|
|
|
|
//定义三个数组 空间换时间 避免结果集二次转换
|
|
|
$title = []; //标题
|
|
|
$data = []; //核心数据,二维数组
|
|
|
- foreach (CarbonPeriod::create($start,$end) as $date){
|
|
|
+ foreach (CarbonPeriod::create($start, $end) as $date) {
|
|
|
/** @var $date Carbon */
|
|
|
$str = $date->format("Y-m-d");
|
|
|
$data[] = $this->getTargetData($str);
|
|
|
@@ -140,26 +136,26 @@ class ControlPanelController extends Controller
|
|
|
}
|
|
|
|
|
|
//大于31天转换为月份显示
|
|
|
- if ($end->diffInDays($start) > 31){
|
|
|
+ if ($end->diffInDays($start) > 31) {
|
|
|
$title = [];
|
|
|
$sign = []; //标记是否已被插入
|
|
|
$dataTemp = []; //临时存储
|
|
|
|
|
|
- foreach ($data as $datum){
|
|
|
- $month = substr($datum["date"],0,7);
|
|
|
- if (!isset($sign[$month])){
|
|
|
- $dataTemp[] = ["date"=>$month,"total"=>$datum["total"],"count"=>$datum["count"],"value"=>$datum["value"]];
|
|
|
+ foreach ($data as $datum) {
|
|
|
+ $month = substr($datum["date"], 0, 7);
|
|
|
+ if (!isset($sign[$month])) {
|
|
|
+ $dataTemp[] = ["date" => $month, "total" => $datum["total"], "count" => $datum["count"], "value" => $datum["value"]];
|
|
|
$title[] = $month;
|
|
|
- $sign[$month] = count($dataTemp)-1;
|
|
|
- }else{
|
|
|
+ $sign[$month] = count($dataTemp) - 1;
|
|
|
+ } else {
|
|
|
$dataTemp[$sign[$month]]["total"] += $datum["total"];
|
|
|
$dataTemp[$sign[$month]]["count"] += $datum["count"];
|
|
|
- $dataTemp[$sign[$month]]["value"] = (string)($dataTemp[$sign[$month]]["total"] ? intval(($dataTemp[$sign[$month]]["count"]/$dataTemp[$sign[$month]]["total"])*100) : 0);
|
|
|
+ $dataTemp[$sign[$month]]["value"] = (string)($dataTemp[$sign[$month]]["total"] ? intval(($dataTemp[$sign[$month]]["count"] / $dataTemp[$sign[$month]]["total"]) * 100) : 0);
|
|
|
}
|
|
|
}
|
|
|
$data = $dataTemp;
|
|
|
}
|
|
|
- $this->success(["title"=>$title,"data"=>$data]);
|
|
|
+ $this->success(["title" => $title, "data" => $data]);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -177,23 +173,23 @@ class ControlPanelController extends Controller
|
|
|
$total = $orderPackageReceivedSyncRecord->succeed_count + $orderPackageReceivedSyncRecord->failed_count;
|
|
|
$data[] = [
|
|
|
'date' => $orderPackageReceivedSyncRecord->recorded_at,
|
|
|
- 'total'=> $total,
|
|
|
- 'count'=>$orderPackageReceivedSyncRecord->succeed_count,
|
|
|
- 'value' => (int)($orderPackageReceivedSyncRecord->succeed_count / $total*100),
|
|
|
- 'logistic_name' =>$orderPackageReceivedSyncRecord->logistic_name
|
|
|
+ 'total' => $total,
|
|
|
+ 'count' => $orderPackageReceivedSyncRecord->succeed_count,
|
|
|
+ 'value' => (int)($orderPackageReceivedSyncRecord->succeed_count / $total * 100),
|
|
|
+ 'logistic_name' => $orderPackageReceivedSyncRecord->logistic_name
|
|
|
];
|
|
|
}
|
|
|
$title = [];
|
|
|
foreach ($data as $data_item) {
|
|
|
$title[] = $data_item['date'];
|
|
|
}
|
|
|
- return ['success' =>true, 'data' =>['data'=>$data,'title'=>$title]];
|
|
|
+ return ['success' => true, 'data' => ['data' => $data, 'title' => $title]];
|
|
|
}
|
|
|
|
|
|
public function exceptionTypeApi(Request $request)
|
|
|
{
|
|
|
- $ownerIds=$request->owner_ids;
|
|
|
- if (!$ownerIds || in_array('all',$ownerIds)) $ownerIds = $this->getCountingOwnerIds(null);
|
|
|
+ $ownerIds = $request->owner_ids;
|
|
|
+ if (!$ownerIds || in_array('all', $ownerIds)) $ownerIds = $this->getCountingOwnerIds(null);
|
|
|
$service = app('OrderPackageExceptionTypeCountingRecordService');
|
|
|
|
|
|
$data = $service->get([
|
|
|
@@ -201,7 +197,7 @@ class ControlPanelController extends Controller
|
|
|
'end_date' => $request->end,
|
|
|
'owner_ids' => $ownerIds,
|
|
|
]);
|
|
|
- $this->success(["title"=>'',"data"=>$data]);
|
|
|
+ $this->success(["title" => '', "data" => $data]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -212,7 +208,7 @@ class ControlPanelController extends Controller
|
|
|
*/
|
|
|
private function getTargetData(string $date)
|
|
|
{
|
|
|
- if ($date == date("Y-m-d")){
|
|
|
+ if ($date == date("Y-m-d")) {
|
|
|
$sql = <<<sql
|
|
|
SELECT DATE_FORMAT(order_packages.created_at,'%Y-%m-%d') date,
|
|
|
SUM(CASE WHEN order_packages.weighed_at IS NOT NULL THEN 1 ELSE 0 END) AS count,
|
|
|
@@ -221,13 +217,13 @@ AND order_packages.created_at >= '{$date} 00:00:00' GROUP BY date
|
|
|
sql;
|
|
|
|
|
|
$pack = DB::selectOne(DB::raw($sql));
|
|
|
- if (!$pack)return ["date"=>$date,"total"=>0,"count"=>0,"value"=>0];
|
|
|
- return ["date"=>$pack->date,"total"=>$pack->total,"count"=>$pack->count,"value"=>(string)($pack->total ? intval(($pack->count/$pack->total)*100) : 0)];
|
|
|
+ if (!$pack) return ["date" => $date, "total" => 0, "count" => 0, "value" => 0];
|
|
|
+ return ["date" => $pack->date, "total" => $pack->total, "count" => $pack->count, "value" => (string)($pack->total ? intval(($pack->count / $pack->total) * 100) : 0)];
|
|
|
}
|
|
|
- return app(CacheService::class)->getOrExecute("weight.".$date,function ()use($date){
|
|
|
- $count = OrderPackageCountingRecord::query()->where("targeted_at",$date)->first();
|
|
|
- if (!$count)return ["date"=>$date,"total"=>0,"count"=>0,"value"=>0];
|
|
|
- return ["date"=>$count->targeted_at,"total"=>$count->total_count,"count"=>$count->un_weigh_count,"value"=>(string)($count->total_count ? intval(($count->un_weigh_count/$count->total_count)*100) : 0)];
|
|
|
- },config("cache.expirations.forever"));
|
|
|
+ return app(CacheService::class)->getOrExecute("weight." . $date, function () use ($date) {
|
|
|
+ $count = OrderPackageCountingRecord::query()->where("targeted_at", $date)->first();
|
|
|
+ if (!$count) return ["date" => $date, "total" => 0, "count" => 0, "value" => 0];
|
|
|
+ return ["date" => $count->targeted_at, "total" => $count->total_count, "count" => $count->un_weigh_count, "value" => (string)($count->total_count ? intval(($count->un_weigh_count / $count->total_count) * 100) : 0)];
|
|
|
+ }, config("cache.expirations.forever"));
|
|
|
}
|
|
|
}
|