FriendRelationController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace App\Module\Friend\AdminControllers;
  3. use App\Module\Friend\AdminControllers\Helper\FilterHelper;
  4. use App\Module\Friend\AdminControllers\Helper\FormHelper;
  5. use App\Module\Friend\AdminControllers\Helper\GridHelper;
  6. use App\Module\Friend\AdminControllers\Helper\ShowHelper;
  7. use App\Module\Friend\Enums\FRIEND_STATUS;
  8. use App\Module\Friend\Repositories\FriendRelationRepository;
  9. use Dcat\Admin\Form;
  10. use Dcat\Admin\Grid;
  11. use Dcat\Admin\Show;
  12. use UCore\DcatAdmin\AdminController;
  13. use Spatie\RouteAttributes\Attributes\Resource;
  14. /**
  15. * 好友关系管理控制器
  16. *
  17. * @package App\Module\Friend\AdminControllers
  18. */
  19. #[Resource('friend-relations', names: 'dcat.admin.friend-relations')]
  20. class FriendRelationController extends AdminController
  21. {
  22. /**
  23. * 标题
  24. *
  25. * @var string
  26. */
  27. protected $title = '好友关系管理';
  28. /**
  29. * 仓库实例
  30. *
  31. * @var FriendRelationRepository
  32. */
  33. protected $repository;
  34. /**
  35. * 构造函数
  36. */
  37. public function __construct()
  38. {
  39. $this->repository = new FriendRelationRepository();
  40. }
  41. /**
  42. * 列表页面
  43. *
  44. * @param Grid $grid
  45. * @return Grid
  46. */
  47. protected function grid(Grid $grid)
  48. {
  49. $helper = GridHelper::make($grid);
  50. $helper->id('ID');
  51. $helper->column('user_id', '用户ID')->sortable();
  52. $helper->column('friend_id', '好友ID')->sortable();
  53. $helper->column('remark', '备注名');
  54. $helper->column('group_id', '分组ID')->sortable();
  55. $helper->column('intimacy', '亲密度')->sortable();
  56. $helper->column('status', '状态')->using([
  57. FRIEND_STATUS::NORMAL => '正常',
  58. FRIEND_STATUS::SPECIAL => '特别关注',
  59. FRIEND_STATUS::BLACKLIST => '黑名单',
  60. ])->label([
  61. FRIEND_STATUS::NORMAL => 'success',
  62. FRIEND_STATUS::SPECIAL => 'info',
  63. FRIEND_STATUS::BLACKLIST => 'danger',
  64. ]);
  65. $helper->column('created_at', '创建时间')->sortable();
  66. $helper->column('updated_at', '更新时间')->sortable();
  67. // 筛选
  68. $filter = $grid->filter();
  69. FilterHelper::make($filter, $this->repository);
  70. $filter->equal('user_id', '用户ID');
  71. $filter->equal('friend_id', '好友ID');
  72. $filter->equal('status', '状态')->select([
  73. FRIEND_STATUS::NORMAL => '正常',
  74. FRIEND_STATUS::SPECIAL => '特别关注',
  75. FRIEND_STATUS::BLACKLIST => '黑名单',
  76. ]);
  77. $filter->between('created_at', '创建时间')->datetime();
  78. return $grid;
  79. }
  80. /**
  81. * 详情页面
  82. *
  83. * @param Show $show
  84. * @return Show
  85. */
  86. protected function detail(Show $show)
  87. {
  88. $helper = ShowHelper::make($show);
  89. $helper->field('id', 'ID');
  90. $helper->field('user_id', '用户ID');
  91. $helper->field('friend_id', '好友ID');
  92. $helper->field('remark', '备注名');
  93. $helper->field('group_id', '分组ID');
  94. $helper->field('intimacy', '亲密度');
  95. $helper->field('status', '状态')->using([
  96. FRIEND_STATUS::NORMAL => '正常',
  97. FRIEND_STATUS::SPECIAL => '特别关注',
  98. FRIEND_STATUS::BLACKLIST => '黑名单',
  99. ]);
  100. $helper->field('created_at', '创建时间');
  101. $helper->field('updated_at', '更新时间');
  102. return $show;
  103. }
  104. /**
  105. * 表单页面
  106. *
  107. * @param Form $form
  108. * @return Form
  109. */
  110. protected function form(Form $form)
  111. {
  112. $helper = FormHelper::make($form);
  113. $helper->display('id', 'ID');
  114. $helper->text('user_id', '用户ID')->required();
  115. $helper->text('friend_id', '好友ID')->required();
  116. $helper->text('remark', '备注名');
  117. $helper->number('group_id', '分组ID')->default(0);
  118. $helper->number('intimacy', '亲密度')->default(0);
  119. $helper->select('status', '状态')->options([
  120. FRIEND_STATUS::NORMAL => '正常',
  121. FRIEND_STATUS::SPECIAL => '特别关注',
  122. FRIEND_STATUS::BLACKLIST => '黑名单',
  123. ])->default(FRIEND_STATUS::NORMAL);
  124. $helper->display('created_at', '创建时间');
  125. $helper->display('updated_at', '更新时间');
  126. return $form;
  127. }
  128. }