Blame view

apps/home/controllers/index.js 5.16 KB
郭成尧 authored
1
/**
郭成尧 authored
2
 * 个人中心 controller
郭成尧 authored
3 4 5 6 7
 * @author: chengyao.guo<chengyao.guo@yoho.cn>
 * @date: 2016/08/10
 */

'use strict';
郭成尧 authored
8
郭成尧 authored
9
const headerModel = require('../../../doraemon/models/header'); // 头部model
10
const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab
郭成尧 authored
11
const indexModel = require('../models/index');
陈峰 authored
12
const _ = require('lodash');
郭成尧 authored
13
郭成尧 authored
14 15 16 17 18 19
/**
 * 用户中心首页
 * @param req
 * @param res
 * @param next
 */
郭成尧 authored
20 21
exports.index = (req, res, next) => {
    let params = {
22
        uid: req.user.uid,
23
        channel: req.query.channel || 1,
zhangxiaoru authored
24 25
        udid: require('yoho-md5')(req.ip),
        contentCode: 'b2b5cde8144aff3073573c3b323344ab'
郭成尧 authored
26 27
    };
陈峰 authored
28 29
    let studentSwitch = !_.get(req.app.locals.wap, 'user.removeStudentIdentification', true);
30 31 32
    // 唤起 APP 的路径
    res.locals.appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy= {"action":"go.mine"}';
zhangxiaoru authored
33
    req.ctx(indexModel).index(params).then(result => {
zhangxiaoru authored
34
郭成尧 authored
35
        if (result) {
郭成尧 authored
36
            res.render('home', Object.assign(result, {
郭成尧 authored
37
                isLogin: params.uid ? true : false,
郭成尧 authored
38 39
                module: 'home',
                page: 'index',
沈志敏 authored
40
                title: '个人中心 | Yoho!Buy有货 | 潮流购物逛不停',
41 42
                pageFooter: true,
                pageChannel: {
43
                    boys: true
44
                },
姜枫 authored
45
                showFooterTab: footerModel.getUrlData('mine'),
陈峰 authored
46 47
                localCss: true,
                studentSwitch
郭成尧 authored
48
            }));
郭成尧 authored
49 50
        }
    }).catch(next);
lijing authored
51
郭成尧 authored
52
};
郭成尧 authored
53 54 55 56 57 58 59 60 61 62 63 64

/**
 * 个人基本资料页面
 * @param req
 * @param res
 * @param next
 */
exports.myDetails = (req, res, next) => {
    let headerData = headerModel.setNav({
        navTitle: '基本资料'
    });
lijing authored
65 66 67 68 69 70 71
    let responseData = {
        pageHeader: headerData,
        module: 'home',
        page: 'personal-details',
        title: '基本资料',
        pageFooter: true
    };
郭成尧 authored
72
lijing authored
73
    let uid = req.user.uid;
lijing authored
74
zhangxiaoru authored
75
    req.ctx(indexModel).myDetails(uid).then(result => {
lijing authored
76
        res.render('personal-details', Object.assign(responseData, result));
郭成尧 authored
77 78
    }).catch(next);
};
lijing authored
79 80 81 82 83 84 85 86

/**
 * 浏览记录
 * @param req
 * @param res
 * @param next
 */
姜枫 authored
87 88 89 90 91 92 93 94
exports.record = (req, res, next) => {
    let uid = req.user.uid;

    let udid = req.user.udid;

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

    let limit = 10;
lijing authored
95 96 97 98 99 100 101 102 103 104

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

    let responseData = {
        pageHeader: headerData,
        module: 'home',
        page: 'browse-record',
        title: '浏览记录',
lijing authored
105
        browseRecordPage: true,
姜枫 authored
106 107 108
        pageFooter: true,
        _noLazy: true,
        localCss: true
lijing authored
109 110
    };
zhangxiaoru authored
111
    req.ctx(indexModel).recordContent(uid, udid, page, limit).then((result) => {
姜枫 authored
112
113
        if (result && result.browseRecord && result.browseRecord.length > 0) {
姜枫 authored
114
            responseData.browseRecord = result.browseRecord;
115 116
        } else {
            responseData.noRecord = true;
姜枫 authored
117 118 119 120 121
        }

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

    }).catch(next);
lijing authored
122
lijing authored
123
};
lijing authored
124
lijing authored
125 126 127 128 129 130
/**
 * 浏览记录列表
 * @param req
 * @param res
 * @param next
 */
lijing authored
131
exports.recordContent = (req, res, next) => {
lijing authored
132
    let uid = req.user.uid;
lijing authored
133 134 135 136

    let udid = req.user.udid;

    let page = req.query.page || 1;
lijing authored
137
姜枫 authored
138
    let limit = 10;
lijing authored
139
zhangxiaoru authored
140
    req.ctx(indexModel).recordContent(uid, udid, page, limit).then((result) => {
lijing authored
141
郭成尧 authored
142
        if (result && result.browseRecord && result.browseRecord.length === 0) {
lijing authored
143 144
            res.json(false);
        } else {
郭成尧 authored
145
            res.render('browse-record-content', _.assign({
lijing authored
146 147 148
                layout: false
            }, result));
        }
lijing authored
149
    }).catch(next);
lijing authored
150 151
};
lijing authored
152 153 154 155 156 157
/**
 * 删除浏览记录
 * @param req
 * @param res
 * @param next
 */
lijing authored
158
exports.delRecord = (req, res, next) => {
lijing authored
159
    let uid = req.user.uid;
lijing authored
160
zzzzzzz authored
161
    let skn = req.query.skn || 0;
lijing authored
162
zhangxiaoru authored
163
    req.ctx(indexModel).delRecord(uid, skn).then((result) => {
zzzzzzz authored
164 165
        res.json({
            code: result.code,
166
            message: result.message
zzzzzzz authored
167
        });
lijing authored
168 169
    }).catch(next);
};
lijing authored
170
lijing authored
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
/**
 * 会员等级展示页
 * @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: '会员等级',
lijing authored
189 190
        pageFooter: true,
        width750: true
lijing authored
191 192
    };
lijing authored
193
    let param = {
lijing authored
194
        uid: req.user.uid,
lijing authored
195
        channel: req.query.channel || 1
lijing authored
196 197
    };
zhangxiaoru authored
198
    req.ctx(indexModel).getGrade(param).then((result) => {
lijing authored
199 200 201
        res.render('vip-grade/vip-grade', Object.assign(result, responseData));
    }).catch(next);
lijing authored
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
};

/**
 * 会员特权列表页
 * @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: '会员特权详情',
lijing authored
222 223
        pageFooter: true,
        width750: true
lijing authored
224 225
    };
lijing authored
226
    let param = {
lijing authored
227
        uid: req.user.uid,
lijing authored
228
        channel: req.query.channel || 1
lijing authored
229 230
    };
zhangxiaoru authored
231
    req.ctx(indexModel).getPreferential(param).then((result) => {
lijing authored
232 233
        res.render('vip-grade/privilege', Object.assign(result, responseData));
    }).catch(next);
lijing authored
234
沈志敏 authored
235
};