Clerk.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\supplier\controller\store;
  3. use app\supplier\controller\Controller;
  4. use app\supplier\model\store\Clerk as ClerkModel;
  5. use app\supplier\model\store\Store as StoreModel;
  6. /**
  7. * 店员控制器
  8. */
  9. class Clerk extends Controller
  10. {
  11. /**
  12. * 店员列表
  13. */
  14. public function index($store_id = 0, $search = '')
  15. {
  16. // 店员列表
  17. $model = new ClerkModel;
  18. $data = $this->postData();
  19. $data['shop_supplier_id'] = $this->getSupplierId();
  20. $list = $model->getList(-1, $store_id, $search, $data);
  21. // 门店列表
  22. $store_list = (new StoreModel)->getList([],$this->getSupplierId());
  23. return $this->renderSuccess('', compact('list', 'store_list'));
  24. }
  25. /**
  26. * 添加店员
  27. */
  28. public function add()
  29. {
  30. $model = new ClerkModel;
  31. //传过来的信息
  32. $data = $this->postData();
  33. $data['shop_supplier_id'] = $this->getSupplierId();
  34. $list = $model->getAll()->toArray();
  35. $list_user_id = array_column($list, 'user_id');
  36. if (in_array($data['user_id'], $list_user_id)) {
  37. return $this->renderError('', '该用户已经是店员,无需重复添加');
  38. }
  39. // 新增记录
  40. if ($model->add($data)) {
  41. return $this->renderSuccess('', '添加成功');
  42. }
  43. return $this->renderError('', $model->getError() ?: '添加失败');
  44. }
  45. public function detail($clerk_id)
  46. {
  47. $detail = ClerkModel::detail($clerk_id);
  48. // 门店列表
  49. $store_list = StoreModel::getAllList($this->getSupplierId());
  50. return $this->renderSuccess('', compact('detail', 'store_list'));
  51. }
  52. /**
  53. * 编辑店员
  54. */
  55. public function edit($clerk_id)
  56. {
  57. if($this->request->isGet()){
  58. return $this->detail($clerk_id);
  59. }
  60. $model = ClerkModel::detail($clerk_id);
  61. //编辑店员的数据
  62. if ($model->edit($this->postData())) {
  63. return $this->renderSuccess('', '更新成功');
  64. }
  65. return $this->renderError('', $model->getError() ?: '更新失败');
  66. }
  67. /**
  68. * 删除店员
  69. */
  70. public function delete($clerk_id)
  71. {
  72. // 店员详情
  73. $model = ClerkModel::detail($clerk_id);
  74. if (!$model->setDelete()) {
  75. return $this->renderError('', '删除失败');
  76. }
  77. return $this->renderSuccess('', $model->getError() ?: '删除成功');
  78. }
  79. }