wujiefeng пре 9 месеци
родитељ
комит
0d6b3eae4f

+ 36 - 0
RewardClient/src/main/java/com/zhongshu/reward/client/model/param/GoodsReceiptsParam.java

@@ -0,0 +1,36 @@
+package com.zhongshu.reward.client.model.param;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.math.BigDecimal;
+
+/**
+ * @author wjf
+ * @date 2024/8/19
+ */
+@Data
+public class GoodsReceiptsParam {
+
+    @ApiModelProperty("外部订单号")
+    @NotNull(message = "外部订单号不能为空")
+    private String outTradeNo;
+
+    @ApiModelProperty("获得返利用户id")
+    @NotNull(message = "获得返利用户id不能为空")
+    private String userId;
+
+    @ApiModelProperty("预计到账时间")
+    @NotNull(message = "预计到账时间不能为空")
+    private Long estimatedTime;
+
+    @ApiModelProperty("返利金额")
+    @NotNull(message = "返利金额不能为空")
+    private BigDecimal total = BigDecimal.ZERO;
+
+    @ApiModelProperty("附加信息")
+    private Object attach;
+}

+ 5 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/domain/WalletReceipts.java

@@ -80,4 +80,9 @@ public class WalletReceipts extends SuperEntity {
      * 产生入账是匹配的规则
      */
     private InviteReceiptsRoleVo ruler;
+
+    /**
+     * 附加信息
+     */
+    private Object attach;
 }

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

@@ -1,8 +1,84 @@
 package com.zhongshu.reward.server.core.service.Impl;
 
+import com.zhongshu.reward.client.model.param.GoodsReceiptsParam;
+import com.zhongshu.reward.client.ret.ResultContent;
+import com.zhongshu.reward.client.ret.ResultState;
+import com.zhongshu.reward.client.type.ReceiptsStatus;
+import com.zhongshu.reward.client.type.ReceiptsType;
+import com.zhongshu.reward.server.core.dao.WalletDao;
+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 com.zhongshu.reward.server.core.service.WalletService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
 /**
  * @author wjf
  * @date 2024/8/5
  */
+@Service
 public class WalletFeignServiceImpl {
+
+    @Autowired
+    WalletReceiptsDao walletReceiptsDao;
+
+    @Autowired
+    WalletDao walletDao;
+
+    @Autowired
+    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();
+    }
 }

+ 12 - 4
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/WalletReceiptsService.java

@@ -132,8 +132,12 @@ public class WalletReceiptsService {
         Long endTime = DateUtils.lastMonthEndTime();
         List<WalletReceipts> list = walletReceiptsDao.listMonth(startTime, endTime, day);
 
-        List<WalletReceipts> receipts = new ArrayList<>();
-        List<Wallet> wallets = new ArrayList<>();
+//        List<WalletReceipts> receipts = new ArrayList<>();
+//        List<Wallet> wallets = new ArrayList<>();
+
+        if (list==null || list.isEmpty()){
+            return;
+        }
 
         //首次订购
         list.forEach(it -> {
@@ -150,6 +154,10 @@ public class WalletReceiptsService {
             return null;
         }).collect(Collectors.toList());
 
+        if (keep.isEmpty()){
+            return;
+        }
+
         keep.forEach(it->{
             boolean cancel = vipUserRecordDao.existsByCpIdAndSucIn(it.getUserId(), List.of(-1, 5));
             if (!cancel){//无退订消息
@@ -164,8 +172,8 @@ public class WalletReceiptsService {
                 }
             }
         });
-        walletDao.saveAll(wallets);
-        walletReceiptsDao.saveAll(receipts);
+//        walletDao.saveAll(wallets);
+//        walletReceiptsDao.saveAll(receipts);
 
     }