Răsfoiți Sursa

feat: 邮箱改为开票必填项,增加前后端校验

- 后端: 校验邮箱非空 + 格式合法性
- 前端: 邮箱字段标记必填,提交时校验非空和格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 2 zile în urmă
părinte
comite
5af59229a4

+ 12 - 2
charge-front/src/pages-common/invoice/invoice-form.vue

@@ -85,8 +85,8 @@
 
       <!-- 公共字段 -->
       <view class="form-item">
-        <view class="fs-28 color-333 mb-12">接收邮箱</view>
-        <input class="input br-8 fs-28 p-20" v-model="form.email" placeholder="请输入邮箱(用于接收电子发票)" />
+        <view class="fs-28 color-333 mb-12">接收邮箱<text class="color-primary">*</text></view>
+        <input class="input br-8 fs-28 p-20" v-model="form.email" placeholder="电子发票将发送至此邮箱" />
       </view>
       <view class="form-item">
         <view class="fs-28 color-333 mb-12">备注</view>
@@ -164,6 +164,8 @@ const selectTitle = (item: any) => {
   form.email = item.email || "";
 };
 
+const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
+
 const submit = () => {
   if (!form.invoiceTitle.trim()) {
     uni.showToast({ title: "请填写抬头名称", icon: "none" });
@@ -173,6 +175,14 @@ const submit = () => {
     uni.showToast({ title: "请填写公司税号", icon: "none" });
     return;
   }
+  if (!form.email.trim()) {
+    uni.showToast({ title: "请填写接收发票的邮箱地址", icon: "none" });
+    return;
+  }
+  if (!emailRegex.test(form.email.trim())) {
+    uni.showToast({ title: "邮箱格式不正确", icon: "none" });
+    return;
+  }
 
   uni.showLoading({ title: "提交中" });
 

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

@@ -98,6 +98,12 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic
         if (!(totalPayAmount > 0 && elecMoney > 0 && serviceMoney > 0)) {
             throw new BusinessException("订单总金额或总电费或总服务费金额异常");
         }
+        if (params.getEmail() == null || params.getEmail().isBlank()) {
+            throw new BusinessException("请填写接收发票的邮箱地址");
+        }
+        if (!params.getEmail().matches("^[\\w.%+-]+@[\\w.-]+\\.[a-zA-Z]{2,}$")) {
+            throw new BusinessException("邮箱格式不正确");
+        }
 
         var invoice = new Invoice()
                 .setUserId(userId)