Toggle navigation
Toggle navigation
This project
Loading...
Sign in
wangshusheng
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to dashboard
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
Rock Zhang
9 years ago
Commit
f794dbee72bb132d5dff1cd16b88e30fabed1f77
2 parents
6a8d04ef
377306b6
Merge branch 'feature/cart' into develop
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
552 additions
and
494 deletions
docs/data-structure.md
library/Plugin/Helpers.php
static/js/shopping-cart/cart-info.js
static/js/shopping-cart/cart.js
static/js/shopping-cart/chose-panel.js
static/js/shopping-cart/good.js
static/sass/shopping-cart/_chose-panel.scss
static/sass/shopping-cart/_good.scss
static/sass/shopping-cart/_index.scss
template/m.yohobuy.com/actions/index/shoppingCart/index.phtml
template/m.yohobuy.com/partials/shopping-cart/cart-content.phtml
template/m.yohobuy.com/partials/shopping-cart/chose-panel.phtml
template/m.yohobuy.com/partials/shopping-cart/gift-advance-good.phtml
template/m.yohobuy.com/partials/shopping-cart/good.phtml
yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php
yohobuy/m.yohobuy.com/application/models/Index/Cart.php
docs/data-structure.md
View file @
f794dbe
...
...
@@ -1266,10 +1266,9 @@
'notForSale':'非卖品',
thumb: [
thumb
s
: [
{
id:1,
url : ''
img : ''
},
...
],
...
...
@@ -1277,28 +1276,30 @@
price: '',
salePrice: '',
colors: [
{
id: 1,
chosed: true,
name: '黄色',
colorNum:10,
sizeNumStr:'10/20/30' //对应的商品尺码数目,用斜杠分割
{
id: 1,
skcId:,
chosed: true,
name: '黄色',
colorNum:10,
sizeNumStr:'10/20/30' //对应的商品尺码数目,用斜杠分割
},
...
],
},
...
],
sizes: [
{
id: 2,
skuId:,
goodId:,
chosed: true,
name: 'X',
sizeNum: 2,
colorNumStr:'10/20/30' //对应的商品颜色数目用斜杠分割
},
...
],
totalNum: 20
]
},
'introUrl' : '',
'id' : '',
...
...
library/Plugin/Helpers.php
View file @
f794dbe
...
...
@@ -197,7 +197,7 @@ class Helpers
* 格式化商品信息
*
* @param array $productData 需要格式化的商品数据
* @param bool $showTag 控制是否显示标签
* @param bool $showTag
s
控制是否显示标签
* @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
;
}
elseif
(
$value
[
'goods_type'
]
==
'gift'
)
{
$oneGoods
[
'gift'
]
=
true
;
$oneGoods
[
'isSoldOut'
]
=
true
;
}
elseif
(
$value
[
'goods_type'
]
==
'gift'
&&
!
isset
(
$value
[
'isAdvanceBuy'
]))
{
$oneGoods
[
'isGift'
]
=
true
;
}
elseif
(
$value
[
'goods_type'
]
==
'price_gift'
)
{
$oneGoods
[
'
a
dvanceBuy'
]
=
true
;
$oneGoods
[
'
isA
dvanceBuy'
]
=
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
;
...
...
static/js/shopping-cart/cart-info.js
0 → 100644
View file @
f794dbe
/**
* 购物车信息读取
* @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
));
};
...
...
static/js/shopping-cart/cart.js
View file @
f794dbe
...
...
@@ -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
...
...
static/js/shopping-cart/chose-panel.js
View file @
f794dbe
...
...
@@ -78,7 +78,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
//根据颜色切换图片
if
(
$this
.
closest
(
'.block-list'
).
hasClass
(
'color-list'
))
{
$
(
'.chose-panel
.basic-info
'
).
find
(
'.thumb'
).
addClass
(
'hide'
).
eq
(
index
).
removeClass
(
'hide'
);
$
(
'.chose-panel'
).
find
(
'.thumb'
).
addClass
(
'hide'
).
eq
(
index
).
removeClass
(
'hide'
);
}
if
(
$chosed
.
length
===
0
)
{
...
...
@@ -120,6 +120,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
}
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
(
'已售罄'
);
}
}
}).
on
(
'touchstart'
,
'.btn-minus'
,
function
()
{
...
...
static/js/shopping-cart/good.js
View file @
f794dbe
...
...
@@ -6,17 +6,14 @@
var
$
=
require
(
'jquery'
),
ellipsis
=
require
(
'mlellipsis'
),
chosePanel
=
require
(
'../shopping-cart/chose-panel'
),
lazyLoad
=
require
(
'yoho.lazyload'
);
var
dialog
=
require
(
'../me/dialog'
),
tip
=
require
(
'../plugin/tip'
),
chosePanel
=
require
(
'./chose-panel'
);
tip
=
require
(
'../plugin/tip'
);
var
$names
;
//chosePanel = require('./chose-panel');
var
cartType
=
'ordinary'
;
var
$names
;
//var $curDelPanel;
...
...
@@ -82,6 +79,24 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
});
}).
on
(
'touchstart'
,
'.icon-edit'
,
function
()
{
//var $this = $(this);
//
//var $cartgood = $this.closest('.shopping-cart-good');
//
////var id = $this.closest('.shopping-cart-good').data('id');
//
//var $viewGood = $cartgood.find('.deps');
// $editGoot = $cartgood.find('.calculate-num');
//
//if ($viewGood.hasClass('show')) {
// $viewGood.removeClass('show').addClass('hide');
// $editGoot.removeClass('hide').addClass('show');
//} else {
// $viewGood.removeClass('hide').addClass('show');
// $editGoot.removeClass('show').addClass('hide');
//}
}).
on
(
'touchstart'
,
'.icon-del'
,
function
(
e
)
{
var
$this
=
$
(
this
);
...
...
@@ -154,26 +169,33 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
$
(
'.btn-balance'
).
on
(
'touchend'
,
function
()
{
window
.
location
.
href
=
'/shoppingCart/orderEnsure?cartType='
+
cartType
;
window
.
location
.
href
=
'/shoppingCart/orderEnsure?cartType='
+
'ordinary'
;
});
$
(
'.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'
);
}
$
(
'.down'
).
on
(
'touchend'
,
function
()
{
chosePanel
.
show
();
});
$
(
'.cut'
).
on
(
'touchend'
,
function
()
{
var
id
=
$
(
this
).
closest
(
'.shopping-cart-good'
).
data
(
'id'
);
$
.
ajax
({
type
:
'GET'
,
url
:
'/shoppingCart/modify'
,
data
:
{
old_product_sku
:
id
,
new_product_sku
:
id
,
buy_number
:
'0'
,
selected
:
'Y'
},
success
:
function
(
data
)
{
if
(
data
.
code
===
200
)
{
window
.
history
.
go
(
0
);
}
},
error
:
function
()
{
tip
.
show
(
'网络错误'
);
}
});
$
(
'.chose'
).
on
(
'touchend'
,
function
()
{
//var id = $(this).closest('.gift-advance-good').data('id');
chosePanel
.
show
();
});
...
...
static/sass/shopping-cart/_chose-panel.scss
View file @
f794dbe
...
...
@@ -113,7 +113,7 @@
border-color
:
#e0e0e0
;
background
:
none
;
color
:
#e0e0e0
;
background-color
:
#
f0f0f
0
;
background-color
:
#
c0c0c
0
;
}
}
...
...
static/sass/shopping-cart/_good.scss
View file @
f794dbe
...
...
@@ -151,6 +151,62 @@
}
}
}
.calculate-num
{
float
:
right
;
.calculate
{
float
:
right
;
border
:
1px
solid
#b0b0b0
;
border-radius
:
.2rem
;
p
{
color
:
#444
;
&
:first-child
{
height
:
60rem
/
$pxConvertRem
;
border-bottom
:
1px
solid
#b0b0b0
;
span
{
border-left
:
1px
solid
#b0b0b0
;
border-right
:
1px
solid
#b0b0b0
;
}
}
i
{
width
:
72rem
/
$pxConvertRem
;
height
:
60rem
/
$pxConvertRem
;
float
:
left
;
line-height
:
60rem
/
$pxConvertRem
;
text-align
:
center
;
}
span
{
width
:
96rem
/
$pxConvertRem
;
height
:
60rem
/
$pxConvertRem
;
float
:
left
;
font-size
:
40rem
/
$pxConvertRem
;
line-height
:
60rem
/
$pxConvertRem
;
text-align
:
center
;
}
&
:last-child
{
span
{
width
:
168rem
/
$pxConvertRem
;
overflow
:
hidden
;
font-size
:
48em
/
$pxConvertRem
;
text-overflow
:ellipsis
;
white-space
:nowrap
;
}
}
}
}
.price
{
line-height
:
60rem
/
$pxConvertRem
;
font-size
:
52em
/
$pxConvertRem
;
font-weight
:
bold
;
}
.count
{
position
:
absolute
;
right
:
20rem
/
$pxConvertRem
;;
top
:
20rem
/
$pxConvertRem
;;
font-size
:
52em
/
$pxConvertRem
;
}
}
}
.shopping-cart-good
:last-child
{
...
...
static/sass/shopping-cart/_index.scss
View file @
f794dbe
...
...
@@ -178,116 +178,6 @@
}
}
.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
{
...
...
template/m.yohobuy.com/actions/index/shoppingCart/index.phtml
View file @
f794dbe
{
{>
layout/header
}
}
<div
id=
"mainCart"
class=
"shopping-cart-page yoho-page"
>
{
{#
shoppingCart
}
}
{
{#if
cartNav
}
}
<ul
class=
"cart-nav clearfix"
>
...
...
@@ -45,7 +44,6 @@
{
{/
shoppingCart
}
}
</div>
<div
id=
"advanceBuy"
class=
"shopping-cart-page yoho-page hide"
>
{
{#
shoppingCart
}
}
{
{#
commonCart
}
}
...
...
@@ -70,4 +68,5 @@
{
{>
product/recommend-for-you
}
}
</div>
{
{>
shopping-cart/chose-panel
}
}
{
{>
layout/footer
}
}
\ No newline at end of file
...
...
template/m.yohobuy.com/partials/shopping-cart/cart-content.phtml
View file @
f794dbe
...
...
@@ -2,6 +2,11 @@
{{# goods}}
{{> shopping-cart/good}}
{{/ goods}}
{{# $notValidGoods}}
{{> shopping-cart/good}}
{{/ $notValidGoods}}
</div>
{{#if freebieOrAdvanceBuy}}
...
...
@@ -21,7 +26,7 @@
<span class="iconfont"></span>
加价购
<a>
<span class="count">{{
c
ount}}</span>
<span class="count">{{
advanceBuyC
ount}}</span>
<span class="iconfont icon-right-arrow"></span>
</a>
</li>
...
...
template/m.yohobuy.com/partials/shopping-cart/chose-panel.phtml
View file @
f794dbe
{
{#cartInfo
}
}
<div class="chose-panel">
<div class="main">
<div class="infos">
...
...
@@ -25,7 +25,7 @@
<span>颜色</span>
<ul class="clearfix" data-type="color">
{{# colors}}
<li
class=
"block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}"
data-num=
"{{colorNum}}"
data-numstr=
"{{sizeNumStr}}"
>
<li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-numstr="{{sizeNumStr}}"
data-skcid="{{skcId}}"
>
{{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}}zero-stock{{/unless}}"
data-id=
{
{id
}
}
data-num=
"{{sizeNum}}"
data-numstr=
"{{colorNumStr}}"
>
<li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}"
data-skuid="{{skuId}}" data-goodid="{{goodId}}"
>
{{name}}
</li>
{{/ sizes}}
...
...
@@ -61,4 +61,3 @@
</div>
</div>
</div>
{
{/cartInfo
}
}
\ No newline at end of file
...
...
template/m.yohobuy.com/partials/shopping-cart/gift-advance-good.phtml
View file @
f794dbe
...
...
@@ -31,4 +31,6 @@
</p>
<button class="chose">选择</button>
</div>
</div>
\ No newline at end of file
...
...
template/m.yohobuy.com/partials/shopping-cart/good.phtml
View file @
f794dbe
<div class="shopping-cart-good clearfix" data-id={{id}}>
<span class="checkbox icon-cb-checked iconfont"></span>
<div class="info">
<img class="thumb lazy" data-original={{thumb}}>
<div class="deps">
{{#if isSoldOut}}
<p class="">失效</p>
{{^}}
{{#if isGift}}
{{^}}
<span class="checkbox icon-cb-checked iconfont"></span>
{{/if}}
{{/if}}
<div class="">
<a class="" href="{{url}}">
<img class="thumb lazy" data-original="{{thumb}}">
</a>
{{#if isAdvanceBuy}}
<p class="few-tag">加价购</p>
{{^}}
{{#if isGift}}
<p class="few-tag">赠品</p>
{{/if}}
{{/if}}
{{#if isSoldOut}}
<p class="few-tag">失效</p>
{{/if}}
</div>
<div class="deps show">
<p class="name row">{{name}}</p>
<p class="row">
{{#if color}}
...
...
@@ -50,6 +73,16 @@
{{/if}}
</p>
</div>
<div class="calculate-num hide">
<div class="calculate">
<p><i class="iconfont cut"></i><span>{{count}}</span><i class="iconfont add"></i></p>
<p><span>颜色:{{color}}尺码:{{size}}{{name}}</span><i class="iconfont down"></i></p>
</div>
<p><span class="price"> ¥{{price}}</span></p>
<span class="count">
×{{count}}
</span>
</div>
</div>
<!--<div class="opt-panel hide">
<div class="put-in-favorite">
...
...
@@ -62,4 +95,5 @@
删除
</div>
</div>-->
</div>
...
...
yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php
View file @
f794dbe
...
...
@@ -13,7 +13,6 @@ class ShoppingCartController extends AbstractAction
/*
* 购物车首页
*/
public
function
indexAction
()
{
$this
->
setTitle
(
'购物车'
);
...
...
@@ -30,243 +29,239 @@ 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
);
}
}
/**
* 移出购物车
*/
public
function
delAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$productId
=
$this
->
post
(
'id'
,
0
);
$uid
=
$this
->
getUid
(
true
);
$shoppingKey
=
$this
->
getSession
(
'shoppingKey'
);
$result
=
CartModel
::
removeFromCart
(
$uid
,
$productId
,
$shoppingKey
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 移入收藏夹
*/
public
function
colAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$productId
=
$this
->
post
(
'id'
,
0
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
addToFav
(
$uid
,
$productId
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/*
* 获取购物车商品数据
*/
public
function
goodinfoAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$num
=
$this
->
get
(
'buy_num'
,
1
);
$skn
=
$this
->
get
(
'id'
,
1
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
cartProductData
(
$uid
,
$skn
,
$num
);
// 测试skn的ID为51172055
$result
[
'num'
]
=
$num
;
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
$result
=
array
();
/*
* 获取购物车加价购商品数据
*/
if
(
$this
->
isAjax
())
{
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$uid
=
$this
->
getUid
(
true
);
public
function
giftinfoAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$skn
=
$this
->
get
(
'skn'
,
null
);
$promotionId
=
$this
->
get
(
'promotionId'
,
null
);
$result
=
CartModel
::
giftProductData
(
$skn
,
$promotionId
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
$result
=
CartModel
::
getCartData
(
$uid
,
$shoppingKey
);
}
/**
* 修改购物车商品数据
*/
public
function
modifyAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$shoppingKey
=
$this
->
getSession
(
'shoppingKey'
);
$uid
=
$this
->
getUid
(
true
);
$params
=
array
();
$params
[
'old_product_sku'
]
=
$this
->
post
(
'old_product_sku'
,
0
);
$params
[
'new_product_sku'
]
=
$this
->
post
(
'new_product_sku'
,
0
);
$params
[
'buy_number'
]
=
$this
->
post
(
'buy_number'
,
0
);
$params
[
'selected'
]
=
$this
->
post
(
'selected'
,
null
);
$result
=
CartModel
::
modifyCartProduct
(
$uid
,
$params
,
$shoppingKey
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 购物车结算请求
*/
public
function
orderEnsureAction
()
{
$this
->
setTitle
(
'购物车'
);
$this
->
setNavHeader
(
'购物车'
);
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
$cookieData
=
$this
->
getCookie
(
'order-info'
,
null
);
$uid
=
$this
->
getUid
(
true
);
$data
=
array
(
'orderEnsurePage'
=>
true
,
'orderEnsure'
=>
CartModel
::
cartPay
(
$uid
,
$cartType
,
$cookieData
)
);
/**
* 购物车商品选择与取消
*/
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
);
}
}
/**
* 移出购物车
*/
public
function
delAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$productId
=
$this
->
post
(
'id'
,
0
);
$uid
=
$this
->
getUid
(
true
);
$shoppingKey
=
$this
->
getSession
(
'shoppingKey'
);
$result
=
CartModel
::
removeFromCart
(
$uid
,
$productId
,
$shoppingKey
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 移入收藏夹
*/
public
function
colAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$productId
=
$this
->
post
(
'id'
,
0
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
addToFav
(
$uid
,
$productId
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/*
* 获取购物车商品数据
*/
public
function
goodinfoAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$num
=
$this
->
get
(
'buy_num'
,
1
);
$skn
=
$this
->
get
(
'id'
,
1
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
cartProductData
(
$uid
,
$skn
,
$num
);
// 测试skn的ID为51172055
$result
[
'num'
]
=
$num
;
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/*
* 获取购物车加价购商品数据
*/
public
function
giftinfoAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$skn
=
$this
->
get
(
'skn'
,
null
);
$promotionId
=
$this
->
get
(
'promotionId'
,
null
);
$result
=
CartModel
::
giftProductData
(
$skn
,
$promotionId
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 修改购物车商品数据
*/
public
function
modifyAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$shoppingKey
=
$this
->
getSession
(
'shoppingKey'
);
$uid
=
$this
->
getUid
(
true
);
$params
=
array
();
$params
[
'old_product_sku'
]
=
$this
->
post
(
'old_product_sku'
,
0
);
$params
[
'new_product_sku'
]
=
$this
->
post
(
'new_product_sku'
,
0
);
$params
[
'buy_number'
]
=
$this
->
post
(
'buy_number'
,
0
);
$params
[
'selected'
]
=
$this
->
post
(
'selected'
,
null
);
$result
=
CartModel
::
modifyCartProduct
(
$uid
,
$params
,
$shoppingKey
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 购物车结算请求
*/
public
function
orderEnsureAction
()
{
$this
->
setTitle
(
'购物车'
);
$this
->
setNavHeader
(
'购物车'
);
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
$cookieData
=
$this
->
getCookie
(
'order-info'
,
null
);
$uid
=
$this
->
getUid
(
true
);
$data
=
array
(
'orderEnsurePage'
=>
true
,
'orderEnsure'
=>
CartModel
::
cartPay
(
$uid
,
$cartType
,
$cookieData
)
);
// var_dump($data);
$this
->
_view
->
display
(
'order-ensure'
,
$data
);
}
/**
* 购物车选择改变字段,重新运算订单数据
*/
public
function
orderComputeAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
$deliveryWay
=
$this
->
post
(
'deliveryId'
,
1
);
$paymentType
=
$this
->
post
(
'paymentTypeId'
,
1
);
$couponCode
=
$this
->
post
(
'couponCode'
,
null
);
$yohoCoin
=
$this
->
post
(
'yohoCoin'
,
null
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
orderCompute
(
$uid
,
$cartType
,
$deliveryWay
,
$paymentType
,
$couponCode
,
$yohoCoin
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 购物车输入优惠券码使用优惠券
*/
public
function
couponSearchAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$couponCode
=
$this
->
get
(
'couponCode'
,
''
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
searchCoupon
(
$uid
,
$couponCode
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 购物车结算--获取优惠券列表
*/
public
function
couponListAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$page
=
$this
->
get
(
'page'
,
1
);
$result
=
CartModel
::
getCouponList
(
$uid
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
$this
->
_view
->
display
(
'order-ensure'
,
$data
);
}
/**
* 购物车选择改变字段,重新运算订单数据
*/
public
function
orderComputeAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
$deliveryWay
=
$this
->
post
(
'deliveryId'
,
1
);
$paymentType
=
$this
->
post
(
'paymentTypeId'
,
1
);
$couponCode
=
$this
->
post
(
'couponCode'
,
null
);
$yohoCoin
=
$this
->
post
(
'yohoCoin'
,
null
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
orderCompute
(
$uid
,
$cartType
,
$deliveryWay
,
$paymentType
,
$couponCode
,
$yohoCoin
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 购物车输入优惠券码使用优惠券
*/
public
function
couponSearchAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$couponCode
=
$this
->
get
(
'couponCode'
,
''
);
$uid
=
$this
->
getUid
(
true
);
$result
=
CartModel
::
searchCoupon
(
$uid
,
$couponCode
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 购物车结算--获取优惠券列表
*/
public
function
couponListAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$page
=
$this
->
get
(
'page'
,
1
);
$result
=
CartModel
::
getCouponList
(
$uid
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
$this
->
echoJson
(
$result
);
}
}
/**
* 下单流程 选择地址
...
...
@@ -277,7 +272,7 @@ class ShoppingCartController extends AbstractAction
$this
->
setTitle
(
'选择地址'
);
$this
->
setNavHeader
(
'选择地址'
,
Helpers
::
url
(
'/shoppingCart/orderEnsure'
));
$uid
=
$this
->
getUid
(
true
);
$uid
=
$this
->
getUid
(
true
);
$address
=
UserModel
::
getAddressData
(
$uid
);
$this
->
_view
->
display
(
'select-address'
,
array
(
...
...
@@ -301,72 +296,36 @@ class ShoppingCartController extends AbstractAction
));
}
/**
* 确认结算订单
*/
public
function
orderSubAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$addressId
=
$this
->
post
(
'addressId'
,
null
);
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
// 默认普通购物车
$deliveryTime
=
$this
->
post
(
'deliveryTimeId'
,
1
);
// 默认只工作日配送
$deliveryWay
=
$this
->
post
(
'deliveryId'
,
1
);
// 默认普通快递
$invoiceTitle
=
$this
->
post
(
'invoiceText'
,
null
);
$invoiceId
=
$this
->
post
(
'invoiceType'
,
null
);
$paymentId
=
$this
->
post
(
'paymentTypeId'
,
15
);
$paymentType
=
$this
->
post
(
'paymentType'
,
1
);
// 默认在线支付
$remark
=
$this
->
post
(
'msg'
,
null
);
$couponCode
=
$this
->
post
(
'couponCode'
,
null
);
$yohoCoin
=
$this
->
post
(
'yohoCoin'
,
1
);
$result
=
CartModel
::
orderSub
(
$uid
,
$addressId
,
$cartType
,
$deliveryTime
,
$deliveryWay
,
$invoiceTitle
,
$invoiceId
,
$paymentId
,
$paymentType
,
$remark
,
$couponCode
,
$yohoCoin
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
// 提交成功清除Cookie
$this
->
setCookie
(
'order-info'
,
null
);
$this
->
echoJson
(
$result
);
}
}
/**
* 加入购物车
*
* @param string productSku 商品的SKU
* @param int buyNumber 购买数量
* @param int promotionId 促销ID, 加价购有关
* @param int goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int isEdit 是否是编辑商品SKU,0表示不是编辑
* @return json
*/
public
function
addAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$shoppingKey
=
Helpers
::
getShoppingKeyByCookie
();
$productSku
=
$this
->
post
(
'productSku'
);
$buyNumber
=
$this
->
post
(
'buyNumber'
,
1
);
$goodsType
=
$this
->
post
(
'goodsType'
,
0
);
$promotionId
=
$this
->
post
(
'promotionId'
,
0
);
$isEdit
=
$this
->
post
(
'isEdit'
,
0
);
$uid
=
$this
->
getUid
(
true
);
// 执行加入购物车操作
$result
=
CartModel
::
addToCart
(
$productSku
,
$buyNumber
,
$goodsType
,
$isEdit
,
$promotionId
,
$uid
,
$shoppingKey
);
// 设置加入购物车凭证到客户端浏览器
if
(
isset
(
$result
[
'data'
][
'shopping_key'
]))
{
$this
->
setCookie
(
'_spk'
,
$shoppingKey
);
}
}
$this
->
echoJson
(
$result
);
}
/**
* 确认结算订单
*/
public
function
orderSubAction
()
{
$result
=
array
();
if
(
$this
->
isAjax
())
{
$uid
=
$this
->
getUid
(
true
);
$addressId
=
$this
->
post
(
'addressId'
,
null
);
$cartType
=
$this
->
post
(
'cartType'
,
'ordinary'
);
// 默认普通购物车
$deliveryTime
=
$this
->
post
(
'deliveryTimeId'
,
1
);
// 默认只工作日配送
$deliveryWay
=
$this
->
post
(
'deliveryId'
,
1
);
// 默认普通快递
$invoiceTitle
=
$this
->
post
(
'invoiceText'
,
null
);
$invoiceId
=
$this
->
post
(
'invoiceType'
,
null
);
$paymentId
=
$this
->
post
(
'paymentTypeId'
,
15
);
$paymentType
=
$this
->
post
(
'paymentType'
,
1
);
// 默认在线支付
$remark
=
$this
->
post
(
'msg'
,
null
);
$couponCode
=
$this
->
post
(
'couponCode'
,
null
);
$yohoCoin
=
$this
->
post
(
'yohoCoin'
,
1
);
$result
=
CartModel
::
orderSub
(
$uid
,
$addressId
,
$cartType
,
$deliveryTime
,
$deliveryWay
,
$invoiceTitle
,
$invoiceId
,
$paymentId
,
$paymentType
,
$remark
,
$couponCode
,
$yohoCoin
);
}
if
(
empty
(
$result
))
{
echo
' '
;
}
else
{
// 提交成功清除Cookie
$this
->
setCookie
(
'order-info'
,
null
);
$this
->
echoJson
(
$result
);
}
}
}
...
...
yohobuy/m.yohobuy.com/application/models/Index/Cart.php
View file @
f794dbe
...
...
@@ -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
);
}
}
...
...
@@ -601,30 +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
();
// 购买的可用商品列表
$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
;
}
...
...
Please
register
or
login
to post a comment