Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop
Showing
9 changed files
with
848 additions
and
7 deletions
@@ -179,6 +179,41 @@ class CartData | @@ -179,6 +179,41 @@ class CartData | ||
179 | } | 179 | } |
180 | 180 | ||
181 | /** | 181 | /** |
182 | + * 增减购物车商品数量 | ||
183 | + * | ||
184 | + * @param int $uid 用户ID | ||
185 | + * @param string $sku 商品SKU | ||
186 | + * @param int $increaseNum 增加的数目 | ||
187 | + * @param int $decreaseNum 减少的数目 | ||
188 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
189 | + * @return array 接口返回的数据 | ||
190 | + */ | ||
191 | + public static function modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey) | ||
192 | + { | ||
193 | + $param = Yohobuy::param(); | ||
194 | + $param['method'] = 'app.Shopping.increase'; | ||
195 | + $param['product_sku'] = $sku; | ||
196 | + | ||
197 | + if (!empty($increaseNum)) { | ||
198 | + $param['increase_number'] = $increaseNum; | ||
199 | + } | ||
200 | + if (!empty($decreaseNum)) { | ||
201 | + $param['decrease_number'] = $decreaseNum; | ||
202 | + } | ||
203 | + | ||
204 | + if (!empty($uid)) { | ||
205 | + $param['uid'] = $uid; | ||
206 | + } | ||
207 | + if ($shoppingKey !== null) { | ||
208 | + $param['shopping_key'] = $shoppingKey; | ||
209 | + } | ||
210 | + | ||
211 | + $param['client_secret'] = Sign::getSign($param); | ||
212 | + | ||
213 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
214 | + } | ||
215 | + | ||
216 | + /** | ||
182 | * 修改购物车商品数据 | 217 | * 修改购物车商品数据 |
183 | * | 218 | * |
184 | * @param int $uid 用户ID | 219 | * @param int $uid 用户ID |
1 | +{{> layout/header}} | ||
2 | +<div class="gift-advance-page yoho-page"> | ||
3 | + {{# shoppingCart}} | ||
4 | + {{#if gift}} | ||
5 | + {{# gift}} | ||
6 | + {{> shopping-cart/gift-advance-good}} | ||
7 | + {{/ gift}} | ||
8 | + {{^}} | ||
9 | + {{# advance}} | ||
10 | + <div class="advance-block"> | ||
11 | + <p class="title">{{title}}</p> | ||
12 | + {{# goods}} | ||
13 | + {{> shopping-cart/gift-advance-good}} | ||
14 | + {{/ goods}} | ||
15 | + </div> | ||
16 | + {{/ advance}} | ||
17 | + {{/if}} | ||
18 | + {{/ shoppingCart}} | ||
19 | +</div> | ||
20 | +{{> layout/footer}} |
1 | +{{> layout/header}} | ||
2 | +<div id="mainCart" class="shopping-cart-page yoho-page"> | ||
3 | + {{# shoppingCart}} | ||
4 | + {{#if cartNav}} | ||
5 | + <ul class="cart-nav clearfix"> | ||
6 | + <li class="active"> | ||
7 | + <span> | ||
8 | + 普通商品({{commonGoodsCount}}) | ||
9 | + </span> | ||
10 | + </li> | ||
11 | + <li> | ||
12 | + <span> | ||
13 | + 预售商品({{presellGoodsCount}}) | ||
14 | + </span> | ||
15 | + </li> | ||
16 | + </ul> | ||
17 | + {{/if}} | ||
18 | + | ||
19 | + {{#if showLoginInfo}} | ||
20 | + <p class="login-info"> | ||
21 | + <span class="iconfont"></span> | ||
22 | + 请您先 | ||
23 | + <a class="btn btn-login">登录</a> | ||
24 | + 可以同步电脑和手机中的商品 | ||
25 | + </p> | ||
26 | + {{/if}} | ||
27 | + | ||
28 | + {{# commonCart}} | ||
29 | + <div class="cart-content common"> | ||
30 | + {{> shopping-cart/cart-content}} | ||
31 | + </div> | ||
32 | + {{/ commonCart}} | ||
33 | + | ||
34 | + {{# preSellCart}} | ||
35 | + <div class="cart-content presell hide"> | ||
36 | + <p class="presell-info"> | ||
37 | + <span class="iconfont"></span> | ||
38 | + <span class="txt">预售商品全场包邮,到货后立即发货</span> | ||
39 | + <span class="txt">预售商品不参加活动,不可使用优惠券</span> | ||
40 | + </p> | ||
41 | + {{> shopping-cart/cart-content}} | ||
42 | + </div> | ||
43 | + {{/ preSellCart}} | ||
44 | + | ||
45 | + {{/ shoppingCart}} | ||
46 | +</div> | ||
47 | +<div id="advanceBuy" class="shopping-cart-page yoho-page hide"> | ||
48 | +{{# shoppingCart}} | ||
49 | + {{# commonCart}} | ||
50 | + {{# advanceBuy}} | ||
51 | + <span> | ||
52 | + {{promotionTitle}} | ||
53 | + </span> | ||
54 | + {{# goods}} | ||
55 | + {{> shopping-cart/gift-advance-good}} | ||
56 | + {{/ goods}} | ||
57 | + {{/ advanceBuy}} | ||
58 | + {{/ commonCart}} | ||
59 | +{{/ shoppingCart}} | ||
60 | +</div> | ||
61 | + | ||
62 | +<div class="shopping-cart-zero yoho-page hide"> | ||
63 | + <div class="cart-zero"> | ||
64 | + <i class="iconfont"></i> | ||
65 | + <p>您的购物车暂无商品</p> | ||
66 | + <a href="">随便逛逛</a> | ||
67 | + </div> | ||
68 | + {{> product/recommend-for-you}} | ||
69 | +</div> | ||
70 | + | ||
71 | + {{> shopping-cart/chose-panel}} | ||
72 | +{{> layout/footer}} |
1 | +{{> layout/header}} | ||
2 | +<div class="order-ensure-page yoho-page"> | ||
3 | + {{# orderEnsure}} | ||
4 | + <a class="address-wrap block" data-id="{{addressId}}" href="/shoppingCart/selectAddress"> | ||
5 | + <p class="infos"> | ||
6 | + 收货地址 | ||
7 | + <span class="per-info">{{name}} {{phoneNum}}</span> | ||
8 | + <span class="address">{{area}} {{address}}</span> | ||
9 | + </p> | ||
10 | + <span class="iconfont"></span> | ||
11 | + </a> | ||
12 | + | ||
13 | + <section class="dispatch block"> | ||
14 | + <div class="sub-block"> | ||
15 | + <h3 class="title">配送方式</h3> | ||
16 | + <ul class="dispatch-mode clearfix"> | ||
17 | + {{#each dispatchMode}} | ||
18 | + <li {{#if isSelected}}class="chosed"{{/if}} data-id="{{id}}">{{name}}</li> | ||
19 | + {{/each}} | ||
20 | + </ul> | ||
21 | + </div> | ||
22 | + | ||
23 | + <div class="sub-block"> | ||
24 | + <h3 class="title">送货时间</h3> | ||
25 | + <ul class="dispatch-time clearfix"> | ||
26 | + {{#each dispatchTime}} | ||
27 | + <li {{#if isSelected}}class="chosed"{{/if}} data-id="{{id}}">{{name}}</li> | ||
28 | + {{/each}} | ||
29 | + </ul> | ||
30 | + </div> | ||
31 | + </section> | ||
32 | + | ||
33 | + <section class="block"> | ||
34 | + <h3 class="title">商品</h3> | ||
35 | + <div class="goods"> | ||
36 | + {{#each goods}} | ||
37 | + {{> me/order/good}} | ||
38 | + {{/each}} | ||
39 | + </div> | ||
40 | + </section> | ||
41 | + | ||
42 | + <section class="block"> | ||
43 | + <ul class="sale-invoice"> | ||
44 | + {{# coupon}} | ||
45 | + <li class="coupon"> | ||
46 | + <a href="/shoppingCart/selectCoupon"> | ||
47 | + <span class="title">优惠券</span> | ||
48 | + {{#if count}} | ||
49 | + <span class="coupon-count"> | ||
50 | + {{count}}张可用 | ||
51 | + </span> | ||
52 | + {{/if}} | ||
53 | + | ||
54 | + {{#if value}} | ||
55 | + <span class="used coupon-use"> | ||
56 | + -¥{{value}} | ||
57 | + <i class="iconfont"></i> | ||
58 | + </span> | ||
59 | + {{^}} | ||
60 | + <span class="not-used coupon-use"> | ||
61 | + 未使用 | ||
62 | + <i class="iconfont"></i> | ||
63 | + </span> | ||
64 | + {{/if}} | ||
65 | + </a> | ||
66 | + </li> | ||
67 | + {{/coupon}} | ||
68 | + | ||
69 | + <li class="coin" data-yoho-coin="{{yohoCoin}}"> | ||
70 | + <span class="title">YOHO币</span> | ||
71 | + <span class="desc">可抵用¥{{yohoCoin}}</span> | ||
72 | + <span class="coin-check"> | ||
73 | + <em>- ¥ {{yohoCoin}}</em> | ||
74 | + <i class="iconfont checkbox icon-cb-checked"></i> | ||
75 | + </span> | ||
76 | + </li> | ||
77 | + | ||
78 | + {{#if invoice}} | ||
79 | + <li class="invoice {{#if needInvoice}}focus{{/if}}"> | ||
80 | + <span class="title">发票</span> | ||
81 | + <span class="iconfont checkbox {{#if needInvoice}}icon-cb-checked{{else}}icon-checkbox{{/if}}"></span> | ||
82 | + <form id="invoice"> | ||
83 | + <input type="text" name="invoice-title" value="{{invoiceText}}" placeholder="发票抬头"> | ||
84 | + <label> | ||
85 | + 发票类型 | ||
86 | + <select class="invoice-type" name="invoice-type"> | ||
87 | + {{# invoice}} | ||
88 | + <option value="{{id}}" {{#if isSelected}}selected{{/if}}>{{name}}</option> | ||
89 | + {{/ invoice}} | ||
90 | + </select> | ||
91 | + </label> | ||
92 | + </form> | ||
93 | + </li> | ||
94 | + {{/if}} | ||
95 | + </ul> | ||
96 | + | ||
97 | + <form id="msg" action="" method="post"> | ||
98 | + <input type="text" name="msg" value="{{msg}}" placeholder="留言"> | ||
99 | + </form> | ||
100 | + </section> | ||
101 | + | ||
102 | + <section class="price-cal block"> | ||
103 | + <ul class="total"> | ||
104 | + <li> | ||
105 | + <span>总价</span> | ||
106 | + ¥{{sumPrice}} | ||
107 | + </li> | ||
108 | + <li> | ||
109 | + <span>活动价</span> | ||
110 | + - ¥{{salePrice}} | ||
111 | + </li> | ||
112 | + <li> | ||
113 | + <span>运费</span> | ||
114 | + + {{freight}} | ||
115 | + </li> | ||
116 | + {{#couponPrice}} | ||
117 | + <li> | ||
118 | + <span>优惠券</span> | ||
119 | + - ¥{{.}} | ||
120 | + </li> | ||
121 | + {{/couponPrice}} | ||
122 | + <li> | ||
123 | + <span>YOHO币</span> | ||
124 | + - ¥{{yohoCoin}} | ||
125 | + </li> | ||
126 | + <li class="cost"> | ||
127 | + 应付金额: <em>¥{{price}}</em> | ||
128 | + </li> | ||
129 | + </ul> | ||
130 | + </section> | ||
131 | + | ||
132 | + <ul class="pay-mode"> | ||
133 | + {{# paymentWay}} | ||
134 | + <li class="{{#if default}}default{{/if}}" data-pay-type="{{paymentType}}" data-pay-id="{{id}}"> | ||
135 | + <span class="iconfont"> | ||
136 | + {{#if default}} | ||
137 | +  | ||
138 | + {{else}} | ||
139 | +  | ||
140 | + {{/if}} | ||
141 | + </span> | ||
142 | + {{name}} | ||
143 | + </li> | ||
144 | + {{/ paymentWay}} | ||
145 | + </ul> | ||
146 | + {{/ orderEnsure}} | ||
147 | +</div> | ||
148 | +<script id="tmpl-price" type="text/tmpl"> | ||
149 | + <ul class="total"> | ||
150 | + <li> | ||
151 | + <span>总价</span> | ||
152 | + ¥\{{sumPrice}} | ||
153 | + </li> | ||
154 | + <li> | ||
155 | + <span>活动价</span> | ||
156 | + - ¥\{{salePrice}} | ||
157 | + </li> | ||
158 | + <li> | ||
159 | + <span>运费</span> | ||
160 | + + \{{freight}} | ||
161 | + </li> | ||
162 | + \{{#couponPrice}} | ||
163 | + <li> | ||
164 | + <span>优惠券</span> | ||
165 | + - ¥\{{.}} | ||
166 | + </li> | ||
167 | + \{{/couponPrice}} | ||
168 | + <li> | ||
169 | + <span>YOHO币</span> | ||
170 | + - ¥\{{yohoCoin}} | ||
171 | + </li> | ||
172 | + <li class="cost"> | ||
173 | + 应付金额: <em>¥\{{price}}</em> | ||
174 | + </li> | ||
175 | + </ul> | ||
176 | +</script> | ||
177 | +{{> layout/footer}} |
1 | +{{> layout/header}} | ||
2 | +<div class="my-address-page select-address-page yoho-page"> | ||
3 | + <div class="page-wrap"> | ||
4 | + {{# address}} | ||
5 | + <a class="address-item" data-address-id="{{address_id}}" href="/shoppingCart/orderEnsure"> | ||
6 | + <span class="name">{{consignee}}</span> | ||
7 | + <span class="tel">{{mobile}}</span> | ||
8 | + <p class="address-info">{{area}} {{address}}</p> | ||
9 | + <div class="action iconfont"> | ||
10 | + <span class="edit" data-href="/home/addressAct?id={{address_id}}&refer=shopping"></span> | ||
11 | + <span class="del" data-id="{{address_id}}"></span> | ||
12 | + </div> | ||
13 | + </a> | ||
14 | + {{/ address}} | ||
15 | + | ||
16 | + <a class="add-address" data-href="/home/addressAct?refer=shopping"> | ||
17 | + 添加新地址 | ||
18 | + </a> | ||
19 | + | ||
20 | + <div class="confim-mask hide"> | ||
21 | + <div class="confim-box"> | ||
22 | + <div class="content"> | ||
23 | + 您确定要删除地址? | ||
24 | + </div> | ||
25 | + <div class="action"> | ||
26 | + <span class="cancel"> | ||
27 | + 取消 | ||
28 | + </span> | ||
29 | + <span class="confim"> | ||
30 | + 确认 | ||
31 | + </span> | ||
32 | + </div> | ||
33 | + </div> | ||
34 | + </div> | ||
35 | + </div> | ||
36 | +</div> | ||
37 | +{{> layout/footer}} |
1 | +{{> layout/header}} | ||
2 | +<div class="yoho-page select-coupon-page my-coupon-page"> | ||
3 | + <form id="new-coupon" method="POST" action=""> | ||
4 | + <input type="text" name="couponCode" value="" placeholder="输入优惠券码"> | ||
5 | + <button type="submit" class="submit">确定</button> | ||
6 | + </form> | ||
7 | + <div id="coupon-list" class="coupon-list"></div> | ||
8 | + <div class="not-avaliable-coupon-line hide">不可使用的优惠券</div> | ||
9 | + <div id="coupon-list-not" class="coupon-list"></div> | ||
10 | +</div> | ||
11 | +<script id="tmpl-coupon" type="text/tmpl"> | ||
12 | +\{{#coupons}} | ||
13 | + \{{^ notAvailable}} | ||
14 | + <a class="employ-main" data-coupon-code="\{{ couponCode}}" data-coupon-value="\{{ couponValue}}" href="/shoppingCart/orderEnsure"> | ||
15 | + <span>\{{ couponValue}}</span> | ||
16 | + <p class="coupon-name">\{{ couponDetailInfomation}}</p> | ||
17 | + <p>有效期:\{{ couponValidity}}</p> | ||
18 | + </a> | ||
19 | + \{{/ notAvailable}} | ||
20 | +\{{/coupons}} | ||
21 | +</script> | ||
22 | +<script id="tmpl-coupon-not-avaliable" type="text/tmpl"> | ||
23 | +\{{# notAvailableCoupons}} | ||
24 | + <div class="employ-main not-avaliable"> | ||
25 | + <span>\{{ couponValue}}</span> | ||
26 | + <p class="coupon-name">\{{ couponDetailInfomation}}</p> | ||
27 | + <p>有效期:\{{ couponValidity}}</p> | ||
28 | + </div> | ||
29 | +\{{/ notAvailableCoupons}} | ||
30 | +</script> | ||
31 | +<script id="tmpl-no-coupon" type="text/tmpl"> | ||
32 | +<div class="coupon-list"> | ||
33 | + <div class="null"> | ||
34 | + <i></i> | ||
35 | + <p>您还没有优惠券!</p> | ||
36 | + </div> | ||
37 | +</div> | ||
38 | +</script> | ||
39 | +{{> layout/footer}} |
@@ -10,6 +10,20 @@ use Plugin\Helpers; | @@ -10,6 +10,20 @@ use Plugin\Helpers; | ||
10 | */ | 10 | */ |
11 | class ShoppingcartController extends AbstractAction | 11 | class ShoppingcartController extends AbstractAction |
12 | { | 12 | { |
13 | + /** | ||
14 | + * 通过当前用户审判是否跳到登录 | ||
15 | + * | ||
16 | + * @param boolean $useSession (true:从服务端session中检查, false:从客户端cookie中检查) | ||
17 | + * @return void | ||
18 | + */ | ||
19 | + protected function auditJumpLogin($useSession = true) | ||
20 | + { | ||
21 | + $uid = $this->getUid($useSession); | ||
22 | + if (!$uid) { | ||
23 | + $this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN)))); | ||
24 | + } | ||
25 | + } | ||
26 | + | ||
13 | /* | 27 | /* |
14 | * 购物车首页 | 28 | * 购物车首页 |
15 | */ | 29 | */ |
@@ -191,6 +205,30 @@ class ShoppingcartController extends AbstractAction | @@ -191,6 +205,30 @@ class ShoppingcartController extends AbstractAction | ||
191 | } | 205 | } |
192 | 206 | ||
193 | /** | 207 | /** |
208 | + * 修改购物车商品数量 | ||
209 | + */ | ||
210 | + public function modifyNumAction() | ||
211 | + { | ||
212 | + $result = array(); | ||
213 | + | ||
214 | + if ($this->isAjax()) { | ||
215 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
216 | + $uid = $this->getUid(true); | ||
217 | + | ||
218 | + $sku= $this->post('sku', 0); | ||
219 | + $increaseNum = $this->post('increaseNum', null); | ||
220 | + $decreaseNum = $this->post('decreaseNum', null); | ||
221 | + $result = CartModel::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey); | ||
222 | + } | ||
223 | + | ||
224 | + if (empty($result)) { | ||
225 | + echo ' '; | ||
226 | + } else { | ||
227 | + $this->echoJson($result); | ||
228 | + } | ||
229 | + } | ||
230 | + | ||
231 | + /** | ||
194 | * 修改购物车商品数据 | 232 | * 修改购物车商品数据 |
195 | */ | 233 | */ |
196 | public function modifyAction() | 234 | public function modifyAction() |
@@ -221,17 +259,28 @@ class ShoppingcartController extends AbstractAction | @@ -221,17 +259,28 @@ class ShoppingcartController extends AbstractAction | ||
221 | */ | 259 | */ |
222 | public function orderEnsureAction() | 260 | public function orderEnsureAction() |
223 | { | 261 | { |
262 | + // 审判跳转登录页 | ||
263 | + $this->auditJumpLogin(); | ||
264 | + | ||
224 | $this->setTitle('购物车'); | 265 | $this->setTitle('购物车'); |
225 | $this->setNavHeader('购物车'); | 266 | $this->setNavHeader('购物车'); |
226 | 267 | ||
227 | - $cartType = $this->post('cartType', 'ordinary'); | 268 | + // 购物车商品为空跳转到购物车页面 |
269 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
270 | + $uid = $this->getUid(true); | ||
271 | + $cartGoods = CartModel::getCartData($uid, $shoppingKey); | ||
272 | + if (empty($cartGoods) || isset($cartGoods['isEmptyCart'])) { | ||
273 | + $this->go(Helpers::url('/shoppingcart')); | ||
274 | + } | ||
275 | + | ||
276 | + $cartType = $this->get('cartType', 'ordinary'); | ||
228 | $cookieData = $this->getCookie('order-info', null); | 277 | $cookieData = $this->getCookie('order-info', null); |
229 | $uid = $this->getUid(true); | 278 | $uid = $this->getUid(true); |
230 | $data = array( | 279 | $data = array( |
231 | 'orderEnsurePage' => true, | 280 | 'orderEnsurePage' => true, |
232 | 'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData) | 281 | 'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData) |
233 | ); | 282 | ); |
234 | - // var_dump($data); | 283 | + |
235 | $this->_view->display('order-ensure', $data); | 284 | $this->_view->display('order-ensure', $data); |
236 | } | 285 | } |
237 | 286 | ||
@@ -288,7 +337,6 @@ class ShoppingcartController extends AbstractAction | @@ -288,7 +337,6 @@ class ShoppingcartController extends AbstractAction | ||
288 | 337 | ||
289 | if ($this->isAjax()) { | 338 | if ($this->isAjax()) { |
290 | $uid = $this->getUid(true); | 339 | $uid = $this->getUid(true); |
291 | - $page = $this->get('page', 1); | ||
292 | $result = CartModel::getCouponList($uid); | 340 | $result = CartModel::getCouponList($uid); |
293 | } | 341 | } |
294 | 342 | ||
@@ -304,6 +352,9 @@ class ShoppingcartController extends AbstractAction | @@ -304,6 +352,9 @@ class ShoppingcartController extends AbstractAction | ||
304 | */ | 352 | */ |
305 | public function selectAddressAction() | 353 | public function selectAddressAction() |
306 | { | 354 | { |
355 | + // 审判跳转登录页 | ||
356 | + $this->auditJumpLogin(); | ||
357 | + | ||
307 | // 设置网站标题 | 358 | // 设置网站标题 |
308 | $this->setTitle('选择地址'); | 359 | $this->setTitle('选择地址'); |
309 | $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); | 360 | $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); |
@@ -323,9 +374,13 @@ class ShoppingcartController extends AbstractAction | @@ -323,9 +374,13 @@ class ShoppingcartController extends AbstractAction | ||
323 | */ | 374 | */ |
324 | public function selectCouponAction() | 375 | public function selectCouponAction() |
325 | { | 376 | { |
377 | + // 审判跳转登录页 | ||
378 | + $this->auditJumpLogin(); | ||
379 | + | ||
326 | // 设置网站标题 | 380 | // 设置网站标题 |
327 | $this->setTitle('选择优惠券'); | 381 | $this->setTitle('选择优惠券'); |
328 | $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); | 382 | $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); |
383 | + | ||
329 | $this->_view->display('select-coupon', array( | 384 | $this->_view->display('select-coupon', array( |
330 | 'selectCouponPage' => true, | 385 | 'selectCouponPage' => true, |
331 | 'pageFooter' => true | 386 | 'pageFooter' => true |
@@ -298,6 +298,29 @@ class CartModel | @@ -298,6 +298,29 @@ class CartModel | ||
298 | } | 298 | } |
299 | 299 | ||
300 | /** | 300 | /** |
301 | + * 修改购物车商品数量 | ||
302 | + * | ||
303 | + * @param int $uid 用户ID | ||
304 | + * @param string $sku 商品SKU | ||
305 | + * @param int $increaseNum 增加的数目 | ||
306 | + * @param int $decreaseNum 减少的数目 | ||
307 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
308 | + * @return array 接口返回的数据 | ||
309 | + */ | ||
310 | + public static function modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey) | ||
311 | + { | ||
312 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
313 | + | ||
314 | + $modify = CartData::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey); | ||
315 | + if ($modify && isset($modify['code'])) { | ||
316 | + $result['code'] = $modify['code']; | ||
317 | + $result['message'] = $modify['message']; | ||
318 | + } | ||
319 | + | ||
320 | + return $result; | ||
321 | + } | ||
322 | + | ||
323 | + /** | ||
301 | * 修改购物车商品数据 | 324 | * 修改购物车商品数据 |
302 | * | 325 | * |
303 | * @param int $uid 用户ID | 326 | * @param int $uid 用户ID |
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | use Action\AbstractAction; | 3 | use Action\AbstractAction; |
4 | +use Index\CartModel; | ||
5 | +use Index\UserModel; | ||
6 | +use Plugin\Helpers; | ||
4 | 7 | ||
5 | /** | 8 | /** |
6 | * 购物车相关的控制器 | 9 | * 购物车相关的控制器 |
@@ -8,14 +11,394 @@ use Action\AbstractAction; | @@ -8,14 +11,394 @@ use Action\AbstractAction; | ||
8 | * @name IndexController | 11 | * @name IndexController |
9 | * @package Cart | 12 | * @package Cart |
10 | * @copyright yoho.inc | 13 | * @copyright yoho.inc |
11 | - * @version 1.0 (2015-10-28 16:34:17) | ||
12 | - * @author fei.hong <fei.hong@yoho.cn> | 14 | + * @version 1.0 (2015-12-16 11:47:20) |
15 | + * @author gtskk <iamgtskk@gmail.com> | ||
13 | */ | 16 | */ |
14 | class IndexController extends AbstractAction | 17 | class IndexController extends AbstractAction |
15 | { | 18 | { |
19 | + /** | ||
20 | + * 通过当前用户审判是否跳到登录 | ||
21 | + * | ||
22 | + * @param boolean $useSession (true:从服务端session中检查, false:从客户端cookie中检查) | ||
23 | + * @return void | ||
24 | + */ | ||
25 | + protected function auditJumpLogin($useSession = true) | ||
26 | + { | ||
27 | + $uid = $this->getUid($useSession); | ||
28 | + if (!$uid) { | ||
29 | + $this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN)))); | ||
30 | + } | ||
31 | + } | ||
32 | + | ||
33 | + /* | ||
34 | + * 购物车首页 | ||
35 | + */ | ||
16 | public function indexAction() | 36 | public function indexAction() |
17 | { | 37 | { |
18 | - // 跳转到老版 | ||
19 | - // $this->go(OLD_MAIN . '/cart/index/index'); | 38 | + $this->setTitle('购物车'); |
39 | + $this->setNavHeader('购物车'); | ||
40 | + | ||
41 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
42 | + $uid = $this->getUid(true); | ||
43 | + | ||
44 | + $data = array( | ||
45 | + 'shoppingCartPage' => true, | ||
46 | + 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey) | ||
47 | + ); | ||
48 | + | ||
49 | + // 渲染模板 | ||
50 | + $this->_view->display('index', $data); | ||
51 | + } | ||
52 | + /* | ||
53 | + * 异步获取购物车数据 | ||
54 | + */ | ||
55 | + public function getCartDataAction() | ||
56 | + { | ||
57 | + $result = array(); | ||
58 | + | ||
59 | + if ($this->isAjax()) { | ||
60 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
61 | + $uid = $this->getUid(true); | ||
62 | + | ||
63 | + $result = CartModel::getCartData($uid, $shoppingKey); | ||
64 | + } | ||
65 | + | ||
66 | + if (empty($result)) { | ||
67 | + echo ' '; | ||
68 | + } else { | ||
69 | + $this->echoJson($result); | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * 购物车商品选择与取消 | ||
75 | + */ | ||
76 | + public function selectAction() | ||
77 | + { | ||
78 | + $result = array(); | ||
79 | + | ||
80 | + if ($this->isAjax()) { | ||
81 | + $productId = $this->post('id', 0); | ||
82 | + $uid = $this->getUid(true); | ||
83 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
84 | + $result = CartModel::selectGoods($uid, $productId, $shoppingKey); | ||
85 | + } | ||
86 | + | ||
87 | + if (empty($result)) { | ||
88 | + echo ' '; | ||
89 | + } else { | ||
90 | + $this->echoJson($result); | ||
91 | + } | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * 移出购物车 | ||
96 | + */ | ||
97 | + public function delAction() | ||
98 | + { | ||
99 | + $result = array(); | ||
100 | + | ||
101 | + if ($this->isAjax()) { | ||
102 | + $productId = $this->post('id', 0); | ||
103 | + $uid = $this->getUid(true); | ||
104 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
105 | + $result = CartModel::removeFromCart($uid, $productId, $shoppingKey); | ||
106 | + } | ||
107 | + | ||
108 | + if (empty($result)) { | ||
109 | + echo ' '; | ||
110 | + } else { | ||
111 | + $this->echoJson($result); | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * 移入收藏夹 | ||
117 | + */ | ||
118 | + public function colAction() | ||
119 | + { | ||
120 | + $result = array(); | ||
121 | + | ||
122 | + if ($this->isAjax()) { | ||
123 | + $productId = $this->post('id', 0); | ||
124 | + $uid = $this->getUid(true); | ||
125 | + $result = CartModel::addToFav($uid, $productId); | ||
126 | + } | ||
127 | + | ||
128 | + if (empty($result)) { | ||
129 | + echo ' '; | ||
130 | + } else { | ||
131 | + $this->echoJson($result); | ||
132 | + } | ||
133 | + } | ||
134 | + | ||
135 | + /* | ||
136 | + * 赠品页面 | ||
137 | + */ | ||
138 | + public function giftAction() | ||
139 | + { | ||
140 | + $this->setTitle('赠品'); | ||
141 | + $this->setNavHeader('赠品'); | ||
142 | + | ||
143 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
144 | + $uid = $this->getUid(true); | ||
145 | + $cartType = $this->get('cartType', 'ordinary'); | ||
146 | + $data = array('shoppingCartPage' => true); | ||
147 | + $data += CartModel::getCartData($uid, $shoppingKey, $cartType, true); | ||
148 | + | ||
149 | + // 渲染模板 | ||
150 | + $this->_view->display('gift-advance-good', $data); | ||
151 | + } | ||
152 | + | ||
153 | + /* | ||
154 | + * 加价购页面 | ||
155 | + */ | ||
156 | + public function advanceBuyAction() | ||
157 | + { | ||
158 | + $this->setTitle('加价购'); | ||
159 | + $this->setNavHeader('加价购'); | ||
160 | + | ||
161 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
162 | + $uid = $this->getUid(true); | ||
163 | + $cartType = $this->get('cartType', 'ordinary'); | ||
164 | + $data = array('shoppingCartPage' => true); | ||
165 | + $data += CartModel::getCartData($uid, $shoppingKey, $cartType, false, true); | ||
166 | + | ||
167 | + // 渲染模板 | ||
168 | + $this->_view->display('gift-advance-good', $data); | ||
169 | + } | ||
170 | + | ||
171 | + /* | ||
172 | + * 获取购物车商品数据 | ||
173 | + */ | ||
174 | + public function goodinfoAction() | ||
175 | + { | ||
176 | + $result = array(); | ||
177 | + | ||
178 | + if ($this->isAjax()) { | ||
179 | + $num = $this->get('buy_num', 1); | ||
180 | + $skn = $this->get('id', 1); | ||
181 | + $uid = $this->getUid(true); | ||
182 | + $result = CartModel::cartProductData($uid, $skn, $num); // 测试skn的ID为51172055 | ||
183 | + $result['num'] = $num; | ||
184 | + } | ||
185 | + | ||
186 | + if (empty($result)) { | ||
187 | + echo ' '; | ||
188 | + } else { | ||
189 | + $this->echoJson($result); | ||
190 | + } | ||
191 | + } | ||
192 | + | ||
193 | + /* | ||
194 | + * 获取购物车加价购商品数据 | ||
195 | + */ | ||
196 | + public function giftinfoAction() | ||
197 | + { | ||
198 | + $result = array(); | ||
199 | + | ||
200 | + if ($this->isAjax()) { | ||
201 | + $skn = $this->get('skn', null); | ||
202 | + $promotionId = $this->get('promotionId', null); | ||
203 | + $result = CartModel::giftProductData($skn, $promotionId); | ||
204 | + } | ||
205 | + | ||
206 | + if (empty($result)) { | ||
207 | + echo ' '; | ||
208 | + } else { | ||
209 | + $this->echoJson($result); | ||
210 | + } | ||
211 | + } | ||
212 | + | ||
213 | + /** | ||
214 | + * 修改购物车商品数据 | ||
215 | + */ | ||
216 | + public function modifyAction() | ||
217 | + { | ||
218 | + $result = array(); | ||
219 | + | ||
220 | + if ($this->isAjax()) { | ||
221 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
222 | + $uid = $this->getUid(true); | ||
223 | + | ||
224 | + $params = array(); | ||
225 | + $params['old_product_sku']= $this->post('old_product_sku', 0); | ||
226 | + $params['new_product_sku']= $this->post('new_product_sku', 0); | ||
227 | + $params['buy_number']= $this->post('buy_number', 0); | ||
228 | + $params['selected']= $this->post('selected', null); | ||
229 | + $result = CartModel::modifyCartProduct($uid, $params, $shoppingKey); | ||
230 | + } | ||
231 | + | ||
232 | + if (empty($result)) { | ||
233 | + echo ' '; | ||
234 | + } else { | ||
235 | + $this->echoJson($result); | ||
236 | + } | ||
237 | + } | ||
238 | + | ||
239 | + /** | ||
240 | + * 购物车结算请求 | ||
241 | + */ | ||
242 | + public function orderEnsureAction() | ||
243 | + { | ||
244 | + // 审判跳转登录页 | ||
245 | + $this->auditJumpLogin(); | ||
246 | + | ||
247 | + $this->setTitle('购物车'); | ||
248 | + $this->setNavHeader('购物车'); | ||
249 | + | ||
250 | + // 购物车商品为空跳转到购物车页面 | ||
251 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
252 | + $uid = $this->getUid(true); | ||
253 | + $cartGoods = CartModel::getCartData($uid, $shoppingKey); | ||
254 | + if (empty($cartGoods) || isset($cartGoods['isEmptyCart'])) { | ||
255 | + $this->go(Helpers::url('/shoppingcart')); | ||
256 | + } | ||
257 | + | ||
258 | + $cartType = $this->get('cartType', 'ordinary'); | ||
259 | + $cookieData = $this->getCookie('order-info', null); | ||
260 | + $uid = $this->getUid(true); | ||
261 | + $data = array( | ||
262 | + 'orderEnsurePage' => true, | ||
263 | + 'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData) | ||
264 | + ); | ||
265 | + | ||
266 | + $this->_view->display('order-ensure', $data); | ||
267 | + } | ||
268 | + | ||
269 | + /** | ||
270 | + * 购物车选择改变字段,重新运算订单数据 | ||
271 | + */ | ||
272 | + public function orderComputeAction() | ||
273 | + { | ||
274 | + $result = array(); | ||
275 | + | ||
276 | + if ($this->isAjax()) { | ||
277 | + $cartType = $this->post('cartType', 'ordinary'); | ||
278 | + $deliveryWay = $this->post('deliveryId', 1); | ||
279 | + $paymentType = $this->post('paymentTypeId', 1); | ||
280 | + $couponCode = $this->post('couponCode', null); | ||
281 | + $yohoCoin = $this->post('yohoCoin', null); | ||
282 | + $uid = $this->getUid(true); | ||
283 | + $result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin); | ||
284 | + } | ||
285 | + | ||
286 | + if (empty($result)) { | ||
287 | + echo ' '; | ||
288 | + } else { | ||
289 | + $this->echoJson($result); | ||
290 | + } | ||
291 | + } | ||
292 | + | ||
293 | + /** | ||
294 | + * 购物车输入优惠券码使用优惠券 | ||
295 | + */ | ||
296 | + public function couponSearchAction() | ||
297 | + { | ||
298 | + $result = array(); | ||
299 | + | ||
300 | + if ($this->isAjax()) { | ||
301 | + $couponCode = $this->get('couponCode', ''); | ||
302 | + $uid = $this->getUid(true); | ||
303 | + $result = CartModel::searchCoupon($uid, $couponCode); | ||
304 | + } | ||
305 | + | ||
306 | + if (empty($result)) { | ||
307 | + echo ' '; | ||
308 | + } else { | ||
309 | + $this->echoJson($result); | ||
310 | + } | ||
311 | + } | ||
312 | + | ||
313 | + /** | ||
314 | + * 购物车结算--获取优惠券列表 | ||
315 | + */ | ||
316 | + public function couponListAction() | ||
317 | + { | ||
318 | + $result = array(); | ||
319 | + | ||
320 | + if ($this->isAjax()) { | ||
321 | + $uid = $this->getUid(true); | ||
322 | + $result = CartModel::getCouponList($uid); | ||
323 | + } | ||
324 | + | ||
325 | + if (empty($result)) { | ||
326 | + echo ' '; | ||
327 | + } else { | ||
328 | + $this->echoJson($result); | ||
329 | + } | ||
330 | + } | ||
331 | + | ||
332 | + /** | ||
333 | + * 下单流程 选择地址 | ||
334 | + */ | ||
335 | + public function selectAddressAction() | ||
336 | + { | ||
337 | + // 审判跳转登录页 | ||
338 | + $this->auditJumpLogin(); | ||
339 | + | ||
340 | + // 设置网站标题 | ||
341 | + $this->setTitle('选择地址'); | ||
342 | + $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); | ||
343 | + | ||
344 | + $uid = $this->getUid(true); | ||
345 | + $address = UserModel::getAddressData($uid); | ||
346 | + | ||
347 | + $this->_view->display('select-address', array( | ||
348 | + 'selectAddressPage' => true, | ||
349 | + 'pageFooter' => true, | ||
350 | + 'address' => $address | ||
351 | + )); | ||
352 | + } | ||
353 | + | ||
354 | + /** | ||
355 | + * 下单流程 选择优惠券 | ||
356 | + */ | ||
357 | + public function selectCouponAction() | ||
358 | + { | ||
359 | + // 审判跳转登录页 | ||
360 | + $this->auditJumpLogin(); | ||
361 | + | ||
362 | + // 设置网站标题 | ||
363 | + $this->setTitle('选择优惠券'); | ||
364 | + $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); | ||
365 | + | ||
366 | + $this->_view->display('select-coupon', array( | ||
367 | + 'selectCouponPage' => true, | ||
368 | + 'pageFooter' => true | ||
369 | + )); | ||
370 | + } | ||
371 | + | ||
372 | + /** | ||
373 | + * 确认结算订单 | ||
374 | + */ | ||
375 | + public function orderSubAction() | ||
376 | + { | ||
377 | + $result = array(); | ||
378 | + | ||
379 | + if ($this->isAjax()) { | ||
380 | + $uid = $this->getUid(true); | ||
381 | + $addressId = $this->post('addressId', null); | ||
382 | + $cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车 | ||
383 | + $deliveryTime = $this->post('deliveryTimeId', 1); // 默认只工作日配送 | ||
384 | + $deliveryWay = $this->post('deliveryId', 1); // 默认普通快递 | ||
385 | + $invoiceTitle = $this->post('invoiceText', null); | ||
386 | + $invoiceId = $this->post('invoiceType', null); | ||
387 | + $paymentId = $this->post('paymentTypeId', 15); | ||
388 | + $paymentType = $this->post('paymentType', 1); // 默认在线支付 | ||
389 | + $remark = $this->post('msg', null); | ||
390 | + $couponCode = $this->post('couponCode', null); | ||
391 | + $yohoCoin = $this->post('yohoCoin', 1); | ||
392 | + $result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin); | ||
393 | + } | ||
394 | + | ||
395 | + if (empty($result)) { | ||
396 | + echo ' '; | ||
397 | + } else { | ||
398 | + // 提交成功清除Cookie | ||
399 | + $this->setCookie('order-info', null); | ||
400 | + | ||
401 | + $this->echoJson($result); | ||
402 | + } | ||
20 | } | 403 | } |
21 | } | 404 | } |
-
Please register or login to post a comment