column('id', 'ID')->sortable(); $grid->column('user_id', '用户ID')->sortable()->display(function ($value) { // 添加到用户绑定和推荐关系的链接 $mappingUrl = admin_url('urs-promotion/user-mappings?user_id=' . $value); $referralUrl = admin_url('urs-promotion/user-referrals?user_id=' . $value); return $value . '
查看绑定关系 | 查看推荐关系 '; }); $grid->column('userMapping.user_id', '用户ID')->sortable()->display(function ($value) { if (!$value) return '未绑定'; // 添加到收益记录的链接 $profitUrl = admin_url('urs-promotion/profits?farm_user_id=' . $value); return $value . '
查看收益记录 '; }); $grid->column('talent_level', '达人等级')->display(function ($value) { return UrsTalentLevel::getLevelName($value); })->label([ 0 => 'default', 1 => 'primary', 2 => 'info', 3 => 'success', 4 => 'warning', 5 => 'danger', ])->sortable(); $grid->column('direct_count', '直推人数')->sortable(); $grid->column('indirect_count', '间推人数')->sortable(); $grid->column('third_count', '三推人数')->sortable(); $grid->column('promotion_count', '团队总人数')->sortable(); $grid->column('last_level_update_time', '最后升级时间')->sortable(); $grid->column('created_at', '创建时间')->sortable(); // 添加批量更新达人等级功能 $grid->tools(function (Grid\Tools $tools) { $tools->append(new \App\Module\UrsPromotion\AdminControllers\Actions\BatchUpdateTalentAction()); }); // 添加单个更新功能 $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->append(new \App\Module\UrsPromotion\AdminControllers\Actions\UpdateTalentAction()); }); $grid->filter(function (Grid\Filter $filter) { UrsUserTalentFilterHelper::make($filter); }); }); } /** * 详情页面 */ protected function detail($id): Show { return Show::make($id, new UrsUserTalentRepository(), function (Show $show) { $show->field('id', 'ID'); $show->field('user_id', '用户ID'); $show->field('talent_level', '达人等级')->using(UrsTalentLevel::getAllLevels()); $show->field('direct_count', '直推人数'); $show->field('indirect_count', '间推人数'); $show->field('third_count', '三推人数'); $show->field('promotion_count', '团队总人数'); $show->field('last_level_update_time', '最后升级时间'); $show->field('created_at', '创建时间'); $show->field('updated_at', '更新时间'); // 显示推荐关系树 $show->divider(); $show->field('referral_tree', '推荐关系树')->unescape()->as(function () { $logic = new \App\Module\UrsPromotion\Logics\UrsTalentLogic(); $tree = $logic->getUserReferralTree($this->user_id); $html = '
'; if (!empty($tree['direct'])) { $html .= '
直推用户 (' . count($tree['direct']) . '人)
'; $html .= ''; } if (!empty($tree['indirect'])) { $html .= '
间推用户 (' . count($tree['indirect']) . '人)
'; $html .= ''; } if (!empty($tree['third'])) { $html .= '
三推用户 (' . count($tree['third']) . '人)
'; $html .= ''; } if (empty($tree['direct']) && empty($tree['indirect']) && empty($tree['third'])) { $html .= '

暂无团队成员

'; } $html .= '
'; return $html; }); // 添加相关链接区域 $show->divider('相关信息'); }); } /** * 表单页面 */ protected function form(): Form { return Form::make(new UrsUserTalentRepository(), function (Form $form) { $form->display('id', 'ID'); $form->number('user_id', '用户ID')->required(); $form->select('talent_level', '达人等级')->options(UrsTalentLevel::getAllLevels())->required(); $form->number('direct_count', '直推人数')->default(0); $form->number('indirect_count', '间推人数')->default(0); $form->number('third_count', '三推人数')->default(0); $form->number('promotion_count', '团队总人数')->default(0); $form->datetime('last_level_update_time', '最后升级时间'); $form->display('created_at', '创建时间'); $form->display('updated_at', '更新时间'); }); } /** * 更新单个用户达人等级 */ public function updateTalent($id) { $talent = UrsUserTalent::find($id); if (!$talent) { return response()->json(['status' => false, 'message' => '用户不存在']); } try { $result = UrsTalentService::updateTalentLevel($talent->user_id); return response()->json(['status' => true, 'message' => '达人等级更新成功']); } catch (\Exception $e) { return response()->json(['status' => false, 'message' => '达人等级更新失败:' . $e->getMessage()]); } } }