quanwei
2025-11-26 6ae85f8ddbae19f5586f4b0c37680fe21889ef14
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
<?php
 
namespace app\api\controller\plus\regactivity;
 
use app\api\controller\Controller;
use app\api\model\plus\regactivity\Activity as ActivityModel;
use app\api\model\plus\regactivity\Category as CategoryModel;
use app\api\model\plus\regactivity\User as UserModel;
use app\api\model\user\BalanceOrder as BalanceOrderModel;
use app\common\enum\order\OrderPayTypeEnum;
use app\common\enum\order\OrderTypeEnum;
 
/**
 * 活动控制器
 */
class Index extends Controller
{
    /**
     *获取分类
     */
    public function category()
    {
        // 分类
        $category = CategoryModel::getAll();
        return $this->renderSuccess('', compact('category'));
    }
 
    /**
     * 活动列表
     */
    public function index($category_id = 0)
    {
        $model = new ActivityModel;
        $list = $model->getList($category_id, $this->postData());
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     *活动详情
     */
    public function detail($activity_id)
    {
        $detail = ActivityModel::detail($activity_id);
        $user = $this->getUser();
        $detail["balance"]=$user["balance"];
        return $this->renderSuccess('', compact('detail'));
    }
 
    /**
     *提交活动报名
     */
    public function submit()
    {
        $params = $this->request->param();
        // 用户信息
        $user = $this->getUser();
        // 生成报名用户
        $model = new UserModel();
        $order_id = $model->addUser($user,$params);
        if(!$order_id){
            return $this->renderError($model->getError() ?: '报名失败');
        }
        if($params['activity_fee'] > 0){
            // 处理微信支付
            $payment = UserModel::onOrderPayment($user, $model, $params['pay_type'], $params['pay_source']);
            // 返回结算信息
            return $this->renderSuccess(['success' => '支付成功', 'error' => '未支付'], [
                'order_id' => $order_id,   // 订单id
                'activity_fee' => $params['activity_fee'],   // 活动费用
                'pay_type' =>  $params['pay_type'],  // 支付方式
                'payment' => $payment,               // 微信支付参数
                'order_type' => OrderTypeEnum::REGACTIVITY, //订单类型
            ]);
        }else{
            return $this->renderSuccess('', compact('order_id'));
        }
    }
 
}