...
|
...
|
@@ -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
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}; |
...
|
...
|
|