summer-web.js 3.71 KB
var couponModel = require('../../models/coupon'),
    cookie = require('../../util/cookie'),
    errUtil = require('../../util/error'),
    msgModel = require('../../models/message');

/**
 * 夏季领券第一波
 */
exports.first = (req, res) => {
    var renderData = {
        layout: false, // 原有活动移植,忽略公有模板
        module: 'coupon/summer-1-web',
        title: 'YOHO!BUY有货【夏日新品节】',
        couponUrl: 'http://www.yohobuy.com/home/coupons', // 个人中心优惠券
        banner: {
            img: 'http://img01.yohoboys.com/staticimg/2016/04/08/18/01c4a1c0eab42c0df420ae91a63bd855ed.jpg',
            url: 'http://www.yohobuy.com/special_14838_0411PCHOME.html'
        }
    };

    var uid = cookie.getUid(req);
    var couponId = res.app.locals.proEnv ? '20455,20457,20459' : '12463,12461,12459';

    renderData.activityId = res.app.locals.proEnv ? 564 : 499;

    couponModel({
        uid: uid,
        couponId: couponId.split(',')
    }).then((couponData) => {
        var couponInfo = JSON.parse(couponData[0]);

        if (couponData.length && couponInfo.code === 200) {

            // 发送站内信有问题
            msgModel.sendSingleMessage({
                uid: uid,
                title: '【优惠券】您有3张夏日新品节优惠券。',
                content: '尊敬的客户:恭喜您成功获得3张夏日新品节优惠券 !您可以在个人中心查看优惠券详情。'
            });
        }
        return couponData;
    }).then((couponData) => {
        var couponInfo = JSON.parse(couponData[0]);

        if (couponInfo.code === 401) {
            renderData.geted = true;
        }

        if (couponInfo.code !== 401 && couponInfo.code !== 200) {
            renderData.fail = true;
        }

        res.render('coupon/summer/index-web', renderData); // 渲染页面
    }).catch((err) => {
        errUtil.webError(err, res); // 抓取 Promise 链的错误
    });
};

/**
 * 夏季领券第二波
 */
exports.second = (req, res) => {
    var renderData = {
        layout: false, // 原有活动移植,忽略公有模板
        module: 'coupon/summer-2-web',
        title: 'YOHO!BUY有货【夏日新品节】',
        couponUrl: 'http://www.yohobuy.com/home/coupons', // 个人中心优惠券
        banner: {
            img: 'http://img01.yohoboys.com/staticimg/2016/04/15/14/019e7f29f91b86847fe0afbba9d2e0a91a.jpg',
            url: 'http://www.yohobuy.com/special_14964_0418PCHOME.html'
        }
    };

    var uid = cookie.getUid(req);
    var couponId = res.app.locals.proEnv ? '20989,20991,20993' : '12463,12461,12459';

    renderData.activityId = res.app.locals.proEnv ? 580 : 499; // 正式活动 ID 580

    couponModel({
        uid: uid,
        couponId: couponId.split(',')
    }).then((couponData) => {
        var couponInfo = JSON.parse(couponData[0]);

        if (couponData.length && couponInfo.code === 200) {

            // 发送站内信有问题
            msgModel.sendSingleMessage({
                uid: uid,
                title: '【优惠券】您有3张夏日新品节优惠券。',
                content: '尊敬的客户:恭喜您成功获得3张夏日新品节优惠券 !您可以在个人中心查看优惠券详情。'
            });
        }
        return couponData;
    }).then((couponData) => {
        var couponInfo = JSON.parse(couponData[0]);

        if (couponInfo.code === 401) {
            renderData.geted = true;
        }

        if (couponInfo.code !== 401 && couponInfo.code !== 200) {
            renderData.fail = true;
        }

        res.render('coupon/summer/index-web', renderData); // 渲染页面
    }).catch((err) => {
        errUtil.webError(err, res); // 抓取 Promise 链的错误
    });
};