generated from liutk/owl-admin-base
总账统计
parent
18349a9ca5
commit
12bc95b45a
|
|
@ -55,6 +55,55 @@ class StatisticsController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 总账统计
|
||||
*/
|
||||
public function ledger(Request $request, StatisticService $statisticService)
|
||||
{
|
||||
$request->validate(
|
||||
rules: [
|
||||
'start_at' => ['bail', 'required', 'date_format:Y-m-d'],
|
||||
'end_at' => ['bail', 'required', 'date_format:Y-m-d'],
|
||||
'before_start_at' => ['bail', 'required', 'date_format:Y-m-d'],
|
||||
'before_end_at' => ['bail', 'required', 'date_format:Y-m-d'],
|
||||
],
|
||||
attributes: [
|
||||
'start_at' => '开始日期',
|
||||
'end_at' => '结束日期',
|
||||
'before_start_at' => '对比开始日期',
|
||||
'before_end_at' => '对比结束日期',
|
||||
],
|
||||
);
|
||||
|
||||
$input = $this->defaultFilterInput($request);
|
||||
|
||||
$ledger = $statisticService->ledger(
|
||||
Carbon::parse($request->input('start_at')),
|
||||
Carbon::parse($request->input('end_at')),
|
||||
$input,
|
||||
);
|
||||
|
||||
$beforeLedger = $statisticService->ledger(
|
||||
Carbon::parse($request->input('before_start_at')),
|
||||
Carbon::parse($request->input('before_end_at')),
|
||||
$input,
|
||||
);
|
||||
|
||||
// 销售涨幅
|
||||
$salesGrowthRate = 0;
|
||||
|
||||
if (bccomp($beforeLedger['sales'], '0', 2) === 0) {
|
||||
$salesGrowthRate = '-';
|
||||
} else {
|
||||
$diff = bcsub($ledger['sales'], $beforeLedger['sales'], 2);
|
||||
$salesGrowthRate = bcdiv(bcmul($diff, '100'), $beforeLedger['sales'], 2);
|
||||
}
|
||||
|
||||
return array_merge($ledger, [
|
||||
'sales_growth_rate' => $salesGrowthRate,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店统计
|
||||
*/
|
||||
|
|
@ -104,27 +153,6 @@ class StatisticsController extends Controller
|
|||
);
|
||||
}
|
||||
|
||||
public function sales2(Request $request, StatisticService $statisticService): array
|
||||
{
|
||||
$request->validate(
|
||||
rules: [
|
||||
'start_at' => ['bail', 'required', 'date_format:Y-m-d'],
|
||||
],
|
||||
attributes: [
|
||||
'start_at' => '开始日期',
|
||||
],
|
||||
);
|
||||
|
||||
// yesterday
|
||||
//
|
||||
|
||||
return $statisticService->sales(
|
||||
Carbon::parse($request->input('start_at')),
|
||||
Carbon::parse($request->input('end_at')),
|
||||
$this->defaultFilterInput($request),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理区域和门店过滤条件
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use Illuminate\Support\Facades\DB;
|
|||
class StatisticService
|
||||
{
|
||||
/**
|
||||
* 上报数据统计
|
||||
* 总账统计
|
||||
*/
|
||||
public function ledger(Carbon $start, Carbon $end, array $input = []): array
|
||||
{
|
||||
|
|
@ -32,7 +32,7 @@ class StatisticService
|
|||
}
|
||||
|
||||
/**
|
||||
* 上报数据趋势
|
||||
* 总账数据趋势
|
||||
*/
|
||||
public function ledgerTrends(Carbon $start, Carbon $end, array $input = []): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ Route::group([
|
|||
Route::get('/statistics/stores', [StatisticsController::class, 'stores']);
|
||||
// 统计数据 - 销售统计
|
||||
Route::get('/statistics/sales', [StatisticsController::class, 'sales']);
|
||||
// 统计数据 - 总账统计
|
||||
Route::get('/statistics/ledger', [StatisticsController::class, 'ledger']);
|
||||
|
||||
// 数据上报
|
||||
Route::apiResource('/ledgers', LedgerController::class)->only(['store', 'show']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue