From cf1d82548a1bd8155ffe9b486df8167aa9e63a7d Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期四, 02 七月 2026 09:19:06 +0800
Subject: [PATCH] 功能开发

---
 server/services/src/main/java/com/doumee/service/business/impl/DouyinVerifyServiceImpl.java |   61 +++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/DouyinVerifyServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/DouyinVerifyServiceImpl.java
index fc14eb8..6211902 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/DouyinVerifyServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/DouyinVerifyServiceImpl.java
@@ -9,6 +9,7 @@
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.douyin.DouyinClient;
 import com.doumee.core.douyin.dto.DouyinBaseResp;
+import com.doumee.core.douyin.dto.DouyinBoundProduct;
 import com.doumee.core.douyin.dto.DouyinCancelParam;
 import com.doumee.core.douyin.dto.DouyinCancelReq;
 import com.doumee.core.douyin.dto.DouyinCancelResp;
@@ -135,7 +136,7 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public DouyinVerifyRecord verify(DouyinVerifyParam param, String operator) {
+    public DouyinVerifyRecord verify(DouyinVerifyParam param, String operator, DouyinBoundProduct boundProduct) {
         // 鍏ュ弬鏍¢獙
         if (param == null || StringUtils.isBlank(param.getVerifyToken())) {
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "verifyToken 涓嶈兘涓虹┖");
@@ -153,6 +154,10 @@
         if (StringUtils.isBlank(param.getSkuId())) {
             // 鏃� skuId 鍒欐棤娉曞弽鏌ュ椁�(鏍搁攢杩斿洖鏈韩涓嶅惈鍟嗗搧鏍囪瘑),鐩存帴鎷︽埅
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "skuId 涓嶈兘涓虹┖");
+        }
+        if (boundProduct == null || boundProduct.getProduct() == null || boundProduct.getDiscount() == null) {
+            // 鍏滃簳:濂楅缁戝畾缁撴灉缂哄け(scanVerify 搴斿凡鏍¢獙,杩欓噷闃� NPE)
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏈壘鍒拌鍒稿搴旂殑鏈湴濂楅,璇峰厛鍦ㄧ鐞嗙缁戝畾");
         }
         Date now = new Date();
 
@@ -204,8 +209,16 @@
         }
 
         // 鏍搁攢鎴愬姛:涓哄綋鍓嶇櫥褰曚汉寮�閫氬椁�(浠讳竴姝ュけ璐� 鈫� 鏁村崟鍥炴粴)
-        openDiscountForVerify(rec, param, operator);
+        // 娉�:scanVerify 宸插湪鏍搁攢鍓嶆牎楠岃繃濂楅缁戝畾骞堕�忎紶缁撴灉,杩欓噷涓嶅啀閲嶅鏌ヨ
+        openDiscountForVerify(rec, param, boundProduct, operator);
         return rec;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public DouyinVerifyRecord verify(DouyinVerifyParam param, String operator) {
+        // 鏃犻鏍¢獙缁撴灉鐨勫吋瀹瑰叆鍙�:鏍搁攢鍓嶅厛鏍¢獙濂楅缁戝畾(鏍搁攢鍔ㄤ綔鍦ㄩ噸杞藉唴瀹屾垚)
+        return verify(param, operator, resolveBoundProduct(param.getSkuId()));
     }
 
     /**
@@ -215,19 +228,23 @@
      *
      * @param rec      鏍搁攢璁板綍(鍚� originCode/certificateId 绛夋姈闊虫爣璇�,寮�閫氬悗鍥炲~濂楅鍗D)
      * @param param    鏍搁攢鍏ュ弬(鍚� skuId 鍙嶆煡濂楅銆乸ayAmount 蹇収)
+     * @param boundProduct 鏍搁攢鍓嶅凡鏍¢獙鐨勬姈闊冲晢鍝� + 鏈湴濂楅(閬垮厤閲嶅鏌ヨ)
      * @param operator 鎿嶄綔浜� = 濂楅褰掑睘浜�(web 绔櫥褰曚細鍛� id)
      */
