quanwei
2025-11-15 6f12eadd25c8f5335fd9eccf373bf9835bf3e4c6
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
<?php
 
namespace app\api\controller\plus\live;
 
use app\api\controller\Controller;
use app\api\model\plus\live\Plan as PlanModel;
use app\api\model\plus\live\PlanOrder as PlanOrderModel;
use app\common\model\app\App as AppModel;
use app\common\enum\order\OrderTypeEnum;
 
/**
 * 充值套餐控制器
 */
class Plan extends Controller
{
    /**
     * 套餐列表
     */
    public function lists()
    {
        $model = new PlanModel();
        $list = $model->getList($this->postData());
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 充值套餐
     */
    public function submit($plan_id)
    {
        // 用户信息
        $user = $this->getUser();
        // 生成等级订单
        $model = new PlanOrderModel;
        $order_id = $model->createOrder($user, $plan_id);
        if (!$order_id) {
            return $this->renderError($model->getError() ?: '创建订单失败');
        }
        // 返回结算信息
        return $this->renderSuccess('', [
            'order_id' => $order_id,   // 订单id
        ]);
    }
 
    /**
     * 立即支付
     */
    public function pay($order_id)
    {
        // 用户信息
        $user = $this->getUser();
        // 获取订单详情
        $model = PlanOrderModel::getUserOrderDetail($order_id, $user['user_id']);
        $params = $this->postData();
        if ($this->request->isGet()) {
            // 开启的支付类型
            $payTypes = AppModel::getPayType($model['app_id'], $params['pay_source']);
            // 支付金额
            $payPrice = $model['pay_price'];
            $balance = $user['balance'];
            return $this->renderSuccess('', compact('payTypes', 'payPrice', 'balance'));
        }
        // 订单支付事件
        if ($model['pay_status']['value'] != 10) {
            return $this->renderError($model->getError() ?: '订单已支付');
        }
        // 构建微信支付请求
        $PlanOrderModel = new PlanOrderModel;
        $payInfo = (new PlanOrderModel)->OrderPay($params, $model, $user);
        if (!$payInfo) {
            return $this->renderError($PlanOrderModel->getError() ?: '订单支付失败');
        }
        // 支付状态提醒
        return $this->renderSuccess('', [
            'order_id' => $order_id,   // 订单id
            'pay_type' => $payInfo['payType'],  // 支付方式
            'payment' => $payInfo['payment'],   // 微信支付参数
            'order_type' => OrderTypeEnum::PLAN, //订单类型
            'use_balance' => $payInfo['use_balance']// 是否使用余额
        ]);
    }
}