ソースを参照

Wesmiler 人人车 初始化项目 0816

APPLE 3 年 前
コミット
400ec57a97

+ 149 - 0
application/admin/controller/store/Stores.php

@@ -0,0 +1,149 @@
+<?php
+
+
+namespace app\admin\controller\store;
+
+
+use app\common\controller\AdminController;
+use app\http\IResponse;
+
+class Stores 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/Stores');
+
+        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/Stores")->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/Stores')->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/Stores')->deleteBy($id);
+        return IResponse::success([],'删除门店成功');
+    }
+
+    /**
+     * 批量操作
+     *
+     * @return mixed
+     */
+    public function plectron(){
+        // 收参数
+        $params = $this->request->param();
+
+        foreach (str2arr($params['ids']) as $id){
+            $model = model('common/Stores')->getBy($id);
+            if ($this->request->isDelete()){
+                return IResponse::success([],'删除门店成功');
+            }
+            $model->allowField(true)->updateBy($id, $params);
+        }
+        return IResponse::success([],'操作成功');
+    }
+
+}

+ 26 - 0
application/common/model/Stores.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace app\common\model;
+
+
+class Stores extends BaseModel
+{
+    /**
+     * @var string
+     */
+    protected $name = 'stores';
+    /**
+     * @var array
+     */
+    protected $auto = [];
+    /**
+     * @var array
+     */
+    protected $insert = ['created_at','updated_at'];
+    /**
+     * @var array
+     */
+    protected $update = ['updated_at'];
+
+}