Authored by Rock Zhang

提取出购物车商品、加价购商品以及赠品详情的处理逻辑

@@ -189,50 +189,7 @@ class CartModel @@ -189,50 +189,7 @@ class CartModel
189 $product = CartData::cartProductData($uid, $skn); 189 $product = CartData::cartProductData($uid, $skn);
190 if (isset($product['code']) && $product['code'] === 200) { 190 if (isset($product['code']) && $product['code'] === 200) {
191 $result['code'] = 200; 191 $result['code'] = 200;
192 - $data = array();  
193 - $productData = $product['data'];  
194 -  
195 - // 品牌信息  
196 - if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {  
197 - $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);  
198 - }  
199 -  
200 - $data['name'] = $productData['product_name'];  
201 - $data['price'] = $productData['market_price'];  
202 - $data['salePrice'] = $productData['sales_price'];  
203 - $data['storage'] = $productData['storage_sum'];  
204 - $data['num'] = $num;  
205 -  
206 - // 商品选择  
207 - if (isset($productData['goods_list'])) {  
208 - $goodsList = $productData['goods_list'];  
209 -  
210 - $colors = array();  
211 - $oneColor = array();  
212 - $sizes = array();  
213 - $oneSize = array();  
214 - foreach ($goodsList as $val) {  
215 - // 颜色  
216 - $oneColor = array();  
217 - $oneColor['id'] = $val['color_id'];  
218 - $oneColor['name'] = $val['color_name'];  
219 -  
220 - // 尺码  
221 - foreach ($val['size_list'] as $one) {  
222 - $oneSize = array();  
223 - $oneSize['id'] = $one['size_id'];  
224 - $oneSize['name'] = $one['size_name'];  
225 - }  
226 - $sizes[] = $oneSize;  
227 -  
228 - $oneColor['sizes'] = $sizes;  
229 - $colors[] = $oneColor;  
230 - }  
231 -  
232 - $data['colors'] = $colors;  
233 - }  
234 -  
235 - $result['data'] = $data; 192 + $result['data'] = self::procGoodsDetail($product['data']);
236 } 193 }
237 194
238 return $result; 195 return $result;
@@ -252,49 +209,7 @@ class CartModel @@ -252,49 +209,7 @@ class CartModel
252 $product = CartData::giftProductData($skn, $promotionId); 209 $product = CartData::giftProductData($skn, $promotionId);
253 if (isset($product['code']) && $product['code'] === 200) { 210 if (isset($product['code']) && $product['code'] === 200) {
254 $result['code'] = 200; 211 $result['code'] = 200;
255 - $data = array();  
256 - $productData = $product['data'];  
257 -  
258 - // 品牌信息  
259 - if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {  
260 - $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);  
261 - }  
262 -  
263 - $data['name'] = $productData['product_name'];  
264 - $data['price'] = $productData['market_price'];  
265 - $data['salePrice'] = $productData['sales_price'];  
266 - $data['storage'] = $productData['storage_sum'];  
267 -  
268 - // 商品选择  
269 - if (isset($productData['goods_list'])) {  
270 - $goodsList = $productData['goods_list'];  
271 -  
272 - $colors = array();  
273 - $oneColor = array();  
274 - $sizes = array();  
275 - $oneSize = array();  
276 - foreach ($goodsList as $val) {  
277 - // 颜色  
278 - $oneColor = array();  
279 - $oneColor['id'] = $val['color_id'];  
280 - $oneColor['name'] = $val['color_name'];  
281 -  
282 - // 尺码  
283 - foreach ($val['size_list'] as $one) {  
284 - $oneSize = array();  
285 - $oneSize['id'] = $one['size_id'];  
286 - $oneSize['name'] = $one['size_name'];  
287 - }  
288 - $sizes[] = $oneSize;  
289 -  
290 - $oneColor['sizes'] = $sizes;  
291 - $colors[] = $oneColor;  
292 - }  
293 -  
294 - $data['colors'] = $colors;  
295 - }  
296 -  
297 - $result['data'] = $data; 212 + $result['data'] = self::procGoodsDetail($product['data']);
298 } 213 }
299 214
300 return $result; 215 return $result;
@@ -657,6 +572,59 @@ class CartModel @@ -657,6 +572,59 @@ class CartModel
657 572
658 573
659 /** 574 /**
  575 + * 处理购物车商品、加价购商品、赠品详情数据
  576 + *
  577 + * @param array $productData 要处理的商品数据
  578 + * @return array $data 处理之后的数据
  579 + */
  580 + private static function procGoodsDetail($productData)
  581 + {
  582 + $data = array();
  583 +
  584 + // 品牌信息
  585 + if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {
  586 + $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);
  587 + }
  588 +
  589 + $data['name'] = $productData['product_name'];
  590 + $data['price'] = $productData['market_price'];
  591 + $data['salePrice'] = $productData['sales_price'];
  592 + $data['storage'] = $productData['storage_sum'];
  593 + $data['num'] = $num;
  594 +
  595 + // 商品选择
  596 + if (isset($productData['goods_list'])) {
  597 + $goodsList = $productData['goods_list'];
  598 +
  599 + $colors = array();
  600 + $oneColor = array();
  601 + $sizes = array();
  602 + $oneSize = array();
  603 + foreach ($goodsList as $val) {
  604 + // 颜色
  605 + $oneColor = array();
  606 + $oneColor['id'] = $val['color_id'];
  607 + $oneColor['name'] = $val['color_name'];
  608 +
  609 + // 尺码
  610 + foreach ($val['size_list'] as $one) {
  611 + $oneSize = array();
  612 + $oneSize['id'] = $one['size_id'];
  613 + $oneSize['name'] = $one['size_name'];
  614 + }
  615 + $sizes[] = $oneSize;
  616 +
  617 + $oneColor['sizes'] = $sizes;
  618 + $colors[] = $oneColor;
  619 + }
  620 +
  621 + $data['colors'] = $colors;
  622 + }
  623 +
  624 + return $data;
  625 + }
  626 +
  627 + /**
660 * 处理不同类型的购物车数据 628 * 处理不同类型的购物车数据
661 * 629 *
662 * @param array $data 不同类型购物车数据 630 * @param array $data 不同类型购物车数据