Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into fix/cart
Showing
17 changed files
with
175 additions
and
103 deletions
framework @ e9d066dd
@@ -19,6 +19,8 @@ class CacheConfig | @@ -19,6 +19,8 @@ class CacheConfig | ||
19 | const KEY_ACTION_KIDS_INDEX = 'key_action_kids_index'; // 潮童首页 | 19 | const KEY_ACTION_KIDS_INDEX = 'key_action_kids_index'; // 潮童首页 |
20 | const KEY_ACTION_LIFESTYLE_INDEX = 'key_action_lifestyle_index'; // 创意生活首页 | 20 | const KEY_ACTION_LIFESTYLE_INDEX = 'key_action_lifestyle_index'; // 创意生活首页 |
21 | 21 | ||
22 | + const KEY_ACTION_INDEX_CONFIG = 'key_action_index_config'; // 频道配置 | ||
23 | + | ||
22 | const KEY_ACTION_BOYS_BOTTOM_BANNER = 'key_action_boys_bottom_banner'; // 男生首页底部banner | 24 | const KEY_ACTION_BOYS_BOTTOM_BANNER = 'key_action_boys_bottom_banner'; // 男生首页底部banner |
23 | const KEY_ACTION_GRILS_BOTTOM_BANNER = 'key_action_girls_bottom_banner';// 女生首页底部banner | 25 | const KEY_ACTION_GRILS_BOTTOM_BANNER = 'key_action_girls_bottom_banner';// 女生首页底部banner |
24 | 26 |
@@ -77,7 +77,8 @@ class IndexData | @@ -77,7 +77,8 @@ class IndexData | ||
77 | { | 77 | { |
78 | $param = Yohobuy::param(); | 78 | $param = Yohobuy::param(); |
79 | $param['client_secret'] = Sign::getSign($param); | 79 | $param['client_secret'] = Sign::getSign($param); |
80 | - return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/entrance/getEntrance',$param,3600); | 80 | + |
81 | + return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/entrance/getEntrance', $param); | ||
81 | } | 82 | } |
82 | 83 | ||
83 | } | 84 | } |
@@ -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; |
@@ -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() { |
@@ -84,6 +84,12 @@ function orderCompute() { | @@ -84,6 +84,12 @@ function orderCompute() { | ||
84 | if (!res) { | 84 | if (!res) { |
85 | tip.show('网络出错'); | 85 | tip.show('网络出错'); |
86 | } else { | 86 | } else { |
87 | + if (res.order_amount) { | ||
88 | + res.order_amount = (+res.order_amount).toFixed(2); | ||
89 | + } | ||
90 | + if (res.discount_amount) { | ||
91 | + res.discount_amount = (+res.discount_amount).toFixed(2); | ||
92 | + } | ||
87 | if (res.last_order_amount) { | 93 | if (res.last_order_amount) { |
88 | res.last_order_amount = (+res.last_order_amount).toFixed(2); | 94 | res.last_order_amount = (+res.last_order_amount).toFixed(2); |
89 | } | 95 | } |
@@ -22,18 +22,24 @@ var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()), | @@ -22,18 +22,24 @@ var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()), | ||
22 | ellipsis.init(); | 22 | ellipsis.init(); |
23 | 23 | ||
24 | $newCoupon.on('submit', function() { | 24 | $newCoupon.on('submit', function() { |
25 | + var $this = $(this); | ||
26 | + | ||
27 | + if (!$this.find('[name="couponCode"]').val()) { | ||
28 | + tip.show('请输入优惠券码'); | ||
29 | + return false; | ||
30 | + } | ||
25 | $.ajax({ | 31 | $.ajax({ |
26 | method: 'POST', | 32 | method: 'POST', |
27 | url: '/cart/index/couponSearch', | 33 | url: '/cart/index/couponSearch', |
28 | - data: $(this).serialize() | 34 | + data: $this.serialize() |
29 | }).then(function(res) { | 35 | }).then(function(res) { |
30 | if (res.code === 200) { | 36 | if (res.code === 200) { |
31 | tip.show('优惠券可用'); | 37 | tip.show('优惠券可用'); |
32 | orderInfo('couponCode', res.data.coupon_code); | 38 | orderInfo('couponCode', res.data.coupon_code); |
33 | orderInfo('couponValue', res.data.coupon_value); | 39 | orderInfo('couponValue', res.data.coupon_value); |
34 | - window.location.href = '/shoppingCart/orderEnsure?coupon_code=' + res.data.coupon_code; | 40 | + window.location.href = '/cart/index/orderEnsure'; |
35 | } else { | 41 | } else { |
36 | - tip.show(res.message); | 42 | + tip.show(res.message || '网络错误'); |
37 | } | 43 | } |
38 | }).fail(function() { | 44 | }).fail(function() { |
39 | tip.show('网络错误'); | 45 | tip.show('网络错误'); |
@@ -78,8 +78,14 @@ $.ajax({ | @@ -78,8 +78,14 @@ $.ajax({ | ||
78 | type: 'GET', | 78 | type: 'GET', |
79 | url: '/cart/index/count', | 79 | url: '/cart/index/count', |
80 | success: function(data) { | 80 | success: function(data) { |
81 | + var count; | ||
82 | + | ||
81 | if (data.code === 200) { | 83 | if (data.code === 200) { |
82 | - $cart.find('.num-tag').html(data.data.cart_goods_count).removeClass('hide'); | 84 | + count = data.data.cart_goods_count || 0; |
85 | + if (count > 99) { | ||
86 | + count = '99+'; | ||
87 | + } | ||
88 | + $cart.find('.num-tag').html(count).removeClass('hide'); | ||
83 | } | 89 | } |
84 | } | 90 | } |
85 | }); | 91 | }); |
@@ -480,16 +480,19 @@ $basicBtnC:#eb0313; | @@ -480,16 +480,19 @@ $basicBtnC:#eb0313; | ||
480 | } | 480 | } |
481 | } | 481 | } |
482 | .num-tag { | 482 | .num-tag { |
483 | - position: absolute; | ||
484 | - left: pxToRem(66px); | ||
485 | - height: pxToRem(20px); | ||
486 | display: block; | 483 | display: block; |
487 | - width: pxToRem(36px); | ||
488 | - height: pxToRem(36px); | ||
489 | - background-color: $basicBtnC; | ||
490 | - border-radius: 50%; | 484 | + position: absolute; |
485 | + top: 0; | ||
486 | + left: pxToRem(48px); | ||
487 | + width: pxToRem(72px); | ||
488 | + height: pxToRem(72px); | ||
489 | + font-size: pxToRem(40px); | ||
490 | + line-height: pxToRem(72px); | ||
491 | color: #fff; | 491 | color: #fff; |
492 | - font-size: pxToRem(24px); | 492 | + background: $basicBtnC; |
493 | + text-align: center; | ||
494 | + border-radius: 50%; | ||
495 | + @include transform(scale(0.5)); | ||
493 | &.hide{ | 496 | &.hide{ |
494 | display: none; | 497 | display: none; |
495 | } | 498 | } |
@@ -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> |
@@ -23,12 +23,14 @@ class IndexController extends AbstractAction | @@ -23,12 +23,14 @@ class IndexController extends AbstractAction | ||
23 | // 设置浏览器缓存5分钟 | 23 | // 设置浏览器缓存5分钟 |
24 | $this->setExpires(300); | 24 | $this->setExpires(300); |
25 | } | 25 | } |
26 | + | ||
26 | $result = Index\HomeModel::getChannel(); | 27 | $result = Index\HomeModel::getChannel(); |
27 | $result['background'] = Index\HomeModel::getBgImage(); | 28 | $result['background'] = Index\HomeModel::getBgImage(); |
28 | $result['channelPage'] = true; | 29 | $result['channelPage'] = true; |
29 | $result['showDownloadApp'] = true; | 30 | $result['showDownloadApp'] = true; |
30 | $result['searchUrl'] = Helpers::url('', null, 'search'); | 31 | $result['searchUrl'] = Helpers::url('', null, 'search'); |
31 | $result['pageFooter'] = true; | 32 | $result['pageFooter'] = true; |
33 | + | ||
32 | // 渲染模板 | 34 | // 渲染模板 |
33 | $this->_view->display('index', $result); | 35 | $this->_view->display('index', $result); |
34 | } | 36 | } |
@@ -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 | ||
520 | + do { | ||
521 | + if (empty($couponCode)) { | ||
522 | + $result['code'] = 401; | ||
523 | + $result['message'] = '优惠券代码为空'; | ||
524 | + break; | ||
525 | + } | ||
526 | + | ||
488 | $coupon = CartData::searchCoupon($uid, $couponCode); | 527 | $coupon = CartData::searchCoupon($uid, $couponCode); |
489 | if ($coupon && isset($coupon['code'])) { | 528 | if ($coupon && isset($coupon['code'])) { |
490 | $result = $coupon; | 529 | $result = $coupon; |
491 | } | 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']; |
@@ -20,6 +20,7 @@ use Configs\CacheConfig; | @@ -20,6 +20,7 @@ use Configs\CacheConfig; | ||
20 | class HomeModel | 20 | class HomeModel |
21 | { | 21 | { |
22 | /* 频道选择页取背景图片的位置码 */ | 22 | /* 频道选择页取背景图片的位置码 */ |
23 | + | ||
23 | const CODE_BG = '7ba9118028f9b22090b57341487567eb'; | 24 | const CODE_BG = '7ba9118028f9b22090b57341487567eb'; |
24 | 25 | ||
25 | /* 男生楼层资源的位置码 */ | 26 | /* 男生楼层资源的位置码 */ |
@@ -70,6 +71,7 @@ class HomeModel | @@ -70,6 +71,7 @@ class HomeModel | ||
70 | 71 | ||
71 | /** | 72 | /** |
72 | * 设置选择的频道保存到浏览器COOKIE | 73 | * 设置选择的频道保存到浏览器COOKIE |
74 | + * (已废弃,改成JS设置) | ||
73 | * | 75 | * |
74 | * @param string $cookie | 76 | * @param string $cookie |
75 | * @return void | 77 | * @return void |
@@ -128,7 +130,7 @@ class HomeModel | @@ -128,7 +130,7 @@ class HomeModel | ||
128 | public static function getBottomBanner($channel) | 130 | public static function getBottomBanner($channel) |
129 | { | 131 | { |
130 | $result = false; | 132 | $result = false; |
131 | - if($channel == 2) { | 133 | + if ($channel == 2) { |
132 | $resource = self::CODE_NAME_GIRLS_BOTTOM_BANNER; | 134 | $resource = self::CODE_NAME_GIRLS_BOTTOM_BANNER; |
133 | $cache = CacheConfig::KEY_ACTION_GRILS_BOTTOM_BANNER; | 135 | $cache = CacheConfig::KEY_ACTION_GRILS_BOTTOM_BANNER; |
134 | } else { | 136 | } else { |
@@ -324,45 +326,65 @@ class HomeModel | @@ -324,45 +326,65 @@ class HomeModel | ||
324 | * | 326 | * |
325 | * @return array | 327 | * @return array |
326 | */ | 328 | */ |
327 | - public static function getChannel(){ | 329 | + public static function getChannel() |
330 | + { | ||
328 | $result = array(); | 331 | $result = array(); |
329 | - $result['showYohood'] = false; | ||
330 | 332 | ||
331 | - $data = IndexData::channelData(); | 333 | + if (USE_CACHE) { |
334 | + $key = CacheConfig::KEY_ACTION_INDEX_CONFIG; | ||
335 | + // 先尝试获取一级缓存(master), 有数据则直接返回. | ||
336 | + $result = Cache::get($key, 'master'); | ||
337 | + if (!empty($result)) { | ||
338 | + return $result; | ||
339 | + } | ||
340 | + } | ||
332 | 341 | ||
333 | - $channelList = array(); | ||
334 | - if(isset($data['data']['list'])){ | ||
335 | - foreach($data['data']['list'] as $key => $value){ | ||
336 | - switch ($value['channel_id']) { | ||
337 | - case 5: | ||
338 | - $result['showYohood'] = true; | ||
339 | - $result['yohoodHref'] = '/yohood'; | ||
340 | - break; | 342 | + $data = IndexData::channelData(); |
343 | + if (!empty($data['data']['list'])) { | ||
344 | + $build = array(); | ||
345 | + foreach ($data['data']['list'] as $value) { | ||
346 | + $build = array(); | ||
347 | + switch (intval($value['channel_id'])) { | ||
341 | case 1: | 348 | case 1: |
342 | - $channelList[$key]['href'] = '/boys'; | ||
343 | - $channelList[$key]['title'] = '男生'; | ||
344 | - $channelList[$key]['entitle'] = 'BOYS'; | 349 | + $build['href'] = '/boys'; |
350 | + $build['title'] = '男生'; | ||
351 | + $build['entitle'] = 'BOYS'; | ||
345 | break; | 352 | break; |
346 | case 2: | 353 | case 2: |
347 | - $channelList[$key]['href'] = '/girls'; | ||
348 | - $channelList[$key]['title'] = '女生'; | ||
349 | - $channelList[$key]['entitle'] = 'GIRLS'; | 354 | + $build['href'] = '/girls'; |
355 | + $build['title'] = '女生'; | ||
356 | + $build['entitle'] = 'GIRLS'; | ||
350 | break; | 357 | break; |
351 | case 3: | 358 | case 3: |
352 | - $channelList[$key]['href'] = '/kids'; | ||
353 | - $channelList[$key]['title'] = '潮童'; | ||
354 | - $channelList[$key]['entitle'] = 'KIDS'; | 359 | + $build['href'] = '/kids'; |
360 | + $build['title'] = '潮童'; | ||
361 | + $build['entitle'] = 'KIDS'; | ||
355 | break; | 362 | break; |
356 | case 4: | 363 | case 4: |
357 | - $channelList[$key]['href'] = '/lifestyle'; | ||
358 | - $channelList[$key]['title'] = '创意生活'; | ||
359 | - $channelList[$key]['entitle'] = 'LIFESTYLE'; | 364 | + $build['href'] = '/lifestyle'; |
365 | + $build['title'] = '创意生活'; | ||
366 | + $build['entitle'] = 'LIFESTYLE'; | ||
360 | break; | 367 | break; |
361 | - default: | 368 | + case 5: |
369 | + $result['showYohood'] = true; | ||
370 | + $result['yohoodHref'] = 'http://yohood.cn'; | ||
362 | break; | 371 | break; |
372 | + default: | ||
373 | + continue; | ||
363 | } | 374 | } |
375 | + $result['channelList'][] = $build; | ||
376 | + } | ||
377 | + } | ||
378 | + | ||
379 | + if (USE_CACHE) { | ||
380 | + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. | ||
381 | + if (empty($result)) { | ||
382 | + $result = Cache::get($key, 'slave'); | ||
383 | + } | ||
384 | + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 | ||
385 | + else { | ||
386 | + Cache::set($key, $result); | ||
364 | } | 387 | } |
365 | - $result['channelList'] = $channelList; | ||
366 | } | 388 | } |
367 | 389 | ||
368 | return $result; | 390 | return $result; |
@@ -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,18 +95,14 @@ class IndexController extends AbstractAction | @@ -77,18 +95,14 @@ 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); | 104 | $this->echoJson($result); |
90 | } | 105 | } |
91 | - } | ||
92 | 106 | ||
93 | /** | 107 | /** |
94 | * 移出购物车 | 108 | * 移出购物车 |
@@ -98,18 +112,15 @@ class IndexController extends AbstractAction | @@ -98,18 +112,15 @@ 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); | 122 | $this->echoJson($result); |
111 | } | 123 | } |
112 | - } | ||
113 | 124 | ||
114 | /** | 125 | /** |
115 | * 移入收藏夹 | 126 | * 移入收藏夹 |
@@ -124,12 +135,8 @@ class IndexController extends AbstractAction | @@ -124,12 +135,8 @@ 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); | 138 | $this->echoJson($result); |
131 | } | 139 | } |
132 | - } | ||
133 | 140 | ||
134 | /* | 141 | /* |
135 | * 赠品页面 | 142 | * 赠品页面 |
@@ -182,12 +189,8 @@ class IndexController extends AbstractAction | @@ -182,12 +189,8 @@ 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); | 192 | $this->echoJson($result); |
189 | } | 193 | } |
190 | - } | ||
191 | 194 | ||
192 | /* | 195 | /* |
193 | * 获取购物车加价购商品数据模板 | 196 | * 获取购物车加价购商品数据模板 |
@@ -212,12 +215,8 @@ class IndexController extends AbstractAction | @@ -212,12 +215,8 @@ 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); | 218 | $this->echoJson($result); |
219 | } | 219 | } |
220 | - } | ||
221 | 220 | ||
222 | /** | 221 | /** |
223 | * 修改购物车商品数量 | 222 | * 修改购物车商品数量 |
@@ -236,12 +235,8 @@ class IndexController extends AbstractAction | @@ -236,12 +235,8 @@ 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); | 238 | $this->echoJson($result); |
243 | } | 239 | } |
244 | - } | ||
245 | 240 | ||
246 | /** | 241 | /** |
247 | * 修改购物车商品数据 | 242 | * 修改购物车商品数据 |
@@ -262,12 +257,8 @@ class IndexController extends AbstractAction | @@ -262,12 +257,8 @@ 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); | 260 | $this->echoJson($result); |
269 | } | 261 | } |
270 | - } | ||
271 | 262 | ||
272 | /** | 263 | /** |
273 | * 购物车结算请求 | 264 | * 购物车结算请求 |
@@ -316,12 +307,8 @@ class IndexController extends AbstractAction | @@ -316,12 +307,8 @@ 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); | 310 | $this->echoJson($result); |
323 | } | 311 | } |
324 | - } | ||
325 | 312 | ||
326 | /** | 313 | /** |
327 | * 购物车输入优惠券码使用优惠券 | 314 | * 购物车输入优惠券码使用优惠券 |
@@ -331,17 +318,13 @@ class IndexController extends AbstractAction | @@ -331,17 +318,13 @@ 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); | 326 | $this->echoJson($result); |
343 | } | 327 | } |
344 | - } | ||
345 | 328 | ||
346 | /** | 329 | /** |
347 | * 购物车结算--获取优惠券列表 | 330 | * 购物车结算--获取优惠券列表 |
@@ -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