123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- var split = function (input, sep) {
- sep === undefined && (sep = ',')
- return input.toString().split(sep)
- }
- var calculateOrderPayMoney = function (
- price,
- selectCardId,
- memberCard,
- currentDiscount,
- currentChangeCoupon,
- productData
- ) {
- var payMoney = price ? parseFloat(price) : 0
-
- if (selectCardId) {
- var memberCardSaveMoney = memberCard.save_money
- ? parseFloat(memberCard.save_money)
- : 0
- var memberCardPrice = memberCard.price ? parseFloat(memberCard.price) : 0
- payMoney -= memberCardSaveMoney
- payMoney += memberCardPrice
- }
-
- if (currentDiscount == 0) {
- payMoney = 0
- }
-
- if (currentChangeCoupon) {
-
- var couponType = currentChangeCoupon.type
- var couponMoney = payMoney
- if (couponType == 1) {
- couponMoney = currentChangeCoupon.price
- ? parseFloat(currentChangeCoupon.price)
- : 0
- } else if (couponType == 2) {
- couponMoney = currentChangeCoupon.full_price
- ? parseFloat(currentChangeCoupon.full_price)
- : 0
- }
- payMoney -= couponMoney
- }
-
- if (productData) {
- payMoney += parseFloat(productData.price ? productData.price : 0.0)
- }
- payMoney = payMoney >= 0 ? payMoney.toFixed(2) : '0.00'
- console.log('calculateOrderPayMoney===', payMoney)
- return payMoney
- }
- var calculateMoney = function (args) {
- var sum = 0.0
- var argsList = args.toString().split(',')
- for (var i = 0; i < argsList.length; i++) {
- if (argsList[i]) {
- sum += parseFloat(argsList[i])
- }
- }
- sum = sum >= 0 ? sum.toFixed(2) : '0.00'
- console.log('calculateMoney===', sum)
- return sum
- }
- var getDistance = function (lat1, lng1, lat2, lng2) {
- lat1 = lat1 || 0;
- lng1 = lng1 || 0;
- lat2 = lat2 || 0;
- lng2 = lng2 || 0;
- var rad1 = lat1 * Math.PI / 180.0;
- var rad2 = lat2 * Math.PI / 180.0;
- var a = rad1 - rad2;
- var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
- var r = 6378137;
- var distance = r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2)));
-
- return (distance/1000).toFixed(1);
- }
-
- var formatValue = function (value, type) {
- if (typeof value === 'string') {
- if (value.match('¥')) {
-
- var reg = getRegExp('¥', 'g')
- value = value.replace(reg, '')
-
- }
- }
- var result = value
- switch (type) {
- case 'split':
- result = ('' + result).split('.')
- break
- case 'price':
-
- break
- case 'sold':
-
- break
- case 'commission':
-
- break
- case 'coupon':
-
- break
- }
- return result
- }
- module.exports = {
- split: split,
- calculateOrderPayMoney: calculateOrderPayMoney,
- calculateMoney: calculateMoney,
- getDistance:getDistance,
- formatValue:formatValue
- }
|