huangsijun
2025-12-11 097a5f9e524acd965fa2abcfd18db30fc3f00ddb
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
<?php
 
namespace app\api\controller\branch;
 
use app\api\controller\Controller;
use app\api\model\branch\Activity as ActivityModel;
use app\api\model\branch\ActivityProduct as ActivityProductModel;
use app\api\model\branch\ActivityCart as ActivityCartModel; // 活动购物车
use app\common\model\branch\Setting as SettingModel;
 
/**
 * 活动商品控制器
 */
class ActivityProduct extends Controller
{
    /**
     * 活动商品列表
    **/
    public function lists($activity_id)
    {
        $data = $this->postData();
        $user = $this->getUser();
        $activityDetail = (new ActivityModel())->detail($activity_id);
        if (!$activityDetail) {
            return $this->renderError('活动不存在');
        }
        if ($activityDetail['status_text']['status'] != 1) {
            return $this->renderError('活动未开始');
        }
        // 检查用户是否能购买
        if (!$activityDetail->checkUserShopping($user['user_id'])) {
            return $this->renderError($activityDetail->getError());
        }
        $model = new ActivityProductModel();
        $list = $model->getList($activity_id);
        $cart_total_num = (new ActivityCartModel())->where(['activity_id'=>$activity_id,'user_id'=>$user['user_id']])->count();
        $words = SettingModel::getItem('words');
        return $this->renderSuccess('', compact('list', 'cart_total_num', 'activityDetail', 'words'));
    }
}