客户余额等于总价时无法配额的问题
parent
81c3973dd3
commit
aeaa8a8540
|
|
@ -52,4 +52,26 @@ public class MathUtil {
|
|||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取double类型的小数位数
|
||||
* @param number
|
||||
* @return
|
||||
*/
|
||||
public static int getNumberDecimalDigits(double number) {
|
||||
String moneyStr = String.valueOf(number);
|
||||
String[] num = moneyStr.split("\\.");
|
||||
if (num.length == 2) {
|
||||
for (;;){
|
||||
if (num[1].endsWith("0")) {
|
||||
num[1] = num[1].substring(0, num[1].length() - 1);
|
||||
}else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return num[1].length();
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.cowr.common.enums.Enums;
|
||||
import com.cowr.common.enums.OrderStateEnum;
|
||||
import com.cowr.common.utils.DateTimeUtil;
|
||||
import com.cowr.common.utils.MathUtil;
|
||||
import com.cowr.common.view.Result;
|
||||
import com.cowr.model.*;
|
||||
import com.cowr.service.ssjygl.base.BaseSyncService;
|
||||
|
|
@ -81,6 +82,10 @@ public class OrderclusterSyncService extends BaseSyncService {
|
|||
int max_truck = obj.getIntValue("max_truck");
|
||||
int product_id = obj.getIntValue("product_id");
|
||||
double total_weight = obj.getDouble("total_weight");
|
||||
int decimal = 0;
|
||||
if (total_weight > 0 && String.valueOf(total_weight).indexOf(".") > 0) {
|
||||
decimal = MathUtil.getNumberDecimalDigits(total_weight);
|
||||
}
|
||||
|
||||
Supermarket supermarket = SvrCacheData.SUP_CACHE.get(supermarket_id);
|
||||
if (supermarket == null) {
|
||||
|
|
@ -130,13 +135,13 @@ public class OrderclusterSyncService extends BaseSyncService {
|
|||
}
|
||||
|
||||
// 本次配额总价不能超过余额
|
||||
if (unitprice.multiply(new BigDecimal(total_weight)).compareTo(prepayCustomer.getSurplus()) > 0) {
|
||||
if (unitprice.multiply(new BigDecimal(total_weight).setScale(decimal, BigDecimal.ROUND_HALF_UP)).compareTo(prepayCustomer.getSurplus()) > 0) {
|
||||
return Result.failedstr("余额 %.2f 不足以购买 %.2f 吨", prepayCustomer.getSurplus(), total_weight);
|
||||
}
|
||||
|
||||
// 客户在所有砂站的未完成的配额中,未执行完成的总金额
|
||||
BigDecimal undo_price = OrderclusterService.me.undoPrice(customer_id);
|
||||
BigDecimal plan_total_price = new BigDecimal(total_weight).multiply(unitprice).add(undo_price); // 本次配额总价格
|
||||
BigDecimal plan_total_price = (new BigDecimal(total_weight).setScale(decimal, BigDecimal.ROUND_HALF_UP)).multiply(unitprice).add(undo_price); // 本次配额总价格
|
||||
|
||||
// 本次计划总额加上未完成的量,不能超过余额
|
||||
if (plan_total_price.compareTo(prepayCustomer.getSurplus()) > 0) {
|
||||
|
|
@ -164,7 +169,7 @@ public class OrderclusterSyncService extends BaseSyncService {
|
|||
|
||||
model.setTransDistance(SupermarketReceiverDistanceService.me.getDistance(supermarket_id, customer_id));
|
||||
|
||||
model.setTotalWeight(new BigDecimal(total_weight));
|
||||
model.setTotalWeight(new BigDecimal(total_weight).setScale(decimal, BigDecimal.ROUND_HALF_UP));
|
||||
model.setStartTime(start_time);
|
||||
model.setCutoffTime(cutoff_time);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue