Authored by 沈志敏

修改商品详情接口

@@ -31,10 +31,10 @@ const component = { @@ -31,10 +31,10 @@ const component = {
31 }); 31 });
32 }, 32 },
33 product(req, res, next) { 33 product(req, res, next) {
34 - const pid = req.params[0];// , goodsId = req.params[1]; 34 + const pid = req.params[0]; // , goodsId = req.params[1];
35 35
36 let params = { 36 let params = {
37 - productId: _.toString(pid), 37 + product_id: _.toString(pid),
38 uid: req.user.uid || 0 38 uid: req.user.uid || 0
39 }; 39 };
40 40
@@ -59,10 +59,10 @@ const component = { @@ -59,10 +59,10 @@ const component = {
59 */ 59 */
60 addToCart(req, res, next) { 60 addToCart(req, res, next) {
61 let params = { 61 let params = {
62 - product_sku: req.body.productSku, // 商品SKU  
63 - buy_number: req.body.buyNumber, // 购买数量  
64 - goods_type: req.body.goodsType || 0, // 商品类型,0表示普通商品,1表示加价购商品  
65 - edit_product_sku: req.body.isEdit || 0, // 是否是编辑商品SKU,0表示不是编辑 62 + product_sku: req.body.productSku, // 商品SKU
  63 + buy_number: req.body.buyNumber, // 购买数量
  64 + goods_type: req.body.goodsType || 0, // 商品类型,0表示普通商品,1表示加价购商品
  65 + edit_product_sku: req.body.isEdit || 0, // 是否是编辑商品SKU,0表示不是编辑
66 selected: 'Y', 66 selected: 'Y',
67 promotion_id: req.body.promotionId || null, // 促销id,默认null(加价购有关) 67 promotion_id: req.body.promotionId || null, // 促销id,默认null(加价购有关)
68 uid: req.user.uid || 0, 68 uid: req.user.uid || 0,
@@ -72,7 +72,9 @@ const component = { @@ -72,7 +72,9 @@ const component = {
72 model.addToCart(params).then(result => { 72 model.addToCart(params).then(result => {
73 if (result.code === 200) { 73 if (result.code === 200) {
74 // 将 shopping_key 写入Cookie 74 // 将 shopping_key 写入Cookie
75 - res.cookie('_SPK', result.data.shopping_key, {maxAge: 86400 * 360}); 75 + res.cookie('_SPK', result.data.shopping_key, {
  76 + maxAge: 86400 * 360
  77 + });
76 } 78 }
77 res.json(result); 79 res.json(result);
78 }).catch(next); 80 }).catch(next);
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 'use strict'; 6 'use strict';
7 7
8 const api = global.yoho.API; 8 const api = global.yoho.API;
  9 +const camelCase = global.yoho.camelCase;
9 10
10 /** 11 /**
11 * 商品详情 12 * 商品详情
@@ -13,26 +14,28 @@ const api = global.yoho.API; @@ -13,26 +14,28 @@ const api = global.yoho.API;
13 const model = { 14 const model = {
14 product(params) { 15 product(params) {
15 return api.get('', Object.assign({ 16 return api.get('', Object.assign({
16 - method: 'h5.product.data'  
17 - }, params))  
18 - .then(result => {  
19 - // result.storage 的 数值 不可靠,循环累加 库存  
20 - let storage = 0; 17 + method: 'app.product.data'
  18 + }, params), {
  19 + code: 200
  20 + }).then(result => {
  21 + if (result.data) {
  22 + let storage = 0; // result.storage 的 数值 不可靠,循环累加 库存
  23 + const goodsList = result.data.goods_list;
21 24
22 - if (result.goodsList) {  
23 - for (let good of result.goodsList) {  
24 - for (let size of good.goodsSizeBoList) {  
25 - storage += size.goodsSizeStorageNum; 25 + if (goodsList) {
  26 + for (let good of goodsList) {
  27 + for (let size of good.size_list) {
  28 + storage += size.storage_number;
26 } 29 }
27 } 30 }
28 } 31 }
29 32
30 - result.storage = storage;  
31 - return result;  
32 - });  
33 - },  
34 - 33 + result.data.storage = storage;
  34 + }
35 35
  36 + return result;
  37 + }).then(camelCase);
  38 + },
36 intro(params) { 39 intro(params) {
37 return api.get('', Object.assign({ 40 return api.get('', Object.assign({
38 method: 'h5.product.intro' 41 method: 'h5.product.intro'
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 </div> 6 </div>
7 <div class="text-box"> 7 <div class="text-box">
8 <h3 class="line-clamp-2">{{entity.productName}}</h3> 8 <h3 class="line-clamp-2">{{entity.productName}}</h3>
9 - <h4>{{entity.productPriceBo && entity.productPriceBo.formatSalesPrice}}</h4> 9 + <h4>{{entity.formatSalesPrice !== '0' ? entity.formatSalesPrice : entity.formatMarketPrice}}</h4>
10 </div> 10 </div>
11 </div> 11 </div>
12 12
@@ -239,13 +239,13 @@ @@ -239,13 +239,13 @@
239 thumbnails[goods.colorId] = goods.colorImage; 239 thumbnails[goods.colorId] = goods.colorImage;
240 240
241 // 生成colorId 与 size的 映射 241 // 生成colorId 与 size的 映射
242 - colorSizes[goods.colorId] = goods.goodsSizeBoList.map((size)=> { 242 + colorSizes[goods.colorId] = goods.sizeList.map((size)=> {
243 if (!stocks[goods.colorId]) { 243 if (!stocks[goods.colorId]) {
244 stocks[goods.colorId] = 0; 244 stocks[goods.colorId] = 0;
245 } 245 }
246 246
247 // 默认选中有库存的第一个颜色尺码 247 // 默认选中有库存的第一个颜色尺码
248 - if (size.goodsSizeStorageNum > 0) { 248 + if (size.storageNumber > 0) {
249 if (!selection.color) { 249 if (!selection.color) {
250 self.selection.color = selection.color = { 250 self.selection.color = selection.color = {
251 text: goods.colorName, 251 text: goods.colorName,
@@ -254,24 +254,24 @@ @@ -254,24 +254,24 @@
254 }; 254 };
255 } 255 }
256 256
257 - if (!selection.size && size.goodsSizeStorageNum > 0) { 257 + if (!selection.size && size.storageNumber > 0) {
258 self.selection.size = selection.size = { 258 self.selection.size = selection.size = {
259 text: size.sizeName, 259 text: size.sizeName,
260 - value: size.goodsSizeSkuId,  
261 - goodsId: size.goodsId, 260 + value: size.productSku,
  261 + goodsId: goods.goodsId,
262 disabled: false 262 disabled: false
263 }; 263 };
264 264
265 } 265 }
266 } 266 }
267 // 计算所有尺码的库存 267 // 计算所有尺码的库存
268 - stocks[goods.colorId] += size.goodsSizeStorageNum; 268 + stocks[goods.colorId] += size.storageNumber;
269 269
270 return { 270 return {
271 text: size.sizeName, 271 text: size.sizeName,
272 - value: size.goodsSizeSkuId,  
273 - disabled: size.goodsSizeStorageNum === 0,  
274 - goodsId: size.goodsId 272 + value: size.productSku,
  273 + disabled: size.storageNumber === 0,
  274 + goodsId: goods.goodsId
275 }; 275 };
276 }); 276 });
277 277
@@ -378,7 +378,7 @@ @@ -378,7 +378,7 @@
378 return; 378 return;
379 } 379 }
380 380
381 - const param = Object.assign({goodsId: this.entity.id}, this.selection); 381 + const param = Object.assign({goodsId: this.entity.productId}, this.selection);
382 382
383 this.onAddToCart(param, this); 383 this.onAddToCart(param, this);
384 }, 384 },
@@ -159,9 +159,8 @@ @@ -159,9 +159,8 @@
159 // 查询 商品 feature 159 // 查询 商品 feature
160 queryProductFeature(pid) { 160 queryProductFeature(pid) {
161 $.get(`/product/product_${pid}.json`).then(result => { 161 $.get(`/product/product_${pid}.json`).then(result => {
162 - this.entity = result; 162 + this.entity = result.data || {};
163 this.showFeatureSelector = true; 163 this.showFeatureSelector = true;
164 - return result;  
165 }); 164 });
166 }, 165 },
167 166
@@ -4,25 +4,25 @@ @@ -4,25 +4,25 @@
4 <image-carousel :goods="entity.goodsList"></image-carousel> 4 <image-carousel :goods="entity.goodsList"></image-carousel>
5 <div class="title-box"> 5 <div class="title-box">
6 <h1 class="line-clamp-2">{{entity.productName}}</h1> 6 <h1 class="line-clamp-2">{{entity.productName}}</h1>
7 - <i class="price" v-if="entity.productPriceBo.marketPrice > entity.productPriceBo.salesPrice"  
8 - :class="{'strike-through': entity.productPriceBo.salesPrice > 0}">{{entity.productPriceBo.formatMarketPrice}}</i> 7 + <i class="price" v-if="entity.marketPrice > entity.salesPrice"
  8 + :class="{'strike-through': entity.salesPrice > 0}">{{entity.formatMarketPrice}}</i>
9 9
10 - <i v-if="entity.productPriceBo.salesPrice > 0"  
11 - :class="{price: true, highlight: entity.productPriceBo.marketPrice > entity.productPriceBo.salesPrice}">  
12 - {{entity.productPriceBo.formatSalesPrice}} 10 + <i v-if="entity.salesPrice > 0"
  11 + :class="{price: true, highlight: entity.marketPrice > entity.salesPrice}">
  12 + {{entity.formatSalesPrice !== '0' ? entity.formatSalesPrice : entity.formatMarketPrice}}
13 </i> 13 </i>
14 </div> 14 </div>
15 </show-box> 15 </show-box>
16 16
17 - <show-box class="brand" v-if="entity.brand">  
18 - <img :src="entity.brand.brandIco | resize 110 68"/> 17 + <show-box class="brand" v-if="brand">
  18 + <img :src="brand.brandIco | resize 110 68"/>
19 19
20 - <h2>{{entity.brand.brandName}}</h2> 20 + <h2>{{brand.brandName}}</h2>
21 <div class="brand-go"> 21 <div class="brand-go">
22 <span>进入店铺</span> 22 <span>进入店铺</span>
23 <span class="icon icon-right"></span> 23 <span class="icon icon-right"></span>
24 </div> 24 </div>
25 - <a :href="entity.brand.brandDomain | brandUrl"></a> 25 + <a :href="brand.brandDomain | brandUrl"></a>
26 </show-box> 26 </show-box>
27 27
28 <show-box v-if="intro.productDescBo"> 28 <show-box v-if="intro.productDescBo">
@@ -153,10 +153,10 @@ @@ -153,10 +153,10 @@
153 <h2>商品详情</h2> 153 <h2>商品详情</h2>
154 <i>DETAILS</i> 154 <i>DETAILS</i>
155 155
156 - <p v-if="entity.brand && entity.brand.brandIntro" v-lazy-html="entity.brand.brandIntro"> 156 + <p v-if="brand && brand.brandIntro" v-lazy-html="brand.brandIntro">
157 </p> 157 </p>
158 158
159 - <p v-if="entity.brand && intro.productIntroBo" v-lazy-html="intro.productIntroBo.productIntro"> 159 + <p v-if="brand && intro.productIntroBo" v-lazy-html="intro.productIntroBo.productIntro">
160 </p> 160 </p>
161 161
162 </show-box> 162 </show-box>
@@ -412,11 +412,8 @@ @@ -412,11 +412,8 @@
412 yoho: yoho, 412 yoho: yoho,
413 intro: {}, 413 intro: {},
414 firstImage: '', 414 firstImage: '',
  415 + brand: null,
415 entity: { 416 entity: {
416 - brand: {  
417 - brandName: '',  
418 - brandIco: ''  
419 - },  
420 productPriceBo: { 417 productPriceBo: {
421 formatMarketPrice: '' 418 formatMarketPrice: ''
422 } 419 }
@@ -482,7 +479,7 @@ @@ -482,7 +479,7 @@
482 toggleFavorite: function() { 479 toggleFavorite: function() {
483 $.post('/product/favorite.json', { 480 $.post('/product/favorite.json', {
484 operation: this.entity.isCollect === 'Y' ? 'remove' : 'add', 481 operation: this.entity.isCollect === 'Y' ? 'remove' : 'add',
485 - id: this.entity.productPriceBo.productId 482 + id: this.entity.productId
486 }).then((result)=> { 483 }).then((result)=> {
487 if (result.code === 200) { 484 if (result.code === 200) {
488 tip(this.entity.isCollect === 'Y' ? '取消收藏成功' : '收藏成功'); 485 tip(this.entity.isCollect === 'Y' ? '取消收藏成功' : '收藏成功');
@@ -519,8 +516,11 @@ @@ -519,8 +516,11 @@
519 516
520 // 读取基础数据 517 // 读取基础数据
521 $.get(`/product/product_${pid}.json`).then((result) => { 518 $.get(`/product/product_${pid}.json`).then((result) => {
522 - // TODO: 异常处理  
523 - this.entity = result; 519 + if (!result.data) {
  520 + return;
  521 + }
  522 + this.entity = result.data;
  523 + this.brand = result.data.brandInfo;
524 524
525 if (this.entity.storage === 0 || this.entity.status === 0) { 525 if (this.entity.storage === 0 || this.entity.status === 0) {
526 this.isSoldOut = true; 526 this.isSoldOut = true;
@@ -549,12 +549,14 @@ @@ -549,12 +549,14 @@
549 }) 549 })
550 }); 550 });
551 551
552 - return result;  
553 - }).then((result)=> {  
554 - // 读取商品详情  
555 - $.get(`/product/product/intro_${pid}.json`, {skn: result.productPriceBo.productSkn}).then(intro => {  
556 - this.intro = intro;  
557 - }); 552 + return result.data;
  553 + }).then((data)=> {
  554 + if (data) {
  555 + // 读取商品详情
  556 + $.get(`/product/product/intro_${pid}.json`, {skn: data.productSkn}).then(intro => {
  557 + this.intro = intro;
  558 + });
  559 + }
558 }) 560 })
559 .always(() => { 561 .always(() => {
560 this.isReady = true; 562 this.isReady = true;