| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace app\admin\controller\store;
- use app\common\controller\AdminController;
- use app\http\IResponse;
- use think\App;
- use think\exception\PDOException;
- class TaxiServiceCategory extends AdminController
- {
- protected $model;
- public function __construct(App $app = null)
- {
- parent::__construct($app);
- $this->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('操作失败');
- }
- }
|