...
|
...
|
@@ -4,95 +4,103 @@ |
|
|
'use strict';
|
|
|
const utils = '../../../utils';
|
|
|
const _ = require('lodash');
|
|
|
const api = global.yoho.API;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
|
|
|
/**
|
|
|
* 从接口获取套装数据
|
|
|
* @private
|
|
|
*/
|
|
|
const getBundleBySkn = (productSkn) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.query.bundleSkn',
|
|
|
product_skn: productSkn
|
|
|
}, {cache: false}).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 套装详情页数据
|
|
|
* @param params
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const detail = (params, isApp) => {
|
|
|
if (!params.skn && !params.bundle_skn) {
|
|
|
return Promise.resolve({});
|
|
|
class bundleModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
let bundleIndex = (params.index || 1);
|
|
|
|
|
|
--bundleIndex;
|
|
|
return getBundleBySkn(params.skn || params.bundle_skn).then(result => {
|
|
|
if (_.has(result, `data[${bundleIndex}]`)) {
|
|
|
let shareInfo = _.get(result, 'data[0].shareInfo', {});
|
|
|
|
|
|
return {
|
|
|
bundleDatas: _.map(result.data, (bundle, index) => {
|
|
|
let query = {bundle_skn: params.skn ||
|
|
|
params.bundle_skn, productId: params.productId, index: index + 1};
|
|
|
/**
|
|
|
* 从接口获取套装数据
|
|
|
* @private
|
|
|
*/
|
|
|
getBundleBySkn(productSkn) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.query.bundleSkn',
|
|
|
product_skn: productSkn
|
|
|
},
|
|
|
param: {cache: false}
|
|
|
}).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (isApp) {
|
|
|
query.app_version = isApp;
|
|
|
}
|
|
|
return {
|
|
|
selected: index === bundleIndex,
|
|
|
title: _.get(bundle, 'bundleInfo.tabName') || '',
|
|
|
href: helpers.urlFormat('/product/bundle/detail', query),
|
|
|
};
|
|
|
}),
|
|
|
shareInfo: {
|
|
|
imgUrl: `http:${helpers.image(shareInfo.imgUrl, 300, 300)}`,
|
|
|
subTitle: encodeURIComponent(shareInfo.subTitle),
|
|
|
title: encodeURIComponent(shareInfo.title),
|
|
|
url: shareInfo.url
|
|
|
},
|
|
|
bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
|
|
|
productList: productProcess.processProductList(_.get(result, `data[${bundleIndex}].productList`, []))
|
|
|
};
|
|
|
/**
|
|
|
* 套装详情页数据
|
|
|
* @param params
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
detail(params, isApp) {
|
|
|
if (!params.skn && !params.bundle_skn) {
|
|
|
return Promise.resolve({});
|
|
|
}
|
|
|
return {};
|
|
|
});
|
|
|
};
|
|
|
let bundleIndex = (params.index || 1);
|
|
|
|
|
|
/**
|
|
|
* 套餐加入购物车
|
|
|
* @param {*} params
|
|
|
*/
|
|
|
const addToCart = (params) => {
|
|
|
let skuList = params.product_sku_list;
|
|
|
let finalParams = {
|
|
|
method: 'app.Shopping.addBundle',
|
|
|
shopping_key: params.shopping_key,
|
|
|
activity_id: params.activity_id,
|
|
|
product_sku_list: skuList
|
|
|
};
|
|
|
--bundleIndex;
|
|
|
return this.getBundleBySkn(params.skn || params.bundle_skn).then(result => {
|
|
|
if (_.has(result, `data[${bundleIndex}]`)) {
|
|
|
let shareInfo = _.get(result, 'data[0].shareInfo', {});
|
|
|
|
|
|
if (params.uid) {
|
|
|
Object.assign(finalParams, {
|
|
|
uid: params.uid
|
|
|
return {
|
|
|
bundleDatas: _.map(result.data, (bundle, index) => {
|
|
|
let query = {bundle_skn: params.skn ||
|
|
|
params.bundle_skn, productId: params.productId, index: index + 1};
|
|
|
|
|
|
if (isApp) {
|
|
|
query.app_version = isApp;
|
|
|
}
|
|
|
return {
|
|
|
selected: index === bundleIndex,
|
|
|
title: _.get(bundle, 'bundleInfo.tabName') || '',
|
|
|
href: helpers.urlFormat('/product/bundle/detail', query),
|
|
|
};
|
|
|
}),
|
|
|
shareInfo: {
|
|
|
imgUrl: `http:${helpers.image(shareInfo.imgUrl, 300, 300)}`,
|
|
|
subTitle: encodeURIComponent(shareInfo.subTitle),
|
|
|
title: encodeURIComponent(shareInfo.title),
|
|
|
url: shareInfo.url
|
|
|
},
|
|
|
bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
|
|
|
productList: productProcess.processProductList(
|
|
|
_.get(result, `data[${bundleIndex}].productList`, []))
|
|
|
};
|
|
|
}
|
|
|
return {};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return api.post('', finalParams, {
|
|
|
headers: {
|
|
|
'User-Agent': params.userAgent
|
|
|
/**
|
|
|
* 套餐加入购物车
|
|
|
* @param {*} params
|
|
|
*/
|
|
|
addToCart(params) {
|
|
|
let skuList = params.product_sku_list;
|
|
|
let finalParams = {
|
|
|
method: 'app.Shopping.addBundle',
|
|
|
shopping_key: params.shopping_key,
|
|
|
activity_id: params.activity_id,
|
|
|
product_sku_list: skuList
|
|
|
};
|
|
|
|
|
|
if (params.uid) {
|
|
|
Object.assign(finalParams, {
|
|
|
uid: params.uid
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getBundleBySkn,
|
|
|
detail,
|
|
|
addToCart
|
|
|
}; |
|
|
return this.post({
|
|
|
data: finalParams,
|
|
|
param: {
|
|
|
headers: {
|
|
|
'User-Agent': params.userAgent
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = bundleModel; |
...
|
...
|
|