SystemStoreStaff.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. Form::radio('coupon_status', '添加优惠券状态', 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  67. Form::radio('price_status', '收款状态', 0)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  68. ];
  69. $form = Form::make_post_form('添加评论', $field, Url::buildUrl('save'), 2);
  70. $this->assign(compact('form'));
  71. return $this->fetch('public/form-builder');
  72. }
  73. /**
  74. * 选择用户
  75. * @param int $id
  76. */
  77. public function select()
  78. {
  79. return $this->fetch();
  80. }
  81. /**
  82. * 编辑表单
  83. * @param $id
  84. * @return string|void
  85. * @throws \FormBuilder\exception\FormBuilderException
  86. */
  87. public function edit($id)
  88. {
  89. $service = StaffModel::get($id);
  90. if (!$service) return Json::fail('数据不存在!');
  91. $f = [
  92. Form::frameImageOne('image', '商城用户', Url::buildUrl('admin/system.SystemStoreStaff/select', array('fodder' => 'image')), $service['avatar'])->icon('plus')->width('100%')->height('500px'),
  93. Form::hidden('uid', $service['uid']),
  94. Form::hidden('avatar', $service['avatar']),
  95. Form::select('store_id', '所属门店', (string)$service->getData('store_id'))->setOptions(function () {
  96. $list = SystemStore::dropList();
  97. // $menus[] = ['value' => 0, 'label' => '顶级分类'];
  98. foreach ($list as $menu) {
  99. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  100. }
  101. return $menus;
  102. })->filterable(1),
  103. Form::input('staff_name', '店员名称', $service['staff_name'])->col(Form::col(24)),
  104. Form::input('phone', '手机号码', $service['phone'])->col(Form::col(24)),
  105. Form::radio('verify_status', '统计管理开关', $service['verify_status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  106. Form::radio('status', '状态', $service['status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  107. Form::radio('coupon_status', '添加优惠券状态', $service['coupon_status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  108. Form::radio('price_status', '收款状态', $service['price_status'])->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]),
  109. ];
  110. $form = Form::make_post_form('修改数据', $f, Url::buildUrl('save', compact('id')));
  111. $this->assign(compact('form'));
  112. return $this->fetch('public/form-builder');
  113. }
  114. /**
  115. * 删除店员
  116. * @param $id
  117. */
  118. public function delete($id)
  119. {
  120. if (!$id) return $this->failed('数据不存在');
  121. if (!StaffModel::be(['id' => $id])) return $this->failed('数据不存在');
  122. if (!StaffModel::del($id))
  123. return Json::fail(StaffModel::getErrorInfo('删除失败,请稍候再试!'));
  124. else
  125. return Json::successful('删除成功!');
  126. }
  127. /**
  128. * 设置单个店员是否开启
  129. * @param string $is_show
  130. * @param string $id
  131. * @return json
  132. */
  133. public function set_show($is_show = '', $id = '')
  134. {
  135. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  136. $res = StaffModel::where(['id' => $id])->update(['status' => (int)$is_show]);
  137. if ($res) {
  138. return JsonService::successful($is_show == 1 ? '开启成功' : '关闭成功');
  139. } else {
  140. return JsonService::fail($is_show == 1 ? '开启失败' : '关闭失败');
  141. }
  142. }
  143. /**
  144. * 保存店员信息
  145. */
  146. public function save($id = 0)
  147. {
  148. $data = UtilService::postMore([
  149. ['uid', 0],
  150. ['avatar', ''],
  151. ['store_id', ''],
  152. ['staff_name', ''],
  153. ['phone', ''],
  154. ['verify_status', 1],
  155. ['status', 1],
  156. ['coupon_status'],
  157. ['price_status']
  158. ]);
  159. if (!$id) {
  160. if (StaffModel::where('uid', $data['uid'])->count()) return Json::fail('添加的店员用户已存在!');
  161. }
  162. if ($data['uid'] == 0) return Json::fail('请选择用户');
  163. if ($data['store_id'] == '') return Json::fail('请选择所属门店');
  164. if ($data['price_status'] == 1) {
  165. $store = \app\admin\model\system\SystemStoreStaff::where('store_id', $data['store_id'])->where('uid', '<>',$data['uid'])->where('price_status', 1)->find();
  166. if ($store) return Json::fail('已有收款账户不能添加第二位');
  167. }
  168. if ($id) {
  169. $res = StaffModel::edit($data, $id);
  170. if ($res) {
  171. return Json::successful('编辑成功');
  172. } else {
  173. return Json::fail('编辑失败');
  174. }
  175. } else {
  176. $data['add_time'] = time();
  177. $res = StaffModel::create($data);
  178. if ($res) {
  179. return Json::successful('店员添加成功');
  180. } else {
  181. return Json::fail('店员添加失败,请稍后再试');
  182. }
  183. }
  184. }
  185. /**
  186. * 获取user表
  187. * @param int $page
  188. * @param int $limit
  189. * @param string $nickname
  190. */
  191. public function get_user_list($page = 0, $limit = 10, $nickname = '')
  192. {
  193. return Json::successlayui(StaffModel::getUserList($page, $limit, $nickname));
  194. }
  195. }