作者 郭文星

123

<?php
namespace app\admin\controller;
use app\admin\controller\Index;
use app\common\controller\Backend;
use think\Db;
use think\exception\DbException;
... ... @@ -106,7 +106,24 @@ class Car extends Backend
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
$istrue=$this->model->where("driver_id",$params['driver_id'])->find();
if($istrue){
$this->error("该司机添加车辆");
}
$route=Db::name("route")->where("id",$params['route_id'])->find();
$driver=Db::name("driver")->where("id",$params['driver_id'])->find();
$result = $this->model->allowField(true)->insertGetId($params);
$index=new Index();
$data=[
"start_address"=>$route["start_address"],
"end_address"=>$route["end_address"],
"name"=>$driver["name"],
"driver_id"=>$driver["id"],
];
$place_image=$index->build($data);
$result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
... ...