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

Commit 6b13188a authored by 张国柄's avatar 张国柄

Merge remote-tracking branch 'origin/dev' into dev

parents 473f9a87 d3da01bd
...@@ -64,6 +64,7 @@ public class KylinTableStatusConst { ...@@ -64,6 +64,7 @@ public class KylinTableStatusConst {
public static final Integer ENTITIES_IS_PAYMENT1 = 1; // 已支付 public static final Integer ENTITIES_IS_PAYMENT1 = 1; // 已支付
public static final Integer ENTITIES_IS_PAYMENT2 = 2; // 退款中 public static final Integer ENTITIES_IS_PAYMENT2 = 2; // 退款中
public static final Integer ENTITIES_IS_PAYMENT3 = 3; // 已退款 public static final Integer ENTITIES_IS_PAYMENT3 = 3; // 已退款
public static final Integer ENTITIES_IS_PAYMENT4 = 4; // 部分退款
// 出票状态 // 出票状态
public static final Integer ENTITIES_STATUS0 = 0; // 未出票 public static final Integer ENTITIES_STATUS0 = 0; // 未出票
public static final Integer ENTITIES_STATUS1 = 1; // 已出票 public static final Integer ENTITIES_STATUS1 = 1; // 已出票
......
...@@ -26,7 +26,7 @@ public class RefundApplyParam implements Serializable { ...@@ -26,7 +26,7 @@ public class RefundApplyParam implements Serializable {
private Double RefundPriceExpress; private Double RefundPriceExpress;
private List<String> ticketEntityIds; private List<String> ticketEntityIds;
private List<BigDecimal> entitiesPrice; private List<Double> entitiesPrice;
private List<String> ids; private List<String> ids;
......
...@@ -3,6 +3,7 @@ package com.liquidnet.service.kylin.dto.vo.mongo; ...@@ -3,6 +3,7 @@ package com.liquidnet.service.kylin.dto.vo.mongo;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@Data @Data
...@@ -36,6 +37,8 @@ public class KylinOrderTicketEntitiesVo implements Serializable, Cloneable { ...@@ -36,6 +37,8 @@ public class KylinOrderTicketEntitiesVo implements Serializable, Cloneable {
private Integer ticketsmId; private Integer ticketsmId;
private Integer timemId; private Integer timemId;
private BigDecimal refundPrice;
private String checkType; private String checkType;
private String checkedAt; private String checkedAt;
private String checkUserId; private String checkUserId;
......
...@@ -98,9 +98,6 @@ public class KylinOrderRefundsVo implements Serializable { ...@@ -98,9 +98,6 @@ public class KylinOrderRefundsVo implements Serializable {
private String refundType; private String refundType;
private Integer refundCate; private Integer refundCate;
@ApiModelProperty(value = "订单入场人/搭售款式表 id 多个 ,分割")
private String orderTicketEntitiesIds;
@ApiModelProperty(value = "添加时间") @ApiModelProperty(value = "添加时间")
private LocalDateTime createdAt; private LocalDateTime createdAt;
......
package com.liquidnet.service.kylin.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.liquidnet.service.kylin.entity.KylinOrderRefundEntities;
/**
* <p>
* 订单退款入场人表 服务类
* </p>
*
* @author jiangxiulong
* @since 2021-06-16
*/
public interface IKylinOrderRefundsEntitiesService extends IService<KylinOrderRefundEntities> {
}
...@@ -7,7 +7,6 @@ import com.github.pagehelper.PageHelper; ...@@ -7,7 +7,6 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.liquidnet.client.admin.common.utils.DateUtils; import com.liquidnet.client.admin.common.utils.DateUtils;
import com.liquidnet.client.admin.common.utils.ShiroUtils; import com.liquidnet.client.admin.common.utils.ShiroUtils;
import com.liquidnet.client.admin.zhengzai.kylin.utils.DataUtils;
import com.liquidnet.commons.lang.util.BeanUtil; import com.liquidnet.commons.lang.util.BeanUtil;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst; import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
...@@ -17,8 +16,6 @@ import com.liquidnet.service.kylin.dao.OrderRefundDao; ...@@ -17,8 +16,6 @@ import com.liquidnet.service.kylin.dao.OrderRefundDao;
import com.liquidnet.service.kylin.dto.param.RefundApplyParam; import com.liquidnet.service.kylin.dto.param.RefundApplyParam;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam; import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.param.RefundSearchParam; import com.liquidnet.service.kylin.dto.param.RefundSearchParam;
import com.liquidnet.service.kylin.dto.vo.admin.OrderDetailsAdminVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo;
import com.liquidnet.service.kylin.dto.vo.returns.KylinOrderRefundsVo; import com.liquidnet.service.kylin.dto.vo.returns.KylinOrderRefundsVo;
...@@ -35,8 +32,8 @@ import org.springframework.stereotype.Service; ...@@ -35,8 +32,8 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
...@@ -70,13 +67,16 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -70,13 +67,16 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
@Autowired @Autowired
private KylinPerformancesMapper kylinPerformancesMapper; private KylinPerformancesMapper kylinPerformancesMapper;
@Autowired
private KylinOrderRefundsEntitiesMapper kylinOrderRefundsEntitiesMapper;
@Autowired @Autowired
MongoTemplate mongoTemplate; MongoTemplate mongoTemplate;
public ResponseDto refundApply(RefundApplyParam refundApplyParam) { public ResponseDto refundApply(RefundApplyParam refundApplyParam) {
String orderTicketsId = refundApplyParam.getOrderTicketsId(); String orderTicketsId = refundApplyParam.getOrderTicketsId();
List<String> ticketEntityIds = refundApplyParam.getTicketEntityIds(); List<String> ticketEntityIds = refundApplyParam.getTicketEntityIds();
List<BigDecimal> entitiesPrice = refundApplyParam.getEntitiesPrice(); List<Double> entitiesPrice = refundApplyParam.getEntitiesPrice();
Double RefundPriceExpress = refundApplyParam.getRefundPriceExpress(); Double RefundPriceExpress = refundApplyParam.getRefundPriceExpress();
if (null == RefundPriceExpress) { if (null == RefundPriceExpress) {
RefundPriceExpress = 0.0; RefundPriceExpress = 0.0;
...@@ -95,44 +95,88 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -95,44 +95,88 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
// todo 转增是否能退 // todo 转增是否能退
// 订单状态需已付款 // 订单状态需已付款
if (thisOrderStatus != KylinTableStatusConst.ORDER_STATUS1) { if (thisOrderStatus != KylinTableStatusConst.ORDER_STATUS1) {
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 是否能单独退快递飞 批量退款是否退快递费 现在做的是自动退剩余快递费
// 传的快递费不能大于实际的快递费=(支付的快递费-已退的快递费)
double refundPriceExpressSum = kylinOrderRefundsMapper.RefundPriceExpressSum(// 已退快递费
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL
);
if (null == refundApplyParam.getOrderRefundBatchesId() || refundApplyParam.getOrderRefundBatchesId().isEmpty()) { // 不是批量退款
if (RefundPriceExpress > (priceExpress - refundPriceExpressSum)) {
return ResponseDto.failure("快递费不能大于实际减去已退的快递费");
}
} else {
RefundPriceExpress = priceExpress - refundPriceExpressSum;
} }
// 传的快递费不能大于实际的快递费
if (RefundPriceExpress > priceExpress) { // todo 出票未出票
return ResponseDto.failure("快递费不能大于实际的快递费"); // 选择退款的入场人是否正确
int choiceCount = kylinOrderTicketEntitiesMapper.selectCount(
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId)
.eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT1)
.in("order_ticket_entities_id", ticketEntityIds)
);
if (choiceCount < 0 || choiceCount != ticketEntityIds.size()) {
return ResponseDto.failure("入场人订单有误");
} }
// 该订单正在退款或已有退款 // 该订单正在退款或已有退款
QueryWrapper<KylinOrderRefunds> refundingCountQuery = new QueryWrapper<KylinOrderRefunds>() int refundingCount = kylinOrderRefundsMapper.selectRefundingCount(
.eq("order_tickets_id", orderTicketsId) orderTicketsId,
.ne("status", KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL); KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
for (String v : ticketEntityIds) { ticketEntityIds
refundingCountQuery.like("order_ticket_entities_ids", v); );
}
int refundingCount = kylinOrderRefundsMapper.selectCount(refundingCountQuery);
if (refundingCount > 0) { if (refundingCount > 0) {
return ResponseDto.failure("该订单正在退款或已有退款"); return ResponseDto.failure("该订单正在退款或已有退款");
} }
// 各个入场人订单填写的退款金额是否正确
// 选择退款的入场人是否正确 double priceActual = orderInfo.getPriceActual().doubleValue();
// TODO: 2021/5/27 出票未出票不知是否要处理 int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
QueryWrapper<KylinOrderTicketEntities> choiceCountQuery = new QueryWrapper<KylinOrderTicketEntities>() new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId) .eq("order_id", orderTicketsId)
.eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT1) .ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
.in("order_ticket_entities_id", ticketEntityIds); );
int choiceCount = kylinOrderTicketEntitiesMapper.selectCount(choiceCountQuery); double onePrice = (priceActual - priceExpress) / allEntitiesCount;//单价
int ticketEntityCount = ticketEntityIds.size(); List<Double> realRefundPriceList = new ArrayList<>();
if (choiceCount < 0 || choiceCount != ticketEntityCount) { if (null == refundApplyParam.getOrderRefundBatchesId() || refundApplyParam.getOrderRefundBatchesId().isEmpty()) { // 不是批量退款
return ResponseDto.failure("入场人订单有误或不存在"); for (int i = 0; i <= ticketEntityIds.size(); i++) {
Double price = entitiesPrice.get(i);
if (price < 0) {
return ResponseDto.failure("退款金额不能为0");
} else {
Double refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
ticketEntityIds.get(i)
);
if (price > (onePrice - refundedPrice)) {
return ResponseDto.failure("超过可退款金额");
}
}
}
realRefundPriceList = entitiesPrice;
} else { // 批量 计算入场人订单可退金额
for (int i = 0; i <= ticketEntityIds.size(); i++) {
Double refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退 包含退款中
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
ticketEntityIds.get(i)
);
Double price = onePrice - refundedPrice; // 计算可退金额
realRefundPriceList.add(price);
}
} }
boolean res = kylinRefundsStatusServiceImpl.orderTicketRefunding( boolean res = kylinRefundsStatusServiceImpl.orderTicketRefunding(
refundApplyParam, orderInfo, orderTicketsId, refundApplyParam, orderInfo, orderTicketsId,
RefundPriceExpress, priceExpress, RefundPriceExpress,
ticketEntityCount, ticketEntityIds ticketEntityIds, realRefundPriceList
); );
if (res) { if (res) {
return ResponseDto.success(); return ResponseDto.success();
...@@ -240,7 +284,8 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -240,7 +284,8 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
RefundCallbackParam refundCallbackParam = new RefundCallbackParam(); RefundCallbackParam refundCallbackParam = new RefundCallbackParam();
refundCallbackParam.setRefund_code(refundInfo.getRefundCode()); refundCallbackParam.setRefund_code(refundInfo.getRefundCode());
refundCallbackParam.setRefund_price(refundInfo.getPrice().doubleValue()); double refundPrice = refundInfo.getPrice().doubleValue() + refundInfo.getPriceExpress().doubleValue();
refundCallbackParam.setRefund_price(refundPrice);
refundCallbackParam.setRefund_type("UNKNOWN"); refundCallbackParam.setRefund_type("UNKNOWN");
refundCallbackParam.setRefund_id(refundInfo.getRefundId()); refundCallbackParam.setRefund_id(refundInfo.getRefundId());
refundCallbackParam.setRefund_at(DateUtils.dateTimeNow()); refundCallbackParam.setRefund_at(DateUtils.dateTimeNow());
...@@ -274,9 +319,11 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -274,9 +319,11 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
.eq("order_refunds_id", orderRefundId) .eq("order_refunds_id", orderRefundId)
); );
String orderTicketEntitiesId = data.getOrderTicketEntitiesIds(); List<KylinOrderRefundEntities> refundEntities = kylinOrderRefundsEntitiesMapper.selectList(
String[] orderTicketEntitiesIdS = orderTicketEntitiesId.split(","); new QueryWrapper<KylinOrderRefundEntities>().eq("order_refunds_id", orderRefundId)
List<KylinOrderRefundsEntitiesDao> entities = kylinOrderTicketEntitiesMapper.selectEntitiesList(orderTicketEntitiesIdS); );
List<String> orderTicketEntitiesIdsArr = refundEntities.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getOrderTicketEntitiesId()).collect(Collectors.toList());
List<KylinOrderRefundsEntitiesDao> entities = kylinOrderTicketEntitiesMapper.selectEntitiesList(orderTicketEntitiesIdsArr);
for (KylinOrderRefundsEntitiesDao item : entities) { for (KylinOrderRefundsEntitiesDao item : entities) {
item.setPaymentName(item.getIsPayment()); item.setPaymentName(item.getIsPayment());
} }
...@@ -311,7 +358,7 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -311,7 +358,7 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
); );
// 订单关联 获取演出id // 订单关联 获取演出id
KylinOrderTicketRelations kylinOrderTicketRelations = kylinOrderTicketRelationsMapper.selectOne( KylinOrderTicketRelations kylinOrderTicketRelations = kylinOrderTicketRelationsMapper.selectOne(
new QueryWrapper<KylinOrderTicketRelations>().eq("order_id", kylinOrderTickets.getOrderTicketsId()) new QueryWrapper<KylinOrderTicketRelations>().eq("order_id", kylinOrderTickets.getOrderTicketsId())
); );
...@@ -321,12 +368,31 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM ...@@ -321,12 +368,31 @@ public class KylinOrderRefundsServiceImpl extends ServiceImpl<KylinOrderRefundsM
); );
List<KylinOrderTicketEntitiesDao> entitiesList = kylinOrderTicketEntitiesMapper.getRefundEntitiesList(kylinOrderTickets.getOrderTicketsId()); List<KylinOrderTicketEntitiesDao> entitiesList = kylinOrderTicketEntitiesMapper.getRefundEntitiesList(kylinOrderTickets.getOrderTicketsId());
if(entitiesList.size() > 0) {
double priceActual = kylinOrderTickets.getPriceActual().doubleValue();
double priceExpress = kylinOrderTickets.getPriceExpress().doubleValue();
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", kylinOrderTickets.getOrderTicketsId())
.ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
);
double onePrice = (priceActual - priceExpress) / allEntitiesCount;//单价
for (KylinOrderTicketEntitiesDao entities : entitiesList) {
double refundedPrice = kylinOrderTicketEntitiesMapper.getRefundEntitiesPrice(//已退 包含退款中
kylinOrderTickets.getOrderTicketsId(),
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
entities.getOrderTicketEntitiesId()
);
double canRefundedPrice = onePrice - refundedPrice;
entities.setCanRefundedPrice(BigDecimal.valueOf(canRefundedPrice));
}
}
KylinOrderTicketVo kylinOrderTicketVo = new KylinOrderTicketVo(); KylinOrderTicketVo kylinOrderTicketVo = new KylinOrderTicketVo();
BeanUtil.copy(kylinOrderTickets,kylinOrderTicketVo); BeanUtil.copy(kylinOrderTickets, kylinOrderTicketVo);
KylinPerformanceVo performanceVo = new KylinPerformanceVo(); KylinPerformanceVo performanceVo = new KylinPerformanceVo();
BeanUtil.copy(kylinPerformances,performanceVo); BeanUtil.copy(kylinPerformances, performanceVo);
/*List<KylinOrderTicketEntitiesDao> entitiesListDao = new ArrayList(); /*List<KylinOrderTicketEntitiesDao> entitiesListDao = new ArrayList();
KylinOrderTicketEntitiesDao kylinOrderTicketEntitiesDao = new KylinOrderTicketEntitiesDao(); KylinOrderTicketEntitiesDao kylinOrderTicketEntitiesDao = new KylinOrderTicketEntitiesDao();
......
...@@ -3,10 +3,10 @@ package com.liquidnet.client.admin.zhengzai.kylin.service.impl; ...@@ -3,10 +3,10 @@ package com.liquidnet.client.admin.zhengzai.kylin.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.liquidnet.client.admin.common.utils.ShiroUtils; import com.liquidnet.client.admin.common.utils.ShiroUtils;
import com.liquidnet.client.admin.common.utils.StringUtils; import com.liquidnet.client.admin.common.utils.StringUtils;
import com.liquidnet.client.admin.zhengzai.kylin.utils.DataUtils; import com.liquidnet.client.admin.zhengzai.kylin.utils.DataUtils;
import com.liquidnet.client.admin.zhengzai.kylin.utils.MongoVoUtils;
import com.liquidnet.commons.lang.util.HttpUtil; import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.IDGenerator; import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
...@@ -15,14 +15,8 @@ import com.liquidnet.service.kylin.dto.param.RefundApplyParam; ...@@ -15,14 +15,8 @@ import com.liquidnet.service.kylin.dto.param.RefundApplyParam;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam; import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo;
import com.liquidnet.service.kylin.entity.KylinOrderRefunds; import com.liquidnet.service.kylin.entity.*;
import com.liquidnet.service.kylin.entity.KylinOrderTicketEntities; import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.entity.KylinOrderTicketStatus;
import com.liquidnet.service.kylin.entity.KylinOrderTickets;
import com.liquidnet.service.kylin.mapper.KylinOrderRefundsMapper;
import com.liquidnet.service.kylin.mapper.KylinOrderTicketEntitiesMapper;
import com.liquidnet.service.kylin.mapper.KylinOrderTicketStatusMapper;
import com.liquidnet.service.kylin.mapper.KylinOrderTicketsMapper;
import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObject;
import com.mongodb.client.model.FindOneAndUpdateOptions; import com.mongodb.client.model.FindOneAndUpdateOptions;
import com.mongodb.client.model.ReturnDocument; import com.mongodb.client.model.ReturnDocument;
...@@ -71,36 +65,38 @@ public class KylinRefundsStatusServiceImpl { ...@@ -71,36 +65,38 @@ public class KylinRefundsStatusServiceImpl {
@Autowired @Autowired
private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper; private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper;
@Autowired
private KylinOrderRefundsEntitiesMapper kylinOrderRefundsEntitiesMapper;
@Autowired
private KylinOrderTicketRelationsMapper kylinOrderTicketRelationsMapper;
@Autowired @Autowired
MongoTemplate mongoTemplate; MongoTemplate mongoTemplate;
@Autowired @Autowired
private DataUtils dataUtils; private DataUtils dataUtils;
@Autowired
private MongoVoUtils mongoVoUtils;
public Boolean orderTicketRefunding( public Boolean orderTicketRefunding(
RefundApplyParam refundApplyParam, KylinOrderTickets orderInfo, String orderTicketsId, RefundApplyParam refundApplyParam, KylinOrderTickets orderInfo, String orderTicketsId,
double RefundPriceExpress, double priceExpress, double RefundPriceExpress,
int ticketEntityCount, List<String> ticketEntityIds List<String> ticketEntityIds, List<Double> entitiesPrice
) { ) {
// 处理数据 // 基础数据
String authId = ShiroUtils.getUserId().toString(); String authId = ShiroUtils.getUserId().toString();
String authName = ShiroUtils.getLoginName(); String authName = ShiroUtils.getLoginName();
String reason = refundApplyParam.getReason(); String reason = refundApplyParam.getReason();
String orderRefundBatchesId = refundApplyParam.getOrderRefundBatchesId(); String orderRefundBatchesId = refundApplyParam.getOrderRefundBatchesId();
double priceActual = orderInfo.getPriceActual().doubleValue(); // 本次退款票总金额
// 本次退款总金额 double entitiesPriceSum = entitiesPrice.stream().mapToDouble(Double::doubleValue).sum();
// 总入场人数量 排出未付款的 用来计算单入场人的价格
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId)
.ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
);
double refundTotalPrice = RefundPriceExpress + ((priceActual - priceExpress) / allEntitiesCount * ticketEntityCount);
// TODO: 2021/5/27 事物 and 部分退款
// 更新数据 // 更新数据
// 订单状态表 // 订单状态表 和 缓存
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus(); KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
// TODO: 2021/5/27 事物 and 部分退款
orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS3); orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS3);
kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>() kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId)); .eq("order_id", orderTicketsId));
...@@ -114,12 +110,12 @@ public class KylinRefundsStatusServiceImpl { ...@@ -114,12 +110,12 @@ public class KylinRefundsStatusServiceImpl {
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER) new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
); );
dataUtils.delOrderTicketRedis(orderTicketsId); dataUtils.delOrderTicketRedis(orderTicketsId);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId);
// 入场人 // 订单入场人表 和 缓存
for (String v : ticketEntityIds) { for (String v : ticketEntityIds) {
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities(); KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
// TODO: 2021/5/27 事物 and 部分退款
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2); entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>() kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", v)); .eq("order_ticket_entities_id", v));
...@@ -151,37 +147,53 @@ public class KylinRefundsStatusServiceImpl { ...@@ -151,37 +147,53 @@ public class KylinRefundsStatusServiceImpl {
String orderRefundCode = orderInfo.getOrderCode(); String orderRefundCode = orderInfo.getOrderCode();
String codeNum = StringUtils.leftPad(String.valueOf(refundCount), 3, "0"); String codeNum = StringUtils.leftPad(String.valueOf(refundCount), 3, "0");
kylinOrderRefunds.setOrderRefundCode(orderRefundCode.concat(codeNum)); kylinOrderRefunds.setOrderRefundCode(orderRefundCode.concat(codeNum));
kylinOrderRefunds.setPrice(BigDecimal.valueOf(refundTotalPrice)); kylinOrderRefunds.setPrice(BigDecimal.valueOf(entitiesPriceSum));
kylinOrderRefunds.setPriceExpress(BigDecimal.valueOf(RefundPriceExpress));
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_APPLY); kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_APPLY);
kylinOrderRefunds.setType(0);
kylinOrderRefunds.setType(KylinTableStatusConst.ORDER_REFUND_TYPE_APPLY);
kylinOrderRefunds.setApplicantId(authId); kylinOrderRefunds.setApplicantId(authId);
kylinOrderRefunds.setApplicantName(authName); kylinOrderRefunds.setApplicantName(authName);
kylinOrderRefunds.setApplicantAt(LocalDateTime.now()); kylinOrderRefunds.setApplicantAt(LocalDateTime.now());
kylinOrderRefunds.setReason(reason); kylinOrderRefunds.setReason(reason);
// TODO: 2021/5/27 判断tyoe if (RefundPriceExpress > 0 && entitiesPriceSum > 0) {
if (RefundPriceExpress > 0) { kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE3);
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE1); } else if (RefundPriceExpress > 0) {
} else {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE2); kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE2);
} else if (entitiesPriceSum > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE1);
} }
kylinOrderRefunds.setOrderTicketEntitiesIds(StringUtils.join(ticketEntityIds, ','));
kylinOrderRefunds.setCreatedAt(LocalDateTime.now()); kylinOrderRefunds.setCreatedAt(LocalDateTime.now());
int rows = kylinOrderRefundsMapper.insert(kylinOrderRefunds); int rows = kylinOrderRefundsMapper.insert(kylinOrderRefunds);
// 退款入场人表
KylinOrderRefundEntities kylinOrderRefundEntities = new KylinOrderRefundEntities();
for (int i = 0; i <= ticketEntityIds.size(); i++) {
String orderRefundsEntitiesId = IDGenerator.nextSnowId().toString();
kylinOrderRefundEntities.setOrderRefundsEntitiesId(orderRefundsEntitiesId);
kylinOrderRefundEntities.setOrderRefundsId(orderRefundsId);
kylinOrderRefundEntities.setRefundPrice(BigDecimal.valueOf(entitiesPrice.get(i)));
kylinOrderRefundEntities.setOrderTicketEntitiesId(ticketEntityIds.get(i));
kylinOrderRefundEntities.setCreatedAt(LocalDateTime.now());
int rowsR = kylinOrderRefundsEntitiesMapper.insert(kylinOrderRefundEntities);
}
return true; return true;
} }
public boolean orderTicketRefundCancel(List<KylinOrderRefunds> refundList) { public boolean orderTicketRefundCancel(List<KylinOrderRefunds> refundList) {
for (KylinOrderRefunds refundInfo : refundList) { for (KylinOrderRefunds refundInfo : refundList) {
String orderTicketEntitiesIds = refundInfo.getOrderTicketEntitiesIds(); List<KylinOrderRefundEntities> refundEntities = kylinOrderRefundsEntitiesMapper.selectList(
String[] orderTicketEntitiesIdsArr = orderTicketEntitiesIds.split(","); 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(); String orderTicketsId = refundInfo.getOrderTicketsId();
String orderRefundsId = refundInfo.getOrderRefundsId(); String orderRefundsId = refundInfo.getOrderRefundsId();
// 更新数据 // 更新数据
// 订单状态表 // 订单状态表
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus(); KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
// TODO: 2021/5/27 事物 and 部分退款 // TODO: 如果原来是部分退款?
orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS1); orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS1);
kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>() kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId)); .eq("order_id", orderTicketsId));
...@@ -195,7 +207,10 @@ public class KylinRefundsStatusServiceImpl { ...@@ -195,7 +207,10 @@ public class KylinRefundsStatusServiceImpl {
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER) new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
); );
dataUtils.delOrderTicketRedis(orderTicketsId); dataUtils.delOrderTicketRedis(orderTicketsId);
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId);
// 入场人 // 入场人
for (String entitiesId : orderTicketEntitiesIdsArr) { for (String entitiesId : orderTicketEntitiesIdsArr) {
...@@ -285,41 +300,30 @@ public class KylinRefundsStatusServiceImpl { ...@@ -285,41 +300,30 @@ public class KylinRefundsStatusServiceImpl {
kylinOrderRefunds.setExecutorName(authName); kylinOrderRefunds.setExecutorName(authName);
kylinOrderRefunds.setExecutorAt(LocalDateTime.now()); kylinOrderRefunds.setExecutorAt(LocalDateTime.now());
kylinOrderRefunds.setRefuse(refuse); kylinOrderRefunds.setRefuse(refuse);
// List<String> refundIds = refundList.stream().map(KylinOrderRefunds -> KylinOrderRefunds.getOrderRefundsId()).collect(Collectors.toList());
for (KylinOrderRefunds refund : refundList) { for (KylinOrderRefunds refund : refundList) {
KylinOrderTickets oderInfo = kylinOrderTicketsMapper.selectOne( KylinOrderTickets oderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>() new QueryWrapper<KylinOrderTickets>()
.eq("order_tickets_id", refund.getOrderTicketsId()) .eq("order_tickets_id", refund.getOrderTicketsId())
); );
double refundPrice = refund.getPrice().doubleValue() + refund.getPriceExpress().doubleValue();
MultiValueMap<String, String> params = new LinkedMultiValueMap(); MultiValueMap<String, String> params = new LinkedMultiValueMap();
params.add("code", oderInfo.getPayCode()); params.add("code", oderInfo.getPayCode());
params.add("order_refund_code", refund.getOrderRefundCode()); params.add("order_refund_code", refund.getOrderRefundCode());
params.add("price", refund.getPrice().toString()); params.add("price", String.valueOf(refundPrice));
params.add("reason", refund.getReason()); params.add("reason", refund.getReason());
params.add("notify_url", notifyUrl); params.add("notify_url", notifyUrl);
String sign = StringUtils.Ksort(params); String sign = StringUtils.Ksort(params);
sign = sign.concat("&key=").concat("R7tXY9smPQPG9Ku5yI0u6sfnlckmk04V"); sign = sign.concat("&key=").concat("R7tXY9smPQPG9Ku5yI0u6sfnlckmk04V");
// sign = MD5.getStrMD5(sign); // sign = MD5.getStrMD5(sign);
sign = sign.toUpperCase(); sign = sign.toUpperCase();
params.add("sign", sign); params.add("sign", sign);
// 请求pay
// start
// TODO: 2021/5/31 待整理
String postResult = null; String postResult = null;
postResult = HttpUtil.post(applyUrl, params); postResult = HttpUtil.post(applyUrl, params);
JsonNode postResultNew = JsonUtils.fromJson(postResult, JsonNode.class); // 更新退款表
// 请求提审接口结果
/*KylinOrderRefunds kylinOrderRefundsErr = new KylinOrderRefunds();
kylinOrderRefundsErr.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_ERROR);
kylinOrderRefundsErr.setRefundError("通知退款中心失败");
kylinOrderRefundsErr.setRefundAt(LocalDateTime.now());
kylinOrderRefundsMapper.update(
kylinOrderRefundsErr,
new UpdateWrapper<KylinOrderRefunds>().eq("order_refunds_id", refund.getOrderRefundsId())
);*/
kylinOrderRefundsMapper.update( kylinOrderRefundsMapper.update(
kylinOrderRefunds, kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refund.getOrderRefundsId()) new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refund.getOrderRefundsId())
...@@ -330,11 +334,16 @@ public class KylinRefundsStatusServiceImpl { ...@@ -330,11 +334,16 @@ public class KylinRefundsStatusServiceImpl {
} }
public boolean orderTicketRefunded(RefundCallbackParam refundCallbackParam, KylinOrderRefunds refundInfo) { public boolean orderTicketRefunded(RefundCallbackParam refundCallbackParam, KylinOrderRefunds refundInfo) {
String orderTicketEntitiesIds = refundInfo.getOrderTicketEntitiesIds(); List<KylinOrderRefundEntities> refundEntities = kylinOrderRefundsEntitiesMapper.selectList(
String[] orderTicketEntitiesIdsArr = orderTicketEntitiesIds.split(","); new QueryWrapper<KylinOrderRefundEntities>().eq("order_refunds_id", refundInfo.getOrderRefundsId())
Integer EntitiesIdsCount = orderTicketEntitiesIdsArr.length; );
List<String> orderTicketEntitiesIdsArr = refundEntities.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getOrderTicketEntitiesId()).collect(Collectors.toList());
String orderTicketsId = refundInfo.getOrderTicketsId(); String orderTicketsId = refundInfo.getOrderTicketsId();
KylinOrderTicketRelations orderRelations = kylinOrderTicketRelationsMapper.selectOne(
new QueryWrapper<KylinOrderTicketRelations>().eq("order_id", orderTicketsId)
);
// 更新数据 // 更新数据
// 订单状态表 // 订单状态表
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne( KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
...@@ -342,51 +351,63 @@ public class KylinRefundsStatusServiceImpl { ...@@ -342,51 +351,63 @@ public class KylinRefundsStatusServiceImpl {
); );
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus(); KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
int newStatus = 0; int newStatus = 0;
if (EntitiesIdsCount + orderInfo.getRefundNumber() == orderInfo.getNumber()) { if (refundCallbackParam.getRefund_price() + orderInfo.getPriceRefund().doubleValue() == orderInfo.getPriceActual().doubleValue()) {
newStatus = KylinTableStatusConst.ORDER_STATUS4; newStatus = KylinTableStatusConst.ORDER_STATUS4;
} else { } else {
newStatus = KylinTableStatusConst.ORDER_STATUS6; newStatus = KylinTableStatusConst.ORDER_STATUS6;
} }
orderStatusTable.setStatus(newStatus); orderStatusTable.setStatus(newStatus);
orderStatusTable.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketStatusMapper.update( kylinOrderTicketStatusMapper.update(
orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>() orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId) .eq("order_id", orderTicketsId)
); );
// 订单表
double price = orderInfo.getPriceRefund().doubleValue() + refundInfo.getPrice().doubleValue();
Integer num = orderInfo.getRefundNumber() + EntitiesIdsCount;
KylinOrderTickets update = new KylinOrderTickets();
update.setRefundNumber(num);
update.setPriceRefund(BigDecimal.valueOf(price));
kylinOrderTicketsMapper.update(
update, new UpdateWrapper<KylinOrderTickets>()
.eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketVo kylinOrderTicketVoOrder = new KylinOrderTicketVo();
kylinOrderTicketVoOrder.setStatus(newStatus);
kylinOrderTicketVoOrder.setRefundNumber(num);
// kylinOrderTicketVoOrder.setPriceRefund(BigDecimal.valueOf(price));
BasicDBObject orderEntitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVoOrder)));
Document docOrder = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderEntitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketRedis(orderTicketsId);
// 入场人 // 入场人
double priceActual = orderInfo.getPriceActual().doubleValue();
double priceExpress = orderInfo.getPriceExpress().doubleValue();
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId)
.ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
);
double onePrice = (priceActual - priceExpress) / allEntitiesCount;//单价
int refundNumber = 0;
for (String entitiesId : orderTicketEntitiesIdsArr) { for (String entitiesId : orderTicketEntitiesIdsArr) {
Double refundedPrice = kylinOrderTicketEntitiesMapper.getRefundOverEntitiesPrice(//已退完成的
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED,
entitiesId
);
KylinOrderRefundEntities refundEntitiesInfo = kylinOrderRefundsEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderRefundEntities>()
.eq("order_refunds_id", refundInfo.getOrderRefundsId())
.eq("order_ticket_entities_id", entitiesId)
);
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities(); KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
// TODO: 2021/5/27 事物 and 部分退款 double priceNew = refundEntitiesInfo.getRefundPrice().doubleValue() + refundedPrice.doubleValue();
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3); if (priceNew == onePrice) {
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3);
refundNumber ++;
} else {
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT4);
}
entitiesTable.setUpdatedAt(LocalDateTime.now());
entitiesTable.setRefundPrice(BigDecimal.valueOf(priceNew));
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>() kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", entitiesId) .eq("order_ticket_entities_id", entitiesId)
.eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT2) .eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT2)
); );
KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo(); KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo();
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3); if (priceNew == onePrice) {
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3);
} else {
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT4);
}
kylinOrderTicketEntitiesVo.setUpdatedAt(LocalDateTime.now().toString());
kylinOrderTicketEntitiesVo.setRefundPrice(BigDecimal.valueOf(priceNew));
BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo))); BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo)));
Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate( Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketEntitiesId").is(entitiesId)).getQueryObject(), Query.query(Criteria.where("orderTicketEntitiesId").is(entitiesId)).getQueryObject(),
...@@ -397,6 +418,33 @@ public class KylinRefundsStatusServiceImpl { ...@@ -397,6 +418,33 @@ public class KylinRefundsStatusServiceImpl {
dataUtils.delOrderTicketEntitiesRedis(entitiesId); dataUtils.delOrderTicketEntitiesRedis(entitiesId);
} }
// 订单表
double price = orderInfo.getPriceRefund().doubleValue() + refundCallbackParam.getRefund_price();
Integer num = orderInfo.getRefundNumber() + refundNumber;
KylinOrderTickets update = new KylinOrderTickets();
update.setRefundNumber(num);
update.setPriceRefund(BigDecimal.valueOf(price));
update.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketsMapper.update(
update, new UpdateWrapper<KylinOrderTickets>()
.eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketVo kylinOrderTicketVoOrder = new KylinOrderTicketVo();
kylinOrderTicketVoOrder.setStatus(newStatus);
kylinOrderTicketVoOrder.setRefundNumber(num);
kylinOrderTicketVoOrder.setUpdatedAt(LocalDateTime.now().toString());
// TODO: 2021/6/16 error
// kylinOrderTicketVoOrder.setPriceRefund(BigDecimal.valueOf(price));
BasicDBObject orderEntitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVoOrder)));
Document docOrder = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderEntitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketRedis(orderTicketsId);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId);
// 退款单完成 // 退款单完成
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds(); KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED); kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED);
...@@ -405,7 +453,7 @@ public class KylinRefundsStatusServiceImpl { ...@@ -405,7 +453,7 @@ public class KylinRefundsStatusServiceImpl {
kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id()); kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id());
kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at()); kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at());
kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error()); kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error());
kylinOrderRefunds.setUpdatedAt(LocalDateTime.now());
kylinOrderRefundsMapper.update( kylinOrderRefundsMapper.update(
kylinOrderRefunds, kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refundInfo.getOrderRefundsId()) new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refundInfo.getOrderRefundsId())
...@@ -415,6 +463,10 @@ public class KylinRefundsStatusServiceImpl { ...@@ -415,6 +463,10 @@ public class KylinRefundsStatusServiceImpl {
// 退还库存 // 退还库存
for (String entitiesId : orderTicketEntitiesIdsArr) { for (String entitiesId : orderTicketEntitiesIdsArr) {
dataUtils.changeSurplusGeneral(entitiesId, 1); dataUtils.changeSurplusGeneral(entitiesId, 1);
KylinOrderTicketEntities entitiesInfo = kylinOrderTicketEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderTicketEntities>().eq("order_ticket_entities_id", entitiesId)
);
dataUtils.changeBuyInfo(orderInfo.getUserId(), "", orderRelations.getPerformanceId(), entitiesInfo.getTicketId(), -1);
} }
} }
......
...@@ -5,6 +5,8 @@ import com.liquidnet.common.cache.redis.util.RedisUtil; ...@@ -5,6 +5,8 @@ import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.kylin.constant.KylinRedisConst; import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.dto.vo.*; import com.liquidnet.service.kylin.dto.vo.*;
import com.liquidnet.service.kylin.dto.vo.middle.KylinTicketTimesVo;
import com.liquidnet.service.kylin.dto.vo.middle.KylinTicketVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo;
...@@ -18,6 +20,8 @@ import org.springframework.data.mongodb.core.query.Criteria; ...@@ -18,6 +20,8 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
@Component @Component
...@@ -215,4 +219,131 @@ public class DataUtils { ...@@ -215,4 +219,131 @@ public class DataUtils {
System.out.println("创建Vo异常"); System.out.println("创建Vo异常");
} }
} }
/**
* 获取巡演列表redis
*/
public List<KylinPerformanceVo> getRoadList(String roadShowId) {
String redisKey = KylinRedisConst.PERFORMANCES_ROADLIST.concat(roadShowId);
if (!redisUtil.hasKey(redisKey)) {
List<KylinPerformanceVo> roadList = mongoTemplate.find(
Query.query(Criteria.where("roadShowId").is(roadShowId)),
KylinPerformanceVo.class,
KylinPerformanceVo.class.getSimpleName()
);
redisUtil.set(redisKey, roadList);
}
return (List<KylinPerformanceVo>) redisUtil.get(redisKey);
}
/**
* 根据演出id 获取 演出vo 详情
*
* @param performanceId
* @return
*/
public KylinPerformanceVo getPerformanceVo(String performanceId) {
if (redisUtil.hasKey(KylinRedisConst.PERFORMANCES + performanceId)) {
} else {
KylinPerformanceVo performanceData = mongoTemplate.findOne(Query.query(Criteria.where("performancesId").is(performanceId)), KylinPerformanceVo.class, KylinPerformanceVo.class.getSimpleName());
List<KylinPerformanceVo> roadList = new ArrayList();
if (Integer.parseInt(performanceData.getRoadShowId()) > 0) {
roadList = getRoadList(performanceData.getRoadShowId());
}
redisUtil.set(KylinRedisConst.PERFORMANCES + performanceId, performanceData);
performanceData.setRoadList(roadList); // 不一起存到演出详情
}
return (KylinPerformanceVo) redisUtil.get(KylinRedisConst.PERFORMANCES + performanceId);
}
/**
* @param performanceId 演出id
* @param ticketId 票种id
* @param buyCount 购买数量 大于 0 增加 小于 0 减少 对应 支付 退款表
*/
public void changeBuyInfo(String userId, String idCard, String performanceId, String ticketId, int buyCount) {
String redisKey;
KylinPerformanceVo vo = getPerformanceVo(performanceId);
int isTrueName = vo.getIsTrueName();
int ticketType = 0;
String useTime = "";
HashMap<String, ArrayList<String>> allTicketId = new HashMap<>();
for (int x = 0; x < vo.getTicketTimeList().size(); x++) {
KylinTicketTimesVo timeItem = vo.getTicketTimeList().get(x);
ArrayList<String> ticketList = new ArrayList<>();
for (int y = 0; y < timeItem.getTicketList().size(); y++) {
KylinTicketVo ticketItem = timeItem.getTicketList().get(y);
if (ticketItem.getType() == 1) {
ticketList.add(ticketItem.getTicketsId());
}
if (ticketItem.getTicketsId().equals(ticketId)) {
useTime = ticketItem.getUseStart();
ticketType = ticketItem.getType();
}
}
allTicketId.put(timeItem.getUseStart(), ticketList);
}
if (0 == isTrueName) {
redisKey = KylinRedisConst.USERID_BUY_INFO + userId;
} else {
redisKey = KylinRedisConst.IDCARD_BUY_INFO + idCard;
}
String performanceIdKey = redisKey + ":" + KylinRedisConst.PERFORMANCE_ID + ":" + performanceId;
String ticketIdKey = redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + ticketId;
String ticketUseTimeKey = ticketIdKey + ":" + KylinRedisConst.USE_TIME;
redisUtil.set(ticketUseTimeKey, useTime);
if (buyCount > 0) {
redisUtil.incr(ticketIdKey, buyCount);
if (1 == ticketType) {
int count = 0;
for (int i = 0; i < allTicketId.get(useTime).size(); i++) {
String item = allTicketId.get(useTime).get(i);
if (allTicketId.get(useTime).size() == 1) {
redisUtil.incr(performanceIdKey, buyCount);
break;
}
if (null == redisUtil.get(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item)) {
redisUtil.set(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item, 0);
}
if (i == 0) {
count = (int) redisUtil.get(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item);
} else {
if (count != (int) redisUtil.get(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item)) {
redisUtil.incr(performanceIdKey, buyCount);
break;
}
}
}
} else {
redisUtil.incr(performanceIdKey, buyCount);
}
} else {
redisUtil.decr(ticketIdKey, Math.abs(buyCount));
if (1 == ticketType) {
int count = 0;
for (int i = 0; i < allTicketId.get(useTime).size(); i++) {
String item = allTicketId.get(useTime).get(i);
if (allTicketId.get(useTime).size() == 1) {
redisUtil.decr(performanceIdKey, Math.abs(buyCount));
break;
}
if (null == redisUtil.get(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item)) {
redisUtil.set(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item, 0);
}
if (i == 0) {
count = (int) redisUtil.get(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item);
} else {
if (count != (int) redisUtil.get(redisKey + ":" + KylinRedisConst.TICKET_ID + ":" + item)) {
redisUtil.decr(performanceIdKey, Math.abs(buyCount));
break;
}
}
}
} else {
redisUtil.decr(performanceIdKey, Math.abs(buyCount));
}
}
}
} }
...@@ -29,6 +29,8 @@ public class KylinOrderTicketEntitiesDao { ...@@ -29,6 +29,8 @@ public class KylinOrderTicketEntitiesDao {
private String useEnd; private String useEnd;
private BigDecimal canRefundedPrice;
/** /**
* 订单 * 订单
*/ */
......
...@@ -60,8 +60,6 @@ public class OrderRefundDao implements Serializable { ...@@ -60,8 +60,6 @@ public class OrderRefundDao implements Serializable {
private String refundType; private String refundType;
private String refundCate; private String refundCate;
private String orderTicketEntitiesIds;
private String createdAt; private String createdAt;
private String updatedAt; private String updatedAt;
......
package com.liquidnet.service.kylin.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* <p>
* 订单退款入场人表
* </p>
*
* @author jiangxiulong
* @since 2021-06-16
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class KylinOrderRefundEntities implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "mid", type = IdType.AUTO)
private Integer mid;
private String orderRefundsEntitiesId;
private String orderRefundsId;
private String orderTicketEntitiesId;
private BigDecimal refundPrice;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
...@@ -69,6 +69,7 @@ public class KylinOrderRefunds implements Serializable { ...@@ -69,6 +69,7 @@ public class KylinOrderRefunds implements Serializable {
* 退款总金额 * 退款总金额
*/ */
private BigDecimal price; private BigDecimal price;
private BigDecimal priceExpress;
/** /**
* 退款状态: 0请求退款 2取消退款 1审核通过 5驳回退款 7等待退款 3正在退款 4完成退款 6退款失败 * 退款状态: 0请求退款 2取消退款 1审核通过 5驳回退款 7等待退款 3正在退款 4完成退款 6退款失败
...@@ -146,11 +147,6 @@ public class KylinOrderRefunds implements Serializable { ...@@ -146,11 +147,6 @@ public class KylinOrderRefunds implements Serializable {
private String refundType; private String refundType;
private Integer refundCate; private Integer refundCate;
/**
* 订单入场人/搭售款式表 id 多个 ,分割
*/
private String orderTicketEntitiesIds;
private LocalDateTime createdAt; private LocalDateTime createdAt;
private LocalDateTime updatedAt; private LocalDateTime updatedAt;
......
package com.liquidnet.service.kylin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liquidnet.service.kylin.entity.KylinOrderRefundEntities;
/**
* <p>
* 订单退款入场人表 Mapper 接口
* </p>
*
* @author jiangxiulong
* @since 2021-06-16
*/
public interface KylinOrderRefundsEntitiesMapper extends BaseMapper<KylinOrderRefundEntities> {
}
...@@ -29,4 +29,14 @@ public interface KylinOrderRefundsMapper extends BaseMapper<KylinOrderRefunds> { ...@@ -29,4 +29,14 @@ public interface KylinOrderRefundsMapper extends BaseMapper<KylinOrderRefunds> {
List<OrderRefundDao> misRefundList(Map<String,Object> map); List<OrderRefundDao> misRefundList(Map<String,Object> map);
int selectRefundingCount(
@Param("orderTicketsId") String orderTicketsId,
@Param("orderRefundStatusCancel") Integer orderRefundStatusCancel,
@Param("ticketEntityIds") List<String> ticketEntityIds
);
double RefundPriceExpressSum(
@Param("orderTicketsId") String orderTicketsId,
@Param("orderRefundStatusCancel") Integer orderRefundStatusCancel
);
} }
...@@ -18,7 +18,19 @@ import java.util.List; ...@@ -18,7 +18,19 @@ import java.util.List;
*/ */
public interface KylinOrderTicketEntitiesMapper extends BaseMapper<KylinOrderTicketEntities> { public interface KylinOrderTicketEntitiesMapper extends BaseMapper<KylinOrderTicketEntities> {
List<KylinOrderRefundsEntitiesDao> selectEntitiesList(@Param("orderTicketEntitiesIdS") String[] orderTicketEntitiesIdS); List<KylinOrderRefundsEntitiesDao> selectEntitiesList(@Param("orderTicketEntitiesIdS") List<String> orderTicketEntitiesIdS);
List<KylinOrderTicketEntitiesDao> getRefundEntitiesList(String orderTicketsId); List<KylinOrderTicketEntitiesDao> getRefundEntitiesList(String orderTicketsId);
Double getRefundEntitiesPrice(
@Param("orderTicketsId") String orderTicketsId,
@Param("orderRefundStatusCancel") Integer orderRefundStatusCancel,
@Param("orderTicketEntitiesId") String orderTicketEntitiesId
);
Double getRefundOverEntitiesPrice(
@Param("orderTicketsId") String orderTicketsId,
@Param("orderRefundStatus") Integer orderRefundStatus,
@Param("entitiesId") String entitiesId
);
} }
...@@ -48,4 +48,25 @@ ...@@ -48,4 +48,25 @@
</if> </if>
</where> </where>
</select> </select>
<select id="selectRefundingCount" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM kylin_order_refunds AS a
JOIN kylin_order_refund_entities AS b ON a.order_refunds_id = b.order_refunds_id
<where>
AND a.order_tickets_id = #{orderTicketsId}
AND a.status != ${orderRefundStatusCancel}
AND b.order_ticket_entities_id IN
<foreach collection="ticketEntityIds" item="entityIds" index="index" open="(" close=")" separator=",">
${entityIds}
</foreach>
</where>
</select>
<select id="RefundPriceExpressSum" resultType="java.lang.Double">
SELECT SUM(price_express)
FROM kylin_order_refunds
<where>
AND order_tickets_id = #{orderTicketsId}
AND status != ${orderRefundStatusCancel}
</where>
</select>
</mapper> </mapper>
...@@ -22,6 +22,27 @@ ...@@ -22,6 +22,27 @@
JOIN kylin_order_tickets AS c ON c.order_tickets_id = a.order_id JOIN kylin_order_tickets AS c ON c.order_tickets_id = a.order_id
<where> <where>
a.order_id = #{orderTicketsId} a.order_id = #{orderTicketsId}
AND a.is_payment != 0
</where>
</select>
<select id="getRefundEntitiesPrice" resultType="java.lang.Double">
SELECT SUM(b.refund_price)
FROM kylin_order_refunds AS a
JOIN kylin_order_refund_entities AS b ON a.order_refunds_id = b.order_refunds_id
<where>
AND a.order_tickets_id = #{orderTicketsId}
AND a.status != ${orderRefundStatusCancel}
AND b.order_ticket_entities_id = #{orderTicketEntitiesId}
</where>
</select>
<select id="getRefundOverEntitiesPrice" resultType="java.lang.Double">
SELECT SUM(b.refund_price)
FROM kylin_order_refunds AS a
JOIN kylin_order_refund_entities AS b ON a.order_refunds_id = b.order_refunds_id
<where>
AND a.order_tickets_id = #{orderTicketsId}
AND a.status = ${orderRefundStatus}
AND b.order_ticket_entities_id = #{orderTicketEntitiesId}
</where> </where>
</select> </select>
</mapper> </mapper>
...@@ -507,10 +507,11 @@ CREATE TABLE `kylin_order_ticket_entities` ...@@ -507,10 +507,11 @@ CREATE TABLE `kylin_order_ticket_entities`
`status` int(11) NOT NULL DEFAULT 0 COMMENT '出票状态: 0未出票 1已出票', `status` int(11) NOT NULL DEFAULT 0 COMMENT '出票状态: 0未出票 1已出票',
`sys_damai` int(11) NOT NULL DEFAULT 0 COMMENT '大麦同步状态: 0不同步 1待同步 2同步完成 3同步失败', `sys_damai` int(11) NOT NULL DEFAULT 0 COMMENT '大麦同步状态: 0不同步 1待同步 2同步完成 3同步失败',
`check_client` varchar(255) NOT NULL DEFAULT '' COMMENT '出票端 例如 pda 验票app android/ios 大麦出票', `check_client` varchar(255) NOT NULL DEFAULT '' COMMENT '出票端 例如 pda 验票app android/ios 大麦出票',
`is_payment` int(11) NOT NULL DEFAULT 0 COMMENT '支付状态: 0未支付 1已支付 2退款中 3已退款 ', `is_payment` int(11) NOT NULL DEFAULT 0 COMMENT '支付状态: 0未支付 1已支付 2退款中 3已退款 4部分退款',
`refund_price` decimal(8, 2) NOT NULL DEFAULT '0.00' COMMENT '已退款金额',
`comment` varchar(255) NULL DEFAULT '' COMMENT 'comment', `comment` varchar(255) NULL DEFAULT '' COMMENT 'comment',
`created_at` datetime(3) NULL DEFAULT NULL COMMENT '创建时间', `created_at` datetime(3) NULL DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime(3) NULL DEFAULT NULL COMMENT '修改时间', `updated_at` datetime(3) NULL DEFAULT NULL COMMENT '修改时间',
KEY `kylin_order_ticket_entities_uid_index` (`order_ticket_entities_id`), KEY `kylin_order_ticket_entities_uid_index` (`order_ticket_entities_id`),
PRIMARY KEY (`mid`) PRIMARY KEY (`mid`)
) ENGINE = InnoDB ) ENGINE = InnoDB
...@@ -658,9 +659,10 @@ CREATE TABLE `kylin_order_refunds` ...@@ -658,9 +659,10 @@ CREATE TABLE `kylin_order_refunds`
`refund_at` timestamp NULL DEFAULT NULL COMMENT '成功退款时间', `refund_at` timestamp NULL DEFAULT NULL COMMENT '成功退款时间',
`refund_id` varchar(50) NOT NULL DEFAULT '' COMMENT '第三方退款编号', `refund_id` varchar(50) NOT NULL DEFAULT '' COMMENT '第三方退款编号',
`refund_error` varchar(100) NOT NULL DEFAULT '' COMMENT '退款失败原因', `refund_error` varchar(100) NOT NULL DEFAULT '' COMMENT '退款失败原因',
`price` decimal(10, 2) NOT NULL DEFAULT '0.00' COMMENT '退款总金额', `price` decimal(10, 2) NOT NULL DEFAULT '0.00' COMMENT '退款票总金额',
`price_express` decimal(10, 2) NOT NULL DEFAULT '0.00' COMMENT '退款快递费',
`status` tinyint NOT NULL DEFAULT '0' COMMENT '退款状态: 0请求退款 2取消退款 1审核通过 5驳回退款 7等待退款 3正在退款 4完成退款 6退款失败', `status` tinyint NOT NULL DEFAULT '0' COMMENT '退款状态: 0请求退款 2取消退款 1审核通过 5驳回退款 7等待退款 3正在退款 4完成退款 6退款失败',
`type` tinyint NOT NULL DEFAULT '0' COMMENT '退款差异: 0申请退款返还库存 1自动退款无法取消退款不返还库存', `type` tinyint NOT NULL DEFAULT '0' COMMENT '退款差异: 0客服或票务申请 1超时自动退款不占库存',
`applicant_id` varchar(255) NOT NULL DEFAULT '' COMMENT '申请人id', `applicant_id` varchar(255) NOT NULL DEFAULT '' COMMENT '申请人id',
`applicant_name` varchar(100) NOT NULL DEFAULT '' COMMENT '申请人名称', `applicant_name` varchar(100) NOT NULL DEFAULT '' COMMENT '申请人名称',
`applicant_at` timestamp NULL DEFAULT NULL COMMENT '申请时间', `applicant_at` timestamp NULL DEFAULT NULL COMMENT '申请时间',
...@@ -675,7 +677,6 @@ CREATE TABLE `kylin_order_refunds` ...@@ -675,7 +677,6 @@ CREATE TABLE `kylin_order_refunds`
`refuse` varchar(200) NOT NULL DEFAULT '' COMMENT '回绝原因', `refuse` varchar(200) NOT NULL DEFAULT '' COMMENT '回绝原因',
`refund_type` varchar(200) NOT NULL DEFAULT '' COMMENT '退款方式', `refund_type` varchar(200) NOT NULL DEFAULT '' COMMENT '退款方式',
`refund_cate` tinyint NOT NULL DEFAULT '0' COMMENT '1票务2快递费3票和快递费', `refund_cate` tinyint NOT NULL DEFAULT '0' COMMENT '1票务2快递费3票和快递费',
`order_ticket_entities_ids` text COMMENT '订单入场人/搭售款式表 id 多个 ,分割',
`created_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`mid`), PRIMARY KEY (`mid`),
...@@ -685,4 +686,20 @@ CREATE TABLE `kylin_order_refunds` ...@@ -685,4 +686,20 @@ CREATE TABLE `kylin_order_refunds`
KEY `kylin_order_refunds_order_refunds_id_index` (`order_refunds_id`) KEY `kylin_order_refunds_order_refunds_id_index` (`order_refunds_id`)
) ENGINE = InnoDB ) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='订单退款表' COLLATE = utf8mb4_unicode_ci COMMENT ='订单退款表';
drop TABLE if exists `kylin_order_refund_entities`;
CREATE TABLE `kylin_order_refund_entities`
(
`mid` int unsigned NOT NULL AUTO_INCREMENT,
`order_refunds_entities_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'order_refunds_entities_id',
`order_refunds_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'order_refunds_id',
`order_ticket_entities_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'order_ticket_entities_id',
`refund_price` decimal(11, 2) NOT NULL DEFAULT '0.00' COMMENT '退款金额',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY `kylin_order_refunds_entities_id_index` (`order_refunds_entities_id`),
PRIMARY KEY (`mid`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT '退款入场人表';
...@@ -3,11 +3,13 @@ package com.liquidnet.service.kylin.controller; ...@@ -3,11 +3,13 @@ package com.liquidnet.service.kylin.controller;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam; import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.service.impl.OrderRefundsCallbackServiceImpl; import com.liquidnet.service.kylin.service.impl.OrderRefundsCallbackServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
...@@ -21,12 +23,29 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -21,12 +23,29 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "前端-退款回调") @Api(tags = "前端-退款回调")
@RestController @RestController
@RequestMapping("refund") @RequestMapping("refund")
@Validated
public class OrderRefundCallbackController { public class OrderRefundCallbackController {
@Autowired @Autowired
private OrderRefundsCallbackServiceImpl orderRefundsCallbackServiceImpl; private OrderRefundsCallbackServiceImpl orderRefundsCallbackServiceImpl;
@PostMapping("apply")
@ApiOperation("超时退款")
@ApiImplicitParams({
@ApiImplicitParam(type = "body", dataType = "String", name = "orderTicketsId", value = "订单ID", required = true),
})
public Boolean refundApply(@RequestParam() String orderTicketsId) {
try {
Boolean res = orderRefundsCallbackServiceImpl.refundApply(orderTicketsId);
if (res) {
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}
@PostMapping("callback") @PostMapping("callback")
@ApiOperation("退款回调") @ApiOperation("退款回调")
public String refundCallback(RefundCallbackParam refundCallbackParam) { public String refundCallback(RefundCallbackParam refundCallbackParam) {
......
...@@ -314,11 +314,11 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM ...@@ -314,11 +314,11 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
orderTickets.setPriceTotal(ticketData.getPrice().multiply(new BigDecimal(payOrderParam.getNumber())).add(payOrderParam.getIsExpress() == 1 ? ticketData.getPriceExpress() : new BigDecimal("0"))); orderTickets.setPriceTotal(ticketData.getPrice().multiply(new BigDecimal(payOrderParam.getNumber())).add(payOrderParam.getIsExpress() == 1 ? ticketData.getPriceExpress() : new BigDecimal("0")));
} }
if (Arrays.asList("dev", "test").contains(environment.getProperty("spring.profiles.active"))) { /*if (Arrays.asList("dev", "test").contains(environment.getProperty("spring.profiles.active"))) {
orderTickets.setPriceActual(new BigDecimal("0.01")); orderTickets.setPriceActual(new BigDecimal("0.01"));
} else { } else {*/
orderTickets.setPriceActual(orderTickets.getPriceTotal()); orderTickets.setPriceActual(orderTickets.getPriceTotal());
} // }
orderTickets.setPriceVoucher(new BigDecimal("0.0")); orderTickets.setPriceVoucher(new BigDecimal("0.0"));
orderTickets.setPriceExpress(ticketData.getPriceExpress()); orderTickets.setPriceExpress(ticketData.getPriceExpress());
...@@ -466,11 +466,11 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM ...@@ -466,11 +466,11 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
LinkedMultiValueMap<String, String> httpData = new LinkedMultiValueMap<String, String>(); LinkedMultiValueMap<String, String> httpData = new LinkedMultiValueMap<String, String>();
httpData.add("type", "TICKET"); httpData.add("type", "TICKET");
if (Arrays.asList("dev", "test").contains(environment.getProperty("spring.profiles.active"))) { /*if (Arrays.asList("dev", "test").contains(environment.getProperty("spring.profiles.active"))) {
httpData.add("price", "0.01"); httpData.add("price", "0.01");
} else { } else {*/
httpData.add("price", orderTickets.getPriceActual().toString()); httpData.add("price", orderTickets.getPriceActual().toString());
} // }
httpData.add("name", useTime + ticketData.getTitle() + "-" + performanceData.getTitle()); httpData.add("name", useTime + ticketData.getTitle() + "-" + performanceData.getTitle());
httpData.add("detail", performanceData.getTitle() + "-" + ticketData.getTitle() + "-" + useTime); httpData.add("detail", performanceData.getTitle() + "-" + ticketData.getTitle() + "-" + useTime);
httpData.add("order_code", orderTickets.getOrderCode()); httpData.add("order_code", orderTickets.getOrderCode());
......
...@@ -3,24 +3,22 @@ package com.liquidnet.service.kylin.service.impl; ...@@ -3,24 +3,22 @@ package com.liquidnet.service.kylin.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst; import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dto.param.RefundApplyParam;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam; import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketEntitiesVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo; import com.liquidnet.service.kylin.dto.vo.mongo.KylinOrderTicketVo;
import com.liquidnet.service.kylin.entity.KylinOrderRefunds; import com.liquidnet.service.kylin.entity.*;
import com.liquidnet.service.kylin.entity.KylinOrderTicketEntities; import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.entity.KylinOrderTicketStatus;
import com.liquidnet.service.kylin.entity.KylinOrderTickets;
import com.liquidnet.service.kylin.mapper.KylinOrderRefundsMapper;
import com.liquidnet.service.kylin.mapper.KylinOrderTicketEntitiesMapper;
import com.liquidnet.service.kylin.mapper.KylinOrderTicketStatusMapper;
import com.liquidnet.service.kylin.mapper.KylinOrderTicketsMapper;
import com.liquidnet.service.kylin.utils.DataUtils; import com.liquidnet.service.kylin.utils.DataUtils;
import com.liquidnet.service.kylin.utils.MongoVoUtils;
import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObject;
import com.mongodb.client.model.FindOneAndUpdateOptions; import com.mongodb.client.model.FindOneAndUpdateOptions;
import com.mongodb.client.model.ReturnDocument; import com.mongodb.client.model.ReturnDocument;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.bson.Document; import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
...@@ -29,6 +27,9 @@ import org.springframework.data.mongodb.core.query.Query; ...@@ -29,6 +27,9 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
...@@ -54,18 +55,32 @@ public class KylinRefundsStatusServiceImpl { ...@@ -54,18 +55,32 @@ public class KylinRefundsStatusServiceImpl {
@Autowired @Autowired
private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper; private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper;
@Autowired
private KylinOrderRefundsEntitiesMapper kylinOrderRefundsEntitiesMapper;
@Autowired
private KylinOrderTicketRelationsMapper kylinOrderTicketRelationsMapper;
@Autowired @Autowired
MongoTemplate mongoTemplate; MongoTemplate mongoTemplate;
@Autowired @Autowired
private DataUtils dataUtils; private DataUtils dataUtils;
@Autowired
private MongoVoUtils mongoVoUtils;
public boolean orderTicketRefunded(RefundCallbackParam refundCallbackParam, KylinOrderRefunds refundInfo) { public boolean orderTicketRefunded(RefundCallbackParam refundCallbackParam, KylinOrderRefunds refundInfo) {
String orderTicketEntitiesIds = refundInfo.getOrderTicketEntitiesIds(); List<KylinOrderRefundEntities> refundEntities = kylinOrderRefundsEntitiesMapper.selectList(
String[] orderTicketEntitiesIdsArr = orderTicketEntitiesIds.split(","); new QueryWrapper<KylinOrderRefundEntities>().eq("order_refunds_id", refundInfo.getOrderRefundsId())
Integer EntitiesIdsCount = orderTicketEntitiesIdsArr.length; );
List<String> orderTicketEntitiesIdsArr = refundEntities.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getOrderTicketEntitiesId()).collect(Collectors.toList());
String orderTicketsId = refundInfo.getOrderTicketsId(); String orderTicketsId = refundInfo.getOrderTicketsId();
KylinOrderTicketRelations orderRelations = kylinOrderTicketRelationsMapper.selectOne(
new QueryWrapper<KylinOrderTicketRelations>().eq("order_id", orderTicketsId)
);
// 更新数据 // 更新数据
// 订单状态表 // 订单状态表
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne( KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
...@@ -73,51 +88,63 @@ public class KylinRefundsStatusServiceImpl { ...@@ -73,51 +88,63 @@ public class KylinRefundsStatusServiceImpl {
); );
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus(); KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
int newStatus = 0; int newStatus = 0;
if (EntitiesIdsCount + orderInfo.getRefundNumber() == orderInfo.getNumber()) { if (refundCallbackParam.getRefund_price() + orderInfo.getPriceRefund().doubleValue() == orderInfo.getPriceActual().doubleValue()) {
newStatus = KylinTableStatusConst.ORDER_STATUS4; newStatus = KylinTableStatusConst.ORDER_STATUS4;
} else { } else {
newStatus = KylinTableStatusConst.ORDER_STATUS6; newStatus = KylinTableStatusConst.ORDER_STATUS6;
} }
orderStatusTable.setStatus(newStatus); orderStatusTable.setStatus(newStatus);
orderStatusTable.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketStatusMapper.update( kylinOrderTicketStatusMapper.update(
orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>() orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId) .eq("order_id", orderTicketsId)
); );
// 订单表
double price = orderInfo.getPriceRefund().doubleValue() + refundInfo.getPrice().doubleValue();
Integer num = orderInfo.getRefundNumber() + EntitiesIdsCount;
KylinOrderTickets update = new KylinOrderTickets();
update.setRefundNumber(num);
update.setPriceRefund(BigDecimal.valueOf(price));
kylinOrderTicketsMapper.update(
update, new UpdateWrapper<KylinOrderTickets>()
.eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketVo kylinOrderTicketVoOrder = new KylinOrderTicketVo();
kylinOrderTicketVoOrder.setStatus(newStatus);
kylinOrderTicketVoOrder.setRefundNumber(num);
// kylinOrderTicketVoOrder.setPriceRefund(BigDecimal.valueOf(price));
BasicDBObject orderEntitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVoOrder)));
Document docOrder = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderEntitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketRedis(orderTicketsId);
// 入场人 // 入场人
double priceActual = orderInfo.getPriceActual().doubleValue();
double priceExpress = orderInfo.getPriceExpress().doubleValue();
int allEntitiesCount = kylinOrderTicketEntitiesMapper.selectCount(// 总入场人数量 排出未付款的 用来计算单入场人的价格
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId)
.ne("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT0)
);
double onePrice = (priceActual - priceExpress) / allEntitiesCount;//单价
int refundNumber = 0;
for (String entitiesId : orderTicketEntitiesIdsArr) { for (String entitiesId : orderTicketEntitiesIdsArr) {
Double refundedPrice = kylinOrderTicketEntitiesMapper.getRefundOverEntitiesPrice(//已退完成的
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED,
entitiesId
);
KylinOrderRefundEntities refundEntitiesInfo = kylinOrderRefundsEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderRefundEntities>()
.eq("order_refunds_id", refundInfo.getOrderRefundsId())
.eq("order_ticket_entities_id", entitiesId)
);
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities(); KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
// TODO: 2021/5/27 事物 and 部分退款 double priceNew = refundEntitiesInfo.getRefundPrice().doubleValue() + refundedPrice.doubleValue();
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3); if (priceNew == onePrice) {
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3);
refundNumber ++;
} else {
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT4);
}
entitiesTable.setUpdatedAt(LocalDateTime.now());
entitiesTable.setRefundPrice(BigDecimal.valueOf(priceNew));
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>() kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", entitiesId) .eq("order_ticket_entities_id", entitiesId)
.eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT2) .eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT2)
); );
KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo(); KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo();
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3); if (priceNew == onePrice) {
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT3);
} else {
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT4);
}
kylinOrderTicketEntitiesVo.setUpdatedAt(LocalDateTime.now().toString());
kylinOrderTicketEntitiesVo.setRefundPrice(BigDecimal.valueOf(priceNew));
BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo))); BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo)));
Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate( Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketEntitiesId").is(entitiesId)).getQueryObject(), Query.query(Criteria.where("orderTicketEntitiesId").is(entitiesId)).getQueryObject(),
...@@ -128,6 +155,33 @@ public class KylinRefundsStatusServiceImpl { ...@@ -128,6 +155,33 @@ public class KylinRefundsStatusServiceImpl {
dataUtils.delOrderTicketEntitiesRedis(entitiesId); dataUtils.delOrderTicketEntitiesRedis(entitiesId);
} }
// 订单表
double price = orderInfo.getPriceRefund().doubleValue() + refundCallbackParam.getRefund_price();
Integer num = orderInfo.getRefundNumber() + refundNumber;
KylinOrderTickets update = new KylinOrderTickets();
update.setRefundNumber(num);
update.setPriceRefund(BigDecimal.valueOf(price));
update.setUpdatedAt(LocalDateTime.now());
kylinOrderTicketsMapper.update(
update, new UpdateWrapper<KylinOrderTickets>()
.eq("order_tickets_id", orderTicketsId)
);
KylinOrderTicketVo kylinOrderTicketVoOrder = new KylinOrderTicketVo();
kylinOrderTicketVoOrder.setStatus(newStatus);
kylinOrderTicketVoOrder.setRefundNumber(num);
kylinOrderTicketVoOrder.setUpdatedAt(LocalDateTime.now().toString());
// TODO: 2021/6/16 error
// kylinOrderTicketVoOrder.setPriceRefund(BigDecimal.valueOf(price));
BasicDBObject orderEntitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVoOrder)));
Document docOrder = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderEntitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketRedis(orderTicketsId);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId);
// 退款单完成 // 退款单完成
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds(); KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED); kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_REFUNDED);
...@@ -136,7 +190,7 @@ public class KylinRefundsStatusServiceImpl { ...@@ -136,7 +190,7 @@ public class KylinRefundsStatusServiceImpl {
kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id()); kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id());
kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at()); kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at());
kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error()); kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error());
kylinOrderRefunds.setUpdatedAt(LocalDateTime.now());
kylinOrderRefundsMapper.update( kylinOrderRefundsMapper.update(
kylinOrderRefunds, kylinOrderRefunds,
new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refundInfo.getOrderRefundsId()) new UpdateWrapper<KylinOrderRefunds>().in("order_refunds_id", refundInfo.getOrderRefundsId())
...@@ -146,9 +200,109 @@ public class KylinRefundsStatusServiceImpl { ...@@ -146,9 +200,109 @@ public class KylinRefundsStatusServiceImpl {
// 退还库存 // 退还库存
for (String entitiesId : orderTicketEntitiesIdsArr) { for (String entitiesId : orderTicketEntitiesIdsArr) {
dataUtils.changeSurplusGeneral(entitiesId, 1); dataUtils.changeSurplusGeneral(entitiesId, 1);
KylinOrderTicketEntities entitiesInfo = kylinOrderTicketEntitiesMapper.selectOne(
new QueryWrapper<KylinOrderTicketEntities>().eq("order_ticket_entities_id", entitiesId)
);
dataUtils.changeBuyInfo(orderInfo.getUserId(), "", orderRelations.getPerformanceId(), entitiesInfo.getTicketId(), -1);
} }
} }
return true; return true;
} }
public Boolean orderTicketRefunding(
KylinOrderTickets orderInfo, String orderTicketsId, List<String> ticketEntityIds
) {
// 基础数据
String authId = "overtime";
String authName = "system";
String reason = "支付超时自动退款";
// 本次退款票总金额
double RefundPriceExpress = orderInfo.getPriceExpress().doubleValue();
double entitiesPriceSum = orderInfo.getPriceActual().doubleValue() - RefundPriceExpress;
// 更新数据
// 订单状态表 和 缓存
KylinOrderTicketStatus orderStatusTable = new KylinOrderTicketStatus();
orderStatusTable.setStatus(KylinTableStatusConst.ORDER_STATUS3);
kylinOrderTicketStatusMapper.update(orderStatusTable, new UpdateWrapper<KylinOrderTicketStatus>()
.eq("order_id", orderTicketsId));
KylinOrderTicketVo kylinOrderTicketVo = new KylinOrderTicketVo();
kylinOrderTicketVo.setStatus(KylinTableStatusConst.ORDER_STATUS3);
BasicDBObject orderObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketVo)));
Document orderDoc = mongoTemplate.getCollection(KylinOrderTicketVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketsId").is(orderTicketsId)).getQueryObject(),
orderObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketRedis(orderTicketsId);
mongoVoUtils.resetOrderListVo(orderInfo.getUserId(), 2, orderTicketsId);
// 订单入场人表 和 缓存
for (String v : ticketEntityIds) {
KylinOrderTicketEntities entitiesTable = new KylinOrderTicketEntities();
entitiesTable.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
kylinOrderTicketEntitiesMapper.update(entitiesTable, new UpdateWrapper<KylinOrderTicketEntities>()
.eq("order_ticket_entities_id", v));
KylinOrderTicketEntitiesVo kylinOrderTicketEntitiesVo = new KylinOrderTicketEntitiesVo();
kylinOrderTicketEntitiesVo.setIsPayment(KylinTableStatusConst.ENTITIES_IS_PAYMENT2);
BasicDBObject entitiesObject = new BasicDBObject("$set", JSON.parse(JsonUtils.toJson(kylinOrderTicketEntitiesVo)));
Document entitiesDoc = mongoTemplate.getCollection(KylinOrderTicketEntitiesVo.class.getSimpleName()).findOneAndUpdate(
Query.query(Criteria.where("orderTicketEntitiesId").is(v)).getQueryObject(),
entitiesObject,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
);
dataUtils.delOrderTicketEntitiesRedis(v);
}
// 退款明细
KylinOrderRefunds kylinOrderRefunds = new KylinOrderRefunds();
String orderRefundsId = IDGenerator.nextSnowId().toString();
kylinOrderRefunds.setOrderRefundsId(orderRefundsId);
kylinOrderRefunds.setOrderTicketsId(orderTicketsId);
Integer refundCount = kylinOrderRefundsMapper.selectCount(
new QueryWrapper<KylinOrderRefunds>()
.eq("order_tickets_id", orderTicketsId)
);
String orderRefundCode = orderInfo.getOrderCode();
String codeNum = StringUtils.leftPad(String.valueOf(refundCount), 3, "0");
kylinOrderRefunds.setOrderRefundCode(orderRefundCode.concat(codeNum));
kylinOrderRefunds.setPrice(BigDecimal.valueOf(entitiesPriceSum));
kylinOrderRefunds.setPriceExpress(BigDecimal.valueOf(RefundPriceExpress));
kylinOrderRefunds.setStatus(KylinTableStatusConst.ORDER_REFUND_STATUS_APPLY);
kylinOrderRefunds.setType(KylinTableStatusConst.ORDER_REFUND_TYPE_AUTO);
kylinOrderRefunds.setApplicantId(authId);
kylinOrderRefunds.setApplicantName(authName);
kylinOrderRefunds.setApplicantAt(LocalDateTime.now());
kylinOrderRefunds.setReason(reason);
if (RefundPriceExpress > 0 && entitiesPriceSum > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE3);
} else if (RefundPriceExpress > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE2);
} else if (entitiesPriceSum > 0) {
kylinOrderRefunds.setRefundCate(KylinTableStatusConst.ORDER_REFUND_CATE1);
}
kylinOrderRefunds.setCreatedAt(LocalDateTime.now());
int rows = kylinOrderRefundsMapper.insert(kylinOrderRefunds);
// 退款入场人表
KylinOrderRefundEntities kylinOrderRefundEntities = new KylinOrderRefundEntities();
for (int i = 0; i <= ticketEntityIds.size(); i++) {
String orderRefundsEntitiesId = IDGenerator.nextSnowId().toString();
kylinOrderRefundEntities.setOrderRefundsEntitiesId(orderRefundsEntitiesId);
kylinOrderRefundEntities.setOrderRefundsId(orderRefundsId);
kylinOrderRefundEntities.setRefundPrice(BigDecimal.valueOf(entitiesPriceSum / ticketEntityIds.size()));
kylinOrderRefundEntities.setOrderTicketEntitiesId(ticketEntityIds.get(i));
kylinOrderRefundEntities.setCreatedAt(LocalDateTime.now());
int rowsR = kylinOrderRefundsEntitiesMapper.insert(kylinOrderRefundEntities);
}
return true;
}
} }
package com.liquidnet.service.kylin.service.impl; package com.liquidnet.service.kylin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.constant.KylinTableStatusConst; import com.liquidnet.service.kylin.constant.KylinTableStatusConst;
import com.liquidnet.service.kylin.dto.param.RefundApplyParam;
import com.liquidnet.service.kylin.dto.param.RefundCallbackParam; import com.liquidnet.service.kylin.dto.param.RefundCallbackParam;
import com.liquidnet.service.kylin.entity.KylinOrderRefunds; import com.liquidnet.service.kylin.entity.KylinOrderRefunds;
import com.liquidnet.service.kylin.mapper.KylinOrderRefundsMapper; import com.liquidnet.service.kylin.entity.KylinOrderTicketEntities;
import com.liquidnet.service.kylin.entity.KylinOrderTicketStatus;
import com.liquidnet.service.kylin.entity.KylinOrderTickets;
import com.liquidnet.service.kylin.mapper.*;
import com.liquidnet.service.kylin.service.IKylinOrderRefundsService; import com.liquidnet.service.kylin.service.IKylinOrderRefundsService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
* 订单退款表 服务实现类 处理逻辑判断 * 订单退款表 服务实现类 处理逻辑判断
...@@ -29,6 +40,15 @@ public class OrderRefundsCallbackServiceImpl extends ServiceImpl<KylinOrderRefun ...@@ -29,6 +40,15 @@ public class OrderRefundsCallbackServiceImpl extends ServiceImpl<KylinOrderRefun
@Autowired @Autowired
private KylinOrderRefundsMapper kylinOrderRefundsMapper; private KylinOrderRefundsMapper kylinOrderRefundsMapper;
@Autowired
private KylinOrderTicketsMapper kylinOrderTicketsMapper;
@Autowired
private KylinOrderTicketStatusMapper kylinOrderTicketStatusMapper;
@Autowired
private KylinOrderTicketEntitiesMapper kylinOrderTicketEntitiesMapper;
@Autowired @Autowired
MongoTemplate mongoTemplate; MongoTemplate mongoTemplate;
...@@ -67,6 +87,7 @@ public class OrderRefundsCallbackServiceImpl extends ServiceImpl<KylinOrderRefun ...@@ -67,6 +87,7 @@ public class OrderRefundsCallbackServiceImpl extends ServiceImpl<KylinOrderRefun
kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id()); kylinOrderRefunds.setRefundId(refundCallbackParam.getRefund_id());
kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at()); kylinOrderRefunds.setRefundAt(refundCallbackParam.getRefund_at());
kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error()); kylinOrderRefunds.setRefundError(refundCallbackParam.getRefund_error());
kylinOrderRefunds.setUpdatedAt(LocalDateTime.now());
kylinOrderRefundsMapper.update( kylinOrderRefundsMapper.update(
kylinOrderRefunds, kylinOrderRefunds,
...@@ -76,4 +97,35 @@ public class OrderRefundsCallbackServiceImpl extends ServiceImpl<KylinOrderRefun ...@@ -76,4 +97,35 @@ public class OrderRefundsCallbackServiceImpl extends ServiceImpl<KylinOrderRefun
return "success"; return "success";
} }
public Boolean refundApply(String orderTicketsId) {
KylinOrderTickets orderInfo = kylinOrderTicketsMapper.selectOne(
new QueryWrapper<KylinOrderTickets>().eq("order_tickets_id", orderTicketsId)
);
// 查询订单入场人
List<KylinOrderTicketEntities> EntitiesList = kylinOrderTicketEntitiesMapper.selectList(
new QueryWrapper<KylinOrderTicketEntities>()
.eq("order_id", orderTicketsId)
.eq("is_payment", KylinTableStatusConst.ENTITIES_IS_PAYMENT1)
);
List<String> ticketEntityIds = EntitiesList.stream().map(KylinOrderTicketEntities -> KylinOrderTicketEntities.getOrderTicketEntitiesId()).collect(Collectors.toList());
// 该订单正在退款或已有退款
int refundingCount = kylinOrderRefundsMapper.selectRefundingCount(
orderTicketsId,
KylinTableStatusConst.ORDER_REFUND_STATUS_CANCEL,
ticketEntityIds
);
if (refundingCount > 0) {
return false;
}
boolean res = kylinRefundsStatusServiceImpl.orderTicketRefunding(
orderInfo, orderTicketsId, ticketEntityIds
);
if (res) {
return true;
} else {
return false;
}
}
} }
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