作者 郭文星

123

... ... @@ -20,8 +20,9 @@ class Car extends Base
* 查询常用路线
* @return void
*/
public function selectroute(){
$res=Db::name("route")->field("id,name,price,start_address,end_address")->limit(2)->select();
public function selectroute()
{
$res = Db::name("route")->field("id,name,price,start_address,end_address")->limit(2)->select();
return $this->success($res);
}
... ... @@ -29,55 +30,56 @@ class Car extends Base
* 通过线路查询车辆
* @return void
*/
public function selectcarbyroute(){
public function selectcarbyroute()
{
$route_id = $this->request->param("route_id");
$time = $this->request->param("time");
$res=Db::name("car")
$res = Db::name("car")
->alias("a")
->join("route b","a.route_id=b.id")
->join("driver c","a.driver_id=c.id")
->join("route b", "a.route_id=b.id")
->join("driver c", "a.driver_id=c.id")
->field("a.id,b.id as route_id,c.id as driver_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,a.seat,a.license_plate")
->where("route_id",$route_id)
->where("scheduling_type",1)
->where("route_id", $route_id)
->where("scheduling_type", 1)
->group("start_time")
->select();
// 查询临时线路车次
$statr_time=strtotime(date("Y-m-d",time()));
$end_time=$statr_time+86400;
$temporary_route=Db::name("temporary_route")
->where("create_time",">",$statr_time)
->where("create_time","<",$end_time)
->where("route_id",$route_id)
$statr_time = strtotime(date("Y-m-d", time()));
$end_time = $statr_time + 86400;
$temporary_route = Db::name("temporary_route")
->where("create_time", ">", $statr_time)
->where("create_time", "<", $end_time)
->where("route_id", $route_id)
->select();
$data=[];
foreach ($temporary_route as $k=>$v){
$data[]=Db::name("car")
$data = [];
foreach ($temporary_route as $k => $v) {
$data[] = Db::name("car")
->alias("a")
->join("route b","a.route_id=b.id")
->join("driver c","a.driver_id=c.id")
->join("route b", "a.route_id=b.id")
->join("driver c", "a.driver_id=c.id")
->field("a.id,b.id as route_id,c.id as driver_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,a.seat,a.license_plate")
->where("route_id",$route_id)
->where("a.id",$temporary_route[$k]['car_id'])
->where("route_id", $route_id)
->where("a.id", $temporary_route[$k]['car_id'])
->group("start_time")
->find();
}
$res=array_merge($data,$res);
$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)
$res = array_merge($data, $res);
$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 $this->success("请求成功", $res);
}
... ... @@ -85,8 +87,9 @@ class Car extends Base
* 创建订单
* @return void
*/
public function createorder(){
$number=$this->request->param("number");//乘车人数
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");//上车地址
... ... @@ -98,79 +101,79 @@ class Car extends Base
$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){
if ($number <= 0) {
$this->error("人数错误");
}
//查询线路
$route=Db::name("route")->where("id",$route_id)->find();
//查询线路
$route = Db::name("route")->where("id", $route_id)->find();
//查询车辆
$car=Db::name("car")->where("id",$car_id)->find();
$car = Db::name("car")->where("id", $car_id)->find();
//查询司机
$driver=Db::name("driver")->where("id",$car['driver_id'])->find();
$driver = Db::name("driver")->where("id", $car['driver_id'])->find();
//判断总表
$time=strtotime(date("Y-m-d",time()));
$order_review=Db::name("order_review")
->where("car_id",$car_id)
->where("car_id",$car_id)
->where("route_id",$route_id)
->where("driver_id",$driver['id'])
->where("createtime",">",$time)
$time = strtotime(date("Y-m-d", time()));
$order_review = Db::name("order_review")
->where("car_id", $car_id)
->where("car_id", $car_id)
->where("route_id", $route_id)
->where("driver_id", $driver['id'])
->where("createtime", ">", $time)
->find();
if(!$order_review){
$order_review_id=Db::name("order_review")
if (!$order_review) {
$order_review_id = Db::name("order_review")
->insertGetId([
"car_id"=>$car_id,
"route_id"=>$route_id,
"driver_id"=>$driver['id'],
"order_status"=>1,
"createtime"=>time()
"car_id" => $car_id,
"route_id" => $route_id,
"driver_id" => $driver['id'],
"order_status" => 1,
"createtime" => time()
]);
}else{
$order_review_id=$order_review['id'];
} else {
$order_review_id = $order_review['id'];
}
//计算价格
$seatres=Db::name("seat")->where("id",$car['seat_id'])->find();
$seatres = Db::name("seat")->where("id", $car['seat_id'])->find();
$seat_no_array = explode(",", $seat_no);
$seat=json_decode($seatres['seat'],true);
$newseat=[];
foreach ($seat as $k=>$v){
if( in_array($seat[$k]['seat_no'],$seat_no_array)){
$newseat[$k]=$seat[$k];
}
$seat = json_decode($seatres['seat'], true);
$newseat = [];
foreach ($seat as $k => $v) {
if (in_array($seat[$k]['seat_no'], $seat_no_array)) {
$newseat[$k] = $seat[$k];
}
}
$price=0;
$specificaddress=Db::name("specificaddress")->where("id",$specificaddress_id)->find();
if($specificaddress){
$price=bcmul($number,$specificaddress['price'],2);
}else{
$price = 0;
$specificaddress = Db::name("specificaddress")->where("id", $specificaddress_id)->find();
if ($specificaddress) {
$price = bcmul($number, $specificaddress['price'], 2);
} else {
$this->error("价格计算错误");
}
$data=[
"order_no"=>getOrderSn(),
"price"=>$price,
"is_pay"=>"2",//未支付
"car_id"=>$car_id,
"order_review_id"=>$order_review_id,
"route_id"=>$route_id,
"specificaddress_id"=>$specificaddress_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"=>time(),
"position"=>$position,
"lat"=>$lat,
"lng"=>$lng,
"number"=>$number,
"remarks"=>$remarks,
"seat_no"=>$seat_no,
"intended_driver_id"=>$intended_driver_id,
$data = [
"order_no" => getOrderSn(),
"price" => $price,
"is_pay" => "2",//未支付
"car_id" => $car_id,
"order_review_id" => $order_review_id,
"route_id" => $route_id,
"specificaddress_id" => $specificaddress_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" => time(),
"position" => $position,
"lat" => $lat,
"lng" => $lng,
"number" => $number,
"remarks" => $remarks,
"seat_no" => $seat_no,
"intended_driver_id" => $intended_driver_id,
];
$res=Db::name("order")->insertGetId($data);
$res = Db::name("order")->insertGetId($data);
$userinfo = Db::name('user')
->where(['id' => $this->auth->id])
->field('id,wx_xcx_openid')
... ... @@ -185,7 +188,7 @@ class Car extends Base
'openid' => $userinfo['wx_xcx_openid'],
];
$f = \addons\epay\library\Service::submitOrder($params);
$this->success("请求成功",$f);
$this->success("请求成功", $f);
}
... ... @@ -195,58 +198,64 @@ class Car extends Base
* 查询乘车人信息
* @return void
*/
public function passengerlist(){
$res=Db::name("passenger")->where("user_id",$this->auth->id)->select();
return $this->success("请求成功",$res);
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
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 $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
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 $this->success("修改成功", $res);
}
/**
* 删除乘车人信息
* @return void
*/
public function deletepassenger(){
$id=$this->request->param("id");
$res=Db::name("passenger")->where("id",$id)->delete();
if($res){
return $this->success("删除成功",$res);
public function deletepassenger()
{
$id = $this->request->param("id");
$res = Db::name("passenger")->where("id", $id)->delete();
if ($res) {
return $this->success("删除成功", $res);
}else{
} else {
return $this->error("删除失败");
}
}
... ... @@ -255,30 +264,31 @@ class Car extends Base
* 查询订单
* @return void
*/
public function selectorder(){
$is_pay=$this->request->param("is_pay"); //是否支付:1=已支付,2=未支付,3=已退款,4=已取消
$page=$this->request->param("page");
$total=$this->request->param("total");
public function selectorder()
{
$is_pay = $this->request->param("is_pay"); //是否支付:1=已支付,2=未支付,3=已退款,4=已取消
$page = $this->request->param("page");
$total = $this->request->param("total");
$w['user_id'] = $this->auth->id;
if ($is_pay!=0){
if ($is_pay != 0) {
$w['is_pay'] = $is_pay;
}
$res=Db::name("order")
$res = Db::name("order")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where($w)
->page($page,$total)
->page($page, $total)
->order("id desc")
->select();
$amount=Db::name("order")
$amount = Db::name("order")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where($w)
->count();
$data=["data"=>$res,"amount"=>$amount];
return $this->success("请求成功",$data);
$data = ["data" => $res, "amount" => $amount];
return $this->success("请求成功", $data);
}
... ... @@ -286,75 +296,78 @@ class Car extends Base
* 切换司机
* @return void
*/
public function switching_driver(){
$res=Db::name("driver")->where("user_id",$this->auth->id)->find();
$car=Db::name("car")->where("driver_id",$res['id'])->find();
if($car){
public function switching_driver()
{
$res = Db::name("driver")->where("user_id", $this->auth->id)->find();
$car = Db::name("car")->where("driver_id", $res['id'])->find();
if ($car) {
//本月收入
$revenue_mon=sprintf('%.2f',Db::name("order")
$revenue_mon = sprintf('%.2f', Db::name("order")
->whereTime('create_time', 'month')
->where("is_pay",1)
->where("driver_id",$res['id'])
->where("is_pay", 1)
->where("driver_id", $res['id'])
->sum("price"));
//累计收入
$all_order=sprintf('%.2f',Db::name("order")
->where("is_pay",1)
->where("driver_id",$res['id'])
$all_order = sprintf('%.2f', Db::name("order")
->where("is_pay", 1)
->where("driver_id", $res['id'])
->sum("price"));
//累计订单
$all_orderquantity=sprintf('%.2f',Db::name("order")
->where("is_pay",1)
->where("driver_id",$res['id'])
$all_orderquantity = sprintf('%.2f', Db::name("order")
->where("is_pay", 1)
->where("driver_id", $res['id'])
->count());
//本月订单
$order_mon=Db::name("order")
->where("is_pay",1)
$order_mon = Db::name("order")
->where("is_pay", 1)
->whereTime('create_time', 'month')
->where("driver_id",$res['id'])
->where("driver_id", $res['id'])
->count();
//累计接送
$all_passenger=sprintf('%.2f',Db::name("order")
->where("is_pay",1)
->where("driver_id",$res['id'])
$all_passenger = sprintf('%.2f', Db::name("order")
->where("is_pay", 1)
->where("driver_id", $res['id'])
->sum("number"));
//本月接送
$month_passenger=sprintf('%.2f',Db::name("order")
->where("is_pay",1)
$month_passenger = sprintf('%.2f', Db::name("order")
->where("is_pay", 1)
->whereTime('create_time', 'month')
->where("driver_id",$res['id'])
->where("driver_id", $res['id'])
->sum("number"));
$res['license_plate']=$car['license_plate'];
$res['car_model']=$car['car_model'];
$res['revenue_mon']=$revenue_mon;
$res['all_order']=$all_order;
$res['order_mon']=$order_mon;
$res['all_orderquantity']=$all_orderquantity;
$res['all_passenger']=$all_passenger;
$res['month_passenger']=$month_passenger;
}else{
$res['license_plate'] = $car['license_plate'];
$res['car_model'] = $car['car_model'];
$res['revenue_mon'] = $revenue_mon;
$res['all_order'] = $all_order;
$res['order_mon'] = $order_mon;
$res['all_orderquantity'] = $all_orderquantity;
$res['all_passenger'] = $all_passenger;
$res['month_passenger'] = $month_passenger;
} else {
return $this->error("请求失败");
}
if($res){
return $this->success("请求成功",$res);
}else{
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){
$res['avatar']=full_image($res['avatar']);
return $this->success("请求成功",$res);
}else{
public function switching_user()
{
$res = Db::name("user")->where("id", $this->auth->id)->find();
if ($res) {
$res['avatar'] = full_image($res['avatar']);
return $this->success("请求成功", $res);
} else {
return $this->error("请求失败");
}
}
... ... @@ -366,14 +379,15 @@ class Car extends Base
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectroutebyname(){
$start_address=$this->request->param("start_address");
$end_address=$this->request->param("end_address");
$route=Db::name("route")
->where("end_address",$end_address)
->where("start_address",$start_address)
public function selectroutebyname()
{
$start_address = $this->request->param("start_address");
$end_address = $this->request->param("end_address");
$route = Db::name("route")
->where("end_address", $end_address)
->where("start_address", $start_address)
->find();
return $this->success("请求成功",$route);
return $this->success("请求成功", $route);
}
/**
... ... @@ -383,41 +397,45 @@ class Car extends Base
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectintercityroutebyname(){
$start_address=$this->request->param("start_address");
$end_address=$this->request->param("end_address");
$route=Db::name("route")
->where("end_address",$end_address)
->where("start_address",$start_address)
public function selectintercityroutebyname()
{
$start_address = $this->request->param("start_address");
$end_address = $this->request->param("end_address");
$route = Db::name("route")
->where("end_address", $end_address)
->where("start_address", $start_address)
->find();
return $this->success("请求成功",$route);
return $this->success("请求成功", $route);
}
/**
* 开始接送
* @return void
*/
public function connect_order(){
$id=$this->request->param("id");
$order=Db::name("order_review")->where("id",$id)->find();
if($order['order_status']==1){
$order=Db::name("order")->where("id",$id)->update(['order_status'=>2]);
public function connect_order()
{
$id = $this->request->param("id");
$order = Db::name("order_review")->where("id", $id)->find();
if ($order['order_status'] == 1) {
$order = Db::name("order")->where("id", $id)->update(['order_status' => 2]);
return $this->success("请求成功");
}else{
} else {
return $this->error("请求失败");
}
}
/**
* 订单进行
* @return void
*/
public function have_order(){
$id=$this->request->param("id");
$order=Db::name("order_review")->where("id",$id)->find();
if($order['order_status']==2){
$order=Db::name("order")->where("id",$id)->update(['order_status'=>3]);
public function have_order()
{
$id = $this->request->param("id");
$order = Db::name("order_review")->where("id", $id)->find();
if ($order['order_status'] == 2) {
$order = Db::name("order")->where("id", $id)->update(['order_status' => 3]);
return $this->success("请求成功");
}else{
} else {
return $this->error("请求失败");
}
}
... ... @@ -426,30 +444,31 @@ class Car extends Base
* 订单完成
* @return void
*/
public function complete_order(){
$id=$this->request->param("id");
$order=Db::name("order")->where("id",$id)->find();
if($order['order_status']==3){
$order=Db::name("order")->where("id",$id)->update(['order_status'=>4]);
if($order){
public function complete_order()
{
$id = $this->request->param("id");
$order = Db::name("order")->where("id", $id)->find();
if ($order['order_status'] == 3) {
$order = Db::name("order")->where("id", $id)->update(['order_status' => 4]);
if ($order) {
//给司机加余额
$car=Db::name("car")->where("id",$order['car_id'])->find();
$user=Db::name("user")->where("id",$car['user_id'])->find();
$money=bcadd($user['money'],$order['price'],2);
$addmoney=Db::name("user")->where("id",$id)->update(['money'=>$money]);
$data=[
"money"=>$money,
"type"=>2,
"create_time"=>time(),
"before"=>$user['money'],
"memo"=>$order['id']."订单完成",
"after"=>$user['money'],
$car = Db::name("car")->where("id", $order['car_id'])->find();
$user = Db::name("user")->where("id", $car['user_id'])->find();
$money = bcadd($user['money'], $order['price'], 2);
$addmoney = Db::name("user")->where("id", $id)->update(['money' => $money]);
$data = [
"money" => $money,
"type" => 2,
"create_time" => time(),
"before" => $user['money'],
"memo" => $order['id'] . "订单完成",
"after" => $user['money'],
];
$addmoney_log=Db::name("user_money_log")->insert($data);
$addmoney_log = Db::name("user_money_log")->insert($data);
}
return $this->success("请求成功");
}else{
} else {
return $this->error("请求失败");
}
}
... ... @@ -458,74 +477,77 @@ class Car extends Base
* 查询订单总览
* @return void
*/
public function selectorderreview(){
$order_status=$this->request->param("order_status"); //接送状态:1=未开始,2=接送中,3=进行中,4=已完成
$page=$this->request->param("page");
$total=$this->request->param("total");
$driver=Db::name("driver")->where("user_id",$this->auth->id)->find();
public function selectorderreview()
{
$order_status = $this->request->param("order_status"); //接送状态:1=未开始,2=接送中,3=进行中,4=已完成
$page = $this->request->param("page");
$total = $this->request->param("total");
$driver = Db::name("driver")->where("user_id", $this->auth->id)->find();
$w["a.driver_id"] = $driver["id"];
if ($order_status!=0){
if ($order_status != 0) {
$w["a.order_status"] = $order_status;
}
$res=Db::name("order_review")
$res = Db::name("order_review")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where($w)
->page($page,$total)
->page($page, $total)
->select();
foreach ($res as $k=>$v){
$res[$k]['price']=sprintf('%.2f',Db::name("order")->sum("price"));
$res[$k]['number']=Db::name("order")->sum("number");
foreach ($res as $k => $v) {
$res[$k]['price'] = sprintf('%.2f', Db::name("order")->sum("price"));
$res[$k]['number'] = Db::name("order")->sum("number");
}
$amount=Db::name("order_review")
$amount = Db::name("order_review")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where($w)
->count();
$data=["data"=>$res,"amount"=>$amount];
$data = ["data" => $res, "amount" => $amount];
return $this->success("请求成功",$data);
return $this->success("请求成功", $data);
}
/**
*司机查询订单
* @return void
*/
public function selectbydriver(){
public function selectbydriver()
{
//$order_status=$this->request->param("order_status"); //接送状态:1=未开始,2=接送中,3=进行中,4=已完成
$page=$this->request->param("page");
$total=$this->request->param("total");
$order_review_id=$this->request->param("order_review_id");
$driver=Db::name("driver")->where("user_id",$this->auth->id)->find();
$page = $this->request->param("page");
$total = $this->request->param("total");
$order_review_id = $this->request->param("order_review_id");
$driver = Db::name("driver")->where("user_id", $this->auth->id)->find();
$w['driver_id'] = $driver["id"];
$w['order_review_id'] = $order_review_id;
$res=Db::name("order")
$w['order_review_id'] = $order_review_id;
$res = Db::name("order")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where($w)
->page($page,$total)
->page($page, $total)
->select();
$amount=Db::name("order")
$amount = Db::name("order")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where($w)
->count();
$data=["data"=>$res,"amount"=>$amount];
return $this->success("请求成功",$data);
$data = ["data" => $res, "amount" => $amount];
return $this->success("请求成功", $data);
}
/**
*紧急手机号
* @return void
*/
public function alarm_phone(){
public function alarm_phone()
{
$content = config("site.alarm_phone");//微信小程序AppID
return $this->success("请求成功",$content);
return $this->success("请求成功", $content);
}
/**
... ... @@ -538,15 +560,16 @@ class Car extends Base
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function refund(){
$id=$this->request->param("id");
public function refund()
{
$id = $this->request->param("id");
//查询订单
$order=Db::name("order")->where("id",$id)->find();
if($order['is_pay']==1){
if($order['order_status']!=1){
$order = Db::name("order")->where("id", $id)->find();
if ($order['is_pay'] == 1) {
if ($order['order_status'] != 1) {
$this->error("该订单无法退款");
}
if($order['pay_type']=="offlinepay"){
if ($order['pay_type'] == "offlinepay") {
$relogs['update_time'] = time();
$relogs['is_pay'] = 4;
$relogs['refund_time'] = time();
... ... @@ -555,32 +578,32 @@ class Car extends Base
->update($relogs);
}
//$this->error("该订单无法退款");
//拼接退款参数
$pay_fee = $order['price'];
$refund_fee = $pay_fee;
$order_sn = $order['order_no'];
$pay_type = 'wechat';
$reason = '订单退款';
$notifyurl = 'https://wyc.tenyes.cn/api/index/refundNotifyx';//退款回调地址
//直接调用退款方法传参即可
$response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($order['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp');
$response = json_encode($response);
$response = json_decode($response, true);
file_put_contents("pcl_repay_v2.log", date("Y-m-d H:i:s") . "::" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
if (!empty($response['return_code'] == 'SUCCESS')) {
//退款成功,更新退款记录
$relogs['update_time'] = time();
$relogs['is_pay'] = 3;
$relogs['out_refund_no'] = $response['out_refund_no'];
$relogs['refund_time'] = time();
$rs2 = Db::name('order')
->where(['id' => $order['id']])
->update($relogs);
//拼接退款参数
$pay_fee = $order['price'];
$refund_fee = $pay_fee;
$order_sn = $order['order_no'];
$pay_type = 'wechat';
$reason = '订单退款';
$notifyurl = 'https://wyc.tenyes.cn/api/index/refundNotifyx';//退款回调地址
//直接调用退款方法传参即可
$response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($order['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp');
$response = json_encode($response);
$response = json_decode($response, true);
file_put_contents("pcl_repay_v2.log", date("Y-m-d H:i:s") . "::" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
if (!empty($response['return_code'] == 'SUCCESS')) {
//退款成功,更新退款记录
$relogs['update_time'] = time();
$relogs['is_pay'] = 3;
$relogs['out_refund_no'] = $response['out_refund_no'];
$relogs['refund_time'] = time();
$rs2 = Db::name('order')
->where(['id' => $order['id']])
->update($relogs);
} else {
$this->error('退款失败');
}
$this->success("退款成功");
} else {
$this->error('退款失败');
}
$this->success("退款成功");
}else{
$relogs['is_pay'] = 4;
$rs2 = Db::name('order')
->where(['id' => $order['id']])
... ... @@ -593,134 +616,140 @@ class Car extends Base
* 添加临时车辆路线
* @return void
*/
public function addtemporaryroute(){
$user_id=$this->auth->id;
$driver=Db::name("driver")->where("user_id",$user_id)->find();
$car=Db::name("car")->where("driver_id",$driver['id'])->find();
$data=[
'user_id'=>$user_id,
'car_id'=>$car['id'],
'route_id'=>$car['route_id'],
'driver_id'=>$driver['id'],
'create_time'=>time(),
public function addtemporaryroute()
{
$user_id = $this->auth->id;
$driver = Db::name("driver")->where("user_id", $user_id)->find();
$car = Db::name("car")->where("driver_id", $driver['id'])->find();
$data = [
'user_id' => $user_id,
'car_id' => $car['id'],
'route_id' => $car['route_id'],
'driver_id' => $driver['id'],
'create_time' => time(),
];
//判断是否重复
//开始时间
$statr_time=strtotime(date("Y-m-d",time()));
$end_time=$statr_time+86400;
$is_repeat=Db::name("temporary_route")
->where("user_id",$user_id)
->where("car_id",$car['id'])
->where("create_time",">",$statr_time)
->where("create_time","<",$end_time)
->where("driver_id",$driver['id'])
$statr_time = strtotime(date("Y-m-d", time()));
$end_time = $statr_time + 86400;
$is_repeat = Db::name("temporary_route")
->where("user_id", $user_id)
->where("car_id", $car['id'])
->where("create_time", ">", $statr_time)
->where("create_time", "<", $end_time)
->where("driver_id", $driver['id'])
->find();
if($is_repeat){
if ($is_repeat) {
return $this->error("添加失败");
}
$res=Db::name("temporary_route")->insert($data);
return $this->success("添加成功",$res);
$res = Db::name("temporary_route")->insert($data);
return $this->success("添加成功", $res);
}
/**
* 意向司机
* @return void
*/
public function intention_driver(){
$route_id=$this->request->param("route_id");
$car=Db::name("car")
public function intention_driver()
{
$route_id = $this->request->param("route_id");
$car = Db::name("car")
->alias("a")
->join("driver b","a.driver_id=b.id")
->where("route_id",$route_id)
->join("driver b", "a.driver_id=b.id")
->where("route_id", $route_id)
->field("b.id,b.name,a.license_plate")
->select();
return $this->success("请求成功",$car);
return $this->success("请求成功", $car);
}
/**
* 添加紧急联系人手机
* @return void
*/
public function emergency_phone(){
$emergency_phone=$this->request->param("emergency_phone");
$user_id=$this->auth->id;
$res=Db::name("user")
->where("id",$user_id)
->update(['emergency_phone'=>$emergency_phone]);
return $this->success("修改成功",$res);
public function emergency_phone()
{
$emergency_phone = $this->request->param("emergency_phone");
$user_id = $this->auth->id;
$res = Db::name("user")
->where("id", $user_id)
->update(['emergency_phone' => $emergency_phone]);
return $this->success("修改成功", $res);
}
/**
* 获取轮播图
* @return void
*/
public function getimage(){
$res=Db::name("image")->where("is_show",1)->select();
foreach ($res as $k=>$v){
$res[$k]['image']=full_image($res[$k]['image']);
public function getimage()
{
$res = Db::name("image")->where("is_show", 1)->select();
foreach ($res as $k => $v) {
$res[$k]['image'] = full_image($res[$k]['image']);
}
return $this->success("请求成功",$res);
return $this->success("请求成功", $res);
}
/**
* 获取座位详情
* @return void
*/
public function car_seat(){
$car_id=$this->request->param("car_id");
$specificaddress_id=$this->request->param("specificaddress_id");
public function car_seat()
{
$car_id = $this->request->param("car_id");
$specificaddress_id = $this->request->param("specificaddress_id");
//查询车辆信息
$specificaddress=Db::name("specificaddress")->where("id",$specificaddress_id)->find();
$car=Db::name("car")->where("id",$car_id)->find();
$seat=Db::name("seat")->where("id",$car['seat_id'])->find();
$seat['seat']=json_decode($seat['seat'],true);
$specificaddress = Db::name("specificaddress")->where("id", $specificaddress_id)->find();
$car = Db::name("car")->where("id", $car_id)->find();
$seat = Db::name("seat")->where("id", $car['seat_id'])->find();
$seat['seat'] = json_decode($seat['seat'], true);
//查询当日订单
$statr_time=strtotime(date("Y-m-d",time()));
$end_time=$statr_time+86400;
$order=Db::name("order")
->where("create_time",">",$statr_time)
->where("create_time","<",$end_time)
->where('type',1)
->where('car_id',$car_id)
$statr_time = strtotime(date("Y-m-d", time()));
$end_time = $statr_time + 86400;
$order = Db::name("order")
->where("create_time", ">", $statr_time)
->where("create_time", "<", $end_time)
->where('type', 1)
->where('car_id', $car_id)
->field("seat_no")
->select();
if($order){
foreach ($order as $k=>$v){
$seat_no[$k]=$order[$k]["seat_no"];
$seat_no[$k]['seat_price']=$specificaddress["price"];
}
$seat_no = array_filter($seat_no, function($value) {
return !empty($value);
});
$seat_no = implode(',', $seat_no);
if ($order) {
foreach ($order as $k => $v) {
$seat_no[$k] = $order[$k]["seat_no"];
$seat_no[$k]['seat_price'] = $specificaddress["price"];
}
$seat_no = array_filter($seat_no, function ($value) {
return !empty($value);
});
$seat_no = implode(',', $seat_no);
$seat_no = explode(",", $seat_no);
$seat_no = explode(",", $seat_no);
}
foreach ($seat['seat'] as $k=>$v){
if($order){
if( in_array($seat['seat'][$k]['seat_no'],$seat_no)){
$seat['seat'][$k]['is_sale']=1;
}else{
$seat['seat'][$k]['is_sale']=0;
foreach ($seat['seat'] as $k => $v) {
if ($order) {
if (in_array($seat['seat'][$k]['seat_no'], $seat_no)) {
$seat['seat'][$k]['is_sale'] = 1;
} else {
$seat['seat'][$k]['is_sale'] = 0;
}
}else{
$seat['seat'][$k]['is_sale']=0;
} else {
$seat['seat'][$k]['is_sale'] = 0;
}
}
return $this->success("请求成功",$seat);
return $this->success("请求成功", $seat);
}
/**
* 支付信息
* @return void
*/
public function order_log(){
$page=$this->request->param("page");
$total=$this->request->param("total");
$res=Db::name("order_log")->where("user_id",$this->auth->id)
->page($page,$total)->select();
return $this->success("请求成功",$res);
public function order_log()
{
$page = $this->request->param("page");
$total = $this->request->param("total");
$res = Db::name("order_log")->where("user_id", $this->auth->id)
->page($page, $total)->select();
return $this->success("请求成功", $res);
}
... ... @@ -728,49 +757,51 @@ class Car extends Base
* 钱包金额
* @return void
*/
public function mywallet(){
$res=Db::name("user")->where("id",$this->auth->id)->field("money")->find();
return $this->success("请求成功",$res);
public function mywallet()
{
$res = Db::name("user")->where("id", $this->auth->id)->field("money")->find();
return $this->success("请求成功", $res);
}
/**
* 提现接口
* @return void
*/
public function withdrawal(){
$money=$this->request->param("money");
$name=$this->request->param("name");
$bank_card=$this->request->param("bank_card");
$user_id=$this->auth->id;
$user=Db::name("user")->where("id",$user_id)->find();
if($user['money']<$money){
public function withdrawal()
{
$money = $this->request->param("money");
$name = $this->request->param("name");
$bank_card = $this->request->param("bank_card");
$user_id = $this->auth->id;
$user = Db::name("user")->where("id", $user_id)->find();
if ($user['money'] < $money) {
$this->error("金额不足");
}
//减少金额
$newmoney=bcsub($user['money'],$money,2);
$updatemoney=Db::name("user")->where("id",$user_id)->update(['money'=>$newmoney]);
if($updatemoney){
$newmoney = bcsub($user['money'], $money, 2);
$updatemoney = Db::name("user")->where("id", $user_id)->update(['money' => $newmoney]);
if ($updatemoney) {
//添加提现记录
$data=[
"user_id"=>$user_id,
"bank_card"=>$bank_card,
"name"=>$name,
"create_time"=>time(),
"money"=>$money,
"newmoney"=>$newmoney,
$data = [
"user_id" => $user_id,
"bank_card" => $bank_card,
"name" => $name,
"create_time" => time(),
"money" => $money,
"newmoney" => $newmoney,
];
$res=Db::name("withdrawal")->insert($data);
$data=[
"money"=>$money,
"type"=>2,
"create_time"=>time(),
"before"=>$user['money'],
"memo"=>"提现",
"after"=>$newmoney,
$res = Db::name("withdrawal")->insert($data);
$data = [
"money" => $money,
"type" => 2,
"create_time" => time(),
"before" => $user['money'],
"memo" => "提现",
"after" => $newmoney,
];
$addmoney_log=Db::name("user_money_log")->insert($data);
return $this->success("提现成功",$res);
}else{
$addmoney_log = Db::name("user_money_log")->insert($data);
return $this->success("提现成功", $res);
} else {
return $this->error("提现失败");
}
}
... ... @@ -779,52 +810,55 @@ class Car extends Base
* 提现金额列表
* @return void
*/
public function withdrawallist(){
$page=$this->request->param("page");
$total=$this->request->param("total");
$user_money_log=Db::name("withdrawal")
->where("user_id",$this->auth->id)
->page($page,$total)
public function withdrawallist()
{
$page = $this->request->param("page");
$total = $this->request->param("total");
$user_money_log = Db::name("withdrawal")
->where("user_id", $this->auth->id)
->page($page, $total)
->select();
return $this->success("请求成功",$user_money_log);
return $this->success("请求成功", $user_money_log);
}
/**
* 司机认证
* @return void
*/
public function driverauthentication(){
$license_plate=$this->request->param("license_plate");//车牌号
$car_model=$this->request->param("car_model");//车型
$colour=$this->request->param("colour");//颜色
$name=$this->request->param("name");//名字
$driving_license=$this->request->param("driving_license");//行驶证
$driver_license=$this->request->param("driver_license");//驾照
$driving_license=$this->uploadBase64($driving_license);
$driver_license=$this->uploadBase64($driver_license);
public function driverauthentication()
{
$license_plate = $this->request->param("license_plate");//车牌号
$car_model = $this->request->param("car_model");//车型
$colour = $this->request->param("colour");//颜色
$name = $this->request->param("name");//名字
$driving_license = $this->request->param("driving_license");//行驶证
$driver_license = $this->request->param("driver_license");//驾照
$driving_license = $this->uploadBase64($driving_license);
$driver_license = $this->uploadBase64($driver_license);
//判断是否已有
$isdriver=Db::name("driver")->where("user_id",$this->auth->id)->find();
if($isdriver){
$isdriver = Db::name("driver")->where("user_id", $this->auth->id)->find();
if ($isdriver) {
return $this->error("已认证");
}
$driver=Db::name("driver")
$driver = Db::name("driver")
->insertGetId([
"user_id"=>$this->auth->id,
"name"=>$name,
"phone"=>$this->auth->mobile
"user_id" => $this->auth->id,
"name" => $name,
"phone" => $this->auth->mobile
]);
$res=Db::name("car")
$res = Db::name("car")
->insert([
"license_plate"=>$license_plate,
"car_model"=>$car_model,
"colour"=>$colour,
"driver_id"=>$driver,
"driving_license"=>$driving_license,
"driver_license"=>$driver_license,
"status"=>2,
"license_plate" => $license_plate,
"car_model" => $car_model,
"colour" => $colour,
"driver_id" => $driver,
"driving_license" => $driving_license,
"driver_license" => $driver_license,
"status" => 2,
]);
return $this->success("请求成功",$res);
return $this->success("请求成功", $res);
}
public function uploadBase64($base64Str)
{
// 将Base64字符串转换为文件并保存
... ... @@ -851,18 +885,20 @@ class Car extends Base
* 乘车须知
* @return void
*/
public function getriding_instructions(){
public function getriding_instructions()
{
$content = config("site.riding_instructions");
return $this->success("请求成功",$content);
return $this->success("请求成功", $content);
}
/**
* 通知公告
* @return void
*/
public function getnotice(){
public function getnotice()
{
$content = config("site.notice");
return $this->success("请求成功",$content);
return $this->success("请求成功", $content);
}
... ... @@ -870,18 +906,20 @@ class Car extends Base
* 司机认证
* @return void
*/
public function getdriver_authentication(){
public function getdriver_authentication()
{
$content = config("site.driver_authentication");
return $this->success("请求成功",$content);
return $this->success("请求成功", $content);
}
/**
* 关于我们
* @return void
*/
public function getaboutwe(){
public function getaboutwe()
{
$content = config("site.aboutwe");
return $this->success("请求成功",$content);
return $this->success("请求成功", $content);
}
... ... @@ -889,7 +927,8 @@ class Car extends Base
* 创建包车订单
* @return void
*/
public function createcharterorder(){
public function createcharterorder()
{
$route_id = $this->request->param("route_id");//线路
$number = $this->request->param("number");//乘车人数
... ... @@ -899,31 +938,31 @@ class Car extends Base
$charter_num = $this->request->param("charter_num");//包车数量
$intended_driver_id = $this->request->param("intended_driver_id");//意向司机
$remarks = $this->request->param("remarks");//备注
$carmodel=Db::name("carmodel")->where("id",$carmodel_id)->find();
$carmodel = Db::name("carmodel")->where("id", $carmodel_id)->find();
$specificaddress_id = $this->request->param("specificaddress_id");//区域id
$chartercar=Db::name("chartercar")
->where("specificaddress_id",$specificaddress_id)
->where("carmodel_id",$carmodel_id)
$chartercar = Db::name("chartercar")
->where("specificaddress_id", $specificaddress_id)
->where("carmodel_id", $carmodel_id)
->find();
$price=0;
$price=bcmul($charter_num,$chartercar['price'],2);
$data=[
"order_no"=>getOrderSn(),
"price"=>$price,
"reservation_time"=>$reservation_time,
"is_pay"=>"2",//未支付
"route_id"=>$route_id,
"user_id"=>$this->auth->id,
"phone"=>$phone,
"create_time"=>time(),
"reservation_time"=>time(),
"type"=>2,
"number"=>$number,
"remarks"=>$remarks,
"intended_driver_id"=>$intended_driver_id,
$price = 0;
$price = bcmul($charter_num, $chartercar['price'], 2);
$data = [
"order_no" => getOrderSn(),
"price" => $price,
"reservation_time" => $reservation_time,
"is_pay" => "2",//未支付
"route_id" => $route_id,
"user_id" => $this->auth->id,
"phone" => $phone,
"create_time" => time(),
"reservation_time" => time(),
"type" => 2,
"number" => $number,
"remarks" => $remarks,
"intended_driver_id" => $intended_driver_id,
];
$res=Db::name("order")->insertGetId($data);
$res = Db::name("order")->insertGetId($data);
$userinfo = Db::name('user')
->where(['id' => $this->auth->id])
->field('id,wx_xcx_openid')
... ... @@ -938,7 +977,7 @@ class Car extends Base
'openid' => $userinfo['wx_xcx_openid'],
];
$f = \addons\epay\library\Service::submitOrder($params);
$this->success("请求成功",$f);
$this->success("请求成功", $f);
}
... ... @@ -946,7 +985,8 @@ class Car extends Base
* 创建包车订单
* @return void
*/
public function createcharterorderofflinepay(){
public function createcharterorderofflinepay()
{
$route_id = $this->request->param("route_id");//线路
$number = $this->request->param("number");//乘车人数
$reservation_time = $this->request->param("reservation_time");//预约时间
... ... @@ -955,33 +995,33 @@ class Car extends Base
$charter_num = $this->request->param("charter_num");//包车数量
$intended_driver_id = $this->request->param("intended_driver_id");//意向司机
$remarks = $this->request->param("remarks");//备注
$carmodel=Db::name("carmodel")->where("id",$carmodel_id)->find();
$carmodel = Db::name("carmodel")->where("id", $carmodel_id)->find();
$specificaddress_id = $this->request->param("specificaddress_id");//区域id
$chartercar=Db::name("chartercar")
->where("specificaddress_id",$specificaddress_id)
->where("carmodel_id",$carmodel_id)
$chartercar = Db::name("chartercar")
->where("specificaddress_id", $specificaddress_id)
->where("carmodel_id", $carmodel_id)
->find();
$price=0;
$price=bcmul($charter_num,$chartercar['price'],2);
$data=[
"order_no"=>getOrderSn(),
"price"=>$price,
"reservation_time"=>$reservation_time,
"is_pay"=>1,//未支付
"route_id"=>$route_id,
"user_id"=>$this->auth->id,
"phone"=>$phone,
"pay_type"=>"offlinepay",
"create_time"=>time(),
"reservation_time"=>time(),
"type"=>2,
"number"=>$number,
"remarks"=>$remarks,
"intended_driver_id"=>$intended_driver_id,
$price = 0;
$price = bcmul($charter_num, $chartercar['price'], 2);
$data = [
"order_no" => getOrderSn(),
"price" => $price,
"reservation_time" => $reservation_time,
"is_pay" => 1,//未支付
"route_id" => $route_id,
"user_id" => $this->auth->id,
"phone" => $phone,
"pay_type" => "offlinepay",
"create_time" => time(),
"reservation_time" => time(),
"type" => 2,
"number" => $number,
"remarks" => $remarks,
"intended_driver_id" => $intended_driver_id,
];
$res=Db::name("order")->insertGetId($data);
$res = Db::name("order")->insertGetId($data);
$this->success("请求成功",$res);
$this->success("请求成功", $res);
}
... ... @@ -989,7 +1029,8 @@ class Car extends Base
* 创建城际订单
* @return void
*/
public function createintercityorder(){
public function createintercityorder()
{
$is_qrcode = $this->request->param("is_qrcode");//二维码下单:0=不是,1=是
$route_id = $this->request->param("route_id");//线路
$position = $this->request->param("position");//上车地址
... ... @@ -1002,37 +1043,37 @@ class Car extends Base
$phone = $this->request->param("phone");//联系电话
$intended_driver_id = $this->request->param("intended_driver_id");//意向司机
$remarks = $this->request->param("remarks");//备注
$driver=Db::name("driver")->where("id",$intended_driver_id)->find();
$car=Db::name("car")->where("driver_id",$driver['id'])->find();
$carmodel=Db::name("carmodel")->where("id",$car['carmodel_id'])->find();
$route=Db::name("route")->where("id",$car['route_id'])->find();
$price=0;
$specificaddress=Db::name("specificaddress")->where("id",$specificaddress_id)->find();
if($specificaddress){
$price=bcmul($number,$specificaddress['price'],2);
}else{
$driver = Db::name("driver")->where("id", $intended_driver_id)->find();
$car = Db::name("car")->where("driver_id", $driver['id'])->find();
$carmodel = Db::name("carmodel")->where("id", $car['carmodel_id'])->find();
$route = Db::name("route")->where("id", $car['route_id'])->find();
$price = 0;
$specificaddress = Db::name("specificaddress")->where("id", $specificaddress_id)->find();
if ($specificaddress) {
$price = bcmul($number, $specificaddress['price'], 2);
} else {
$this->error("价格计算错误");
}
$data=[
"order_no"=>getOrderSn(),
"price"=>$price,
"driver_id"=>$driver['id'],
"is_qrcode"=>$is_qrcode,
"specificaddress_id"=>$specificaddress_id,
"reservation_time"=>$reservation_time,
"is_pay"=>"2",//未支付
"route_id"=>$route_id,
"user_id"=>$this->auth->id,
"driver_id"=>$driver['id'],
"phone"=>$phone,
"create_time"=>time(),
"reservation_time"=>time(),
"type"=>2,
"number"=>$number,
"remarks"=>$remarks,
"intended_driver_id"=>$intended_driver_id,
$data = [
"order_no" => getOrderSn(),
"price" => $price,
"driver_id" => $driver['id'],
"is_qrcode" => $is_qrcode,
"specificaddress_id" => $specificaddress_id,
"reservation_time" => $reservation_time,
"is_pay" => "2",//未支付
"route_id" => $route_id,
"user_id" => $this->auth->id,
"driver_id" => $driver['id'],
"phone" => $phone,
"create_time" => time(),
"reservation_time" => time(),
"type" => 2,
"number" => $number,
"remarks" => $remarks,
"intended_driver_id" => $intended_driver_id,
];
$res=Db::name("order")->insertGetId($data);
$res = Db::name("order")->insertGetId($data);
$userinfo = Db::name('user')
->where(['id' => $this->auth->id])
->field('id,wx_xcx_openid')
... ... @@ -1047,7 +1088,7 @@ class Car extends Base
'openid' => $userinfo['wx_xcx_openid'],
];
$f = \addons\epay\library\Service::submitOrder($params);
$this->success("请求成功",$f);
$this->success("请求成功", $f);
}
... ... @@ -1056,7 +1097,8 @@ class Car extends Base
* 创建城际订单线下支付
* @return void
*/
public function createintercityorderofflinepay(){
public function createintercityorderofflinepay()
{
$is_qrcode = $this->request->param("is_qrcode");//二维码下单:0=不是,1=是
$route_id = $this->request->param("route_id");//线路
$number = $this->request->param("number");//乘车人数
... ... @@ -1069,57 +1111,59 @@ class Car extends Base
$specificaddress_id = $this->request->param("specificaddress_id");//区域id
$intended_driver_id = $this->request->param("intended_driver_id");//意向司机
$remarks = $this->request->param("remarks");//备注
$driver=Db::name("driver")->where("id",$intended_driver_id)->find();
$car=Db::name("car")->where("driver_id",$driver['id'])->find();
$carmodel=Db::name("carmodel")->where("id",$carmodel_id)->find();
$route=Db::name("route")->where("id",$car['route_id'])->find();
$price=0;
$specificaddress=Db::name("specificaddress")->where("id",$specificaddress_id)->find();
if($specificaddress){
$price=bcmul($number,$specificaddress['price'],2);
}else{
$driver = Db::name("driver")->where("id", $intended_driver_id)->find();
$car = Db::name("car")->where("driver_id", $driver['id'])->find();
$carmodel = Db::name("carmodel")->where("id", $carmodel_id)->find();
$route = Db::name("route")->where("id", $car['route_id'])->find();
$price = 0;
$specificaddress = Db::name("specificaddress")->where("id", $specificaddress_id)->find();
if ($specificaddress) {
$price = bcmul($number, $specificaddress['price'], 2);
} else {
$this->error("价格计算错误");
}
$data=[
"order_no"=>getOrderSn(),
"price"=>$price,
"is_qrcode"=>$is_qrcode,
"specificaddress_id"=>$specificaddress_id,
"reservation_time"=>$reservation_time,
"is_pay"=>1,//未支付
"route_id"=>$route_id,
"driver_id"=>$driver['id'],
"user_id"=>$this->auth->id,
"phone"=>$phone,
"pay_type"=>"offlinepay",
"create_time"=>time(),
"reservation_time"=>time(),
"type"=>2,
"number"=>$number,
"remarks"=>$remarks,
"intended_driver_id"=>$intended_driver_id,
$data = [
"order_no" => getOrderSn(),
"price" => $price,
"is_qrcode" => $is_qrcode,
"specificaddress_id" => $specificaddress_id,
"reservation_time" => $reservation_time,
"is_pay" => 1,//未支付
"route_id" => $route_id,
"driver_id" => $driver['id'],
"user_id" => $this->auth->id,
"phone" => $phone,
"pay_type" => "offlinepay",
"create_time" => time(),
"reservation_time" => time(),
"type" => 2,
"number" => $number,
"remarks" => $remarks,
"intended_driver_id" => $intended_driver_id,
];
$res=Db::name("order")->insertGetId($data);
$this->success("请求成功",$res);
$res = Db::name("order")->insertGetId($data);
$this->success("请求成功", $res);
}
/**
* 查询二维码
* @return void
*/
public function qrcode(){
$driver=Db::name("driver")->where('user_id',$this->auth->id)->field("place_image")->find();
$driver['place_image']=full_image($driver['place_image']);
$this->success("请求成功",$driver);
public function qrcode()
{
$driver = Db::name("driver")->where('user_id', $this->auth->id)->field("place_image")->find();
$driver['place_image'] = full_image($driver['place_image']);
$this->success("请求成功", $driver);
}
/**
* 查询二维码
* @return void
*/
public function carmodel(){
$carmodel=Db::name("carmodel")->select();
$this->success("请求成功",$carmodel);
public function carmodel()
{
$carmodel = Db::name("carmodel")->select();
$this->success("请求成功", $carmodel);
}
/**
... ... @@ -1130,47 +1174,49 @@ class Car extends Base
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectintercityorder(){
$page=$this->request->param("page");
$total=$this->request->param("total");
$start_time=$this->request->param("start_time");
$end_time=$this->request->param("end_time");
$driver=Db::name("driver")->where('user_id',7)->find();
$res=Db::name("order")
public function selectintercityorder()
{
$page = $this->request->param("page");
$total = $this->request->param("total");
$start_time = $this->request->param("start_time");
$end_time = $this->request->param("end_time");
$driver = Db::name("driver")->where('user_id', 7)->find();
$res = Db::name("order")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where("a.driver_id",$driver["id"])
->where("is_qrcode",1)
->where("a.create_time",">",$start_time)
->where("a.create_time","<",$end_time)
->page($page,$total)
->where("a.driver_id", $driver["id"])
->where("is_qrcode", 1)
->where("a.create_time", ">", $start_time)
->where("a.create_time", "<", $end_time)
->page($page, $total)
->select();
$amount=Db::name("order")
$amount = Db::name("order")
->alias("a")
->join("route b","a.route_id=b.id")
->join("route b", "a.route_id=b.id")
->field("a.*,b.start_address,b.end_address")
->where("driver_id",$driver["id"])
->where("is_qrcode",1)
->where("a.create_time",">",$start_time)
->where("a.create_time","<",$end_time)
->where("driver_id", $driver["id"])
->where("is_qrcode", 1)
->where("a.create_time", ">", $start_time)
->where("a.create_time", "<", $end_time)
->count();
$data=["data"=>$res,"amount"=>$amount];
return $this->success("请求成功",$data);
$data = ["data" => $res, "amount" => $amount];
return $this->success("请求成功", $data);
}
/**
* 从蒙自出发
* @return void
*/
public function set_out(){
$where = ["type"=>1];
public function set_out()
{
$where = ["type" => 1];
$indexList = [];
$itemArr = [];
$list = Db::name("route")->where($where)
->select();
foreach ($list as $k=>$v){
$list[$k]['specificaddress']=Db::name("specificaddress")->where("route_id",$list[$k]['id'])->select();
->select();
foreach ($list as $k => $v) {
$list[$k]['specificaddress'] = Db::name("specificaddress")->where("route_id", $list[$k]['id'])->select();
}
$charArray = [];
if (!empty($list)) {
... ... @@ -1201,14 +1247,15 @@ class Car extends Base
* 到达蒙自
* @return void
*/
public function reach(){
$where = ["type"=>2];
public function reach()
{
$where = ["type" => 2];
$indexList = [];
$itemArr = [];
$list = Db::name("route")->where($where)
->select();
foreach ($list as $k=>$v){
$list[$k]['specificaddress']=Db::name("specificaddress")->where("route_id",$list[$k]['id'])->select();
foreach ($list as $k => $v) {
$list[$k]['specificaddress'] = Db::name("specificaddress")->where("route_id", $list[$k]['id'])->select();
}
$charArray = [];
if (!empty($list)) {
... ... @@ -1241,36 +1288,37 @@ class Car extends Base
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function orderpayagain(){
$order_no=$this->request->param("order_no");
$order=Db::name("order")->where("order_no",$order_no)->find();
public function orderpayagain()
{
$order_no = $this->request->param("order_no");
$order = Db::name("order")->where("order_no", $order_no)->find();
if(!$order){
$this->error("无此订单");
}
if($order['is_pay']!=2){
$this->error("无法支付该订单");
}
$data=[
"order_no"=>getOrderSn(),
];
$res=Db::name("order")->where("id",$order['id'])->update($data);
$order=Db::name("order")->where("id",$order['id'])->find();
if (!$order) {
$this->error("无此订单");
}
if ($order['is_pay'] != 2) {
$this->error("无法支付该订单");
}
$data = [
"order_no" => getOrderSn(),
];
$res = Db::name("order")->where("id", $order['id'])->update($data);
$order = Db::name("order")->where("id", $order['id'])->find();
$userinfo = Db::name('user')
->where(['id' => $this->auth->id])
->field('id,wx_xcx_openid')
->find();
$notifyURI = $this->doman . '/addons/epay/api/OrderPayNtf';
$params = [
$notifyURI = $this->doman . '/addons/epay/api/OrderPayNtf';
$params = [
'amount' => $order['price'],
'orderid' => $order['order_no'],
'type' => 'wechat',
'notifyurl' => $notifyURI,
'method' => 'miniapp',
'openid' => $userinfo['wx_xcx_openid'],
];
];
$f = \addons\epay\library\Service::submitOrder($params);
$this->success("请求成功",$f);
$this->success("请求成功", $f);
}
/**
... ... @@ -1280,10 +1328,11 @@ class Car extends Base
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectspecificaddress(){
$route_id=$this->request->param("route_id");
$specificaddress=Db::name("specificaddress")->where("route_id",$route_id)->select();
$this->success("请求成功",$specificaddress);
public function selectspecificaddress()
{
$route_id = $this->request->param("route_id");
$specificaddress = Db::name("specificaddress")->where("route_id", $route_id)->select();
$this->success("请求成功", $specificaddress);
}
... ... @@ -1291,32 +1340,32 @@ class Car extends Base
* 查询订单中选中的座位
* @return void
*/
public function findseat(){
$order_id=$this->request->param("order_id");
$order=Db::name("order")->where("id",$order_id)->find();
$car=Db::name("car")->where("id",$order['car_id'])->find();
$seat=Db::name("seat")->where("id",$car['seat_id'])->find();
$seat_data=json_decode($seat['seat'],true);
$seat_no = array_filter($seat_data, function($value) {
public function findseat()
{
$order_id = $this->request->param("order_id");
$order = Db::name("order")->where("id", $order_id)->find();
$car = Db::name("car")->where("id", $order['car_id'])->find();
$seat = Db::name("seat")->where("id", $car['seat_id'])->find();
$seat_data = json_decode($seat['seat'], true);
$seat_no = array_filter($seat_data, function ($value) {
return !empty($value);
});
print_r($seat_no);return;
$orderseat_no = explode(",", $order["seat_no"]);
if($seat_data){
if($order['seat_no']){
foreach ($seat_data as $k=>$v){
foreach ($orderseat_no as $ks=>$vs){
if($seat_data[$k]["seat_no"]==$orderseat_no[$ks]){
$seat_data[$k]["is_select"]=1;
}else{
$seat_data[$k]["is_select"]=0;
if ($seat_data) {
if ($order['seat_no']) {
foreach ($seat_data as $k => $v) {
foreach ($orderseat_no as $ks => $vs) {
if ($seat_data[$k]["seat_no"] == $orderseat_no[$ks]) {
$seat_data[$k]["is_select"] = 1;
} else {
$seat_data[$k]["is_select"] = 0;
}
}
}
}
}
}
$this->success("请求成功",$seat_data);
}else{
$this->success("请求成功", $seat_data);
} else {
$this->error("请求失败");
}
}
... ...