Authored by hf

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

... ... @@ -624,8 +624,8 @@ class Helpers
$oneGoods['name'] = $single['product_name'];
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : '';
$oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据
$oneGoods['price'] = $single['last_price'];
$oneGoods['marketPrice'] = $single['market_price'];
$oneGoods['price'] = self::transPrice($single['last_price']);
$oneGoods['marketPrice'] = self::transPrice($single['market_price']);
$oneGoods['count'] = $single['storage_number'];
$gift['goods'][] = $oneGoods;
... ...
... ... @@ -5,46 +5,53 @@
* @date: 2015/10/21
*/
var $ = require('jquery'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading');
// Handlebars = require('yoho.handlebars');
// bikai
// 增加init函数,异步请求的接口需要重新初始化一下选择列表
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
// var $page = $('.yoho-page');
var $ = require('jquery'),
Handlebars = require('yoho.handlebars'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading');
var $num,
var panelTmpl,
$chosePanel = $('#chose-panel'),
$num,
$chosed,
re = /\d+/,
leftNum,
$colorList = $('.color-list ul>li'),
$sizeList = $('.size-list ul>li'),
firstColorId = $colorList.eq(0).data('id'),
$colorList,
$sizeList,
firstColorId,
colorIndex,
confirming;
//初始化购物车面板显示
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === firstColorId) {
$(this).removeClass('hide');
// 读取模板
$.get('/cart/index/giftinfoTpl', function(html) {
if (!html) {
tip.show('网络错误');
return;
}
panelTmpl = Handlebars.compile(html);
}).fail(function() {
tip.show('网络错误');
});
//初始化购物车面板显示
function init() {
$colorList = $('.chose-panel .color-list ul>li');
$sizeList = $('.chose-panel .size-list ul>li');
firstColorId = $colorList.eq(0).data('id');
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === firstColorId) {
$(this).removeClass('hide');
}
});
}
// var tpl;
//读取partials
// $.ajax({
// type: 'GET',
// url: '/shoppingCart/tpl',
// success: function(data) {
// tpl = Handlebars.compile(data);
// }
// });
init();
//显示
// function show(data) {
... ... @@ -57,7 +64,12 @@ $sizeList.each(function() {
function show() {
function show(data) {
if (data) {
$chosePanel.html(panelTmpl(data));
init();
}
$('.chose-panel').show();
$('body').css('overflow', 'hidden');
... ... @@ -112,16 +124,18 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
isEdit: isEdit
}
}).done(function(res) {
loading.hideLoadingMask();
if (res.code === 200) {
loading.hideLoadingMask();
$('.num-tag').html(numInCart + buyNumber);
$('.num-tag').removeClass('hide');
confirming = false;
remove();
}
if (res.message) {
tip.show(res.message);
}
}).fail(function() {
tip.show('网络出了点问题~');
}).always(function() {
confirming = false;
});
}
... ... @@ -241,5 +255,5 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
$num.val(num + 1);
});
exports.show = show;
\ No newline at end of file
exports.init = init;
exports.show = show;
... ...
... ... @@ -6,27 +6,14 @@
var $ = require('jquery'),
lazyLoad = require('yoho.lazyload'),
Handlebars = require('yoho.handlebars'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading'),
chosePanel = require('./chose-panel');
var panelTmpl,
$page = $('.gift-advance-page'),
$chosePanel = $('#chose-panel');
var $page = $('.gift-advance-page');
lazyLoad($('.lazy'));
$.get('/cart/index/giftinfoTpl', function(html) {
if (!html) {
tip.show('网络错误');
return;
}
panelTmpl = Handlebars.compile(html);
}).fail(function() {
tip.show('网络错误');
});
function getProductInfo(skn, promotionId) {
loading.showLoadingMask();
$.get('/cart/index/giftinfo', {
... ... @@ -37,14 +24,10 @@ function getProductInfo(skn, promotionId) {
tip.show('网络错误');
return;
}
if (!panelTmpl) {
return;
}
if (res.code === 200) {
$chosePanel.html(panelTmpl({
cartInfo: res.data
}));
chosePanel.show();
chosePanel.show({
cartInfo: res.data
});
} else {
tip.show(res.message || '网络错误');
}
... ...
... ... @@ -148,12 +148,14 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
}
}, function() {
var id = $this.closest('.shopping-cart-good').data('id');
var count = $this.data('count');
$.ajax({
method: 'post',
url: '/cart/index/del',
data: {
id: id
sku: id,
count: count
}
}).then(function(data) {
if (data.code === 200) {
... ... @@ -240,7 +242,7 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) {
}
goodInfo.goods_type = type;
goodInfo.selected = isSelected ? 'Y' : 'N';
goodInfo.selected = isSelected ? 'N' : 'Y';
$goods.each(function(idx, good) {
$good = $(good);
... ... @@ -257,9 +259,8 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) {
//是否要全选
function willBeSelected() {
function willBeSelected($this) {
var isSelected = true;
var $this = $(this);
if ($this.hasClass('icon-cb-checked')) {
isSelected = true;
... ... @@ -272,7 +273,8 @@ function willBeSelected() {
//全选按钮点击事件
$selectAllBtn.on('touchend', function() {
bottomCheckBoxHandeler(willBeSelected(), getCartType(), didUpdateAllGoodsCheckStatus);
var $this = $(this);
bottomCheckBoxHandeler(willBeSelected($this), getCartType(), didUpdateAllGoodsCheckStatus);
});
$('.down').on('touchend', function() {
... ...
... ... @@ -8,8 +8,8 @@
right: 0;
background: rgba(0,0,0,.3);
z-index:3;
.main {
position: absolute;
height: pxToRem(610px);
... ... @@ -86,7 +86,7 @@
top: 20rem / $pxConvertRem;
}
}
.size-list li.hide {
display: none;
}
... ... @@ -94,7 +94,9 @@
.block {
float: left;
display: block;
width: 80rem / $pxConvertRem;
box-sizing: border-box;
padding: 0 20rem / $pxConvertRem;
min-width: 80rem / $pxConvertRem;
height: 80rem / $pxConvertRem;
border: 1px solid #000;
margin-right: 30rem / $pxConvertRem;
... ... @@ -112,10 +114,10 @@
&.zero-stock {
color: #e0e0e0;
border-color: #e0e0e0;
border-color: #e0e0e0;
}
&.zero-stock.chosed {
border-color: #e0e0e0;
border-color: #e0e0e0;
background: none;
color: #e0e0e0;
background-color: #c0c0c0;
... ... @@ -168,4 +170,4 @@
border: none;
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -55,7 +55,7 @@
margin-left: 135rem / $pxConvertRem;
}
.name {
.gift-advance-good .name {
margin-bottom: 20rem / $pxConvertRem;
width: 440rem / $pxConvertRem;
font-size: 28rem / $pxConvertRem;
... ...
... ... @@ -6,6 +6,7 @@
.shopping-cart-page {
padding-bottom: 120rem / $pxConvertRem;
overflow-x: hidden;
.cart-nav {
color: #c6c6c6;
... ... @@ -208,8 +209,8 @@
border:1px solid #505050;
border-radius:.2rem;
display: block;
margin: 0 auto;
margin: 0 auto;
text-align: center;
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -5,7 +5,7 @@
<div class="cart-zero">
<i class="iconfont">&#xe62c</i>
<p>您的购物车暂无商品</p>
<a href="">随便逛逛</a>
<a href="/product/new">随便逛逛</a>
</div>
{{> product/recommend-for-you}}
</div>
... ... @@ -31,7 +31,7 @@
<p class="login-info">
<span class="iconfont">&#xe628;</span>
请您先
<a class="btn btn-login">登录</a>
<a class="btn btn-login" href="{{signurl}}">登录</a>
可以同步电脑和手机中的商品
</p>
{{/if}}
... ...
... ... @@ -15,7 +15,7 @@
<li class="freebie">
<span class="iconfont">&#xe620;</span>
赠品
<a href={{url}}>
<a href="/cart/index/gift">
<span class="count">{{count}}</span>
<span class="iconfont icon-right-arrow">&#xe614;</span>
</a>
... ... @@ -25,7 +25,7 @@
<li class="advance-buy">
<span class="iconfont">&#xe61b;</span>
加价购
<a>
<a href="/cart/index/advanceBuy">
<span class="count">{{advanceBuyCount}}</span>
<span class="iconfont icon-right-arrow">&#xe614;</span>
</a>
... ...
... ... @@ -13,9 +13,9 @@
<div class="text-info">
<p class="name">{{name}}</p>
<p class="price">
<span class="sale-price{{^price}} no-price{{/price}}">¥{{salePrice}}</span>
<span class="sale-price{{^price}} no-price{{/price}}">{{salePrice}}</span>
{{#if price}}
<span class="market-price">¥{{price}}</span>
<span class="market-price">{{price}}</span>
{{/if}}
</p>
</div>
... ...
... ... @@ -51,8 +51,7 @@
{{/if}}
<span class="iconfont icon-del">&#xe621;</span>
<span class="iconfont icon-del" data-count="{{count}}">&#xe621;</span>
</p>
<p class="row">
{{#if lowStocks}}
... ...
... ... @@ -41,6 +41,8 @@ class CartModel
}
/**
* 获取购物车信息
*
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @param string $cartType 购物车类型
... ... @@ -54,6 +56,7 @@ class CartModel
// 用户是否登录
if (empty($uid)) {
$result['signurl'] = Helpers::url('/signin.html', array('refer' => Helpers::url('/cart/index/index')));
$result['showLoginInfo'] = true;
}
... ... @@ -63,11 +66,14 @@ class CartModel
// 处理普通购物车和预售购物车的数据
do {
if (!isset($cartData['data']) || empty($cartData['data'])) {
// $result['isEmptyCart'] = true;
break;
}
$cart = $cartData['data'];
$result['cartNav'] = true;
if ($cartType !== 'all') { // 加价购或者赠品数据
$result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
break;
... ... @@ -93,6 +99,31 @@ class CartModel
}
/**
* 获取购物车商品数目
*
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @return array|mixed 购物车商品数目
*/
public static function getCartCount($uid, $shoppingKey)
{
$result = array(
'code' => 200,
'data' => array(
'cart_goods_count' => 0
)
);
$carData = self::getCartData($uid, $shoppingKey);
if (isset($carData['commonGoodsCount'])) {
$result['data']['cart_goods_count'] = $carData['commonGoodsCount'] + $carData['presellGoodsCount'];
}
return $result;
}
/**
* 购物车商品选择与取消接口返回的数据处理
*
* @param int $uid 用户ID
... ... @@ -123,16 +154,17 @@ class CartModel
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $sku 商品sku
* @param string $count 要删除的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
public static function removeFromCart($uid, $sku, $shoppingKey)
public static function removeFromCart($uid, $sku, $count, $shoppingKey)
{
$result = array('code' => 400, 'message' => '出错啦~');
// 处理sku
$sku_list = json_encode(array($sku => 1));
$sku_list = json_encode(array($sku => $count));
$remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey);
if ($remove && isset($remove['code'])) {
... ... @@ -485,10 +517,18 @@ class CartModel
{
$result = array('code' => 400, 'message' => '出错啦~');
$coupon = CartData::searchCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code'])) {
$result = $coupon;
}
do {
if (empty($couponCode)) {
$result['code'] = 401;
$result['message'] = '优惠券代码为空';
break;
}
$coupon = CartData::searchCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code'])) {
$result = $coupon;
}
}while(0);
return $result;
}
... ... @@ -583,8 +623,8 @@ class CartModel
$data = array();
$data['name'] = $productData['product_name'];
$data['price'] = Helpers::transPrice($productData['market_price']);
$data['salePrice'] = Helpers::transPrice($productData['sales_price']);
$data['price'] = $productData['format_market_price'];
$data['salePrice'] = $productData['format_sales_price'];
if (isset($productData['storage_sum'])) {
$data['storage'] = $productData['storage_sum'];
... ...
... ... @@ -45,9 +45,11 @@ class IndexController extends AbstractAction
'shoppingCartPage' => true,
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey)
);
// 渲染模板
$this->_view->display('index', $data);
}
/*
* 异步获取购物车数据
*/
... ... @@ -70,6 +72,22 @@ class IndexController extends AbstractAction
}
/**
* 异步获取购物车商品数目
*/
public function countAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::getCartCount($uid, $shoppingKey);
}
$this->echoJson($result);
}
/**
* 购物车商品选择与取消
*/
public function selectAction()
... ... @@ -77,17 +95,13 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$productId = $this->post('skuList', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -98,17 +112,14 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$sku = $this->post('sku', 0);
$count = $this->post('count', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$result = CartModel::removeFromCart($uid, $productId, $shoppingKey);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -124,11 +135,7 @@ class IndexController extends AbstractAction
$result = CartModel::addToFav($uid, $productId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/*
... ... @@ -182,11 +189,7 @@ class IndexController extends AbstractAction
$result['num'] = $num;
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/*
... ... @@ -212,11 +215,7 @@ class IndexController extends AbstractAction
$result = CartModel::giftProductData($skn, $promotionId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -236,11 +235,7 @@ class IndexController extends AbstractAction
$result = CartModel::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -262,11 +257,7 @@ class IndexController extends AbstractAction
$result = CartModel::modifyCartProduct($uid, $params, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -316,11 +307,7 @@ class IndexController extends AbstractAction
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -331,16 +318,12 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$couponCode = $this->get('couponCode', '');
$couponCode = $this->post('couponCode', '');
$uid = $this->getUid(true);
$result = CartModel::searchCoupon($uid, $couponCode);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -464,7 +447,7 @@ class IndexController extends AbstractAction
// 设置加入购物车凭证到客户端浏览器
if (isset($result['data']['shopping_key'])) {
$this->setCookie('_spk', $shoppingKey);
$this->setCookie('_spk', $result['data']['shopping_key']);
}
}
... ...