Store.php 2.6 KB

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