UserLabelRepository.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\user;
  12. use app\common\dao\user\UserLabelDao;
  13. use app\common\repositories\BaseRepository;
  14. use FormBuilder\Exception\FormBuilderException;
  15. use FormBuilder\Factory\Elm;
  16. use FormBuilder\Form;
  17. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\DbException;
  19. use think\db\exception\ModelNotFoundException;
  20. use think\facade\Route;
  21. /**
  22. * Class UserLabelRepository
  23. * @package app\common\repositories\user
  24. * @author xaboy
  25. * @day 2020-05-07
  26. * @mixin UserLabelDao
  27. */
  28. class UserLabelRepository extends BaseRepository
  29. {
  30. /**
  31. * @var UserLabelDao
  32. */
  33. protected $dao;
  34. /**
  35. * UserGroupRepository constructor.
  36. * @param UserLabelDao $dao
  37. */
  38. public function __construct(UserLabelDao $dao)
  39. {
  40. $this->dao = $dao;
  41. }
  42. /**
  43. * @param array $where
  44. * @param $page
  45. * @param $limit
  46. * @return array
  47. * @throws DataNotFoundException
  48. * @throws DbException
  49. * @throws ModelNotFoundException
  50. * @author xaboy
  51. * @day 2020-05-07
  52. */
  53. public function getList(array $where, $page, $limit)
  54. {
  55. $query = $this->dao->search($where);
  56. $count = $query->count($this->dao->getPk());
  57. $list = $query->order('label_id DESC')->page($page, $limit)->select();
  58. return compact('count', 'list');
  59. }
  60. /**
  61. * @param null $id
  62. * @param array $formData
  63. * @return Form
  64. * @throws FormBuilderException
  65. * @author xaboy
  66. * @day 2020-05-07
  67. */
  68. public function form($id = null, array $formData = [])
  69. {
  70. $isCreate = is_null($id);
  71. $action = Route::buildUrl($isCreate ? 'systemUserLabelCreate' : 'systemUserLabelUpdate', $isCreate ? [] : compact('id'))->build();
  72. return Elm::createForm($action, [
  73. Elm::input('label_name', '用户标签名称')->required()
  74. ])->setTitle($isCreate ? '添加用户标签' : '编辑用户标签')->formData($formData);
  75. }
  76. /**
  77. * @param $id
  78. * @return Form
  79. * @throws FormBuilderException
  80. * @throws DataNotFoundException
  81. * @throws DbException
  82. * @throws ModelNotFoundException
  83. * @author xaboy
  84. * @day 2020-05-07
  85. */
  86. public function updateForm($id)
  87. {
  88. return $this->form($id, $this->dao->get($id)->toArray());
  89. }
  90. }