Forráskód Böngészése

提现失败自动补偿一次

wujiefeng 11 hónapja
szülő
commit
700264f972

+ 6 - 0
RewardServer/pom.xml

@@ -116,6 +116,12 @@
 			<version>${project.version}</version>
 		</dependency>
 
+		<dependency>
+			<groupId>com.github.microservice.encryption</groupId>
+			<artifactId>ProductCenterClient</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+
 <!--		<dependency>-->
 <!--			<groupId>org.redisson</groupId>-->
 <!--			<artifactId>redisson-spring-boot-starter</artifactId>-->

+ 16 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/config/ProductConfig.java

@@ -0,0 +1,16 @@
+package com.zhongshu.reward.server.core.config;
+
+import com.github.microservice.productcenter.client.config.ProductCenterClientConfiguration;
+import com.zhongshu.vip.client.config.VipCenterClientConfiguration;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+/**
+ * @author wjf
+ * @date 2024/8/26
+ */
+
+@Configuration
+@Import(ProductCenterClientConfiguration.class)
+public class ProductConfig {
+}

+ 11 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/Impl/WalletReceiptsDaoImpl.java

@@ -38,6 +38,7 @@ public class WalletReceiptsDaoImpl implements WalletReceiptsDaoExtend {
         if (StringUtils.isNotEmpty(inviteUserId)){
             criteria.and("inviteUserId").is(inviteUserId);
         }
+        criteria.and("receiptsType").is(ReceiptsType.COMMISSION);
         criteria.and("status").is(ReceiptsStatus.RECEIPTS);
         Query query = Query.query(criteria);
         query.with(Sort.by(Sort.Order.desc("receiptsTime")));
@@ -115,4 +116,14 @@ public class WalletReceiptsDaoImpl implements WalletReceiptsDaoExtend {
 
         return mongoTemplate.findOne(query, WalletReceipts.class);
     }
+
+    @Override
+    public List<WalletReceipts> findByEstimatedTime(Long currentTime) {
+        Criteria criteria = new Criteria();
+        criteria.and("status").in(ReceiptsStatus.WAIT);
+        criteria.and("receiptsType").is(ReceiptsType.COMMISSION);
+        criteria.and("estimatedTime").lte(currentTime);
+        Query query = Query.query(criteria);
+        return mongoTemplate.find(query, WalletReceipts.class);
+    }
 }

+ 1 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/WalletReceiptsDao.java

@@ -24,4 +24,5 @@ public interface WalletReceiptsDao extends MongoDao<WalletReceipts>, WalletRecei
     WalletReceipts findTop1ByVipUserRecord_Id(String vipUserRecordId);
 
     List<WalletReceipts> findByOutTradeNoAndGoodsIdInAndStatus(String outTradeNo, List<String> goodsIds, ReceiptsStatus status);
+
 }

+ 3 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/dao/extend/WalletReceiptsDaoExtend.java

@@ -1,6 +1,7 @@
 package com.zhongshu.reward.server.core.dao.extend;
 
 import com.zhongshu.reward.client.model.InviteSuccessModel;
+import com.zhongshu.reward.server.core.dao.WalletReceiptsDao;
 import com.zhongshu.reward.server.core.domain.WalletReceipts;
 
 import java.util.List;
@@ -20,4 +21,6 @@ public interface WalletReceiptsDaoExtend {
     List<WalletReceipts> listMonthBySetMealCode(Long startTime, Long endTime, List<String> setMealCodeList);
 
     WalletReceipts findNoCancelByCreateTime(String userId, Long startTime, Long endTime);
+
+    List<WalletReceipts> findByEstimatedTime(Long currentTime);
 }

+ 44 - 2
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/GoodsReceiptsService.java

@@ -1,5 +1,9 @@
 package com.zhongshu.reward.server.core.service;
 
+import com.github.microservice.productcenter.client.model.ProductRuleModel;
+import com.github.microservice.productcenter.client.ret.ResultContent;
+import com.github.microservice.productcenter.client.ret.ResultState;
+import com.github.microservice.productcenter.client.service.ProductRuleService;
 import com.zhongshu.reward.client.type.ReceiptsStatus;
 import com.zhongshu.reward.client.type.ReceiptsType;
 import com.zhongshu.reward.server.core.dao.WalletDao;
