员工业绩
parent
0693198f07
commit
8fb094e408
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Store;
|
||||
|
||||
use App\Enums\OfflineOrderStatus;
|
||||
use App\Models\OfflineOrder;
|
||||
use App\Models\UserInfo;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StaffPerformanceController extends AdminController
|
||||
{
|
||||
protected $translation = 'store-staff-performance';
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
$datetime = request('datetime');
|
||||
// 开始时间
|
||||
$start = $datetime['start'] ?? '';
|
||||
// 结束时间
|
||||
$end = $datetime['end'] ?? '';
|
||||
|
||||
$infoTable = (new UserInfo())->getTable();
|
||||
|
||||
$inviteUsersCounts = UserInfo::select([
|
||||
'inviter_id',
|
||||
DB::raw('count(1) as invite_users_count')
|
||||
])
|
||||
->when($start || $end, function ($builder) use ($start, $end) {
|
||||
if ($start && $end) {
|
||||
return $builder->whereBetween('created_at', [$start, $end]);
|
||||
}
|
||||
|
||||
return $builder->when($start, fn ($builder) => $builder->where('created_at', '>=', $start))
|
||||
->when($end, fn ($builder) => $builder->where('created_at', '<=', $end));
|
||||
})
|
||||
->groupBy('inviter_id');
|
||||
|
||||
$offlineOrderPerformances = OfflineOrder::select([
|
||||
'staff_id',
|
||||
DB::raw('SUM(products_total_amount) as offline_products_total_amount'),
|
||||
DB::raw('SUM(discount_reduction_amount) as offline_discount_reduction_amount'),
|
||||
DB::raw('SUM(points_deduction_amount) offline_points_deduction_amount'),
|
||||
DB::raw('SUM(payment_amount) as offline_payment_amount'),
|
||||
])
|
||||
->where('status', OfflineOrderStatus::Paid)
|
||||
->when($start || $end, function ($builder) use ($start, $end) {
|
||||
if ($start && $end) {
|
||||
return $builder->whereBetween('created_at', [$start, $end]);
|
||||
}
|
||||
|
||||
return $builder->when($start, fn ($builder) => $builder->where('created_at', '>=', $start))
|
||||
->when($end, fn ($builder) => $builder->where('created_at', '<=', $end));
|
||||
})
|
||||
->groupBy('staff_id');
|
||||
|
||||
$builder = UserInfo::with(['user'])
|
||||
->leftJoinSub($inviteUsersCounts, 'invite_users_counts', fn ($join) => $join->on("{$infoTable}.user_id", '=', 'invite_users_counts.inviter_id'))
|
||||
->leftJoinSub($offlineOrderPerformances, 'offline_order_performances', fn ($join) => $join->on("{$infoTable}.user_id", '=', 'offline_order_performances.staff_id'))
|
||||
->select([
|
||||
'user_id',
|
||||
'nickname',
|
||||
'avatar',
|
||||
'invite_users_count',
|
||||
'offline_products_total_amount',
|
||||
'offline_discount_reduction_amount',
|
||||
'offline_points_deduction_amount',
|
||||
'offline_payment_amount',
|
||||
])
|
||||
->where('is_company', true);
|
||||
|
||||
$grid = new Grid($builder);
|
||||
|
||||
$grid->combine('offline_order', [
|
||||
'offline_products_total_amount',
|
||||
'offline_discount_reduction_amount',
|
||||
'offline_points_deduction_amount',
|
||||
'offline_payment_amount',
|
||||
]);
|
||||
|
||||
$grid->column('user_id', 'ID');
|
||||
$grid->column('phone')->display(fn () => $this->user?->phone)->copyable();
|
||||
$grid->column('nickname');
|
||||
$grid->column('invite_users_count')->display(fn ($v) => (int) $v);
|
||||
$grid->column('offline_products_total_amount')->display(fn ($v) => bcdiv($v, 100, 2));
|
||||
$grid->column('offline_discount_reduction_amount')->display(fn ($v) => bcdiv($v, 100, 2));
|
||||
$grid->column('offline_points_deduction_amount')->display(fn ($v) => bcdiv($v, 100, 2));
|
||||
$grid->column('offline_payment_amount')->display(fn ($v) => bcdiv($v, 100, 2));
|
||||
|
||||
$grid->disableRefreshButton();
|
||||
$grid->disableFilterButton();
|
||||
$grid->disableActions();
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->like('user.phone', '手机号')->width(3);
|
||||
$filter->between('datetime')->datetime()->ignore()->width(4);
|
||||
});
|
||||
|
||||
return $grid;
|
||||
}
|
||||
}
|
||||
|
|
@ -203,6 +203,7 @@ Route::group([
|
|||
$router->resource('store/device', 'Store\DeviceController')->names('store.device');
|
||||
$router->resource('store/desk', 'Store\DeskController')->names('store.desk');
|
||||
$router->get('store/stock-total', 'Store\StockTotalController@index')->name('store.stock_total.index');
|
||||
$router->get('store/staff-performances', 'Store\StaffPerformanceController@index')->name('store.staff_performance.index');
|
||||
|
||||
$router->resource('profit', 'OrderProfitController');
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'labels' => [
|
||||
'store' => '门店管理',
|
||||
'StaffPerformance' => '员工业绩',
|
||||
'staff-performances' => '员工业绩',
|
||||
],
|
||||
'fields' => [
|
||||
'phone' => '手机号',
|
||||
'nickname' => '昵称',
|
||||
'invite_users_count' => '邀请人数',
|
||||
'offline_order' => '线下订单',
|
||||
'offline_products_total_amount' => '订单总额',
|
||||
'offline_discount_reduction_amount' => '折扣优惠',
|
||||
'offline_points_deduction_amount' => '积分抵扣',
|
||||
'offline_payment_amount' => '实付金额',
|
||||
'datetime' => '日期',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
];
|
||||
Loading…
Reference in New Issue