Merge branch 'feature/yohoCoinUse' into release/5.2
Showing
5 changed files
with
174 additions
and
69 deletions
@@ -12,7 +12,7 @@ const crypto = global.yoho.crypto; | @@ -12,7 +12,7 @@ const crypto = global.yoho.crypto; | ||
12 | 12 | ||
13 | const easypayApi = require('./easypay-api'); | 13 | const easypayApi = require('./easypay-api'); |
14 | 14 | ||
15 | -const handelViewPrice = list => { | 15 | +const _handelViewPrice = list => { |
16 | if (list) { | 16 | if (list) { |
17 | _.forEach(list, val => { | 17 | _.forEach(list, val => { |
18 | if (val.promotion === '商品金额') { | 18 | if (val.promotion === '商品金额') { |
@@ -26,6 +26,36 @@ const handelViewPrice = list => { | @@ -26,6 +26,36 @@ const handelViewPrice = list => { | ||
26 | } | 26 | } |
27 | }; | 27 | }; |
28 | 28 | ||
29 | +const _handelUseYohoCoin = (info) => { | ||
30 | + let resData = {}; | ||
31 | + let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0); | ||
32 | + | ||
33 | + if (info) { | ||
34 | + Object.assign(resData, { | ||
35 | + yoho_coin: info.yoho_coin, | ||
36 | + use_yoho_coin: info.use_yoho_coin, | ||
37 | + total_yoho_coin_num: info.total_yoho_coin_num, | ||
38 | + yoho_coin_pay_rule: info.yoho_coin_pay_rule, | ||
39 | + canUseCoinNum: _.round(info.yoho_coin * 100), | ||
40 | + usedCoinNum: _.round(info.use_yoho_coin * 100) | ||
41 | + }); | ||
42 | + | ||
43 | + if (!resData.canUseCoinNum) { | ||
44 | + let coinErrorTip = ''; | ||
45 | + | ||
46 | + if (info.total_yoho_coin_num > limitCoin) { | ||
47 | + coinErrorTip = '抱歉,您的订单实付款不满足有货币使用条件'; | ||
48 | + } else { | ||
49 | + coinErrorTip = `抱歉,您的有货币不足,有货币满${limitCoin}个方可使用`; | ||
50 | + } | ||
51 | + | ||
52 | + resData.coinErrorTip = coinErrorTip; | ||
53 | + } | ||
54 | + } | ||
55 | + | ||
56 | + return resData; | ||
57 | +}; | ||
58 | + | ||
29 | const _handelPaymentInfo = (d) => { | 59 | const _handelPaymentInfo = (d) => { |
30 | let resData = {}; | 60 | let resData = {}; |
31 | 61 | ||
@@ -81,14 +111,14 @@ const _handelPaymentInfo = (d) => { | @@ -81,14 +111,14 @@ const _handelPaymentInfo = (d) => { | ||
81 | }; | 111 | }; |
82 | 112 | ||
83 | if (d.shopping_cart_data && d.shopping_cart_data.promotion_formula_list) { | 113 | if (d.shopping_cart_data && d.shopping_cart_data.promotion_formula_list) { |
84 | - handelViewPrice(d.shopping_cart_data.promotion_formula_list); | 114 | + _handelViewPrice(d.shopping_cart_data.promotion_formula_list); |
85 | } | 115 | } |
86 | 116 | ||
87 | Object.assign(resData, { | 117 | Object.assign(resData, { |
88 | paymentWay: d.payment_way, | 118 | paymentWay: d.payment_way, |
89 | deliveryTime: d.delivery_time, | 119 | deliveryTime: d.delivery_time, |
90 | deliveryWay: d.delivery_way, | 120 | deliveryWay: d.delivery_way, |
91 | - shoppingCartData: d.shopping_cart_data, | 121 | + shoppingCartData: Object.assign(d.shopping_cart_data, _handelUseYohoCoin(d)), |
92 | invoices: d.invoices | 122 | invoices: d.invoices |
93 | }); | 123 | }); |
94 | 124 | ||
@@ -142,8 +172,10 @@ const getOrderComputeData = (uid, cartType, params) => { | @@ -142,8 +172,10 @@ const getOrderComputeData = (uid, cartType, params) => { | ||
142 | } | 172 | } |
143 | 173 | ||
144 | if (_.has(result, 'data.promotion_formula_list')) { | 174 | if (_.has(result, 'data.promotion_formula_list')) { |
145 | - handelViewPrice(result.data.promotion_formula_list); | 175 | + _handelViewPrice(result.data.promotion_formula_list); |
146 | } | 176 | } |
177 | + | ||
178 | + result.data = Object.assign(_handelUseYohoCoin(result.data), result.data); | ||
147 | } | 179 | } |
148 | return result; | 180 | return result; |
149 | }); | 181 | }); |
@@ -268,23 +268,37 @@ | @@ -268,23 +268,37 @@ | ||
268 | <span id="use-coin" class="use-coin coin-trigger">使用有货币支付</span> | 268 | <span id="use-coin" class="use-coin coin-trigger">使用有货币支付</span> |
269 | 269 | ||
270 | <div class="using-coin coin-trigger hide"> | 270 | <div class="using-coin coin-trigger hide"> |
271 | - <ul> | 271 | + <ul id="using-coin-cont"> |
272 | + {{#if coinErrorTip}} | ||
273 | + <li><span class="red">{{coinErrorTip}}</span></li> | ||
274 | + {{/if}} | ||
272 | <li> | 275 | <li> |
273 | - 使用有货币:<input id="coin-used" class="coin-used" type="text" data-max="{{hasCoin}}">个 | ||
274 | - </li> | ||
275 | - <li class="coin-sum-row"> | ||
276 | - 您目前有有货币<em>{{hasCoin}}</em>个 | 276 | + 有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍 |
277 | + | ||
278 | + <i class="iconfont help-icon"></i> | ||
279 | + <div class="coin-tip-help"> | ||
280 | + <p>有货币使用条件:</p> | ||
281 | + <p> | ||
282 | + 1.订单金额大于20元(含)<br> | ||
283 | + 2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含) <br> | ||
284 | + 3.有货币支付不得超过每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}} | ||
285 | + </p> | ||
286 | + <p>备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p> | ||
287 | + </div> | ||
277 | </li> | 288 | </li> |
278 | - <li class="coin-tip-row"> | ||
279 | - <span id="coin-tip" class="coin-tip vhide"></span> | 289 | + <li>您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span class="red">{{canUseCoinNum}}</span> 个</li> |
290 | + <li> | ||
291 | + <p{{#if coinErrorTip}} class="coin-use-hide"{{/if}}>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span></p> | ||
280 | </li> | 292 | </li> |
281 | </ul> | 293 | </ul> |
282 | 294 | ||
283 | <p class="btns"> | 295 | <p class="btns"> |
284 | <span id="coin-sure" class="coin-sure sure-btn">确定</span> | 296 | <span id="coin-sure" class="coin-sure sure-btn">确定</span> |
285 | <span id="coin-cancel" class="coin-cancel cancel-btn">取消</span> | 297 | <span id="coin-cancel" class="coin-cancel cancel-btn">取消</span> |
298 | + <a href="/help/?category_id=87" class="coin-help" target="_blank">有货币使用规则?</a> | ||
286 | </p> | 299 | </p> |
287 | </div> | 300 | </div> |
301 | + <input id="coin-used" type="hidden" data-coin="{{usedCoinNum}}" data-max={{canUseCoinNum}}> | ||
288 | </li> | 302 | </li> |
289 | </ul> | 303 | </ul> |
290 | </div> | 304 | </div> |
@@ -101,6 +101,30 @@ | @@ -101,6 +101,30 @@ | ||
101 | \{{/each}} | 101 | \{{/each}} |
102 | </script> | 102 | </script> |
103 | 103 | ||
104 | +<script id="yoho-coin-tpl" type="text/html"> | ||
105 | + \{{#if coinErrorTip}} | ||
106 | + <li><span class="red">\{{coinErrorTip}}</span></li> | ||
107 | + \{{/if}} | ||
108 | + <li> | ||
109 | + 有货币满<span class="red">\{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span class="red">\{{yoho_coin_pay_rule.num_limit}}</span>的整数倍 | ||
110 | + | ||
111 | + <i class="iconfont help-icon"></i> | ||
112 | + <div class="coin-tip-help"> | ||
113 | + <p>有货币使用条件:</p> | ||
114 | + <p> | ||
115 | + 1.订单金额大于20元(含)<br> | ||
116 | + 2.有货币数量大于\{{yoho_coin_pay_rule.num_limit}}个(含) <br> | ||
117 | + 3.有货币支付不得超过每笔订单应付金额的\{{yoho_coin_pay_rule.max_pay_rate_desc}} | ||
118 | + </p> | ||
119 | + <p>备注:使用有货币数量为\{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p> | ||
120 | + </div> | ||
121 | + </li> | ||
122 | + <li>您当前共有有货币 <span class="red">\{{total_yoho_coin_num}}</span> 个,可用 <span class="red">\{{canUseCoinNum}}</span> 个</li> | ||
123 | + <li> | ||
124 | + <p\{{#if coinErrorTip}} class="coin-use-hide"\{{/if}}>本次使用有货币<span class="red">\{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥\{{yoho_coin}}</span></p> | ||
125 | + </li> | ||
126 | +</script> | ||
127 | + | ||
104 | <script id="promotion-list-tpl" type="text/html"> | 128 | <script id="promotion-list-tpl" type="text/html"> |
105 | \{{#each promotion_formula_list}} | 129 | \{{#each promotion_formula_list}} |
106 | <li class="promotion-item\{{#isEqual promotion '运费'}} fregit-promotion\{{/isEqual}}"> | 130 | <li class="promotion-item\{{#isEqual promotion '运费'}} fregit-promotion\{{/isEqual}}"> |
@@ -13,19 +13,11 @@ var $pdUsed = $('#pay-delivery-used'); | @@ -13,19 +13,11 @@ var $pdUsed = $('#pay-delivery-used'); | ||
13 | var $balance = $('#balance-detail'); | 13 | var $balance = $('#balance-detail'); |
14 | 14 | ||
15 | var couponsTpl = Hbs.compile($('#coupons-tpl').html()); | 15 | var couponsTpl = Hbs.compile($('#coupons-tpl').html()); |
16 | +var coinTpl = Hbs.compile($('#yoho-coin-tpl').html()); | ||
16 | var promotionTpl = Hbs.compile($('#promotion-list-tpl').html()); | 17 | var promotionTpl = Hbs.compile($('#promotion-list-tpl').html()); |
17 | 18 | ||
18 | var $coin = $('#coin-used'); | 19 | var $coin = $('#coin-used'); |
19 | -var $coinTip = $('#coin-tip'); | ||
20 | var $coinSure = $('#coin-sure'); | 20 | var $coinSure = $('#coin-sure'); |
21 | -var coinMax = +$coin.data('max'); | ||
22 | -var coinStatus = { | ||
23 | - err: '请输入一个正整数', | ||
24 | - max: '您的有货币不足', | ||
25 | - success: '抵扣', | ||
26 | - maxUse: '您最多使用', | ||
27 | - muPostfix: '个有货币' | ||
28 | -}; | ||
29 | 21 | ||
30 | var queryInfo; | 22 | var queryInfo; |
31 | var pkgCache = {}; | 23 | var pkgCache = {}; |
@@ -67,16 +59,18 @@ function updateUsedPdShow(info) { | @@ -67,16 +59,18 @@ function updateUsedPdShow(info) { | ||
67 | } | 59 | } |
68 | 60 | ||
69 | // 订单计算 | 61 | // 订单计算 |
70 | -function compute() { | ||
71 | - var coinUsed = $coin.data('coin'); | 62 | +// 传有货币数量则使用有货币,否者不使用,更改订单总价有货币使用数量重置为0 |
63 | +function compute(coin) { | ||
72 | var d = { | 64 | var d = { |
73 | cartType: window.queryString().type, | 65 | cartType: window.queryString().type, |
74 | deliveryWay: $('input[name="delivery-way-radio"]:checked').val(), | 66 | deliveryWay: $('input[name="delivery-way-radio"]:checked').val(), |
75 | paymentType: $('#payment-way').data('id'), | 67 | paymentType: $('#payment-way').data('id'), |
76 | - coin: coinUsed ? parseInt(coinUsed, 10) : 0 | 68 | + coin: coin ? parseInt(coin, 10) : 0 |
77 | }; | 69 | }; |
78 | var couponCode = $('#coupons-sure').data('coupons'); | 70 | var couponCode = $('#coupons-sure').data('coupons'); |
79 | 71 | ||
72 | + $coin.data('coin', d.coin); | ||
73 | + | ||
80 | if (couponCode) { | 74 | if (couponCode) { |
81 | d.couponCode = couponCode; | 75 | d.couponCode = couponCode; |
82 | } | 76 | } |
@@ -106,6 +100,9 @@ function compute() { | @@ -106,6 +100,9 @@ function compute() { | ||
106 | 100 | ||
107 | res = data.data; | 101 | res = data.data; |
108 | 102 | ||
103 | + // update yoho coin using | ||
104 | + $('#using-coin-cont').html(coinTpl(res)); | ||
105 | + | ||
109 | // update last order amount | 106 | // update last order amount |
110 | $('#sum-row em').html(res.last_order_amount); | 107 | $('#sum-row em').html(res.last_order_amount); |
111 | 108 | ||
@@ -178,63 +175,32 @@ if ($('#use-coupons').length) { | @@ -178,63 +175,32 @@ if ($('#use-coupons').length) { | ||
178 | } | 175 | } |
179 | 176 | ||
180 | // 有货币 | 177 | // 有货币 |
178 | +if ($coin) { | ||
179 | + $coin.data($coin.data()); // 防止人为页面更改有货币使用数量 | ||
180 | +} | ||
181 | + | ||
181 | $('#use-coin, #coin-sure, #coin-cancel').click(function() { | 182 | $('#use-coin, #coin-sure, #coin-cancel').click(function() { |
182 | $('.coin-trigger').toggleClass('hide'); | 183 | $('.coin-trigger').toggleClass('hide'); |
183 | }); | 184 | }); |
184 | 185 | ||
185 | -$coin.on('propertychange input', function() { | ||
186 | - var c = $.trim($coin.val()); | ||
187 | - var err = true; | ||
188 | - | ||
189 | - if (c === '') { | ||
190 | - | ||
191 | - // 输入框为空,确定按钮不可点 | ||
192 | - $coinTip.addClass('vhide'); | ||
193 | - $coinTip.text(coinStatus.err); | ||
194 | - return; | ||
195 | - } else if (!/^[1-9]\d*$/.test(c)) { | ||
196 | - | ||
197 | - // 验证输入不为正整数 | ||
198 | - $coinTip.text(coinStatus.err); | ||
199 | - } else if (+c > coinMax) { | ||
200 | - | ||
201 | - // 有货币不足 | ||
202 | - $coinTip.text(coinStatus.max); | ||
203 | - } else if (+c > $('#sum-row').data('amount') * 100) { | ||
204 | - | ||
205 | - // 输入的有货币大于订单额度 | ||
206 | - $coinTip.text(coinStatus.maxUse + ($('#sum-row').data('amount') * 100) + coinStatus.muPostfix); | ||
207 | - } else { | ||
208 | - err = false; | ||
209 | - $coinTip.text(coinStatus.success + (c / 100).toFixed(2) + '元'); | ||
210 | - | ||
211 | - // 已使用面板的数据显示更新 | ||
212 | - // $coinUsed.html(c); | ||
213 | - // $coinDeduction.html((c / 100).toFixed(2)); | ||
214 | - } | ||
215 | - | ||
216 | - if (err) { | ||
217 | - $coinSure.addClass('disable'); | ||
218 | - $coinTip.removeClass('vhide'); | ||
219 | - } else { | ||
220 | - $coinSure.removeClass('disable'); | ||
221 | - $coinTip.addClass('vhide'); | ||
222 | - } | ||
223 | -}); | ||
224 | - | ||
225 | $coinSure.click(function() { | 186 | $coinSure.click(function() { |
226 | - if ($coinSure.hasClass('disable')) { | 187 | + var data = $coin.data(); |
188 | + | ||
189 | + if ($coinSure.hasClass('disable') || | ||
190 | + data.coin === data.max) { | ||
227 | return; | 191 | return; |
228 | } | 192 | } |
229 | - $coin.data('coin', $.trim($coin.val())); | ||
230 | 193 | ||
231 | // coin change trigger compute | 194 | // coin change trigger compute |
232 | - compute(); | 195 | + compute(data.max); |
233 | }); | 196 | }); |
234 | 197 | ||
235 | $('#coin-cancel').click(function() { | 198 | $('#coin-cancel').click(function() { |
236 | - $coin.val('').data('coin', ''); | ||
237 | - $coinTip.addClass('vhide').text(''); | 199 | + var data = $coin.data(); |
200 | + | ||
201 | + if (data.coin * 1 === 0) { | ||
202 | + return; | ||
203 | + } | ||
238 | 204 | ||
239 | // coin cancel trigger compute | 205 | // coin cancel trigger compute |
240 | compute(); | 206 | compute(); |
@@ -242,7 +208,7 @@ $('#coin-cancel').click(function() { | @@ -242,7 +208,7 @@ $('#coin-cancel').click(function() { | ||
242 | 208 | ||
243 | // 结算信息列表中修改有货币按钮 | 209 | // 结算信息列表中修改有货币按钮 |
244 | $('.balance-detail').on('click', '.modify-coin', function() { | 210 | $('.balance-detail').on('click', '.modify-coin', function() { |
245 | - $('.coin-trigger').filter('.use-coin').addClass('hide').end().filter('.using-coin').removeClass('hide'); | 211 | + $('#use-coin').trigger('click'); |
246 | }); | 212 | }); |
247 | 213 | ||
248 | // delivery way change trigger compute | 214 | // delivery way change trigger compute |
@@ -492,6 +492,75 @@ | @@ -492,6 +492,75 @@ | ||
492 | } | 492 | } |
493 | } | 493 | } |
494 | 494 | ||
495 | + .using-coin { | ||
496 | + text-align: left; | ||
497 | + | ||
498 | + li { | ||
499 | + padding-bottom: 10px; | ||
500 | + } | ||
501 | + | ||
502 | + .red { | ||
503 | + color: #db6976; | ||
504 | + } | ||
505 | + | ||
506 | + .help-icon { | ||
507 | + float: right; | ||
508 | + cursor: pointer; | ||
509 | + | ||
510 | + &:hover + .coin-tip-help { | ||
511 | + display: block; | ||
512 | + } | ||
513 | + } | ||
514 | + | ||
515 | + .coin-tip-help { | ||
516 | + width: 310px; | ||
517 | + padding: 6px; | ||
518 | + border: 1px solid #000; | ||
519 | + background-color: #fff; | ||
520 | + position: absolute; | ||
521 | + margin-left: 56px; | ||
522 | + margin-top: 10px; | ||
523 | + display: none; | ||
524 | + } | ||
525 | + | ||
526 | + .coin-use-hide { | ||
527 | + color: #d4d4d4; | ||
528 | + } | ||
529 | + | ||
530 | + .coin-box { | ||
531 | + display: inline-block; | ||
532 | + width: 70px; | ||
533 | + height: 24px; | ||
534 | + line-height: 24px; | ||
535 | + text-align: center; | ||
536 | + border: 1px solid #d4d4d4; | ||
537 | + margin: 0 6px; | ||
538 | + } | ||
539 | + | ||
540 | + .btns { | ||
541 | + margin-top: 10px; | ||
542 | + text-align: left; | ||
543 | + | ||
544 | + span { | ||
545 | + padding: 4px 14px; | ||
546 | + cursor: pointer; | ||
547 | + border: 1px solid #ccc; | ||
548 | + } | ||
549 | + | ||
550 | + .sure-btn { | ||
551 | + color: #fff; | ||
552 | + background-color: #000; | ||
553 | + border-color: #000; | ||
554 | + margin-right: 20px; | ||
555 | + } | ||
556 | + | ||
557 | + .coin-help { | ||
558 | + float: right; | ||
559 | + color: #5291f7; | ||
560 | + } | ||
561 | + } | ||
562 | + } | ||
563 | + | ||
495 | .coin-sum-row, | 564 | .coin-sum-row, |
496 | .coin-tip-row { | 565 | .coin-tip-row { |
497 | padding: 10px 0; | 566 | padding: 10px 0; |
-
Please register or login to post a comment