SystemStoreStaff.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\merchant;
  12. use app\services\system\store\SystemStoreServices;
  13. use app\services\system\store\SystemStoreStaffServices;
  14. use think\facade\App;
  15. use app\adminapi\controller\AuthController;
  16. /**
  17. * 店员
  18. * Class SystemStoreStaff
  19. * @package app\adminapi\controller\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. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function index()
  42. {
  43. $where = $this->request->getMore([
  44. [['store_id', 'd'], 0],
  45. ]);
  46. return app('json')->success($this->services->getStoreStaffList($where));
  47. }
  48. /**
  49. * 门店列表
  50. * @param SystemStoreServices $services
  51. * @return mixed
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function store_list(SystemStoreServices $services)
  57. {
  58. return app('json')->success($services->getStore());
  59. }
  60. /**
  61. * 店员新增表单
  62. * @return mixed
  63. * @throws \FormBuilder\Exception\FormBuilderException
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. */
  68. public function create()
  69. {
  70. return app('json')->success($this->services->createForm());
  71. }
  72. /**
  73. * 店员修改表单
  74. * @return mixed
  75. * @throws \FormBuilder\Exception\FormBuilderException
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function edit()
  81. {
  82. [$id] = $this->request->getMore([
  83. [['id', 'd'], 0],
  84. ], true);
  85. return app('json')->success($this->services->updateForm($id));
  86. }
  87. /**
  88. * 保存店员信息
  89. * @param int $id
  90. * @return mixed
  91. */
  92. public function save($id = 0)
  93. {
  94. $data = $this->request->postMore([
  95. ['image', ''],
  96. ['uid', 0],
  97. ['avatar', ''],
  98. ['store_id', ''],
  99. ['staff_name', ''],
  100. ['phone', ''],
  101. ['verify_status', 1],
  102. ['status', 1],
  103. ]);
  104. if (!$id) {
  105. if ($data['image'] == '') {
  106. return app('json')->fail(400250);
  107. }
  108. if ($this->services->count(['uid' => $data['image']['uid']])) {
  109. return app('json')->fail(400126);
  110. }
  111. $data['uid'] = $data['image']['uid'];
  112. $data['avatar'] = $data['image']['image'];
  113. } else {
  114. $data['avatar'] = $data['image'];
  115. }
  116. if ($data['uid'] == 0) {
  117. return app('json')->fail(400250);
  118. }
  119. if ($data['store_id'] == '') {
  120. return app('json')->fail(400127);
  121. }
  122. if ($data['staff_name'] == ''){
  123. return app('json')->fail(400128);
  124. }
  125. if ($data['phone'] == ''){
  126. return app('json')->fail(400129);
  127. }
  128. unset($data['image']);
  129. if ($id) {
  130. $res = $this->services->update($id, $data);
  131. if ($res) {
  132. return app('json')->success(100001);
  133. } else {
  134. return app('json')->fail(100007);
  135. }
  136. } else {
  137. $data['add_time'] = time();
  138. $res = $this->services->save($data);
  139. if ($res) {
  140. return app('json')->success(400130);
  141. } else {
  142. return app('json')->fail(400131);
  143. }
  144. }
  145. }
  146. /**
  147. * 设置单个店员是否开启
  148. * @param string $is_show
  149. * @param string $id
  150. * @return mixed
  151. */
  152. public function set_show($is_show = '', $id = '')
  153. {
  154. if ($is_show == '' || $id == '') {
  155. app('json')->fail(100100);
  156. }
  157. $res = $this->services->update($id, ['status' => (int)$is_show]);
  158. if ($res) {
  159. return app('json')->success(100014);
  160. } else {
  161. return app('json')->fail(100015);
  162. }
  163. }
  164. /**
  165. * 删除店员
  166. * @param $id
  167. * @return mixed
  168. */
  169. public function delete($id)
  170. {
  171. if (!$id) return app('json')->fail(100100);
  172. if (!$this->services->delete($id))
  173. return app('json')->fail(100008);
  174. else
  175. return app('json')->success(100002);
  176. }
  177. }