| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace App\Module\Friend\AdminControllers;
- use App\Module\Friend\AdminControllers\Helper\FilterHelper;
- use App\Module\Friend\AdminControllers\Helper\FormHelper;
- use App\Module\Friend\AdminControllers\Helper\GridHelper;
- use App\Module\Friend\AdminControllers\Helper\ShowHelper;
- use App\Module\Friend\Enums\FRIEND_STATUS;
- use App\Module\Friend\Repositories\FriendRelationRepository;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use UCore\DcatAdmin\AdminController;
- use Spatie\RouteAttributes\Attributes\Resource;
- /**
- * 好友关系管理控制器
- *
- * @package App\Module\Friend\AdminControllers
- */
- #[Resource('friend-relations', names: 'dcat.admin.friend-relations')]
- class FriendRelationController extends AdminController
- {
- /**
- * 标题
- *
- * @var string
- */
- protected $title = '好友关系管理';
- /**
- * 仓库实例
- *
- * @var FriendRelationRepository
- */
- protected $repository;
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->repository = new FriendRelationRepository();
- }
- /**
- * 列表页面
- *
- * @param Grid $grid
- * @return Grid
- */
- protected function grid(Grid $grid)
- {
- $helper = GridHelper::make($grid);
- $helper->id('ID');
- $helper->column('user_id', '用户ID')->sortable();
- $helper->column('friend_id', '好友ID')->sortable();
- $helper->column('remark', '备注名');
- $helper->column('group_id', '分组ID')->sortable();
- $helper->column('intimacy', '亲密度')->sortable();
- $helper->column('status', '状态')->using([
- FRIEND_STATUS::NORMAL => '正常',
- FRIEND_STATUS::SPECIAL => '特别关注',
- FRIEND_STATUS::BLACKLIST => '黑名单',
- ])->label([
- FRIEND_STATUS::NORMAL => 'success',
- FRIEND_STATUS::SPECIAL => 'info',
- FRIEND_STATUS::BLACKLIST => 'danger',
- ]);
- $helper->column('created_at', '创建时间')->sortable();
- $helper->column('updated_at', '更新时间')->sortable();
- // 筛选
- $filter = $grid->filter();
- FilterHelper::make($filter, $this->repository);
- $filter->equal('user_id', '用户ID');
- $filter->equal('friend_id', '好友ID');
- $filter->equal('status', '状态')->select([
- FRIEND_STATUS::NORMAL => '正常',
- FRIEND_STATUS::SPECIAL => '特别关注',
- FRIEND_STATUS::BLACKLIST => '黑名单',
- ]);
- $filter->between('created_at', '创建时间')->datetime();
- return $grid;
- }
- /**
- * 详情页面
- *
- * @param Show $show
- * @return Show
- */
- protected function detail(Show $show)
- {
- $helper = ShowHelper::make($show);
- $helper->field('id', 'ID');
- $helper->field('user_id', '用户ID');
- $helper->field('friend_id', '好友ID');
- $helper->field('remark', '备注名');
- $helper->field('group_id', '分组ID');
- $helper->field('intimacy', '亲密度');
- $helper->field('status', '状态')->using([
- FRIEND_STATUS::NORMAL => '正常',
- FRIEND_STATUS::SPECIAL => '特别关注',
- FRIEND_STATUS::BLACKLIST => '黑名单',
- ]);
- $helper->field('created_at', '创建时间');
- $helper->field('updated_at', '更新时间');
- return $show;
- }
- /**
- * 表单页面
- *
- * @param Form $form
- * @return Form
- */
- protected function form(Form $form)
- {
- $helper = FormHelper::make($form);
- $helper->display('id', 'ID');
- $helper->text('user_id', '用户ID')->required();
- $helper->text('friend_id', '好友ID')->required();
- $helper->text('remark', '备注名');
- $helper->number('group_id', '分组ID')->default(0);
- $helper->number('intimacy', '亲密度')->default(0);
- $helper->select('status', '状态')->options([
- FRIEND_STATUS::NORMAL => '正常',
- FRIEND_STATUS::SPECIAL => '特别关注',
- FRIEND_STATUS::BLACKLIST => '黑名单',
- ])->default(FRIEND_STATUS::NORMAL);
- $helper->display('created_at', '创建时间');
- $helper->display('updated_at', '更新时间');
- return $form;
- }
- }
|