...
|
...
|
@@ -4,36 +4,43 @@ |
|
|
'use strict';
|
|
|
const utils = '../../../utils';
|
|
|
const _ = require('lodash');
|
|
|
const api = global.yoho.API;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
|
|
|
/**
|
|
|
class bundleModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从接口获取套装数据
|
|
|
* @private
|
|
|
*/
|
|
|
const getBundleBySkn = (productSkn) => {
|
|
|
return api.get('', {
|
|
|
getBundleBySkn(productSkn) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.query.bundleSkn',
|
|
|
product_skn: productSkn
|
|
|
}, {cache: false}).then(result => {
|
|
|
},
|
|
|
param: {cache: false}
|
|
|
}).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 套装详情页数据
|
|
|
* @param params
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const detail = (params, isApp) => {
|
|
|
detail(params, isApp) {
|
|
|
if (!params.skn && !params.bundle_skn) {
|
|
|
return Promise.resolve({});
|
|
|
}
|
|
|
let bundleIndex = (params.index || 1);
|
|
|
|
|
|
--bundleIndex;
|
|
|
return getBundleBySkn(params.skn || params.bundle_skn).then(result => {
|
|
|
return this.getBundleBySkn(params.skn || params.bundle_skn).then(result => {
|
|
|
if (_.has(result, `data[${bundleIndex}]`)) {
|
|
|
let shareInfo = _.get(result, 'data[0].shareInfo', {});
|
|
|
|
...
|
...
|
@@ -58,18 +65,19 @@ const detail = (params, isApp) => { |
|
|
url: shareInfo.url
|
|
|
},
|
|
|
bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
|
|
|
productList: productProcess.processProductList(_.get(result, `data[${bundleIndex}].productList`, []))
|
|
|
productList: productProcess.processProductList(
|
|
|
_.get(result, `data[${bundleIndex}].productList`, []))
|
|
|
};
|
|
|
}
|
|
|
return {};
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 套餐加入购物车
|
|
|
* @param {*} params
|
|
|
*/
|
|
|
const addToCart = (params) => {
|
|
|
addToCart(params) {
|
|
|
let skuList = params.product_sku_list;
|
|
|
let finalParams = {
|
|
|
method: 'app.Shopping.addBundle',
|
...
|
...
|
@@ -84,15 +92,15 @@ const addToCart = (params) => { |
|
|
});
|
|
|
}
|
|
|
|
|
|
return api.post('', finalParams, {
|
|
|
return this.post({
|
|
|
data: finalParams,
|
|
|
param: {
|
|
|
headers: {
|
|
|
'User-Agent': params.userAgent
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
|
getBundleBySkn,
|
|
|
detail,
|
|
|
addToCart
|
|
|
}; |
|
|
module.exports = bundleModel; |
...
|
...
|
|