|
|
<?php
|
|
|
|
|
|
namespace Index;
|
|
|
|
|
|
use LibModels\Wap\Home\CartData;
|
|
|
use Plugin\Images;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @name CartModel
|
|
|
* @package models/Index
|
|
|
* @copyright yoho.inc
|
|
|
* @version 1.0 (2015-11-09 14:05:09)
|
|
|
* @author Gtskk (tttt6399998@126.com)
|
|
|
*/
|
|
|
class CartModel
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* @param integer $uid 用户ID
|
|
|
* @return array|mixed 处理之后的购物车数据
|
|
|
*/
|
|
|
public static function getCartData($uid)
|
|
|
{
|
|
|
$result = array(
|
|
|
'cartNav' => true,
|
|
|
'showLoginInfo' => true
|
|
|
);
|
|
|
|
|
|
// 调用接口获取购物车的数据
|
|
|
$cartData = CartData::cartData($uid);
|
|
|
|
|
|
// 处理普通购物车和预售购物车的数据
|
|
|
/* 普通购物车 */
|
|
|
if (isset($cartData['data']) && !empty($cartData['data'])) {
|
|
|
$cart = $cartData['data'];
|
|
|
|
|
|
/* 普通购物车 */
|
|
|
if(isset($cart['ordinary_cart_data'])) {
|
|
|
$result['commonGoodsCount'] = count($cart['ordinary_cart_data']['goods_list']);
|
|
|
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data']);
|
|
|
}
|
|
|
|
|
|
/* 预售购物车 */
|
|
|
if(isset($cart['advance_cart_data'])) {
|
|
|
$result['presellGoodsCount'] = count($cart['advance_cart_data']['goods_list']);
|
|
|
$result['preSellCart'] = self::procCartData($cart['advance_cart_data']);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 处理不同类型的购物车数据
|
|
|
*
|
|
|
* @param array $data 不同类型购物车数据
|
|
|
* @return array $result 处理之后的不同类型购物车数据
|
|
|
*/
|
|
|
private static function procCartData($data)
|
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
$oneGoods = array();
|
|
|
// 购买的商品列表
|
|
|
foreach ($data['goods_list'] as $value) {
|
|
|
$oneGoods['id'] = $value['product_id'];
|
|
|
$oneGoods['name'] = $value['product_name'];
|
|
|
$oneGoods['thumb'] = Images::getImageUrl($value['goods_images'], 120, 120);
|
|
|
$oneGoods['color'] = $value['color_name'];
|
|
|
$oneGoods['size'] = $value['size_name'];
|
|
|
$oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据
|
|
|
$oneGoods['price'] = $value['real_price'];
|
|
|
$oneGoods['count'] = $value['buy_number'];
|
|
|
$oneGoods['lowStocks'] = true;
|
|
|
|
|
|
$result['goods'][] = $oneGoods;
|
|
|
}
|
|
|
// 赠品
|
|
|
count($data['gift_list']) && $result['freebieOrAdvanceBuy'] = true;
|
|
|
$result['freebie'] = $data['gift_list'];
|
|
|
// 加价购
|
|
|
$result['advanceBuy'] = $data['price_gift'];
|
|
|
// 结算数据
|
|
|
$result['price'] = $data['shopping_cart_data']['order_amount'];
|
|
|
$result['activityPrice'] = $data['shopping_cart_data']['discount_amount'];
|
|
|
$result['count'] = $data['shopping_cart_data']['goods_count'];
|
|
|
$result['sumPrice'] = $data['shopping_cart_data']['order_amount'];
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|