Clerk.php 2.6 KB

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