model = new \app\common\model\TaxiServiceCategory(); } /** * 列表 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/3/16 14:39 * * @return \think\response\Json * @throws \think\exception\DbException */ public function index() { $where = []; $list = $this->model->where($where)->paginate(input('limit'),false); return IResponse::paginate($list); } /** * @desc desc * @throws PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/3 0003 */ public function create() { $params = input(); $result = false; $this->model->startTrans(); try { $result = $this->model->save($params); $this->model->commit(); } catch(PDOException $e) { $this->model->rollback(); } if ($result) { IResponse::success([],'操作成功'); } IResponse::failure('操作失败'); } /** * @desc desc * @param $id * @throws PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/3 0003 */ public function update($id) { $params = input(); $row = $this->model::get($id); if (!$row) { IResponse::failure('该记录不存在'); } $result = false; $this->model->startTrans(); try { $result = $row->allowField(true)->save($params); $this->model->commit(); } catch(PDOException $e) { $this->model->rollback(); } if ($result !== false) { IResponse::success([],'操作成功'); } IResponse::failure('操作失败'); } /** * @desc desc * @param $id * @throws PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/3 0003 */ public function delete($id) { $row = $this->model::get($id); if (!$row) { IResponse::failure('该记录不存在'); } $result = false; $this->model->startTrans(); try { $result = $row->delete(); $this->model->commit(); } catch(PDOException $e) { $this->model->rollback(); } if ($result) { IResponse::success([],'操作成功'); } IResponse::failure('操作失败'); } /** * @desc desc * @param $id * @throws PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/3 0003 */ public function change() { $params = input(); $list = $this->model->whereIn('id', $params['id'])->select(); if (!$list) { IResponse::failure('记录不存在'); } $result = 0; $this->model->startTrans(); try { foreach ($list as $item) { $item->status = $params['status']; $res = $item->save(); if ($res) { $result++; } } $this->model->commit(); } catch(PDOException $e) { $this->model->rollback(); } if ($result) { IResponse::success([],'操作成功'); } IResponse::failure('操作失败'); } }