作者 何书鹏

代付openid

@@ -546,6 +546,7 @@ class Order extends Api @@ -546,6 +546,7 @@ class Order extends Api
546 * @ApiMethod (POST) 546 * @ApiMethod (POST)
547 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 547 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
548 * @ApiParams (name="id", type="integer", required=true, description="订单ID") 548 * @ApiParams (name="id", type="integer", required=true, description="订单ID")
  549 + * @ApiParams (name="openid", type="string", required=false, description="代付人openid")
549 * @ApiReturn ({ 550 * @ApiReturn ({
550 'code':'1', 551 'code':'1',
551 'msg':'返回成功' 552 'msg':'返回成功'
@@ -554,19 +555,20 @@ class Order extends Api @@ -554,19 +555,20 @@ class Order extends Api
554 public function pay() 555 public function pay()
555 { 556 {
556 $order_id = $this->request->post('id'); 557 $order_id = $this->request->post('id');
557 - $friend_id = $this->request->post('user_id'); 558 + $openid = $this->request->post('openid');
558 empty($order_id) && $this->error('缺少必需参数'); 559 empty($order_id) && $this->error('缺少必需参数');
559 560
560 $model = new \app\api\model\Order(); 561 $model = new \app\api\model\Order();
561 $order = $model::get($order_id); 562 $order = $model::get($order_id);
562 if (!$order) $this->error('订单不存在'); 563 if (!$order) $this->error('订单不存在');
563 -// $openid = Third::get(['user_id'=>$this->auth->id]);  
564 - $openid = Third::alias('a') 564 +// $third = Third::get(['user_id'=>$this->auth->id]);
  565 + $third = Third::alias('a')
565 ->join('user b','b.id = a.user_id') 566 ->join('user b','b.id = a.user_id')
566 ->where('a.user_id',$order['user_id']) 567 ->where('a.user_id',$order['user_id'])
567 ->field('a.openid') 568 ->field('a.openid')
568 ->find(); 569 ->find();
569 - if (!$openid) $this->error('未注册用户'); 570 + if (!$third) $this->error('下单人未注册');
  571 +
570 $params = [ 572 $params = [
571 'type' => 'wechat', 573 'type' => 'wechat',
572 'orderid' => $order['order_no'], 574 'orderid' => $order['order_no'],
@@ -574,7 +576,7 @@ class Order extends Api @@ -574,7 +576,7 @@ class Order extends Api
574 // 'amount' => $order['pay_price'], 576 // 'amount' => $order['pay_price'],
575 'amount' => 0.01, 577 'amount' => 0.01,
576 'method' => 'miniapp', 578 'method' => 'miniapp',
577 - 'openid' => $openid['openid'], 579 + 'openid' => !empty($openid) ? $openid : $third['openid'],
578 'notifyurl' => $this->request->domain().'/api/notify/orderNotify/type/wechat', 580 'notifyurl' => $this->request->domain().'/api/notify/orderNotify/type/wechat',
579 'returnurl' => '', 581 'returnurl' => '',
580 ]; 582 ];