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
<?php
 
namespace app\api\controller\plus\groupbuy;
 
use app\api\controller\Controller;
use app\api\model\plus\groupbuy\Product as ProductModel;
use app\api\model\plus\groupbuy\Active as ActiveModel;
 
/**
 * 团购商品控制器
 */
class Product extends Controller
{
    /**
     * 团购商品列表
     */
    public function lists($groupbuy_active_id, $limit = 10)
    {
        $list = (new ActiveModel)->getGroupbuyProductList($groupbuy_active_id, $limit);
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 团购商品详情
     */
    public function detail()
    {
        $groupbuy_product_id = $this->request->param('groupbuy_product_id');
        if (empty($groupbuy_product_id)) {
            return $this->renderError('缺少必要参数:groupbuy_product_id');
        }
        
        $detail = ProductModel::detail($groupbuy_product_id, ['product' => ['sku', 'image.file'], 'groupbuySku']);
        if (empty($detail)) {
            return $this->renderError('商品不存在');
        }
        return $this->renderSuccess('', compact('detail'));
    }
 
    /**
     * 团购商品规格详情
     */
    public function getProductSku($groupbuy_product_id, $product_sku_id)
    {
        $model = new ProductModel;
        $detail = $model->getProductSku($groupbuy_product_id, $product_sku_id);
        return $this->renderSuccess('', compact('detail'));
    }
 
    /**
     * 搜索团购商品
     */
    public function search($keyword = '', $groupbuy_active_id = 0)
    {
        $params = [];
        if ($keyword) {
            $params['keyword'] = $keyword;
        }
        if ($groupbuy_active_id) {
            $params['groupbuy_active_id'] = $groupbuy_active_id;
        }
        
        $list = (new ProductModel)->getProductListByApi($params);
        return $this->renderSuccess('', compact('list'));
    }
}