diff --git a/app/Admin/Controllers/Store/StaffPerformanceController.php b/app/Admin/Controllers/Store/StaffPerformanceController.php new file mode 100644 index 00000000..51b7245a --- /dev/null +++ b/app/Admin/Controllers/Store/StaffPerformanceController.php @@ -0,0 +1,103 @@ +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; + } +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index ff64adc5..feafd5a0 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -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'); diff --git a/resources/lang/zh_CN/store-staff-performance.php b/resources/lang/zh_CN/store-staff-performance.php new file mode 100644 index 00000000..d6c620ef --- /dev/null +++ b/resources/lang/zh_CN/store-staff-performance.php @@ -0,0 +1,22 @@ + [ + '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' => [ + ], +];