Преглед на файлове

发票字段内容调整&邮件模板调整

wangpenghui преди 10 месеца
родител
ревизия
03078c3fb6
променени са 23 файла, в които са добавени 526 реда и са изтрити 38 реда
  1. 2 2
      background-user/src/main/java/cn/kdan/compdf/controller/v1/BackgroundUserBalanceController.java
  2. 4 0
      background-user/src/main/java/cn/kdan/compdf/dto/BillSendEmailDTO.java
  3. 8 5
      background-user/src/main/java/cn/kdan/compdf/entity/OrderCashFlow.java
  4. 7 4
      background-user/src/main/java/cn/kdan/compdf/entity/Orders.java
  5. 122 0
      background-user/src/main/java/cn/kdan/compdf/entity/OrdersGoods.java
  6. 4 0
      background-user/src/main/java/cn/kdan/compdf/entity/dto/DashboardQueryDTO.java
  7. 3 0
      background-user/src/main/java/cn/kdan/compdf/mapper/OrderCashFlowMapper.java
  8. 11 0
      background-user/src/main/java/cn/kdan/compdf/mapper/OrdersGoodsMapper.java
  9. 1 1
      background-user/src/main/java/cn/kdan/compdf/service/BackgroundUserBalanceService.java
  10. 3 0
      background-user/src/main/java/cn/kdan/compdf/service/OrderCashFlowService.java
  11. 13 0
      background-user/src/main/java/cn/kdan/compdf/service/OrdersGoodsService.java
  12. 16 6
      background-user/src/main/java/cn/kdan/compdf/service/impl/BackgroundConvertDataServiceImpl.java
  13. 32 2
      background-user/src/main/java/cn/kdan/compdf/service/impl/BackgroundUserBalanceServiceImpl.java
  14. 25 3
      background-user/src/main/java/cn/kdan/compdf/service/impl/OrderCashFlowServiceImpl.java
  15. 16 0
      background-user/src/main/java/cn/kdan/compdf/service/impl/OrdersGoodsServiceImpl.java
  16. 1 0
      background-user/src/main/java/cn/kdan/compdf/service/impl/OrdersServiceImpl.java
  17. 113 12
      background-user/src/main/java/cn/kdan/compdf/service/impl/UserBillingInformationServiceImpl.java
  18. 45 0
      background-user/src/main/java/cn/kdan/compdf/vo/BillingInfoVO.java
  19. 28 0
      background-user/src/main/java/cn/kdan/compdf/vo/OrderBillingInfoVO.java
  20. 2 2
      background-user/src/main/java/cn/kdan/compdf/vo/UserBillingInfoVO.java
  21. 19 0
      background-user/src/main/resources/mapper/OrderCashFlowMapper.xml
  22. 35 0
      background-user/src/main/resources/mapper/OrdersGoodsMapper.xml
  23. 16 1
      background-user/src/main/resources/templates/invoice.html

+ 2 - 2
background-user/src/main/java/cn/kdan/compdf/controller/v1/BackgroundUserBalanceController.java

