Authored by 毕凯

Merge branch 'feature/ctxlj' into 'release/6.0'

Feature/ctxlj

个人中心ctx优化

See merge request !754
... ... @@ -5,7 +5,7 @@ const headerModel = require('../../../doraemon/models/header'), // 头部model
// status为使用状态
const index = (req, res, next) => {
model.couponData({
req.ctx(model).couponData({
method: 'app.coupons.li',
uid: req.user.uid,
status: req.body.status || 0,
... ... @@ -29,7 +29,7 @@ const index = (req, res, next) => {
};
const couponsAjax = (req, res, next) => {
model.couponData({
req.ctx(model).couponData({
method: 'app.coupons.li',
uid: req.user.uid,
status: parseInt(req.body.status || 0, 10),
... ...
... ... @@ -15,7 +15,7 @@ const favorite = (req, res, next) => {
let page = 1;
let limit = 10;
favoriteModel.index(uid, page, limit, tab === 'brand').then((result)=>{
req.ctx(favoriteModel).index(uid, page, limit, tab === 'brand').then((result)=>{
res.render('favorite', {
module: 'home',
page: 'favorite',
... ... @@ -39,7 +39,7 @@ let favProduct = (req, res, next) => {
let page = req.query.page || 1;
let limit = 10;
favoriteModel.favProduct(uid, page, limit).then((result) => {
req.ctx(favoriteModel).favProduct(uid, page, limit).then((result) => {
if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') {
res.render('favorite/favorite-product', {
layout: false,
... ... @@ -56,7 +56,7 @@ let favfavBrand = (req, res, next) => {
let page = req.query.page || 1;
let limit = 10;
favoriteModel.favfavBrand(uid, page, limit).then((result) => {
req.ctx(favoriteModel).favfavBrand(uid, page, limit).then((result) => {
if (typeof(result.total) === 'undefined' && typeof(result.more) === 'undefined') {
res.render('favorite/favorite-brand', {
... ... @@ -75,7 +75,7 @@ let favoriteDelete = (req, res, next) => {
let type = 'product';
let favId = req.body.id;
favoriteModel.favoriteDelete(uid, type, favId).then((result) => {
req.ctx(favoriteModel).favoriteDelete(uid, type, favId).then((result) => {
res.json(result);
}).catch(next);
};
... ...
// 帮助 by acgpiano
'use strict';
const headerModel = require('../../../doraemon/models/header'), // 头部model
model = require('../models/help');
exports.index = (req, res, next) => {
model.getHelpList().then(result => {
res.render('help', {
module: 'home',
page: 'help',
pageHeader: headerModel.setNav({
navTitle: '帮助中心',
navBtn: false
}),
title: '帮助中心',
pageFooter: true,
iHelp: result
});
}).catch(next);
};
exports.helpDetail = (req, res, next) => {
model.getHelpDetail(req.query.code).then(result => {
res.render('help-detail', {
module: 'home',
page: 'help-detail',
pageHeader: headerModel.setNav({
navTitle: req.query.name,
navBtn: false
}),
title: req.query.name,
pageFooter: true,
detail: result
});
}).catch(next);
};
... ... @@ -4,7 +4,7 @@ const headerModel = require('../../../doraemon/models/header'), // 头部model
model = require('../models/message');
const _getList = (req, res, next) => {
model.getList({
req.ctx(model).getList({
page: req.body.page,
size: 20,
uid: req.user.uid,
... ... @@ -26,7 +26,7 @@ const _getList = (req, res, next) => {
};
const _msgDetail = (req, res, next) => {
model.getList({
req.ctx(model).getList({
page: req.body.page,
size: 1000,
msgid: req.query.id,
... ... @@ -61,7 +61,7 @@ exports.index = (req, res, next) => {
};
exports.ajaxDelMes = (req, res, next) => {
model.delMsg({
req.ctx(model).delMsg({
uid: req.user.uid,
msgid: req.body.id,
}).then(result => {
... ... @@ -71,7 +71,7 @@ exports.ajaxDelMes = (req, res, next) => {
};
exports.pickCoupon = (req, res, next) => {
model.pickCoupon({
req.ctx(model).pickCoupon({
uid: req.user.uid,
couponId: req.body.id,
}).then(result => {
... ... @@ -92,7 +92,7 @@ exports.birthCoupon = (req, res, next) => {
pageFooter: true
};
model._getBirthCouponById(req.user.uid).then(result => {
req.ctx(model)._getBirthCouponById(req.user.uid).then(result => {
res.render('birth-coupon', Object.assign(responseData, result));
}).catch(next);
};
... ...
... ... @@ -14,8 +14,7 @@ const myCurrency = (req, res, next) => {
let uid = req.user.uid;
let contentCode = '05afedf76886d732573f10f7451a1703';
myCurrencyModel.myCurrency(uid, contentCode).then(result => {
req.ctx(myCurrencyModel).myCurrency(uid, contentCode).then(result => {
res.render('currency-new', {
module: 'home',
page: 'mycurrency',
... ... @@ -39,7 +38,7 @@ const currencyDetail = (req, res, next) => {
let page = 1;
let limit = 10;
myCurrencyModel.currencyDetailIndex(uid, page, limit).then(result => {
req.ctx(myCurrencyModel).currencyDetailIndex(uid, page, limit).then(result => {
res.render('currency-detail', {
module: 'home',
page: 'currencyDetail',
... ... @@ -63,7 +62,7 @@ let ajaxCurrencyDetail = (req, res, next) => {
let page = req.body.page || 1;
let limit = 10;
myCurrencyModel.currencyDetail(uid, page, limit).then((result) => {
req.ctx(myCurrencyModel).currencyDetail(uid, page, limit).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -20,7 +20,7 @@ exports.index = (req, res, next) => {
} catch (e) {
uname = params.uname;
}
model.getQr({
req.ctx(model).getQr({
token: params.token,
}).then(result => {
params.token = result;
... ...
... ... @@ -11,7 +11,7 @@ const QRcodeModel = require('../models/qrcode');
exports.QRcode = (req, res, next) => {
let id = req.params.id || 0;
QRcodeModel.getQRcodeData(id, req.user.uid).then((result)=>{
req.ctx(QRcodeModel).getQRcodeData(id, req.user.uid).then((result)=>{
if (result) {
result.ticks = result.ticks.map(item=>{
if (+item.ticket_type === 2) {
... ...
... ... @@ -4,7 +4,12 @@
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const couponData = (params) => {
class couponsModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
couponData(params) {
return api.get('', params).then(result => {
if (result && result.data && result.data.couponList) {
... ... @@ -33,8 +38,7 @@ const couponData = (params) => {
return [];
});
};
}
}
module.exports = {
couponData
};
module.exports = couponsModel;
... ...
... ... @@ -15,7 +15,12 @@ const _ = require('lodash');
const config = global.yoho.config;
const helpers = global.yoho.helpers;
const favProduct = (uid, page, limit) => {
class favoriteIndexModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
favProduct(uid, page, limit) {
return api.get('', {
method: 'app.favorite.product',
... ... @@ -115,10 +120,9 @@ const favProduct = (uid, page, limit) => {
};
}
});
};
const favfavBrand = (uid, page, limit) => {
}
favfavBrand(uid, page, limit) {
return api.get('', {
method: 'app.favorite.brand',
uid: uid,
... ... @@ -199,9 +203,9 @@ const favfavBrand = (uid, page, limit) => {
};
}
});
};
}
const favoriteDelete = (uid, type, favId) => {
favoriteDelete(uid, type, favId) {
return api.get('', {
method: 'app.favorite.cancel',
... ... @@ -209,28 +213,25 @@ const favoriteDelete = (uid, type, favId) => {
type: type,
fav_id: favId
});
};
const index = (uid, page, limit, isbrand) => {
}
index(uid, page, limit, isbrand) {
if (isbrand) {
return favfavBrand(uid, page, limit).then(result=> {
return this.favfavBrand(uid, page, limit).then(result=> {
if (result.total === 0) {
result = {nobrandData: 1};
}
return result;
});
} else {
return favProduct(uid, page, limit).then(result=> {
return this.favProduct(uid, page, limit).then(result=> {
if (result.total === 0) {
result = {noproductData: 1};
}
return result;
});
}
};
}
}
module.exports = {
favProduct,
favfavBrand,
favoriteDelete,
index
};
module.exports = favoriteIndexModel;
... ...
// 帮助 by acgpiano
'use strict';
const api = global.yoho.API;
// 获取帮助列表
exports.getHelpList = () => {
return api.get('', {
method: 'app.help.li'
}).then(result => {
if (result && result.code === 200 && result.data) {
let final = [];
for (let name of result.data) {
final.push({
name: name.caption,
code: name.code,
});
}
return final;
}
});
};
// 获取帮助详情
exports.getHelpDetail = (code) => {
return api.get('', {
method: 'app.help.detail',
code: code,
}).then(result => {
return result.replace(/^<!DOCTYPE.*<body>/g, '').
replace(/<\/body>.*<\/html>/g, '');
});
};
... ... @@ -15,8 +15,13 @@ const _formatDay = (day) => {
return moment(day).format('YYYY.MM.DD');
};
// 获取列表页
const _list = (result) => {
class messageModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 获取列表页
_list(result) {
let final = [];
if (result.data && result.data.list) {
... ... @@ -46,10 +51,10 @@ const _list = (result) => {
}
}
return final;
};
}
// 获取生日信息
const _getBirthCouponById = (uid) => {
// 获取生日信息
_getBirthCouponById(uid) {
return api.get('', {
method: 'app.promotion.queryBirthCoupon',
uid: uid,
... ... @@ -94,10 +99,10 @@ const _getBirthCouponById = (uid) => {
}
}
});
};
}
// 获取详情页
const _detail = (result, id) => {
// 获取详情页
_detail(result, id) {
let final = {};
if (result.data && result.data.list) {
... ... @@ -146,10 +151,10 @@ const _detail = (result, id) => {
}
}
return final;
};
}
// 获取列表或详情
const getList = (params) => {
// 获取列表或详情
getList(params) {
return api.get('', {
method: 'app.inbox.getlist',
page: params.page || 1,
... ... @@ -158,15 +163,15 @@ const getList = (params) => {
}).then(result => {
if (params.msgid) {
// 绕的一比
return _detail(result, params.msgid);
return this._detail(result, params.msgid);
} else {
return _list(result);
return this._list(result);
}
});
};
}
// 删除消息
const delMsg = (params) => {
// 删除消息
delMsg(params) {
return api.get('', {
method: 'app.inbox.delmessage',
uid: params.uid,
... ... @@ -183,10 +188,10 @@ const delMsg = (params) => {
};
}
});
};
}
// 领取优惠券
const pickCoupon = (params) => {
// 领取优惠券
pickCoupon(params) {
return api.get('', {
method: 'app.promotion.getCoupon',
uid: params.uid,
... ... @@ -203,11 +208,7 @@ const pickCoupon = (params) => {
};
}
});
};
}
}
module.exports = {
getList,
delMsg,
pickCoupon,
_getBirthCouponById
};
module.exports = messageModel;
... ...
... ... @@ -5,7 +5,12 @@ const api = global.yoho.API;
const _ = require('lodash');
const logger = global.yoho.logger;
const _yohoCoin = (uid) => {
class myCurrencyModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_yohoCoin(uid) {
return api.get('', {
method: 'app.yoho.yohocoin',
uid: uid
... ... @@ -20,9 +25,9 @@ const _yohoCoin = (uid) => {
return data;
});
};
}
const bannerData = (contentCode) => {
bannerData(contentCode) {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
... ... @@ -39,20 +44,22 @@ const bannerData = (contentCode) => {
return {};
}
});
};
}
const myCurrency = (uid, contentCode) => {
return Promise.all([_yohoCoin(uid), bannerData(contentCode)])
.then((result) => {
myCurrency(uid, contentCode) {
return Promise.all([
this._yohoCoin(uid),
this.bannerData(contentCode)
]).then((result) => {
return {
yohoCoin: result[0],
banner: result[1]
};
});
};
}
const currencyDetail = (uid, page, limit) => {
currencyDetail(uid, page, limit) {
return api.get('', {
method: 'app.yohocoin.lists',
uid: uid,
... ... @@ -73,22 +80,19 @@ const currencyDetail = (uid, page, limit) => {
return data;
});
};
}
const currencyDetailIndex = (uid, page, limit) => {
return Promise.all(
[currencyDetail(uid, page, limit), _yohoCoin(uid)]
).then(result => {
currencyDetailIndex(uid, page, limit) {
return Promise.all([
this.currencyDetail(uid, page, limit),
this._yohoCoin(uid)
]).then(result => {
return {
coinlist: result[0],
yohoCoin: result[1]
};
});
};
module.exports = {
myCurrency,
currencyDetailIndex,
currencyDetail,
bannerData
};
}
}
module.exports = myCurrencyModel;
... ...
... ... @@ -4,7 +4,12 @@ const api = global.yoho.API;
const crypto = global.yoho.crypto;
const PASSWORD = 'yoho9646yoho9646';
exports.getQr = (params) => {
class qrcodeModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getQr(params) {
let uid = '';
try {
... ... @@ -20,4 +25,7 @@ exports.getQr = (params) => {
}).then(result => {
return (result && result.data && result.data.code) || '';
});
};
}
}
module.exports = qrcodeModel;
... ...
... ... @@ -8,7 +8,12 @@
const logger = global.yoho.logger;
var api = global.yoho.API;
exports.getQRcodeData = (id, uid) => {
class qrcodeModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getQRcodeData(id, uid) {
return api.get('', {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: id,
... ... @@ -21,5 +26,7 @@ exports.getQRcodeData = (id, uid) => {
return false;
}
});
};
}
}
module.exports = qrcodeModel;
... ...
... ... @@ -24,7 +24,6 @@ const orderController = require(`${cRoot}/order`);
const orderDetailController = require(`${cRoot}/orderDetail`);
const currencyController = require(`${cRoot}/myCurrency`);
const coupons = require(`${cRoot}/coupons`);
const help = require(`${cRoot}/help`);
const suggest = require(`${cRoot}/suggest`);
const message = require(`${cRoot}/message`);
const onlineService = require(`${cRoot}/onlineService`);
... ... @@ -84,10 +83,6 @@ router.post('/favoriteDel', auth, favorite.favoriteDelete);// 取消收藏
router.use('/coupons', auth, coupons.index);
router.use('/couponsAjax', coupons.couponsAjax);
// 帮助中心
router.get('/help', help.index);
router.get('/helpDetail', help.helpDetail);
// 意见反馈
router.get('/suggest', suggest.suggestData);
router.post('/upAndDown', suggest.upAndDown);
... ...
{{{detail}}}
\ No newline at end of file
<div class="i-help">
<ul>
{{#iHelp}}
<li><a href="//m.yohobuy.com/home/helpDetail?code={{code}}&name={{name}}"><span>{{name}}</span><i class="iconfont num">&#xe604;</i></a></li>
{{/iHelp}}
</ul>
</div>
\ No newline at end of file
... ... @@ -65,7 +65,7 @@ const about = (req, res, next) => {
width750: true
};
aboutModel.about(req.yoho.isApp).then(result => {
req.ctx(aboutModel).about(req.yoho.isApp).then(result => {
res.render('agreement/about', Object.assign(responseData, {wxFooter: result}));
}).catch(next);
};
... ...
... ... @@ -2,7 +2,12 @@
const api = global.yoho.API;
const about = (isApp) => {
class aboutModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
about(isApp) {
return api.get('', {
method: 'app.document.config'
}, {
... ... @@ -19,8 +24,7 @@ const about = (isApp) => {
}
return result;
});
};
}
}
module.exports = {
about
};
module.exports = aboutModel;
... ...