Просмотр исходного кода

提现失败自动补偿一次

wujiefeng 9 месяцев назад
Родитель
Сommit
570bf9267d

+ 58 - 0
RewardServer/src/main/java/com/zhongshu/reward/server/core/controller/TestController.java

@@ -0,0 +1,58 @@
+package com.zhongshu.reward.server.core.controller;
+
+import com.zhongshu.reward.client.ret.ResultContent;
+import com.zhongshu.reward.server.core.domain.VipUserRecord;
+import com.zhongshu.reward.server.core.service.Impl.InviteRecordFeignServiceImpl;
+import com.zhongshu.reward.server.core.service.WalletReceiptsService;
+import com.zhongshu.reward.server.core.util.DateUtils;
+import com.zhongshu.vip.client.model.param.VipUserParam;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author wjf
+ * @date 2024/8/16
+ */
+@Slf4j
+@RestController
+@RequestMapping("/test")
+@Api(tags = "测试")
+public class TestController {
+
+    @Autowired
+    WalletReceiptsService walletReceiptsService;
+
+    @Autowired
+    InviteRecordFeignServiceImpl inviteRecordFeignService;
+
+    @ApiOperation("会员消息")
+    @PostMapping("vipUser")
+    public Object vipUser(@RequestBody VipUserParam param){
+        VipUserRecord vipUserRecord = new VipUserRecord();
+        BeanUtils.copyProperties(param, vipUserRecord, "createTime");
+        vipUserRecord.setOperateTime(DateUtils.timeToLong(param.getCreateTime(), DateUtils.FORMAT_LONG));
+        walletReceiptsService.receipts(vipUserRecord);
+        return ResultContent.buildSuccess();
+    }
+
+    @ApiOperation("结算奖励")
+    @PostMapping("settle")
+    public Object settle(){
+        walletReceiptsService.settle();
+        return ResultContent.buildSuccess();
+    }
+
+    @ApiOperation("生成持续订购返利")
+    @PostMapping("autoReceipts")
+    public Object autoReceipts(){
+        walletReceiptsService.autoReceipts();
+        return ResultContent.buildSuccess();
+    }
+}

+ 23 - 10
RewardServer/src/main/java/com/zhongshu/reward/server/core/service/WxTransferService.java

@@ -86,8 +86,8 @@ public class WxTransferService {
      * @param param
      * @return
      */
-    @Transactional
-    public Object transfer(WalletTransferParam param){
+//    @Transactional
+    public ResultContent transfer(WalletTransferParam param){
         String userId = authHelper.getCurrentUser().getUserId();
         OperateDisable operateDisable = operateDisableDao.findTopByUserIdAndType(userId, OperateType.TRANSFER);
         if (ObjectUtils.isNotEmpty(operateDisable)){
@@ -121,6 +121,15 @@ public class WxTransferService {
         transferModel.setTotalNum(detailList.size());
         transferModel.setTransferDetailList(detailList);
 
+        //初始化提现单
+        WxTransferBatch wxTransferBatch = new WxTransferBatch();
+        wxTransferBatch.setBatchNo(outBatchNo);
+        wxTransferBatch.setDetailNo(outDetailNo);
+        wxTransferBatch.setWallet(wallet);
+        wxTransferBatch.setTotal(param.getTotal());
+        wxTransferBatch.setChannel(TransferChannel.WeChat);
+        wxTransferBatch.setBeforeWalletInfo(wallet);
+
         InitiateBatchTransferResponse response = wechatService.initiateBatchTransfer(transferModel, param.getAppid());
         if (response==null){
             OperateDisable newDisable = new OperateDisable();
@@ -128,19 +137,23 @@ public class WxTransferService {
             newDisable.setType(OperateType.TRANSFER);
             newDisable.setTTL(new Date(this.dbHelper.getTime() + 60*60 * 1000L));
             operateDisableDao.save(newDisable);
-            return ResultContent.build(ResultState.Fail);
+            wxTransferBatch.setTransferStatus(TransferStatus.FAIL);
+            wxTransferBatch.setFailReason("提现失败请一小时后再次尝试");
+            wxTransferBatchDao.save(wxTransferBatch);
+            //失败做一次补偿
+            return transfer(param);
         }
-        WxTransferBatch wxTransferBatch = new WxTransferBatch();
-        wxTransferBatch.setBatchNo(outBatchNo);
-        wxTransferBatch.setDetailNo(outDetailNo);
-        wxTransferBatch.setWallet(wallet);
-        wxTransferBatch.setTotal(param.getTotal());
-        wxTransferBatch.setChannel(TransferChannel.WeChat);
-        wxTransferBatch.setBeforeWalletInfo(wallet);
+//        wxTransferBatch.setBatchNo(outBatchNo);
+//        wxTransferBatch.setDetailNo(outDetailNo);
+//        wxTransferBatch.setWallet(wallet);
+//        wxTransferBatch.setTotal(param.getTotal());
+//        wxTransferBatch.setChannel(TransferChannel.WeChat);
+//        wxTransferBatch.setBeforeWalletInfo(wallet);
         wxTransferBatch.setBatchStatus(response.getBatchStatus());
         wxTransferBatch.setWxBatchId(response.getBatchId());
         wxTransferBatch.setTransferStatus(TransferStatus.PROCESSING);
         wxTransferBatchDao.save(wxTransferBatch);
+
         wallet.setAmount(wallet.getAmount().subtract(param.getTotal()));
         wallet.setTodayTransferAmount(wallet.getTodayTransferAmount().add(param.getTotal()));
         walletDao.save(wallet);