SystemStoreStaff.php 8.3 KB

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