Authored by 沈志敏

完善调用数据接口

/**
* 主页
* 个人中心主页
* @author: shenzm<zhimin.shen@yoho.cn>
* @date: 2016/07/18
*/
... ... @@ -14,6 +14,8 @@ const helpers = global.yoho.helpers;
const component = {
index: (req, res, next) => {
let uid = req.user.uid;
uid = 8050378; // 测试uid
if (!uid && req.xhr) {
return res.json({
code: 400,
... ... @@ -22,16 +24,16 @@ const component = {
}
homeModel.getUserHomeData(uid).then(data => {
const proData = data[0];
let result = {
module: 'home',
page: 'index',
head_ico: uid ? '' : '',
profile_name: uid ? 'James Sen' : '登录/注册',
head_ico: proData.head_ico ? helpers.image(proData.head_ico, 200, 200) : '',
profile_name: uid ? proData.profile_name : '登录/注册',
userinfourl: uid ? '/home/mydetails' : helpers.urlFormat('/signin.html', {
refer: req.originalUrl
}),
};
res.render('index', _.merge(result, data[1]));
}).catch(next);
},
... ... @@ -44,9 +46,8 @@ const component = {
});
}).catch(next);
},
helpDetail: (req, res, next) => {
var helpDetailPara = {
let helpDetailPara = {
code: req.query.code,
caption: req.query.caption
};
... ... @@ -59,7 +60,6 @@ const component = {
});
}).catch(next);
},
feedback: (req, res, next) => {
res.render('feedback', {
module: 'home',
... ... @@ -67,7 +67,6 @@ const component = {
suggestSub: true,
}).catch(next);
},
saveFeedback: (req, res, next) => {
let saveFeedbackPara = {
uid: '13549737',
... ... @@ -103,63 +102,99 @@ const component = {
}
}).catch(next);
},
favorite: (req, res, next) => {
let tab = req.query.tab;
let testData = {
brandUrl: helpers.urlFormat('/product/new'),
productUrl: helpers.urlFormat('/product/new')
};
if (tab === 'brand') {
res.render('favorite-brand', _.merge({
if (req.query.tab === 'brand') {
res.render('favorite-brand', {
module: 'home',
page: 'favorite-brand',
}, testData));
brandUrl: helpers.urlFormat('/product/new')
});
} else {
res.render('favorite', _.merge({
res.render('favorite', {
module: 'home',
page: 'favorite',
}, testData));
productUrl: helpers.urlFormat('/product/new')
});
}
},
favpaging: (req, res, next) => {
let tab = req.query.tab;
let page = req.query.page;
if (page > 2) return res.json([]);
let testData = [];
for (var i = 1; i <= 9; i++) {
if (tab === 'brand') {
testData.push({
fav_id: Number(page + i),
brandName: '品牌名测试' + Number(page + i),
invalidGoods: true
let uid = req.user.uid;
uid = 20000134; // 测试uid
const tab = req.query.tab;
const page = req.query.page;
const result = [];
let isend = true;
if (tab === 'brand') {
const gender = '1,2,3'; // todo 获取频道的性别
homeModel.getFavBrandData(uid, gender, page, 10).then(data => {
if (data && page <= data.page_total) {
data.brand_list.forEach(function(d) {
result.push({
fav_id: d.brand_id,
link: "", // todo
imgUrl: d.brand_ico ? helpers.image(d.brand_ico, 160, 125) : '',
brandName: d.brand_name,
down: d.status == 0
})
});
if (page < data.page_total) {
isend = false;
}
}
return res.json({
isend: isend,
list: result
});
} else {
testData.push({
fav_id: Number(page + i),
title: '商品名测试测试测试测试测试测试测试测试' + Number(page + i),
invalidGoods: true,
discountPrice: '¥' + 900,
price: '¥' + 990
});
} else {
homeModel.getFavProductData(uid, page, 10).then(data => {
if (data && page <= data.page_total) {
data.product_list.forEach(function(d) {
if (!d.product_skn) {
return;
}
let link = '';
if (d.goodsId && d.cnAlphabet) {
link = helpers.urlFormat(`/product/pro_${d.product_id}_${d.goodsId}/${d.cnAlphabet}.html`);
}
result.push({
fav_id: d.product_id,
link: link,
imgUrl: d.image ? helpers.image(d.image) : '',
title: d.product_name,
price: '¥' + Number(d.market_price).toFixed(2),
discountPrice: (Number(d.market_price) - Number(d.sales_price) > 0) ? '¥' + Number(d.sales_price).toFixed(2) : false,
sellOut: d.storage < 0,
invalidGoods: d.status == 0
})
});
if (page < data.page_total) {
isend = false;
}
}
return res.json({
isend: isend,
list: result
});
}
}).catch(next);
}
return res.json(testData);
},
favdel: (req, res, next) => {
let id = req.body.id;
let uid = req.user.uid;
uid = 20000134; // 测试uid
return res.json({
code: 200
});
const favId = req.body.favId;
const type = req.body.type;
homeModel.favoriteDelete(uid, favId, type).then(data => {
return res.json(data);
})
},
// 关于我们
aboutUs: (req, res, next) => {
res.render('about-us', {
... ... @@ -169,4 +204,4 @@ const component = {
}
};
module.exports = component;
module.exports = component;
\ No newline at end of file
... ...
... ... @@ -7,71 +7,132 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
* 处理用户个人详情数据
* 查询用户信息
*
* @param int uid 用户ID
* @return Object 处理之后的个人详情数据
* @return Object 个人详情数据
*/
const _getUserProfileData = (uid) => {
return co(function*() {
// 调用接口获取个人详情
const data = {};
return data;
// return api.get('operations/api/v5/resource/get', {
// uid: uid
// }, {
// cache: true,
// code: 200
// });
})();
return api.get('', {
uid: uid,
method: 'app.passport.profile'
}).then(result => {
return result.data;
});
};
/**
* 处理个人中心页面优惠券,收藏的商品等的数目数据
* 个人中心页面收藏及订单等的数目数据
*
* @param int uid 用户ID
* @return Object 处理之后的个人中心页面收藏的商品等的数目数据
* @return Object 处理之后的数据
*/
const _getInfoNumData = (uid) => {
return co(function*() {
const data = {
wait_pay_num: 1,
wait_cargo_num: 2,
send_cargo_num: 3,
address_num: 4,
product_favorite_total: 5,
brand_favorite_total: 6,
yoho_coin_num: 7
return api.all([api.get('', {
uid: uid,
method: 'app.home.getInfoNum' // 收藏及订单数目数据
}), api.get('', {
uid: uid,
method: 'app.address.gethidden' // 用户地址的数据
})]).then(data => {
let res = {
wait_pay_num: 0,
wait_cargo_num: 0,
send_cargo_num: 0,
refund_exchange_num: 0,
product_favorite_total: 0,
brand_favorite_total: 0,
yoho_coin_num: 0
};
return data;
})();
if (data[0].data) {
for (let k in data[0].data) {
if (res[k] !== undefined) {
res[k] = data[0].data[k] ? data[0].data[k] : "";
if (k !== 'yoho_coin_num' && res[k] > 99) {
res[k] = '99+';
}
}
}
}
if (data[1].data) {
res = _.merge(res, {
address_num: data[1].data.length ? data[1].data.length : ""
});
}
return res;
})
};
/**
* 个人中心主页数据
*
* @param int uid 用户ID
* @return Object 处理之后的数据
*/
exports.getUserHomeData = (uid) => {
return Promise.all([_getUserProfileData(uid), _getInfoNumData(uid)]);
};
// 处理帮助中心数据
const helpListDataProc = (helpData) => {
const formatData = [];
helpData = helpData || [];
_.forEach(helpData, (item) => {
formatData.push({
name: item.caption,
code: item.code,
url: helpers.urlFormat('/home/helpDetail', {
code: item.code,
caption: item.caption,
})
});
/**
* 处理用户收藏的商品数据
*
* @param int uid 用户ID
* @param int page 第几页
* @param int limit 限制读取的数目,默认10
* @return array 处理之后的收藏的商品数据
*/
exports.getFavProductData = (uid, page, limit) => {
return api.get('', {
method: 'app.favorite.product',
uid: uid,
page: page,
limit: limit
}).then(result => {
return result.data;
});
return formatData;
};
/**
* 处理用户收藏的品牌数据
*
* @param int uid 用户ID
* @param string gender 性别 1,3表示男,2,3表示女,1,2,3表示全部
* @param int page 第几页
* @param int limit 限制读取的数目
* @return array 处理之后的收藏的品牌数据
*/
exports.getFavBrandData = (uid, gender, page, limit) => {
return api.get('', {
method: 'app.favorite.brand',
uid: uid,
gender: gender,
page: page,
limit: limit
}).then(result => {
return result.data;
})
}
/**
* 取消收藏的商品/品牌数据
*
* @param int uid 用户ID
* @param int favId 要取消的收藏id
* @param string type 取消类型(brand:品牌,product:商品)
* @return array 接口返回的数据
*/
exports.favoriteDelete = (uid, favId, type) => {
return api.get('', {
method: 'app.favorite.cancel',
uid: uid,
type: type,
fav_id: favId
});
}
/**
* 帮助中心列表页
*
* @param data
... ... @@ -84,8 +145,21 @@ exports.getHelpInfo = (data) => {
infoData = Object.assign(defaultParam, data);
return api.get('', infoData).then(result => {
const helpData = result.data;
const formatData = [];
return helpListDataProc(result.data);
helpData = helpData || [];
_.forEach(helpData, (item) => {
formatData.push({
name: item.caption,
code: item.code,
url: helpers.urlFormat('/home/helpDetail', {
code: item.code,
caption: item.caption,
})
});
});
return formatData;
});
};
... ... @@ -106,8 +180,6 @@ exports.getHelpDetail = (data) => {
});
};
/**
* 保存意见反馈数据
*
... ... @@ -122,4 +194,4 @@ exports.saveFeedback = (data) => {
// 参考接口数据
});
};
};
\ No newline at end of file
... ...
... ... @@ -37,8 +37,8 @@
<a class="type-item" href="/home/orders?type=5">
<span>&#xe633;</span>
<br>退换货
{{#if send_cargo_num}}
<span class="num">{{send_cargo_num}}</span>
{{#if refund_exchange_num}}
<span class="num">{{refund_exchange_num}}</span>
{{/if}}
</a>
</div>
... ...
... ... @@ -28,7 +28,7 @@
width: 35px;
height: 35px;
margin-right: 15px;
margin-top: 90px;
margin-top: 80px;
background: resolve("home/fav/fav-del.png");
}
}
... ...
... ... @@ -11,7 +11,7 @@
</div>
<div class="fav-info-list">
<span class="title">{{item.brandName}}</span>
<span class="down" v-if="item.invalidGoods">品牌已下架</span>
<span class="down" v-if="item.down">品牌已下架</span>
</div>
</a>
</li>
... ... @@ -52,13 +52,16 @@
tab : "brand"
}
}).then(result => {
if (result.length) {
result.forEach(function(o){
if (result.isend) {
_this.busy = true;
} else {
_this.busy = false;
}
if (result.list.length) {
result.list.forEach(function(o){
_this.brandData.push(o);
});
_this.busy = false;
} else {
_this.busy = true;
}
_this.nullbox = _this.brandData.length ? "hide" : "";
... ... @@ -77,7 +80,8 @@
method: 'post',
url: '/home/favorite/favdel',
data: {
id: id
favId: id,
type: 'brand'
}
}).then(function(data) {
if (data.code === 200) {
... ...
... ... @@ -59,13 +59,16 @@
page : ++_this.page
}
}).then(result => {
if (result.length) {
result.forEach(function(o){
if (result.isend) {
_this.busy = true;
} else {
_this.busy = false;
}
if (result.list.length) {
result.list.forEach(function(o){
_this.productData.push(o);
});
_this.busy = false;
} else {
_this.busy = true;
}
_this.nullbox = _this.productData.length ? "hide" : "";
... ... @@ -84,7 +87,8 @@
method: 'post',
url: '/home/favorite/favdel',
data: {
id: id
favId: id,
type: 'product'
}
}).then(function(data) {
if (data.code === 200) {
... ...