-    private void openDiscountForVerify(DouyinVerifyRecord rec, DouyinVerifyParam param, String operator) {
-        // 鈶� 鍙嶆煡濂楅:skuId 鈫� douyin_product_sku 鈫� product_id 鈫� douyin_product.out_id 鈫� discount
-        DouyinProduct product = resolveProduct(param.getSkuId());
-        Discount discount = resolveDiscount(product);
+    private void openDiscountForVerify(DouyinVerifyRecord rec, DouyinVerifyParam param,
+                                       DouyinBoundProduct boundProduct, String operator) {
+        // 鍟嗗搧 + 濂楅宸茬敱 scanVerify 鏍搁攢鍓嶆牎楠�(resolveBoundProduct)鏌ュ嚭骞堕�忎紶,鐩存帴浣跨敤
+        DouyinProduct product = boundProduct.getProduct();
+        Discount discount = boundProduct.getDiscount();
 
         Date now = new Date();
 
-        // 鈶� 闃查噸:鍚屼竴鍒哥爜宸蹭负璇ョ敤鎴峰紑杩囧椁愬崱鍒欒烦杩�(閬垮厤閲嶅鏍搁攢閲嶅紑)
+        // 鈶� 闃查噸:鍚屼竴鍒哥爜宸蹭负璇ョ敤鎴峰紑杩囥�屾甯搞�嶅椁愬崱鍒欒烦杩�(閬垮厤閲嶅鏍搁攢閲嶅紑)銆�
+        //    娉ㄦ剰:宸蹭綔搴�(status=1,濡傛挙閿�鏍搁攢鍚�)鐨勫崱涓嶅弬涓庨槻閲嶁�斺�旀挙閿�鍚庨噸鏂版牳閿�搴旀甯稿紑鏂板崱銆�
         DiscountMember existCard = discountMemberMapper.selectOne(new QueryWrapper<DiscountMember>().lambda()
                 .eq(DiscountMember::getCode, rec.getOriginCode())
                 .eq(DiscountMember::getMemberId, operator)
+                .eq(DiscountMember::getStatus, Constants.ZERO)
                 .eq(DiscountMember::getIsdeleted, Constants.ZERO)
                 .last("limit 1"));
         if (existCard != null) {
@@ -340,13 +357,23 @@
     private Discount resolveDiscount(DouyinProduct product) {
         Discount discount = discountMapper.selectOne(new QueryWrapper<Discount>().lambda()
                 .eq(Discount::getId, product.getOutId())
-                .eq(Discount::getStatus, Constants.ZERO)
                 .eq(Discount::getIsdeleted, Constants.ZERO)
                 .last("limit 1"));
         if (discount == null) {
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏈壘鍒拌鍒稿搴旂殑鏈湴濂楅,璇峰厛鍦ㄧ鐞嗙缁戝畾");
         }
         return discount;
+    }
+
+    @Override
+    public DouyinBoundProduct resolveBoundProduct(String skuId) {
+        if (StringUtils.isBlank(skuId)) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "skuId 涓嶈兘涓虹┖");
+        }
+        // 澶嶇敤鏃㈡湁鏍¢獙閾捐矾:skuId 鈫� 鎶栭煶鍟嗗搧(鍦ㄥ簱 + 宸茬粦 out_id)鈫� 鏈湴濂楅(鏈夋晥)
+        DouyinProduct product = resolveProduct(skuId);
+        Discount discount = resolveDiscount(product);
+        return new DouyinBoundProduct(product, discount);
     }
 
     @Override
@@ -389,10 +416,13 @@
         rec.setRawResponse(respText);
         // 鎾ら攢澶辫触:鏇存柊璁板綍鎻忚堪鍚庢姏鍑�(璁板綍淇濈暀鍘熸牳閿�鐘舵��)
         if (!ok) {
+            // 澶辫触鍘熷洜:浼樺厛 extra.description,鏈� sub_description 鏃惰拷鍔�(sub_description 鏇村叿浣�)
             String desc = resp == null || resp.getExtra() == null ? "鏃犲搷搴�" : resp.getExtra().getDescription();
-            rec.setCancelMsg("鎾ら攢澶辫触:" + desc);
+            String subDesc = resp == null || resp.getExtra() == null ? null : resp.getExtra().getSubDescription();
+            String failMsg = StringUtils.isBlank(subDesc) ? desc : desc + ";" + subDesc;
+            rec.setCancelMsg("鎾ら攢澶辫触:" + failMsg);
             douyinVerifyRecordMapper.updateById(rec);
-            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鎾ら攢澶辫触:" + desc);
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鎾ら攢澶辫触:" + failMsg);
         }
         // 鎾ら攢鎴愬姛:缃挙閿�鐘舵�併�佹挙閿�鏃堕棿涓庢挙閿�浜�
         rec.setCancelStatus(Constants.DOUYIN_VERIFY_CANCEL_STATUS.DONE.getKey());
@@ -403,6 +433,15 @@
         // 鍚屾浣滃簾鏈湴宸插紑閫氱殑濂楅鍗�(闃叉鎶栭煶鎾ら攢鍚庡椁愪粛琚娇鐢�);鍙傜収 backGoodsorder 閫�鍗�
         cancelDiscountMember(rec, operator, now);
         return rec;
+    }
+
+    @Override
+    public void fillPackageInfo(DouyinVerifyRecord record) {
+        // 鏃犲椁愬崱ID鎴栨煡涓嶅埌鏃剁疆 null,涓嶅奖鍝嶄富娴佺▼(scanVerify 鐢ㄤ簬鍓嶇灞曠ず濂楅淇℃伅)
+        if (record == null || StringUtils.isBlank(record.getDiscountMemberId())) {
+            return;
+        }
+        record.setPackageInfo(discountMemberMapper.selectById(record.getDiscountMemberId()));
     }
 
     /**
@@ -495,6 +534,8 @@
                 .selectAs(DouyinProduct::getCategory, DouyinVerifyRecordPageVO::getCategory)
                 // 鎶栭煶鍒稿悕:discount_member.name(鏈湴寮�閫氬椁愬悕)
                 .selectAs(DiscountMember::getName, DouyinVerifyRecordPageVO::getCouponName)
+                // 濂楅浣跨敤娆℃暟:瀛愭煡璇㈢粺璁¤濂楅鍗″湪 member_rides 鐨勯獞琛岃褰曟暟(t 涓轰富琛� douyin_verify_record)
+                .select(" ( select count(1) from member_rides where discount_member_id = t.discount_member_id and isdeleted = 0 ) ", DouyinVerifyRecordPageVO::getUseCount)
                 // 涓夎〃 leftJoin:discount_member(缁� discount_member_id)鈫� member(缁� member_id);douyin_product(缁� product_id)
                 .leftJoin(DiscountMember.class, DiscountMember::getId, DouyinVerifyRecord::getDiscountMemberId)
                 .leftJoin(Member.class, Member::getId, DiscountMember::getMemberId)

--
Gitblit v1.9.3