...
|
...
|
@@ -20,20 +20,18 @@ use wxapp\pay\WeixinPay; |
|
|
*/
|
|
|
class OrderController extends HomeBaseController{
|
|
|
|
|
|
/**
|
|
|
* @title 生成订单
|
|
|
* @description 生成订单,加入开始时间和用户id
|
|
|
* @author 董瑞恩
|
|
|
* @url /portal/order/createOrder
|
|
|
* @method GET
|
|
|
*
|
|
|
* @param name:users_id type:String require:1 default:无 other: desc:用户id
|
|
|
* @param name:name type:String require:1 default:无 other: desc:设备名称
|
|
|
*
|
|
|
*/
|
|
|
public function createOrder(){
|
|
|
$users_id=$this->request->param('users_id');
|
|
|
$name=$this->request->param('name');
|
|
|
// /**
|
|
|
// * @title 生成订单
|
|
|
// * @description 生成订单,加入开始时间和用户id
|
|
|
// * @author 董瑞恩
|
|
|
// * @url /portal/order/createOrder
|
|
|
// * @method GET
|
|
|
// *
|
|
|
// * @param name:users_id type:String require:1 default:无 other: desc:用户id
|
|
|
// * @param name:name type:String require:1 default:无 other: desc:设备名称
|
|
|
// *
|
|
|
// */
|
|
|
public function createOrder($users_id,$name){
|
|
|
$order=[
|
|
|
'order_no' => cmf_get_order_sn(),
|
|
|
'eq_name' => $name,
|
...
|
...
|
@@ -49,28 +47,31 @@ class OrderController extends HomeBaseController{ |
|
|
Db::rollback();
|
|
|
$data=[
|
|
|
'state'=>false,
|
|
|
'message'=>$exception
|
|
|
'message'=>$exception->getMessage()
|
|
|
];
|
|
|
return $data;
|
|
|
}
|
|
|
Db::commit();
|
|
|
$this->apiResponse(200,'success');
|
|
|
$data=[
|
|
|
'state'=>true,
|
|
|
'order_no' => $order['order_no']
|
|
|
];
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @title 完成订单
|
|
|
* @description 订单完成,加入结束时间和结算费用,并调用微信统一下单
|
|
|
* @author 董瑞恩
|
|
|
* @url /portal/order/order
|
|
|
* @method GET
|
|
|
*
|
|
|
* @param name:users_id type:String require:1 default:无 other: desc:用户id
|
|
|
*
|
|
|
* @return data:返回用于调用支付的参数
|
|
|
*/
|
|
|
public function order(){
|
|
|
$users_id=$this->request->param('users_id');
|
|
|
$users=Db::name('users')->where('id',$users_id)->find();
|
|
|
$order= Db::name('order')->where('order_no',$users['order_no'])->find();
|
|
|
// /**
|
|
|
// * @title 完成订单
|
|
|
// * @description 订单完成,加入结束时间和结算费用,并调用微信统一下单
|
|
|
// * @author 董瑞恩
|
|
|
// * @url /portal/order/order
|
|
|
// * @method GET
|
|
|
// *
|
|
|
// * @param name:users_id type:String require:1 default:无 other: desc:用户id
|
|
|
// *
|
|
|
// * @return data:返回用于调用支付的参数
|
|
|
// */
|
|
|
public function order($users_id,$name){
|
|
|
$order= Db::name('order')->where(['users_id'=>$users_id,'state'=>1])->find();
|
|
|
$end_time=time();
|
|
|
$price=$this->getPrice($order['start_time'],$end_time);
|
|
|
$time=ceil(($end_time-$order['start_time'])/3600);
|
...
|
...
|
@@ -83,13 +84,20 @@ class OrderController extends HomeBaseController{ |
|
|
try{
|
|
|
Db::startTrans();
|
|
|
Db::name('users')->where('id',$users_id)->update(['is_use'=>0,'order_no'=>null]);
|
|
|
Db::name('order')->where('order_no',$users['order_no'])->update($data);
|
|
|
Db::name('equipment')->where('name',$name)->update(['use'=>0]);
|
|
|
Db::name('order')->where('order_no',$order['order_no'])->update($data);
|
|
|
}catch (\Exception $exception){
|
|
|
Db::rollback();
|
|
|
$this->apiResponse(301,'订单生成失败,错误信息:'.$exception->getMessage());
|
|
|
$data=[
|
|
|
'state'=>false,
|
|
|
'message'=>$exception->getMessage()
|
|
|
];
|
|
|
$this->apiResponse(200,'success',$data);
|
|
|
}
|
|
|
Db::commit();
|
|
|
//调起支付
|
|
|
$this->pay($order['order_no']);
|
|
|
|
|
|
}
|
|
|
|
|
|
public function getPrice($start_time,$end_time){
|
...
|
...
|
@@ -133,10 +141,22 @@ class OrderController extends HomeBaseController{ |
|
|
$price=$order['price']*100;//订单价格
|
|
|
$notify_url=url('order/notify','','',true);//回调地址
|
|
|
$wxPay=new WeixinPay($openId,$order_no,$body,$price,$notify_url);
|
|
|
$data=$wxPay->pay();
|
|
|
if (isset($data['package'])){
|
|
|
$this->apiResponse(200,'下单成功',$data);//微信支付下单成功,返回调用支付的参数
|
|
|
$pay=$wxPay->pay();
|
|
|
if (isset($pay['package'])){
|
|
|
$data=[
|
|
|
'state'=>1,
|
|
|
'pay'=>$pay
|
|
|
];
|
|
|
$this->apiResponse(200,'success',$data);
|
|
|
}else{
|
|
|
$data=[
|
|
|
'state'=>0,
|
|
|
'message'=>'统一下单失败',
|
|
|
'error' => $pay
|
|
|
];
|
|
|
$this->apiResponse(200,'success',$data);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//支付回调接口
|
...
|
...
|
|