Authored by yyq

ticket giftcard

@@ -39,10 +39,11 @@ const ticketEnsure = (req, res, next) => { @@ -39,10 +39,11 @@ const ticketEnsure = (req, res, next) => {
39 39
40 const ticketSubmit = (req, res, next) => { 40 const ticketSubmit = (req, res, next) => {
41 let uid = req.user.uid; 41 let uid = req.user.uid;
42 - let sku = req.body.sku || 0;  
43 - let count = req.body.count || 0;  
44 - let mobile = req.body.mobile || 0;  
45 - let yohoCoin = req.body.coin || 0; 42 + let params = req.body;
  43 + let sku = params.sku || 0;
  44 + let count = params.count || 0;
  45 + let mobile = params.mobile || 0;
  46 + let yohoCoin = params.coin || 0;
46 47
47 if (!sku || !count || !mobile) { 48 if (!sku || !count || !mobile) {
48 return res.json({ 49 return res.json({
@@ -51,7 +52,9 @@ const ticketSubmit = (req, res, next) => { @@ -51,7 +52,9 @@ const ticketSubmit = (req, res, next) => {
51 }); 52 });
52 } 53 }
53 54
54 - ticketService.submitTicket(uid, sku, count, mobile, yohoCoin).then(result => { 55 + params.udid = req.yoho.udid;
  56 +
  57 + ticketService.submitTicket(uid, sku, count, mobile, yohoCoin, params).then(result => {
55 return res.json(result); 58 return res.json(result);
56 }).catch(next); 59 }).catch(next);
57 }; 60 };
@@ -62,7 +65,7 @@ const ticketCompute = (req, res, next) => { @@ -62,7 +65,7 @@ const ticketCompute = (req, res, next) => {
62 let buyNumber = req.body.count || 0; 65 let buyNumber = req.body.count || 0;
63 let yohoCoin = req.body.coin || 0; 66 let yohoCoin = req.body.coin || 0;
64 67
65 - ticketService.addTicket(uid, sku, buyNumber, yohoCoin).then(result => { 68 + ticketService.addTicket(uid, sku, buyNumber, yohoCoin, req.body).then(result => {
66 if (_.isEmpty(result)) { 69 if (_.isEmpty(result)) {
67 return res.json({ 70 return res.json({
68 code: 401, 71 code: 401,
@@ -12,7 +12,7 @@ const api = global.yoho.API; @@ -12,7 +12,7 @@ const api = global.yoho.API;
12 * @param mobile 手机号码 12 * @param mobile 手机号码
13 * @param yohoCoin 有货币 13 * @param yohoCoin 有货币
14 */ 14 */
15 -function submit(uid, sku, count, mobile, yohoCoin) { 15 +function submit(uid, sku, count, mobile, yohoCoin, other = {}) {
16 let params = { 16 let params = {
17 method: 'app.shopping.submitTicket', 17 method: 'app.shopping.submitTicket',
18 uid, 18 uid,
@@ -25,6 +25,18 @@ function submit(uid, sku, count, mobile, yohoCoin) { @@ -25,6 +25,18 @@ function submit(uid, sku, count, mobile, yohoCoin) {
25 params.use_yoho_coin = yohoCoin / 100; 25 params.use_yoho_coin = yohoCoin / 100;
26 } 26 }
27 27
  28 + if (other.giftCard) {
  29 + Object.assign(params, {
  30 + gift_card_code: other.giftCard
  31 + });
  32 + }
  33 +
  34 + if (other.udid) {
  35 + Object.assign(params, {
  36 + udid: other.udid
  37 + });
  38 + }
  39 +
28 return api.get('', params); 40 return api.get('', params);
29 } 41 }
30 42
@@ -35,7 +47,7 @@ function submit(uid, sku, count, mobile, yohoCoin) { @@ -35,7 +47,7 @@ function submit(uid, sku, count, mobile, yohoCoin) {
35 * @param count 购买数量 1-4 47 * @param count 购买数量 1-4
36 * @param yohoCoin 有货币 48 * @param yohoCoin 有货币
37 */ 49 */
38 -function add(uid, sku, count, yohoCoin) { 50 +function add(uid, sku, count, yohoCoin, other = {}) {
39 let params = { 51 let params = {
40 method: 'app.shopping.ticket', 52 method: 'app.shopping.ticket',
41 uid, 53 uid,
@@ -47,6 +59,12 @@ function add(uid, sku, count, yohoCoin) { @@ -47,6 +59,12 @@ function add(uid, sku, count, yohoCoin) {
47 params.use_yoho_coin = yohoCoin / 100; 59 params.use_yoho_coin = yohoCoin / 100;
48 } 60 }
49 61
  62 + if (other.giftCard) {
  63 + Object.assign(params, {
  64 + gift_card_code: other.giftCard
  65 + });
  66 + }
  67 +
50 return api.get('', params); 68 return api.get('', params);
51 } 69 }
52 70
@@ -21,8 +21,8 @@ function _handleAmount(info) { @@ -21,8 +21,8 @@ function _handleAmount(info) {
21 return _.get(info, 'data.shopping_cart_data.last_order_amount', 0); 21 return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
22 } 22 }
23 23
24 -const addTicket = co(function * (uid, sku, count, yohoCoin) {  
25 - let ticketInfo = yield api.add(uid, sku, count, yohoCoin); 24 +const addTicket = co(function * (uid, sku, count, yohoCoin, other) {
  25 + let ticketInfo = yield api.add(uid, sku, count, yohoCoin, other);
26 let result = {}; 26 let result = {};
27 27
28 if (_.isEmpty(ticketInfo)) { 28 if (_.isEmpty(ticketInfo)) {
@@ -47,8 +47,8 @@ const addTicket = co(function * (uid, sku, count, yohoCoin) { @@ -47,8 +47,8 @@ const addTicket = co(function * (uid, sku, count, yohoCoin) {
47 return result; 47 return result;
48 }); 48 });
49 49
50 -const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {  
51 - let result = yield api.submit(uid, sku, count, mobile, yohoCoin); 50 +const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin, other) {
  51 + let result = yield api.submit(uid, sku, count, mobile, yohoCoin, other);
52 52
53 if (_.isEmpty(result)) { 53 if (_.isEmpty(result)) {
54 return { 54 return {
@@ -41,7 +41,7 @@ router.post('/easypay/compute', auth, easypay.compute); // 价格重新计算 @@ -41,7 +41,7 @@ router.post('/easypay/compute', auth, easypay.compute); // 价格重新计算
41 router.post('/easypay/submit', auth, easypay.submit); // 限购商品订单提交 41 router.post('/easypay/submit', auth, easypay.submit); // 限购商品订单提交
42 42
43 router.get('/ticketEnsure', auth, ticket.ticketEnsure); 43 router.get('/ticketEnsure', auth, ticket.ticketEnsure);
44 -router.post('/ticketSubmit', auth, ticket.ticketSubmit); 44 +router.post('/ticketSubmit', auth, ensure.submitCheck, ticket.ticketSubmit);
45 router.post('/ticketCompute', auth, ticket.ticketCompute); 45 router.post('/ticketCompute', auth, ticket.ticketCompute);
46 46
47 router.get('/cart', cart.cart); 47 router.get('/cart', cart.cart);
@@ -75,35 +75,55 @@ @@ -75,35 +75,55 @@
75 <dd id="yoho-coin-box" class="yoho-coin-box" data-coin="{{usedCoinNum}}" 75 <dd id="yoho-coin-box" class="yoho-coin-box" data-coin="{{usedCoinNum}}"
76 data-max={{canUseCoinNum}} data-total="{{total_yoho_coin_num}}"> 76 data-max={{canUseCoinNum}} data-total="{{total_yoho_coin_num}}">
77 <div class="outer-view"> 77 <div class="outer-view">
78 - <p class="coin-err-tip">{{coinErrorTip}}</p>  
79 - <p>有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span  
80 - class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>  
81 - <i class="help-icon"></i>  
82 - <div class="coin-tip-help">  
83 - <p>有货币使用提示:</p>  
84 - <p>  
85 - 1.订单金额大于20元(含20元)<br>  
86 - 2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含{{yoho_coin_pay_rule.num_limit}}个) <br>  
87 - 3.有货币支付上限为每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}  
88 - </p>  
89 - <p class="rs-text">备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>  
90 - </div>  
91 - </div>  
92 - <div class="coin-main-view">  
93 - <p>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span>  
94 - </p>  
95 - <p class="grey fw300">您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span  
96 - class="red">{{canUseCoinNum}}</span></p>  
97 - <label class="coin-cancel-btn fw300">取消使用</label>  
98 - <label class="coin-use-btn">确定</label>  
99 - </div> 78 + <p class="coin-err-tip">{{coinErrorTip}}</p>
  79 + <p>有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span
  80 + class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>
  81 + <i class="help-icon"></i>
  82 + <div class="coin-tip-help">
  83 + <p>有货币使用提示:</p>
  84 + <p>
  85 + 1.订单金额大于20元(含20元)<br>
  86 + 2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含{{yoho_coin_pay_rule.num_limit}}个) <br>
  87 + 3.有货币支付上限为每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}
  88 + </p>
  89 + <p class="rs-text">备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
  90 + </div>
  91 + </div>
  92 + <div class="coin-main-view">
  93 + <p>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span>
  94 + </p>
  95 + <p class="grey fw300">您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span
  96 + class="red">{{canUseCoinNum}}</span></p>
  97 + <label class="coin-cancel-btn fw300">取消使用</label>
  98 + <label class="coin-use-btn">确定</label>
  99 + </div>
100 </dd> 100 </dd>
101 101
102 </dl> 102 </dl>
  103 +
  104 + <dt id="use-gift-card"><span class="locker-switch"></span>使用礼品卡<span class="can-use-tip"></span></dt>
  105 + <dd class="gift-card-box">
  106 + <table>
  107 + <thead>
  108 + <tr>
  109 + <th width="260">卡号</th>
  110 + <th>面值</th>
  111 + <th>卡内余额</th>
  112 + <th width="230">有效期</th>
  113 + <th width="86">选择</th>
  114 + </tr>
  115 + </thead>
  116 + <tbody>
  117 + <tr>
  118 + <td colspan="5">暂无礼品卡</td>
  119 + </tr>
  120 + </tbody>
  121 + </table>
  122 + </dd>
103 </div> 123 </div>
104 124
105 <div class="sum-wrap"> 125 <div class="sum-wrap">
106 - 应付金额:<span id="order-price" class="price">¥ {{round last_order_amount 2}}</span> 126 + 应付金额:<span id="order-price" class="price" data-price="{{last_order_amount}}">¥ {{round last_order_amount 2}}</span>
107 <button id="order-submit" data-url="{{productUrl}}">提交订单</button> 127 <button id="order-submit" data-url="{{productUrl}}">提交订单</button>
108 </div> 128 </div>
109 129
@@ -758,7 +758,7 @@ giftCard = { @@ -758,7 +758,7 @@ giftCard = {
758 }); 758 });
759 759
760 order.giftCard = codes.join(','); 760 order.giftCard = codes.join(',');
761 - compute(); 761 + compute(order.coin);
762 }, 762 },
763 setUseStatus: function(price) { 763 setUseStatus: function(price) {
764 if (!this.$radios) { 764 if (!this.$radios) {
@@ -11,9 +11,14 @@ var yas = require('../common/data-yas'), @@ -11,9 +11,14 @@ var yas = require('../common/data-yas'),
11 var $orderPrice = $('#order-price'); 11 var $orderPrice = $('#order-price');
12 var order = {}; 12 var order = {};
13 13
14 -var yohoCoin; 14 +var yohoCoin,
  15 + giftCard;
  16 +
  17 +var lastOrderPrice = $orderPrice.data('price');
15 var submitting = false; 18 var submitting = false;
16 19
  20 +var giftCardTpl = require('hbs/cart/ensure-gift-card-list.hbs');
  21 +
17 require('../common'); 22 require('../common');
18 require('../simple-header'); 23 require('../simple-header');
19 24
@@ -85,7 +90,11 @@ function compute(coin) { @@ -85,7 +90,11 @@ function compute(coin) {
85 order.coin = result.data.usedCoinNum; 90 order.coin = result.data.usedCoinNum;
86 yohoCoin.maxCoin = result.data.canUseCoinNum; 91 yohoCoin.maxCoin = result.data.canUseCoinNum;
87 92
88 - $orderPrice.html('¥ ' + result.data.last_order_amount); 93 + lastOrderPrice = result.data.last_order_amount;
  94 +
  95 + $orderPrice.html('¥ ' + lastOrderPrice);
  96 +
  97 + giftCard.setUseStatus(lastOrderPrice);
89 } 98 }
90 }); 99 });
91 } 100 }
@@ -133,44 +142,212 @@ yohoCoin = { @@ -133,44 +142,212 @@ yohoCoin = {
133 } 142 }
134 }; 143 };
135 144
136 -$('.locker-switch').click(function() {  
137 - var $this = $(this),  
138 - $par = $this.parent(); 145 +// 礼品卡
  146 +giftCard = {
  147 + $el: $('#use-gift-card'),
  148 + init: function() {
  149 + if (!this.$el.length) {
  150 + return;
  151 + }
139 152
140 - $par.toggleClass('open');  
141 -}); 153 + this.$giftCardWrap = this.$el.next();
142 154
  155 + this.getList();
  156 + this.eventBind();
  157 + },
  158 + getList: function() {
  159 + var that = this;
143 160
144 -$('#order-submit').on('click', function() {  
145 - var $this = $(this); 161 + $.ajax({
  162 + type: 'GET',
  163 + url: '/cart/ensure/giftcards'
  164 + }).then(function(data) {
  165 + if (data.code === 200) {
  166 + if (data.data && data.data.usable_giftCards && data.data.usable_giftCards.length) {
  167 + $('.can-use-tip', that.$el).text('(' + data.data.usable_giftCards.length + '张可用)');
  168 + }
  169 +
  170 + if (data.data.usable_giftCards.length) {
  171 + $('tbody', that.$giftCardWrap).html(giftCardTpl(data.data));
  172 +
  173 + that.$radios = $('.gift-card-radio', that.$giftCardWrap);
  174 + }
  175 +
  176 + that.checkContent = '<h2>安全验证</h2>' +
  177 + '<p class="tip-info">您正在使用礼品卡支付,为了保障您的安全,请进行安全验证。</p>' +
  178 + '<p class="receiver-info">验证码已发送至' + (data.data.userMobile || '您绑定的') + '手机号</p>' +
  179 + '<p><input type="text" placeholder="短信验证码" maxlength="8"><span class="send-sms">获取验证码</span></p>';
  180 + }
  181 + });
  182 + },
  183 + eventBind: function() {
  184 + var that = this;
146 185
147 - if (submitting) {  
148 - return;  
149 - } 186 + this.$giftCardWrap.on('click', '.gift-card-radio', function() {
  187 + var $this = $(this);
150 188
151 - order = handleOrderInfo(order); 189 + if ($this.hasClass('disabled')) {
  190 + return;
  191 + }
152 192
153 - if (!validateUserInfo(order)) {  
154 - return; 193 + if ($this.hasClass('on')) {
  194 + // 取消使用礼品卡,设置其他礼品卡可用
  195 + that.setUseStatus(2);
  196 + } else if (+$this.data('price') >= lastOrderPrice * 1) { // 已选礼品卡总价大于订单总价,设置其他礼品卡不可选
  197 + that.setUseStatus();
  198 + }
  199 +
  200 + $this.toggleClass('on');
  201 + that.changeCardUse();
  202 + });
  203 + },
  204 + changeCardUse: function() {
  205 + var codes = [];
  206 +
  207 + if (!this.$radios) {
  208 + return;
  209 + }
  210 +
  211 + this.$radios.filter('.on').each(function() {
  212 + codes.push($(this).data('id'));
  213 + });
  214 +
  215 + order.giftCard = codes.join(',');
  216 + compute(order.coin);
  217 + },
  218 + setUseStatus: function(price) {
  219 + if (!this.$radios) {
  220 + return;
  221 + }
  222 +
  223 + if (price && price * 1 > 0) {
  224 + this.$radios.filter('.disable').removeClass('disable');
  225 + } else {
  226 + this.$radios.not('.on').addClass('disable');
  227 + }
155 } 228 }
  229 +};
156 230
  231 +function submitOrder(reqData, url) {
157 submitting = true; 232 submitting = true;
158 $.ajax({ 233 $.ajax({
159 type: 'POST', 234 type: 'POST',
160 url: '/cart/ticketSubmit', 235 url: '/cart/ticketSubmit',
161 - data: order 236 + data: reqData
162 }).then(function(data) { 237 }).then(function(data) {
163 if (data.code === 200) { 238 if (data.code === 200) {
164 window.location.href = data.data.refer; 239 window.location.href = data.data.refer;
165 } else if (data.code === 500) { 240 } else if (data.code === 500) {
166 - errorInfo(data.message, $this.data('url')); 241 + errorInfo(data.message, url);
  242 + } else {
  243 + new dialog.Alert(data.message || '网络异常~').show();
167 } 244 }
168 }).always(function() { 245 }).always(function() {
169 submitting = false; 246 submitting = false;
170 }); 247 });
  248 +}
  249 +
  250 +function sendCkeckSms() {
  251 + return $.ajax({
  252 + type: 'POST',
  253 + url: '/cart/property/checksms',
  254 + data: {giftCard: order.giftCard}
  255 + });
  256 +}
  257 +
  258 +$('.locker-switch').click(function() {
  259 + var $this = $(this),
  260 + $par = $this.parent();
  261 +
  262 + $par.toggleClass('open');
  263 +});
  264 +
  265 +$('#order-submit').on('click', function() {
  266 + var errUrl = $(this).data('url'),
  267 + checkDg;
  268 +
  269 + if (submitting) {
  270 + return;
  271 + }
  272 +
  273 + order = handleOrderInfo(order);
  274 +
  275 + if (!validateUserInfo(order)) {
  276 + return;
  277 + }
  278 +
  279 + // 使用礼品卡时候进行短信校验
  280 + if (order.giftCard) {
  281 + checkDg = new dialog.Dialog({
  282 + content: giftCard.checkContent || '',
  283 + className: 'gift-card-check-dialog',
  284 + btns: [{
  285 + id: 'check-cancel',
  286 + btnClass: ['check-cancel'],
  287 + name: '取消',
  288 + cb: function() {
  289 + checkDg.close();
  290 + }
  291 + }, {
  292 + id: 'check-sure',
  293 + btnClass: ['check-sure'],
  294 + name: '确定使用',
  295 + cb: function() {
  296 + order.checkCode = $('input', checkDg.$el).val();
  297 +
  298 + if (order.checkCode) {
  299 + submitOrder(order, errUrl);
  300 + checkDg.close();
  301 + }
  302 + }
  303 + }]
  304 + });
  305 +
  306 + checkDg.$sendBtn = $('.send-sms', checkDg.$el);
  307 + checkDg.sendSms = function() {
  308 + var that = this;
  309 +
  310 + if (!this.$sendBtn || this.seconds > 0) {
  311 + return;
  312 + }
  313 +
  314 + sendCkeckSms(); // 发送验证码
  315 +
  316 + if (!this.seconds || this.seconds < 1) {
  317 + this.seconds = 59;
  318 + }
  319 +
  320 + this.timer && clearInterval(this.timer);
  321 +
  322 + this.$sendBtn.text((this.seconds--) + 's').addClass('timer');
  323 +
  324 + this.timer = setInterval(function() {
  325 + if (that.seconds > 0) {
  326 + that.$sendBtn.text((that.seconds--) + 's').addClass('timer');
  327 + } else {
  328 + that.$sendBtn.text('重新获取').removeClass('timer');
  329 + clearInterval(that.timer);
  330 + }
  331 + }, 1000);
  332 +
  333 + return this;
  334 + };
  335 +
  336 + checkDg.$sendBtn.click(function() {
  337 + checkDg.sendSms();
  338 + });
  339 +
  340 + checkDg.sendSms().show();
  341 +
  342 + return;
  343 + }
  344 +
  345 + order.checkCode && delete order.checkCode;
  346 + submitOrder(order, errUrl);
171 }); 347 });
172 348
173 yohoCoin.init(); 349 yohoCoin.init();
  350 +giftCard.init();
174 351
175 // 获取用户是否新客(品众统计)写cookie 352 // 获取用户是否新客(品众统计)写cookie
176 $.ajax({type: 'GET', url: '/home/newuser'}); 353 $.ajax({type: 'GET', url: '/home/newuser'});