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,37 +4,41 @@
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const couponData = (params) => {
return api.get('', params).then(result => {
if (result && result.data && result.data.couponList) {
let status0 = params.status === 0;
let status1 = params.status === 1;
return result.data.couponList.map(function(elem) {
delete elem.id;
if (status0) {
elem.bestowLink = helpers.urlFormat('/product/index/index',
{
coupon_id: elem.couponId,
coupon_code: elem.couponCode,
title: '优惠活动商品',
intro_text: `以下商品可使用【${elem.couponDetailInfomation}】优惠券`
}
);
} else if (status1) {
delete elem.overState;
elem.employbg = true;
}
return elem;
});
}
return [];
});
};
module.exports = {
couponData
};
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) {
let status0 = params.status === 0;
let status1 = params.status === 1;
return result.data.couponList.map(function(elem) {
delete elem.id;
if (status0) {
elem.bestowLink = helpers.urlFormat('/product/index/index',
{
coupon_id: elem.couponId,
coupon_code: elem.couponCode,
title: '优惠活动商品',
intro_text: `以下商品可使用【${elem.couponDetailInfomation}】优惠券`
}
);
} else if (status1) {
delete elem.overState;
elem.employbg = true;
}
return elem;
});
}
return [];
});
}
}
module.exports = couponsModel;
... ...
... ... @@ -15,222 +15,223 @@ const _ = require('lodash');
const config = global.yoho.config;
const helpers = global.yoho.helpers;
const favProduct = (uid, page, limit) => {
return api.get('', {
method: 'app.favorite.product',
uid: uid,
page: page,
limit: limit
}).then((result) => {
let resu = {
hasFavProduct: []
};
class favoriteIndexModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
if (result && result.code === 200) {
favProduct(uid, page, limit) {
let list = camelCase(result);
return api.get('', {
method: 'app.favorite.product',
uid: uid,
page: page,
limit: limit
}).then((result) => {
if (page > 1 && list === []) {
resu.end = true;
}
let resu = {
hasFavProduct: []
};
if (list.data.total === 0) {
resu.total = 0;
}
if (result && result.code === 200) {
if (page <= list.data.pageTotal) {
list.data.productList = _.filter(list.data.productList, function(n) {
return n.productSkn > 0;
});
_.forEach(list.data.productList, function(val) {
let obj = {};
let list = camelCase(result);
// if (empty(val.productSkn)) {
// continue;
// }
if (page > 1 && list === []) {
resu.end = true;
}
if (val.goodsId && val.cnAlphabet) {
obj = _.assign(obj, {
link: config.siteUrl + '/product/' + val.productSkn + '.html' // 商品url改版
});
} else {
obj = _.assign(obj, {
link: ''
});
}
if (list.data.total === 0) {
resu.total = 0;
}
if (val.image) {
obj = _.assign(obj, {
imgUrl: val.image
});
} else {
obj = _.assign(obj, {
imgUrl: ''
});
}
if (val.marketPrice - val.salesPrice > 0) {
obj = _.assign(obj, {
discountPrice: '¥' + Number(val.salesPrice).toFixed(2)
});
}
if (val.priceDown > 0) {
obj = _.assign(obj, {
savePrice: '¥' + Number(val.priceDown).toFixed(2)
});
} else {
obj = _.assign(obj, {
savePrice: false
});
}
if (page <= list.data.pageTotal) {
list.data.productList = _.filter(list.data.productList, function(n) {
return n.productSkn > 0;
});
_.forEach(list.data.productList, function(val) {
let obj = {};
// if (empty(val.productSkn)) {
// continue;
// }
if (val.goodsId && val.cnAlphabet) {
obj = _.assign(obj, {
link: config.siteUrl + '/product/' + val.productSkn + '.html' // 商品url改版
});
} else {
obj = _.assign(obj, {
link: ''
});
}
if (val.image) {
obj = _.assign(obj, {
imgUrl: val.image
});
} else {
obj = _.assign(obj, {
imgUrl: ''
});
}
if (val.marketPrice - val.salesPrice > 0) {
obj = _.assign(obj, {
discountPrice: '¥' + Number(val.salesPrice).toFixed(2)
});
}
if (val.priceDown > 0) {
obj = _.assign(obj, {
savePrice: '¥' + Number(val.priceDown).toFixed(2)
});
} else {
obj = _.assign(obj, {
savePrice: false
});
}
if (val.storage <= 0) {
obj = _.assign(obj, {
sellOut: true
});
}
if (val.storage <= 0) {
obj = _.assign(obj, {
sellOut: true
favId: val.productId,
title: val.productName,
price: '¥' + Number(val.marketPrice).toFixed(2),
invalidGoods: val.status === 0
});
}
obj = _.assign(obj, {
favId: val.productId,
title: val.productName,
price: '¥' + Number(val.marketPrice).toFixed(2),
invalidGoods: val.status === 0
resu.hasFavProduct.push(obj);
});
resu.hasFavProduct.push(obj);
});
} else {
resu.more = true;
}
return resu;
} else {
resu.more = true;
logger.error('fav goods code no 200');
return {
total: 0
};
}
});
}
return resu;
} else {
logger.error('fav goods code no 200');
return {
total: 0
};
}
});
};
favfavBrand(uid, page, limit) {
return api.get('', {
method: 'app.favorite.brand',
uid: uid,
page: page,
limit: limit
}).then((result) => {
const favfavBrand = (uid, page, limit) => {
let resu = {
hasFavBrand: []
};
return api.get('', {
method: 'app.favorite.brand',
uid: uid,
page: page,
limit: limit
}).then((result) => {
if (result && result.code === 200) {
let list = camelCase(result);
let resu = {
hasFavBrand: []
};
if (page > 1 && list === []) {
resu.end = true;
}
if (result && result.code === 200) {
let list = camelCase(result);
if (list.data.total === 0) {
resu.total = 0;
}
if (page > 1 && list === []) {
resu.end = true;
}
if (page <= list.data.pageTotal) {
if (list.data.total === 0) {
resu.total = 0;
}
_.forEach(list.data.brandList, function(val) {
let obj = {
productList: []
};
if (page <= list.data.pageTotal) {
// if (empty(val.productSkn)) {
// continue;
// }
if (val.brandOrShopType === 'brandOrShopType') {
obj = _.assign(obj, {
link: helpers.urlFormat('/product/index/brand', {
shop_id: val.shopId
})
});
} else {
obj = _.assign(obj, {
link: helpers.urlFormat('', {}, val.brandDomain)
_.forEach(list.data.brandList, function(val) {
let obj = {
productList: []
};
});
}
// if (empty(val.productSkn)) {
// continue;
// }
if (val.brandOrShopType === 'brandOrShopType') {
obj = _.assign(obj, {
link: helpers.urlFormat('/product/index/brand', {
shop_id: val.shopId
})
id: val.brandId,
brandName: val.brandName,
updata: val.newProductNum,
discount: val.productDiscountNum,
brandImg: val.brandIco,
update: val.newProductNum
});
} else {
obj = _.assign(obj, {
link: helpers.urlFormat('', {}, val.brandDomain)
_.forEach(val.newProduct, function(data, key) {
obj.productList.push({
link: '/product/' + data.productSkn + '.html', // 商品url改版
imgUrl: data.defaultImages,
price: '¥' + Number(data.marketPrice).toFixed(2),
discount: data.marketPrice > data.salesPrice ? '¥' +
Number(data.salesPrice).toFixed(2) : false,
top3: key < 3 ? 1 : 0
});
});
}
obj = _.assign(obj, {
id: val.brandId,
brandName: val.brandName,
updata: val.newProductNum,
discount: val.productDiscountNum,
brandImg: val.brandIco,
update: val.newProductNum
});
_.forEach(val.newProduct, function(data, key) {
obj.productList.push({
link: '/product/' + data.productSkn + '.html', // 商品url改版
imgUrl: data.defaultImages,
price: '¥' + Number(data.marketPrice).toFixed(2),
discount: data.marketPrice > data.salesPrice ? '¥' +
Number(data.salesPrice).toFixed(2) : false,
top3: key < 3 ? 1 : 0
});
resu.hasFavBrand.push(obj);
});
resu.hasFavBrand.push(obj);
});
} else {
resu.more = true;
}
return resu;
} else {
resu.more = true;
logger.error('fav brand code no 200');
return {
total: 0
};
}
});
}
favoriteDelete(uid, type, favId) {
return api.get('', {
method: 'app.favorite.cancel',
uid: uid,
type: type,
fav_id: favId
});
}
return resu;
index(uid, page, limit, isbrand) {
if (isbrand) {
return this.favfavBrand(uid, page, limit).then(result=> {
if (result.total === 0) {
result = {nobrandData: 1};
}
return result;
});
} else {
logger.error('fav brand code no 200');
return {
total: 0
};
return this.favProduct(uid, page, limit).then(result=> {
if (result.total === 0) {
result = {noproductData: 1};
}
return result;
});
}
});
};
const favoriteDelete = (uid, type, favId) => {
return api.get('', {
method: 'app.favorite.cancel',
uid: uid,
type: type,
fav_id: favId
});
};
const index = (uid, page, limit, isbrand) => {
if (isbrand) {
return favfavBrand(uid, page, limit).then(result=> {
if (result.total === 0) {
result = {nobrandData: 1};
}
return result;
});
} else {
return 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,199 +15,200 @@ const _formatDay = (day) => {
return moment(day).format('YYYY.MM.DD');
};
// 获取列表页
const _list = (result) => {
let final = [];
if (result.data && result.data.list) {
// PHP排序了,应该不用
for (let item of result.data.list) {
let obj = {
id: item.id,
isNotReaded: item.is_read === 'Y' ? false : true,
title: item.title,
time: `${item.create_date} ${_formatTime(item.create_time * 1000)}`,
};
if (item.body && item.type === 'pullCoupon') {
Object.assign(obj, {
birthType: true,
// name: item.body.name,
// collarTime: item.body.collar_time,
// useTime: item.body.use_time,
isCollar: item.body.is_collar === 'Y' ? true : false,
isOverTime: item.body.is_over_time === 'Y' ? true : false
});
}
class messageModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 获取列表页
_list(result) {
let final = [];
if (result.data && result.data.list) {
// PHP排序了,应该不用
for (let item of result.data.list) {
let obj = {
id: item.id,
isNotReaded: item.is_read === 'Y' ? false : true,
title: item.title,
time: `${item.create_date} ${_formatTime(item.create_time * 1000)}`,
};
if (item.body && item.type === 'pullCoupon') {
Object.assign(obj, {
birthType: true,
final.push(obj);
// name: item.body.name,
// collarTime: item.body.collar_time,
// useTime: item.body.use_time,
isCollar: item.body.is_collar === 'Y' ? true : false,
isOverTime: item.body.is_over_time === 'Y' ? true : false
});
}
final.push(obj);
}
}
return final;
}
return final;
};
// 获取生日信息
const _getBirthCouponById = (uid) => {
return api.get('', {
method: 'app.promotion.queryBirthCoupon',
uid: uid,
couponType: 4,
}).then(result => {
if (result && result.data) {
let final = {
ticket: []
};
final.birthType = true;
if (result.data.list && result.data.list[0].body.is_collar === 'Y') {
final = {
isCollar: true
// 获取生日信息
_getBirthCouponById(uid) {
return api.get('', {
method: 'app.promotion.queryBirthCoupon',
uid: uid,
couponType: 4,
}).then(result => {
if (result && result.data) {
let final = {
ticket: []
};
} else {
if (result.data && !result.data[0].err) {
for (let coupon of result.data) {
final.ticket.push({
id: coupon.id ? coupon.id : '',
couponAmount: coupon.couponAmount,
couponName: coupon.couponName.split('-')[0],
startTime: _formatDay(coupon.startTime),
endTime: _formatDay(coupon.endTime),
useLimit: coupon.useLimit
});
}
} else {
final.birthType = true;
if (result.data.list && result.data.list[0].body.is_collar === 'Y') {
final = {
err: result.data[0].err
isCollar: true
};
} else {
if (result.data && !result.data[0].err) {
for (let coupon of result.data) {
final.ticket.push({
id: coupon.id ? coupon.id : '',
couponAmount: coupon.couponAmount,
couponName: coupon.couponName.split('-')[0],
startTime: _formatDay(coupon.startTime),
endTime: _formatDay(coupon.endTime),
useLimit: coupon.useLimit
});
}
} else {
final = {
err: result.data[0].err
};
}
}
}
return final;
} else {
if (result.code === 410) {
return [{err: result.message}];
} else if (result.code === 411) {
return [{err: result.message}];
return final;
} else {
return [];
if (result.code === 410) {
return [{err: result.message}];
} else if (result.code === 411) {
return [{err: result.message}];
} else {
return [];
}
}
}
});
};
});
}
// 获取详情页
const _detail = (result, id) => {
let final = {};
if (result.data && result.data.list) {
for (let item of result.data.list) {
if (item.id === Number(id) && item.type !== 'showGetCoin' && item.type !== 'notice') {
final.sender = item.from;
final.title = item.title;
final.time = `${item.create_date} ${_formatTime(item.create_time * 1000)}`; // 时间
// 判断消息类型
switch (item.type) {
case 'button':
// 促销活动
if (item.body) {
final.sale = {
image: item.body.image ? item.body.image : '',
content: item.body.text ? item.body.text : '',
btnLink: item.body.pc_link ? item.body.pc_link : '',
btnName: item.body.button_text ? item.body.button_text : '',
// 获取详情页
_detail(result, id) {
let final = {};
if (result.data && result.data.list) {
for (let item of result.data.list) {
if (item.id === Number(id) && item.type !== 'showGetCoin' && item.type !== 'notice') {
final.sender = item.from;
final.title = item.title;
final.time = `${item.create_date} ${_formatTime(item.create_time * 1000)}`; // 时间
// 判断消息类型
switch (item.type) {
case 'button':
// 促销活动
if (item.body) {
final.sale = {
image: item.body.image ? item.body.image : '',
content: item.body.text ? item.body.text : '',
btnLink: item.body.pc_link ? item.body.pc_link : '',
btnName: item.body.button_text ? item.body.button_text : '',
};
}
break;
case 'pushCoupon':
// 查看优惠券
if (item.body) {
final.coupons = [];
final.coupons.push({
remark: item.body.coupon_name ? item.body.coupon_name : '',
useTime: item.body.time ? item.body.time : '',
id: item.body.inboxId ? item.body.inboxId : '',
price: item.body.price ? item.body.price : '',
url: helpers.urlFormat('/home/coupons', {
t: (new Date().getTime()) / 1000,
}),
});
}
break;
default:
// 普通文本
final.text = {
content: item.body.content ? item.body.content : '',
};
}
break;
case 'pushCoupon':
// 查看优惠券
if (item.body) {
final.coupons = [];
final.coupons.push({
remark: item.body.coupon_name ? item.body.coupon_name : '',
useTime: item.body.time ? item.body.time : '',
id: item.body.inboxId ? item.body.inboxId : '',
price: item.body.price ? item.body.price : '',
url: helpers.urlFormat('/home/coupons', {
t: (new Date().getTime()) / 1000,
}),
});
}
break;
default:
// 普通文本
final.text = {
content: item.body.content ? item.body.content : '',
};
break;
break;
}
}
}
}
return final;
}
return final;
};
// 获取列表或详情
const getList = (params) => {
return api.get('', {
method: 'app.inbox.getlist',
page: params.page || 1,
size: params.size || 10,
uid: params.uid,
}).then(result => {
if (params.msgid) {
// 绕的一比
return _detail(result, params.msgid);
} else {
return _list(result);
}
});
};
// 获取列表或详情
getList(params) {
return api.get('', {
method: 'app.inbox.getlist',
page: params.page || 1,
size: params.size || 10,
uid: params.uid,
}).then(result => {
if (params.msgid) {
// 绕的一比
return this._detail(result, params.msgid);
} else {
return this._list(result);
}
});
}
// 删除消息
const delMsg = (params) => {
return api.get('', {
method: 'app.inbox.delmessage',
uid: params.uid,
id: params.msgid,
}).then(result => {
if (result && result.code === 200) {
return {
code: 200
};
} else {
return {
code: 400,
message: '出错啦~',
};
}
});
};
// 删除消息
delMsg(params) {
return api.get('', {
method: 'app.inbox.delmessage',
uid: params.uid,
id: params.msgid,
}).then(result => {
if (result && result.code === 200) {
return {
code: 200
};
} else {
return {
code: 400,
message: '出错啦~',
};
}
});
}
// 领取优惠券
const pickCoupon = (params) => {
return api.get('', {
method: 'app.promotion.getCoupon',
uid: params.uid,
couponId: params.couponId,
}).then(result => {
if (result && result.code === 200) {
return {
code: 200
};
} else {
return {
code: result.code,
message: result.message,
};
}
});
};
// 领取优惠券
pickCoupon(params) {
return api.get('', {
method: 'app.promotion.getCoupon',
uid: params.uid,
couponId: params.couponId,
}).then(result => {
if (result && result.code === 200) {
return {
code: 200
};
} else {
return {
code: result.code,
message: result.message,
};
}
});
}
}
module.exports = {
getList,
delMsg,
pickCoupon,
_getBirthCouponById
};
module.exports = messageModel;
... ...
... ... @@ -5,90 +5,94 @@ const api = global.yoho.API;
const _ = require('lodash');
const logger = global.yoho.logger;
const _yohoCoin = (uid) => {
return api.get('', {
method: 'app.yoho.yohocoin',
uid: uid
}).then((result) => {
let data = [];
if (result && result.code === 200) {
data = result.data;
} else {
logger.error('youhocoin code no 200');
}
return data;
});
};
const bannerData = (contentCode) => {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('banner is not 200');
return {};
}
});
};
const myCurrency = (uid, contentCode) => {
return Promise.all([_yohoCoin(uid), bannerData(contentCode)])
.then((result) => {
class myCurrencyModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_yohoCoin(uid) {
return api.get('', {
method: 'app.yoho.yohocoin',
uid: uid
}).then((result) => {
let data = [];
if (result && result.code === 200) {
data = result.data;
} else {
logger.error('youhocoin code no 200');
}
return data;
});
}
bannerData(contentCode) {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('banner is not 200');
return {};
}
});
}
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) => {
return api.get('', {
method: 'app.yohocoin.lists',
uid: uid,
page: page,
limit: limit
}).then((result) => {
let data = [];
if (result && result.code === 200) {
data = _.get(result, 'data.coinlist', []);
_.forEach(data, (perCoin, key) => {
if (perCoin.num > 0) {
data[key].num = '+' + perCoin.num;
}
});
}
return data;
});
};
const currencyDetailIndex = (uid, page, limit) => {
return Promise.all(
[currencyDetail(uid, page, limit), _yohoCoin(uid)]
).then(result => {
return {
coinlist: result[0],
yohoCoin: result[1]
};
});
};
module.exports = {
myCurrency,
currencyDetailIndex,
currencyDetail,
bannerData
};
}
currencyDetail(uid, page, limit) {
return api.get('', {
method: 'app.yohocoin.lists',
uid: uid,
page: page,
limit: limit
}).then((result) => {
let data = [];
if (result && result.code === 200) {
data = _.get(result, 'data.coinlist', []);
_.forEach(data, (perCoin, key) => {
if (perCoin.num > 0) {
data[key].num = '+' + perCoin.num;
}
});
}
return data;
});
}
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 = myCurrencyModel;
... ...
... ... @@ -4,20 +4,28 @@ const api = global.yoho.API;
const crypto = global.yoho.crypto;
const PASSWORD = 'yoho9646yoho9646';
exports.getQr = (params) => {
let uid = '';
class qrcodeModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getQr(params) {
let uid = '';
try {
uid = crypto.decrypt(PASSWORD, decodeURIComponent(params.token));
uid = parseInt(uid, 10);
} catch (e) {
uid = params.token;
}
try {
uid = crypto.decrypt(PASSWORD, decodeURIComponent(params.token));
uid = parseInt(uid, 10);
} catch (e) {
uid = params.token;
return api.get('', {
method: 'app.twoDimen.getCode',
uid: uid,
}).then(result => {
return (result && result.data && result.data.code) || '';
});
}
}
return api.get('', {
method: 'app.twoDimen.getCode',
uid: uid,
}).then(result => {
return (result && result.data && result.data.code) || '';
});
};
module.exports = qrcodeModel;
... ...
... ... @@ -8,18 +8,25 @@
const logger = global.yoho.logger;
var api = global.yoho.API;
exports.getQRcodeData = (id, uid) => {
return api.get('', {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: id,
uid: uid
}).then(result => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error(`查看二维码ID: ${id} 接口返回数据错误`);
return false;
}
});
};
class qrcodeModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getQRcodeData(id, uid) {
return api.get('', {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: id,
uid: uid
}).then(result => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error(`查看二维码ID: ${id} 接口返回数据错误`);
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,25 +2,29 @@
const api = global.yoho.API;
const about = (isApp) => {
return api.get('', {
method: 'app.document.config'
}, {
cache: true,
code: 200
}).then(result => {
if (result && result.data) {
result = {
wxTitle: result.data.wechatAtten,
wxTip: result.data.wechatAttenSub,
wxCopy: result.data.wechatCopy,
isApp: isApp
};
}
return result;
});
};
class aboutModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
module.exports = {
about
};
about(isApp) {
return api.get('', {
method: 'app.document.config'
}, {
cache: true,
code: 200
}).then(result => {
if (result && result.data) {
result = {
wxTitle: result.data.wechatAtten,
wxTip: result.data.wechatAttenSub,
wxCopy: result.data.wechatCopy,
isApp: isApp
};
}
return result;
});
}
}
module.exports = aboutModel;
... ...