Ver código fonte

fix codex包月订单1周后可开票

zoujiajian 1 mês atrás
pai
commit
90d45c5a4e

+ 19 - 2
netflix-service/src/main/java/com/cyksj/service/invoice/impl/UserInvoiceApplyRecordServiceImpl.java

@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -53,6 +54,8 @@ public class UserInvoiceApplyRecordServiceImpl implements UserInvoiceApplyRecord
 
 	private final VipOrderDonMapper vipOrderDonMapper;
 
+	private static final long CODEX_INVOICE_WAIT_MILLIS = 7 * Constant.DAY_MILLS;
+
 	@Override
 	@Transactional(rollbackFor = Throwable.class)
 	public Long applyOrderInvoice(UserInvoiceOrderReq req) {
@@ -95,8 +98,10 @@ public class UserInvoiceApplyRecordServiceImpl implements UserInvoiceApplyRecord
 							.in(OrderDon::getId, orderIds)
 							.in(OrderDon::getUserId, userIdList)
 							.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-							.select(OrderDon::getId, OrderDon::getMoney, OrderDon::getShopId));
+							.select(OrderDon::getId, OrderDon::getMoney, OrderDon::getShopId,
+									OrderDon::getGoodsId, OrderDon::getPayTime, OrderDon::getCreatedTime));
 					for (OrderDon o : orderDonList) {
+						checkCodexInvoiceTime(o.getGoodsId(), o.getPayTime(), o.getCreatedTime());
 						invoiceApplyRecord.setMoney(invoiceApplyRecord.getMoney().add(o.getMoney()));
 						shopIdSet.add(o.getShopId());
 					}
@@ -106,8 +111,10 @@ public class UserInvoiceApplyRecordServiceImpl implements UserInvoiceApplyRecord
 							.in(UpgradeOrderDon::getId, orderIds)
 							.in(UpgradeOrderDon::getUserId, userIdList)
 							.notIn(UpgradeOrderDon::getStatus, Constant.noOrderAllStatus)
-							.select(UpgradeOrderDon::getId, UpgradeOrderDon::getMoney, UpgradeOrderDon::getShopId));
+							.select(UpgradeOrderDon::getId, UpgradeOrderDon::getMoney, UpgradeOrderDon::getShopId,
+									UpgradeOrderDon::getGoodsId, UpgradeOrderDon::getPayTime, UpgradeOrderDon::getCreatedTime));
 					for (UpgradeOrderDon o : upgradeOrderDons) {
+						checkCodexInvoiceTime(o.getGoodsId(), o.getPayTime(), o.getCreatedTime());
 						invoiceApplyRecord.setMoney(invoiceApplyRecord.getMoney().add(o.getMoney()));
 						shopIdSet.add(o.getShopId());
 					}
@@ -160,4 +167,14 @@ public class UserInvoiceApplyRecordServiceImpl implements UserInvoiceApplyRecord
 			redisService.del(key);
 		}
 	}
+
+	private void checkCodexInvoiceTime(Long goodsId, Date payTime, Date createdTime) {
+		if (!Constant.CODEX_GOODS_ID.equals(goodsId)) {
+			return;
+		}
+		Date purchaseTime = payTime == null ? createdTime : payTime;
+		if (purchaseTime == null || System.currentTimeMillis() - purchaseTime.getTime() < CODEX_INVOICE_WAIT_MILLIS) {
+			throw BusinessRuntimeException.getInstance("Codex包月API订单购买满7天后才可申请开票");
+		}
+	}
 }

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/invoice/UserInvoiceFrontController.java

@@ -92,7 +92,7 @@ public class UserInvoiceFrontController {
 		List<UserInvoiceChoseOrderViews> list = new ArrayList<>();
 		if (orderCount > 0) {
 			//普通订单
-			String order_sql = "(select id,goods_id,sku_id,order_no,money,user_id,pay_time,shop_id,created_time,1 as type from order_don where money > 0 and status not in ('close','noPayment','refund') and type = 'ALI_PAY')";
+			String order_sql = String.format("(select id,goods_id,sku_id,order_no,money,user_id,pay_time,shop_id,created_time,1 as type from order_don where money > 0 and status not in ('close','noPayment','refund') and type = 'ALI_PAY' and (goods_id <> %d or ifnull(pay_time,created_time) <= date_sub(now(), interval 7 day)))", Constant.CODEX_GOODS_ID);
 			List<UserInvoiceChoseOrderViews> orderViewsList = beanSearcher.searchAll(UserInvoiceChoseOrderViews.class, builder.put("order", order_sql).build());
 			if (CollUtil.isNotEmpty(orderViewsList)) {
 				list.addAll(orderViewsList);
@@ -104,7 +104,7 @@ public class UserInvoiceFrontController {
 		if (upgradeOrders > 0) {
 			List<Long> goodsIds = upgradeOrderDonMapper.selectUpgradeDistinctGoodsId(userIdList);
 			//增值订单
-			String upgrade_order_sql = String.format("(select id,goods_id,sku_id,order_no,money,user_id,pay_time,shop_id,created_time,2 as type from upgrade_order_don where goods_id in (%s) and money > 0 and status not in ('close','noPayment','refund') and type = 'ALI_PAY')", goodsIds.stream().map(v -> v.toString()).collect(Collectors.joining(",")));
+			String upgrade_order_sql = String.format("(select id,goods_id,sku_id,order_no,money,user_id,pay_time,shop_id,created_time,2 as type from upgrade_order_don where goods_id in (%s) and money > 0 and status not in ('close','noPayment','refund') and type = 'ALI_PAY' and (goods_id <> %d or ifnull(pay_time,created_time) <= date_sub(now(), interval 7 day)))", goodsIds.stream().map(v -> v.toString()).collect(Collectors.joining(",")), Constant.CODEX_GOODS_ID);
 			List<UserInvoiceChoseOrderViews> upgradeOrderList = beanSearcher.searchAll(UserInvoiceChoseOrderViews.class, builder.put("order", upgrade_order_sql).build());
 			if (CollUtil.isNotEmpty(upgradeOrderList)) {
 				list.addAll(upgradeOrderList);