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

Commit 7eab0789 authored by jiangxiulong's avatar jiangxiulong

主动完成退款调用platform的notifyUrl

parent 00845b70
......@@ -499,157 +499,23 @@ public class KylinRefundsStatusServiceImpl {
}
public boolean orderTicketRefunded(RefundCallbackParam refundCallbackParam, KylinOrderRefunds refundInfo) {
List<KylinOrderRefundEntities> refundEntities = kylinOrderRefundsEntitiesMapper.selectList(
new QueryWrapper<KylinOrderRefundEntities>().eq("order_refunds_id", refundInfo.getOrderRefundsId())
);
List<String> orderTicketEntitiesIdsArr = refundEntities.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getOrderTicketEntitiesId()).collect(Collectors.toList());
String orderTicketsId = refundInfo.getOrderTicketsId();
KylinOrderTicketRelations orderRelations = kylinOrderTicketRelationsMapper.selectOne(
new QueryWrapper<KylinOrderTicketRelations>().eq("order_id", orderTicketsId)
);
// 更新数据
// 订单状态表
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
int newStatus = 0;
if (refundCallbackParam.getRefundPrice().add(refundInfo.getPriceCharges()).add(orderInfo.getPriceRefund()).add(orderInfo.getRefundPriceCharges()).compareTo(orderInfo.getPriceActual()) == 0) {
newStatus = KylinTableStatusConst.ORDER_STATUS4;
} else {
newStatus = KylinTableStatusConst.ORDER_STATUS6;
}
orderStatusTable.setStatus(newStatus);
orderStatusTable.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketStatusMapper.update(
orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId)
);
// 入场人
BigDecimal priceActual = orderInfo.getPriceActual();
BigDecimal priceExpress = orderInfo.getPriceExpress();
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId)
.ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
);
BigDecimal onePrice = priceActual.subtract(priceExpress).divide(BigDecimal.valueOf(allEntitiesCount));//单价
int refundNumber = 0;
for (String entitiesId : orderTicketEntitiesIdsArr) {
KylinOrderTicketEntities EntitiesInfo = kylinOrderTicketEntitiesMapper.selectOne(//已退完成的
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", entitiesId)
);
BigDecimal refundedPrice = EntitiesInfo.getRefundPrice();
KylinOrderRefundEntities refundEntitiesInfo = kylinOrderRefundsEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderRefundEntities>()
.eq("order_refunds_id", refundInfo.getOrderRefundsId())
.eq("order_ticket_entities_id", entitiesId)
);
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
BigDecimal priceNew = refundEntitiesInfo.getRefundPrice().add(refundedPrice);
int isPayment = 0;
if (priceNew.compareTo(onePrice) == 0) {
isPayment = KylinTableStatusConst.ENTITIES_IS_PAYMENT3;
refundNumber++;
} else {
isPayment = KylinTableStatusConst.ENTITIES_IS_PAYMENT4;
}
entitiesTable.setIsPayment(isPayment);
entitiesTable.setUpdatedAt(LocalDateTime.now());
entitiesTable.setRefundPrice(priceNew);
Integer[] entitiesTableIsPayment = {KylinTableStatusConst.ENTITIES_IS_PAYMENT2, KylinTableStatusConst.ENTITIES_IS_PAYMENT4};
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", entitiesId)
.in("is_payment", entitiesTableIsPayment)
);
HashMap<String, Object> EntitiesVo = new HashMap<>();
EntitiesVo.put("updatedAt", DateUtil.getNowTime());
EntitiesVo.put("refundPrice", priceNew);
EntitiesVo.put("isPayment", isPayment);
BasicDBObject EntitiesVov = new BasicDBObject("$set", mongoConverter.convertToMongoType(EntitiesVo));
UpdateResult updateResult = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketEntitiesId").is(entitiesId)).getQueryObject(),
EntitiesVov
);
dataUtils.delOrderTicketEntitiesRedis(entitiesId);
}
// 订单表
BigDecimal price = orderInfo.getPriceRefund().add(refundCallbackParam.getRefundPrice());
Integer num = orderInfo.getRefundNumber() + refundNumber;
KylinOrderTickets update = new KylinOrderTickets();
update.setRefundNumber(num);
update.setPriceRefund(price);
update.setRefundPriceCharges(orderInfo.getRefundPriceCharges().add(refundInfo.getPriceCharges()));
update.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketsMapper.update(
update, new UpdateWrapper<KylinOrderTickets>()
.eq("order_tickets_id", orderTicketsId)
);
HashMap<String, Object> orderVo = new HashMap<>();
orderVo.put("updatedAt", DateUtil.getNowTime());
orderVo.put("priceRefund", price);
orderVo.put("refundPriceCharges", orderInfo.getRefundPriceCharges().add(refundInfo.getPriceCharges()));
orderVo.put("status", newStatus);
orderVo.put("refundNumber", num);
BasicDBObject orderVov = new BasicDBObject("$set", mongoConverter.convertToMongoType(orderVo));
UpdateResult orderUpdateResult = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderVov
);
dataUtils.delOrderTicketRedis(orderTicketsId);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId, null);
// 退款单完成
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED);
kylinOrderRefunds.setRefundCode(refundCallbackParam.getRefundCode());
kylinOrderRefunds.setRefundType(refundCallbackParam.getRefundType());
kylinOrderRefunds.setRefundId(refundCallbackParam.getRefundId());
kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefundAt());
kylinOrderRefunds.setUpdatedAt(LocalDateTime.now());
kylinOrderRefundsMapper.update(
kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refundInfo.getOrderRefundsId())
);
// 修改缓存
KylinOrderRefundsVo kylinOrderRefundsVo = new KylinOrderRefundsVo();
BeanUtils.copyProperties(kylinOrderRefunds, kylinOrderRefundsVo);
BasicDBObject object = new BasicDBObject("$set", mongoConverter.convertToMongoType(kylinOrderRefundsVo));
UpdateResult updateResult = mongoTemplate.getCollection(KylinOrderRefundsVo.class.getSimpleName()).updateOne(
Query.query(Criteria.where("orderRefundsId").is(refundInfo.getOrderRefundsId())).getQueryObject(),
object
);
List<String> orderRefundIds = new ArrayList<>();
orderRefundIds.add(refundInfo.getOrderRefundsId());
List<String> orderIds = new ArrayList<>();
orderIds.add(orderTicketsId);
dataUtils.delOrderRefundVo(orderRefundIds);
dataUtils.delOrderRefundVoByOrderId(orderIds);
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("status", "1");
params.add("refundPrice", refundCallbackParam.getRefundPrice().toString());
params.add("refundError", refundCallbackParam.getRefundError());
params.add("refundCode", refundCallbackParam.getRefundCode());// PAY
params.add("refundAt", refundCallbackParam.getRefundAt());
params.add("orderRefundCode", refundInfo.getOrderRefundCode());
params.add("refundId", refundCallbackParam.getRefundId());
params.add("refundType", refundCallbackParam.getRefundType());
MultiValueMap<String, String> headers = CollectionUtil.linkedMultiValueMapStringString();
headers.add("Accept", "application/json;charset=UTF-8");
if (refundInfo.getType() == KylinTableStatusConst.ORDER_REFUND_TYPE_APPLY) {
// 退还库存
for (String entitiesId : orderTicketEntitiesIdsArr) {
KylinOrderTicketEntities entitiesInfo = kylinOrderTicketEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderTicketEntities>().eq("order_ticket_entities_id", entitiesId)
);
if (entitiesInfo.getIsPayment() == KylinTableStatusConst.ENTITIES_IS_PAYMENT3) {
dataUtils.changeSurplusGeneral(entitiesInfo.getTicketId(), 1);
log.info(UserPathDto.setData("changeBuyInfo", "UserId=" + orderInfo.getUserId() + "idCard=" + entitiesInfo.getEnterIdCode() + " PerformanceId=" + orderRelations.getPerformanceId() + " TicketId=" + entitiesInfo.getTicketId(), "info"));
dataUtils.changeBuyInfo(orderInfo.getUserId(), entitiesInfo.getEnterIdCode(), orderRelations.getPerformanceId(), entitiesInfo.getTicketId(), -1);
}
}
}
log.info("订单主动完成退款orderTicketRefunded:[refundCallbackParam={}, [orderRefundCode={}, notifyUrl={}]",
refundCallbackParam, refundInfo.getOrderRefundCode(), notifyUrl);
String returnData = HttpUtil.post(notifyUrl, params, headers);
log.info("订单主动完成退款orderTicketRefunded-platform结果:{}", returnData);
return true;
}
......
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