|
|
@@ -136,7 +136,10 @@ public class SubmitOrderListener {
|
|
|
Long shopId = shopCartOrderDto.getShopId();
|
|
|
// 订单信息
|
|
|
com.yami.shop.bean.model.Order order = new com.yami.shop.bean.model.Order();
|
|
|
- Double actualTotal = shopCartOrderDto.getActualTotal();
|
|
|
+ order.setIsPayed(0);
|
|
|
+ order.setStatus(OrderStatus.UNPAY.value());
|
|
|
+ double actualTotal = Arith.add(shopCartOrderDto.getActualTotal(), shopCartOrderDto.getTransfee());
|
|
|
+ boolean isUseTransfee = false;
|
|
|
//企业用户才进这个判断,并且该用户的积分必须大于0
|
|
|
if (1 == mergerOrder.getPlatform() && null != point && point > 0) {
|
|
|
// 计算商品金额和积分
|
|
|
@@ -144,15 +147,20 @@ public class SubmitOrderListener {
|
|
|
Double vp = Double.valueOf(point);
|
|
|
if (vp >= mul) {
|
|
|
//积分完全足够支付
|
|
|
+ order.setOffsetPoints(Long.valueOf(String.valueOf(mul).split("\\.")[0]));
|
|
|
actualTotal = 0.0;//剩下需要付的钱
|
|
|
- order.setOffsetPoints(Long.valueOf(String.valueOf(mul)));
|
|
|
} else {
|
|
|
//积分不够抵扣
|
|
|
double sub = Arith.sub(mul, vp);
|
|
|
//剩下需要付的钱
|
|
|
+ order.setOffsetPoints(Long.valueOf(String.valueOf(sub).split("\\.")[0]));
|
|
|
actualTotal = sub / 100;
|
|
|
- order.setOffsetPoints(Long.valueOf(String.valueOf(sub)));
|
|
|
+ mergerOrder.setNextPay(Boolean.TRUE);
|
|
|
+ order.setIsPayed(1);
|
|
|
+ order.setStatus(OrderStatus.PADYED.value());
|
|
|
}
|
|
|
+ } else {
|
|
|
+ mergerOrder.setNextPay(Boolean.TRUE);
|
|
|
}
|
|
|
// 订单商品名称
|
|
|
StringBuilder orderProdName = new StringBuilder(100);
|
|
|
@@ -183,8 +191,14 @@ public class SubmitOrderListener {
|
|
|
Double actualItem = shopCartItem.getActualTotal();
|
|
|
//后台充值的积分
|
|
|
if (1 == mergerOrder.getPlatform() && null != point && point > 0) {
|
|
|
+ Double useActualItem = actualItem;
|
|
|
+ if (!isUseTransfee) {//每个订单增加手续费,都只扣一次
|
|
|
+ Double transfee = shopCartOrderDto.getTransfee();
|
|
|
+ useActualItem = Arith.add(useActualItem, transfee);
|
|
|
+ isUseTransfee = Boolean.TRUE;
|
|
|
+ }
|
|
|
//把钱换算成积分
|
|
|
- actualItem = this.doGetOrderItemPoints(Arith.mul(actualItem, 100), expiryQueue, orderNumber);
|
|
|
+ actualItem = this.doGetOrderItemPoints(Arith.mul(useActualItem, 100), expiryQueue, orderNumber);
|
|
|
//把积分换算成钱
|
|
|
if (actualItem > 0) {
|
|
|
actualItem = Arith.div(actualItem, 100);
|
|
|
@@ -225,11 +239,10 @@ public class SubmitOrderListener {
|
|
|
order.setTotal(shopCartOrderDto.getTotal());
|
|
|
// 实际总额
|
|
|
order.setActualTotal(actualTotal);
|
|
|
- order.setStatus(OrderStatus.UNPAY.value());
|
|
|
+
|
|
|
order.setChannelId(Long.valueOf(mergerOrder.getPlatform()));
|
|
|
order.setUpdateTime(now);
|
|
|
order.setCreateTime(now);
|
|
|
- order.setIsPayed(0);
|
|
|
order.setDeleteStatus(0);
|
|
|
order.setProductNums(shopCartOrderDto.getTotalCount());
|
|
|
order.setAddrOrderId(addrOrderId);
|
|
|
@@ -382,32 +395,50 @@ public class SubmitOrderListener {
|
|
|
|
|
|
private Double doGetOrderItemPoints(Double actualTotal, ArrayDeque<PointsRecord> expiryQueue, String orderNumber) {
|
|
|
PointsRecord pointsRecord = expiryQueue.poll();
|
|
|
- //判定可用金额
|
|
|
- BigDecimal points = pointsRecord.getPoints();
|
|
|
- BigDecimal variablePoints = pointsRecord.getVariablePoints();
|
|
|
- //充值记录中可用的记录
|
|
|
- Double available = points.subtract(variablePoints).doubleValue();
|
|
|
- actualTotal = Arith.sub(actualTotal, available);
|
|
|
- pointsRecord.setVariablePoints(BigDecimal.valueOf(available));
|
|
|
- if (available > actualTotal) {
|
|
|
- //钱已经抵扣完,但是当条积分还有剩余,所以不要重新把剩余的放入队列
|
|
|
- //更改pointsRecord的变动的值,并修改数据库
|
|
|
- expiryQueue.addFirst(pointsRecord);
|
|
|
- }
|
|
|
- int update = pointsRecordMapper.updateById(pointsRecord);
|
|
|
- if (update > 0) {
|
|
|
- PointsRecord pr = new PointsRecord();
|
|
|
+ PointsRecord pr = new PointsRecord();
|
|
|
+ if (pointsRecord != null) {
|
|
|
+ //判定可用金额
|
|
|
+ BigDecimal points = pointsRecord.getPoints() != null ? pointsRecord.getPoints() : BigDecimal.ZERO;
|
|
|
+ BigDecimal variablePoints = pointsRecord.getVariablePoints() != null ? pointsRecord.getVariablePoints() : BigDecimal.ZERO;
|
|
|
+ //充值记录中可用的记录
|
|
|
+ double available = points.subtract(variablePoints).doubleValue();
|
|
|
BeanUtil.copyProperties(pointsRecord, pr);
|
|
|
- pr.setId(null);
|
|
|
- pr.setOrderNumber(orderNumber);
|
|
|
- }
|
|
|
- // TODO 插入数据库
|
|
|
- if (actualTotal > available) {
|
|
|
- //把当前积分已完全够扣,但是还有钱
|
|
|
- actualTotal = this.doGetOrderItemPoints(actualTotal, expiryQueue, orderNumber);
|
|
|
- } else {
|
|
|
- //恰好积分等于钱
|
|
|
-// actualTotal = Arith.sub(actualTotal, available);
|
|
|
+ if (available > actualTotal) {
|
|
|
+ //钱已经抵扣完,但是当条积分还有剩余,所以不要重新把剩余的放入队列。钱少积分多
|
|
|
+ //剩余的积分
|
|
|
+ pointsRecord.setVariablePoints(variablePoints.add(BigDecimal.valueOf(actualTotal)));
|
|
|
+ pr.setVariablePoints(variablePoints.add(BigDecimal.valueOf(actualTotal)));
|
|
|
+ expiryQueue.addFirst(pointsRecord);
|
|
|
+ pointsRecord.setPointsAudit(2);//部分使用
|
|
|
+ pr.setPointsAudit(2);//部分使用
|
|
|
+ actualTotal = 0.0;
|
|
|
+ } else if (actualTotal > available) {
|
|
|
+ actualTotal = Arith.sub(actualTotal, available);
|
|
|
+ //把当前积分已扣完,但是还有钱。钱多积分少
|
|
|
+ pointsRecord.setVariablePoints(points);
|
|
|
+ pr.setVariablePoints(points);
|
|
|
+ pr.setPointsAudit(3);
|
|
|
+ pointsRecord.setPointsAudit(3);
|
|
|
+ } else {
|
|
|
+ //恰好等于
|
|
|
+ pr.setPointsAudit(3);
|
|
|
+ pointsRecord.setPointsAudit(3);
|
|
|
+ pointsRecord.setVariablePoints(pointsRecord.getPoints());
|
|
|
+ pr.setVariablePoints(pointsRecord.getPoints());
|
|
|
+ actualTotal = 0.0;
|
|
|
+ }
|
|
|
+ int update = pointsRecordMapper.updateById(pointsRecord);
|
|
|
+ if (update > 0) {
|
|
|
+ pr.setId(null);
|
|
|
+ pr.setPointsType(2);
|
|
|
+ pr.setOrderNumber(orderNumber);
|
|
|
+ pr.setExpiryDate(null);
|
|
|
+ pointsRecordMapper.insert(pr);
|
|
|
+ }
|
|
|
+ // 插入数据库
|
|
|
+ if (actualTotal > 0.0) {
|
|
|
+ actualTotal = this.doGetOrderItemPoints(actualTotal, expiryQueue, orderNumber);
|
|
|
+ }
|
|
|
}
|
|
|
return actualTotal;
|
|
|
}
|