员工业绩
parent
3433b3b6b9
commit
d6f4079cd4
|
|
@ -144,6 +144,75 @@ class StaffPerformanceController extends AdminController
|
|||
$filter->between('datetime')->datetime()->ignore()->width(4);
|
||||
});
|
||||
|
||||
$grid->footer(function ($collection) use ($grid, $infoTable, $onlineOrderPerformances, $offlineOrderPerformances) {
|
||||
// 线上订单
|
||||
$onlineQuery = UserInfo::query()
|
||||
->leftJoinSub($onlineOrderPerformances, 'online_performances', fn ($join) => $join->on("{$infoTable}.user_id", '=', 'online_performances.inviter_id'))
|
||||
->select([
|
||||
DB::raw('SUM(online_performances.orders_count) AS orders_count'),
|
||||
DB::raw('SUM(online_performances.points_deduction_amount) AS points_deduction_amount'),
|
||||
DB::raw('SUM(online_performances.payment_amount) AS payment_amount'),
|
||||
DB::raw('SUM(online_performances.profit) AS profit'),
|
||||
])
|
||||
->where('is_company', true);
|
||||
|
||||
// 线下订单
|
||||
$offlineQuery = UserInfo::query()
|
||||
->leftJoinSub($offlineOrderPerformances, 'offline_performances', fn ($join) => $join->on("{$infoTable}.user_id", '=', 'offline_performances.staff_id'))
|
||||
->select([
|
||||
// 线下订单
|
||||
DB::raw('SUM(offline_performances.orders_count) AS orders_count'),
|
||||
DB::raw('SUM(offline_performances.points_deduction_amount) AS points_deduction_amount'),
|
||||
DB::raw('SUM(offline_performances.payment_amount) AS payment_amount'),
|
||||
])
|
||||
->where('is_company', true);
|
||||
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$onlineQuery, &$offlineQuery) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$onlineQuery = call_user_func_array([$onlineQuery, $value['method']], $value['arguments'] ?? []);
|
||||
$offlineQuery = call_user_func_array([$offlineQuery, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
$onlineResults = $onlineQuery->first();
|
||||
|
||||
$onlineOrdersCount = $onlineResults['orders_count'] ?? 0;
|
||||
$onlinePointsDeductionAmount = bcdiv($onlineResults['points_deduction_amount'] ?? 0, 100, 2);
|
||||
$onlinePaymentAmount = bcdiv($onlineResults['payment_amount'] ?? 0, 100, 2);
|
||||
$onlineTotalAmount = bcadd($onlinePointsDeductionAmount, $onlinePaymentAmount, 2);
|
||||
$onlineProfit = $onlineResults['profit'] ?? 0;
|
||||
|
||||
$offlineResults = $offlineQuery->first();
|
||||
$offlineOrdersCount = $offlineResults['orders_count'] ?? 0;
|
||||
$offlinePointsDeductionAmount = bcdiv($offlineResults['points_deduction_amount'] ?? 0, 100, 2);
|
||||
$offlinePaymentAmount = bcdiv($offlineResults['payment_amount'] ?? 0, 100, 2);
|
||||
$offlineTotalAmount = bcadd($offlinePointsDeductionAmount, $offlinePaymentAmount, 2);
|
||||
|
||||
return <<<HTML
|
||||
<table class="table table-bordered">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>线上订单统计</td>
|
||||
<td>订单数: $onlineOrdersCount</td>
|
||||
<td>订单总额: $onlineTotalAmount</td>
|
||||
<td>积分抵扣: $onlinePointsDeductionAmount</td>
|
||||
<td>实付总额: $onlinePaymentAmount</td>
|
||||
<td>累计返利: $onlineProfit</td>
|
||||
<tr>
|
||||
<tr>
|
||||
<td>线下订单统计</td>
|
||||
<td>订单数: $offlineOrdersCount</td>
|
||||
<td>订单总额: $offlineTotalAmount</td>
|
||||
<td>积分抵扣: $offlinePointsDeductionAmount</td>
|
||||
<td colspan="2">实付总额: $offlinePaymentAmount</td>
|
||||
<tr>
|
||||
</tbody>
|
||||
</table>
|
||||
HTML;
|
||||
});
|
||||
|
||||
return $grid;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue