Car.php
6.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
namespace app\api\controller;
use app\api\controller\v1\Base;
use app\common\controller\Api;
use think\Db;
/**
* 首页接口
*/
class Car extends Base
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* 查询常用路线
* @return void
*/
public function selectroute(){
$res=Db::name("route")->field("id,name,start_address,end_address")->limit(2)->select();
return $this->success($res);
}
/**
* 通过线路查询车辆
* @return void
*/
public function selectcarbyroute(){
$route_id = $this->request->param("route_id");
$time = $this->request->param("time");
$res=Db::name("car")
->alias("a")
->join("route b","a.route_id=b.id")
->field("a.id,b.id as route_id,DATE_FORMAT(FROM_UNIXTIME(a.reservation_time), '%H:%i') AS reservation_time ,DATE_FORMAT(FROM_UNIXTIME(a.start_time), '%H:%i') AS start_time ,b.price")
->where("route_id",$route_id)
->group("start_time")
->select();
$start_time=strtotime(date("Y-m-d",$time));
$end_time=$start_time+86400;
$newtime=time();
foreach ($res as $k=>$v){
$res[$k]['order']=Db::name("order")
->where("car_id",$res[$k]['id'])
->where("is_pay",1)
->where("reservation_time",">",$start_time)
->where("reservation_time","<",$end_time)
->count();
}
return $this->success($res);
}
/**
* 创建订单
* @return void
*/
public function createorder(){
$number=$this->request->param("number");//乘车人数
$phone = $this->request->param("phone");//联系手机号码
$user_name = $this->request->param("user_name");//联系人
$position = $this->request->param("position");//上车地址
$lat = $this->request->param("lat");//经度
$lng = $this->request->param("lng");//维度
$remarks = $this->request->param("remarks");//备注
$intended_driver_id = $this->request->param("intended_driver_id");//意向司机
$route_id = $this->request->param("route_id");//线路
$car_id = $this->request->param("car_id");//车辆
if($number<=0){
$this->error("人数错误");
}
//查询线路
$route=Db::name("route")->where("id",$route_id)->find();
//查询车辆
$car=Db::name("car")->where("id",$car_id)->find();
//查询司机
$driver=Db::name("driver")->where("id",$car['driver_id'])->find();
$data=[
"order_no"=>getOrderSn(),
"price"=>bcmul($route['price'],$number,2),
"is_pay"=>"2",//未支付
"car_id"=>$car_id,
"user_id"=>$this->auth->id,
"phone"=>$phone,
"user_name"=>$user_name,
"driver_id"=>$driver['id'],
"driver_name"=>$driver['name'],
"create_time"=>time(),
"reservation_time"=>getOrderSn(),
"position"=>$position,
"lat"=>$lat,
"lng"=>$lng,
"number"=>$number,
"remarks"=>$remarks,
"intended_driver_id"=>$intended_driver_id,
];
$res=Db::name("order")->insertGetId($data);
$userinfo = Db::name('user')
->where(['id' => $this->auth->id])
->field('id,wx_xcx_openid')
->find();
$notifyURI = $this->doman . '/addons/epay/api/OrderPayNtf';
$params = [
'amount' => $data['price'],
'orderid' => $data['order_no'],
'type' => 'wechat',
'notifyurl' => $notifyURI,
'method' => 'miniapp',
'openid' => $userinfo['wx_xcx_openid'],
];
$f = \addons\epay\library\Service::submitOrder($params);
$this->success("请求成功",$f);
}
/**
* 查询乘车人信息
* @return void
*/
public function passengerlist(){
$res=Db::name("passenger")->where("user_id",$this->auth->id)->select();
return $this->success("请求成功",$res);
}
/**
* 增加乘车人信息
* @return void
*/
public function addpassenger(){
$name=$this->request->param("name");
$IDcard=$this->request->param("IDcard");
$phone=$this->request->param("phone");
$is_adult=$this->request->param("is_adult");
$res=Db::name("passenger")->insert([
"name"=>$name,
"IDcard"=>$IDcard,
"phone"=>$phone,
"user_id"=>$this->auth->id,
"is_adult"=>$is_adult
]);
return $this->success("添加成功",$res);
}
/**
* 修改乘车人信息
* @return void
*/
public function updatepassenger(){
$name=$this->request->param("name");
$IDcard=$this->request->param("IDcard");
$phone=$this->request->param("phone");
$is_adult=$this->request->param("is_adult");
$id=$this->request->param("id");
$res=Db::name("passenger")->where("id",$id)->update([
"name"=>$name,
"IDcard"=>$IDcard,
"phone"=>$phone,
"is_adult"=>$is_adult
]);
return $this->success("修改成功",$res);
}
/**
* 查询订单
* @return void
*/
public function selectorder(){
$is_pay=$this->request->param("is_pay"); //是否支付:1=已支付,2=未支付,3=已退款,4=已取消
$w['user_id'] = $this->auth->id;
if ($is_pay){
$w['is_pay'] = $is_pay;
}
$res=Db::name("order")
->where($w)
->select();
return $this->success("请求成功",$res);
}
/**
* 切换司机
* @return void
*/
public function switching_driver(){
$res=Db::name("driver")->where("user_id",$this->auth->id)->find();
if($res){
return $this->success("请求成功",$res);
}else{
return $this->error("请求失败");
}
}
/**
* 切换司机
* @return void
*/
public function switching_user(){
$res=Db::name("user")->where("id",$this->auth->id)->find();
if($res){
return $this->success("请求成功",$res);
}else{
return $this->error("请求失败");
}
}
/**
*
* @return void
*/
public function selectbydriver(){
//$driver
$res=Db::name("order")
->where("user_id",$this->auth->id)
->select();
}
/**
*认证声明
* @return void
*/
public function authentication_statement(){
$content = config("site.content");//微信小程序AppID
return $this->success($content);
}
}