作者 郭文星

123

1 <?php 1 <?php
2 2
3 namespace app\admin\controller; 3 namespace app\admin\controller;
4 - 4 +use app\admin\controller\Index;
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
6 use think\Db; 6 use think\Db;
7 use think\exception\DbException; 7 use think\exception\DbException;
@@ -106,7 +106,24 @@ class Car extends Backend @@ -106,7 +106,24 @@ class Car extends Backend
106 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; 106 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
107 $this->model->validateFailException()->validate($validate); 107 $this->model->validateFailException()->validate($validate);
108 } 108 }
109 - $result = $this->model->allowField(true)->save($params); 109 + $istrue=$this->model->where("driver_id",$params['driver_id'])->find();
  110 + if($istrue){
  111 + $this->error("该司机添加车辆");
  112 + }
  113 + $route=Db::name("route")->where("id",$params['route_id'])->find();
  114 + $driver=Db::name("driver")->where("id",$params['driver_id'])->find();
  115 +
  116 + $result = $this->model->allowField(true)->insertGetId($params);
  117 +
  118 + $index=new Index();
  119 + $data=[
  120 + "start_address"=>$route["start_address"],
  121 + "end_address"=>$route["end_address"],
  122 + "name"=>$driver["name"],
  123 + "driver_id"=>$driver["id"],
  124 + ];
  125 + $place_image=$index->build($data);
  126 + $result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image]);
110 Db::commit(); 127 Db::commit();
111 } catch (ValidateException|PDOException|Exception $e) { 128 } catch (ValidateException|PDOException|Exception $e) {
112 Db::rollback(); 129 Db::rollback();