PageLinkRepository.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\system\diy;
  12. use app\common\dao\system\diy\PageLinkDao;
  13. use app\common\repositories\BaseRepository;
  14. use FormBuilder\Factory\Elm;
  15. use think\exception\ValidateException;
  16. use think\facade\Route;
  17. class PageLinkRepository extends BaseRepository
  18. {
  19. public function __construct(PageLinkDao $dao)
  20. {
  21. $this->dao = $dao;
  22. }
  23. public function getList(array $where, int $page, int $limit)
  24. {
  25. $query = $this->dao->getSearch($where)->with(['category'])->order('add_time DESC');
  26. $count = $query->count();
  27. $list = $query->page($page, $limit)->select();
  28. return compact('count','list');
  29. }
  30. public function form(?int $id, $isMer)
  31. {
  32. if ($id) {
  33. $formData = $this->dao->get($id)->toArray();
  34. $form = Elm::createForm(Route::buildUrl($isMer ? 'systemDiyPageLinkMerUpdate' : 'systemDiyPageLinkUpdate', ['id' => $id])->build());
  35. } else {
  36. $form = Elm::createForm(Route::buildUrl($isMer ? 'systemDiyPageLinkMerCreate': 'systemDiyPageLinkCreate')->build());
  37. $formData = [];
  38. }
  39. $rule = [
  40. Elm::cascader('cate_id', '上级分类')->options(function () use($isMer) {
  41. $options = app()->make(PageCategoryRepository::class)->getSearch(['status' => 1,'is_mer' => $isMer,'type' => 'link','level' => 3])->column('id value, name label');
  42. return $options;
  43. })->props(['props' => ['checkStrictly' => true, 'emitPath' => false]])
  44. ->filterable(true)
  45. ->appendValidate(Elm::validateInt()->required()->message('请选择上级分类')),
  46. Elm::input('name', '页面名称')->required(),
  47. Elm::input('url', '页面链接')->required(),
  48. Elm::text('param', '参数'),
  49. Elm::switches('status', '是否显示', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
  50. Elm::number('sort', '排序', 0)->precision(0)->max(99999),
  51. ];
  52. $form->setRule($rule);
  53. return $form->setTitle(is_null($id) ? '添加分类' : '编辑分类')->formData($formData);
  54. }
  55. /**
  56. * TODO 分类下的链接列表
  57. * @param int $pid
  58. * @param int $merId
  59. * @return mixed
  60. * @author Qinii
  61. * @day 3/24/22
  62. */
  63. public function getLinkList(int $pid,int $merId)
  64. {
  65. $where['pid'] = $pid;
  66. $where['is_mer'] = $merId ? 1 : 0;
  67. $make = app()->make(PageCategoryRepository::class);
  68. $list = $make->getSearch($where)->with([
  69. 'pageLink',
  70. ])->select();
  71. return $list;
  72. }
  73. }