Selaa lähdekoodia

申请开具发票

skyline 2 vuotta sitten
vanhempi
säilyke
a923294c5f

+ 1 - 1
admin/src/main/resources/application-dev.yml

@@ -40,7 +40,7 @@ wechat:
     baseInformation: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/base-information
     taxCodes: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/tax-codes
     fapiaoApplications: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications
-    notifyUrl: https://dev-cloud.kuaiyuman.cn/api/invoice/notify
+    notifyUrl: https://dev.kuaiyuman.cn/api/invoice/notify
     devConfig: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/development-config
     fapiaoFiles: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/%s/fapiao-files
     queryFapiao: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/%s

+ 8 - 1
entity/src/main/java/com/kym/entity/miniapp/InvoiceTitle.java

@@ -5,6 +5,7 @@ import com.kym.entity.BaseEntity;
 import java.io.Serializable;
 import lombok.Getter;
 import lombok.Setter;
+import lombok.experimental.Accessors;
 
 /**
  * <p>
@@ -12,11 +13,12 @@ import lombok.Setter;
  * </p>
  *
  * @author skyline
- * @since 2023-09-21
+ * @since 2023-10-13
  */
 @Getter
 @Setter
 @TableName("t_invoice_title")
+@Accessors(chain = true)
 public class InvoiceTitle extends BaseEntity {
 
     private static final long serialVersionUID = 1L;
@@ -28,6 +30,11 @@ public class InvoiceTitle extends BaseEntity {
      */
     private String email;
 
+    /**
+     * 电话
+     */
+    private String phone;
+
     /**
      * 发票类型:INDIVIDUAL-个人 ORGANIZATION-企业
      */

+ 2 - 1
mapper/src/main/resources/mappers/miniapp/InvoiceTitleMapper.xml

@@ -6,6 +6,7 @@
     <resultMap id="BaseResultMap" type="com.kym.entity.miniapp.InvoiceTitle">
         <result column="user_id" property="userId" />
         <result column="email" property="email" />
+        <result column="phone" property="phone" />
         <result column="invoice_type" property="invoiceType" />
         <result column="invoice_title" property="invoiceTitle" />
         <result column="tax_id" property="taxId" />
@@ -17,7 +18,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        user_id, email, invoice_type, invoice_title, tax_id, address, bank_name, bank_account, remark
+        id,user_id, email, phone, invoice_type, invoice_title, tax_id, address, bank_name, bank_account, remark,create_time,update_time
     </sql>
 
 </mapper>

+ 1 - 1
miniapp/src/main/resources/application-dev.yml

@@ -40,7 +40,7 @@ wechat:
     baseInformation: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/base-information
     taxCodes: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/tax-codes
     fapiaoApplications: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications
-    notifyUrl: https://dev-cloud.kuaiyuman.cn/api/invoice/notify
+    notifyUrl: https://dev.kuaiyuman.cn/api/invoice/notify
     devConfig: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/development-config
     fapiaoFiles: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/%s/fapiao-files
     queryFapiao: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/%s

+ 2 - 0
service/src/main/java/com/kym/service/miniapp/impl/InvoiceServiceImpl.java

@@ -18,6 +18,7 @@ import jakarta.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * <p>
@@ -55,6 +56,7 @@ public class InvoiceServiceImpl extends ServiceImpl<InvoiceMapper, Invoice> impl
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public TitleUrl applyInvoice(ApplyInvoiceParams params) {
         // orderDetails 获取申请开票的订单
         var userId = StpUtil.getLoginIdAsLong();

+ 38 - 16
service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -92,13 +92,15 @@ public class WxPayServiceImpl implements WxPayService {
 
     private final InvoiceService invoiceService;
 
+    private final InvoiceTitleService invoiceTitleService;
+
     /**
      * 微信支付专用,支持自动签名验签解密等
      */
     private OkHttpClientAdapter wxHttpClient;
 
 
-    public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService, PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService, RefundLogService refundLogService, InvoiceService invoiceService) {
+    public WxPayServiceImpl(WxPayConfig conf, WxFapiaoConfig fapiaoConfig, WalletDetailService walletDetailService, PayLogService payLogService, AccountService accountService, ChargeOrderService chargeOrderService, RefundLogService refundLogService, InvoiceService invoiceService, InvoiceTitleService invoiceTitleService) {
         this.conf = conf;
         this.fapiaoConfig = fapiaoConfig;
         this.walletDetailService = walletDetailService;
@@ -107,6 +109,7 @@ public class WxPayServiceImpl implements WxPayService {
         this.chargeOrderService = chargeOrderService;
         this.refundLogService = refundLogService;
         this.invoiceService = invoiceService;
+        this.invoiceTitleService = invoiceTitleService;
     }
 
     /**
@@ -572,11 +575,11 @@ public class WxPayServiceImpl implements WxPayService {
                 "fapiao_apply_id", invoice.getApplyId(),
                 "appid", conf.getAppid(),
                 "openid", invoice.getOpenid(),
-                "total_amount", invoice.getTotalMoney(),
+                "total_amount", invoice.getInvoiceAmount(),
                 "source", "MINIPROGRAM"
         );
         headers.addHeader("Accept", "application/json");
-        var res = wxHttpClient.get(headers, fapiaoConfig.getTitleUrl().concat(URLUtil.buildQuery(params, StandardCharsets.UTF_8)), TitleUrl.class);
+        var res = wxHttpClient.get(headers, fapiaoConfig.getTitleUrl().concat("?").concat(URLUtil.buildQuery(params, StandardCharsets.UTF_8)), TitleUrl.class);
         return res.getServiceResponse();
     }
 
@@ -591,24 +594,42 @@ public class WxPayServiceImpl implements WxPayService {
     public void titleWriteNotice(HttpServletRequest request) {
         var notifyRes = handleWxNotify(request);
         try {
-            // TODO: 2023-10-12 步骤 用户选择开票的订单,确定(数据库插入invoice数据)进入抬头填写页面,输入抬头确定开票,收到抬头填写完成通知后
-            //  再获取用户抬头更新invoice抬头数据。后台审核人员进行开票操作
             TitleWriteNotification titleWriteNotification = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], TitleWriteNotification.class);
+
             // 查询用户填写的抬头信息
             var applyId = titleWriteNotification.getFapiaoApplyId();
             var buyerInformation = userTitle(applyId);
+
             // 更新invoice表数据
-            invoiceService.lambdaUpdate()
-                    .eq(Invoice::getApplyId, applyId)
-                    .set(Invoice::getInvoiceType, buyerInformation.getType())
-                    .set(Invoice::getInvoiceTitle, buyerInformation.getName())
-                    .set(Invoice::getTaxId, buyerInformation.getTaxpayer_id())
-                    .set(Invoice::getAddress, buyerInformation.getAddress())
-                    .set(Invoice::getBankName, buyerInformation.getBank_name())
-                    .set(Invoice::getBankAccount, buyerInformation.getBank_account())
-                    .set(Invoice::getPhone, buyerInformation.getPhone())
-                    .set(Invoice::getEmail, buyerInformation.getEmail())
-                    .update();
+            var invoice = invoiceService.lambdaQuery().eq(Invoice::getApplyId, applyId).one();
+            invoice.setInvoiceType(buyerInformation.getType())
+                    .setInvoiceTitle(buyerInformation.getName())
+                    .setTaxId(buyerInformation.getTaxpayer_id())
+                    .setAddress(buyerInformation.getAddress())
+                    .setBankName(buyerInformation.getBank_name())
+                    .setBankAccount(buyerInformation.getBank_account())
+                    .setEmail(buyerInformation.getEmail())
+                    .setPhone(buyerInformation.getPhone());
+            invoiceService.updateById(invoice);
+
+            // 将发票抬头写入用户抬头表
+            var invoiceTitle = new InvoiceTitle()
+                    .setUserId(invoice.getUserId())
+                    .setInvoiceType(buyerInformation.getType())
+                    .setInvoiceTitle(buyerInformation.getName())
+                    .setTaxId(buyerInformation.getTaxpayer_id())
+                    .setAddress(buyerInformation.getAddress())
+                    .setBankName(buyerInformation.getBank_name())
+                    .setBankAccount(buyerInformation.getBank_account())
+                    .setEmail(buyerInformation.getEmail())
+                    .setPhone(buyerInformation.getPhone());
+            boolean exist = invoiceTitleService.lambdaQuery()
+                    .eq(InvoiceTitle::getUserId, invoiceTitle.getUserId())
+                    .eq(InvoiceTitle::getTaxId, invoiceTitle.getTaxId())
+                    .exists();
+            if (!exist) {
+                invoiceTitleService.save(invoiceTitle);
+            }
             // 运营后台财务操作开具发票
         } catch (ValidationException e) {
             // 签名验证失败,返回 401 UNAUTHORIZED 状态码
@@ -741,6 +762,7 @@ public class WxPayServiceImpl implements WxPayService {
 
     /**
      * 接收电子发票相关回调通知
+     *
      * @param request
      */
     @Override