quanwei
2025-10-28 36cacbaf78e510713002fcd5e3d61cece2e01421
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
<?php
 
namespace app\api\controller\user;
 
use app\api\controller\Controller;
use app\common\enum\order\OrderTypeEnum;
use app\api\model\user\Card as UserCardModel;
use app\api\model\user\CardRecord as CardRecordModel;
 
/**
 * 会员卡
 */
class UserCard extends Controller
{
    private $user;
 
    /**
     * 构造方法
     */
    public function initialize()
    {
        parent::initialize();
        $this->user = $this->getUser();
    }
 
    //会员卡列表
    public function index()
    {
        $model = new UserCardModel();
        $list = $model->getList($this->postData());
        return $this->renderSuccess('', compact('list'));
    }
 
    //会员卡详情
    public function detail($card_id)
    {
        $detail = UserCardModel::detail($card_id);
        return $this->renderSuccess('', compact('detail'));
    }
 
    //我的会员卡详情
    public function recordDetail($order_id)
    {
        $detail = CardRecordModel::getDetail($order_id);
        return $this->renderSuccess('', compact('detail'));
    }
 
    /**
     * 购买
     */
    public function buy()
    {
        $params = $this->request->param();
        // 用户信息
        $user = $this->user;
        // 生成订单
        $model = new CardRecordModel();
        $order_id = $model->createOrder($user, $params);
        if (!$order_id) {
            return $this->renderError($model->getError() ?: '购买失败');
        }
        // 在线支付
        $model['pay_price'] = $model['money'];
        $payment = CardRecordModel::onOrderPayment($user, [$model], $params['pay_type'], $params['pay_source']);
        // 返回结算信息
        return $this->renderSuccess(['success' => '支付成功', 'error' => '订单未支付'], [
            'order_id' => $order_id,   // 订单id
            'pay_type' => $params['pay_type'],  // 支付方式
            'payment' => $payment,               // 微信支付参数
            'order_type' => OrderTypeEnum::CARD, //订单类型
        ]);
    }
}