@@ -56,11 +56,11 @@ public class BackgroundUserBalanceController {
      * 账户消费充值记录导出
      */
     @GetMapping("/exportBalanceRecordList")
-    public void exportBalanceRecordList(Integer isDecs,Integer timeZone,HttpServletResponse response) {
+    public void exportBalanceRecordList(Integer isDecs,Integer timeZone,Boolean isCN,HttpServletResponse response) {
         if (ObjectUtil.isEmpty(isDecs)) {
             isDecs = 1;
         }
-        backgroundUserBalanceService.exportBalanceRecordList(timeZone,isDecs,TokenUtil.getRequestHeader().getId(), response);
+        backgroundUserBalanceService.exportBalanceRecordList(timeZone,isDecs,TokenUtil.getRequestHeader().getId(),isCN, response);
     }
 
 

+ 4 - 0
background-user/src/main/java/cn/kdan/compdf/dto/BillSendEmailDTO.java

@@ -16,5 +16,9 @@ public class BillSendEmailDTO {
     private Integer orderId;
     @NotEmpty(message = "email不能为空")
     private String email;
+    /**
+     * true:中文 false:英文
+     */
+    private Boolean isCN;
 
 }

+ 8 - 5
background-user/src/main/java/cn/kdan/compdf/entity/OrderCashFlow.java

@@ -4,9 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
-
-import java.math.BigDecimal;
 import java.util.Date;
+import java.math.BigDecimal;
 
 /**
  * @author ComPDFKit-WPH 2023-05-25
@@ -27,13 +26,13 @@ public class OrderCashFlow {
     /**
      * 订单id
      */
-    private Integer orderId;
+    private Integer orderGoodsId;
     /**
-     * 支付类型:1 PayPal,2 paddle,3 wxpay,4 alipay
+     * 1paddle支付 2支付宝 3微信 4其他支付 5paypal
      */
     private Integer payType;
     /**
-     * 交易类型:1 付款,2 订阅
+     * 交易类型:1 订阅 2 package
      */
     private Integer tradeType;
     /**
@@ -88,5 +87,9 @@ public class OrderCashFlow {
      * 0正常1已删除
      */
     private Integer delFlag;
+    /**
+     * 期数
+     */
+    private Integer period;
 
 }

+ 7 - 4
background-user/src/main/java/cn/kdan/compdf/entity/Orders.java

@@ -5,12 +5,11 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
-
-import java.math.BigDecimal;
 import java.util.Date;
+import java.math.BigDecimal;
 
 /**
- * @author ComPDFKit-WPH 2023-05-16
+ * @author ComPDFKit-WPH 2024-01-25
  */
 @Data
 @TableName("orders")
@@ -88,7 +87,7 @@ public class Orders {
     /**
      * 第三方交易号
      */
-    private String paddleNo;
+    private String thirdTradeNo;
     /**
      * 
      */
@@ -105,5 +104,9 @@ public class Orders {
      * 缴税费用
      */
     private BigDecimal tax;
+    /**
+     * 备注(是否已退款)
+     */
+    private String remark;
 
 }

+ 122 - 0
background-user/src/main/java/cn/kdan/compdf/entity/OrdersGoods.java

@@ -0,0 +1,122 @@
+package cn.kdan.compdf.entity;
+
+import cn.kdan.compdf.base.BaseEntity;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import java.util.Date;
+import java.math.BigDecimal;
+
+/**
+ * @author ComPDFKit-WPH 2024-01-25
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName("orders_goods")
+public class OrdersGoods extends BaseEntity{
+
+    /**
+     * 
+     */
+    @TableId(type = IdType.AUTO)
+    private Integer id;
+    /**
+     * 订单id
+     */
+    private Integer orderId;
+    /**
+     * 订单号
+     */
+    private String orderNo;
+    /**
+     * 订单明细单号
+     */
+    private String goodsNo;
+    /**
+     * 支付订单号
+     */
+    private String merchantNo;
+    /**
+     * 商品第三方支付交易明细订单号
+     */
+    private String detailsMerchantNo;
+    /**
+     * 支付类型:1paddle支付2支付宝3微信4不需支付
+     */
+    private Integer payType;
+    /**
+     * 状态:0待支付,1为已付款或者订阅中,2已完成 3待退款 4已关闭 5取消订阅 6已退款
+     */
+    private Integer status;
+    /**
+     * 支付时间
+     */
+    private Date payTime;
+    /**
+     * 订单类型:1后台创建2用户购买
+     */
+    private Integer type;
+    /**
+     * 订单类别:1SDK试用  2SDK订单  3SaaS订单
+     */
+    private Integer detailsType;
+    /**
+     * appid/Machine ID
+     */
+    private String appid;
+    /**
+     * 商品支付金额
+     */
+    private BigDecimal price;
+    /**
+     * 用户ID
+     */
+    private Integer userId;
+    /**
+     * 关闭时间
+     */
+    private Date closetime;
+    /**
+     * 商品购买年限
+     */
+    private Integer payYears;
+    /**
+     * 商品ID
+     */
+    private Integer goodsId;
+    /**
+     * 创建时间
+     */
+    private Date createdAt;
+    /**
+     * 修改时间
+     */
+    private Date updatedAt;
+    /**
+     * 第三方交易号
+     */
+    private String thirdTradeNo;
+    /**
+     * 续订的父订单明细ID
+     */
+    private Integer renweGoodsid;
+    /**
+     * 配置的资产,后台新建订单自定义配置订阅套餐档位
+     */
+    private Integer specialAssets;
+    /**
+     * SaaS订单套餐类型 1:订阅 2:package
+     */
+    private Integer packageType;
+    /**
+     * 订阅类型订单下次扣款时间
+     */
+    private Date nextBillingTime;
+    /**
+     * 备注 时候退款等
+     */
+    private String remark;
+
+}

+ 4 - 0
background-user/src/main/java/cn/kdan/compdf/entity/dto/DashboardQueryDTO.java

@@ -55,4 +55,8 @@ public class DashboardQueryDTO {
      */
     private Integer timeZone;
 
+    /**
+     * true:中文 false:英文
+     */
+    private Boolean isCN;
 }

+ 3 - 0
background-user/src/main/java/cn/kdan/compdf/mapper/OrderCashFlowMapper.java

@@ -1,11 +1,14 @@
 package cn.kdan.compdf.mapper;
 
 import cn.kdan.compdf.entity.OrderCashFlow;
+import cn.kdan.compdf.vo.OrderBillingInfoVO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * @author ComPDFKit-WPH 2023-05-25
  */
 public interface OrderCashFlowMapper extends BaseMapper<OrderCashFlow> {
 
+    OrderBillingInfoVO selectOrderBillingInfo(@Param("orderCashFlowId") Integer orderCashFlowId);
 }

+ 11 - 0
background-user/src/main/java/cn/kdan/compdf/mapper/OrdersGoodsMapper.java

@@ -0,0 +1,11 @@
+package cn.kdan.compdf.mapper;
+
+import cn.kdan.compdf.entity.OrdersGoods;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * @author ComPDFKit-WPH 2024-01-25
+ */
+public interface OrdersGoodsMapper extends BaseMapper<OrdersGoods> {
+
+}

+ 1 - 1
background-user/src/main/java/cn/kdan/compdf/service/BackgroundUserBalanceService.java

@@ -45,7 +45,7 @@ public interface BackgroundUserBalanceService extends IService<BackgroundUserBal
      * @param userId 用户id
      * @param response response
      */
-    void exportBalanceRecordList(Integer timeZone,Integer isDecs,Long userId, HttpServletResponse response);
+    void exportBalanceRecordList(Integer timeZone,Integer isDecs,Long userId,Boolean isCN, HttpServletResponse response);
 
     /**
      * plan 消费记录数据同步 一天一次

+ 3 - 0
background-user/src/main/java/cn/kdan/compdf/service/OrderCashFlowService.java

@@ -2,6 +2,7 @@ package cn.kdan.compdf.service;
 
 import cn.kdan.compdf.entity.OrderCashFlow;
 import cn.kdan.compdf.vo.OrderBillVo;
+import cn.kdan.compdf.vo.OrderBillingInfoVO;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
@@ -37,4 +38,6 @@ public interface OrderCashFlowService extends IService<OrderCashFlow> {
      * @return OrderBillVo
      */
     OrderBillVo getOrderCashFlowByOrderId(Integer orderCashFlowId);
+
+    OrderBillingInfoVO getOrderBillingInfo(Integer orderCashFlowId);
 }

