quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
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
<?php
 
namespace app\api\controller\coupon;
 
use app\api\controller\Controller;
use app\api\model\plus\coupon\Coupon as CouponModel;
use app\api\model\product\Product as ProductModel;
use app\api\model\plus\coupon\UserCoupon as UserCouponModel;
/**
 * 优惠券中心
 */
class Coupon extends Controller
{
    /**
     * 优惠券列表
     */
    public function lists()
    {
        $model = new CouponModel;
        $list = $model->getWaitList([], $this->getUser(false), 0, 1,true);
        return $this->renderSuccess('', compact('list'));
    }
 
    public function detail($coupon_id)
    {
        $model = CouponModel::detailWithSupplier($coupon_id);
        $user = $this->getUser(false);
        $model['is_get'] = 0;
        if ($user) {
            $CouponModel = new UserCouponModel();
            $userCouponIds = $CouponModel->getUserCouponIds($user['user_id']);
            $model['is_get'] = in_array($model['coupon_id'], $userCouponIds);
        }
        if ($model['apply_range'] == 20) {
            $product_ids = explode(',', $model['product_ids']);
            $model['product'] = (new ProductModel())->getListByIdsFromApi($product_ids, $this->getUser(false));
        }
        $product_list = [];
        if ($model['apply_range'] == 30) {
            $category_ids = json_decode($model['category_ids'], true);
            $product_list = (new ProductModel())->getListByCatIdsFromApi($category_ids, $this->getUser(false), $model['shop_supplier_id']);
        }
        return $this->renderSuccess('', compact('model', 'product_list'));
    }
}