Authored by 沈志敏

修改商品详情接口

... ... @@ -31,10 +31,10 @@ const component = {
});
},
product(req, res, next) {
const pid = req.params[0];// , goodsId = req.params[1];
const pid = req.params[0]; // , goodsId = req.params[1];
let params = {
productId: _.toString(pid),
product_id: _.toString(pid),
uid: req.user.uid || 0
};
... ... @@ -59,10 +59,10 @@ const component = {
*/
addToCart(req, res, next) {
let params = {
product_sku: req.body.productSku, // 商品SKU
buy_number: req.body.buyNumber, // 购买数量
goods_type: req.body.goodsType || 0, // 商品类型,0表示普通商品,1表示加价购商品
edit_product_sku: req.body.isEdit || 0, // 是否是编辑商品SKU,0表示不是编辑
product_sku: req.body.productSku, // 商品SKU
buy_number: req.body.buyNumber, // 购买数量
goods_type: req.body.goodsType || 0, // 商品类型,0表示普通商品,1表示加价购商品
edit_product_sku: req.body.isEdit || 0, // 是否是编辑商品SKU,0表示不是编辑
selected: 'Y',
promotion_id: req.body.promotionId || null, // 促销id,默认null(加价购有关)
uid: req.user.uid || 0,
... ... @@ -72,7 +72,9 @@ const component = {
model.addToCart(params).then(result => {
if (result.code === 200) {
// 将 shopping_key 写入Cookie
res.cookie('_SPK', result.data.shopping_key, {maxAge: 86400 * 360});
res.cookie('_SPK', result.data.shopping_key, {
maxAge: 86400 * 360
});
}
res.json(result);
}).catch(next);
... ...
... ... @@ -6,6 +6,7 @@
'use strict';
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
/**
* 商品详情
... ... @@ -13,26 +14,28 @@ const api = global.yoho.API;
const model = {
product(params) {
return api.get('', Object.assign({
method: 'h5.product.data'
}, params))
.then(result => {
// result.storage 的 数值 不可靠,循环累加 库存
let storage = 0;
method: 'app.product.data'
}, params), {
code: 200
}).then(result => {
if (result.data) {
let storage = 0; // result.storage 的 数值 不可靠,循环累加 库存
const goodsList = result.data.goods_list;
if (result.goodsList) {
for (let good of result.goodsList) {
for (let size of good.goodsSizeBoList) {
storage += size.goodsSizeStorageNum;
if (goodsList) {
for (let good of goodsList) {
for (let size of good.size_list) {
storage += size.storage_number;
}
}
}
result.storage = storage;
return result;
});
},
result.data.storage = storage;
}
return result;
}).then(camelCase);
},
intro(params) {
return api.get('', Object.assign({
method: 'h5.product.intro'
... ...
... ... @@ -6,7 +6,7 @@
</div>
<div class="text-box">
<h3 class="line-clamp-2">{{entity.productName}}</h3>
<h4>{{entity.productPriceBo && entity.productPriceBo.formatSalesPrice}}</h4>
<h4>{{entity.formatSalesPrice !== '0' ? entity.formatSalesPrice : entity.formatMarketPrice}}</h4>
</div>
</div>
... ... @@ -239,13 +239,13 @@
thumbnails[goods.colorId] = goods.colorImage;
// 生成colorId 与 size的 映射
colorSizes[goods.colorId] = goods.goodsSizeBoList.map((size)=> {
colorSizes[goods.colorId] = goods.sizeList.map((size)=> {
if (!stocks[goods.colorId]) {
stocks[goods.colorId] = 0;
}
// 默认选中有库存的第一个颜色尺码
if (size.goodsSizeStorageNum > 0) {
if (size.storageNumber > 0) {
if (!selection.color) {
self.selection.color = selection.color = {
text: goods.colorName,
... ... @@ -254,24 +254,24 @@
};
}
if (!selection.size && size.goodsSizeStorageNum > 0) {
if (!selection.size && size.storageNumber > 0) {
self.selection.size = selection.size = {
text: size.sizeName,
value: size.goodsSizeSkuId,
goodsId: size.goodsId,
value: size.productSku,
goodsId: goods.goodsId,
disabled: false
};
}
}
// 计算所有尺码的库存
stocks[goods.colorId] += size.goodsSizeStorageNum;
stocks[goods.colorId] += size.storageNumber;
return {
text: size.sizeName,
value: size.goodsSizeSkuId,
disabled: size.goodsSizeStorageNum === 0,
goodsId: size.goodsId
value: size.productSku,
disabled: size.storageNumber === 0,
goodsId: goods.goodsId
};
});
... ... @@ -378,7 +378,7 @@
return;
}
const param = Object.assign({goodsId: this.entity.id}, this.selection);
const param = Object.assign({goodsId: this.entity.productId}, this.selection);
this.onAddToCart(param, this);
},
... ...
... ... @@ -159,9 +159,8 @@
// 查询 商品 feature
queryProductFeature(pid) {
$.get(`/product/product_${pid}.json`).then(result => {
this.entity = result;
this.entity = result.data || {};
this.showFeatureSelector = true;
return result;
});
},
... ...
... ... @@ -4,25 +4,25 @@
<image-carousel :goods="entity.goodsList"></image-carousel>
<div class="title-box">
<h1 class="line-clamp-2">{{entity.productName}}</h1>
<i class="price" v-if="entity.productPriceBo.marketPrice > entity.productPriceBo.salesPrice"
:class="{'strike-through': entity.productPriceBo.salesPrice > 0}">{{entity.productPriceBo.formatMarketPrice}}</i>
<i class="price" v-if="entity.marketPrice > entity.salesPrice"
:class="{'strike-through': entity.salesPrice > 0}">{{entity.formatMarketPrice}}</i>
<i v-if="entity.productPriceBo.salesPrice > 0"
:class="{price: true, highlight: entity.productPriceBo.marketPrice > entity.productPriceBo.salesPrice}">
{{entity.productPriceBo.formatSalesPrice}}
<i v-if="entity.salesPrice > 0"
:class="{price: true, highlight: entity.marketPrice > entity.salesPrice}">
{{entity.formatSalesPrice !== '0' ? entity.formatSalesPrice : entity.formatMarketPrice}}
</i>
</div>
</show-box>
<show-box class="brand" v-if="entity.brand">
<img :src="entity.brand.brandIco | resize 110 68"/>
<show-box class="brand" v-if="brand">
<img :src="brand.brandIco | resize 110 68"/>
<h2>{{entity.brand.brandName}}</h2>
<h2>{{brand.brandName}}</h2>
<div class="brand-go">
<span>进入店铺</span>
<span class="icon icon-right"></span>
</div>
<a :href="entity.brand.brandDomain | brandUrl"></a>
<a :href="brand.brandDomain | brandUrl"></a>
</show-box>
<show-box v-if="intro.productDescBo">
... ... @@ -153,10 +153,10 @@
<h2>商品详情</h2>
<i>DETAILS</i>
<p v-if="entity.brand && entity.brand.brandIntro" v-lazy-html="entity.brand.brandIntro">
<p v-if="brand && brand.brandIntro" v-lazy-html="brand.brandIntro">
</p>
<p v-if="entity.brand && intro.productIntroBo" v-lazy-html="intro.productIntroBo.productIntro">
<p v-if="brand && intro.productIntroBo" v-lazy-html="intro.productIntroBo.productIntro">
</p>
</show-box>
... ... @@ -412,11 +412,8 @@
yoho: yoho,
intro: {},
firstImage: '',
brand: null,
entity: {
brand: {
brandName: '',
brandIco: ''
},
productPriceBo: {
formatMarketPrice: ''
}
... ... @@ -482,7 +479,7 @@
toggleFavorite: function() {
$.post('/product/favorite.json', {
operation: this.entity.isCollect === 'Y' ? 'remove' : 'add',
id: this.entity.productPriceBo.productId
id: this.entity.productId
}).then((result)=> {
if (result.code === 200) {
tip(this.entity.isCollect === 'Y' ? '取消收藏成功' : '收藏成功');
... ... @@ -519,8 +516,11 @@
// 读取基础数据
$.get(`/product/product_${pid}.json`).then((result) => {
// TODO: 异常处理
this.entity = result;
if (!result.data) {
return;
}
this.entity = result.data;
this.brand = result.data.brandInfo;
if (this.entity.storage === 0 || this.entity.status === 0) {
this.isSoldOut = true;
... ... @@ -549,12 +549,14 @@
})
});
return result;
}).then((result)=> {
// 读取商品详情
$.get(`/product/product/intro_${pid}.json`, {skn: result.productPriceBo.productSkn}).then(intro => {
this.intro = intro;
});
return result.data;
}).then((data)=> {
if (data) {
// 读取商品详情
$.get(`/product/product/intro_${pid}.json`, {skn: data.productSkn}).then(intro => {
this.intro = intro;
});
}
})
.always(() => {
this.isReady = true;
... ...