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