Authored by Lynnic

Merge branch 'feature/cart' of git.dev.yoho.cn:web/yohobuy into feature/cart

framework @ e9d066dd
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
... ...
... ... @@ -48,6 +48,32 @@ class CartData
}
/**
* 购物车商品选择与取消接口
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 购物车接口返回的数据
*/
public static function selectGoods($uid, $sku, $shoppingKey)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.selected';
$param['product_sku_list'] = $sku;
if (!empty($uid)) {
$param['uid'] = $uid;
}
if (!empty($shoppingKey)) {
$param['shopping_key'] = $shoppingKey;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 购物车数据
*
* @param int $uid 用户ID
... ...
... ... @@ -556,6 +556,86 @@ class Helpers
}
/**
* 格式化购物车商品
*
* @param array $cartGoods 购物车商品列表
* @param bool $haveLink 控制是否需要商品链接
*/
public static function formatCartGoods($cartGoods, $haveLink = false)
{
$arr = array();
$oneGoods = array();
foreach ($cartGoods as $key => $value) {
$oneGoods['id'] = $value['product_sku'];
$oneGoods['skn'] = $value['product_skn'];
$oneGoods['name'] = $value['product_name'];
$oneGoods['thumb'] = !empty($value['goods_images']) ? 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'] = ($value['buy_number'] < $value['storage_number']);
//gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
if (!isset($value['goods_type'])) {
$oneGoods['soldOut'] = true;
} elseif ($value['goods_type'] == 'gift') {
$oneGoods['gift'] = true;
} elseif ($value['goods_type'] == 'price_gift') {
$oneGoods['advanceBuy'] = 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');
}
$arr[$key] = $oneGoods;
}
return $arr;
}
/**
* 格式化加价购商品
*
* @param array $advanceGoods 加价购商品列表
* @param bool $haveLink 控制是否需要商品链接
*/
public static function formatAdvanceGoods($advanceGoods)
{
$arr = array();
$gift = array();
$oneGoods = array();
foreach ($advanceGoods as $value) {
$gift = array();
$gift['promotionTitle'] = $value['promotion_title'];
foreach ($value['goods_list'] as $single) {
$oneGoods['id'] = $single['product_skn'];
$oneGoods['name'] = $single['product_name'];
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 120) : '';
$oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据
$oneGoods['price'] = $single['last_price'];
$oneGoods['marketPrice'] = $single['market_price'];
$oneGoods['count'] = $single['storage_number'];
$gift['goods'][] = $oneGoods;
}
$arr[] = $gift;
}
return $arr;
}
/**
* 订单状态,按订单支付类型和订单状态
* @var array
*/
... ...
.shopping-cart-good {
$cartRed: #d0253b;
position: relative;
padding-left: 16rem / $pxConvertRem;
... ... @@ -16,24 +17,28 @@
.info {
float: left;
margin-left: 50rem / $pxConvertRem;
margin-left: 30rem / $pxConvertRem;
padding: 16rem / $pxConvertRem 0;
border-bottom: 1px solid #e0e0e0;
padding-right: 20rem / $pxConvertRem;
}
.thumb {
float: left;
width: 120rem / $pxConvertRem;
height: 160rem / $pxConvertRem;
width: 180rem / $pxConvertRem;
height: 200rem / $pxConvertRem;
background-size: 100%;
background-repeat: no-repeat;
}
.deps {
margin-left: 135rem / $pxConvertRem;
padding-right: 20rem / $pxConvertRem;
margin-left: 173rem / $pxConvertRem;
padding-bottom: 60rem / $pxConvertRem;
border-bottom: 1px solid #e0e0e0;
}
.name {
font-size: 28rem / $pxConvertRem;
color: #5a5a5a;
}
.row:nth-child(2) {
... ... @@ -55,12 +60,14 @@
}
.appear-date {
color: #e01;
color: $cartRed;
display: block;
margin-top: 4rem / $pxConvertRem;
}
.price {
font-size: 24rem / $pxConvertRem;
color: #000;
color: $cartRed;
}
.count {
... ... @@ -78,7 +85,11 @@
border: none;
color: #fff;
text-align: center;
margin-left: 16rem / $pxConvertRem;
float: right;
margin-top: 20rem / $pxConvertRem;
margin-right: 16rem / $pxConvertRem;
border-radius: 20rem / $pxConvertRem;
padding: 4rem / $pxConvertRem;
}
.sold-out {
... ... @@ -86,7 +97,7 @@
}
.low-stocks {
background: #e01;
background: #7f7f7f;
}
.icon-del,
... ... @@ -141,3 +152,9 @@
}
}
}
.shopping-cart-good:last-child {
.deps {
border: none;
}
}
... ...
... ... @@ -17,11 +17,6 @@
</span>
{{/if}}
{{#if appearDate}}
<span class="appear-date">
上市期:{{appearDate}}
</span>
{{/if}}
</p>
<p class="row">
<span class="price">
... ... @@ -36,14 +31,23 @@
</span>
{{/if}}
<span class="iconfont icon-edit">&#xe61e;</span>
<span class="iconfont icon-del">&#xe621;</span>
</p>
<p class="row">
{{#if lowStocks}}
<span class="low-stocks">
库存不足
</span>
{{/if}}
<span class="iconfont icon-edit">&#xe61e;</span>
<span class="iconfont icon-del">&#xe621;</span>
</p>
<p class="row">
{{#if appearDate}}
<span class="appear-date">
上市期:{{appearDate}}
</span>
{{/if}}
</p>
</div>
</div>
... ...
... ... @@ -13,7 +13,6 @@ class ShoppingCartController extends AbstractAction
/*
* 购物车首页
*/
public function indexAction()
{
$this->setTitle('购物车');
... ... @@ -30,6 +29,47 @@ class ShoppingCartController extends AbstractAction
// 渲染模板
$this->_view->display('index', $data);
}
/*
* 异步获取购物车数据
*/
public function getCartDataAction()
{
$result = array();
if ($this->isAjax()) {
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$result = CartModel::getCartData($uid, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 购物车商品选择与取消
*/
public function selectAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 移出购物车
... ...
... ... @@ -63,13 +63,13 @@ class CartModel
/* 普通购物车 */
if(isset($cart['ordinary_cart_data'])) {
$result['commonGoodsCount'] = count($cart['ordinary_cart_data']['goods_list']);
$result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count'];
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data']);
}
/* 预售购物车 */
if(isset($cart['advance_cart_data'])) {
$result['presellGoodsCount'] = count($cart['advance_cart_data']['goods_list']);
$result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count'];
$result['preSellCart'] = self::procCartData($cart['advance_cart_data']);
}
... ... @@ -79,6 +79,30 @@ class CartModel
}
/**
* 购物车商品选择与取消接口返回的数据处理
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 处理之后的数据的数据
*/
public static function selectGoods($uid, $sku, $shoppingKey)
{
$result = array('code' => 400, 'message' => '出错啦~');
// 处理sku
$sku_list = json_encode(array($sku => 1));
$select = CartData::selectGoods($uid, $sku_list, $shoppingKey);
if ($select && isset($select['code'])) {
$result['code'] = $select['code'];
$result['message'] = $select['message'];
}
return $result;
}
/**
* 移出购物车
*
* @param int $uid 用户ID
... ... @@ -567,31 +591,25 @@ class CartModel
$result = array();
$oneGoods = array();
// 购买的商品列表
foreach ($data['goods_list'] as $value) {
$oneGoods['id'] = $value['product_sku'];
$oneGoods['skn'] = $value['product_skn'];
$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;
// 购买的可用商品列表
$validGoods = Helpers::formatCartGoods($data['goods_list']);
!empty($validGoods) && $result['goods'] = $validGoods;
// 失效商品列表
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
$result['goods'][] = $oneGoods;
}
// 赠品
count($data['gift_list']) && $result['freebieOrAdvanceBuy'] = true;
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
$result['freebie'] = $data['gift_list'];
// 加价购
$result['advanceBuy'] = $data['price_gift'];
$result['advanceBuy'] = Helpers::formatAdvanceGoods($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'];
print_r($result);
return $result;
}
... ...