作者 郭文星

123

... ... @@ -103,36 +103,42 @@ class Car extends Backend
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$istrue=$this->model->where("driver_id",$params['driver_id'])->find();
if($istrue){
$this->error("该司机已添加车辆");
}
// $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();
$user=Db::name("user")->where("mobile",$params['driver_phone'])->find();
if($user){
$driver=Db::name("driver")->where("user_id",$user['id'])->find();
$params['driver_id']=$driver['id'];
}
$result = $this->model->allowField(true)->save($params);
$carmodel=Db::name("carmodel")->where("id",$params['carmodel_id'])->find();
$car=Db::name("car")->where("driver_id",$driver['id'])->find();
$index=new Index();
$data=[
"start_address"=>$route["start_address"],
"end_address"=>$route["end_address"],
"price"=>$route["price"],
"name"=>$driver["name"],
"license_plate"=>$car["license_plate"],
"driver_id"=>$driver["id"],
"route_id"=>$route["id"],
];
$urldata="start_address=".$route['start_address']."
if($user){
$carmodel=Db::name("carmodel")->where("id",$params['carmodel_id'])->find();
$car=Db::name("car")->where("driver_id",$driver['id'])->find();
$index=new Index();
$data=[
"start_address"=>$route["start_address"],
"end_address"=>$route["end_address"],
"price"=>$route["price"],
"name"=>$driver["name"],
"license_plate"=>$car["license_plate"],
"driver_id"=>$driver["id"],
"route_id"=>$route["id"],
];
$urldata="start_address=".$route['start_address']."
&route_id=".$route['id']."
&driver_id=".$driver['id']."
&license_plate=".$car['license_plate']."
&name=".$driver['name']."
&end_address=".$route['end_address']."
&price=".$route['price'];
$url_data=urlencode($urldata);
$place_image=$this->getQRCode($url_data);
//encodeURIComponent
$result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]);
$url_data=urlencode($urldata);
$place_image=$this->getQRCode($url_data);
//encodeURIComponent
$result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]);
}
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
... ... @@ -182,6 +188,11 @@ class Car extends Backend
$car=Db::name('car')->where("id",$ids)->find();
$driver=Db::name('driver')->where("id",$car['driver_id'])->find();
$user=Db::name("user")->where("mobile",$params['driver_phone'])->find();
if($user){
$driver=Db::name("driver")->where("user_id",$user['id'])->find();
$params['driver_id']=$driver['id'];
if(!$driver['place_image']){
$index=new Index();
$route=Db::name("route")->where("id",$params['route_id'])->find();
... ... @@ -208,7 +219,7 @@ class Car extends Backend
$place_image=$this->getQRCode($url_data);
$result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]);
}
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
... ...
... ... @@ -3,6 +3,10 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 司机管理
... ... @@ -69,5 +73,99 @@ class Driver extends Backend
}
return $this->view->fetch();
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$user=Db::name("user")->where("mobile",$params['phone'])->find();
if($user){
$params['user_id']=$user['id'];
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$user=Db::name("user")->where("mobile",$params['phone'])->find();
if($user){
$params['user_id']=$user['id'];
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}
... ...
... ... @@ -19,9 +19,9 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Driver_id')}:</label>
<label class="control-label col-xs-12 col-sm-2">司机手机:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-driver_id" data-rule="required" data-source="driver/index" class="form-control selectpage" name="row[driver_id]" type="text" value="">
<input id="c-driver_phone" class="form-control" name="row[driver_phone]" type="text" value="">
</div>
</div>
<div class="form-group">
... ...
... ... @@ -19,9 +19,9 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Driver_id')}:</label>
<label class="control-label col-xs-12 col-sm-2">司机手机:</label>
<div class="col-xs-12 col-sm-8">
<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}">
<input id="c-driver_phone" class="form-control" name="row[driver_phone]" type="text" value="{$row.driver_phone|htmlentities}">
</div>
</div>
<div class="form-group">
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<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="">
</div>
</div>
<div class="form-group" id="kevin_company_type">
<label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<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}">
</div>
</div>
<div class="form-group" id="kevin_company_type">
<label class="control-label col-xs-12 col-sm-2">{:__('Offline_payment')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -92,6 +92,24 @@ class Login extends Base
$moblie=$phone['phoneNumber'];
if($moblie){
Db::name("user")->where("id", $user_id)->update(["mobile" => $moblie]);
$driver=Db::name("driver")->where("phone",$moblie)->find();
if($driver){
Db::name("driver")->where("id",$driver['id'])->update(["user_id"=>$user_id]);
Db::name("car")->where("driver_phone",$moblie)->update(["driver_id"=>$driver['id']]);
$car=Db::name("car")->where("driver_id",$driver['id'])->find();
$route=Db::name("route")->where("id",$car['route_id'])->find();
$urldata="start_address=".$route['start_address']."
&route_id=".$route['id']."
&driver_id=".$driver['id']."
&license_plate=".$car['license_plate']."
&name=".$driver['name']."
&end_address=".$route['end_address']."
&price=".$route['price'];
$url_data=urlencode($urldata);
$place_image=$this->getQRCode($url_data);
//encodeURIComponent
$result = Db::name('driver')->where('id','=',$driver["id"])->update(['place_image'=>$place_image['fileurl']]);
}
$res=$this->auth->direct($user_id);
$return_data = $this->auth->getUserinfo();
$this->success('查询用户信息成功',$return_data);
... ...