正在显示
7 个修改的文件
包含
154 行增加
和
40 行删除
@@ -103,36 +103,42 @@ class Car extends Backend | @@ -103,36 +103,42 @@ class Car extends Backend | ||
103 | $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | 103 | $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; |
104 | $this->model->validateFailException()->validate($validate); | 104 | $this->model->validateFailException()->validate($validate); |
105 | } | 105 | } |
106 | - $istrue=$this->model->where("driver_id",$params['driver_id'])->find(); | ||
107 | - if($istrue){ | ||
108 | - $this->error("该司机已添加车辆"); | ||
109 | - } | 106 | +// $istrue=$this->model->where("driver_id",$params['driver_id'])->find(); |
107 | +// if($istrue){ | ||
108 | +// $this->error("该司机已添加车辆"); | ||
109 | +// } | ||
110 | $route=Db::name("route")->where("id",$params['route_id'])->find(); | 110 | $route=Db::name("route")->where("id",$params['route_id'])->find(); |
111 | - $driver=Db::name("driver")->where("id",$params['driver_id'])->find(); | 111 | + $user=Db::name("user")->where("mobile",$params['driver_phone'])->find(); |
112 | + if($user){ | ||
113 | + $driver=Db::name("driver")->where("user_id",$user['id'])->find(); | ||
114 | + $params['driver_id']=$driver['id']; | ||
115 | + } | ||
112 | $result = $this->model->allowField(true)->save($params); | 116 | $result = $this->model->allowField(true)->save($params); |
113 | - $carmodel=Db::name("carmodel")->where("id",$params['carmodel_id'])->find(); | ||
114 | - $car=Db::name("car")->where("driver_id",$driver['id'])->find(); | ||
115 | - $index=new Index(); | ||
116 | - $data=[ | ||
117 | - "start_address"=>$route["start_address"], | ||
118 | - "end_address"=>$route["end_address"], | ||
119 | - "price"=>$route["price"], | ||
120 | - "name"=>$driver["name"], | ||
121 | - "license_plate"=>$car["license_plate"], | ||
122 | - "driver_id"=>$driver["id"], | ||
123 | - "route_id"=>$route["id"], | ||
124 | - ]; | ||
125 | - $urldata="start_address=".$route['start_address']." | 117 | + if($user){ |
118 | + $carmodel=Db::name("carmodel")->where("id",$params['carmodel_id'])->find(); | ||
119 | + $car=Db::name("car")->where("driver_id",$driver['id'])->find(); | ||
120 | + $index=new Index(); | ||
121 | + $data=[ | ||
122 | + "start_address"=>$route["start_address"], | ||
123 | + "end_address"=>$route["end_address"], | ||
124 | + "price"=>$route["price"], | ||
125 | + "name"=>$driver["name"], | ||
126 | + "license_plate"=>$car["license_plate"], | ||
127 | + "driver_id"=>$driver["id"], | ||
128 | + "route_id"=>$route["id"], | ||
129 | + ]; | ||
130 | + $urldata="start_address=".$route['start_address']." | ||
126 | &route_id=".$route['id']." | 131 | &route_id=".$route['id']." |
127 | &driver_id=".$driver['id']." | 132 | &driver_id=".$driver['id']." |
128 | &license_plate=".$car['license_plate']." | 133 | &license_plate=".$car['license_plate']." |
129 | &name=".$driver['name']." | 134 | &name=".$driver['name']." |
130 | &end_address=".$route['end_address']." | 135 | &end_address=".$route['end_address']." |
131 | &price=".$route['price']; | 136 | &price=".$route['price']; |
132 | - $url_data=urlencode($urldata); | ||
133 | - $place_image=$this->getQRCode($url_data); | ||
134 | - //encodeURIComponent | ||
135 | - $result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]); | 137 | + $url_data=urlencode($urldata); |
138 | + $place_image=$this->getQRCode($url_data); | ||
139 | + //encodeURIComponent | ||
140 | + $result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]); | ||
141 | + } | ||
136 | Db::commit(); | 142 | Db::commit(); |
137 | } catch (ValidateException|PDOException|Exception $e) { | 143 | } catch (ValidateException|PDOException|Exception $e) { |
138 | Db::rollback(); | 144 | Db::rollback(); |
@@ -182,6 +188,11 @@ class Car extends Backend | @@ -182,6 +188,11 @@ class Car extends Backend | ||
182 | 188 | ||
183 | $car=Db::name('car')->where("id",$ids)->find(); | 189 | $car=Db::name('car')->where("id",$ids)->find(); |
184 | $driver=Db::name('driver')->where("id",$car['driver_id'])->find(); | 190 | $driver=Db::name('driver')->where("id",$car['driver_id'])->find(); |
191 | + $user=Db::name("user")->where("mobile",$params['driver_phone'])->find(); | ||
192 | + if($user){ | ||
193 | + $driver=Db::name("driver")->where("user_id",$user['id'])->find(); | ||
194 | + $params['driver_id']=$driver['id']; | ||
195 | + | ||
185 | if(!$driver['place_image']){ | 196 | if(!$driver['place_image']){ |
186 | $index=new Index(); | 197 | $index=new Index(); |
187 | $route=Db::name("route")->where("id",$params['route_id'])->find(); | 198 | $route=Db::name("route")->where("id",$params['route_id'])->find(); |
@@ -208,7 +219,7 @@ class Car extends Backend | @@ -208,7 +219,7 @@ class Car extends Backend | ||
208 | $place_image=$this->getQRCode($url_data); | 219 | $place_image=$this->getQRCode($url_data); |
209 | $result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]); | 220 | $result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]); |
210 | } | 221 | } |
211 | - | 222 | + } |
212 | $result = $row->allowField(true)->save($params); | 223 | $result = $row->allowField(true)->save($params); |
213 | Db::commit(); | 224 | Db::commit(); |
214 | } catch (ValidateException|PDOException|Exception $e) { | 225 | } catch (ValidateException|PDOException|Exception $e) { |
@@ -3,6 +3,10 @@ | @@ -3,6 +3,10 @@ | ||
3 | namespace app\admin\controller; | 3 | namespace app\admin\controller; |
4 | 4 | ||
5 | use app\common\controller\Backend; | 5 | use app\common\controller\Backend; |
6 | +use think\Db; | ||
7 | +use think\exception\DbException; | ||
8 | +use think\exception\PDOException; | ||
9 | +use think\exception\ValidateException; | ||
6 | 10 | ||
7 | /** | 11 | /** |
8 | * 司机管理 | 12 | * 司机管理 |
@@ -69,5 +73,99 @@ class Driver extends Backend | @@ -69,5 +73,99 @@ class Driver extends Backend | ||
69 | } | 73 | } |
70 | return $this->view->fetch(); | 74 | return $this->view->fetch(); |
71 | } | 75 | } |
76 | + /** | ||
77 | + * 添加 | ||
78 | + * | ||
79 | + * @return string | ||
80 | + * @throws \think\Exception | ||
81 | + */ | ||
82 | + public function add() | ||
83 | + { | ||
84 | + if (false === $this->request->isPost()) { | ||
85 | + return $this->view->fetch(); | ||
86 | + } | ||
87 | + $params = $this->request->post('row/a'); | ||
88 | + if (empty($params)) { | ||
89 | + $this->error(__('Parameter %s can not be empty', '')); | ||
90 | + } | ||
91 | + $params = $this->preExcludeFields($params); | ||
72 | 92 | ||
93 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
94 | + $params[$this->dataLimitField] = $this->auth->id; | ||
95 | + } | ||
96 | + $result = false; | ||
97 | + Db::startTrans(); | ||
98 | + try { | ||
99 | + //是否采用模型验证 | ||
100 | + if ($this->modelValidate) { | ||
101 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
102 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
103 | + $this->model->validateFailException()->validate($validate); | ||
104 | + } | ||
105 | + $user=Db::name("user")->where("mobile",$params['phone'])->find(); | ||
106 | + if($user){ | ||
107 | + $params['user_id']=$user['id']; | ||
108 | + } | ||
109 | + $result = $this->model->allowField(true)->save($params); | ||
110 | + Db::commit(); | ||
111 | + } catch (ValidateException|PDOException|Exception $e) { | ||
112 | + Db::rollback(); | ||
113 | + $this->error($e->getMessage()); | ||
114 | + } | ||
115 | + if ($result === false) { | ||
116 | + $this->error(__('No rows were inserted')); | ||
117 | + } | ||
118 | + $this->success(); | ||
119 | + } | ||
120 | + /** | ||
121 | + * 编辑 | ||
122 | + * | ||
123 | + * @param $ids | ||
124 | + * @return string | ||
125 | + * @throws DbException | ||
126 | + * @throws \think\Exception | ||
127 | + */ | ||
128 | + public function edit($ids = null) | ||
129 | + { | ||
130 | + $row = $this->model->get($ids); | ||
131 | + if (!$row) { | ||
132 | + $this->error(__('No Results were found')); | ||
133 | + } | ||
134 | + $adminIds = $this->getDataLimitAdminIds(); | ||
135 | + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { | ||
136 | + $this->error(__('You have no permission')); | ||
137 | + } | ||
138 | + if (false === $this->request->isPost()) { | ||
139 | + $this->view->assign('row', $row); | ||
140 | + return $this->view->fetch(); | ||
141 | + } | ||
142 | + $params = $this->request->post('row/a'); | ||
143 | + if (empty($params)) { | ||
144 | + $this->error(__('Parameter %s can not be empty', '')); | ||
145 | + } | ||
146 | + $params = $this->preExcludeFields($params); | ||
147 | + $result = false; | ||
148 | + Db::startTrans(); | ||
149 | + try { | ||
150 | + //是否采用模型验证 | ||
151 | + if ($this->modelValidate) { | ||
152 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
153 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
154 | + $row->validateFailException()->validate($validate); | ||
155 | + } | ||
156 | + $user=Db::name("user")->where("mobile",$params['phone'])->find(); | ||
157 | + if($user){ | ||
158 | + $params['user_id']=$user['id']; | ||
159 | + } | ||
160 | + $result = $row->allowField(true)->save($params); | ||
161 | + Db::commit(); | ||
162 | + } catch (ValidateException|PDOException|Exception $e) { | ||
163 | + Db::rollback(); | ||
164 | + $this->error($e->getMessage()); | ||
165 | + } | ||
166 | + if (false === $result) { | ||
167 | + $this->error(__('No rows were updated')); | ||
168 | + } | ||
169 | + $this->success(); | ||
170 | + } | ||
73 | } | 171 | } |
@@ -19,9 +19,9 @@ | @@ -19,9 +19,9 @@ | ||
19 | </div> | 19 | </div> |
20 | </div> | 20 | </div> |
21 | <div class="form-group"> | 21 | <div class="form-group"> |
22 | - <label class="control-label col-xs-12 col-sm-2">{:__('Driver_id')}:</label> | 22 | + <label class="control-label col-xs-12 col-sm-2">司机手机:</label> |
23 | <div class="col-xs-12 col-sm-8"> | 23 | <div class="col-xs-12 col-sm-8"> |
24 | - <input id="c-driver_id" data-rule="required" data-source="driver/index" class="form-control selectpage" name="row[driver_id]" type="text" value=""> | 24 | + <input id="c-driver_phone" class="form-control" name="row[driver_phone]" type="text" value=""> |
25 | </div> | 25 | </div> |
26 | </div> | 26 | </div> |
27 | <div class="form-group"> | 27 | <div class="form-group"> |
@@ -19,9 +19,9 @@ | @@ -19,9 +19,9 @@ | ||
19 | </div> | 19 | </div> |
20 | </div> | 20 | </div> |
21 | <div class="form-group"> | 21 | <div class="form-group"> |
22 | - <label class="control-label col-xs-12 col-sm-2">{:__('Driver_id')}:</label> | 22 | + <label class="control-label col-xs-12 col-sm-2">司机手机:</label> |
23 | <div class="col-xs-12 col-sm-8"> | 23 | <div class="col-xs-12 col-sm-8"> |
24 | - <input id="c-driver_id" data-rule="required" data-source="driver/index" class="form-control selectpage" name="row[driver_id]" type="text" value="{$row.driver_id|htmlentities}"> | 24 | + <input id="c-driver_phone" class="form-control" name="row[driver_phone]" type="text" value="{$row.driver_phone|htmlentities}"> |
25 | </div> | 25 | </div> |
26 | </div> | 26 | </div> |
27 | <div class="form-group"> | 27 | <div class="form-group"> |
1 | <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> | 1 | <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> |
2 | 2 | ||
3 | - <div class="form-group"> | ||
4 | - <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label> | ||
5 | - <div class="col-xs-12 col-sm-8"> | ||
6 | - <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="username" class="form-control selectpage" name="row[user_id]" type="text" value=""> | ||
7 | - </div> | ||
8 | - </div> | ||
9 | <div class="form-group" id="kevin_company_type"> | 3 | <div class="form-group" id="kevin_company_type"> |
10 | <label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label> | 4 | <label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label> |
11 | <div class="col-xs-12 col-sm-8"> | 5 | <div class="col-xs-12 col-sm-8"> |
1 | <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> | 1 | <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> |
2 | - | ||
3 | - <div class="form-group"> | ||
4 | - <label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label> | ||
5 | - <div class="col-xs-12 col-sm-8"> | ||
6 | - <input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="username" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}"> | ||
7 | - </div> | ||
8 | - </div> | ||
9 | <div class="form-group" id="kevin_company_type"> | 2 | <div class="form-group" id="kevin_company_type"> |
10 | <label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label> | 3 | <label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label> |
11 | <div class="col-xs-12 col-sm-8"> | 4 | <div class="col-xs-12 col-sm-8"> |
@@ -92,6 +92,24 @@ class Login extends Base | @@ -92,6 +92,24 @@ class Login extends Base | ||
92 | $moblie=$phone['phoneNumber']; | 92 | $moblie=$phone['phoneNumber']; |
93 | if($moblie){ | 93 | if($moblie){ |
94 | Db::name("user")->where("id", $user_id)->update(["mobile" => $moblie]); | 94 | Db::name("user")->where("id", $user_id)->update(["mobile" => $moblie]); |
95 | + $driver=Db::name("driver")->where("phone",$moblie)->find(); | ||
96 | + if($driver){ | ||
97 | + Db::name("driver")->where("id",$driver['id'])->update(["user_id"=>$user_id]); | ||
98 | + Db::name("car")->where("driver_phone",$moblie)->update(["driver_id"=>$driver['id']]); | ||
99 | + $car=Db::name("car")->where("driver_id",$driver['id'])->find(); | ||
100 | + $route=Db::name("route")->where("id",$car['route_id'])->find(); | ||
101 | + $urldata="start_address=".$route['start_address']." | ||
102 | + &route_id=".$route['id']." | ||
103 | + &driver_id=".$driver['id']." | ||
104 | + &license_plate=".$car['license_plate']." | ||
105 | + &name=".$driver['name']." | ||
106 | + &end_address=".$route['end_address']." | ||
107 | + &price=".$route['price']; | ||
108 | + $url_data=urlencode($urldata); | ||
109 | + $place_image=$this->getQRCode($url_data); | ||
110 | + //encodeURIComponent | ||
111 | + $result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]); | ||
112 | + } | ||
95 | $res=$this->auth->direct($user_id); | 113 | $res=$this->auth->direct($user_id); |
96 | $return_data = $this->auth->getUserinfo(); | 114 | $return_data = $this->auth->getUserinfo(); |
97 | $this->success('查询用户信息成功',$return_data); | 115 | $this->success('查询用户信息成功',$return_data); |
-
请 注册 或 登录 后发表评论