@@ -7,6 +11,8 @@ import com.zhongshu.reward.server.core.dao.WalletReceiptsDao;
 import com.zhongshu.reward.server.core.domain.Wallet;
 import com.zhongshu.reward.server.core.domain.WalletReceipts;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -33,15 +39,25 @@ public class GoodsReceiptsService {
     @Autowired
     WalletReceiptsDao walletReceiptsDao;
 
+    @Autowired
+    ProductRuleService productRuleService;
+
     /**
      * 购物返利 todo// 1、获取产品库 返利规则 2、获取订单详情、获取商品详情
      * @param userId 用户id
-     * @param total 返利金额
+     * @param goodsTotal 商品金额
      * @param orderNo 订单号
      * @param goodsId 商品id
      */
     @Transactional
-    public void receipts(String userId, BigDecimal total, String orderNo, String goodsId){
+    public void receipts(String userId, BigDecimal goodsTotal, String orderNo, String goodsId){
+
+        ProductRuleModel productRule = getRule(goodsId);
+        if (null == productRule){
+            return;
+        }
+
+        BigDecimal total = getReceiptsTotal(goodsTotal, productRule);
 
         Wallet wallet = walletService.getWalletByUserId(userId);
 
@@ -59,6 +75,32 @@ public class GoodsReceiptsService {
         log.info("购物返利入账");
     }
 
+    @NotNull
+    private static BigDecimal getReceiptsTotal(BigDecimal goodsTotal, ProductRuleModel productRule) {
+        BigDecimal total = BigDecimal.ZERO;
+
+        if (productRule.getCashBackFixed()!=null){
+            total = productRule.getCashBackFixed();
+        }else if (productRule.getCashBackPercent()!=null){
+            total = goodsTotal.multiply(productRule.getCashBackPercent().multiply(BigDecimal.TEN.pow(2)));
+        } return total;
+    }
+
+    @Nullable
+    private ProductRuleModel getRule(String goodsId) {
+        ResultContent<ProductRuleModel> goodsRulerResult = productRuleService.list(goodsId);
+        ResultContent<ProductRuleModel> overRulerResult = productRuleService.list(null);
+
+        ProductRuleModel productRule = goodsRulerResult.getContent();
+        ProductRuleModel overRule = overRulerResult.getContent();
+        if (productRule.getEnableCashback()!=null && productRule.getEnableCashback()){
+            return productRule;
+        }else if (overRule.getEnableCashback()!=null && overRule.getEnableCashback()){
+            return overRule;
+        }
+        return null;
+    }
+
 
     /**
      * 取消购物返利

+ 0 - 48
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/Impl/WalletFeignServiceImpl.java

@@ -32,53 +32,5 @@ public class WalletFeignServiceImpl {
     WalletService walletService;
 
 
-    public ResultContent<String> addWait(GoodsReceiptsParam param) {
-        Wallet wallet = walletService.getWalletByUserId(param.getUserId());
 
-        WalletReceipts walletReceipts = new WalletReceipts();
-        walletReceipts.setWallet(wallet);
-        walletReceipts.setEstimatedTime(param.getEstimatedTime());
-        walletReceipts.setReceiptsType(ReceiptsType.REBATE);
-        walletReceipts.setTotal(param.getTotal());
-        walletReceipts.setStatus(ReceiptsStatus.WAIT);
-        walletReceipts.setOutTradeNo(param.getOutTradeNo());
-        walletReceipts.setAttach(param.getAttach());
-
-        walletReceiptsDao.save(walletReceipts);
-        wallet.setWaitAmount(wallet.getWaitAmount().add(param.getTotal()));
-        walletDao.save(wallet);
-
-        return ResultContent.buildContent(walletReceipts.getId());
-    }
-
-    public ResultContent cancel(String outTradeNo) {
-        WalletReceipts walletReceipts = walletReceiptsDao.findTopByOutTradeNo(outTradeNo);
-
-        if (!walletReceipts.getStatus().equals(ReceiptsStatus.WAIT)){
-            return ResultContent.build(ResultState.Fail, "只有即将到账的入帐单可以取消");
-        }
-
-        walletReceipts.setReceiptsTime(new Date().getTime());
-        walletReceipts.setStatus(ReceiptsStatus.RECEIPTS);
-        walletReceiptsDao.save(walletReceipts);
-
-        Wallet wallet = walletDao.findTop1ById(walletReceipts.getWallet().getId());
-        wallet.setAmount(wallet.getAmount().add(walletReceipts.getTotal()));
-        wallet.setWaitAmount(wallet.getWaitAmount().subtract(walletReceipts.getTotal()));
-        walletDao.save(wallet);
-        return ResultContent.buildSuccess();
-    }
-
-    public ResultContent receipts(String outTradeNo) {
-        WalletReceipts walletReceipts = walletReceiptsDao.findTopByOutTradeNo(outTradeNo);
-        walletReceipts.setReceiptsTime(new Date().getTime());
-        walletReceipts.setStatus(ReceiptsStatus.RECEIPTS);
-        walletReceiptsDao.save(walletReceipts);
-
-        Wallet wallet = walletDao.findTop1ById(walletReceipts.getWallet().getId());
-        wallet.setAmount(wallet.getAmount().add(walletReceipts.getTotal()));
-        wallet.setWaitAmount(wallet.getWaitAmount().subtract(walletReceipts.getTotal()));
-        walletDao.save(wallet);
-        return ResultContent.buildSuccess();
-    }
 }

+ 7 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/InviteReceiptsService.java

@@ -239,9 +239,16 @@ public class InviteReceiptsService {
             return;
         }
 
+        List<WalletReceipts> byEstimatedTime = walletReceiptsDao.findByEstimatedTime(new Date().getTime());
+        if (null != byEstimatedTime && !byEstimatedTime.isEmpty()){
+            list.addAll(byEstimatedTime);
+        }
+
         //首次订购
         list.forEach(this::addAmount);
 
+
+
 //        Map<String, List<WalletReceipts>> map = list.stream().collect(Collectors.groupingBy(WalletReceipts::getInviteUserId));
 //
 //        for (String key : map.keySet()){