sale.js 4.02 KB
/**
 * sale controller
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/5/17
 */

'use strict';
const library = '../../../library';
const mRoot = '../models';

// const cookie = require(`${library}/cookie`);
const headerModel = require('../../../doraemon/models/header');
const log = require(`${library}/logger`);
const saleModel = require(`${mRoot}/sale`);

const saleLogger = (err, res) => {
    log.error('sale页面渲染错误:' + JSON.stringify(err));
    res.send('error');
};


/**
 * sale 首页
 */
exports.index = (req, res) => {
    let headerData = headerModel.setNavHeader('SALE');
    let renderData = {
        module: 'product',
        page: 'sale',
        pageHeader: headerData,
        pageFooter: true
    };


    saleModel.getSaleData({
        yh_channel: 1,
        page: 1,
        limit: 10,
        order: 's_t_desc'
    }).then((result) => {
        result = {
            headerBanner: {
                list: [
                    {
                        url: '',
                        src: 'http://img11.static.yhbimg.com/yhb-img01/2016/04/18/06/01abda0859d64f9af63a434ca281d213c5.jpg?imageView2/2/w/640/h/240'
                    },
                    {
                        url: '',
                        src: 'http://img12.static.yhbimg.com/yhb-img01/2016/04/18/05/0239e814b8121913aa67b9ad509bd4e310.jpg?imageView2/2/w/640/h/240'
                    }
                ]
            },
            smallPic: {
                data: [
                    {
                        url: '',
                        src: 'http://img12.static.yhbimg.com/yhb-img01/2016/04/18/05/0239e814b8121913aa67b9ad509bd4e310.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80'
                    },
                    {
                        url: '',
                        src: 'http://img11.static.yhbimg.com/yhb-img01/2016/05/12/15/011684760312d139ac2429c3678951ebd0.jpg?imageView2/2/w/640/h/403'
                    },
                    {
                        url: '',
                        src: 'http://img11.static.yhbimg.com/yhb-img01/2016/05/12/15/011684760312d139ac2429c3678951ebd0.jpg?imageView2/2/w/275/h/160'
                    }
                ]
            },
            title: {
                title: '最新降价'
            },
            goods: {
                url: 'http://m.yohobuy.com/product/pro_320421_412063/SYSTAGYuanLingWeiYiSYSA601HC09.html',
                thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/12/07/09/01ced0e2ed6a4f2a6d95be70cd0a6c5a56.jpg?imageView/2/w/235/h/314',
                name: 'NEFF ONE OF US RAGLAN L/S 男款森林风连帽卫衣',
                salePrice: '759.00',
                price: '799.00',
                tags: {
                    isNew: true,
                    isAdvance: false,
                    isDiscount: false,
                    isYohoood: false,
                    isLimited: false
                },
                isSoonSoldOut: true
            }
        };
        res.render('sale', Object.assign(renderData, result));
    }).catch((err) => {
        saleLogger(err, res);
    });
};


/**
 * 折扣专场列表
 */
exports.special = (req, res) => {
    let headerData = headerModel.setNavHeader('折扣专场');
    let renderData = {
        module: 'product',
        page: 'sale',
        pageHeader: headerData,
        pageFooter: true
    };

    saleModel.getSpecialData().then((result) => {
        res.render('special', Object.assign(renderData, result));
    }).catch((err) => {
        saleLogger(err, res);
    });
};


/**
 * 折扣专场专题详情
 */
exports.specialDetail = (req, res) => {
    let headerData = headerModel.setNavHeader('折扣专场');
    let renderData = {
        module: 'product',
        page: 'sale',
        pageHeader: headerData,
        pageFooter: true
    };

    saleModel.getSpecialDetailData().then((result) => {
        res.render('special-detail', Object.assign(renderData, result));
    }).catch((err) => {
        saleLogger(err, res);
    });
};