index.js 4.7 KB
/**
 * 个人中心 controller
 * @author: chengyao.guo<chengyao.guo@yoho.cn>
 * @date: 2016/08/10
 */

'use strict';

const headerModel = require('../../../doraemon/models/header'); // 头部model
const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab
const indexModel = require('../models/index');

/**
 * 用户中心首页
 * @param req
 * @param res
 * @param next
 */
exports.index = (req, res, next) => {
    let params = {
        uid: req.user.uid,
        channel: req.query.channel || 1,
        udid: require('md5')(req.ip)
    };

    indexModel.index(params).then(result => {
        if (result) {
            res.render('home', Object.assign(result, {
                isLogin: params.uid ? true : false,
                module: 'home',
                page: 'index',
                title: '个人中心 | Yoho!Buy有货 | 潮流购物逛不停',
                pageFooter: true,
                pageChannel: {
                    boys: true
                },
                showFooterTab: footerModel.getUrlData('mine'),
                localCss: true
            }));
        }
    }).catch(next);

};

/**
 * 个人基本资料页面
 * @param req
 * @param res
 * @param next
 */
exports.myDetails = (req, res, next) => {
    let headerData = headerModel.setNav({
        navTitle: '基本资料'
    });

    let responseData = {
        pageHeader: headerData,
        module: 'home',
        page: 'personal-details',
        title: '基本资料',
        pageFooter: true
    };

    let uid = req.user.uid;

    indexModel.myDetails(uid).then(result => {
        res.render('personal-details', Object.assign(responseData, result));
    }).catch(next);
};

/**
 * 浏览记录
 * @param req
 * @param res
 * @param next
 */

exports.record = (req, res, next) => {
    let uid = req.user.uid;

    let udid = req.user.udid;

    let page = req.query.page || 1;

    let limit = 10;

    let headerData = headerModel.setNav({
        navTitle: '浏览记录'
    });

    let responseData = {
        pageHeader: headerData,
        module: 'home',
        page: 'browse-record',
        title: '浏览记录',
        browseRecordPage: true,
        pageFooter: true,
        _noLazy: true,
        localCss: true
    };

    indexModel.recordContent(uid, udid, page, limit).then((result) => {

        if (result.browseRecord && result.browseRecord.length > 0) {
            responseData.browseRecord = result.browseRecord;
        } else {
            responseData.noRecord = true;
        }

        res.render('browse-record', responseData);

    }).catch(next);

};

/**
 * 浏览记录列表
 * @param req
 * @param res
 * @param next
 */
exports.recordContent = (req, res, next) => {
    let uid = req.user.uid;

    let udid = req.user.udid;

    let page = req.query.page || 1;

    let limit = 10;

    indexModel.recordContent(uid, udid, page, limit).then((result) => {

        if (result.browseRecord && result.browseRecord.length === 0) {
            res.json(false);
        } else {
            res.render('browse-record-content', Object.assign({
                layout: false
            }, result));
        }
    }).catch(next);
};

/**
 * 删除浏览记录
 * @param req
 * @param res
 * @param next
 */
exports.delRecord = (req, res, next) => {
    let uid = req.user.uid;

    let skn = req.query.skn || 0;

    indexModel.delRecord(uid, skn).then((result) => {
        res.json({
            code: result.code,
            message: result.message
        });
    }).catch(next);
};

/**
 * 会员等级展示页
 * @param req
 * @param res
 * @param next
 */

exports.grade = (req, res, next) => {

    let headerData = headerModel.setNav({
        navTitle: '会员等级'
    });

    let responseData = {
        pageHeader: headerData,
        module: 'home',
        page: 'grade',
        title: '会员等级',
        pageFooter: true
    };

    let param = {
        uid: req.user.uid,
        channel: req.query.channel || 1
    };

    indexModel.getGrade(param).then((result) => {
        res.render('vip-grade/vip-grade', Object.assign(result, responseData));
    }).catch(next);

};

/**
 * 会员特权列表页
 * @param req
 * @param res
 * @param next
 */

exports.preferential = (req, res, next) => {

    let headerData = headerModel.setNav({
        navTitle: '会员特权详情'
    });

    let responseData = {
        pageHeader: headerData,
        module: 'home',
        page: 'grade',
        title: '会员特权详情',
        pageFooter: true
    };

    let param = {
        uid: req.user.uid,
        channel: req.query.channel || 1
    };

    indexModel.getPreferential(param).then((result) => {
        res.render('vip-grade/privilege', Object.assign(result, responseData));
    }).catch(next);

};