Store.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\shop\controller\store;
  3. use app\shop\controller\Controller;
  4. use app\shop\model\store\Store as StoreModel;
  5. /**
  6. * 门店控制器
  7. */
  8. class Store extends Controller
  9. {
  10. /**
  11. * 门店列表
  12. */
  13. public function index()
  14. {
  15. $model = new StoreModel;
  16. $list = $model->getList($this->postData());
  17. foreach ($list as $key => $val) {
  18. $list[$key]['detail_address'] = $val['region']['province'] . $val['region']['city'] . $val['region']['region'] . $val['address'];
  19. }
  20. return $this->renderSuccess('', compact('list'));
  21. }
  22. /**
  23. * 添加门店
  24. */
  25. public function add()
  26. {
  27. $model = new StoreModel;
  28. //Vue要添加的数据
  29. $data = $this->postData();
  30. if ($data['logo_image_id'] == 0) {
  31. return $this->renderError('请上传logo');
  32. }
  33. $coordinate = explode(',', $data['coordinate']);
  34. if (count($coordinate) <= 1) {
  35. return $this->renderError('请在地图点击选择坐标');
  36. }
  37. // 新增记录
  38. if ($model->add($data)) {
  39. return $this->renderSuccess('添加成功');
  40. }
  41. return $this->renderError($model->getError() ?: '添加失败');
  42. }
  43. /**
  44. * 修改门店信息
  45. */
  46. public function edit($store_id)
  47. {
  48. // 门店详情
  49. $model = StoreModel::detail($store_id);
  50. if($this->request->isGet()){
  51. $model['coordinate'] = $model['latitude'] . ',' . $model['longitude'];
  52. return $this->renderSuccess('', compact('model'));
  53. }
  54. // 修改记录
  55. if ($model->edit($this->postData())) {
  56. return $this->renderSuccess('更新成功');
  57. }
  58. return $this->renderError($model->getError() ?: '更新失败');
  59. }
  60. /**
  61. * 软删除
  62. */
  63. public function delete($store_id)
  64. {
  65. $model = new StoreModel;
  66. // 门店详情
  67. if (!$model->setDelete(['store_id' => $store_id])) {
  68. return $this->renderError('删除失败');
  69. }
  70. return $this->renderSuccess($model->getError() ?: '删除成功');
  71. }
  72. }