Shop.php 2.1 KB

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