记得上下班打卡 | git大法好,push需谨慎

Commit 939c980d authored by jiangxiulong's avatar jiangxiulong

add try applyrefund

parent 6508d91a
...@@ -93,82 +93,100 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -93,82 +93,100 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
private MongoConverter mongoConverter; private MongoConverter mongoConverter;
public ResponseDto refundApply(RefundApplyParam refundApplyParam, String authId, String authName) { public ResponseDto refundApply(RefundApplyParam refundApplyParam, String authId, String authName) {
String orderTicketsId = refundApplyParam.getOrderTicketsId(); try {
List<String> ticketEntityIds = refundApplyParam.getTicketEntityIds(); String orderTicketsId = refundApplyParam.getOrderTicketsId();
List<BigDecimal> entitiesPrice = refundApplyParam.getEntitiesPrice(); List<String> ticketEntityIds = refundApplyParam.getTicketEntityIds();
BigDecimal RefundPriceExpress = refundApplyParam.getRefundPriceExpress(); List<BigDecimal> entitiesPrice = refundApplyParam.getEntitiesPrice();
if (null == RefundPriceExpress) { BigDecimal RefundPriceExpress = refundApplyParam.getRefundPriceExpress();
RefundPriceExpress = new BigDecimal(0); if (null == RefundPriceExpress) {
} RefundPriceExpress = new BigDecimal(0);
}
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne( KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId) new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
); );
KylinOrderTicketStatus orderStatus = kylinOrderTicketStatusMapper.selectOne( KylinOrderTicketStatus orderStatus = kylinOrderTicketStatusMapper.selectOne(
new QueryWrapper<KylinOrderTicketStatus>().eq("order_id", orderTicketsId) new QueryWrapper<KylinOrderTicketStatus>().eq("order_id", orderTicketsId)
); );
int thisOrderStatus = orderStatus.getStatus(); int thisOrderStatus = orderStatus.getStatus();
int thisPayStatus = orderStatus.getPayStatus(); int thisPayStatus = orderStatus.getPayStatus();
BigDecimal priceExpress = orderInfo.getPriceExpress(); BigDecimal priceExpress = orderInfo.getPriceExpress();
// todo 转增是否能退 // todo 转增是否能退
// 订单状态需已付款 // 订单状态需已付款
if (thisOrderStatus != KylinTableStatusConst.ORDER_STATUS1 && thisOrderStatus != KylinTableStatusConst.ORDER_STATUS3 && thisOrderStatus != KylinTableStatusConst.ORDER_STATUS6) { if (thisOrderStatus != KylinTableStatusConst.ORDER_STATUS1 && thisOrderStatus != KylinTableStatusConst.ORDER_STATUS3 && thisOrderStatus != KylinTableStatusConst.ORDER_STATUS6) {
return ResponseDto.failure("当前订单状态不支持退款申请"); return ResponseDto.failure("当前订单状态不支持退款申请");
} }
if (!(orderStatus.getTransferStatus() == 0 || orderStatus.getTransferStatus() == 5)) { if (!(orderStatus.getTransferStatus() == 0 || orderStatus.getTransferStatus() == 5)) {
return ResponseDto.failure("当前转增状态不可退款"); return ResponseDto.failure("当前转增状态不可退款");
} }
// 订单支付状态需为已支付 // 订单支付状态需为已支付
if (thisPayStatus != KylinTableStatusConst.ORDER_PAY_STATUS1) { if (thisPayStatus != KylinTableStatusConst.ORDER_PAY_STATUS1) {
return ResponseDto.failure("订单支付状态需为已支付"); return ResponseDto.failure("订单支付状态需为已支付");
} }
// TODO: 2021/6/16 是否能单独退快递飞 批量退款是否退快递费 现在做的是自动退剩余快递费 // TODO: 2021/6/16 是否能单独退快递飞 批量退款是否退快递费 现在做的是自动退剩余快递费
// 传的快递费不能大于实际的快递费=(支付的快递费-已退的快递费) // 传的快递费不能大于实际的快递费=(支付的快递费-已退的快递费)
BigDecimal refundPriceExpressSum = kylinOrderRefundsMapper.RefundPriceExpressSum(// 已退快递费 BigDecimal refundPriceExpressSum = kylinOrderRefundsMapper.RefundPriceExpressSum(// 已退快递费
orderTicketsId, orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL
); );
if (null == refundPriceExpressSum) { if (null == refundPriceExpressSum) {
refundPriceExpressSum = new BigDecimal(0); refundPriceExpressSum = new BigDecimal(0);
} }
if (null == refundApplyParam.getOrderRefundBatchesId() || refundApplyParam.getOrderRefundBatchesId().isEmpty()) { // 不是批量退款 if (null == refundApplyParam.getOrderRefundBatchesId() || refundApplyParam.getOrderRefundBatchesId().isEmpty()) { // 不是批量退款
if (RefundPriceExpress.compareTo(priceExpress.subtract(refundPriceExpressSum)) > 0) { if (RefundPriceExpress.compareTo(priceExpress.subtract(refundPriceExpressSum)) > 0) {
return ResponseDto.failure("快递费不能大于实际减去已退的快递费"); return ResponseDto.failure("快递费不能大于实际减去已退的快递费");
}
} else {
RefundPriceExpress = priceExpress.subtract(refundPriceExpressSum);
} }
} else {
RefundPriceExpress = priceExpress.subtract(refundPriceExpressSum);
}
// todo 出票未出票 // todo 出票未出票
// 选择退款的入场人是否正确 // 选择退款的入场人是否正确
Integer[] entitiesStatus = new Integer[]{KylinTableStatusConst.ENTITIES_IS_PAYMENT1, KylinTableStatusConst.ENTITIES_IS_PAYMENT2, KylinTableStatusConst.ENTITIES_IS_PAYMENT4}; Integer[] entitiesStatus = new Integer[]{KylinTableStatusConst.ENTITIES_IS_PAYMENT1, KylinTableStatusConst.ENTITIES_IS_PAYMENT2, KylinTableStatusConst.ENTITIES_IS_PAYMENT4};
int choiceCount = kylinOrderTicketEntitiesMapper.selectCount( int choiceCount = kylinOrderTicketEntitiesMapper.selectCount(
new QueryWrapper<KylinOrderTicketEntities>() new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId) .eq("order_id", orderTicketsId)
.in("is_payment", entitiesStatus) .in("is_payment", entitiesStatus)
.in("order_ticket_entities_id", ticketEntityIds) .in("order_ticket_entities_id", ticketEntityIds)
); );
if (choiceCount < 0 || choiceCount != ticketEntityIds.size()) { if (choiceCount < 0 || choiceCount != ticketEntityIds.size()) {
return ResponseDto.failure("入场人订单有误"); return ResponseDto.failure("入场人订单有误");
} }
// 该订单正在退款或已有退款 因支持填入价格所有取消判断 // 该订单正在退款或已有退款 因支持填入价格所有取消判断
// 各个入场人订单填写的退款金额是否正确 // 各个入场人订单填写的退款金额是否正确
BigDecimal priceActual = orderInfo.getPriceActual(); BigDecimal priceActual = orderInfo.getPriceActual();
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格 int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
new QueryWrapper<KylinOrderTicketEntities>() new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId) .eq("order_id", orderTicketsId)
.ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0) .ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
); );
BigDecimal onePrice = priceActual.subtract(priceExpress).divide(BigDecimal.valueOf(allEntitiesCount));//单价 BigDecimal onePrice = priceActual.subtract(priceExpress).divide(BigDecimal.valueOf(allEntitiesCount));//单价
List<BigDecimal> realRefundPriceList = new ArrayList<>(); List<BigDecimal> realRefundPriceList = new ArrayList<>();
if (null == refundApplyParam.getOrderRefundBatchesId() || refundApplyParam.getOrderRefundBatchesId().isEmpty()) { // 不是批量退款 if (null == refundApplyParam.getOrderRefundBatchesId() || refundApplyParam.getOrderRefundBatchesId().isEmpty()) { // 不是批量退款
for (int i = 0; i <= ticketEntityIds.size() - 1; i++) { for (int i = 0; i <= ticketEntityIds.size() - 1; i++) {
BigDecimal price = entitiesPrice.get(i); BigDecimal price = entitiesPrice.get(i);
if (price.compareTo(BigDecimal.ZERO) <= 0) { if (price.compareTo(BigDecimal.ZERO) <= 0) {
return ResponseDto.failure(ErrorMapping.get("20021")); return ResponseDto.failure(ErrorMapping.get("20021"));
} else { } else {
BigDecimal refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退 BigDecimal refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
ticketEntityIds.get(i)
);
if (null == refundedPrice) {
refundedPrice = new BigDecimal(0);
}
if (price.compareTo(onePrice.subtract(refundedPrice)) > 0) {
return ResponseDto.failure("超过可退款金额");
}
}
}
realRefundPriceList = entitiesPrice;
} else { // 批量 计算入场人订单可退金额
List<String> ticketEntityIdsNew = new ArrayList<>();
for (int i = 0; i <= ticketEntityIds.size() - 1; i++) {
BigDecimal refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退 包含退款中
orderTicketsId, orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL, KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
ticketEntityIds.get(i) ticketEntityIds.get(i)
...@@ -176,50 +194,37 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -176,50 +194,37 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
if (null == refundedPrice) { if (null == refundedPrice) {
refundedPrice = new BigDecimal(0); refundedPrice = new BigDecimal(0);
} }
if (price.compareTo(onePrice.subtract(refundedPrice)) > 0) { BigDecimal price = onePrice.subtract(refundedPrice); // 计算可退金额
return ResponseDto.failure("超过可退款金额"); if (price.compareTo(BigDecimal.ZERO) > 0) {
realRefundPriceList.add(price);
ticketEntityIdsNew.add(ticketEntityIds.get(i));
} }
} }
// 剔除掉已经退完的入场人订单 可能包含正在退的
ticketEntityIds = ticketEntityIdsNew;
} }
realRefundPriceList = entitiesPrice;
} else { // 批量 计算入场人订单可退金额
List<String> ticketEntityIdsNew = new ArrayList<>();
for (int i = 0; i <= ticketEntityIds.size() - 1; i++) {
BigDecimal refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退 包含退款中
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
ticketEntityIds.get(i)
);
if (null == refundedPrice) {
refundedPrice = new BigDecimal(0);
}
BigDecimal price = onePrice.subtract(refundedPrice); // 计算可退金额
if (price.compareTo(BigDecimal.ZERO) > 0) {
realRefundPriceList.add(price);
ticketEntityIdsNew.add(ticketEntityIds.get(i));
}
}
// 剔除掉已经退完的入场人订单 可能包含正在退的
ticketEntityIds = ticketEntityIdsNew;
}
boolean res = kylinRefundsStatusServiceImpl.orderTicketRefunding(
refundApplyParam, orderInfo, orderTicketsId,
RefundPriceExpress,
ticketEntityIds, realRefundPriceList
, authId, authName
);
HashMap<String, Object> map = new HashMap<>(); boolean res = kylinRefundsStatusServiceImpl.orderTicketRefunding(
map.put("isHaveRefundDetails", 1); refundApplyParam, orderInfo, orderTicketsId,
BasicDBObject obj = new BasicDBObject("$set", mongoConverter.convertToMongoType(map)); RefundPriceExpress,
mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).updateOne( ticketEntityIds, realRefundPriceList
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(), , authId, authName
obj); );
if (res) { HashMap<String, Object> map = new HashMap<>();
return ResponseDto.success(); map.put("isHaveRefundDetails", 1);
} else { BasicDBObject obj = new BasicDBObject("$set", mongoConverter.convertToMongoType(map));
mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
obj);
if (res) {
return ResponseDto.success();
} else {
return ResponseDto.failure("操作失败");
}
} catch (Exception e) {
log.error("orderApplyException e[{}]", e);
return ResponseDto.failure("操作失败"); return ResponseDto.failure("操作失败");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment