Authored by yyq

Merge branch 'feature/giftCart' into release/6.1

... ... @@ -39,10 +39,11 @@ const ticketEnsure = (req, res, next) => {
const ticketSubmit = (req, res, next) => {
let uid = req.user.uid;
let sku = req.body.sku || 0;
let count = req.body.count || 0;
let mobile = req.body.mobile || 0;
let yohoCoin = req.body.coin || 0;
let params = req.body;
let sku = params.sku || 0;
let count = params.count || 0;
let mobile = params.mobile || 0;
let yohoCoin = params.coin || 0;
if (!sku || !count || !mobile) {
return res.json({
... ... @@ -51,7 +52,9 @@ const ticketSubmit = (req, res, next) => {
});
}
ticketService.submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
params.udid = req.yoho.udid;
ticketService.submitTicket(uid, sku, count, mobile, yohoCoin, params).then(result => {
return res.json(result);
}).catch(next);
};
... ... @@ -62,7 +65,7 @@ const ticketCompute = (req, res, next) => {
let buyNumber = req.body.count || 0;
let yohoCoin = req.body.coin || 0;
ticketService.addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
ticketService.addTicket(uid, sku, buyNumber, yohoCoin, req.body).then(result => {
if (_.isEmpty(result)) {
return res.json({
code: 401,
... ...
... ... @@ -12,7 +12,7 @@ const api = global.yoho.API;
* @param mobile 手机号码
* @param yohoCoin 有货币
*/
function submit(uid, sku, count, mobile, yohoCoin) {
function submit(uid, sku, count, mobile, yohoCoin, other = {}) {
let params = {
method: 'app.shopping.submitTicket',
uid,
... ... @@ -25,6 +25,18 @@ function submit(uid, sku, count, mobile, yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
if (other.giftCard) {
Object.assign(params, {
gift_card_code: other.giftCard
});
}
if (other.udid) {
Object.assign(params, {
udid: other.udid
});
}
return api.get('', params);
}
... ... @@ -35,7 +47,7 @@ function submit(uid, sku, count, mobile, yohoCoin) {
* @param count 购买数量 1-4
* @param yohoCoin 有货币
*/
function add(uid, sku, count, yohoCoin) {
function add(uid, sku, count, yohoCoin, other = {}) {
let params = {
method: 'app.shopping.ticket',
uid,
... ... @@ -47,6 +59,12 @@ function add(uid, sku, count, yohoCoin) {
params.use_yoho_coin = yohoCoin / 100;
}
if (other.giftCard) {
Object.assign(params, {
gift_card_code: other.giftCard
});
}
return api.get('', params);
}
... ...
... ... @@ -21,8 +21,8 @@ function _handleAmount(info) {
return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
}
const addTicket = co(function * (uid, sku, count, yohoCoin) {
let ticketInfo = yield api.add(uid, sku, count, yohoCoin);
const addTicket = co(function * (uid, sku, count, yohoCoin, other) {
let ticketInfo = yield api.add(uid, sku, count, yohoCoin, other);
let result = {};
if (_.isEmpty(ticketInfo)) {
... ... @@ -47,8 +47,8 @@ const addTicket = co(function * (uid, sku, count, yohoCoin) {
return result;
});
const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {
let result = yield api.submit(uid, sku, count, mobile, yohoCoin);
const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin, other) {
let result = yield api.submit(uid, sku, count, mobile, yohoCoin, other);
if (_.isEmpty(result)) {
return {
... ...
... ... @@ -41,7 +41,7 @@ router.post('/easypay/compute', auth, easypay.compute); // 价格重新计算
router.post('/easypay/submit', auth, easypay.submit); // 限购商品订单提交
router.get('/ticketEnsure', auth, ticket.ticketEnsure);
router.post('/ticketSubmit', auth, ticket.ticketSubmit);
router.post('/ticketSubmit', auth, ensure.submitCheck, ticket.ticketSubmit);
router.post('/ticketCompute', auth, ticket.ticketCompute);
router.get('/cart', cart.cart);
... ...
... ... @@ -75,35 +75,55 @@
<dd id="yoho-coin-box" class="yoho-coin-box" data-coin="{{usedCoinNum}}"
data-max={{canUseCoinNum}} data-total="{{total_yoho_coin_num}}">
<div class="outer-view">
<p class="coin-err-tip">{{coinErrorTip}}</p>
<p>有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span
class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>
<i class="help-icon"></i>
<div class="coin-tip-help">
<p>有货币使用提示:</p>
<p>
1.订单金额大于20元(含20元)<br>
2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含{{yoho_coin_pay_rule.num_limit}}个) <br>
3.有货币支付上限为每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}
</p>
<p class="rs-text">备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
</div>
</div>
<div class="coin-main-view">
<p>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span>
</p>
<p class="grey fw300">您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span
class="red">{{canUseCoinNum}}</span></p>
<label class="coin-cancel-btn fw300">取消使用</label>
<label class="coin-use-btn">确定</label>
</div>
<p class="coin-err-tip">{{coinErrorTip}}</p>
<p>有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span
class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>
<i class="help-icon"></i>
<div class="coin-tip-help">
<p>有货币使用提示:</p>
<p>
1.订单金额大于20元(含20元)<br>
2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含{{yoho_coin_pay_rule.num_limit}}个) <br>
3.有货币支付上限为每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}
</p>
<p class="rs-text">备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
</div>
</div>
<div class="coin-main-view">
<p>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span>
</p>
<p class="grey fw300">您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span
class="red">{{canUseCoinNum}}</span></p>
<label class="coin-cancel-btn fw300">取消使用</label>
<label class="coin-use-btn">确定</label>
</div>
</dd>
</dl>
<dt id="use-gift-card"><span class="locker-switch"></span>使用礼品卡<span class="can-use-tip"></span></dt>
<dd class="gift-card-box">
<table>
<thead>
<tr>
<th width="260">卡号</th>
<th>面值</th>
<th>卡内余额</th>
<th width="230">有效期</th>
<th width="86">选择</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5">暂无礼品卡</td>
</tr>
</tbody>
</table>
</dd>
</div>
<div class="sum-wrap">
应付金额:<span id="order-price" class="price">¥ {{round last_order_amount 2}}</span>
应付金额:<span id="order-price" class="price" data-price="{{last_order_amount}}">¥ {{round last_order_amount 2}}</span>
<button id="order-submit" data-url="{{productUrl}}">提交订单</button>
</div>
... ...
... ... @@ -758,7 +758,7 @@ giftCard = {
});
order.giftCard = codes.join(',');
compute();
compute(order.coin);
},
setUseStatus: function(price) {
if (!this.$radios) {
... ...
... ... @@ -11,9 +11,14 @@ var yas = require('../common/data-yas'),
var $orderPrice = $('#order-price');
var order = {};
var yohoCoin;
var yohoCoin,
giftCard;
var lastOrderPrice = $orderPrice.data('price');
var submitting = false;
var giftCardTpl = require('hbs/cart/ensure-gift-card-list.hbs');
require('../common');
require('../simple-header');
... ... @@ -85,7 +90,11 @@ function compute(coin) {
order.coin = result.data.usedCoinNum;
yohoCoin.maxCoin = result.data.canUseCoinNum;
$orderPrice.html('¥ ' + result.data.last_order_amount);
lastOrderPrice = result.data.last_order_amount;
$orderPrice.html('¥ ' + lastOrderPrice);
giftCard.setUseStatus(lastOrderPrice);
}
});
}
... ... @@ -133,44 +142,212 @@ yohoCoin = {
}
};
$('.locker-switch').click(function() {
var $this = $(this),
$par = $this.parent();
// 礼品卡
giftCard = {
$el: $('#use-gift-card'),
init: function() {
if (!this.$el.length) {
return;
}
$par.toggleClass('open');
});
this.$giftCardWrap = this.$el.next();
this.getList();
this.eventBind();
},
getList: function() {
var that = this;
$('#order-submit').on('click', function() {
var $this = $(this);
$.ajax({
type: 'GET',
url: '/cart/ensure/giftcards'
}).then(function(data) {
if (data.code === 200) {
if (data.data && data.data.usable_giftCards && data.data.usable_giftCards.length) {
$('.can-use-tip', that.$el).text('(' + data.data.usable_giftCards.length + '张可用)');
}
if (data.data.usable_giftCards.length) {
$('tbody', that.$giftCardWrap).html(giftCardTpl(data.data));
that.$radios = $('.gift-card-radio', that.$giftCardWrap);
}
that.checkContent = '<h2>安全验证</h2>' +
'<p class="tip-info">您正在使用礼品卡支付,为了保障您的安全,请进行安全验证。</p>' +
'<p class="receiver-info">验证码已发送至' + (data.data.userMobile || '您绑定的') + '手机号</p>' +
'<p><input type="text" placeholder="短信验证码" maxlength="8"><span class="send-sms">获取验证码</span></p>';
}
});
},
eventBind: function() {
var that = this;
if (submitting) {
return;
}
this.$giftCardWrap.on('click', '.gift-card-radio', function() {
var $this = $(this);
order = handleOrderInfo(order);
if ($this.hasClass('disabled')) {
return;
}
if (!validateUserInfo(order)) {
return;
if ($this.hasClass('on')) {
// 取消使用礼品卡,设置其他礼品卡可用
that.setUseStatus(2);
} else if (+$this.data('price') >= lastOrderPrice * 1) { // 已选礼品卡总价大于订单总价,设置其他礼品卡不可选
that.setUseStatus();
}
$this.toggleClass('on');
that.changeCardUse();
});
},
changeCardUse: function() {
var codes = [];
if (!this.$radios) {
return;
}
this.$radios.filter('.on').each(function() {
codes.push($(this).data('id'));
});
order.giftCard = codes.join(',');
compute(order.coin);
},
setUseStatus: function(price) {
if (!this.$radios) {
return;
}
if (price && price * 1 > 0) {
this.$radios.filter('.disable').removeClass('disable');
} else {
this.$radios.not('.on').addClass('disable');
}
}
};
function submitOrder(reqData, url) {
submitting = true;
$.ajax({
type: 'POST',
url: '/cart/ticketSubmit',
data: order
data: reqData
}).then(function(data) {
if (data.code === 200) {
window.location.href = data.data.refer;
} else if (data.code === 500) {
errorInfo(data.message, $this.data('url'));
errorInfo(data.message, url);
} else {
new dialog.Alert(data.message || '网络异常~').show();
}
}).always(function() {
submitting = false;
});
}
function sendCkeckSms() {
return $.ajax({
type: 'POST',
url: '/cart/property/checksms',
data: {giftCard: order.giftCard}
});
}
$('.locker-switch').click(function() {
var $this = $(this),
$par = $this.parent();
$par.toggleClass('open');
});
$('#order-submit').on('click', function() {
var errUrl = $(this).data('url'),
checkDg;
if (submitting) {
return;
}
order = handleOrderInfo(order);
if (!validateUserInfo(order)) {
return;
}
// 使用礼品卡时候进行短信校验
if (order.giftCard) {
checkDg = new dialog.Dialog({
content: giftCard.checkContent || '',
className: 'gift-card-check-dialog',
btns: [{
id: 'check-cancel',
btnClass: ['check-cancel'],
name: '取消',
cb: function() {
checkDg.close();
}
}, {
id: 'check-sure',
btnClass: ['check-sure'],
name: '确定使用',
cb: function() {
order.checkCode = $('input', checkDg.$el).val();
if (order.checkCode) {
submitOrder(order, errUrl);
checkDg.close();
}
}
}]
});
checkDg.$sendBtn = $('.send-sms', checkDg.$el);
checkDg.sendSms = function() {
var that = this;
if (!this.$sendBtn || this.seconds > 0) {
return;
}
sendCkeckSms(); // 发送验证码
if (!this.seconds || this.seconds < 1) {
this.seconds = 59;
}
this.timer && clearInterval(this.timer);
this.$sendBtn.text((this.seconds--) + 's').addClass('timer');
this.timer = setInterval(function() {
if (that.seconds > 0) {
that.$sendBtn.text((that.seconds--) + 's').addClass('timer');
} else {
that.$sendBtn.text('重新获取').removeClass('timer');
clearInterval(that.timer);
}
}, 1000);
return this;
};
checkDg.$sendBtn.click(function() {
checkDg.sendSms();
});
checkDg.sendSms().show();
return;
}
order.checkCode && delete order.checkCode;
submitOrder(order, errUrl);
});
yohoCoin.init();
giftCard.init();
// 获取用户是否新客(品众统计)写cookie
$.ajax({type: 'GET', url: '/home/newuser'});
... ...