Authored by Rock Zhang

添加赠品和加价购页面

Code Review By Rock Zhang
... ... @@ -560,10 +560,9 @@ class Helpers
* 格式化购物车商品
*
* @param array $cartGoods 购物车商品列表
* @param bool $haveLink 控制是否需要商品链接
* @return array 处理之后的购物车商品数据
*/
public static function formatCartGoods($cartGoods, $haveLink = false)
public static function formatCartGoods($cartGoods)
{
$arr = array();
... ... @@ -580,19 +579,19 @@ class Helpers
$oneGoods['lowStocks'] = ($value['buy_number'] < $value['storage_number']);
//gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
if (!isset($value['goods_type'])) {
$oneGoods['soldOut'] = true;
$oneGoods['isSoldOut'] = true;
} elseif ($value['goods_type'] == 'gift') {
$oneGoods['gift'] = true;
$oneGoods['isGift'] = true;
} elseif ($value['goods_type'] == 'price_gift') {
$oneGoods['advanceBuy'] = true;
$oneGoods['isAdvanceBuy'] = true;
}
// 上市期
if (!empty($value['expect_arrival_time'])) {
$oneGoods['appearDate'] = $value['expect_arrival_time'];
}
// 商品链接
if ($haveLink && isset($value['product_id'])) {
$oneGoods['link'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html');
if (isset($value['cn_alphabet']) ) {
$oneGoods['url'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html');
}
$arr[$key] = $oneGoods;
... ...
... ... @@ -29,6 +29,7 @@ class ShoppingCartController extends AbstractAction
// 渲染模板
$this->_view->display('index', $data);
}
/*
* 异步获取购物车数据
*/
... ... @@ -135,6 +136,47 @@ class ShoppingCartController extends AbstractAction
}
/*
* 赠品页面
*/
public function giftAction()
{
$this->setTitle('赠品');
$this->setNavHeader('赠品');
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$data = array(
'shoppingCartPage' => true,
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey, true)
);
// 渲染模板
$this->_view->display('gift-advance-good', $data);
}
/*
* 加价购页面
*/
public function advanceBuyAction()
{
$this->setTitle('加价购');
$this->setNavHeader('加价购');
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$data = array(
'shoppingCartPage' => true,
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey, false, true)
);
print_r($data);
// 渲染模板
$this->_view->display('gift-advance-good', $data);
}
/*
* 获取购物车加价购商品数据
*/
public function giftinfoAction()
... ...
... ... @@ -43,9 +43,11 @@ class CartModel
/**
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @param bool $onlyGift 只获取赠品的商品数据
* @param bool $onlyAdvanceBuy 只获取加价购的商品数据
* @return array|mixed 处理之后的购物车数据
*/
public static function getCartData($uid, $shoppingKey)
public static function getCartData($uid, $shoppingKey, $onlyGift = false, $onlyAdvanceBuy = false)
{
$result = array('cartNav' => true);
... ... @@ -64,13 +66,13 @@ class CartModel
/* 普通购物车 */
if(isset($cart['ordinary_cart_data'])) {
$result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count'];
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data']);
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
}
/* 预售购物车 */
if(isset($cart['advance_cart_data'])) {
$result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count'];
$result['preSellCart'] = self::procCartData($cart['advance_cart_data']);
$result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
}
}
... ... @@ -601,31 +603,44 @@ class CartModel
* 处理不同类型的购物车数据
*
* @param array $data 不同类型购物车数据
* @param bool $onlyGift 只获取赠品的商品数据
* @param bool $onlyAdvanceBuy 只获取加价购的商品数据
* @return array $result 处理之后的不同类型购物车数据
*/
private static function procCartData($data)
private static function procCartData($data, $onlyGift = false, $onlyAdvanceBuy = false)
{
$result = array();
// 购买的可用商品列表
$validGoods = Helpers::formatCartGoods($data['goods_list']);
!empty($validGoods) && $result['goods'] = $validGoods;
// 失效商品列表
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
// 赠品
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
$result['freebie'] = $data['gift_list'];
// 加价购
$result['advanceBuyCount'] = 0;
$result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
// 结算数据
$result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
$result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']);
$result['count'] = $data['shopping_cart_data']['goods_count'];
$result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
if (!$onlyAdvanceBuy) {
// 赠品
$result['giftCount'] = 0;
$result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $result['giftCount']);
}
if (!$onlyGift) {
// 加价购
$result['advanceBuyCount'] = 0;
$result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
}
if (!$onlyGift && !$onlyAdvanceBuy) {
// 购买的可用商品列表
$validGoods = Helpers::formatCartGoods($data['goods_list']);
!empty($validGoods) && $result['goods'] = $validGoods;
// 失效商品列表
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
// 赠品和加价购商品
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
// 结算数据
$result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
$result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']);
$result['count'] = $data['shopping_cart_data']['goods_count'];
$result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
}
return $result;
}
... ...