+ 13 - 0
background-user/src/main/java/cn/kdan/compdf/service/OrdersGoodsService.java

@@ -0,0 +1,13 @@
+package cn.kdan.compdf.service;
+
+import cn.kdan.compdf.entity.OrdersGoods;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+/**
+ * @author ComPDFKit-WPH 2024-01-25
+ */
+public interface OrdersGoodsService extends IService<OrdersGoods> {
+
+
+}

+ 16 - 6
background-user/src/main/java/cn/kdan/compdf/service/impl/BackgroundConvertDataServiceImpl.java

@@ -502,16 +502,26 @@ public class BackgroundConvertDataServiceImpl extends ServiceImpl<BackgroundConv
         response.setCharacterEncoding("utf-8");
         List<List<String>> listHand = new ArrayList<>();
         List<String> head0 = new ArrayList<>();
-        // 判断是Hour还是Date
-        head0.add(hourOrDate ? "Hour" : "Date");
         List<String> head1 = new ArrayList<>();
-        head1.add("Succesful Requests");
         List<String> head2 = new ArrayList<>();
-        head2.add("Error Requests");
         List<String> head3 = new ArrayList<>();
-        head3.add("Error Ratio");
         List<String> head4 = new ArrayList<>();
-        head4.add("Average Process Time");
+
+        if (queryDTO.getIsCN()){
+            // 判断是Hour还是Date
+            head0.add(hourOrDate ? "小时" : "天");
+            head1.add("成功请求数");
+            head2.add("错误请求数");
+            head3.add("错误率");
+            head4.add("平均处理时间");
+        }else {
+            // 判断是Hour还是Date
+            head0.add(hourOrDate ? "Hour" : "Date");
+            head1.add("Successful Requests");
+            head2.add("Error Requests");
+            head3.add("Error Ratio");
+            head4.add("Average Process Time");
+        }
         listHand.add(head0);
         listHand.add(head1);
         listHand.add(head2);

+ 32 - 2
background-user/src/main/java/cn/kdan/compdf/service/impl/BackgroundUserBalanceServiceImpl.java

@@ -146,7 +146,7 @@ public class BackgroundUserBalanceServiceImpl extends ServiceImpl<BackgroundUser
      * @param response response
      */
     @Override
