Coupon.php 3.41 KB
<?php

namespace Index;

use WebPlugin\Helpers;
use WebPlugin\Images;
use Index\HomeModel;
use LibModels\Web\Home\CouponData;

/**
 * 领券频道模型层
 */
class CouponModel
{

    /**
     * 获取领券频道资源
     * @param type $uid 用户uid
     * @param type $contentCode 频道位置码
     */
    public static function getCouponData($contentCode, $uid = 0)
    {
        $data = array();
        $result = array(
            'couponCenterPage' => true,
            'pathNav' => array(
                HomeModel::getHomeChannelNav('boys'),
                array('name' => '领券频道')
            ),
            'footerTop' => true,
            'slide' => array(),
            'categories' => array(),
        );
        //获取领券数据
        $coupon = CouponData::getCouponRousource($contentCode, $uid);

        do {
            if (!isset($coupon['data']) || empty($coupon['data'])) {
                break;
            }
            $i = 0;
            foreach ($coupon['data'] as $couponlistkey => $couponlistval) {
                //头部banner
                if (isset($couponlistval['templateName']) && $couponlistval['templateName'] == 'focus') {
                    foreach ($couponlistval['data'] as $focus) {
                        $result['slide']['list'][] = array(
                            'href' => $focus['url'], //banner跳转链接
                            'img' => Images::getForceSourceUrl($focus['src'])//banner图片
                        );
                    }
                }
                else if (isset($couponlistval['template_name']) && $couponlistval['template_name'] == 'getCoupon') {
                    //优惠券楼层     
                    if (!isset($coupon['data'][$couponlistkey - 1]['data']['text'])) {
                        continue;
                    }
                    $result['categories'][$i] = array(
                        'title' => $coupon['data'][$couponlistkey - 1]['data']['text'], //楼层标题
                        'coupons' => array()
                    );
                    foreach ($couponlistval['data'] as $couponskey => $couponsval) {
                        $result['categories'][$i]['coupons'][$couponskey] = array(
                            'id' => $couponsval['couponID'], //优惠券号
                            'img' => Images::getForceSourceUrl($couponsval['image']['src']), //优惠券图片
                            'url' => $couponsval['image']['url']    //去逛逛链接
                        );

                        //领取状态判断
                        switch ($couponsval['status']) {
                            case 3 :
                                $result['categories'][$i]['coupons'][$couponskey]['got'] = true; //优惠券已领取                                
                                break;
                            case 2 :
                                $result['categories'][$i]['coupons'][$couponskey]['empty'] = true; //优惠券已抢光
                                break;
                            default :
                                $result['categories'][$i]['coupons'][$couponskey]['normal'] = true; //可领取优惠券
                        }
                    }
                    $i = $i + 1;
                }
            }
        }
        while (false);
        return $result;
    }

}