UserLabelRepository.php 2.3 KB

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