SystemStoreStaff.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\system\SystemStore as StoreModel;
  5. use crmeb\services\FormBuilder as Form;
  6. use crmeb\services\JsonService;
  7. use crmeb\services\JsonService as Json;
  8. use app\admin\model\system\SystemStoreStaff as StaffModel;
  9. use app\admin\model\system\SystemStore;
  10. use crmeb\services\UtilService;
  11. use think\facade\Route as Url;
  12. /**
  13. * 店员管理
  14. * Class StoreStaff
  15. * @package app\store_admin\controller\store
  16. */
  17. class SystemStoreStaff extends AuthController
  18. {
  19. /**
  20. * 店员列表
  21. */
  22. public function list()
  23. {
  24. $where = UtilService::getMore([
  25. ['page', 1],
  26. ['limit', 20],
  27. ['name', ''],
  28. ['store_id', '']
  29. ]);
  30. return JsonService::successlayui(StaffModel::lst($where));
  31. }
  32. /**
  33. * 门店设置
  34. * @return string
  35. */
  36. public function index()
  37. {
  38. $store_list = StoreModel::dropList();
  39. $this->assign('store_list', $store_list);
  40. return $this->fetch();
  41. }
  42. /**
  43. * 店员添加
  44. * @param int $id
  45. * @return string
  46. */
  47. public function create()
  48. {
  49. $field = [
  50. Form::frameImageOne('image', '商城用户', Url::buildUrl('admin/system.SystemStoreStaff/select', array('fodder' => 'image')))->icon('plus')->width('100%')->height('500px'),
  51. Form::hidden('uid', 0),
  52. Form::hidden('avatar', ''),
  53. Form::select('store_id', '所属门店')->setOptions(function () {
  54. $list = SystemStore::dropList();
  55. // $menus[] = ['value' => 0, 'label' => '顶级分类'];
  56. $menus = [];
  57. foreach ($list as $menu) {
  58. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  59. }
  60. return $menus;
  61. })->filterable(1),
  62. Form::input('staff_name', '店员名称')->col(Form::col(24)),
  63. Form::input('phone', '手机号码')->col(Form::col(24)),
  64. Form::radio('verify_status', '核销开关', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  65. Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']])
  66. ];
  67. $form = Form::make_post_form('添加评论', $field, Url::buildUrl('save'), 2);
  68. $this->assign(compact('form'));
  69. return $this->fetch('public/form-builder');
  70. }
  71. /**
  72. * 选择用户
  73. * @param int $id
  74. */
  75. public function select()
  76. {
  77. return $this->fetch();
  78. }
  79. /**
  80. * 编辑表单
  81. * @param $id
  82. * @return string|void
  83. * @throws \FormBuilder\exception\FormBuilderException
  84. */
  85. public function edit($id)
  86. {
  87. $service = StaffModel::get($id);
  88. if (!$service) return Json::fail('数据不存在!');
  89. $f = [
  90. Form::frameImageOne('image', '商城用户', Url::buildUrl('admin/system.SystemStoreStaff/select', array('fodder' => 'image')), $service['avatar'])->icon('plus')->width('100%')->height('500px'),
  91. Form::hidden('uid', $service['uid']),
  92. Form::hidden('avatar', $service['avatar']),
  93. Form::select('store_id', '所属门店', (string)$service->getData('store_id'))->setOptions(function () {
  94. $list = SystemStore::dropList();
  95. // $menus[] = ['value' => 0, 'label' => '顶级分类'];
  96. foreach ($list as $menu) {
  97. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  98. }
  99. return $menus;
  100. })->filterable(1),
  101. Form::input('staff_name', '店员名称', $service['staff_name'])->col(Form::col(24)),
  102. Form::input('phone', '手机号码', $service['phone'])->col(Form::col(24)),
  103. Form::radio('verify_status', '核销开关', $service['verify_status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  104. Form::radio('status', '状态', $service['status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']])
  105. ];
  106. $form = Form::make_post_form('修改数据', $f, Url::buildUrl('save', compact('id')));
  107. $this->assign(compact('form'));
  108. return $this->fetch('public/form-builder');
  109. }
  110. /**
  111. * 删除店员
  112. * @param $id
  113. */
  114. public function delete($id)
  115. {
  116. if (!$id) return $this->failed('数据不存在');
  117. if (!StaffModel::be(['id' => $id])) return $this->failed('数据不存在');
  118. if (!StaffModel::del($id))
  119. return Json::fail(StaffModel::getErrorInfo('删除失败,请稍候再试!'));
  120. else
  121. return Json::successful('删除成功!');
  122. }
  123. /**
  124. * 设置单个店员是否开启
  125. * @param string $is_show
  126. * @param string $id
  127. * @return json
  128. */
  129. public function set_show($is_show = '', $id = '')
  130. {
  131. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  132. $res = StaffModel::where(['id' => $id])->update(['status' => (int)$is_show]);
  133. if ($res) {
  134. return JsonService::successful($is_show == 1 ? '开启成功' : '关闭成功');
  135. } else {
  136. return JsonService::fail($is_show == 1 ? '开启失败' : '关闭失败');
  137. }
  138. }
  139. /**
  140. * 保存店员信息
  141. */
  142. public function save($id = 0)
  143. {
  144. $data = UtilService::postMore([
  145. ['uid', 0],
  146. ['avatar', ''],
  147. ['store_id', ''],
  148. ['staff_name', ''],
  149. ['phone', ''],
  150. ['verify_status', 1],
  151. ['status', 1],
  152. ]);
  153. if (!$id) {
  154. if (StaffModel::where('uid', $data['uid'])->count()) return Json::fail('添加的店员用户已存在!');
  155. }
  156. if ($data['uid'] == 0) return Json::fail('请选择用户');
  157. if ($data['store_id'] == '') return Json::fail('请选择所属门店');
  158. if ($id) {
  159. $res = StaffModel::edit($data, $id);
  160. if ($res) {
  161. return Json::successful('编辑成功');
  162. } else {
  163. return Json::fail('编辑失败');
  164. }
  165. } else {
  166. $data['add_time'] = time();
  167. $res = StaffModel::create($data);
  168. if ($res) {
  169. return Json::successful('店员添加成功');
  170. } else {
  171. return Json::fail('店员添加失败,请稍后再试');
  172. }
  173. }
  174. }
  175. /**
  176. * 获取user表
  177. * @param int $page
  178. * @param int $limit
  179. * @param string $nickname
  180. */
  181. public function get_user_list($page = 0, $limit = 10, $nickname = '')
  182. {
  183. return Json::successlayui(StaffModel::getUserList($page, $limit, $nickname));
  184. }
  185. }