| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace App\Module\UrsPromotion\AdminControllers;
- use App\Module\UrsPromotion\Logics\UrsRelationCacheLogic;
- use App\Module\UrsPromotion\Repositorys\UrsUserRelationCacheRepository;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use UCore\DcatAdmin\AdminController;
- use UCore\DcatAdmin\Helper\FilterHelper;
- use UCore\DcatAdmin\Helper\GridHelper;
- use UCore\DcatAdmin\Helper\ShowHelper;
- /**
- * URS用户关系缓存后台控制器
- *
- * 路由: /admin/urs-promotion/user-relation-cache
- * 菜单位置: URS推广 -> 关系缓存管理
- */
- class UrsUserRelationCacheController extends AdminController
- {
- protected $title = 'URS用户关系缓存';
- /**
- * 列表页面
- */
- protected function grid(): Grid
- {
- $grid = Grid::make(new UrsUserRelationCacheRepository(), function (Grid $grid) {
- $grid->column('id', 'ID')->sortable();
- $grid->column('user_id', '农场用户ID')->sortable();
- $grid->column('related_user_id', '关联农场用户ID(上级)')->sortable();
- $grid->column('urs_user_id', 'URS用户ID')->sortable();
- $grid->column('urs_related_user_id', '关联URS用户ID(上级)')->sortable();
- $grid->column('level', '关系层级')->using([
- 1 => '直接',
- 2 => '间接'
- ])->label([
- 1 => 'success',
- 2 => 'info'
- ])->sortable();
- $grid->column('depth', '层级深度')->sortable();
- $grid->column('path', '关系路径(农场用户)')->limit(50);
- $grid->column('urs_path', 'URS关系路径')->limit(50);
- $grid->column('created_at', '创建时间')->sortable();
- $grid->column('updated_at', '更新时间')->sortable();
- // 筛选器
- $grid->filter(function (Grid\Filter $filter) {
- FilterHelper::addIdFilter($filter);
- $filter->equal('user_id', '农场用户ID');
- $filter->equal('related_user_id', '关联农场用户ID');
- $filter->equal('urs_user_id', 'URS用户ID');
- $filter->equal('urs_related_user_id', '关联URS用户ID');
- $filter->equal('level', '关系层级')->select([
- 1 => '直接',
- 2 => '间接'
- ]);
- $filter->equal('depth', '层级深度');
- FilterHelper::addDateRangeFilter($filter, 'created_at', '创建时间');
- });
- // 工具栏
- $grid->tools(function (Grid\Tools $tools) {
- // 添加重建缓存按钮
- $tools->append('<a href="javascript:void(0)" class="btn btn-primary btn-sm" onclick="rebuildCache()">
- <i class="fa fa-refresh"></i> 重建所有缓存
- </a>');
-
- // 添加检查完整性按钮
- $tools->append('<a href="javascript:void(0)" class="btn btn-info btn-sm" onclick="checkIntegrity()">
- <i class="fa fa-check"></i> 检查完整性
- </a>');
- });
- // 禁用新增和编辑
- $grid->disableCreateButton();
- $grid->disableEditButton();
-
- // 批量操作
- $grid->batchActions(function (Grid\Tools\BatchActions $batch) {
- $batch->disableDelete();
- });
- GridHelper::defaultConfig($grid);
- });
- return $grid;
- }
- /**
- * 详情页面
- */
- protected function detail($id): Show
- {
- return Show::make($id, new UrsUserRelationCacheRepository(), function (Show $show) {
- $show->field('id', 'ID');
- $show->field('user_id', '农场用户ID');
- $show->field('related_user_id', '关联农场用户ID(上级)');
- $show->field('urs_user_id', 'URS用户ID');
- $show->field('urs_related_user_id', '关联URS用户ID(上级)');
- $show->field('level', '关系层级')->using([
- 1 => '直接',
- 2 => '间接'
- ]);
- $show->field('depth', '层级深度');
- $show->field('path', '关系路径(农场用户)');
- $show->field('urs_path', 'URS关系路径');
- $show->field('created_at', '创建时间');
- $show->field('updated_at', '更新时间');
- ShowHelper::defaultConfig($show);
- });
- }
- /**
- * 表单页面(禁用)
- */
- protected function form(): Form
- {
- return Form::make(new UrsUserRelationCacheRepository(), function (Form $form) {
- $form->display('id', 'ID');
- // 关系缓存数据不允许手动编辑
- $form->html('<div class="alert alert-warning">关系缓存数据由系统自动生成,不允许手动编辑</div>');
- });
- }
- /**
- * 重建所有缓存
- */
- public function rebuildCache()
- {
- try {
- $logic = new UrsRelationCacheLogic();
- $result = $logic->rebuildAllRelationCache();
-
- return response()->json([
- 'status' => true,
- 'message' => '缓存重建完成',
- 'data' => $result
- ]);
- } catch (\Exception $e) {
- return response()->json([
- 'status' => false,
- 'message' => '缓存重建失败: ' . $e->getMessage()
- ]);
- }
- }
- /**
- * 检查缓存完整性
- */
- public function checkIntegrity()
- {
- try {
- $logic = new UrsRelationCacheLogic();
- $result = $logic->checkRelationCacheIntegrity();
-
- return response()->json([
- 'status' => true,
- 'message' => '完整性检查完成',
- 'data' => $result
- ]);
- } catch (\Exception $e) {
- return response()->json([
- 'status' => false,
- 'message' => '完整性检查失败: ' . $e->getMessage()
- ]);
- }
- }
- }
|