Authored by 梁志锋

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

... ... @@ -1261,7 +1261,7 @@
chosed: true,
name: '黄色',
colorNum:10,
shortUrl:'',
sizeNumStr:'10/20/30' //对应的商品尺码数目,用斜杠分割
},
...
... ... @@ -1271,7 +1271,8 @@
id: 2,
chosed: true,
name: 'X',
sizeNum: 2
sizeNum: 2,
colorNumStr:'10/20/30' //对应的商品颜色数目用斜杠分割
},
...
],
... ...
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
*/
... ...
... ... @@ -58,21 +58,51 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
}).on('touchstart', '#chose-btn-sure', function() {
//确定
}).on('touchstart', '.block', function() {
}).on('touchstart', '.block', function(e) {
//尺寸颜色点选
var $this = $(this);
if ($this.hasClass('.chosed') || $this.hasClass('disable')) {
var $this = $(this),
$that = $(e.target).closest('.chose-items'),
numArray,
index;
if ($this.hasClass('chosed')) {
$this.parent().find('.block').removeClass('chosed');
$that.find('.num .left-num').html('');
} else if ($this.hasClass('disable')) {
$this.css('background-color', '#000');
return;
} else if (!$this.hasClass('chosed')) {
$this.siblings('.chosed').removeClass('chosed');
$this.addClass('chosed');
index = $this.index();
//根据颜色切换图片
if ($this.closest('.block-list').hasClass('color-list')) {
$('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide');
}
//剩余的商品数
if ($that.find('.color-list ul>li').hasClass('chosed') && $that.find('.size-list ul>li').hasClass('chosed')) {
numArray = $this.closest('.block-list').siblings(':first').find('.chosed').data('numstr').split('/');
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
} else {
$that.find('.num .left-num').html('');
}
//点击切换
}
$this.siblings('.chosed').removeClass('chosed');
$this.addClass('chosed');
}).on('touchstart', '.btn-minus', function() {
var num = +$num.val();
if (num === 1) {
//若颜色和尺码没有被同时选中,则不能点击
if ($('.block-list>ul>li.chosed').length < 2) {
return;
}
if (num === 0) {
return;
}
... ... @@ -80,6 +110,11 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
}).on('touchstart', '.btn-plus', function() {
var num = +$num.val();
//若颜色和尺码没有被同时选中,则不能点击
if ($('.block-list>ul>li.chosed').length < 2) {
return;
}
//TODO:库存数验证
$num.val(num + 1);
});
... ...
... ... @@ -79,6 +79,11 @@
left: 0;
top: 20rem / $pxConvertRem;
}
>span.left-num{
position: absolute;
left: pxToRem(380px);
top: 20rem / $pxConvertRem;
}
}
.block {
... ... @@ -99,6 +104,11 @@
background-position: bottom right;
color: #e10;
}
&.disable {
color: #e0e0e0;
border-color: #e0e0e0;
}
}
.num {
... ...
.shopping-cart-good {
$cartRed: #d0253b;
position: relative;
padding-left: 16rem / $pxConvertRem;
... ... @@ -16,26 +17,30 @@
.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) {
font-size: 22rem / $pxConvertRem;
height: 45rem / $pxConvertRem;
... ... @@ -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,
... ... @@ -140,4 +151,10 @@
}
}
}
}
\ No newline at end of file
}
.shopping-cart-good:last-child {
.deps {
border: none;
}
}
... ...
... ... @@ -3,7 +3,13 @@
<div class="main">
<div class="infos">
<div class="basic-info">
<img class="thumb" src={{thumb}}>
{{#thumbs}}
{{#if @first}}
<img class="thumb" src={{img}}>
{{else}}
<img class="thumb hide" src={{img}}>
{{/if}}
{{/thumbs}}
<div class="text-info">
<p class="name">{{name}}</p>
<p class="price">
... ... @@ -15,21 +21,21 @@
</div>
</div>
<div class="chose-items">
<div class="color-list">
<div class="color-list block-list">
<span>颜色</span>
<ul class="clearfix" data-type="color">
{{# colors}}
<li class="block {{#if chosed}}chosed{{/if}}" data-id={{id}}>
<li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{sizeNumStr}}">
{{name}}
</li>
{{/ colors}}
</ul>
</div>
<div class="size-list">
<div class="size-list block-list">
<span>尺码</span>
<ul class="clearfix {{#if @first}}{{^}}hide{{/if}}" data-type="size" >
<ul class="clearfix" data-type="size" >
{{# sizes}}
<li class="block {{#if chosed}}chosed{{/if}}" data-id={{id}}>
<li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{colorNumStr}}">
{{name}}
</li>
{{/ sizes}}
... ... @@ -44,8 +50,9 @@
<input id="good-num" class="good-num" type="text" value={{num}}>
<a class="btn btn-plus" href="javascript:void(0);">
<span class="iconfont">&#xe624;</span>
</a>
</a>
</div>
<span class="left-num"></span>
</div>
</div>
</div>
... ...
... ... @@ -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>
... ... @@ -58,4 +62,4 @@
删除
</div>
</div>
</div>
\ No newline at end of file
</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,26 +591,19 @@ 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;
$result['goods'][] = $oneGoods;
}
// 购买的可用商品列表
$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']) && $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'];
... ...