Shop.php 2.3 KB

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