Car.php
4.3 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 首页接口
*/
class Car extends Api
{
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");
$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");
}
/**
* 查询乘车人信息
* @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 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);
}
}