Authored by uedxwg

'样式冲突修改'

... ... @@ -190,14 +190,14 @@ class Helpers
*/
public static function transPrice($price)
{
return (!empty($price) && !is_float($price)) ? $price . '.00' : $price;
return (!empty($price) && !is_float($price)) ? $price . '.00' : number_format($price, 2, '.', '');
}
/**
* 格式化商品信息
*
* @param array $productData 需要格式化的商品数据
* @param bool $showTag 控制是否显示标签
* @param bool $showTags 控制是否显示标签
* @param bool $showNew 控制是否显示NEW图标
* @param bool $showSale 控制是否显示SALE图标
* @param int $width 图片的宽度
... ... @@ -522,6 +522,7 @@ class Helpers
* @param array $orderGoods 订单
* @param int $count 计订单件数
* @param bool $haveLink 控制是否需要商品链接
* @return array $arr 处理之后的订单商品数据
*/
public static function formatOrderGoods($orderGoods, &$count = 0, $haveLink = false)
{
... ... @@ -559,9 +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();
... ... @@ -573,25 +574,24 @@ class Helpers
$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['price'] = self::transPrice($value['sales_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;
$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;
... ... @@ -604,13 +604,13 @@ class Helpers
* 格式化加价购商品
*
* @param array $advanceGoods 加价购商品列表
* @param bool $haveLink 控制是否需要商品链接
* @param int $count 计商品件数
* @return array $arr 处理之后的加价购商品数据
*/
public static function formatAdvanceGoods($advanceGoods)
public static function formatAdvanceGoods($advanceGoods, &$count = 0)
{
$arr = array();
$gift = array();
$oneGoods = array();
foreach ($advanceGoods as $value) {
... ... @@ -630,6 +630,9 @@ class Helpers
}
$arr[] = $gift;
// 计算加价购商品数目
$count += count($value['goods_list']);
}
return $arr;
... ...
... ... @@ -114,7 +114,7 @@ function search() {
}
function scrollHandler() {
if (!end || $(window).scrollTop() + winH >= $(document).height() - 50) {
if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) {
search();
}
}
... ...
... ... @@ -18,11 +18,6 @@ var goodsDiscountEl = document.getElementById('goodsDiscount'),
var $cart = $('.cart-bar');
require('./desc');
require('./comments-consults');
require('../recommend-for-you-product-desc');
//add extra marign-bottom for footer to show the yoho copyright
function showFooter() {
var $cartBar = $('.cart-bar');
... ... @@ -74,6 +69,10 @@ if (goodsDiscountHammer && $discountFolder.children().length > 0) {
});
}
require('./desc');
require('./comments-consults');
require('../recommend-for-you-product-desc');
//购物车商品数量
$.ajax({
type: 'GET',
... ...
... ... @@ -73,14 +73,13 @@ if (addToCartHammer) {
addToCartHammer.on('tap', function(e) {
chosePanel.show();
// 统计代码:用于统计用户加入购物车的动作
// if (window._yas) {
// window._yas.sendCustomInfo({
// pd: productId,
// by: 1
// }, false);
// }
//统计代码:用于统计用户加入购物车的动作
if (window._yas) {
window._yas.sendCustomInfo({
pd: productId,
by: 1
}, true);
}
});
}
... ...
/**
* 购物车信息读取
* @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));
};
... ...
... ... @@ -8,9 +8,13 @@ var $ = require('jquery'),
lazyLoad = require('yoho.lazyload'),
Hammer = require('yoho.hammer');
var chosePanel = require('./chose-panel'),
cartInfo = require('./cart-info').cartInfo;
var $cartContent = $('.cart-content');
var navHammer;
var navHammer,
cartType = 'ordinary';
require('./good');
... ... @@ -32,4 +36,34 @@ navHammer.on('tap', function(e) {
//trigger lazyload
$(window).trigger('scroll');
});
\ No newline at end of file
});
$('.btn-balance').on('touchend', function() {
window.location.href = '/shoppingCart/orderEnsure?cartType=' + cartType;
});
$('.advance-buy').on('touchend', function() {
var $advanceBuy = $('#advanceBuy'),
$mainCart = $('#mainCart');
if ($advanceBuy.hasClass('hide')) {
$mainCart.removeClass('show').addClass('hide');
$advanceBuy.removeClass('hide').addClass('show');
} else {
$advanceBuy.removeClass('show').addClass('hide');
$mainCart.removeClass('hide').addClass('show');
}
});
$('.chose').on('touchend', function() {
//var id = $(this).closest('.gift-advance-good').data('id');
chosePanel.show();
});
cartInfo = 0;
\ No newline at end of file
... ...
... ... @@ -11,7 +11,8 @@ var $ = require('jquery');
// var $page = $('.yoho-page');
var $num;
var $num,
$chosed;
// var tpl;
... ... @@ -64,41 +65,69 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
var $this = $(this),
$that = $(e.target).closest('.chose-items'),
numArray,
index;
index,
i;
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();
var $siblingBlock = $this.closest('.block-list').siblings(':first'),
currentNumArray = $this.data('numstr').split('/');
$this.siblings('.chosed').removeClass('chosed');
$this.toggleClass('chosed');
index = $this.index();
$chosed = $('.block-list>ul>li.chosed');
//根据颜色切换图片
if ($this.closest('.block-list').hasClass('color-list')) {
$('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide');
}
//根据颜色切换图片
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('');
if ($chosed.length === 0) {
$this.closest('ul>li').each(function() {
$(this).removeClass('zero-stock');
if (0 === $(this).data('num') - 0) {
$(this).addClass('zero-stock');
}
});
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if (0 === $(this).data('num') - 0) {
$(this).addClass('zero-stock');
}
});
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
numArray = $chosed.data('numstr').split('/');
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < numArray.length; i++) {
if (0 === numArray[i] - 0) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
//点击切换
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if (0 === $(this).data('num') - 0) {
$(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] - 0) {
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
}
}
numArray = $siblingBlock.find('.chosed').data('numstr').split('/');
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
}
}).on('touchstart', '.btn-minus', function() {
var num = +$num.val();
var num = +$num.val(),
$chosed = $('.block-list>ul>li.chosed');
//若颜色和尺码没有被同时选中,则不能点击
if ($('.block-list>ul>li.chosed').length < 2) {
if ($chosed.length < 2) {
return;
}
... ...
... ... @@ -7,23 +7,23 @@
var $ = require('jquery'),
lazyLoad = require('yoho.lazyload');
var chosePanel = require('./chose-panel');
//var chosePanel = require('./chose-panel');
lazyLoad($('.lazy'));
$('.gift-advance-page').on('touchstart', '.chose', function() {
var id = $(this).closest('.gift-advance-good').data('id');
$.ajax({
type: 'GET',
url: '/shoppingCart/goodinfo',
data: {
id: id
},
success: function(data) {
if (data.code === 200) {
chosePanel.show(data.data);
}
}
});
});
\ No newline at end of file
//$('.gift-advance-page').on('touchstart', '.chose', function() {
// var id = $(this).closest('.gift-advance-good').data('id');
//
// $.ajax({
// type: 'GET',
// url: '/shoppingCart/goodinfo',
// data: {
// id: id
// },
// success: function(data) {
// if (data.code === 200) {
// chosePanel.show(data.data);
// }
// }
// });
//});
\ No newline at end of file
... ...
... ... @@ -12,11 +12,8 @@ var $ = require('jquery'),
var dialog = require('../me/dialog'),
tip = require('../plugin/tip');
var $names;
//chosePanel = require('./chose-panel');
var cartType = 'ordinary';
var $names;
//var $curDelPanel;
... ... @@ -184,4 +181,3 @@ $('.cut').on('touchend', function() {
});
... ...
... ... @@ -80,6 +80,7 @@ function orderCompute() {
sumPrice: res.order_amount,
salePrice: res.discount_amount,
freight: res.promotion_formula_list[1].promotion_amount,
couponPrice: res.coupon_amount,
yohoCoin: res.use_yoho_coin,
price: res.last_order_amount
});
... ... @@ -98,8 +99,8 @@ function submitOrder() {
data: {
addressId: orderInfo('addressId'),
cartType: orderInfo('cartType'),
deliveryId: orderInfo('deliveryId'),
deliveryTimeId: orderInfo('deliveryTimeId'),
deliveryId: orderInfo('deliveryId') || 1,
deliveryTimeId: orderInfo('deliveryTimeId') || 1,
invoiceText: orderInfo('invoiceText'),
invoiceType: orderInfo('invoiceType'),
msg: orderInfo('msg'),
... ... @@ -109,13 +110,24 @@ function submitOrder() {
yohoCoin: orderInfo('yohoCoin')
}
}).then(function(res) {
console.log(res);
if (!res) {
tip.show('网络出错');
}
if (res.code !== 200) {
tip.show(res.message || '网络出错');
} else {
console.log(1);
}
}).fail(function() {
tip.show('网络出错');
});
}
// 界面点击,状态存 cookie
if (!orderInfo('addressId')) {
orderInfo('addressId', $('.address-wrap').data('address-id'));
}
$('.dispatch-mode').on('touchend', 'li', function() {
orderInfo('deliveryId', $(this).data('id'));
orderCompute();
... ...
... ... @@ -3,6 +3,7 @@
* @author: bikai<kai.bi@yoho.cn>
* @date: 2015/12/14
*/
var $ = require('jquery');
var info = window.cookie('order-info');
// info 必须是 JSON 字符串
... ... @@ -10,10 +11,10 @@ try {
info = JSON.parse(info);
} catch (e) {
info = {
deliveryId: null,
deliveryTimeId: null,
paymentTypeId: null,
yohoCoin: null,
deliveryId: 1,
deliveryTimeId: 1,
paymentTypeId: 1,
yohoCoin: $('.coin').data('yoho-coin') || 0,
addressId: null,
couponCode: null,
couponValue: null,
... ... @@ -22,6 +23,7 @@ try {
invoiceType: null,
msg: null
};
window.setCookie('order-info', JSON.stringify(info));
}
exports.orderInfo = function(key, value) {
... ...
... ... @@ -21,7 +21,7 @@
"yoho.iswiper": "3.0.1",
"iscroll": "5.1.2",
"import-style": "1.0.0",
"yoho.lazyload": "1.1.3",
"yoho.lazyload": "1.1.4",
"yoho.handlebars": "3.0.3",
"yoho.hammer": "2.0.4"
},
... ...
... ... @@ -105,10 +105,16 @@
color: #e10;
}
&.disable {
&.zero-stock {
color: #e0e0e0;
border-color: #e0e0e0;
}
&.zero-stock.chosed {
border-color: #e0e0e0;
background: none;
color: #e0e0e0;
background-color: #f0f0f0;
}
}
.num {
... ...
... ... @@ -177,6 +177,117 @@
font-size: 28rem / $pxConvertRem;
}
}
.gift-advance-good {
position: relative;
padding: 20rem / $pxConvertRem 0;
margin-left: 34rem / $pxConvertRem;
height: 160rem / $pxConvertRem;
border-bottom: 1px solid #e0e0e0;
&:last-child {
border-bottom: none;
}
}
.advance-block .gift-advance-good:last-child {
border-bottom: none;
}
.advance-block:last-child .gift-advance-good:last-child {
border-bottom: 1px solid #e0e0e0;
}
.thumb-wrap {
position: relative;
float: left;
width: 120rem / $pxConvertRem;
height: 160rem / $pxConvertRem;
.thumb {
width: 100%;
height: 100%;
}
}
.tag {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 25rem / $pxConvertRem;
color: #fff;
text-align: center;
background: #a1ce4e;
&:before {
content: '赠品';
}
}
.deps {
margin-left: 135rem / $pxConvertRem;
}
.name {
font-size: 28rem / $pxConvertRem;
}
.row:nth-child(2) {
font-size: 22rem / $pxConvertRem;
height: 45rem / $pxConvertRem;
line-height: 45rem / $pxConvertRem;
> span {
margin-right: 15rem / $pxConvertRem;
}
}
.row:nth-child(3) {
position: relative;
}
.color, .size {
color: #b6b6b6;
}
.price {
font-size: 24rem / $pxConvertRem;
color: #000;
}
.count {
font-size: 20rem / $pxConvertRem;
color: #999;
margin-left: 22rem / $pxConvertRem;
}
.chose {
position: absolute;
width: 88rem / $pxConvertRem;
height: 58rem / $pxConvertRem;
background: #f8f8f8;
border: 1px solid #ccc;
right: 20rem / $pxConvertRem;
top: 71rem / $pxConvertRem;
font-size: 26rem / $pxConvertRem;
}
.title {
height: 50rem / $pxConvertRem;
line-height: 50rem / $pxConvertRem;
padding-left: 20rem / $pxConvertRem;
font-size: 24rem / $pxConvertRem;
background: #f8f8f8;
}
.advance-block .tag {
background: #eb76aa;
&:before {
content: '加价购';
}
}
}
.shopping-cart-zero{
.cart-zero{
... ...
{{> layout/header}}
<div class="shopping-cart-page yoho-page">
<div id="mainCart" class="shopping-cart-page yoho-page">
{{# shoppingCart}}
{{#if cartNav}}
<ul class="cart-nav clearfix">
... ... @@ -44,7 +44,22 @@
{{/ shoppingCart}}
</div>
<div class="shopping-cart-zero yoho-page" style="display: none;">
<div id="advanceBuy" class="shopping-cart-page yoho-page hide">
{{# shoppingCart}}
{{# commonCart}}
{{# advanceBuy}}
<span>
{{promotionTitle}}
</span>
{{# goods}}
{{> shopping-cart/gift-advance-good}}
{{/ goods}}
{{/ advanceBuy}}
{{/ commonCart}}
{{/ shoppingCart}}
</div>
<div class="shopping-cart-zero yoho-page hide">
<div class="cart-zero">
<i class="iconfont">&#xe62c</i>
<p>您的购物车暂无商品</p>
... ... @@ -53,4 +68,6 @@
{{> product/recommend-for-you}}
{{> shopping-cart/chose-panel}}
</div>
{{> shopping-cart/chose-panel}}
{{> layout/footer}}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="order-ensure-page yoho-page">
{{# orderEnsure}}
<a class="address-wrap block" href="/shoppingCart/selectAddress">
<a class="address-wrap block" href="/shoppingCart/selectAddress" data-address-id="{{addressId}}">
<p class="infos">
收货地址
<span class="per-info">{{name}} {{phoneNum}}</span>
... ... @@ -41,7 +41,7 @@
<section class="block">
<ul class="sale-invoice">
{{#if coupon}}
{{# coupon}}
<li class="coupon">
<a href="/shoppingCart/selectCoupon">
<!-- <a href="{{url}}"> -->
... ... @@ -65,7 +65,7 @@
{{/if}}
</a>
</li>
{{/if}}
{{/coupon}}
{{# yohoCoin}}
<li class="coin" data-yoho-coin="{{.}}">
... ... @@ -114,11 +114,17 @@
</li>
<li>
<span>运费</span>
+ ¥{{freight}}
+ {{freight}}
</li>
{{#couponPrice}}
<li>
<span>优惠券</span>
- ¥{{.}}
</li>
{{/couponPrice}}
<li>
<span>YOHO币</span>
- ¥{{yohoCoin}}
- {{yohoCoin}}
</li>
<li class="cost">
应付金额: <em>¥{{price}}</em>
... ... @@ -156,6 +162,12 @@
<span>运费</span>
+ \{{freight}}
</li>
\{{#couponPrice}}
<li>
<span>优惠券</span>
- ¥\{{.}}
</li>
\{{/couponPrice}}
<li>
<span>YOHO币</span>
- ¥\{{yohoCoin}}
... ...
... ... @@ -16,16 +16,16 @@
</a>
</li>
{{/ freebie}}
{{# advanceBuy}}
{{#if advanceBuy}}
<li class="advance-buy">
<span class="iconfont">&#xe61b;</span>
加价购
<a href={{url}}>
<span class="count">{{count}}</span>
<a>
<span class="count">{{advanceBuyCount}}</span>
<span class="iconfont icon-right-arrow">&#xe614;</span>
</a>
</li>
{{/ advanceBuy}}
{{/if}}
</ul>
{{/if}}
... ... @@ -54,4 +54,4 @@
<a class="btn-balance">
结算
</a>
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -25,7 +25,7 @@
<span>颜色</span>
<ul class="clearfix" data-type="color">
{{# colors}}
<li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{sizeNumStr}}">
<li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-numstr="{{sizeNumStr}}">
{{name}}
</li>
{{/ colors}}
... ... @@ -35,7 +35,7 @@
<span>尺码</span>
<ul class="clearfix" data-type="size" >
{{# sizes}}
<li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{colorNumStr}}">
<li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}">
{{name}}
</li>
{{/ sizes}}
... ...
... ... @@ -31,4 +31,6 @@
</p>
<button class="chose">选择</button>
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -3,6 +3,23 @@
<div class="info">
<img class="thumb lazy" data-original={{thumb}}>
<!-- <div class="deps">
<div class="">
<a class="" href="{{url}}">
<img class="thumb lazy" data-original="{{thumb}}">
</a>
{{#if isGift}}
<p class="few-tag">赠品</p>
{{/if}}
{{#if isAdvanceBuy}}
<p class="few-tag">加价购</p>
{{/if}}
{{#if isSoldOut}}
<p class="few-tag">失效</p>
{{/if}}
</div>
<div class="deps">
<p class="name row">{{name}}</p>
<p class="row">
{{#if color}}
... ...
... ... @@ -25,10 +25,11 @@ class ShoppingCartController extends AbstractAction
'shoppingCartPage' => true,
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey)
);
print_r($data);
// 渲染模板
$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()
... ... @@ -195,7 +237,7 @@ class ShoppingCartController extends AbstractAction
'orderEnsurePage' => true,
'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData)
);
// var_dump($data);
$this->_view->display('order-ensure', $data);
}
... ...
... ... @@ -23,7 +23,7 @@ class CartModel
* @param int $productSku 商品SKU
* @param int $buyNumber 购买数量
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
* @param null|int $promotionId 促销id,默认null(加价购有关)
* @param null|int $uid 用户UID,可以不传
* @return array 加入购物车接口返回的数据
... ... @@ -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);
}
}
... ... @@ -406,7 +408,7 @@ class CartModel
$oneGoods['name'] = $single['product_name'];
$oneGoods['color'] = $single['color_name'];
$oneGoods['size'] = $single['size_name'];
$oneGoods['price'] = Helpers::transPrice($single['real_price']); // last_price有些带.00,有些不带,real_price都不带.00
$oneGoods['price'] = Helpers::transPrice($single['sales_price']);
$oneGoods['count'] = $single['buy_number'];
$result['goods'][] = $oneGoods;
... ... @@ -428,18 +430,20 @@ class CartModel
}
// 有货币
$result['yohoCoin'] = isset($orderCompute['use_yoho_coin']) ? isset($orderCompute['use_yoho_coin']) : $payReturn['yoho_coin'];
$result['yohoCoin'] = (isset($orderCompute['use_yoho_coin']) && !empty($orderCompute['use_yoho_coin'])) ? $orderCompute['use_yoho_coin'] : $payReturn['yoho_coin'];
// 订单数据
if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
$sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount'];
$salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['discount_amount'];
$freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list'][1]['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][1]['promotion_amount'];
$couponPrice = isset($orderCompute['coupon_amount']) ? $orderCompute['coupon_amount'] : false;
$salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][3]['promotion_amount'];
$price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount'];
$freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list']['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][1]['promotion_amount'];
$result['sumPrice'] = Helpers::transPrice($sumPrice);
$result['salePrice'] = Helpers::transPrice($salePrice);
$result['price'] = Helpers::transPrice($price);
$result['freight'] = strtr($freight, array('¥'=>'','¥'=>'')) . '.00';
$result['freight'] = $freight;
$result['couponPrice'] = $couponPrice;
}
// 发票有关数据
... ... @@ -468,7 +472,7 @@ class CartModel
// 优惠券数据
$coupons = array();
!empty($orderCompute['coupon_amount']) && $coupons['value'] = $orderInfo['couponValue'];
$coupons += self::getCouponList($uid, 0, 1, true);
$coupons += self::getCouponList($uid, true);
$result['coupon'] = $coupons;
}
... ... @@ -535,7 +539,7 @@ class CartModel
if (isset($coupons['data'])) {
if ($onlyTotal) {
$result['count'] = $coupons['data']['total'];
$result['count'] = count($coupons['data']['couponList']);
} else {
$couponArr = array();
isset($coupons['data']['couponList']) && $couponArr = $coupons['data']['couponList'];
... ... @@ -599,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();
$oneGoods = 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['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'];
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;
}
... ...