Authored by xuqi

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

framework @ 75bbc3b0
Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
... ...
... ... @@ -27,6 +27,7 @@ class DetailData
*
* @param int $productId 商品ID
* @param int $uid 用户ID
* @param int $productSkn SKN
* @return array
*/
public static function baseInfo($productId, $uid, $productSkn = null)
... ...
... ... @@ -8,7 +8,7 @@
/**
* @ignore
*/
class OAuthException extends Exception {
class OAuthException extends \Exception {
// pass
}
... ...
/**
* 购物车信息读取
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/12/15
*/
var info = window.cookie('cart-info');
// info 必须是 JSON 字符串
try {
info = JSON.parse(info);
} catch (e) {
info = {
deliveryId: null,
deliveryTimeId: null,
paymentTypeId: null,
yohoCoin: null,
addressId: null,
couponCode: null,
couponValue: null,
invoice: null,
invoiceText: null,
invoiceType: null,
msg: null
};
window.setCookie('cart-info', JSON.stringify(info));
}
exports.cartInfo = function(key, value) {
if (value === undefined) {
return info[key];
}
info[key] = value;
window.setCookie('cart-info', JSON.stringify(info));
};
... ... @@ -10,56 +10,37 @@
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
var $ = require('jquery'),
Handlebars = require('yoho.handlebars'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading');
var panelTmpl,
$chosePanel = $('#chose-panel'),
var $chosePanel = $('#chose-panel'),
$num,
$chosed,
// re = /\d+/,
leftNum,
confirming,
hasChooseColor = false,
hasChooseSize = false,
curColorIndex,
curSizeIndex,
$curSizeRow,
$curSizeBlock = null,
$sizeRowList = $('.size-list ul');
// 读取模板
$.get('/cart/index/giftinfoTpl', function(html) {
if (!html) {
tip.show('网络错误');
return;
}
panelTmpl = Handlebars.compile(html);
}).fail(function() {
tip.show('网络错误');
});
hasChooseColor,
hasChooseSize,
$curSizeBlock,
$sizeRowList;
//初始化购物车面板显示
function init() {
var $firstRow;
//$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 $firstRow = $sizeRowList.eq(0);
hasChooseColor = false;
hasChooseSize = false;
$curSizeBlock = null;
$sizeRowList = $('.size-list ul');
$firstRow = $sizeRowList.eq(0);
$firstRow.toggleClass('hide');
$curSizeRow = $firstRow;
}
init();
function checkColorSizeNum() {
if (!hasChooseColor && !hasChooseSize) {
... ... @@ -75,11 +56,9 @@ function checkColorSizeNum() {
return true;
}
init();
function show(data) {
if (data) {
$chosePanel.html(panelTmpl(data));
function show(html) {
if (html) {
$chosePanel.html(html);
init();
}
$('.chose-panel').show();
... ... @@ -88,20 +67,55 @@ function show(data) {
$num = $('#good-num');
}
////显示当前Panel
//function show() {
// $('.chose-panel').show();
//
// $('body').css('overflow', 'hidden');
// $num = $('#good-num');
//}
//隐藏当前Panel
function hide() {
$('.chose-panel').hide();
$('body').css('overflow', 'auto');
}
//修改加入购物车的文字和背景
function updateConformButtonClassAndText() {
$chosed = $('.chose-items').find('.chosed');
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
$('#chose-btn-sure').html('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
}
}
//重置颜色块的库存为0的样式
function resetColorZeroStock($siblingBlock) {
var numArray = ($curSizeBlock.data('numstr') + '').split('/'),
i;
if (!hasChooseSize) {
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if ('0' === $(this).data('num')) {
$(this).addClass('zero-stock');
}
});
} else {
for (i = 0; i < numArray.length; i++) {
if ('0' === numArray[i]) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
}
}
// 选择了颜色切换商品图片
function changeGoodImgWhenClickColor() {
if (hasChooseColor && curColorIndex) {
$('.chose-panel').find('.thumb').addClass('hide').eq(curColorIndex).removeClass('hide');
}
}
init();
$('.yoho-page').on('touchstart', '.chose-panel', function(e) {
var $cur = $(e.target);
... ... @@ -143,11 +157,6 @@ $('.color-list').on('touchstart', '.block', function(e) {
} else {
hasChooseColor = true;
//根据颜色切换图片
if ($this.closest('.block-list').hasClass('color-list')) {
$('.chose-panel').find('.thumb').addClass('hide').eq(index).removeClass('hide');
}
//把当前选中颜色对应的尺码那一行显示出来
$sizeRowList.addClass('hide');
$curSizeRow.removeClass('hide').addClass('show');
... ... @@ -180,91 +189,22 @@ $('.color-list').on('touchstart', '.block', function(e) {
curColorIndex = index;
// 设置按钮的样式和文字
$chosed = $('.chose-items').find('.chosed');
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
$('#chose-btn-sure').html('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
}
/**if ($chosed.length === 0) {
$this.closest('ul>li').each(function() {
$(this).removeClass('zero-stock');
if ('0' === $(this).data('num')) {
$(this).addClass('zero-stock');
}
});
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if ('0' === $(this).data('num')) {
$(this).addClass('zero-stock');
}
});
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
$sizeList.addClass('hide');
//切换尺码信息
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === $this.data('id')) {
$(this).removeClass('hide');
}
});
numArray = ($chosed.data('numstr') + '').split('/');
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < numArray.length; i++) {
if ('0' === numArray[i]) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if ('0' === $(this).data('num')) {
$(this).addClass('zero-stock');
}
});
$that.find('.num .left-num').html('');
} else if ($chosed.length === 2) {
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < currentNumArray.length; i++) {
if ('0' === currentNumArray[i]) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
$('#chose-btn-sure').html('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
}
}**/
updateConformButtonClassAndText();
// 修改颜色时修改商品图片
changeGoodImgWhenClickColor();
});
$('.size-list').on('touchstart', '.block', function(e) {
var $this = $(this),
$that = $(e.target).closest('.chose-items'),
index,
$colorChosed,
curGoodNum;
var $siblingBlock = $this.closest('.block-list').siblings(':first');
$this.siblings('.chosed').removeClass('chosed');
index = $this.index();
$colorChosed = $siblingBlock.find('.chosed');
$curSizeRow = $sizeRowList.eq(index);
// 当前尺码已经是选中状态,再点击时
... ... @@ -275,11 +215,6 @@ $('.size-list').on('touchstart', '.block', function(e) {
$('#left-num').val(0);
hasChooseSize = false;
// 去掉已经选中颜色的 数量为0的样式
if ($colorChosed.length > 0) {
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
}
// 当前尺码不是选中状态,选中时
} else {
hasChooseSize = true;
... ... @@ -296,10 +231,10 @@ $('.size-list').on('touchstart', '.block', function(e) {
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
$('#left-num').val(curGoodNum);
} else {
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
$that.find('.num .left-num').html('');
$('#left-num').val(0);
}
}
$this.toggleClass('chosed');
... ... @@ -307,78 +242,10 @@ $('.size-list').on('touchstart', '.block', function(e) {
$curSizeBlock = $this;
// 设置按钮的样式和文字
$chosed = $('.chose-items').find('.chosed');
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
$('#chose-btn-sure').html('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
}
/**if ($chosed.length === 0) {
$this.closest('ul>li').each(function() {
$(this).removeClass('zero-stock');
if ('0' === $(this).data('num')) {
$(this).addClass('zero-stock');
}
});
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if ('0' === $(this).data('num')) {
$(this).addClass('zero-stock');
}
});
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
if ($this.closest('.block-list').hasClass('color-list')) {
$sizeList.addClass('hide');
//切换尺码信息
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === $this.data('id')) {
$(this).removeClass('hide');
}
});
}
numArray = ($chosed.data('numstr') + '').split('/');
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < numArray.length; i++) {
if ('0' === numArray[i]) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
updateConformButtonClassAndText();
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if ('0' === $(this).data('num')) {
$(this).addClass('zero-stock');
}
});
$that.find('.num .left-num').html('');
} else if ($chosed.length === 2) {
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < currentNumArray.length; i++) {
if ('0' === currentNumArray[i]) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
$('#chose-btn-sure').html('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
}
}**/
// 重置颜色块的样式
resetColorZeroStock($siblingBlock);
});
... ... @@ -426,6 +293,7 @@ $('#chose-btn-sure').on('touchstart', function() {
numInCart = $('.num-tag').html() - 0,
num = $num.val();
//颜色尺码没有选择
if (!checkColorSizeNum()) {
return;
}
... ...
... ... @@ -19,17 +19,12 @@ function getProductInfo(skn, promotionId) {
$.get('/cart/index/giftinfo', {
skn: skn,
promotionId: promotionId
}).then(function(res) {
if (res.code === 200) {
chosePanel.show({
cartInfo: res.data,
cb: function(loc) {
window.location.href = loc;
}
});
} else {
tip.show(res.message);
}).then(function(html) {
if (!html) {
tip.show('网络错误');
return;
}
chosePanel.show(html);
}, function() {
tip.show('网络错误');
}).always(function() {
... ...
{{> cart/chose-panel}}
\ No newline at end of file
... ...
... ... @@ -38,33 +38,33 @@
<ul class="size-row clearfix hide">
{{# size}}
<li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-colorid="{{colorId}}" data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodsId}}">
{{name}}
</li>
{{/ size}}
</ul>
{{name}}
</li>
{{/ size}}
</ul>
{{/ sizes}}
</div>
<p>
<div class="num">
<span>数量</span>
<div class="clearfix">
<a class="btn btn-minus" href="javascript:void(0);">
<span class="iconfont">&#xe625;</span>
</a>
<input id="good-num" class="good-num" type="text" value="1">
<a class="btn btn-plus" href="javascript:void(0);">
<span class="iconfont">&#xe624;</span>
</a>
{{/ sizes}}
</div>
<p>
<div class="num">
<span>数量</span>
<div class="clearfix">
<a class="btn btn-minus" href="javascript:void(0);">
<span class="iconfont">&#xe625;</span>
</a>
<input id="good-num" class="good-num" type="text" value="1">
<a class="btn btn-plus" href="javascript:void(0);">
<span class="iconfont">&#xe624;</span>
</a>
</div>
<span class="left-num"></span>
<input id="left-num" type="hidden" value="0">
</div>
<span class="left-num"></span>
<input id="left-num" type="hidden" value="0">
</div>
</div>
</div>
<div class="btn-wrap">
<button id="chose-btn-sure" class="btn btn-sure">确定</button>
<div class="btn-wrap">
<button id="chose-btn-sure" class="btn btn-sure">确定</button>
</div>
</div>
</div>
</div>
{{/cartInfo}}
\ No newline at end of file
{{/cartInfo}}
\ No newline at end of file
... ...
... ... @@ -39,7 +39,7 @@ class DetailModel
elseif (is_numeric($productSkn)) {
$baseInfo = DetailData::baseInfo(null, $uid, $productSkn);
}
// 商品名称
if (empty($baseInfo['productName'])) {
return $result;
... ... @@ -196,7 +196,7 @@ class DetailModel
);
$colorStorageNum += intval($size['goodsSizeStorageNum']);
$sizeStorageStr .= $size['goodsSizeStorageNum'] . '/';
$colorStorageGroup[$size['sizeName']][$value['colorId']] = $size['goodsSizeStorageNum'];
$colorStorageGroup[$size['sizeName']][$value['productSkc']] = $size['goodsSizeStorageNum'];
}
// 颜色分组
... ...
... ... @@ -192,15 +192,15 @@ class IndexController extends AbstractAction
$this->echoJson($result);
}
/*
* 获取购物车加价购商品数据模板
*/
public function giftinfoTplAction()
{
if ($this->isAjax()) {
echo file_get_contents($this->_view->getScriptPath() . '/../partials/cart/chose-panel.phtml');
}
}
// /*
// * 获取购物车加价购商品数据模板
// */
// public function giftinfoTplAction()
// {
// if ($this->isAjax()) {
// echo file_get_contents($this->_view->getScriptPath() . '/../partials/cart/chose-panel.phtml');
// }
// }
/*
* 获取购物车加价购商品数据
... ... @@ -215,7 +215,9 @@ class IndexController extends AbstractAction
$result = CartModel::giftProductData($skn, $promotionId);
}
$this->echoJson($result);
$this->_view->display('gift-info', array(
'cartInfo' => $result['data']
));
}
/**
... ...