detail-helper.js 1.52 KB
/**
 * Created by TaoHuang on 2016/6/13.
 */

'use strict';

const moment = require('moment');

/* COOKIE标识访问的是男生频道 */
const COOKIE_NAME_BOYS = 'boys';
const COOKIE_DOMAIN = '.yohobuy.com';

// 商品详情页的默认头像
const DEFAULT_AVATAR_ICO = 'https://static.yohobuy.com/images/v3/boy.jpg';
const IMAGE_SERVICE_URL = 'http://head.static.yhbimg.com/yhb-head/';

const setSwitchToCookie = (res) => {
    res.cookie('_Channel', COOKIE_NAME_BOYS, {
        domain: COOKIE_DOMAIN,
        maxAge: moment.duration(300, 'days').seconds()
    });
};

const getGenderByCookie = (req) => {
    let gender = null;

    let channel = req.cookies._Channel || 'boys';

    switch (channel) {
        case 'boys':
        {
            gender = '1,3';
            break;
        }
        case 'girls':
        {
            gender = '2,3';
            break;
        }
        default:
        {
            gender = '1,2,3';
        }
    }

    return gender;
};

const vipLevel = (vipTitle) => {
    return (function(title) {
        if (title === '普通会员') {
            return 0;
        } else if (title === '银卡会员') {
            return 1;
        } else if (title === '金卡会员') {
            return 2;
        } else if (title === '白金会员') {
            return 3;
        } else {
            return 0;
        }
    }(vipTitle));
};

module.exports = {
    COOKIE_NAME_BOYS,
    COOKIE_DOMAIN,
    DEFAULT_AVATAR_ICO,
    IMAGE_SERVICE_URL,
    setSwitchToCookie,
    getGenderByCookie,
    vipLevel
};