-    public void exportBalanceRecordList(Integer timeZone,Integer isDecs, Long userId, HttpServletResponse response) {
+    public void exportBalanceRecordList(Integer timeZone,Integer isDecs, Long userId,Boolean isCN, HttpServletResponse response) {
         LambdaQueryWrapper<BackgroundUserBalance> eq = new LambdaQueryWrapper<BackgroundUserBalance>()
                 .eq(BackgroundUserBalance::getUserId, userId)
                 .orderByDesc(BackgroundUserBalance::getId);
@@ -175,7 +175,37 @@ public class BackgroundUserBalanceServiceImpl extends ServiceImpl<BackgroundUser
             response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
             response.setCharacterEncoding("utf-8");
             response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
-            EasyExcel.write(response.getOutputStream(), BackgroundUserBalanceVO.class)
+
+            List<List<String>> listHand = new ArrayList<>();
+            List<String> head0 = new ArrayList<>();
+            List<String> head1 = new ArrayList<>();
+            List<String> head2 = new ArrayList<>();
+            List<String> head3 = new ArrayList<>();
+            List<String> head4 = new ArrayList<>();
+
+            if (isCN){
+                // 判断是Hour还是Date
+                head0.add("日期");
+                head1.add("描述");
+                head2.add("余额变动");
+                head3.add("剩余文档数量");
+                head4.add("id");
+            }else {
+                // 判断是Hour还是Date
+                head0.add("Date");
+                head1.add("Description");
+                head2.add("Balance Change");
+                head3.add("Remaining Files");
+                head4.add("id");
+            }
+            listHand.add(head0);
+            listHand.add(head1);
+            listHand.add(head2);
+            listHand.add(head3);
+            listHand.add(head4);
+
+            EasyExcel.write(response.getOutputStream())
+                    .head(listHand)
                     .registerWriteHandler(new ExcelWidthStyleStrategy())
                     .autoCloseStream(Boolean.FALSE)
                     .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())

+ 25 - 3
background-user/src/main/java/cn/kdan/compdf/service/impl/OrderCashFlowServiceImpl.java

@@ -2,11 +2,16 @@ package cn.kdan.compdf.service.impl;
 
 import cn.kdan.compdf.constant.MyConstant;
 import cn.kdan.compdf.entity.OrderCashFlow;
+import cn.kdan.compdf.entity.OrdersGoods;
+import cn.kdan.compdf.exception.BusinessException;
 import cn.kdan.compdf.mapper.OrderCashFlowMapper;
 import cn.kdan.compdf.service.OrderCashFlowService;
+import cn.kdan.compdf.service.OrdersGoodsService;
 import cn.kdan.compdf.vo.OrderBillVo;
+import cn.kdan.compdf.vo.OrderBillingInfoVO;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.RequiredArgsConstructor;
 import org.jetbrains.annotations.NotNull;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
@@ -19,8 +24,11 @@ import java.util.stream.Collectors;
  * @author ComPDFKit-WPH 2023-05-25
  */
 @Service
+@RequiredArgsConstructor
 public class OrderCashFlowServiceImpl extends ServiceImpl<OrderCashFlowMapper, OrderCashFlow> implements OrderCashFlowService {
 
+    private final OrdersGoodsService ordersGoodsService;
+
     /**
      * 获取流水账单
      *
@@ -30,11 +38,19 @@ public class OrderCashFlowServiceImpl extends ServiceImpl<OrderCashFlowMapper, O
     @Override
     public List<OrderBillVo> getOrderCashFlowByOrderId(List<Integer> orderIds, Integer flag) {
         List<OrderCashFlow> orderCashFlows = new ArrayList<>();
+        orderIds = orderIds.stream().distinct().collect(Collectors.toList());
+        if (CollectionUtils.isEmpty(orderIds)){
+            return new ArrayList<>();
+        }
+        List<OrdersGoods> ordersGoods = ordersGoodsService.getBaseMapper().selectList(new LambdaQueryWrapper<OrdersGoods>()
+                .select(OrdersGoods::getId)
+                .in(OrdersGoods::getOrderId, orderIds));
+        List<Integer> ordersGoodsIds = ordersGoods.stream().map(OrdersGoods::getId).collect(Collectors.toList());
 
         if (MyConstant.ORDER_SUCCESS.equals(flag)){
             List<OrderCashFlow> orderCashFlowsSuccess = this.baseMapper.selectList(new LambdaQueryWrapper<OrderCashFlow>()
                     .eq(OrderCashFlow::getDelFlag, 0)
-                    .in(OrderCashFlow::getOrderId, orderIds)
+                    .in(OrderCashFlow::getOrderGoodsId, ordersGoodsIds)
                     .orderByDesc(OrderCashFlow::getCreatedAt));
             if (!CollectionUtils.isEmpty(orderCashFlowsSuccess)) {
                 orderCashFlows.addAll(orderCashFlowsSuccess);
@@ -47,7 +63,7 @@ public class OrderCashFlowServiceImpl extends ServiceImpl<OrderCashFlowMapper, O
             orderIds.forEach(orderId ->{
                 List<OrderCashFlow> orderCashFlowsFail = this.baseMapper.selectList(new LambdaQueryWrapper<OrderCashFlow>()
                         .eq(OrderCashFlow::getDelFlag, 0)
-                        .eq(OrderCashFlow::getOrderId, orderId)
+                        .eq(OrderCashFlow::getOrderGoodsId, ordersGoodsIds)
                         .orderByDesc(OrderCashFlow::getCreatedAt).last("LIMIT 18446744073709551615 OFFSET 1"));
                 if (!CollectionUtils.isEmpty(orderCashFlowsFail)) {
                     orderCashFlows.addAll(orderCashFlowsFail);
@@ -64,7 +80,8 @@ public class OrderCashFlowServiceImpl extends ServiceImpl<OrderCashFlowMapper, O
         orderCashFlow.setInvoiceNum(billNo);
         orderCashFlow.setInvoiceUrl(billUrl);
         orderCashFlow.setUserBill(userBillStr);
-        this.baseMapper.update(orderCashFlow,new LambdaQueryWrapper<OrderCashFlow>().eq(OrderCashFlow::getId,orderCashFlowId));
+        orderCashFlow.setId(orderCashFlowId);
+        this.baseMapper.updateById(orderCashFlow);
     }
 
     @Override
@@ -73,6 +90,11 @@ public class OrderCashFlowServiceImpl extends ServiceImpl<OrderCashFlowMapper, O
         return orderCashFlowToOrderBillVo(orderCashFlow);
     }
 
+    @Override
+    public OrderBillingInfoVO getOrderBillingInfo(Integer orderCashFlowId) {
+        return this.baseMapper.selectOrderBillingInfo(orderCashFlowId);
+    }
+
     /**
      * OrderCashFlow 转 OrderBillVo
      *

+ 16 - 0
background-user/src/main/java/cn/kdan/compdf/service/impl/OrdersGoodsServiceImpl.java

@@ -0,0 +1,16 @@
+package cn.kdan.compdf.service.impl;
+
+import cn.kdan.compdf.entity.OrdersGoods;
+import cn.kdan.compdf.mapper.OrdersGoodsMapper;
+import cn.kdan.compdf.service.OrdersGoodsService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author ComPDFKit-WPH 2024-01-25
+ */
+@Service
+public class OrdersGoodsServiceImpl extends ServiceImpl<OrdersGoodsMapper, OrdersGoods> implements OrdersGoodsService {
+
+
+}

+ 1 - 0
background-user/src/main/java/cn/kdan/compdf/service/impl/OrdersServiceImpl.java

@@ -4,6 +4,7 @@ import cn.kdan.compdf.entity.Orders;
 import cn.kdan.compdf.mapper.OrdersMapper;
 import cn.kdan.compdf.service.OrdersService;
 import cn.kdan.compdf.vo.OrderBillVo;
+import cn.kdan.compdf.vo.OrderBillingInfoVO;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

+ 113 - 12
background-user/src/main/java/cn/kdan/compdf/service/impl/UserBillingInformationServiceImpl.java

@@ -1,8 +1,6 @@
 package cn.kdan.compdf.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.date.DateUtil;
 import cn.kdan.compdf.constant.MyConstant;
 import cn.kdan.compdf.dto.ApplyInvoiceDTO;
 import cn.kdan.compdf.dto.BillSendEmailDTO;
@@ -16,9 +14,8 @@ import cn.kdan.compdf.service.OrderCashFlowService;
 import cn.kdan.compdf.service.OrdersService;
 import cn.kdan.compdf.service.UserBillingInformationService;
 import cn.kdan.compdf.utils.TemplatesUtil;
-import cn.kdan.compdf.vo.ApplyInvoiceVO;
-import cn.kdan.compdf.vo.OrderBillVo;
-import cn.kdan.compdf.vo.UserBillingInfoVO;
+import cn.kdan.compdf.utils.TokenUtil;
+import cn.kdan.compdf.vo.*;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -45,11 +42,14 @@ import javax.mail.internet.MimeMessage;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Field;
-import java.net.MalformedURLException;
+import java.math.BigDecimal;
+import java.math.MathContext;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
-import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -74,6 +74,47 @@ public class UserBillingInformationServiceImpl extends ServiceImpl<UserBillingIn
 
     private final OrderCashFlowService orderCashFlowService;
 
+    private static final String EMAIL_USER_NAME = "#\"userName\"";
+
+    private final static String emailTemplate_EN = "<!DOCTYPE html>\n" +
+            "<html>\n" +
+            "<head>\n" +
+            "<meta charset=\"utf-8\">\n" +
+            "<title>HTML Editor - LDDGO.NET</title>\n" +
+            "<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.1/build/styles/default.min.css\" type=\"text/css\">\n" +
+            "</head>\n" +
+            "<body>\n" +
+            "\n" +
+            "<p>Dear "+EMAIL_USER_NAME+",</p>\n" +
+            "<p>Your invoice has been sent to your email. Please check the attached PDF file.&nbsp;</p>\n" +
+            "<p>Thank you for your support of ComPDFKit!</p>\n" +
+            "<p><br />Thanks,<br />ComPDFKit Team<br /><a href=\"https://www.compdf.com\">https://www.compdf.com</a></p>\n" +
+            "\n" +
+            "<script src=\"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.1/build/highlight.min.js\" type=\"text/javascript\"></script>\n" +
+            "<script type=\"text/javascript\">hljs.highlightAll();</script>\n" +
+            "</body>\n" +
+            "</html>";
+
+    private final static String emailTemplate_CN = "<!DOCTYPE html>\n" +
+            "<html>\n" +
+            "<head>\n" +
+            "<meta charset=\"utf-8\">\n" +
+            "<title>HTML Editor - LDDGO.NET</title>\n" +
+            "<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.1/build/styles/default.min.css\" type=\"text/css\">\n" +
+            "</head>\n" +
+            "<body>\n" +
+            "\n" +
+            "<p>尊敬的 "+EMAIL_USER_NAME+",</p>\n" +
+            "<p>您好!您的发票已通过电子邮件发送至您的邮箱,请查收附件中的PDF文件。</p>\n" +
+            "<p>感谢您对ComPDFKit的支持!</p>\n" +
+            "<p><br />ComPDFKit 团队<br /><a href=\"https://www.compdf.com/zh-cn\">https://www.compdf.com/zh-cn</a></p>\n" +
+            "\n" +
+            "<script src=\"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.1/build/highlight.min.js\" type=\"text/javascript\"></script>\n" +
+            "<script type=\"text/javascript\">hljs.highlightAll();</script>\n" +
+            "</body>\n" +
+            "</html>";
+
+
     static {
         try {
             invoiceHtml = new String(StreamUtils.copyToByteArray(UserBillingInformationServiceImpl.class.getClassLoader().getResourceAsStream("templates/invoice.html")), StandardCharsets.UTF_8);
@@ -162,12 +203,54 @@ public class UserBillingInformationServiceImpl extends ServiceImpl<UserBillingIn
             checkFieldNotNullOrEmpty(userBillingInfo, field);
         }
         // 生成发票号
-        Date now = new Date();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
+
+        Date now = new Date();
         String billNo = sdf.format(now.getTime()).concat(String.valueOf(new Random().nextInt(9)));
+
+        OrderBillingInfoVO orderBillingInfoVO = orderCashFlowService.getOrderBillingInfo(applyInvoiceDTO.getOrderId());
+        // 是订阅
+        String startDateStr = "";
+        String endDateStr = "";
+        String paymentCycle = "";
+        if (orderBillingInfoVO.getPackageType().equals(1)) {
+            if ("Monthly".equals(orderBillingInfoVO.getSubscriptionType())) {
+                LocalDateTime startDate = orderBillingInfoVO.getPayTime().plusMonths(orderBillingInfoVO.getPeriod());
+                LocalDateTime endDate = orderBillingInfoVO.getPayTime().plusMonths(orderBillingInfoVO.getPeriod() + 1);
+                startDateStr = startDate.format(formatter);
+                endDateStr = endDate.format(formatter);
+                paymentCycle = "Monthly Payments";
+            } else if ("Annually".equals(orderBillingInfoVO.getSubscriptionType())) {
+                LocalDateTime startDate = orderBillingInfoVO.getPayTime().plusYears(orderBillingInfoVO.getPeriod());
+                LocalDateTime endDate = orderBillingInfoVO.getPayTime().plusYears(orderBillingInfoVO.getPeriod() + 1);
+                startDateStr = startDate.format(formatter);
+                endDateStr = endDate.format(formatter);
+                paymentCycle = "Annually Payments";
+            }
+        } else if (orderBillingInfoVO.getPackageType().equals(2)) {
+            paymentCycle = "Package Payments";
+        }
+
+        BillingInfoVO billingInfoVO = new BillingInfoVO(userBillingInfo);
+        billingInfoVO.setStartDate(startDateStr);
+        billingInfoVO.setEndDate(endDateStr);
+        billingInfoVO.setPaymentCycle(paymentCycle);
+        billingInfoVO.setGearLevel(orderBillingInfoVO.getGearLevel());
+        billingInfoVO.setPrice(orderBillingInfoVO.getPrice().toString());
+        BigDecimal totalTax = orderBillingInfoVO.getPrice().multiply(new BigDecimal("0.05"));
+        billingInfoVO.setTotalExcludingTax(totalTax.toString());
+        billingInfoVO.setTotal(orderBillingInfoVO.getPrice().add(totalTax).toString());
+        billingInfoVO.setBillNo(billNo);
+        // 01/15/2024
+
+        LocalDate date = LocalDate.now();
+        String invoiceDate = date.format(formatter);
+        billingInfoVO.setInvoiceDate(invoiceDate);
+
         // 获取html模板
         // 填充数据
-        String htmlStr = TemplatesUtil.replaceStringUsingFreeMarker(invoiceHtml, userBillingInfo);
+        String htmlStr = TemplatesUtil.replaceStringUsingFreeMarker(invoiceHtml, billingInfoVO);
         // 调用PHP接口生成PDF发票
         // 设置请求header
         HttpHeaders headers = new HttpHeaders();
@@ -193,6 +276,9 @@ public class UserBillingInformationServiceImpl extends ServiceImpl<UserBillingIn
     @Override
     public void billSendEmail(BillSendEmailDTO billSendEmailDTO) {
         OrderBillVo orderBillVo = orderCashFlowService.getOrderCashFlowByOrderId(billSendEmailDTO.getOrderId());
+
+        UserBillingInfoVO userBillingInfo = this.getUserBillingInfo(TokenUtil.getRequestHeader().getUsersId());
+
         try {
             // 发送邮件并发送附件
             MimeMessage message = javaMailSender.createMimeMessage();
@@ -200,9 +286,24 @@ public class UserBillingInformationServiceImpl extends ServiceImpl<UserBillingIn
             MimeMessageHelper helper = new MimeMessageHelper(message, true);
             helper.setFrom(fromEmail);
             helper.setTo(billSendEmailDTO.getEmail());
-            helper.setSubject("发票");
-            //第2个参数:是否解析html
-            helper.setText("这是一个发票", true);
+
+            String emailContent;
+            if (billSendEmailDTO.getIsCN()) {
+                helper.setSubject("ComPDFKit API 发票号:"+orderBillVo.getBillNo());
+                emailContent = emailTemplate_CN.replaceAll(EMAIL_USER_NAME,userBillingInfo.getFirstName()
+                        + " " + userBillingInfo.getLastName());
+            }else {
+                LocalDate date = LocalDate.now();
+                // 01/15/2024
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
+                String formattedDate = date.format(formatter);
+                helper.setSubject("Invoice "+orderBillVo.getBillNo()+" for ComPDFKit API due  "+formattedDate);
+                //第2个参数:是否解析html
+                emailContent = emailTemplate_EN.replaceAll(EMAIL_USER_NAME,userBillingInfo.getFirstName()
+                        + " " + userBillingInfo.getLastName());
+            }
+
+            helper.setText(emailContent, true);
             //添加附件
             File file = new File("invoice.pdf");
             FileUtils.copyURLToFile(new URL(orderBillVo.getBillUrl()), file);

+ 45 - 0
background-user/src/main/java/cn/kdan/compdf/vo/BillingInfoVO.java

@@ -0,0 +1,45 @@
+package cn.kdan.compdf.vo;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
+/**
+ * @author ComPDFKit-WPH 2024/1/29
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@ToString
+public class BillingInfoVO extends UserBillingInfoVO {
+
+    private String startDate;
+
+    private String endDate;
+
+    private String paymentCycle;
+
+    private String gearLevel;
+
+    private String price;
+
+    private String totalExcludingTax;
+
+    private String total;
+
+    private String billNo;
+
+    private String invoiceDate;
+
+    public BillingInfoVO(UserBillingInfoVO userBillingInfoVO) {
+        this.setEmail(userBillingInfoVO.getEmail());
+        this.setUserId(userBillingInfoVO.getUserId());
+        this.setFirstName(userBillingInfoVO.getFirstName());
+        this.setLastName(userBillingInfoVO.getLastName());
+        this.setCompany(userBillingInfoVO.getCompany());
+        this.setAddress(userBillingInfoVO.getAddress());
+        this.setCountry(userBillingInfoVO.getCountry());
+        this.setProvince(userBillingInfoVO.getProvince());
+        this.setZip(userBillingInfoVO.getZip());
+    }
+
+}

+ 28 - 0
background-user/src/main/java/cn/kdan/compdf/vo/OrderBillingInfoVO.java

@@ -0,0 +1,28 @@
+package cn.kdan.compdf.vo;
+
+import lombok.Data;
+import lombok.ToString;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @author ComPDFKit-WPH 2024/1/29
+ */
+@Data
+@ToString
+public class OrderBillingInfoVO {
+
+    private LocalDateTime payTime;
+
+    private Integer period;
+
+    private Integer packageType;
+
+    private String subscriptionType;
+
+    private String gearLevel;
+
+    private BigDecimal price;
+
+}

+ 2 - 2
background-user/src/main/java/cn/kdan/compdf/vo/UserBillingInfoVO.java

@@ -3,6 +3,8 @@ package cn.kdan.compdf.vo;
 import lombok.Data;
 import lombok.ToString;
 
+import java.math.BigDecimal;
+
 /**
  * @author ComPDFKit-WPH 2023/5/15
  */
@@ -54,6 +56,4 @@ public class UserBillingInfoVO {
      * 邮编
      */
     private String zip;
-
-
 }

+ 19 - 0
background-user/src/main/resources/mapper/OrderCashFlowMapper.xml

@@ -24,4 +24,23 @@
         <result property="delFlag" column="del_flag" />
     </resultMap>
 
+    <select id="selectOrderBillingInfo" resultType="cn.kdan.compdf.vo.OrderBillingInfoVO">
+        SELECT
+        og.pay_time,
+        ( SELECT COUNT(*) FROM order_cash_flow WHERE order_goods_id = ( SELECT order_goods_id FROM order_cash_flow WHERE
+        id = #{orderCashFlowId} ) AND id &lt;= #{orderCashFlowId} ) period,
+        og.package_type,
+        gc.title subscription_type,
+        gc2.title gear_level,
+        ocf.price
+        FROM
+        order_cash_flow ocf
+        JOIN orders_goods og ON ocf.order_goods_id = og.id
+        JOIN goods gd ON og.goods_id = gd.id
+        JOIN goods_classification gc ON gd.level1 = gc.id
+        JOIN goods_classification gc2 ON gd.level2 = gc2.id
+        WHERE
+        ocf.id = #{orderCashFlowId}
+    </select>
+
 </mapper>

+ 35 - 0
background-user/src/main/resources/mapper/OrdersGoodsMapper.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="cn.kdan.compdf.mapper.OrdersGoodsMapper">
+
+    <!-- 可根据自己的需求,是否要使用 -->
+    <resultMap id="OrdersGoodsResultMap" type="cn.kdan.compdf.entity.OrdersGoods">
+        <result property="id" column="id" />
+        <result property="orderId" column="order_id" />
+        <result property="orderNo" column="order_no" />
+        <result property="goodsNo" column="goods_no" />
+        <result property="merchantNo" column="merchant_no" />
+        <result property="detailsMerchantNo" column="details_merchant_no" />
+        <result property="payType" column="pay_type" />
+        <result property="status" column="status" />
+        <result property="payTime" column="pay_time" />
+        <result property="type" column="type" />
+        <result property="detailsType" column="details_type" />
+        <result property="appid" column="appid" />
+        <result property="price" column="price" />
+        <result property="userId" column="user_id" />
+        <result property="closetime" column="closetime" />
+        <result property="payYears" column="pay_years" />
+        <result property="goodsId" column="goods_id" />
+        <result property="createdAt" column="created_at" />
+        <result property="updatedAt" column="updated_at" />
+        <result property="thirdTradeNo" column="third_trade_no" />
+        <result property="renweGoodsid" column="renwe_goodsid" />
+        <result property="specialAssets" column="special_assets" />
+        <result property="packageType" column="package_type" />
+        <result property="nextBillingTime" column="next_billing_time" />
+        <result property="remark" column="remark" />
+    </resultMap>
+
+</mapper>

+ 16 - 1
background-user/src/main/resources/templates/invoice.html

@@ -1 +1,16 @@
-123
+firstName: ${firstName}<br/>
+lastName: ${lastName}<br/>
+email: ${email}<br/>
+company: ${company}<br/>
+country: ${country}<br/>
+province: ${province}<br/>
+address: ${address}<br/>
+startDate: ${startDate}<br/>
+endDate: ${endDate}<br/>
+paymentCycle: ${paymentCycle}<br/>
+gearLevel: ${gearLevel}<br/>
+price: ${price}<br/>
+totalExcludingTax: ${totalExcludingTax}<br/>
+total: ${total}<br/>
+billNo: ${billNo}<br/>
+invoiceDate: ${invoiceDate}<br/>