plusstar.js 3.59 KB
/**
 * 潮流优选
 * @author: xiaoxiao<xiaoxiao.hao@yoho.cn>
 * @date: 2016/08/04
 */
'use strict';

const mRoot = '../models';
const plusstarModel = require(`${mRoot}/plusstar`);
const headerModel = require('../../../doraemon/models/header'); // 头部model
const _ = require('lodash');
let channels = {
    boys: 1,
    girl: 2,
    kids: 3,
    lifestyle: 4
};

/**
 * 潮流优选首页
 */
exports.index = (req, res, next) => {
    let isApp = req.query.app_version || req.query.appVersion || false;
    let parameter = {};
    let title = '潮流优选';
    let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;

    if (isApp === false) {
        parameter = {
            pageHeader: headerModel.setNav({
                navTitle: title
            }),
            pageFooter: true
        };
    }

    let result = {};

    plusstarModel.getAllChannels({
        gender: gender,
        app_type: 0
    }).then(data => {
        result = Object.assign(result, data);
        let focus = _.find(result.channel, d => d.focus) || {};
        let code = focus.code || '';

        return plusstarModel.getResourcesData({
            content_code: code,
            yh_channel: 1
        }, {
            isApp: isApp
        });
    }).then(data => {
        result = Object.assign(result, data);
        res.render('plusstar/index', Object.assign({
            page: 'plusstar-index',
            result: result,
            isApp: isApp,
            title: title,
            localCss: true
        }, parameter));
    }).catch(next);
};

exports.userSkn = (req, res, next) => {
    let isApp = req.body.app_version || req.body.appVersion || false;
    let uid = '';
    let param = {};
    let skns = req.body.skns || '';

    skns = skns.split(',') || [];

    if (req.yoho.isApp) {
        uid = req.body.uid;
    } else {
        uid = req.user.uid;
    }

    if (uid) {
        param.uid = uid;
        param.content_code = req.body.code || '';
        param.yh_channel = req.body.yh_channel || 1;

        plusstarModel.getFashionPrefer(param, {
            isApp: isApp
        }).then(result => {
            let preferSkns = result.data || [];

            skns = _.uniq(skns.concat(preferSkns));
            res.json(skns);
        }).catch(next);
    } else {
        res.json(skns);
    }
};

/**
 * 潮流优选首页-资源位
 */
exports.resourcesTemplate = (req, res, next) => {
    let isApp = req.query.app_version || req.query.appVersion || false;
    let uid = '';
    let param = {};

    if (req.yoho.isApp) {
        uid = req.query.uid;
    } else {
        uid = req.user.uid;
    }

    if (uid) {
        param.uid = uid;
    }

    param.content_code = req.query.code || '';
    param.yh_channel = req.query.yh_channel || 1;


    plusstarModel.getResourcesData(param, {
        isApp: isApp
    }).then(result => {
        res.render('plusstar/resources-template', {
            layout: false,
            result: result,
            title: '潮流优选'
        });
    }).catch(next);
};

/**
 * 潮流优选首页-资源位-商品列表
 */
exports.resourcesGoodsList = (req, res, next) => {
    let productSkn = req.body.productSkn || '';
    let isApp = req.body.app_version || req.body.appVersion || false;
    let param = {};

    param = {
        productSkn: productSkn.split(',')
    };

    plusstarModel.getProductBatch(param, {
        isApp: isApp
    }).then(result => {
        res.render('plusstar/resources-goodsList', {
            layout: false,
            result: result,
            title: '潮流优选',
            _noLazy: true
        });
    }).catch(next);
};