generated from liutk/owl-admin-base
78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Employee;
|
|
use App\Models\Store;
|
|
use App\Models\TaskPerformance;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CockpitController extends Controller
|
|
{
|
|
/**
|
|
* 基础数据统计
|
|
*/
|
|
public function basic(): array
|
|
{
|
|
// 门店总数
|
|
$storesCount = Store::onlyOpen()->count();
|
|
// 员工总数
|
|
$employeesCount = Employee::onlyOnline()->count();
|
|
|
|
return [
|
|
'stores_count' => $storesCount,
|
|
'employees_count' => $employeesCount,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 销售趋势
|
|
*/
|
|
public function salesTrend(Request $request): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 彩种销售趋势
|
|
*/
|
|
public function lotterySalesTrend(Request $request): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 门店销量排名
|
|
*/
|
|
public function storeSalesRanking(Request $request): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 年度目标
|
|
*/
|
|
public function yearlyGoals(Request $request): array
|
|
{
|
|
$request->validate(
|
|
rules: [
|
|
'year' => ['bail', 'required', 'int'],
|
|
],
|
|
);
|
|
|
|
$aggregates = TaskPerformance::select([
|
|
DB::raw('SUM(`expected_performance`) as expected_performance'),
|
|
DB::raw('SUM(`actual_performance`) as actual_performance'),
|
|
])->whereYear(DB::raw("STR_TO_DATE(CONCAT(`month`, '-01'), '%Y-%m-%d')"), $request->input('year'))->first();
|
|
|
|
return [
|
|
// 目标业绩
|
|
'expected_performance' => trim_zeros($aggregates['expected_performance'] ?? 0),
|
|
// 实际业绩
|
|
'actual_performance' => trim_zeros($aggregates['actual_performance'] ?? 0),
|
|
];
|
|
}
|
|
}
|