SystemStoreStaffDao.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\dao\store;
  12. use app\dao\BaseDao;
  13. use app\model\store\SystemStoreStaff;
  14. /**
  15. * 门店店员
  16. * Class SystemStoreStaffDao
  17. * @package app\dao\system\store
  18. */
  19. class SystemStoreStaffDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return SystemStoreStaff::class;
  28. }
  29. /**
  30. * @return \crmeb\basic\BaseModel
  31. */
  32. public function getWhere()
  33. {
  34. return $this->getModel();
  35. }
  36. /**
  37. * 门店店员搜索器
  38. * @param array $where
  39. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  40. */
  41. public function search(array $where = [])
  42. {
  43. return parent::search($where)->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
  44. if (!isset($where['field_key']) || $where['field_key'] == '') {
  45. $query->whereLike('id|uid|staff_name|phone', '%' . $where['keyword'] . '%');
  46. } else {
  47. $query->where($where['field_key'], $where['keyword']);
  48. }
  49. });
  50. }
  51. /**
  52. * 获取门店管理员列表
  53. * @param array $where
  54. * @param int $page
  55. * @param int $limit
  56. * @param array|string[] $with
  57. * @return array
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function getStoreAdminList(array $where, int $page = 0, int $limit = 0, array $with = ['user'])
  63. {
  64. return $this->search($where)->when($with, function ($query) use ($with) {
  65. $query->with($with);
  66. })->when($page && $limit, function ($query) use ($page, $limit) {
  67. $query->page($page, $limit);
  68. })->order('add_time DESC')->select()->toArray();
  69. }
  70. /**
  71. * 获取店员列表
  72. * @param array $where
  73. * @param string $field
  74. * @param int $page
  75. * @param int $limit
  76. * @param array|string[] $with
  77. * @return array
  78. * @throws \think\db\exception\DataNotFoundException
  79. * @throws \think\db\exception\DbException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. */
  82. public function getStoreStaffList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = ['store', 'user'])
  83. {
  84. return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
  85. $query->with(array_merge($with, ['store', 'user']));
  86. })->when($page && $limit, function ($query) use ($page, $limit) {
  87. $query->page($page, $limit);
  88. })->when(isset($where['notId']), function ($query) use ($where) {
  89. $query->where('id', '<>', $where['notId']);
  90. })->when(isset($where['store_id']), function ($query) use ($where) {
  91. $query->where('store_id', $where['store_id']);
  92. })->order('add_time DESC')->select()->toArray();
  93. }
  94. /**
  95. * 获取店员select
  96. * @param array $where
  97. * @return array
  98. */
  99. public function getSelectList(array $where)
  100. {
  101. return $this->search($where)->field('id,staff_name')->select()->toArray();
  102. }
  103. /**
  104. * 用户注销删除门店店员
  105. * @param int $uid
  106. * @return \crmeb\basic\BaseModel
  107. */
  108. public function cancelUserDel(int $uid)
  109. {
  110. return $this->getModel()->where('uid', $uid)->where('level', '>', 0)->update(['is_del' => 1]);
  111. }
  112. }