Authored by 郝肖肖

'fix'

... ... @@ -28,7 +28,7 @@ const shopIndex = (req, res) => {
}
}
shopModel.banner(contentCode).then((result) => {
req.ctx(shopModel).banner(contentCode).then((result) => {
res.render('shop-collect/index', Object.assign({
module: 'activity',
page: 'shop-collect',
... ... @@ -45,7 +45,7 @@ const shopIndex = (req, res) => {
const shopNav = (req, res, next) => {
let channelId = req.query.channelId || '';
shopModel.shopNav(channelId).then((result) => {
req.ctx(shopModel).shopNav(channelId).then((result) => {
res.json(result);
}).catch(next);
};
... ... @@ -56,7 +56,7 @@ const shopList = (req, res, next) => {
let tabName = req.query.tabName;
let channelId = req.query.channelId || '';
shopModel.shopList(uid, tabName, channelId).then((result) => {
req.ctx(shopModel).shopList(uid, tabName, channelId).then((result) => {
res.json(result);
}).catch(next);
};
... ... @@ -70,7 +70,7 @@ const shopFav = (req, res, next) => {
return;
}
shopModel.shopFav(uid, shopIds).then((result) => {
req.ctx(shopModel).shopFav(uid, shopIds).then((result) => {
res.json(result);
}).catch(next);
};
... ...
const api = global.yoho.API;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const service = global.yoho.ServiceAPI;
const serviceAPI = global.yoho.ServiceAPI;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -13,7 +12,7 @@ module.exports = class extends global.yoho.BaseModel {
*/
shareIndex(activityId, isApp, uid) {
return api.all([this._CouponInfo(activityId, uid),
return Promise.all([this._CouponInfo(activityId, uid),
this._redeatList(),
this._banner()
]).then(result => {
... ... @@ -71,12 +70,17 @@ module.exports = class extends global.yoho.BaseModel {
* 首页资源位
*/
_banner() {
return service.get('operations/api/v5/resource/get', {
content_code: 'a4ceb2d742c55008ac7be30bca43e03f',
platform: 'iphone'
}, {
cache: true,
code: 200
return this.get({
api: serviceAPI,
url: 'operations/api/v5/resource/get',
data: {
content_code: 'a4ceb2d742c55008ac7be30bca43e03f',
platform: 'iphone'
},
param: {
cache: true,
code: 200
}
}).then((result) => {
if (result && result.data) {
... ... @@ -89,12 +93,15 @@ module.exports = class extends global.yoho.BaseModel {
* 首页获取优惠券信息
*/
_CouponInfo(activityId, uid) {
return api.get('', {
method: 'app.activity.getActivityCouponInfo',
activity_id: activityId,
uid: uid
}, {
code: 200
return this.get({
data: {
method: 'app.activity.getActivityCouponInfo',
activity_id: activityId,
uid: uid
},
param: {
code: 200
}
}).then((result) => {
if (result && result.code === 200 && result.data) {
return result;
... ... @@ -106,11 +113,14 @@ module.exports = class extends global.yoho.BaseModel {
* 首页获取返利记录
*/
_redeatList() {
return api.get('', {
method: 'app.yohocoinrebeat.lastedlist'
}, {
code: 200,
cache: true
return this.get({
data: {
method: 'app.yohocoinrebeat.lastedlist'
},
param: {
code: 200,
cache: true
}
}).then((result) => {
if (result && result.code === 200 && result.data) {
return result;
... ... @@ -122,12 +132,15 @@ module.exports = class extends global.yoho.BaseModel {
* 优惠劵详情数据
*/
shareDetail(param, isApp) {
return api.get('', {
method: 'app.activity.getActivityCouponDesc',
coupon_code: param.couponCode,
coupon_id: param.couponId
}, {
code: 200
return this.get({
data: {
method: 'app.activity.getActivityCouponDesc',
coupon_code: param.couponCode,
coupon_id: param.couponId
},
param: {
code: 200
}
}).then((result) => {
let moreUrl,
detailData,
... ... @@ -184,10 +197,12 @@ module.exports = class extends global.yoho.BaseModel {
* 获取分享码
*/
getCouponCode(uid, couponId, protocol) {
return api.get('', {
method: 'app.activity.getActivityCouponCode',
uid: uid,
coupon_id: couponId
return this.get({
data: {
method: 'app.activity.getActivityCouponCode',
uid: uid,
coupon_id: couponId
}
}).then(result => {
if (result && result.code === 200 && result.data) {
result.data.detailUrl = helpers.urlFormat('/activity/share-buy/detail', {
... ... @@ -205,11 +220,14 @@ module.exports = class extends global.yoho.BaseModel {
* 我的返利页数据
*/
myRebeat(uid, isApp) {
return api.get('', {
method: 'app.yohocoinrebeat.detail',
uid: uid
}, {
code: 200
return this.get({
data: {
method: 'app.yohocoinrebeat.detail',
uid: uid
},
param: {
code: 200
}
}).then((result) => {
let currencyUrl = helpers.urlFormat('/service/qaDetail', {
keyword: '%E6%9C%89%E8%B4%A7%E5%B8%81',
... ...
... ... @@ -4,122 +4,136 @@
* @date: 2016/10/17
*/
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const logger = global.yoho.logger;
const service = global.yoho.ServiceAPI;
const serviceAPI = global.yoho.ServiceAPI;
const shopList = (uid, tabName, channelId) => {
let params = {
method: 'app.shops.promote'
};
if (uid) {
params.uid = uid;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
if (tabName) {
params.tab_name = tabName;
}
shopList(uid, tabName, channelId) {
let params = {
method: 'app.shops.promote'
};
if (channelId) {
params.channel_id = channelId;
}
if (uid) {
params.uid = uid;
}
return api.get('', params, {
code: 200
}).then((result) => {
if (result && result.code === 200) {
_.forEach(result.data, function(data) {
let href = '//m.yohobuy.com/product/shop?shop_id=' +
data.shopsId + '&openby:yohobuy={"action":"go.shop","params":{"shop_id":"' +
data.shopsId + '","shop_template_type":"' +
data.shopTemplateType + '","shop_name":"' + data.shopName + '"}}';
if (tabName) {
params.tab_name = tabName;
}
data.isFavorite = data.isFavorite === 'Y';
if (channelId) {
params.channel_id = channelId;
}
if (parseInt(data.collectionNum, 10) > 10000) {
data.collectionNum = (data.collectionNum / 10000).toFixed(1) + ' w';
}
return this.get({
data: params,
param: {
code: 200
}
}).then((result) => {
if (result && result.code === 200) {
_.forEach(result.data, function(data) {
let href = '//m.yohobuy.com/product/shop?shop_id=' +
data.shopsId + '&openby:yohobuy={"action":"go.shop","params":{"shop_id":"' +
data.shopsId + '","shop_template_type":"' +
data.shopTemplateType + '","shop_name":"' + data.shopName + '"}}';
data.href = href;
});
return result.data;
} else {
logger.error('shop list data return code is not 200');
return {};
}
});
};
data.isFavorite = data.isFavorite === 'Y';
const shopNav = (channelId) => {
let params = {
method: 'app.shops.promoteTabNameList'
};
if (parseInt(data.collectionNum, 10) > 10000) {
data.collectionNum = (data.collectionNum / 10000).toFixed(1) + ' w';
}
if (channelId) {
params.channel_id = channelId;
}
return api.get('', params, {
cache: true,
code: 200
}).then((result) => {
if (result.data) {
if (result.data.length === 0 || (result.data.length === 1 && result.data[0] === 'NULL')) {
return false;
} else {
data.href = href;
});
return result.data;
} else {
logger.error('shop list data return code is not 200');
return {};
}
}
});
};
});
}
const banner = (contentCode) => {
return service.get('operations/api/v5/resource/get', {
content_code: contentCode,
platform: 'iphone'
}, {
cache: true,
code: 200
}).then((result) => {
if (result && result.data) {
return result.data[0];
}
});
};
shopNav(channelId) {
let params = {
method: 'app.shops.promoteTabNameList'
};
const shopFav = (uid, shopIds) => {
return api.get('', {
method: 'app.shops.promoteFavorite',
shop_ids: shopIds,
uid: uid
}, {
code: 200
}).then((result) => {
if (result.data) {
return result.data;
if (channelId) {
params.channel_id = channelId;
}
});
};
/**
* 根据店铺ID调获取店铺数据
* 图片字段:pic_popular
order 传 pools_id_asc 或者 pools_id_desc
* @param {*} params
*/
const batchGetShops = (params) => {
return api.get('', {
method: 'app.shops.batchGetShops',
shop_ids: params.shop_ids,
order: params.order
});
};
return this.get({
data: params,
param: {
cache: true,
code: 200
}
}).then((result) => {
if (result.data) {
if (result.data.length === 0 || (result.data.length === 1 && result.data[0] === 'NULL')) {
return false;
} else {
return result.data;
}
}
});
}
banner(contentCode) {
return this.get({
api: serviceAPI,
url: 'operations/api/v5/resource/get',
data: {
content_code: contentCode,
platform: 'iphone'
},
param: {
cache: true,
code: 200
}
}).then((result) => {
if (result && result.data) {
return result.data[0];
}
});
}
module.exports = {
shopList,
shopNav,
banner,
shopFav,
batchGetShops
shopFav(uid, shopIds) {
return this.get({
data: {
method: 'app.shops.promoteFavorite',
shop_ids: shopIds,
uid: uid
},
param: {
code: 200
}
}).then((result) => {
if (result.data) {
return result.data;
}
});
}
/**
* 根据店铺ID调获取店铺数据
* 图片字段:pic_popular
order 传 pools_id_asc 或者 pools_id_desc
* @param {*} params
*/
batchGetShops(params) {
return this.get({
data: {
method: 'app.shops.batchGetShops',
shop_ids: params.shop_ids,
order: params.order
}
});
}
};
... ...