diff --git a/src/main/java/com/ai/da/service/CreditsService.java b/src/main/java/com/ai/da/service/CreditsService.java index 1d076527..62d9e5e4 100644 --- a/src/main/java/com/ai/da/service/CreditsService.java +++ b/src/main/java/com/ai/da/service/CreditsService.java @@ -17,9 +17,9 @@ public interface CreditsService extends IService { String getCredits(Long accountId); - void creditsRefund(Long accountId, Integer quantity); + void creditsRefund(Long accountId, Integer quantity, String orderNo); - void insertToCreditsDetail(Long accountId, String changeEvent, String credits, String changeType); + void insertToCreditsDetail(Long accountId, String changeEvent, String credits, String changeType, String orderNo); PageBaseResponse queryCreditsDetailsPage(QueryIncomeOrExpenditureDTO queryPageByTimeDTO); diff --git a/src/main/java/com/ai/da/service/impl/AliPayServiceImpl.java b/src/main/java/com/ai/da/service/impl/AliPayServiceImpl.java index ccbd47d2..04fc8993 100644 --- a/src/main/java/com/ai/da/service/impl/AliPayServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AliPayServiceImpl.java @@ -217,7 +217,8 @@ public class AliPayServiceImpl implements AliPayService { creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(), CreditsEventsEnum.BUY_CREDITS.getName() + "--Alipay", String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), - "positive"); + "positive", + orderByOrderNo.getOrderNo()); } finally { //要主动释放锁 lock.unlock(); @@ -320,7 +321,8 @@ public class AliPayServiceImpl implements AliPayService { creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(), CreditsEventsEnum.BUY_CREDITS.getName() + "--Alipay", String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), - "positive"); + "positive", + orderByOrderNo.getOrderNo()); } } @@ -393,7 +395,7 @@ public class AliPayServiceImpl implements AliPayService { // 更新积分状态 OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo); // creditsService.creditsRefund(orderByOrderNo.getAccountId(), orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue())); - creditsService.creditsRefund(orderByOrderNo.getAccountId(), (int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue()))); + creditsService.creditsRefund(orderByOrderNo.getAccountId(), (int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue())), orderNo); } else { log.info("调用失败,返回码 ===> " + response.getCode() + ", 返回描述 ===> " + response.getMsg()); diff --git a/src/main/java/com/ai/da/service/impl/AlipayHKServiceImpl.java b/src/main/java/com/ai/da/service/impl/AlipayHKServiceImpl.java index f20d7350..417a03bd 100644 --- a/src/main/java/com/ai/da/service/impl/AlipayHKServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AlipayHKServiceImpl.java @@ -248,7 +248,8 @@ public class AlipayHKServiceImpl implements AlipayHKService { creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(), CreditsEventsEnum.BUY_CREDITS.getName() + "--AlipayHK", String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), - "positive"); + "positive", + orderByOrderNo.getOrderNo()); log.info("用户:{} 积分信息更新成功",orderByOrderNo.getAccountId()); } finally { //要主动释放锁 diff --git a/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java b/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java index 9cc17ce8..5c24211c 100644 --- a/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CreditsServiceImpl.java @@ -100,7 +100,7 @@ public class CreditsServiceImpl extends ServiceImpl增 negative->减 */ @Override - public void insertToCreditsDetail(Long accountId, String changeEvent, String credits, String changeType) { + public void insertToCreditsDetail(Long accountId, String changeEvent, String credits, String changeType, String orderNo) { CreditsDetail creditsDetail = new CreditsDetail(); Account account = accountMapper.selectById(accountId); // BigDecimal finalCredits; @@ -137,6 +137,7 @@ public class CreditsServiceImpl extends ServiceImpl i if (b) creditsService.insertToCreditsDetail(accountId, CreditsEventsEnum.TO_PRODUCT_IMAGE.getName(), CreditsEventsEnum.TO_PRODUCT_IMAGE.getValue(), - "negative"); + "negative", null); } } @@ -736,7 +736,7 @@ public class GenerateServiceImpl extends ServiceImpl i if (b) creditsService.insertToCreditsDetail(accountId, CreditsEventsEnum.RELIGHT.getName(), CreditsEventsEnum.RELIGHT.getValue(), - "negative"); + "negative", null); } } diff --git a/src/main/java/com/ai/da/service/impl/PayPalCheckoutServiceImpl.java b/src/main/java/com/ai/da/service/impl/PayPalCheckoutServiceImpl.java index 22c57621..fb5d5409 100644 --- a/src/main/java/com/ai/da/service/impl/PayPalCheckoutServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/PayPalCheckoutServiceImpl.java @@ -441,11 +441,11 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService { * 申请退款 */ @Transactional(rollbackFor = Exception.class) - public Boolean refundOrder(String orderId, String reason) throws IOException { + public Boolean refundOrder(String orderNo, String reason) throws IOException { - RefundInfo refundByOrderNo = refundsInfoService.createRefundByOrderNo(orderId, reason); + RefundInfo refundByOrderNo = refundsInfoService.createRefundByOrderNo(orderNo, reason); - OrdersGetRequest ordersGetRequest = new OrdersGetRequest(orderId); + OrdersGetRequest ordersGetRequest = new OrdersGetRequest(orderNo); PayPalClient payPalClient = new PayPalClient(); HttpResponse ordersGetResponse = null; ordersGetRequest.authorization("Bearer " + getOAuth()); @@ -461,7 +461,7 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService { request.authorization("Bearer " + getOAuth()); request.prefer("return=representation"); - OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderId); + OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderNo); request.requestBody(buildRefundRequestBody(String.valueOf(orderInfo.getTotalFee()), reason)); HttpResponse response = null; try { @@ -476,7 +476,7 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService { //进行数据库操作,修改状态为已退款(配合回调和退款查询确定退款成功) //更新订单状态 - orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.REFUND_SUCCESS); + orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.REFUND_SUCCESS); refundsInfoService.updateRefundForPayPal( refundByOrderNo.getId(), @@ -485,14 +485,14 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService { AliPayTradeStateEnum.REFUND_SUCCESS.getType()); //退款成功 // 更新积分状态 - OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderId); + OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo); // creditsService.creditsRefund(orderByOrderNo.getAccountId(), orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue())); - creditsService.creditsRefund(orderByOrderNo.getAccountId(), (int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue()))); + creditsService.creditsRefund(orderByOrderNo.getAccountId(), (int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue())), orderNo); log.info("退款成功"); result = Boolean.TRUE; } else { //更新订单状态 - orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.REFUND_ABNORMAL); + orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.REFUND_ABNORMAL); //更新退款单 refundsInfoService.updateRefundForPayPal( @@ -571,19 +571,19 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService { // 处理当前订单 @Transactional(rollbackFor = Exception.class) - public void processOrder(String orderId) { + public void processOrder(String orderNo) { // 1、确定当前订单是否已经被扣款 - OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderId); + OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderNo); if (orderInfo.getOrderStatus().equals(OrderStatusEnum.SUCCESS.getType())) { // 直接返回 return; } // 发起扣款请求 - Order capturedOrder = captureOrder(orderId); + Order capturedOrder = captureOrder(orderNo); // 业务处理 if (PayPalOrderStatusEnum.COMPLETED.getStatus().equals(capturedOrder.status())) { //更新订单状态 - orderInfoService.updateStatusByOrderNo(orderId, OrderStatusEnum.SUCCESS); + orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.SUCCESS); //记录支付日志 paymentInfoService.createPaymentInfoForPayPal(capturedOrder); float quantity = orderInfo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue()); @@ -593,7 +593,7 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService { creditsService.insertToCreditsDetail(orderInfo.getAccountId(), CreditsEventsEnum.BUY_CREDITS.getName() + "--PayPal", String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), - "positive"); + "positive", orderNo); } } @@ -637,7 +637,7 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService { creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(), CreditsEventsEnum.BUY_CREDITS.getName() + "--Paypal", String.valueOf((Long.parseLong(CreditsEventsEnum.BUY_CREDITS.getValue()) * quantity)), - "positive"); + "positive", orderNo); } } diff --git a/src/main/java/com/ai/da/service/impl/PaymentInfoServiceImpl.java b/src/main/java/com/ai/da/service/impl/PaymentInfoServiceImpl.java index 035e1135..36acae75 100644 --- a/src/main/java/com/ai/da/service/impl/PaymentInfoServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/PaymentInfoServiceImpl.java @@ -187,10 +187,15 @@ public class PaymentInfoServiceImpl extends ServiceImpl resp = new HashMap<>(); + resp.put("paymentMethod", null); + resp.put("last4", null); + return resp; } catch (StripeException e) { throw new RuntimeException(e); } @@ -668,15 +684,15 @@ public class StripeServiceImpl implements StripeService { return false; } PaymentInfo paymentInfo = paymentInfos.get(0); - if (paymentInfo.getNotified() == 1){ - // 已经邮件通知过,直接返回 - return true; - } if (StringUtil.isNullOrEmpty(type)){ // 如果没有传入type,则使用paymentInfo中记录的类型 // (其实这里也可以通过invoiceId查询stripe,但是记录在自己的db中可以不用每次都查,且方便查看) type = paymentInfo.getType(); } + if (!type.equals("reminder") && paymentInfo.getNotified() == 1){ + // 已经邮件通知过,直接返回 + return true; + } com.ai.da.mapper.primary.entity.Account account = accountMapper.selectById(subscriptionInfo.getAccountId()); String userName = account.getUserName(); @@ -692,18 +708,20 @@ public class StripeServiceImpl implements StripeService { emailParamsDTO.setPaymentMethod(subscriptionInfo.getPaymentMethod()); emailParamsDTO.setSubscriptionId(subscriptionInfo.getId().toString()); emailParamsDTO.setSubscriptionType(subscriptionInfo.getType()); - emailParamsDTO.setStartDate(changeTimeStampFormat(subscriptionInfo.getCurrentPeriodStart(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy)); + emailParamsDTO.setStartDate(changeTimeStampFormat(subscriptionInfo.getCreateTime())); emailParamsDTO.setNextPayDate(changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy)); emailParamsDTO.setRenewalTime(changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_MMM_dd_yyyy)); SendEmailUtil.subscriptionEmailReminder(type, emailParamsDTO, language, account.getUserEmail()); // 邮件通知成功后,更新标志 - PaymentInfo payment = new PaymentInfo(); - payment.setId(paymentInfo.getId()); - payment.setNotified(1); - payment.setUpdateTime(LocalDateTime.now()); - paymentInfoMapper.updateById(payment); + if (!type.equals("reminder")){ + PaymentInfo payment = new PaymentInfo(); + payment.setId(paymentInfo.getId()); + payment.setNotified(1); + payment.setUpdateTime(LocalDateTime.now()); + paymentInfoMapper.updateById(payment); + } return true; } @@ -723,7 +741,7 @@ public class StripeServiceImpl implements StripeService { List subscriptionInfos = subscriptionInfoMapper.selectList(qw); for (SubscriptionInfo subscriptionInfo : subscriptionInfos) { - boolean b = sendEmail(subscriptionInfo.getSubscriptionId(), null); + boolean b = sendEmail(subscriptionInfo.getSubscriptionId(), "reminder"); if (b) log.info("提前7天向用户 {} 发送续订通知邮件", subscriptionInfo.getAccountId()); } } diff --git a/src/main/java/com/ai/da/service/impl/SuperResolutionServiceImpl.java b/src/main/java/com/ai/da/service/impl/SuperResolutionServiceImpl.java index 03ed3d69..eda65b46 100644 --- a/src/main/java/com/ai/da/service/impl/SuperResolutionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/SuperResolutionServiceImpl.java @@ -149,7 +149,7 @@ public class SuperResolutionServiceImpl extends ServiceImpl