SystemStoreStaff.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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\controller\admin\v1\merchant;
  12. use app\services\store\SystemStoreServices;
  13. use app\services\store\SystemStoreStaffServices;
  14. use think\facade\App;
  15. use app\controller\admin\AuthController;
  16. /**
  17. * 店员
  18. * Class SystemStoreStaff
  19. * @package app\controller\admin\v1\merchant
  20. */
  21. class SystemStoreStaff extends AuthController
  22. {
  23. /**
  24. * 构造方法
  25. * SystemStoreStaff constructor.
  26. * @param App $app
  27. * @param SystemStoreStaffServices $services
  28. */
  29. public function __construct(App $app, SystemStoreStaffServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 获取店员列表
  36. * @return mixed
  37. */
  38. public function index()
  39. {
  40. $where = $this->request->getMore([
  41. [['store_id', 'd'], 0],
  42. ]);
  43. return $this->success($this->services->getStoreStaffList($where, ['store', 'user']));
  44. }
  45. /**
  46. * 门店列表
  47. * @return mixed
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function store_list(SystemStoreServices $services)
  53. {
  54. return $this->success($services->getStore());
  55. }
  56. /**
  57. * 店员新增表单
  58. * @return mixed
  59. * @throws \FormBuilder\Exception\FormBuilderException
  60. */
  61. public function create()
  62. {
  63. return $this->success($this->services->createForm());
  64. }
  65. /**
  66. * 店员修改表单
  67. * @return mixed
  68. * @throws \FormBuilder\Exception\FormBuilderException
  69. */
  70. public function edit()
  71. {
  72. [$id] = $this->request->getMore([
  73. [['id', 'd'], 0],
  74. ], true);
  75. return $this->success($this->services->updateForm($id));
  76. }
  77. /**
  78. * 保存店员信息
  79. */
  80. public function save($id = 0)
  81. {
  82. $data = $this->request->postMore([
  83. ['image', ''],
  84. ['uid', 0],
  85. ['avatar', ''],
  86. ['store_id', ''],
  87. ['staff_name', ''],
  88. ['phone', ''],
  89. ['verify_status', 1],
  90. ['status', 1],
  91. ]);
  92. if ($data['store_id'] == '') {
  93. return $this->fail('请选择所属提货点');
  94. }
  95. if ($data['staff_name'] == '') {
  96. return $this->fail('请填写核销员名称');
  97. }
  98. if ($data['phone'] == '') {
  99. return $this->fail('请填写核销员电话');
  100. }
  101. if ($data['uid'] == 0) {
  102. return $this->fail('请选择用户');
  103. }
  104. if (!$id) {
  105. if ($data['image'] == '') {
  106. return $this->fail('请选择用户');
  107. }
  108. if ($this->services->count(['uid' => $data['uid'], 'store_id' => $data['store_id'], 'is_del' => 0])) {
  109. return $this->fail('添加的核销员用户已存在!');
  110. }
  111. $data['uid'] = $data['image']['uid'];
  112. $data['avatar'] = $data['image']['image'];
  113. } else {
  114. $data['avatar'] = $data['image'];
  115. }
  116. unset($data['image']);
  117. if ($id) {
  118. $res = $this->services->update($id, $data);
  119. if ($res) {
  120. return $this->success('编辑成功');
  121. } else {
  122. return $this->fail('编辑失败');
  123. }
  124. } else {
  125. $data['add_time'] = time();
  126. $res = $this->services->save($data);
  127. if ($res) {
  128. return $this->success('核销员添加成功');
  129. } else {
  130. return $this->fail('核销员添加失败,请稍后再试');
  131. }
  132. }
  133. }
  134. /**
  135. * 设置单个店员是否开启
  136. * @param string $is_show
  137. * @param string $id
  138. * @return mixed
  139. */
  140. public function set_show($is_show = '', $id = '')
  141. {
  142. if ($is_show == '' || $id == '') {
  143. $this->fail('缺少参数');
  144. }
  145. $res = $this->services->update($id, ['status' => (int)$is_show]);
  146. if ($res) {
  147. return $this->success($is_show == 1 ? '开启成功' : '关闭成功');
  148. } else {
  149. return $this->fail($is_show == 1 ? '开启失败' : '关闭失败');
  150. }
  151. }
  152. /**
  153. * 删除店员
  154. * @param $id
  155. */
  156. public function delete($id)
  157. {
  158. if (!$id) return $this->fail('数据不存在');
  159. if (!$this->services->delete($id))
  160. return $this->fail('删除失败,请稍候再试!');
  161. else
  162. return $this->success('删除成功!');
  163. }
  164. }