| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace app\admin\controller\store;
- use app\common\controller\AdminController;
- use app\http\IResponse;
- class Store extends AdminController
- {
- /**
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/15 18:20
- *
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $where = [];
- $type = $this->request->get('type', 0);
- if($type>0){
- $where['type'] = $type;
- }
- //组合搜索
- $model = model('common/Store');
- return IResponse::paginate($model->where($where)
- ->paginate(input('limit'),false));
- }
- /**
- * 新增
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/06/07 23:59
- *
- * @return mixed
- */
- public function save()
- {
- // 接收数据
- $params = $this->request->param();
- // 数据校验
- $valid = $this->validate($params, [
- 'name|门店名称' => 'require',
- 'logo|门头LOGO图片' => 'require',
- 'type|门店类型' => 'require',
- 'content|介绍内容' => 'require',
- 'location|位置' => 'require',
- 'time_slot|服务时段' => 'require'
- ]);
- // 错误返回
- (true !== $valid) && IResponse::failure($valid);
- // 保存数据
- $coordinate = isset($params['coordinate'])? trim($params['coordinate']) : '';
- $coordinate = $coordinate? explode(',', $coordinate) : [];
- $params['latitude'] = isset($coordinate[0])? $coordinate[0] : '';
- $params['ongitude'] = isset($coordinate[1])? $coordinate[1] : '';
- unset($params['coordinate']);
- $model = model("common/Store")->storeBy($params);
- return $model ? IResponse::success([],'新增门店信息成功'):
- IResponse::failure('新增门店信息异常');
- }
- /**
- * 更新数据
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/06/07 14:24
- *
- * @param $id
- * @return \think\response\Json
- */
- public function update($id)
- {
- // 接收数据
- $params = $this->request->param();
- // 查询用户
- $model = model('common/Store')->findBy($id);
- // 是否更改状态操作
- if (isset($params['status']) && $params['status'] != '') {
- $valid = $this->validate($params, [
- 'status|配置状态' => 'require|integer'
- ]);
- }else {
- // 数据校验
- $valid = $this->validate($params, [
- 'name|门店名称' => 'require',
- 'logo|门头LOGO图片' => 'require',
- 'type|门店类型' => 'require',
- 'content|介绍内容' => 'require',
- 'location|位置' => 'require',
- 'time_slot|服务时段' => 'require'
- ]);
- }
- // 错误返回
- (true !== $valid) && IResponse::failure($valid);
- // 更新信息
- $coordinate = isset($params['coordinate'])? trim($params['coordinate']) : '';
- $coordinate = $coordinate? explode(',', $coordinate) : [];
- $params['latitude'] = isset($coordinate[0])? $coordinate[0] : '';
- $params['ongitude'] = isset($coordinate[1])? $coordinate[1] : '';
- $model->updateBy($id, $params);
- return IResponse::success('更新门店信息成功');
- }
- /**
- * 删除
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/3/16 14:22
- *
- * @param $id
- * @return \think\response\Json
- */
- public function delete($id)
- {
- model('common/Store')->deleteBy($id);
- return IResponse::success([],'删除门店成功');
- }
- /**
- * 批量操作
- *
- * @return mixed
- */
- public function plectron(){
- // 收参数
- $params = $this->request->param();
- foreach (str2arr($params['ids']) as $id){
- $model = model('common/Store')->getBy($id);
- if ($this->request->isDelete()){
- return IResponse::success([],'删除门店成功');
- }
- $model->allowField(true)->updateBy($id, $params);
- }
- return IResponse::success([],'操作成功');
- }
- }
|