Authored by htoooth

fix

... ... @@ -4,8 +4,7 @@
'use strict';
const mRoot = '../models';
const service = require(`${mRoot}/coupon-service`);
const service = require('../models/coupon-service');
const acquire = (req, res, next) => {
let uid = req.user.uid;
... ... @@ -18,7 +17,7 @@ const acquire = (req, res, next) => {
});
}
service.acquireAsync(cid, uid).then((result) => {
req.ctx(service).acquireAsync(cid, uid).then((result) => {
return res.json(result);
}).catch(next);
};
... ...
... ... @@ -43,7 +43,6 @@ const showMain = (req, res, next) => {
page: 'detail'
}, result.seo, result));
}).catch(()=> next());
};
const showMainBack = (req, res) => {
... ... @@ -62,7 +61,6 @@ const showMainBack = (req, res) => {
res.end();
}).catch();
};
/**
... ...
... ... @@ -18,7 +18,7 @@ const changeFavoriteBrand = (req, res, next) => {
let type = req.body.type || '';
if (uid && brandId) {
brandService.changeAsync(type, uid, brandId).then(result => {
req.ctx(brandService).changeAsync(type, uid, brandId).then(result => {
return res.json(result);
}).catch(next);
} else if (!uid) {
... ... @@ -42,7 +42,7 @@ const isFavoriteBrand = (req, res, next) => {
let brandId = req.query.brandId;
if (uid && brandId) {
brandService.isFavoriteAsync(uid, brandId).then(result => {
req.ctx(brandService).isFavoriteAsync(uid, brandId).then(result => {
return res.json(result);
}).catch(next);
} else {
... ... @@ -61,7 +61,7 @@ const collectProduct = (req, res, next) => {
if (uid && pid) {
switch (type) {
case 'add':
productService.createAsync(uid, pid)
req.ctx(productService).createAsync(uid, pid)
.then(result => {
if (result.code === 413) {
result.message = '该商品已经收藏';
... ... @@ -72,7 +72,7 @@ const collectProduct = (req, res, next) => {
.catch(next);
break;
case 'cancel':
productService.deleteAsync(uid, pid)
req.ctx(productService).deleteAsync(uid, pid)
.then(result => res.json(result))
.catch(next);
break;
... ... @@ -120,7 +120,7 @@ const collectShop = (req, res, next) => {
message: '收藏失败'
});
} else {
fav.toggleFavShop(shopId, uid, isadd).then(result => {
req.ctx(fav).toggleFavShop(shopId, uid, isadd).then(result => {
res.json(result);
}).catch(next);
}
... ... @@ -137,7 +137,7 @@ const isFavShop = (req, res, next) => {
});
}
fav.getFavStatus(uid, shopId, 'shop').then(result => {
req.ctx(fav).getFavStatus(uid, shopId, 'shop').then(result => {
return res.json(result);
}).catch(next);
};
... ... @@ -147,13 +147,13 @@ const num = (req, res, next) => {
let sid = _.parseInt(`0${req.query.sid}`) || 0;
if (sid) {
return brandService.getShopFavNumAsync(sid).then((result) => {
return req.ctx(brandService).getShopFavNumAsync(sid).then((result) => {
res.json(result);
}).catch(next);
}
if (bid) {
return brandService.getBrandFavNumAsync(bid).then((result) => {
return req.ctx(brandService).getBrandFavNumAsync(bid).then((result) => {
res.json(result);
}).catch(next);
}
... ...
/**
* Created by TaoHuang on 2016/6/28.
*/
'use strict';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
shopBannerAsync(shopId) {
return this.get({data: {
method: 'app.shop.banner',
shop_id: shopId
}});
}
queryShopsByBrandId(sid, bid) {
return this.get({data: {
method: 'app.product.queryShopsInfoById',
brand_id: bid,
shop_id: sid
}});
}
};
... ...
/**
* Created by TaoHuang on 2016/6/28.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const Api = require('./ctx-shop-api');
const DEFAULT_IMG = '01091c21f2317a64f123f1649fbbccf7ba';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new Api(ctx);
}
getShopBannerAsync(shopId) {
return this.api.shopBannerAsync(shopId).then((result) => {
if (result.code === 200) {
return _.includes(result.data.banner, DEFAULT_IMG) ? '' : result.data.banner;
} else {
return null;
}
});
}
queryShopByBrandIdAsync(sid, bid) {
return co(function * () {
let result = yield this.api.queryShopsByBrandId(sid, bid);
if (_.get(result, 'code') !== 200) {
return false;
}
return _.get(result, 'data[0]', {});
}).bind(this)();
}
};
... ...
... ... @@ -146,12 +146,12 @@ module.exports = class extends global.yoho.BaseModel {
* 店铺推荐
*/
getShopRecommendAsync(skn, page, limit) {
return this.get({
return this.get({data: {
method: 'web.product.shopRecommend',
product_skn: skn,
page: page || 1,
limit: limit || 20
});
}});
}
/**
... ...
... ... @@ -22,10 +22,9 @@ const ConsultServiceModel = require('./detail-consult-service');
const CommentServiceModel = require('./detail-comment-service');
const HotAreaServiceModel = require('./detail-hotarea-service');
const CouponServiceModel = require('./coupon-service');
const ShopServiceModel = require('./shop-service');
const ShopServiceModel = require('./ctx-shop-service');
const BrandServiceModel = require('./brand-service');
const favoriteProductService = require('./favorite-product-service');
const FavoriteProductServiceModel = require('./favorite-product-service');
const homeService = require('./home-service');
const HeaderModel = require('../../../doraemon/models/header');
... ... @@ -85,7 +84,7 @@ function _getProductFavoriteDataAsync(uid, pid) {
let requestApi = {};
if (pid) {
requestApi.product = favoriteProductService.isFavoriteAsync(uid, pid);
requestApi.product = this.favoriteProductService.isFavoriteAsync(uid, pid);
}
let requestData = yield Promise.props(requestApi);
... ... @@ -1107,17 +1106,21 @@ function _detailDataPkg(origin, uid, vipLevel, cookies) {
let coupon = requestData.coupon;
let limitedInfo = requestData.limited;
let bundle = requestData.bundle;
let recommendKeywords = requestData.recommendKeywords ? JSON.parse(requestData.recommendKeywords) : [];
let recommendKeywords = JSON.parse(requestData.recommendAsync || '[]');
let shopRecommend = requestData.shopRecommend;
let alike = requestData.alike;
// 处理相似商品
result.alike = productProcess.processProductList(_.get(requestData, 'alike.data.product_list', ''));
result.alike = productProcess.processProductList(
_.get(alike, 'data.product_list', '')
);
// 推荐关键词页面
result.recommendKeywords = getKeywordsInfo(recommendKeywords);
// 处理店铺推荐
result.shopRecommend = productProcess.processProductList(
_.get(requestData, 'shopRecommend.data.product_list', '')
_.get(shopRecommend, 'data.product_list', '')
);
// 商品标签
... ... @@ -1479,11 +1482,7 @@ function saleReturn(skn) {
* 第一次把售价隐藏,防爬虫的需要
*/
function _removeSalePrice(productInfo) {
delete productInfo.goodsInfo.salePrice;
delete productInfo.goodsInfo.hasOtherPrice;
delete productInfo.goodsInfo.promotion;
return productInfo;
return _.omit(productInfo, ['goodsInfo.salePrice', 'goodsInfo.hasOtherPrice', 'goodsInfo.promotion']);
}
/**
... ... @@ -1710,6 +1709,7 @@ module.exports = class extends global.yoho.BaseModel {
this.couponService = new CouponServiceModel(ctx);
this.shopService = new ShopServiceModel(ctx);
this.brandService = new BrandServiceModel(ctx);
this.favoriteProductService = new FavoriteProductServiceModel(ctx);
// 获取评论列表
this.getShareOrderListAsync = this.commentService.getShareOrderListAsync.bind(this.commentService);
... ...
... ... @@ -4,11 +4,12 @@
* @date: 2016/7/17
*/
'use strict';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const api = global.yoho.API;
/**
/**
* 是否收藏API
* @function cancelFavAsync
* @param { number } uid 用户uid
... ... @@ -16,16 +17,16 @@ const api = global.yoho.API;
* @param { string } type 类型 product--商品 brand--品牌 shop--店铺
* @return { Object } 收藏状态
*/
const isFavAsync = (uid, id, type) => {
return api.get('', {
isFavAsync(uid, id, type) {
return this.get({ data: {
method: 'app.favorite.isFavorite',
id: id,
uid: uid,
type: type
});
};
}});
}
/**
/**
* 收藏API
* @function addFavAsync
* @param { number } uid 用户uid
... ... @@ -33,16 +34,16 @@ const isFavAsync = (uid, id, type) => {
* @param { string } type 收藏类型 product--商品 brand--品牌 shop--店铺
* @return { Object } 收藏结果
*/
const addFavAsync = (uid, id, type) => {
return api.get('', {
addFavAsync(uid, id, type) {
return this.get({ data: {
method: 'app.favorite.add',
id: id,
uid: uid,
type: type
});
};
}});
}
/**
/**
* 取消收藏API
* @function cancelFavAsync
* @param { number } uid 用户uid
... ... @@ -50,17 +51,14 @@ const addFavAsync = (uid, id, type) => {
* @param { string } type 收藏类型 product--商品 brand--品牌 shop--店铺
* @return { Object } 取消收藏结果
*/
const cancelFavAsync = (uid, id, type) => {
return api.get('', {
cancelFavAsync(uid, id, type) {
return this.get({ data: {
method: 'app.favorite.cancel',
fav_id: id,
uid: uid,
type: type
});
}});
}
};
module.exports = {
isFavAsync, // 是否收藏
addFavAsync, // 收藏
cancelFavAsync // 取消收藏
};
... ...
... ... @@ -4,37 +4,42 @@
'use strict';
const api = require('./favorite-api');
const serviceApi = global.yoho.SingleAPI;
const ApiService = require('./favorite-api');
const _ = require('lodash');
const isFavoriteAsync = _.partial(api.isFavAsync, _, _, 'brand');
const addFavAsync = _.partial(api.addFavAsync, _, _, 'brand');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new ApiService(ctx);
const cancelFavAsync = _.partial(api.cancelFavAsync, _, _, 'brand');
this.isFavoriteAsync = _.partial(this.api.isFavAsync.bind(this.api), _, _, 'brand');
this.addFavAsync = _.partial(this.api.addFavAsync.bind(this.api), _, _, 'brand');
this.cancelFavAsync = _.partial(this.api.cancelFavAsync.bind(this.api), _, _, 'brand');
}
const getShopFavNumAsync = (sid) => {
return serviceApi.post('/favorite', {
getShopFavNumAsync(sid) {
return this.post({
data: {
favIds: sid,
type: 'shop',
method: 'app.favorite.queryFavoriteCountByShopIds'
},
url: '/favorite',
api: global.yoho.SingleAPI
});
};
}
const getBrandIdNumAsync = (bid) => {
return serviceApi.post('/favorite', {
getBrandIdNumAsync(bid) {
return this.post({
data: {
brandId: bid,
type: 'brand',
method: 'app.favorite.queryFavoriteCountByBrandId'
method: 'app.favorite.queryFavoriteCountByBrandId',
},
url: '/favorite',
api: global.yoho.SingleAPI
});
};
}
module.exports = {
isFavoriteAsync,
addFavAsync,
cancelFavAsync,
getShopFavNumAsync,
getBrandIdNumAsync
};
... ...
... ... @@ -4,22 +4,30 @@
'use strict';
const api = require('./favorite-brand-api');
const ApiModel = require('./favorite-brand-api');
const _ = require('lodash');
const changeAsync = (type, uid, brandId) => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new ApiModel(ctx);
this.isFavoriteAsync = this.api.isFavoriteAsync.bind(this.api);
}
changeAsync(type, uid, brandId) {
switch (type) {
case 'add':
return api.addFavAsync(uid, brandId);
return this.api.addFavAsync(uid, brandId);
case 'cancel' :
return api.cancelFavAsync(uid, brandId);
return this.api.cancelFavAsync(uid, brandId);
default:
return Promise.reject('favorite brand error');
}
};
};
const getShopFavNumAsync = (sid) => {
return api.getShopFavNumAsync(sid).then((result) => {
getShopFavNumAsync(sid) {
return this.api.getShopFavNumAsync(sid).then((result) => {
if (result.code === 200) {
return {
code: 200,
... ... @@ -34,10 +42,10 @@ const getShopFavNumAsync = (sid) => {
};
}
});
};
};
const getBrandFavNumAsync = (bid) => {
return api.getBrandIdNumAsync(bid).then((result) => {
getBrandFavNumAsync(bid) {
return this.api.getBrandIdNumAsync(bid).then((result) => {
if (result.code === 200) {
return {
code: 200,
... ... @@ -52,14 +60,7 @@ const getBrandFavNumAsync = (bid) => {
};
}
});
};
};
const isFavoriteAsync = api.isFavoriteAsync;
module.exports = {
changeAsync,
isFavoriteAsync,
getShopFavNumAsync,
getBrandFavNumAsync
};
... ...
... ... @@ -4,38 +4,40 @@
'use strict';
const api = global.yoho.API;
const favApi = global.yoho.FavAPI;
const _ = require('lodash');
const FavoriteApiModel = require('./favorite-api');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.favoriteApi = new FavoriteApiModel(ctx);
const favoriteApi = require('./favorite-api');
this.createAsync = _.partial(this.favoriteApi.addFavAsync.bind(this.favoriteApi), _, _, 'product');
this.deleteAsync = _.partial(this.favoriteApi.cancelFavAsync.bind(this.favoriteApi), _, _, 'product');
}
const isFavoriteAsync = (uid, pid) => {
isFavoriteAsync(uid, pid) {
let onNewApi = false;
if (onNewApi) {
return favApi.get('', {
return this.get({
data: {
method: 'app.favorite.isFavoriteNew',
id: pid,
uid: uid,
type: 'product'
},
api: global.yoho.FavAPI
});
} else {
return api.get('', {
return this.get({
data: {
method: 'app.favorite.isFavorite',
id: pid,
uid: uid,
type: 'product'
}
});
}
};
const createAsync = _.partial(favoriteApi.addFavAsync, _, _, 'product');
const deleteAsync = _.partial(favoriteApi.cancelFavAsync, _, _, 'product');
module.exports = {
isFavoriteAsync,
createAsync,
deleteAsync
}
};
... ...
... ... @@ -4,6 +4,6 @@
'use strict';
const favoriteProductAPI = require('./favorite-product-api');
const FavoriteProductAPI = require('./favorite-product-api');
module.exports = favoriteProductAPI;
module.exports = FavoriteProductAPI;
... ...
... ... @@ -6,9 +6,16 @@
'use strict';
const favAPI = require('./favorite-api');
const FavAPI = require('./favorite-api');
/**
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.favAPI = new FavAPI(ctx);
}
/**
* 收藏商品
* @function toggleFavProduct
* @param { number } productId 商品id
... ... @@ -16,15 +23,15 @@ const favAPI = require('./favorite-api');
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
const toggleFavProduct = (productId, uid, isadd) => {
toggleFavProduct(productId, uid, isadd) {
if (isadd) {
return favAPI.addFavAsync(uid, productId, 'product');
return this.favAPI.addFavAsync(uid, productId, 'product');
} else {
return favAPI.cancelFavAsync(uid, productId, 'product');
return this.favAPI.cancelFavAsync(uid, productId, 'product');
}
}
};
/**
/**
* 收藏品牌
* @function toggleFavBrand
* @param { number } brandId 品牌id
... ... @@ -32,15 +39,15 @@ const toggleFavProduct = (productId, uid, isadd) => {
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
const toggleFavBrand = (brandId, uid, isadd) => {
toggleFavBrand(brandId, uid, isadd) {
if (isadd) {
return favAPI.addFavAsync(uid, brandId, 'brand');
return this.favAPI.addFavAsync(uid, brandId, 'brand');
} else {
return favAPI.cancelFavAsync(uid, brandId, 'brand');
return this.favAPI.cancelFavAsync(uid, brandId, 'brand');
}
}
};
/**
/**
* 收藏店铺
* @function toggleFavShop
* @param { number } shopId 店铺id
... ... @@ -48,21 +55,16 @@ const toggleFavBrand = (brandId, uid, isadd) => {
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
const toggleFavShop = (shopId, uid, isadd) => {
toggleFavShop(shopId, uid, isadd) {
if (isadd) {
return favAPI.addFavAsync(uid, shopId, 'shop');
return this.favAPI.addFavAsync(uid, shopId, 'shop');
} else {
return favAPI.cancelFavAsync(uid, shopId, 'shop');
return this.favAPI.cancelFavAsync(uid, shopId, 'shop');
}
}
};
const getFavStatus = (uid, id, type) => {
return favAPI.isFavAsync(uid, id, type);
};
getFavStatus(uid, id, type) {
return this.favAPI.isFavAsync(uid, id, type);
}
module.exports = {
getFavStatus, // 收藏状态
toggleFavProduct, // 收藏商品
toggleFavBrand, // 收藏品牌
toggleFavShop // 收藏店铺
};
... ...
... ... @@ -3,23 +3,49 @@
*/
'use strict';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
const api = global.yoho.API;
const config = global.yoho.config;
/**
* 获取店铺装修的所有资源接口
*/
exports.shopsDecoratorListAsync = shopId => {
return api.get('', {
method: 'app.shopsdecorator.getList',
shop_id: shopId
}, config.apiCache);
};
/**
* 获取店铺优惠券接口
*/
exports.shopCouponListAsync = (shopId, uid) => {
let extra = {
code: 200
};
if (!uid) {
extra.cache = true;
}
shopBannerAsync(shopId) {
return this.get({data: {
return api.get('', {
method: 'shop.coupons.list',
shop_id: shopId,
uid: uid
}, extra);
};
exports.shopBannerAsync = (shopId) => {
return api.get('', {
method: 'app.shop.banner',
shop_id: shopId
}});
}
});
};
queryShopsByBrandId(sid, bid) {
return this.get({data: {
exports.queryShopsByBrandId = (sid, bid) => {
return api.get('', {
method: 'app.product.queryShopsInfoById',
brand_id: bid,
shop_id: sid
}});
}
});
};
... ...
... ... @@ -6,35 +6,112 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const Api = require('./shop-api');
const api = require('./shop-api');
const DEFAULT_IMG = '01091c21f2317a64f123f1649fbbccf7ba';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new Api(ctx);
/**
* 生成缩略图
*/
const _imageView2 = (url, width, height) => {
url += url.includes('?') ? '&' : '?';
return `${url}imageView2/1/w${width}/h/${height}`;
};
/**
* 解析 resource_data 参数
*/
const _getResourceData = list => {
list.resource_data = JSON.parse(list.resource_data || '[]');
return list;
};
/**
* 店铺Banner 资源位
*/
const _shopTopBanner = data => {
let result = {
banner: '',
isShowShopName: false,
bannerHeight: 150
};
let resource = _.head(data.resource_data);
if (resource.shopSrc) {
result.banner = _imageView2(resource.shopSrc, 1150, 150);
}
if (resource.detailSrc) {
result.detailSrc = _imageView2(resource.detailSrc, 1150, 150);
}
if (resource.isShowShopName) {
result.isShowShopName = resource.isShowShopName === 'Y';
}
return result;
};
const _shopTopBannerBase = _shopTopBanner;
/**
* 基础模板
*/
exports.basisTemplateAsync = shopId => {
return co(function * () {
let data = { shopTopBanner_base: {}};
const ResourceHandler = {
shopTopBanner_base: _shopTopBannerBase
};
let shops = yield api.shopsDecoratorListAsync(shopId);
if (!shops.code || shops.code !== 200 || _.isEmpty(shops.data.list)) {
return data;
}
getShopBannerAsync(shopId) {
return this.api.shopBannerAsync(shopId).then((result) => {
shops.data.list.forEach(shop => {
let resourceHandlerName = shop.resource_name;
if (!ResourceHandler[resourceHandlerName]) {
return;
}
let resourceData = ResourceHandler[resourceHandlerName](_getResourceData(shop));
switch (resourceHandlerName) {
case 'shopTopBanner_base':
{
data[resourceHandlerName] = resourceData;
break;
}
default:
break;
}
});
return data;
})();
};
exports.getShopBannerAsync = (shopId) => {
return api.shopBannerAsync(shopId).then((result) => {
if (result.code === 200) {
return _.includes(result.data.banner, DEFAULT_IMG) ? '' : result.data.banner;
} else {
return null;
}
});
}
};
queryShopByBrandIdAsync(sid, bid) {
exports.queryShopByBrandIdAsync = (sid, bid) => {
return co(function * () {
let result = yield this.api.queryShopsByBrandId(sid, bid);
let result = yield api.queryShopsByBrandId(sid, bid);
if (_.get(result, 'code') !== 200) {
return false;
}
return _.get(result, 'data[0]', {});
}).bind(this)();
}
})();
};
... ...