Authored by yyq

限定发售 有货币使用改造

... ... @@ -12,6 +12,30 @@ const crypto = global.yoho.crypto;
const easypayApi = require('./easypay-api');
const _hadelUseYohoCoin = (info) => {
let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0);
if (info) {
info.canUseCoinNum = _.round(info.yoho_coin * 100);
info.usedCoinNum = _.round(info.use_yoho_coin * 100);
if (!info.canUseCoinNum) {
let coinErrorTip = '';
if (info.total_yoho_coin_num > limitCoin) {
coinErrorTip = '抱歉,您的订单实付款不满足有货币使用条件';
} else {
coinErrorTip = `抱歉,您的有货币不足,有货币满${limitCoin}个方可使用`;
}
info.coinErrorTip = coinErrorTip;
}
}
return info;
};
const _handelPaymentInfo = (d) => {
let resData = {};
... ... @@ -70,7 +94,7 @@ const _handelPaymentInfo = (d) => {
paymentWay: d.payment_way,
deliveryTime: d.delivery_time,
deliveryWay: d.delivery_way,
shoppingCartData: d.shopping_cart_data,
shoppingCartData: _hadelUseYohoCoin(d.shopping_cart_data),
invoices: d.invoices
});
... ...
... ... @@ -270,6 +270,24 @@
<div class="using-coin coin-trigger hide">
<ul>
<li>
{{#if coinErrorTip}}
<span class="red">{{coinErrorTip}}</span>
{{^}}
有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍
{{/if}}
<i class="iconfont help-icon">&#xe628;</i>
<div class="coin-tip-help">
<p>有货币使用条件:</p>
<p>1.订单金额大于20元(含) 2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含) 3.有货币支付不得超过每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}</p>
<p>备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
</div>
</li>
<li>您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span class="red">{{canUseCoinNum}}</span></li>
<li>
<p{{#if coinErrorTip}} class="coin-use-hide"{{/if}}>本次使用有货币<span class="coin-box">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span></p>
</li>
{{!-- <li>
使用有货币:<input id="coin-used" class="coin-used" type="text" data-max="{{hasCoin}}">个
</li>
<li class="coin-sum-row">
... ... @@ -277,14 +295,16 @@
</li>
<li class="coin-tip-row">
<span id="coin-tip" class="coin-tip vhide"></span>
</li>
</li> --}}
</ul>
<p class="btns">
<span id="coin-sure" class="coin-sure sure-btn">确定</span>
<span id="coin-cancel" class="coin-cancel cancel-btn">取消</span>
<a href="/help/?category_id=87" class="coin-help" target="_blank">有货币使用规则?</a>
</p>
</div>
<input id="coin-used" type="hidden" data-coin="{{usedCoinNum}}" data-max={{canUseCoinNum}}>
</li>
</ul>
</div>
... ...
... ... @@ -16,16 +16,7 @@ var couponsTpl = Hbs.compile($('#coupons-tpl').html());
var promotionTpl = Hbs.compile($('#promotion-list-tpl').html());
var $coin = $('#coin-used');
var $coinTip = $('#coin-tip');
var $coinSure = $('#coin-sure');
var coinMax = +$coin.data('max');
var coinStatus = {
err: '请输入一个正整数',
max: '您的有货币不足',
success: '抵扣',
maxUse: '您最多使用',
muPostfix: '个有货币'
};
var queryInfo;
var pkgCache = {};
... ... @@ -178,63 +169,35 @@ if ($('#use-coupons').length) {
}
// 有货币
if ($coin) {
$coin.data($coin.data()); // 防止人为更改有货币使用数量
}
$('#use-coin, #coin-sure, #coin-cancel').click(function() {
$('.coin-trigger').toggleClass('hide');
});
$coin.on('propertychange input', function() {
var c = $.trim($coin.val());
var err = true;
if (c === '') {
$coinSure.click(function() {
var data = $coin.data();
// 输入框为空,确定按钮不可点
$coinTip.addClass('vhide');
$coinTip.text(coinStatus.err);
if ($coinSure.hasClass('disable') ||
data.coin === data.max) {
return;
} else if (!/^[1-9]\d*$/.test(c)) {
// 验证输入不为正整数
$coinTip.text(coinStatus.err);
} else if (+c > coinMax) {
// 有货币不足
$coinTip.text(coinStatus.max);
} else if (+c > $('#sum-row').data('amount') * 100) {
// 输入的有货币大于订单额度
$coinTip.text(coinStatus.maxUse + ($('#sum-row').data('amount') * 100) + coinStatus.muPostfix);
} else {
err = false;
$coinTip.text(coinStatus.success + (c / 100).toFixed(2) + '元');
// 已使用面板的数据显示更新
// $coinUsed.html(c);
// $coinDeduction.html((c / 100).toFixed(2));
}
if (err) {
$coinSure.addClass('disable');
$coinTip.removeClass('vhide');
} else {
$coinSure.removeClass('disable');
$coinTip.addClass('vhide');
}
});
$coinSure.click(function() {
if ($coinSure.hasClass('disable')) {
return;
}
$coin.data('coin', $.trim($coin.val()));
$coin.data('coin', data.max);
// coin change trigger compute
compute();
});
$('#coin-cancel').click(function() {
$coin.val('').data('coin', '');
$coinTip.addClass('vhide').text('');
var data = $coin.data();
if (data.coin * 1 === 0) {
return;
}
$coin.data('coin', 0);
// coin cancel trigger compute
compute();
... ...
... ... @@ -492,6 +492,75 @@
}
}
.using-coin {
text-align: left;
li {
padding-bottom: 10px;
}
.red {
color: #db6976;
}
.help-icon {
float: right;
cursor: pointer;
&:hover + .coin-tip-help {
display: block;
}
}
.coin-tip-help {
width: 310px;
padding: 6px;
border: 1px solid #000;
background-color: #fff;
position: absolute;
margin-left: 56px;
margin-top: 10px;
display: none;
}
.coin-use-hide {
color: #d4d4d4;
}
.coin-box {
display: inline-block;
width: 70px;
height: 24px;
line-height: 24px;
text-align: center;
border: 1px solid #d4d4d4;
margin: 0 6px;
}
.btns {
margin-top: 10px;
text-align: left;
span {
padding: 4px 14px;
cursor: pointer;
border: 1px solid #ccc;
}
.sure-btn {
color: #fff;
background-color: #000;
border-color: #000;
margin-right: 20px;
}
.coin-help {
float: right;
color: #5291f7;
}
}
}
.coin-sum-row,
.coin-tip-row {
padding: 10px 0;
... ...