liyinglin 3 years ago
parent 4cb1e2d962
commit dfa139a0a1

@ -0,0 +1,148 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Models\Config;
use App\Models\Visit;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use App\Helpers\ResponseCode;
/**
* 配置
*/
class ChartController extends CommonController
{
/**
* @OA\Get(
* path="/api/admin/chart/month",
* tags={"图表"},
* summary="月度统计",
* description="",
* @OA\Parameter(name="year", in="query", @OA\Schema(type="string"), required=true, description="年份例如2022"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function month()
{
$all = \request()->all();
$messages = [
'year.required' => '年份必填',
];
$validator = Validator::make($all, [
'year' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$monthList = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$list = [];
foreach ($monthList as $item) {
$month = $all['year'] . '-' . $item;
$list[] = [
'month' => $month,
'plan_total'=>Visit::where('date','like',"%{$month}%")->count(),
'enter_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
'cancel_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
];
}
return $this->success($list);
}
/**
* @OA\Get(
* path="/api/admin/chart/time",
* tags={"图表"},
* summary="时段统计",
* description="",
* @OA\Parameter(name="date", in="query", @OA\Schema(type="string"), required=true, description="日期例如2022=01=01"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function time()
{
$all = \request()->all();
$messages = [
'date.required' => '时段必填',
];
$validator = Validator::make($all, [
'date' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$monthList = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$list = [];
foreach ($monthList as $item) {
$month = $all['year'] . '-' . $item;
$list[] = [
'month' => $month,
'plan_total'=>Visit::where('date','like',"%{$month}%")->count(),
'enter_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
'cancel_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
];
}
return $this->success($list);
}
/**
* @OA\Get(
* path="/api/admin/chart/car",
* tags={"图表"},
* summary="车辆统计",
* description="",
* @OA\Parameter(name="year", in="query", @OA\Schema(type="string"), required=true, description="年份例如2022"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function car()
{
$all = \request()->all();
$messages = [
'year.required' => '年份必填',
];
$validator = Validator::make($all, [
'year' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$monthList = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$list = [];
foreach ($monthList as $item) {
$month = $all['year'] . '-' . $item;
$list[] = [
'month' => $month,
'plan_total'=>Visit::where('date','like',"%{$month}%")->count(),
'enter_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
'cancel_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
];
}
return $this->success($list);
}
}

@ -31,7 +31,7 @@ class Visit extends SoftDeletesModel
public function getAuditStatusTextAttribute()
{
$array = ['-1' => '待学习', '0' => '待审核', '1' => '通过', '2' => '驳回', '3' => '已进厂', '4' => '已离厂'];
return $array[$this->type] ?? '';
return $array[$this->audit_status] ?? '';
}
public function visitTime()

@ -26,6 +26,12 @@ Route::get("admin/gate/use-code", [\App\Http\Controllers\Admin\GateController::c
// 后台
Route::group(["namespace" => "Admin", "prefix" => "admin", "middleware" => "sanctum.jwt:admin,rbac"], function () {
// 统计
Route::get("chart/month", [\App\Http\Controllers\Admin\ChartController::class, "month"]);
Route::get("chart/time", [\App\Http\Controllers\Admin\ChartController::class, "time"]);
Route::get("chart/car", [\App\Http\Controllers\Admin\ChartController::class, "car"]);
// 配置管理
Route::get("config/index", [\App\Http\Controllers\Admin\ConfigController::class, "index"]);
Route::get("config/show", [\App\Http\Controllers\Admin\ConfigController::class, "show"]);

Loading…
Cancel
Save