Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop
Showing
13 changed files
with
165 additions
and
141 deletions
@@ -624,8 +624,8 @@ class Helpers | @@ -624,8 +624,8 @@ class Helpers | ||
624 | $oneGoods['name'] = $single['product_name']; | 624 | $oneGoods['name'] = $single['product_name']; |
625 | $oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : ''; | 625 | $oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : ''; |
626 | $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | 626 | $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 |
627 | - $oneGoods['price'] = $single['last_price']; | ||
628 | - $oneGoods['marketPrice'] = $single['market_price']; | 627 | + $oneGoods['price'] = self::transPrice($single['last_price']); |
628 | + $oneGoods['marketPrice'] = self::transPrice($single['market_price']); | ||
629 | $oneGoods['count'] = $single['storage_number']; | 629 | $oneGoods['count'] = $single['storage_number']; |
630 | 630 | ||
631 | $gift['goods'][] = $oneGoods; | 631 | $gift['goods'][] = $oneGoods; |
@@ -5,46 +5,53 @@ | @@ -5,46 +5,53 @@ | ||
5 | * @date: 2015/10/21 | 5 | * @date: 2015/10/21 |
6 | */ | 6 | */ |
7 | 7 | ||
8 | -var $ = require('jquery'), | ||
9 | - tip = require('../plugin/tip'), | ||
10 | - loading = require('../plugin/loading'); | ||
11 | - | ||
12 | -// Handlebars = require('yoho.handlebars'); | 8 | +// bikai |
9 | +// 增加init函数,异步请求的接口需要重新初始化一下选择列表 | ||
10 | +// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框 | ||
13 | 11 | ||
14 | -// var $page = $('.yoho-page'); | 12 | +var $ = require('jquery'), |
13 | + Handlebars = require('yoho.handlebars'), | ||
14 | + tip = require('../plugin/tip'), | ||
15 | + loading = require('../plugin/loading'); | ||
15 | 16 | ||
16 | -var $num, | 17 | +var panelTmpl, |
18 | + $chosePanel = $('#chose-panel'), | ||
19 | + $num, | ||
17 | $chosed, | 20 | $chosed, |
18 | re = /\d+/, | 21 | re = /\d+/, |
19 | leftNum, | 22 | leftNum, |
20 | - $colorList = $('.color-list ul>li'), | ||
21 | - $sizeList = $('.size-list ul>li'), | ||
22 | - firstColorId = $colorList.eq(0).data('id'), | 23 | + $colorList, |
24 | + $sizeList, | ||
25 | + firstColorId, | ||
23 | colorIndex, | 26 | colorIndex, |
24 | confirming; | 27 | confirming; |
25 | 28 | ||
26 | -//初始化购物车面板显示 | ||
27 | -$sizeList.each(function() { | ||
28 | - colorIndex = $(this).data('colorid'); | ||
29 | - | ||
30 | - if (colorIndex === firstColorId) { | ||
31 | - $(this).removeClass('hide'); | 29 | +// 读取模板 |
30 | +$.get('/cart/index/giftinfoTpl', function(html) { | ||
31 | + if (!html) { | ||
32 | + tip.show('网络错误'); | ||
33 | + return; | ||
32 | } | 34 | } |
35 | + panelTmpl = Handlebars.compile(html); | ||
36 | +}).fail(function() { | ||
37 | + tip.show('网络错误'); | ||
33 | }); | 38 | }); |
34 | 39 | ||
40 | +//初始化购物车面板显示 | ||
41 | +function init() { | ||
42 | + $colorList = $('.chose-panel .color-list ul>li'); | ||
43 | + $sizeList = $('.chose-panel .size-list ul>li'); | ||
44 | + firstColorId = $colorList.eq(0).data('id'); | ||
45 | + $sizeList.each(function() { | ||
46 | + colorIndex = $(this).data('colorid'); | ||
47 | + | ||
48 | + if (colorIndex === firstColorId) { | ||
49 | + $(this).removeClass('hide'); | ||
50 | + } | ||
51 | + }); | ||
52 | +} | ||
35 | 53 | ||
36 | - | ||
37 | -// var tpl; | ||
38 | - | ||
39 | -//读取partials | ||
40 | -// $.ajax({ | ||
41 | -// type: 'GET', | ||
42 | -// url: '/shoppingCart/tpl', | ||
43 | -// success: function(data) { | ||
44 | -// tpl = Handlebars.compile(data); | ||
45 | -// } | ||
46 | -// }); | ||
47 | - | 54 | +init(); |
48 | 55 | ||
49 | //显示 | 56 | //显示 |
50 | // function show(data) { | 57 | // function show(data) { |
@@ -57,7 +64,12 @@ $sizeList.each(function() { | @@ -57,7 +64,12 @@ $sizeList.each(function() { | ||
57 | 64 | ||
58 | 65 | ||
59 | 66 | ||
60 | -function show() { | 67 | +function show(data) { |
68 | + if (data) { | ||
69 | + $chosePanel.html(panelTmpl(data)); | ||
70 | + init(); | ||
71 | + } | ||
72 | + | ||
61 | $('.chose-panel').show(); | 73 | $('.chose-panel').show(); |
62 | 74 | ||
63 | $('body').css('overflow', 'hidden'); | 75 | $('body').css('overflow', 'hidden'); |
@@ -112,16 +124,18 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | @@ -112,16 +124,18 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | ||
112 | isEdit: isEdit | 124 | isEdit: isEdit |
113 | } | 125 | } |
114 | }).done(function(res) { | 126 | }).done(function(res) { |
127 | + loading.hideLoadingMask(); | ||
115 | if (res.code === 200) { | 128 | if (res.code === 200) { |
116 | - loading.hideLoadingMask(); | ||
117 | $('.num-tag').html(numInCart + buyNumber); | 129 | $('.num-tag').html(numInCart + buyNumber); |
118 | $('.num-tag').removeClass('hide'); | 130 | $('.num-tag').removeClass('hide'); |
119 | - confirming = false; | ||
120 | remove(); | 131 | remove(); |
121 | } | 132 | } |
133 | + if (res.message) { | ||
134 | + tip.show(res.message); | ||
135 | + } | ||
122 | }).fail(function() { | 136 | }).fail(function() { |
123 | tip.show('网络出了点问题~'); | 137 | tip.show('网络出了点问题~'); |
124 | - | 138 | + }).always(function() { |
125 | confirming = false; | 139 | confirming = false; |
126 | }); | 140 | }); |
127 | } | 141 | } |
@@ -241,5 +255,5 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | @@ -241,5 +255,5 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | ||
241 | $num.val(num + 1); | 255 | $num.val(num + 1); |
242 | }); | 256 | }); |
243 | 257 | ||
244 | - | ||
245 | -exports.show = show; | ||
258 | +exports.init = init; | ||
259 | +exports.show = show; |
@@ -6,27 +6,14 @@ | @@ -6,27 +6,14 @@ | ||
6 | 6 | ||
7 | var $ = require('jquery'), | 7 | var $ = require('jquery'), |
8 | lazyLoad = require('yoho.lazyload'), | 8 | lazyLoad = require('yoho.lazyload'), |
9 | - Handlebars = require('yoho.handlebars'), | ||
10 | tip = require('../plugin/tip'), | 9 | tip = require('../plugin/tip'), |
11 | loading = require('../plugin/loading'), | 10 | loading = require('../plugin/loading'), |
12 | chosePanel = require('./chose-panel'); | 11 | chosePanel = require('./chose-panel'); |
13 | 12 | ||
14 | -var panelTmpl, | ||
15 | - $page = $('.gift-advance-page'), | ||
16 | - $chosePanel = $('#chose-panel'); | 13 | +var $page = $('.gift-advance-page'); |
17 | 14 | ||
18 | lazyLoad($('.lazy')); | 15 | lazyLoad($('.lazy')); |
19 | 16 | ||
20 | -$.get('/cart/index/giftinfoTpl', function(html) { | ||
21 | - if (!html) { | ||
22 | - tip.show('网络错误'); | ||
23 | - return; | ||
24 | - } | ||
25 | - panelTmpl = Handlebars.compile(html); | ||
26 | -}).fail(function() { | ||
27 | - tip.show('网络错误'); | ||
28 | -}); | ||
29 | - | ||
30 | function getProductInfo(skn, promotionId) { | 17 | function getProductInfo(skn, promotionId) { |
31 | loading.showLoadingMask(); | 18 | loading.showLoadingMask(); |
32 | $.get('/cart/index/giftinfo', { | 19 | $.get('/cart/index/giftinfo', { |
@@ -37,14 +24,10 @@ function getProductInfo(skn, promotionId) { | @@ -37,14 +24,10 @@ function getProductInfo(skn, promotionId) { | ||
37 | tip.show('网络错误'); | 24 | tip.show('网络错误'); |
38 | return; | 25 | return; |
39 | } | 26 | } |
40 | - if (!panelTmpl) { | ||
41 | - return; | ||
42 | - } | ||
43 | if (res.code === 200) { | 27 | if (res.code === 200) { |
44 | - $chosePanel.html(panelTmpl({ | ||
45 | - cartInfo: res.data | ||
46 | - })); | ||
47 | - chosePanel.show(); | 28 | + chosePanel.show({ |
29 | + cartInfo: res.data | ||
30 | + }); | ||
48 | } else { | 31 | } else { |
49 | tip.show(res.message || '网络错误'); | 32 | tip.show(res.message || '网络错误'); |
50 | } | 33 | } |
@@ -148,12 +148,14 @@ $('.cart-goods').on('touchstart', '.checkbox', function() { | @@ -148,12 +148,14 @@ $('.cart-goods').on('touchstart', '.checkbox', function() { | ||
148 | } | 148 | } |
149 | }, function() { | 149 | }, function() { |
150 | var id = $this.closest('.shopping-cart-good').data('id'); | 150 | var id = $this.closest('.shopping-cart-good').data('id'); |
151 | + var count = $this.data('count'); | ||
151 | 152 | ||
152 | $.ajax({ | 153 | $.ajax({ |
153 | method: 'post', | 154 | method: 'post', |
154 | url: '/cart/index/del', | 155 | url: '/cart/index/del', |
155 | data: { | 156 | data: { |
156 | - id: id | 157 | + sku: id, |
158 | + count: count | ||
157 | } | 159 | } |
158 | }).then(function(data) { | 160 | }).then(function(data) { |
159 | if (data.code === 200) { | 161 | if (data.code === 200) { |
@@ -240,7 +242,7 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) { | @@ -240,7 +242,7 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) { | ||
240 | } | 242 | } |
241 | 243 | ||
242 | goodInfo.goods_type = type; | 244 | goodInfo.goods_type = type; |
243 | - goodInfo.selected = isSelected ? 'Y' : 'N'; | 245 | + goodInfo.selected = isSelected ? 'N' : 'Y'; |
244 | 246 | ||
245 | $goods.each(function(idx, good) { | 247 | $goods.each(function(idx, good) { |
246 | $good = $(good); | 248 | $good = $(good); |
@@ -257,9 +259,8 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) { | @@ -257,9 +259,8 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) { | ||
257 | 259 | ||
258 | 260 | ||
259 | //是否要全选 | 261 | //是否要全选 |
260 | -function willBeSelected() { | 262 | +function willBeSelected($this) { |
261 | var isSelected = true; | 263 | var isSelected = true; |
262 | - var $this = $(this); | ||
263 | 264 | ||
264 | if ($this.hasClass('icon-cb-checked')) { | 265 | if ($this.hasClass('icon-cb-checked')) { |
265 | isSelected = true; | 266 | isSelected = true; |
@@ -272,7 +273,8 @@ function willBeSelected() { | @@ -272,7 +273,8 @@ function willBeSelected() { | ||
272 | 273 | ||
273 | //全选按钮点击事件 | 274 | //全选按钮点击事件 |
274 | $selectAllBtn.on('touchend', function() { | 275 | $selectAllBtn.on('touchend', function() { |
275 | - bottomCheckBoxHandeler(willBeSelected(), getCartType(), didUpdateAllGoodsCheckStatus); | 276 | + var $this = $(this); |
277 | + bottomCheckBoxHandeler(willBeSelected($this), getCartType(), didUpdateAllGoodsCheckStatus); | ||
276 | }); | 278 | }); |
277 | 279 | ||
278 | $('.down').on('touchend', function() { | 280 | $('.down').on('touchend', function() { |
@@ -8,8 +8,8 @@ | @@ -8,8 +8,8 @@ | ||
8 | right: 0; | 8 | right: 0; |
9 | background: rgba(0,0,0,.3); | 9 | background: rgba(0,0,0,.3); |
10 | z-index:3; | 10 | z-index:3; |
11 | - | ||
12 | - | 11 | + |
12 | + | ||
13 | .main { | 13 | .main { |
14 | position: absolute; | 14 | position: absolute; |
15 | height: pxToRem(610px); | 15 | height: pxToRem(610px); |
@@ -86,7 +86,7 @@ | @@ -86,7 +86,7 @@ | ||
86 | top: 20rem / $pxConvertRem; | 86 | top: 20rem / $pxConvertRem; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | - | 89 | + |
90 | .size-list li.hide { | 90 | .size-list li.hide { |
91 | display: none; | 91 | display: none; |
92 | } | 92 | } |
@@ -94,7 +94,9 @@ | @@ -94,7 +94,9 @@ | ||
94 | .block { | 94 | .block { |
95 | float: left; | 95 | float: left; |
96 | display: block; | 96 | display: block; |
97 | - width: 80rem / $pxConvertRem; | 97 | + box-sizing: border-box; |
98 | + padding: 0 20rem / $pxConvertRem; | ||
99 | + min-width: 80rem / $pxConvertRem; | ||
98 | height: 80rem / $pxConvertRem; | 100 | height: 80rem / $pxConvertRem; |
99 | border: 1px solid #000; | 101 | border: 1px solid #000; |
100 | margin-right: 30rem / $pxConvertRem; | 102 | margin-right: 30rem / $pxConvertRem; |
@@ -112,10 +114,10 @@ | @@ -112,10 +114,10 @@ | ||
112 | 114 | ||
113 | &.zero-stock { | 115 | &.zero-stock { |
114 | color: #e0e0e0; | 116 | color: #e0e0e0; |
115 | - border-color: #e0e0e0; | 117 | + border-color: #e0e0e0; |
116 | } | 118 | } |
117 | &.zero-stock.chosed { | 119 | &.zero-stock.chosed { |
118 | - border-color: #e0e0e0; | 120 | + border-color: #e0e0e0; |
119 | background: none; | 121 | background: none; |
120 | color: #e0e0e0; | 122 | color: #e0e0e0; |
121 | background-color: #c0c0c0; | 123 | background-color: #c0c0c0; |
@@ -168,4 +170,4 @@ | @@ -168,4 +170,4 @@ | ||
168 | border: none; | 170 | border: none; |
169 | } | 171 | } |
170 | } | 172 | } |
171 | -} | ||
173 | +} |
@@ -55,7 +55,7 @@ | @@ -55,7 +55,7 @@ | ||
55 | margin-left: 135rem / $pxConvertRem; | 55 | margin-left: 135rem / $pxConvertRem; |
56 | } | 56 | } |
57 | 57 | ||
58 | - .name { | 58 | + .gift-advance-good .name { |
59 | margin-bottom: 20rem / $pxConvertRem; | 59 | margin-bottom: 20rem / $pxConvertRem; |
60 | width: 440rem / $pxConvertRem; | 60 | width: 440rem / $pxConvertRem; |
61 | font-size: 28rem / $pxConvertRem; | 61 | font-size: 28rem / $pxConvertRem; |
@@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
6 | 6 | ||
7 | .shopping-cart-page { | 7 | .shopping-cart-page { |
8 | padding-bottom: 120rem / $pxConvertRem; | 8 | padding-bottom: 120rem / $pxConvertRem; |
9 | + overflow-x: hidden; | ||
9 | 10 | ||
10 | .cart-nav { | 11 | .cart-nav { |
11 | color: #c6c6c6; | 12 | color: #c6c6c6; |
@@ -208,8 +209,8 @@ | @@ -208,8 +209,8 @@ | ||
208 | border:1px solid #505050; | 209 | border:1px solid #505050; |
209 | border-radius:.2rem; | 210 | border-radius:.2rem; |
210 | display: block; | 211 | display: block; |
211 | - margin: 0 auto; | 212 | + margin: 0 auto; |
212 | text-align: center; | 213 | text-align: center; |
213 | } | 214 | } |
214 | } | 215 | } |
215 | -} | ||
216 | +} |
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <div class="cart-zero"> | 5 | <div class="cart-zero"> |
6 | <i class="iconfont"></i> | 6 | <i class="iconfont"></i> |
7 | <p>您的购物车暂无商品</p> | 7 | <p>您的购物车暂无商品</p> |
8 | - <a href="">随便逛逛</a> | 8 | + <a href="/product/new">随便逛逛</a> |
9 | </div> | 9 | </div> |
10 | {{> product/recommend-for-you}} | 10 | {{> product/recommend-for-you}} |
11 | </div> | 11 | </div> |
@@ -31,7 +31,7 @@ | @@ -31,7 +31,7 @@ | ||
31 | <p class="login-info"> | 31 | <p class="login-info"> |
32 | <span class="iconfont"></span> | 32 | <span class="iconfont"></span> |
33 | 请您先 | 33 | 请您先 |
34 | - <a class="btn btn-login">登录</a> | 34 | + <a class="btn btn-login" href="{{signurl}}">登录</a> |
35 | 可以同步电脑和手机中的商品 | 35 | 可以同步电脑和手机中的商品 |
36 | </p> | 36 | </p> |
37 | {{/if}} | 37 | {{/if}} |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | <li class="freebie"> | 15 | <li class="freebie"> |
16 | <span class="iconfont"></span> | 16 | <span class="iconfont"></span> |
17 | 赠品 | 17 | 赠品 |
18 | - <a href={{url}}> | 18 | + <a href="/cart/index/gift"> |
19 | <span class="count">{{count}}</span> | 19 | <span class="count">{{count}}</span> |
20 | <span class="iconfont icon-right-arrow"></span> | 20 | <span class="iconfont icon-right-arrow"></span> |
21 | </a> | 21 | </a> |
@@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
25 | <li class="advance-buy"> | 25 | <li class="advance-buy"> |
26 | <span class="iconfont"></span> | 26 | <span class="iconfont"></span> |
27 | 加价购 | 27 | 加价购 |
28 | - <a> | 28 | + <a href="/cart/index/advanceBuy"> |
29 | <span class="count">{{advanceBuyCount}}</span> | 29 | <span class="count">{{advanceBuyCount}}</span> |
30 | <span class="iconfont icon-right-arrow"></span> | 30 | <span class="iconfont icon-right-arrow"></span> |
31 | </a> | 31 | </a> |
@@ -13,9 +13,9 @@ | @@ -13,9 +13,9 @@ | ||
13 | <div class="text-info"> | 13 | <div class="text-info"> |
14 | <p class="name">{{name}}</p> | 14 | <p class="name">{{name}}</p> |
15 | <p class="price"> | 15 | <p class="price"> |
16 | - <span class="sale-price{{^price}} no-price{{/price}}">¥{{salePrice}}</span> | 16 | + <span class="sale-price{{^price}} no-price{{/price}}">{{salePrice}}</span> |
17 | {{#if price}} | 17 | {{#if price}} |
18 | - <span class="market-price">¥{{price}}</span> | 18 | + <span class="market-price">{{price}}</span> |
19 | {{/if}} | 19 | {{/if}} |
20 | </p> | 20 | </p> |
21 | </div> | 21 | </div> |
@@ -41,6 +41,8 @@ class CartModel | @@ -41,6 +41,8 @@ class CartModel | ||
41 | } | 41 | } |
42 | 42 | ||
43 | /** | 43 | /** |
44 | + * 获取购物车信息 | ||
45 | + * | ||
44 | * @param integer $uid 用户ID | 46 | * @param integer $uid 用户ID |
45 | * @param string $shoppingKey 未登录用户唯一识别码 | 47 | * @param string $shoppingKey 未登录用户唯一识别码 |
46 | * @param string $cartType 购物车类型 | 48 | * @param string $cartType 购物车类型 |
@@ -54,6 +56,7 @@ class CartModel | @@ -54,6 +56,7 @@ class CartModel | ||
54 | 56 | ||
55 | // 用户是否登录 | 57 | // 用户是否登录 |
56 | if (empty($uid)) { | 58 | if (empty($uid)) { |
59 | + $result['signurl'] = Helpers::url('/signin.html', array('refer' => Helpers::url('/cart/index/index'))); | ||
57 | $result['showLoginInfo'] = true; | 60 | $result['showLoginInfo'] = true; |
58 | } | 61 | } |
59 | 62 | ||
@@ -63,11 +66,14 @@ class CartModel | @@ -63,11 +66,14 @@ class CartModel | ||
63 | // 处理普通购物车和预售购物车的数据 | 66 | // 处理普通购物车和预售购物车的数据 |
64 | do { | 67 | do { |
65 | if (!isset($cartData['data']) || empty($cartData['data'])) { | 68 | if (!isset($cartData['data']) || empty($cartData['data'])) { |
69 | +// $result['isEmptyCart'] = true; | ||
66 | break; | 70 | break; |
67 | } | 71 | } |
68 | 72 | ||
69 | $cart = $cartData['data']; | 73 | $cart = $cartData['data']; |
70 | 74 | ||
75 | + $result['cartNav'] = true; | ||
76 | + | ||
71 | if ($cartType !== 'all') { // 加价购或者赠品数据 | 77 | if ($cartType !== 'all') { // 加价购或者赠品数据 |
72 | $result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy); | 78 | $result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy); |
73 | break; | 79 | break; |
@@ -93,6 +99,31 @@ class CartModel | @@ -93,6 +99,31 @@ class CartModel | ||
93 | } | 99 | } |
94 | 100 | ||
95 | /** | 101 | /** |
102 | + * 获取购物车商品数目 | ||
103 | + * | ||
104 | + * @param integer $uid 用户ID | ||
105 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
106 | + * @return array|mixed 购物车商品数目 | ||
107 | + */ | ||
108 | + public static function getCartCount($uid, $shoppingKey) | ||
109 | + { | ||
110 | + $result = array( | ||
111 | + 'code' => 200, | ||
112 | + 'data' => array( | ||
113 | + 'cart_goods_count' => 0 | ||
114 | + ) | ||
115 | + ); | ||
116 | + | ||
117 | + $carData = self::getCartData($uid, $shoppingKey); | ||
118 | + if (isset($carData['commonGoodsCount'])) { | ||
119 | + $result['data']['cart_goods_count'] = $carData['commonGoodsCount'] + $carData['presellGoodsCount']; | ||
120 | + } | ||
121 | + | ||
122 | + return $result; | ||
123 | + | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
96 | * 购物车商品选择与取消接口返回的数据处理 | 127 | * 购物车商品选择与取消接口返回的数据处理 |
97 | * | 128 | * |
98 | * @param int $uid 用户ID | 129 | * @param int $uid 用户ID |
@@ -123,16 +154,17 @@ class CartModel | @@ -123,16 +154,17 @@ class CartModel | ||
123 | * 移出购物车 | 154 | * 移出购物车 |
124 | * | 155 | * |
125 | * @param int $uid 用户ID | 156 | * @param int $uid 用户ID |
126 | - * @param string $sku 商品sku列表 | 157 | + * @param string $sku 商品sku |
158 | + * @param string $count 要删除的数目 | ||
127 | * @param string $shoppingKey 未登录用户唯一识别码 | 159 | * @param string $shoppingKey 未登录用户唯一识别码 |
128 | * @return array 接口返回的数据 | 160 | * @return array 接口返回的数据 |
129 | */ | 161 | */ |
130 | - public static function removeFromCart($uid, $sku, $shoppingKey) | 162 | + public static function removeFromCart($uid, $sku, $count, $shoppingKey) |
131 | { | 163 | { |
132 | $result = array('code' => 400, 'message' => '出错啦~'); | 164 | $result = array('code' => 400, 'message' => '出错啦~'); |
133 | 165 | ||
134 | // 处理sku | 166 | // 处理sku |
135 | - $sku_list = json_encode(array($sku => 1)); | 167 | + $sku_list = json_encode(array($sku => $count)); |
136 | 168 | ||
137 | $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey); | 169 | $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey); |
138 | if ($remove && isset($remove['code'])) { | 170 | if ($remove && isset($remove['code'])) { |
@@ -485,10 +517,18 @@ class CartModel | @@ -485,10 +517,18 @@ class CartModel | ||
485 | { | 517 | { |
486 | $result = array('code' => 400, 'message' => '出错啦~'); | 518 | $result = array('code' => 400, 'message' => '出错啦~'); |
487 | 519 | ||
488 | - $coupon = CartData::searchCoupon($uid, $couponCode); | ||
489 | - if ($coupon && isset($coupon['code'])) { | ||
490 | - $result = $coupon; | ||
491 | - } | 520 | + do { |
521 | + if (empty($couponCode)) { | ||
522 | + $result['code'] = 401; | ||
523 | + $result['message'] = '优惠券代码为空'; | ||
524 | + break; | ||
525 | + } | ||
526 | + | ||
527 | + $coupon = CartData::searchCoupon($uid, $couponCode); | ||
528 | + if ($coupon && isset($coupon['code'])) { | ||
529 | + $result = $coupon; | ||
530 | + } | ||
531 | + }while(0); | ||
492 | 532 | ||
493 | return $result; | 533 | return $result; |
494 | } | 534 | } |
@@ -583,8 +623,8 @@ class CartModel | @@ -583,8 +623,8 @@ class CartModel | ||
583 | $data = array(); | 623 | $data = array(); |
584 | 624 | ||
585 | $data['name'] = $productData['product_name']; | 625 | $data['name'] = $productData['product_name']; |
586 | - $data['price'] = Helpers::transPrice($productData['market_price']); | ||
587 | - $data['salePrice'] = Helpers::transPrice($productData['sales_price']); | 626 | + $data['price'] = $productData['format_market_price']; |
627 | + $data['salePrice'] = $productData['format_sales_price']; | ||
588 | 628 | ||
589 | if (isset($productData['storage_sum'])) { | 629 | if (isset($productData['storage_sum'])) { |
590 | $data['storage'] = $productData['storage_sum']; | 630 | $data['storage'] = $productData['storage_sum']; |
@@ -45,9 +45,11 @@ class IndexController extends AbstractAction | @@ -45,9 +45,11 @@ class IndexController extends AbstractAction | ||
45 | 'shoppingCartPage' => true, | 45 | 'shoppingCartPage' => true, |
46 | 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey) | 46 | 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey) |
47 | ); | 47 | ); |
48 | + | ||
48 | // 渲染模板 | 49 | // 渲染模板 |
49 | $this->_view->display('index', $data); | 50 | $this->_view->display('index', $data); |
50 | } | 51 | } |
52 | + | ||
51 | /* | 53 | /* |
52 | * 异步获取购物车数据 | 54 | * 异步获取购物车数据 |
53 | */ | 55 | */ |
@@ -70,6 +72,22 @@ class IndexController extends AbstractAction | @@ -70,6 +72,22 @@ class IndexController extends AbstractAction | ||
70 | } | 72 | } |
71 | 73 | ||
72 | /** | 74 | /** |
75 | + * 异步获取购物车商品数目 | ||
76 | + */ | ||
77 | + public function countAction() | ||
78 | + { | ||
79 | + $result = array(); | ||
80 | + | ||
81 | + if ($this->isAjax()) { | ||
82 | + $uid = $this->getUid(true); | ||
83 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
84 | + $result = CartModel::getCartCount($uid, $shoppingKey); | ||
85 | + } | ||
86 | + | ||
87 | + $this->echoJson($result); | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
73 | * 购物车商品选择与取消 | 91 | * 购物车商品选择与取消 |
74 | */ | 92 | */ |
75 | public function selectAction() | 93 | public function selectAction() |
@@ -77,17 +95,13 @@ class IndexController extends AbstractAction | @@ -77,17 +95,13 @@ class IndexController extends AbstractAction | ||
77 | $result = array(); | 95 | $result = array(); |
78 | 96 | ||
79 | if ($this->isAjax()) { | 97 | if ($this->isAjax()) { |
80 | - $productId = $this->post('id', 0); | 98 | + $productId = $this->post('skuList', 0); |
81 | $uid = $this->getUid(true); | 99 | $uid = $this->getUid(true); |
82 | - $shoppingKey = $this->getSession('shoppingKey'); | 100 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); |
83 | $result = CartModel::selectGoods($uid, $productId, $shoppingKey); | 101 | $result = CartModel::selectGoods($uid, $productId, $shoppingKey); |
84 | } | 102 | } |
85 | 103 | ||
86 | - if (empty($result)) { | ||
87 | - echo ' '; | ||
88 | - } else { | ||
89 | - $this->echoJson($result); | ||
90 | - } | 104 | + $this->echoJson($result); |
91 | } | 105 | } |
92 | 106 | ||
93 | /** | 107 | /** |
@@ -98,17 +112,14 @@ class IndexController extends AbstractAction | @@ -98,17 +112,14 @@ class IndexController extends AbstractAction | ||
98 | $result = array(); | 112 | $result = array(); |
99 | 113 | ||
100 | if ($this->isAjax()) { | 114 | if ($this->isAjax()) { |
101 | - $productId = $this->post('id', 0); | 115 | + $sku = $this->post('sku', 0); |
116 | + $count = $this->post('count', 0); | ||
102 | $uid = $this->getUid(true); | 117 | $uid = $this->getUid(true); |
103 | - $shoppingKey = $this->getSession('shoppingKey'); | ||
104 | - $result = CartModel::removeFromCart($uid, $productId, $shoppingKey); | 118 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); |
119 | + $result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey); | ||
105 | } | 120 | } |
106 | 121 | ||
107 | - if (empty($result)) { | ||
108 | - echo ' '; | ||
109 | - } else { | ||
110 | - $this->echoJson($result); | ||
111 | - } | 122 | + $this->echoJson($result); |
112 | } | 123 | } |
113 | 124 | ||
114 | /** | 125 | /** |
@@ -124,11 +135,7 @@ class IndexController extends AbstractAction | @@ -124,11 +135,7 @@ class IndexController extends AbstractAction | ||
124 | $result = CartModel::addToFav($uid, $productId); | 135 | $result = CartModel::addToFav($uid, $productId); |
125 | } | 136 | } |
126 | 137 | ||
127 | - if (empty($result)) { | ||
128 | - echo ' '; | ||
129 | - } else { | ||
130 | - $this->echoJson($result); | ||
131 | - } | 138 | + $this->echoJson($result); |
132 | } | 139 | } |
133 | 140 | ||
134 | /* | 141 | /* |
@@ -182,11 +189,7 @@ class IndexController extends AbstractAction | @@ -182,11 +189,7 @@ class IndexController extends AbstractAction | ||
182 | $result['num'] = $num; | 189 | $result['num'] = $num; |
183 | } | 190 | } |
184 | 191 | ||
185 | - if (empty($result)) { | ||
186 | - echo ' '; | ||
187 | - } else { | ||
188 | - $this->echoJson($result); | ||
189 | - } | 192 | + $this->echoJson($result); |
190 | } | 193 | } |
191 | 194 | ||
192 | /* | 195 | /* |
@@ -212,11 +215,7 @@ class IndexController extends AbstractAction | @@ -212,11 +215,7 @@ class IndexController extends AbstractAction | ||
212 | $result = CartModel::giftProductData($skn, $promotionId); | 215 | $result = CartModel::giftProductData($skn, $promotionId); |
213 | } | 216 | } |
214 | 217 | ||
215 | - if (empty($result)) { | ||
216 | - echo ' '; | ||
217 | - } else { | ||
218 | - $this->echoJson($result); | ||
219 | - } | 218 | + $this->echoJson($result); |
220 | } | 219 | } |
221 | 220 | ||
222 | /** | 221 | /** |
@@ -236,11 +235,7 @@ class IndexController extends AbstractAction | @@ -236,11 +235,7 @@ class IndexController extends AbstractAction | ||
236 | $result = CartModel::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey); | 235 | $result = CartModel::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey); |
237 | } | 236 | } |
238 | 237 | ||
239 | - if (empty($result)) { | ||
240 | - echo ' '; | ||
241 | - } else { | ||
242 | - $this->echoJson($result); | ||
243 | - } | 238 | + $this->echoJson($result); |
244 | } | 239 | } |
245 | 240 | ||
246 | /** | 241 | /** |
@@ -262,11 +257,7 @@ class IndexController extends AbstractAction | @@ -262,11 +257,7 @@ class IndexController extends AbstractAction | ||
262 | $result = CartModel::modifyCartProduct($uid, $params, $shoppingKey); | 257 | $result = CartModel::modifyCartProduct($uid, $params, $shoppingKey); |
263 | } | 258 | } |
264 | 259 | ||
265 | - if (empty($result)) { | ||
266 | - echo ' '; | ||
267 | - } else { | ||
268 | - $this->echoJson($result); | ||
269 | - } | 260 | + $this->echoJson($result); |
270 | } | 261 | } |
271 | 262 | ||
272 | /** | 263 | /** |
@@ -316,11 +307,7 @@ class IndexController extends AbstractAction | @@ -316,11 +307,7 @@ class IndexController extends AbstractAction | ||
316 | $result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin); | 307 | $result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin); |
317 | } | 308 | } |
318 | 309 | ||
319 | - if (empty($result)) { | ||
320 | - echo ' '; | ||
321 | - } else { | ||
322 | - $this->echoJson($result); | ||
323 | - } | 310 | + $this->echoJson($result); |
324 | } | 311 | } |
325 | 312 | ||
326 | /** | 313 | /** |
@@ -331,16 +318,12 @@ class IndexController extends AbstractAction | @@ -331,16 +318,12 @@ class IndexController extends AbstractAction | ||
331 | $result = array(); | 318 | $result = array(); |
332 | 319 | ||
333 | if ($this->isAjax()) { | 320 | if ($this->isAjax()) { |
334 | - $couponCode = $this->get('couponCode', ''); | 321 | + $couponCode = $this->post('couponCode', ''); |
335 | $uid = $this->getUid(true); | 322 | $uid = $this->getUid(true); |
336 | $result = CartModel::searchCoupon($uid, $couponCode); | 323 | $result = CartModel::searchCoupon($uid, $couponCode); |
337 | } | 324 | } |
338 | 325 | ||
339 | - if (empty($result)) { | ||
340 | - echo ' '; | ||
341 | - } else { | ||
342 | - $this->echoJson($result); | ||
343 | - } | 326 | + $this->echoJson($result); |
344 | } | 327 | } |
345 | 328 | ||
346 | /** | 329 | /** |
@@ -464,7 +447,7 @@ class IndexController extends AbstractAction | @@ -464,7 +447,7 @@ class IndexController extends AbstractAction | ||
464 | 447 | ||
465 | // 设置加入购物车凭证到客户端浏览器 | 448 | // 设置加入购物车凭证到客户端浏览器 |
466 | if (isset($result['data']['shopping_key'])) { | 449 | if (isset($result['data']['shopping_key'])) { |
467 | - $this->setCookie('_spk', $shoppingKey); | 450 | + $this->setCookie('_spk', $result['data']['shopping_key']); |
468 | } | 451 | } |
469 | } | 452 | } |
470 | 453 |
-
Please register or login to post a comment