summer-web.js 1.94 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(function(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/first-web', renderData); // 渲染页面
    }).catch((err) => {
        errUtil.webError(err, res); // 抓取 Promise 链的错误
    });
};