瀏覽代碼

fix 订单退款情况变更

zoujiajian 3 年之前
父節點
當前提交
56ff4cf36f

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/views/OrderDonView.java

@@ -60,6 +60,9 @@ public class OrderDonView {
     @DbField("sku.spec_val")
     private String specVal;
 
+    @DbField("sku.months")
+    private Integer months;
+
     @DbField("u.id")
     private Long userId;
 

+ 80 - 18
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -54,6 +54,7 @@ import com.cyksj.service.mange.stock.GoodsDonStockService;
 import com.cyksj.service.order.OrderDonService;
 import com.cyksj.service.wechat.WeChatService;
 import com.cyksj.task.JobManager;
+import com.cyksj.task.OrderCustomerHandleScheduler;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapUtils;
@@ -730,7 +731,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			throw BusinessRuntimeException.getInstance("该订单不是微信支付的订单");
 		}
 		//校验订单是否符合退款
-		checkOrderRefund(orderDon, goodsDon);
+		checkOrderRefund(orderDon, goodsDon, sku);
 		if (wxOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
 			throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
 		}
@@ -767,7 +768,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
 		});
 		//虚物订单退款,清出车队,车票变为已过期
-		clearUnrealGoodsDetail(orderDon, goodsDon);
+		clearUnrealGoodsDetail(orderDon, goodsDon, sku);
 		//若存在优惠券使用,退还优惠券
 		if (orderDon.getCouponUserId() != 0) {
 			redisService.set(String.format("%s-%s", orderDon.getId(), orderDon.getCouponUserId()), orderDon.getId(), 120l);
@@ -789,7 +790,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			throw BusinessRuntimeException.getInstance("该订单不是支付宝支付的订单");
 		}
 		//校验订单是否符合退款
-		checkOrderRefund(orderDon, goodsDon);
+		checkOrderRefund(orderDon, goodsDon, sku);
 		if (zfbOrderRefundReq.getRefundMoney().compareTo(orderDon.getMoney()) > 0) {
 			throw BusinessRuntimeException.getInstance("退款金额大于订单金额");
 		}
@@ -843,7 +844,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				goodsDonStockService.upStockRelate(null, orderDon.getId(),"refund");
 			});
 			//虚物订单退款,清出车队,车票变为已过期
-			clearUnrealGoodsDetail(orderDon, goodsDon);
+			clearUnrealGoodsDetail(orderDon, goodsDon, sku);
 			if (orderDon.getCouponUserId() != 0) {
 				//zfb订单退款,返还优惠券
 				updateOrderDonCouponStatus(orderDon);
@@ -858,16 +859,53 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 	 * @param orderDon
 	 * @param goodsDon
 	 */
-	private void clearUnrealGoodsDetail(OrderDon orderDon, GoodsDon goodsDon) {
+	private void clearUnrealGoodsDetail(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
 		if (goodsDon != null && goodsDon.getType() == 1) {
 			//清出车队,车位变为已过期
 			Long relationId = orderDon.getRelationId();
+			Integer months = sku.getMonths();
+			Integer num = orderDon.getNum();
+			DateTime now = DateTime.now();
 			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) {
-				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);
+					}
+				}
 			}
 		}
 	}
@@ -876,7 +914,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 	 * 校验订单是否符合退款操作
 	 * @param orderDon
 	 */
-	private void checkOrderRefund(OrderDon orderDon, GoodsDon goodsDon) {
+	private void checkOrderRefund(OrderDon orderDon,GoodsDon goodsDon, GoodsDonSku sku) {
 		if (orderDon == null) {
 			throw BusinessRuntimeException.getInstance("订单不存在");
 		}
@@ -889,16 +927,40 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		if (OrderDon.Status.noPayment == orderDon.getStatus() || OrderDon.Status.close == 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("该虚物订单已过退款时间");
+//			}
+//		}
 	}
 
 	/**