|
|
|
@ -1,75 +1,6 @@
|
|
|
|
|
/**
|
|
|
|
|
* Created by yixian on 2017-05-08
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
function CashCoupon(id, minPay, cash, title, autoUse, group) {
|
|
|
|
|
this.getGroup = function () {
|
|
|
|
|
return group;
|
|
|
|
|
};
|
|
|
|
|
this.handleDiscount = function (price, originPrice, discounts, useCoupons) {
|
|
|
|
|
if (autoUse || useCoupons.indexOf(id) >= 0) {
|
|
|
|
|
var rate = 1;
|
|
|
|
|
if (window.currency == 'CNY') {
|
|
|
|
|
rate = parseFloat(window.exchange_rate);
|
|
|
|
|
}
|
|
|
|
|
var comparePrice = Decimal.mul(originPrice, rate).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
if (new Decimal(comparePrice).gte(Decimal.mul(minPay, rate).toFixed(2, Decimal.ROUND_FLOOR))) {
|
|
|
|
|
var nPrice = Decimal.sub(price, Decimal.mul(cash, rate).toFixed(2, Decimal.ROUND_FLOOR)).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
discounts.push({title: '满减', amount: Decimal.sub(price, nPrice).toFixed(2, Decimal.ROUND_FLOOR)});
|
|
|
|
|
return nPrice;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Decimal(price).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function DiscountCoupon(id, minPay, percentage, title, autoUse, group) {
|
|
|
|
|
this.getGroup = function () {
|
|
|
|
|
return group;
|
|
|
|
|
};
|
|
|
|
|
this.handleDiscount = function (price, originPrice, discounts, useCoupons) {
|
|
|
|
|
if (autoUse || useCoupons.indexOf(id) >= 0) {
|
|
|
|
|
var rate = 1;
|
|
|
|
|
if (window.currency == 'CNY') {
|
|
|
|
|
rate = parseFloat(window.exchange_rate);
|
|
|
|
|
}
|
|
|
|
|
var comparePrice = Decimal.mul(originPrice, rate).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
if (new Decimal(comparePrice).gte(new Decimal(minPay))) {
|
|
|
|
|
var nPrice = Decimal.mul(price, percentage).mul(0.01).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
discounts.push({title: '折扣', amount: Decimal.sub(price, nPrice).toFixed(2, Decimal.ROUND_FLOOR)});
|
|
|
|
|
return nPrice;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Decimal(price).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BalanceCoupon(id, minPay, balance, title, autoUse, group) {
|
|
|
|
|
this.getGroup = function () {
|
|
|
|
|
return group;
|
|
|
|
|
};
|
|
|
|
|
this.handleDiscount = function (price, originPrice, discounts, useCoupons) {
|
|
|
|
|
if (autoUse || useCoupons.indexOf(id) >= 0) {
|
|
|
|
|
var rate = 1;
|
|
|
|
|
if (window.currency == 'CNY') {
|
|
|
|
|
rate = parseFloat(window.exchange_rate);
|
|
|
|
|
}
|
|
|
|
|
var comparePrice = Decimal.mul(originPrice, rate).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
if (new Decimal(comparePrice).gte(new Decimal(minPay))) {
|
|
|
|
|
var result = Decimal.sub(price, Decimal.mul(balance, rate));
|
|
|
|
|
var nPrice = Decimal.max(result, 0).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
var discountAmount = Decimal.sub(price, nPrice).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
if (discountAmount > 0) {
|
|
|
|
|
discounts.push({title: '抵扣', amount: discountAmount});
|
|
|
|
|
}
|
|
|
|
|
return nPrice;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Decimal(price).toFixed(2, Decimal.ROUND_FLOOR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.coupons = [];
|
|
|
|
|
$(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
var dataCache = {price: '0', coupons: [], coupon_groups: {}};
|
|
|
|
@ -227,7 +158,7 @@ $(function () {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dataCache.paying = true;
|
|
|
|
|
var data = {amount: dataCache.price + '', original_number: true, currency: window.currency,device_id: window.cashier_phone};
|
|
|
|
|
var data = {price: dataCache.price + '', original_number: true, currency: window.currency,device_id: window.cashier_phone};
|
|
|
|
|
if (dataCache.remark) {
|
|
|
|
|
data.description = dataCache.remark;
|
|
|
|
|
}else {
|
|
|
|
|