UserIdentityRepository.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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\UserIdentityDao;
  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 UserIdentityRepository
  22. * @package app\common\repositories\user
  23. * @author xaboy
  24. * @day 2020-05-07
  25. * @mixin UserIdentityDao
  26. */
  27. class UserIdentityRepository extends BaseRepository
  28. {
  29. /**
  30. * @var UserIdentityDao
  31. */
  32. protected $dao;
  33. /**
  34. * UserGroupRepository constructor.
  35. * @param UserIdentityDao $dao
  36. */
  37. public function __construct(UserIdentityDao $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. $action = Route::buildUrl('configIdentityUpdate' , compact('id'))->build();
  70. return Elm::createForm($action, [
  71. Elm::number('arrive_num_own', '个人达标贡献值')->min(0)->size('large'),
  72. Elm::number('arrive_num_team', '团队达标贡献值')->min(0)->size('large')
  73. ])->setTitle('业务员升级设置')->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. /**
  90. * @param array $where
  91. * @return array
  92. * @throws DataNotFoundException
  93. * @throws DbException
  94. * @throws ModelNotFoundException
  95. */
  96. public function getIdentityList(array $where = [])
  97. {
  98. $query = $this->dao->search($where);
  99. return $query->select()->toArray();
  100. }
  101. }