Store.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\admin\controller\store;
  3. use app\common\controller\AdminController;
  4. use app\http\IResponse;
  5. class Store extends AdminController
  6. {
  7. /**
  8. *
  9. * @author 许祖兴 < zuxing.xu@lettered.cn>
  10. * @date 2020/7/15 18:20
  11. *
  12. * @return mixed
  13. * @throws \think\exception\DbException
  14. */
  15. public function index()
  16. {
  17. $where = [];
  18. $type = $this->request->get('type', 0);
  19. if($type>0){
  20. $where['type'] = $type;
  21. }
  22. //组合搜索
  23. $model = model('common/Store');
  24. return IResponse::paginate($model->where($where)
  25. ->paginate(input('limit'),false));
  26. }
  27. /**
  28. * 新增
  29. *
  30. * @author 许祖兴 < zuxing.xu@lettered.cn>
  31. * @date 2020/06/07 23:59
  32. *
  33. * @return mixed
  34. */
  35. public function save()
  36. {
  37. // 接收数据
  38. $params = $this->request->param();
  39. // 数据校验
  40. $valid = $this->validate($params, [
  41. 'name|门店名称' => 'require',
  42. 'logo|门头LOGO图片' => 'require',
  43. 'type|门店类型' => 'require',
  44. 'content|介绍内容' => 'require',
  45. 'location|位置' => 'require',
  46. 'time_slot|服务时段' => 'require'
  47. ]);
  48. // 错误返回
  49. (true !== $valid) && IResponse::failure($valid);
  50. // 保存数据
  51. $coordinate = isset($params['coordinate'])? trim($params['coordinate']) : '';
  52. $coordinate = $coordinate? explode(',', $coordinate) : [];
  53. $params['latitude'] = isset($coordinate[0])? $coordinate[0] : '';
  54. $params['ongitude'] = isset($coordinate[1])? $coordinate[1] : '';
  55. unset($params['coordinate']);
  56. $model = model("common/Store")->storeBy($params);
  57. return $model ? IResponse::success([],'新增门店信息成功'):
  58. IResponse::failure('新增门店信息异常');
  59. }
  60. /**
  61. * 更新数据
  62. *
  63. * @author 许祖兴 < zuxing.xu@lettered.cn>
  64. * @date 2020/06/07 14:24
  65. *
  66. * @param $id
  67. * @return \think\response\Json
  68. */
  69. public function update($id)
  70. {
  71. // 接收数据
  72. $params = $this->request->param();
  73. // 查询用户
  74. $model = model('common/Store')->findBy($id);
  75. // 是否更改状态操作
  76. if (isset($params['status']) && $params['status'] != '') {
  77. $valid = $this->validate($params, [
  78. 'status|配置状态' => 'require|integer'
  79. ]);
  80. }else {
  81. // 数据校验
  82. $valid = $this->validate($params, [
  83. 'name|门店名称' => 'require',
  84. 'logo|门头LOGO图片' => 'require',
  85. 'type|门店类型' => 'require',
  86. 'content|介绍内容' => 'require',
  87. 'location|位置' => 'require',
  88. 'time_slot|服务时段' => 'require'
  89. ]);
  90. }
  91. // 错误返回
  92. (true !== $valid) && IResponse::failure($valid);
  93. // 更新信息
  94. $coordinate = isset($params['coordinate'])? trim($params['coordinate']) : '';
  95. $coordinate = $coordinate? explode(',', $coordinate) : [];
  96. $params['latitude'] = isset($coordinate[0])? $coordinate[0] : '';
  97. $params['ongitude'] = isset($coordinate[1])? $coordinate[1] : '';
  98. $model->updateBy($id, $params);
  99. return IResponse::success('更新门店信息成功');
  100. }
  101. /**
  102. * 删除
  103. *
  104. * @author 许祖兴 < zuxing.xu@lettered.cn>
  105. * @date 2020/3/16 14:22
  106. *
  107. * @param $id
  108. * @return \think\response\Json
  109. */
  110. public function delete($id)
  111. {
  112. model('common/Store')->deleteBy($id);
  113. return IResponse::success([],'删除门店成功');
  114. }
  115. /**
  116. * 批量操作
  117. *
  118. * @return mixed
  119. */
  120. public function plectron(){
  121. // 收参数
  122. $params = $this->request->param();
  123. foreach (str2arr($params['ids']) as $id){
  124. $model = model('common/Store')->getBy($id);
  125. if ($this->request->isDelete()){
  126. return IResponse::success([],'删除门店成功');
  127. }
  128. $model->allowField(true)->updateBy($id, $params);
  129. }
  130. return IResponse::success([],'操作成功');
  131. }
  132. }