Authored by Rock Zhang

添加购物车首页的逻辑

<?php
namespace LibModels\Wap\Home;
use Api\Sign;
use Api\Yohobuy;
/**
* 购物车的数据模型
*
* @name CartData
* @package LibModels/Wap/Home
* @copyright yoho.inc
* @version 1.0 (2015-11-09 13:58:27)
* @author Gtskk <tttt6399998@126.com>
*/
class CartData
{
/**
* 购物车数据
*
* @return array 购物车接口返回的数据
*/
public static function cartData($uid)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.cart';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -9,80 +9,16 @@ class ShoppingCartController extends AbstractAction
{
public function indexAction()
{
$this->setTitle('购物车');
$this->setNavHeader('购物车');
$data = array(
'cartNav' => true,
'commonGoodsCount' => 2,
'presellGoodsCount' => 2,
'showLoginInfo' => true,
'commonCart' => array(
'goods' => array(
array(
'id' => 1,
'name' => '黄伟文Wyman X y yohood 联名商品YYYOHOOD圆领卫衣',
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
'color' => '黄色',
'size' => 'F',
'appearDate' => '12月',
'price' => 399.00,
'count' => 8,
'lowStocks' => true
),
array(
'id' => 2,
'name' => 'TYAKSHA圣诞树凭借三角领蓝色白条毛衣',
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/03/10/01bc1878f9154e77ac4f7a6003c954f1b8.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'color' => '黄色',
'size' => 'F',
'price' => 553.00,
'count' => 1,
'soldOut' => true
)
),
'freebieOrAdvanceBuy' => true,
'freebie' => array(
'url' => '',
'count' => 2
),
'advanceBuy' => array(
'url' => '',
'count' => 3
),
'price' => 3192,
'activityPrice' => 0,
'count' => 8,
'sumPrice' => 3192
),
'preSellCart' => array(
'goods' => array(
array(
'id' => 2,
'name' => 'TYAKSHA圣诞树凭借三角领蓝色白条毛衣',
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/03/10/01bc1878f9154e77ac4f7a6003c954f1b8.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'color' => '黄色',
'size' => 'F',
'price' => 553.00,
'count' => 1,
'soldOut' => true
)
),
'freebieOrAdvanceBuy' => true,
'freebie' => array(
'url' => '',
'count' => 2
),
'advanceBuy' => array(
'url' => '',
'count' => 3
),
'price' => 553,
'activityPrice' => 0,
'count' => 1,
'sumPrice' => 553
)
'shoppingCartPage' => true,
'shoppingCart' => \Index\CartModel::getCartData(967016)
);
// 渲染模板
$this->_view->display('index', array('shoppingCartPage' => true, 'pageHeader' => array(
'navBack' => 'http://m.yohobuy.com', 'navTitle' => '购物车'), 'shoppingCart' => $data));
$this->_view->display('index', $data);
}
public function giftAdvanceAction()
... ...
<?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;
}
}
... ...