|
@@ -57,6 +57,7 @@ import com.cyksj.service.market.task.TaskService;
|
|
|
import com.cyksj.service.order.OrderDonService;
|
|
import com.cyksj.service.order.OrderDonService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.task.JobManager;
|
|
import com.cyksj.task.JobManager;
|
|
|
|
|
+import com.cyksj.task.OrderCustomerHandleScheduler;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
@@ -156,6 +157,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
|
|
private final TaskTypeMapper taskTypeMapper;
|
|
private final TaskTypeMapper taskTypeMapper;
|
|
|
|
|
|
|
|
|
|
+ private final CustomerServiceRenewOrderRecordMapper customerServiceRenewOrderRecordMapper;
|
|
|
|
|
+
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@Override
|
|
@Override
|
|
|
public OrderDon submit(OrderPayRequest payRequest) throws Exception {
|
|
public OrderDon submit(OrderPayRequest payRequest) throws Exception {
|
|
@@ -430,6 +433,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//无车队,新增车队
|
|
//无车队,新增车队
|
|
|
checkNoGroupsTripsAndSendMsg(sku, order);
|
|
checkNoGroupsTripsAndSendMsg(sku, order);
|
|
|
}
|
|
}
|
|
|
|
|
+ //客服续费订单
|
|
|
|
|
+ handleServiceRenewOrder(order);
|
|
|
//完成任务
|
|
//完成任务
|
|
|
TASK_POOL.execute(() -> {
|
|
TASK_POOL.execute(() -> {
|
|
|
TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
@@ -686,6 +691,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (null == orderDon) {
|
|
if (null == orderDon) {
|
|
|
throw BusinessRuntimeException.getInstance("订单不存在.");
|
|
throw BusinessRuntimeException.getInstance("订单不存在.");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (orderDon.getPopularizeId() == null) {
|
|
|
|
|
+ orderDon.setShopId(null);
|
|
|
|
|
+ }
|
|
|
boolean signVerified = AlipaySignature.rsaCheckV1(params,shopConfigMapper.getByAppId((Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.ZFB_DEFAULT_APP_ID))).getPublicKey(), BaseZfbConfig.charset, BaseZfbConfig.signType);
|
|
boolean signVerified = AlipaySignature.rsaCheckV1(params,shopConfigMapper.getByAppId((Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.ZFB_DEFAULT_APP_ID))).getPublicKey(), BaseZfbConfig.charset, BaseZfbConfig.signType);
|
|
|
if (!signVerified) {
|
|
if (!signVerified) {
|
|
|
log.error("支付宝回调校验签名错误,自定义入参:{}", params.get("body"));
|
|
log.error("支付宝回调校验签名错误,自定义入参:{}", params.get("body"));
|
|
@@ -719,6 +727,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//无车队,新增车队
|
|
//无车队,新增车队
|
|
|
checkNoGroupsTripsAndSendMsg(sku, orderDon);
|
|
checkNoGroupsTripsAndSendMsg(sku, orderDon);
|
|
|
}
|
|
}
|
|
|
|
|
+ //客服续费订单
|
|
|
|
|
+ handleServiceRenewOrder(orderDon);
|
|
|
//完成任务
|
|
//完成任务
|
|
|
TASK_POOL.execute(() -> {
|
|
TASK_POOL.execute(() -> {
|
|
|
TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
@@ -740,7 +750,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw BusinessRuntimeException.getInstance("该订单不是微信支付的订单");
|
|
throw BusinessRuntimeException.getInstance("该订单不是微信支付的订单");
|
|
|
}
|
|
}
|
|
|
//校验订单是否符合退款
|
|
//校验订单是否符合退款
|
|
|
- checkOrderRefund(orderDon, goodsDon);
|
|
|
|
|
|
|
+ checkOrderRefund(orderDon, goodsDon, sku);
|
|
|
if (wxOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
|
|
if (wxOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
|
|
throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
|
|
|
}
|
|
}
|
|
@@ -777,7 +787,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
|
|
goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
|
|
|
});
|
|
});
|
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
|
- clearUnrealGoodsDetail(orderDon, goodsDon);
|
|
|
|
|
|
|
+ clearUnrealGoodsDetail(orderDon, goodsDon, sku);
|
|
|
//若存在优惠券使用,退还优惠券
|
|
//若存在优惠券使用,退还优惠券
|
|
|
if (orderDon.getCouponUserId() != 0) {
|
|
if (orderDon.getCouponUserId() != 0) {
|
|
|
redisService.set(String.format("%s-%s", orderDon.getId(), orderDon.getCouponUserId()), orderDon.getId(), 120l);
|
|
redisService.set(String.format("%s-%s", orderDon.getId(), orderDon.getCouponUserId()), orderDon.getId(), 120l);
|
|
@@ -799,7 +809,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw BusinessRuntimeException.getInstance("该订单不是支付宝支付的订单");
|
|
throw BusinessRuntimeException.getInstance("该订单不是支付宝支付的订单");
|
|
|
}
|
|
}
|
|
|
//校验订单是否符合退款
|
|
//校验订单是否符合退款
|
|
|
- checkOrderRefund(orderDon, goodsDon);
|
|
|
|
|
|
|
+ checkOrderRefund(orderDon, goodsDon, sku);
|
|
|
if (zfbOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
|
|
if (zfbOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
|
|
throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
|
|
|
}
|
|
}
|
|
@@ -812,6 +822,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
}
|
|
|
String outRefundNo = "";
|
|
String outRefundNo = "";
|
|
|
if (OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
if (OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
|
|
+ if (orderDon.getPopularizeId() == null) {
|
|
|
|
|
+ orderDon.setShopId(null);
|
|
|
|
|
+ }
|
|
|
//支付宝退款
|
|
//支付宝退款
|
|
|
AlipayClient alipayClient = AliPayCommon.getAlipayClient(shopConfigMapper.getByAppId(Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.ZFB_DEFAULT_APP_ID)));
|
|
AlipayClient alipayClient = AliPayCommon.getAlipayClient(shopConfigMapper.getByAppId(Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.ZFB_DEFAULT_APP_ID)));
|
|
|
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
@@ -850,7 +863,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
|
|
goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
|
|
|
});
|
|
});
|
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
|
- clearUnrealGoodsDetail(orderDon, goodsDon);
|
|
|
|
|
|
|
+ clearUnrealGoodsDetail(orderDon, goodsDon, sku);
|
|
|
if (orderDon.getCouponUserId() != 0) {
|
|
if (orderDon.getCouponUserId() != 0) {
|
|
|
//zfb订单退款,返还优惠券
|
|
//zfb订单退款,返还优惠券
|
|
|
updateOrderDonCouponStatus(orderDon);
|
|
updateOrderDonCouponStatus(orderDon);
|
|
@@ -865,16 +878,53 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
* @param orderDon
|
|
* @param orderDon
|
|
|
* @param goodsDon
|
|
* @param goodsDon
|
|
|
*/
|
|
*/
|
|
|
- private void clearUnrealGoodsDetail(OrderDon orderDon, GoodsDon goodsDon) {
|
|
|
|
|
|
|
+ private void clearUnrealGoodsDetail(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
|
|
|
if (goodsDon != null && goodsDon.getType() == 1) {
|
|
if (goodsDon != null && goodsDon.getType() == 1) {
|
|
|
//清出车队,车位变为已过期
|
|
//清出车队,车位变为已过期
|
|
|
Long relationId = orderDon.getRelationId();
|
|
Long relationId = orderDon.getRelationId();
|
|
|
|
|
+ Integer months = sku.getMonths();
|
|
|
|
|
+ Integer num = orderDon.getNum();
|
|
|
|
|
+ DateTime now = DateTime.now();
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
|
|
+ Date expiryTime = relation.getExpiryTime();
|
|
|
|
|
+ Boolean isFlag = true;
|
|
|
|
|
+ if (orderDon.getOrderType() == 2) {
|
|
|
|
|
+ //是否有其他付款订单是否过期
|
|
|
|
|
+ OrderDon otherOrder = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
|
|
+ .eq(OrderDon::getRelationId, relationId)
|
|
|
|
|
+ .eq(OrderDon::getUserId, orderDon.getUserId())
|
|
|
|
|
+ .ne(OrderDon::getId, orderDon.getId())
|
|
|
|
|
+ .notIn(OrderDon::getStatus, OrderCustomerHandleScheduler.noOrderStatus)
|
|
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (otherOrder != null) {
|
|
|
|
|
+ DateTime endTime = DateUtil.offsetMonth(otherOrder.getCreatedTime(), months * num);
|
|
|
|
|
+ if (now.isBefore(endTime)) {
|
|
|
|
|
+ isFlag = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (relation != null) {
|
|
if (relation != null) {
|
|
|
- relation.setUserId(0l);
|
|
|
|
|
- relation.setStatus(GroupsRelation.Status.none);
|
|
|
|
|
- groupsRelationMapper.updateById(relation);
|
|
|
|
|
- delRelation(relation.getId());
|
|
|
|
|
|
|
+ if (isFlag) {
|
|
|
|
|
+ relation.setUserId(0l);
|
|
|
|
|
+ relation.setStatus(GroupsRelation.Status.none);
|
|
|
|
|
+ if (expiryTime != null) {
|
|
|
|
|
+ relation.setStartTime(null);
|
|
|
|
|
+ relation.setExpiryTime(null);
|
|
|
|
|
+ relation.setIsHandle(false);
|
|
|
|
|
+ relation.setRenewStatus(false);
|
|
|
|
|
+ relation.setAccount(null);
|
|
|
|
|
+ groupsRelationMapper.updateExpiryTime(relation, expiryTime);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
|
|
+ }
|
|
|
|
|
+ delRelation(relation.getId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (expiryTime != null) {
|
|
|
|
|
+ relation.setExpiryTime(DateUtil.offsetMonth(expiryTime, -months * num));
|
|
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -883,7 +933,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
* 校验订单是否符合退款操作
|
|
* 校验订单是否符合退款操作
|
|
|
* @param orderDon
|
|
* @param orderDon
|
|
|
*/
|
|
*/
|
|
|
- private void checkOrderRefund(OrderDon orderDon, GoodsDon goodsDon) {
|
|
|
|
|
|
|
+ private void checkOrderRefund(OrderDon orderDon,GoodsDon goodsDon, GoodsDonSku sku) {
|
|
|
if (orderDon == null) {
|
|
if (orderDon == null) {
|
|
|
throw BusinessRuntimeException.getInstance("订单不存在");
|
|
throw BusinessRuntimeException.getInstance("订单不存在");
|
|
|
}
|
|
}
|
|
@@ -896,16 +946,40 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (OrderDon.Status.noPayment == orderDon.getStatus() || OrderDon.Status.close == orderDon.getStatus()) {
|
|
if (OrderDon.Status.noPayment == orderDon.getStatus() || OrderDon.Status.close == orderDon.getStatus()) {
|
|
|
throw BusinessRuntimeException.getInstance("订单{0}状态不支持退款", orderDon.getStatus());
|
|
throw BusinessRuntimeException.getInstance("订单{0}状态不支持退款", orderDon.getStatus());
|
|
|
}
|
|
}
|
|
|
- //续费订单
|
|
|
|
|
- if (orderDon.getOrderType() == 2 && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("续费订单不支持退款");
|
|
|
|
|
- }
|
|
|
|
|
- if (goodsDon != null && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
|
|
- //虚物订单 7天内可退款
|
|
|
|
|
- if (goodsDon.getType() == 1 && DateTime.now().isAfter(DateUtil.offsetDay(orderDon.getPayTime(), 7))) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("该虚物订单已过退款时间");
|
|
|
|
|
|
|
+ if (goodsDon.getType() == 1) {
|
|
|
|
|
+ //虚拟原订单是否已过期
|
|
|
|
|
+ Integer months = sku.getMonths();
|
|
|
|
|
+ Integer num = orderDon.getNum();
|
|
|
|
|
+ DateTime now = DateTime.now();
|
|
|
|
|
+ DateTime endTime = DateUtil.offsetMonth(orderDon.getCreatedTime(), months * num);
|
|
|
|
|
+ if (now.isAfter(endTime)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该订单车票已过期");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (orderDon.getOrderType() == 1) {
|
|
|
|
|
+ //是否有其他付款订单是否过期
|
|
|
|
|
+ OrderDon otherOrder = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
|
|
+ .eq(OrderDon::getRelationId, orderDon.getRelationId())
|
|
|
|
|
+ .eq(OrderDon::getUserId, orderDon.getUserId())
|
|
|
|
|
+ .ne(OrderDon::getId, orderDon.getId())
|
|
|
|
|
+ .notIn(OrderDon::getStatus, OrderCustomerHandleScheduler.noOrderStatus)
|
|
|
|
|
+ .eq(OrderDon::getOrderType, 2)
|
|
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (otherOrder != null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该笔订单存在续费订单,请先退掉续费订单");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //续费订单
|
|
|
|
|
+// if (orderDon.getOrderType() == 2 && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
|
|
+// throw BusinessRuntimeException.getInstance("续费订单不支持退款");
|
|
|
|
|
+// }
|
|
|
|
|
+// if (goodsDon != null && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
|
|
+// //虚物订单 7天内可退款
|
|
|
|
|
+// if (goodsDon.getType() == 1 && DateTime.now().isAfter(DateUtil.offsetDay(orderDon.getPayTime(), 7))) {
|
|
|
|
|
+// throw BusinessRuntimeException.getInstance("该虚物订单已过退款时间");
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1398,4 +1472,22 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
}
|
|
|
return relation;
|
|
return relation;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void handleServiceRenewOrder(OrderDon orderDon) {
|
|
|
|
|
+ //续费订单
|
|
|
|
|
+ if (orderDon.getOrderType() == 2) {
|
|
|
|
|
+ Long relationId = orderDon.getRelationId();
|
|
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
|
|
+ if (StrUtil.isNotBlank(relation.getCustomerService())) {
|
|
|
|
|
+ //记录客服续费订单业绩
|
|
|
|
|
+ CustomerServiceRenewOrderRecord renewOrderRecord = new CustomerServiceRenewOrderRecord();
|
|
|
|
|
+ renewOrderRecord.setUserId(orderDon.getUserId());
|
|
|
|
|
+ renewOrderRecord.setOrderId(orderDon.getId());
|
|
|
|
|
+ renewOrderRecord.setCustomerService(relation.getCustomerService());
|
|
|
|
|
+ customerServiceRenewOrderRecordMapper.insert(renewOrderRecord);
|
|
|
|
|
+
|
|
|
|
|
+ groupsRelationMapper.updateCustomerService(relation.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|