SystemStoreStaff.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\adminapi\controller\v1\merchant;
  3. use think\facade\Route as Url;
  4. use app\adminapi\controller\AuthController;
  5. use app\models\system\{
  6. SystemStore, SystemStoreStaff as StoreStaffModel
  7. };
  8. use crmeb\services\{
  9. FormBuilder as Form, UtilService as Util
  10. };
  11. class SystemStoreStaff extends AuthController
  12. {
  13. /**
  14. * 获取店员列表
  15. * @return mixed
  16. */
  17. public function index()
  18. {
  19. $where = Util::getMore([
  20. [['page', 'd'], 1],
  21. [['limit', 'd'], 15],
  22. [['store_id', 'd'], 0],
  23. ]);
  24. $where['mer_id'] = $this->merId ?: '';
  25. return $this->success(StoreStaffModel::getList($where));
  26. }
  27. /**
  28. * 门店列表
  29. * @return mixed
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function store_list()
  35. {
  36. return $this->success(SystemStore::verificWhere($this->merId)->field(['id', 'name'])->select()->toArray());
  37. }
  38. /**
  39. * 店员新增表单
  40. * @return mixed
  41. * @throws \FormBuilder\exception\FormBuilderException
  42. */
  43. public function create()
  44. {
  45. $field = [
  46. Form::frameImageOne('image', '商城用户', Url::buildUrl('admin/system.User/list', array('fodder' => 'image')))->icon('ios-add')->width('50%')->height('500px')->setProps(['srcKey'=>'image']),
  47. Form::hidden('uid', 0),
  48. Form::hidden('avatar', ''),
  49. Form::select('store_id', '所属提货点')->setOptions(function () {
  50. $mer_id = $this->merId ?: '';
  51. $list = SystemStore::dropList($mer_id);
  52. $menus = [];
  53. foreach ($list as $menu) {
  54. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  55. }
  56. return $menus;
  57. })->filterable(1),
  58. Form::input('staff_name', '核销员名称')->col(Form::col(24)),
  59. Form::input('phone', '手机号码')->col(Form::col(24)),
  60. Form::radio('verify_status', '核销开关', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  61. Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']])
  62. ];
  63. return $this->makePostForm('添加核销员', $field, Url::buildUrl('/merchant/store_staff/save/0')->suffix(false));
  64. }
  65. /**
  66. * 店员修改表单
  67. * @return mixed
  68. * @throws \FormBuilder\exception\FormBuilderException
  69. */
  70. public function edit()
  71. {
  72. list($id) = Util::getMore([
  73. [['id', 'd'], 0],
  74. ], $this->request, true);
  75. $info = StoreStaffModel::get($id);
  76. if (!$info) return $this->fail('参数错误');
  77. $field = [
  78. Form::frameImageOne('image', '商城用户', Url::buildUrl('admin/system.User/list'), $info['avatar'])->icon('ios-add')->width('50%')->height('500px')->allowRemove(false),
  79. Form::hidden('uid', $info['uid']),
  80. Form::hidden('avatar', $info['avatar']),
  81. Form::select('store_id', '所属提货点', (string)$info->getData('store_id'))->setOptions(function () {
  82. $mer_id = $this->merId ?: '';
  83. $list = SystemStore::dropList($mer_id);
  84. $menus = [];
  85. foreach ($list as $menu) {
  86. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  87. }
  88. return $menus;
  89. })->filterable(1),
  90. Form::input('staff_name', '核销员名称', $info['staff_name'])->col(Form::col(24)),
  91. Form::input('phone', '手机号码', $info['phone'])->col(Form::col(24)),
  92. Form::radio('verify_status', '核销开关', $info['verify_status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  93. Form::radio('status', '状态', $info['status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']])
  94. ];
  95. return $this->makePostForm('修改核销员', $field, Url::buildUrl('/merchant/store_staff/save/' . $info['id'])->suffix(false));
  96. }
  97. /**
  98. * 保存店员信息
  99. */
  100. public function save($id = 0)
  101. {
  102. $data = Util::postMore([
  103. ['image',''],
  104. ['uid', 0],
  105. ['avatar', ''],
  106. ['store_id', ''],
  107. ['staff_name', ''],
  108. ['phone', ''],
  109. ['verify_status', 1],
  110. ['status', 1],
  111. ]);
  112. if (!$id) {
  113. if($data['image']=='') return $this->fail('请选择用户');
  114. if (StoreStaffModel::where('uid', $data['uid'])->count()) return $this->fail('添加的核销员用户已存在!');
  115. $data['uid'] = $data['image']['uid'];
  116. $data['avatar'] = $data['image']['image'];
  117. }
  118. if ($data['uid'] == 0) return $this->fail('请选择用户');
  119. if ($data['store_id'] == '') return $this->fail('请选择所属提货点');
  120. $data['mer_id'] = $this->merId ?: '';
  121. unset($data['image']);
  122. if ($id) {
  123. $res = StoreStaffModel::edit($data, $id);
  124. if ($res) {
  125. return $this->success('编辑成功');
  126. } else {
  127. return $this->fail('编辑失败');
  128. }
  129. } else {
  130. $data['add_time'] = time();
  131. $res = StoreStaffModel::create($data);
  132. if ($res) {
  133. return $this->success('核销员添加成功');
  134. } else {
  135. return $this->fail('核销员添加失败,请稍后再试');
  136. }
  137. }
  138. }
  139. /**
  140. * 设置单个店员是否开启
  141. * @param string $is_show
  142. * @param string $id
  143. * @return mixed
  144. */
  145. public function set_show($is_show = '', $id = '')
  146. {
  147. ($is_show == '' || $id == '') && $this->fail('缺少参数');
  148. $res = StoreStaffModel::where(['id' => $id])->update(['status' => (int)$is_show]);
  149. if ($res) {
  150. return $this->success($is_show == 1 ? '开启成功' : '关闭成功');
  151. } else {
  152. return $this->fail($is_show == 1 ? '开启失败' : '关闭失败');
  153. }
  154. }
  155. /**
  156. * 删除店员
  157. * @param $id
  158. */
  159. public function delete($id)
  160. {
  161. if (!$id) return $this->fail('数据不存在');
  162. if (!StoreStaffModel::be(['id' => $id])) return $this->failed('数据不存在');
  163. if (!StoreStaffModel::del($id))
  164. return $this->fail(StoreStaffModel::getErrorInfo('删除失败,请稍候再试!'));
  165. else
  166. return $this->success('删除成功!');
  167. }
  168. }