作者 郭文星

123

... ... @@ -52,4 +52,21 @@ if (!function_exists('insert_openid_info')) {
}
return true;
}
}
/**
* 生成订单号
* 重复就重新生成
*/
if (!function_exists('getOrderSn')) {
function getOrderSn()
{
$orderid = date("YmdHis") . mt_rand(1000, 999999);
$odcks = \think\Db::name('order')
->where(['order_no' => $orderid])
->find();
while (!empty($odcks)) {
$orderid = date("YmdHis") . mt_rand(1000, 999999);
}
return $orderid;
}
}
\ No newline at end of file
... ...
... ... @@ -58,15 +58,63 @@ class Car extends Api
* @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");
$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 = 'https://wyc.tenyes.cn/addons/epay/api/notifyx/type/wechat';
$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);
print_r($f);return;
$this->success("请求成功",$res);
}
... ...