Clerk.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\store\controller\shop;
  3. use app\store\controller\Controller;
  4. use app\store\model\store\Shop as ShopModel;
  5. use app\store\model\store\shop\Clerk as ClerkModel;
  6. /**
  7. * 门店店员控制器
  8. * Class Clerk
  9. * @package app\store\controller\shop
  10. */
  11. class Clerk extends Controller
  12. {
  13. /**
  14. * 店员列表
  15. * @param int $shop_id
  16. * @param string $search
  17. * @return mixed
  18. * @throws \think\exception\DbException
  19. */
  20. public function index($shop_id = 0, $search = '')
  21. {
  22. // 店员列表
  23. $model = new ClerkModel;
  24. $list = $model->getList(-1, $shop_id, $search);
  25. // 门店列表
  26. $shopList = ShopModel::getAllList();
  27. return $this->fetch('index', compact('list', 'shopList'));
  28. }
  29. /**
  30. * 添加店员
  31. * @return array|bool|mixed
  32. * @throws \Exception
  33. */
  34. public function add()
  35. {
  36. $model = new ClerkModel;
  37. if (!$this->request->isAjax()) {
  38. // 门店列表
  39. $shopList = ShopModel::getAllList();
  40. return $this->fetch('add', compact('shopList'));
  41. }
  42. // 新增记录
  43. if ($model->add($this->postData('clerk'))) {
  44. return $this->renderSuccess('添加成功', url('shop.clerk/index'));
  45. }
  46. return $this->renderError($model->getError() ?: '添加失败');
  47. }
  48. /**
  49. * 编辑店员
  50. * @param $clerk_id
  51. * @return array|bool|mixed
  52. * @throws \think\exception\DbException
  53. */
  54. public function edit($clerk_id)
  55. {
  56. // 店员详情
  57. $model = ClerkModel::detail($clerk_id);
  58. if (!$this->request->isAjax()) {
  59. // 门店列表
  60. $shopList = ShopModel::getAllList();
  61. return $this->fetch('edit', compact('model', 'shopList'));
  62. }
  63. // 新增记录
  64. if ($model->edit($this->postData('clerk'))) {
  65. return $this->renderSuccess('更新成功', url('shop.clerk/index'));
  66. }
  67. return $this->renderError($model->getError() ?: '更新失败');
  68. }
  69. /**
  70. * 删除店员
  71. * @param $clerk_id
  72. * @return array
  73. * @throws \think\exception\DbException
  74. */
  75. public function delete($clerk_id)
  76. {
  77. // 店员详情
  78. $model = ClerkModel::detail($clerk_id);
  79. if (!$model->setDelete()) {
  80. return $this->renderError($model->getError() ?: '删除失败');
  81. }
  82. return $this->renderSuccess('删除成功');
  83. }
  84. }