From 79e82d188a24ad92395ac4b39c1a49266a647c3f Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 04 十二月 2024 15:44:20 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WalletController.java |   72 +++++++++++++++++++++++++++++++++---
 1 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WalletController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WalletController.java
index 291de10..8c47f79 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WalletController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WalletController.java
@@ -1,25 +1,39 @@
 package com.ruoyi.account.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.account.api.model.AppUser;
 import com.ruoyi.account.api.model.BalanceChangeRecord;
+import com.ruoyi.account.service.AppUserService;
 import com.ruoyi.account.service.BalanceChangeRecordService;
+import com.ruoyi.account.service.VipSettingService;
 import com.ruoyi.account.service.WalletService;
 import com.ruoyi.account.vo.WalletVO;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.common.security.utils.SecurityUtils;
+import com.ruoyi.order.feignClient.RemoteOrderGoodsClient;
+import com.ruoyi.order.model.Order;
+import com.ruoyi.other.api.domain.VipSetting;
 import com.ruoyi.system.api.model.LoginUser;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.YearMonth;
 import java.util.List;
+import java.util.stream.Collectors;
 
-@Api("钱包")
+@Api(tags = "小程序-个人中心-我的钱包")
 @RestController
 @RequestMapping("wallet")
 public class WalletController extends BaseController {
@@ -29,27 +43,73 @@
     private TokenService tokenService;
     @Resource
     private WalletService walletService;
+    @Resource
+    private RemoteOrderGoodsClient remoteOrderGoodsClient;
+    @Resource
+    private AppUserService appUserService;
+    @Resource
+    private VipSettingService vipSettingService;
 
     /**
      * 钱包详情
      */
     @GetMapping("detail")
-    @ApiOperation(value = "钱包详情", notes = "钱包详情", tags = {"小程序-个人中心-我的钱包-钱包详情"})
+    @ApiOperation(value = "钱包详情", notes = "钱包详情")
     public R<WalletVO> detail() {
         LoginUser loginUserApplet = tokenService.getLoginUserApplet();
+        VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid());
         WalletVO walletVO = walletService.getWalletByUserId(loginUserApplet.getUserid());
+        walletVO.setVipWithdrawalFee(vipSetting.getVipWithdrawalFee());
         return R.ok(walletVO);
     }
 
     /**
      * 变更明细
      */
-    @ApiOperation(value = "变更明细", notes = "变更明细", tags = {"小程序-个人中心-我的钱包-变更记录"})
+    @ApiOperation(value = "变更明细", notes = "变更明细")
     @GetMapping("change")
-    public R<List<BalanceChangeRecord>> change() {
+    public R<List<BalanceChangeRecord>> change(@ApiParam(value = "变更类型")
+                                               @RequestParam(required = false) Integer changeType,
+                                               @ApiParam(value = "创建时间")
+                                               @RequestParam(required = false)
+                                               @DateTimeFormat(pattern = "yyyy-MM-dd")
+                                               LocalDate createTime) {
         Long userId = SecurityUtils.getUserId();
-        return R.ok(balanceChangeRecordService.list(new LambdaQueryWrapper<BalanceChangeRecord>()
-                .eq(BalanceChangeRecord::getAppUserId, userId)));
+
+        LocalDateTime startTime = null;
+        LocalDateTime endTime = null;
+        if (createTime != null) {
+            // 将 createTime 设置为当天的开始时间 (00:00)
+            startTime = createTime.atStartOfDay();
+
+            // 使用 YearMonth 来获取该月的最后一天
+            YearMonth yearMonth = YearMonth.from(createTime);
+            LocalDate lastDayOfMonth = yearMonth.atEndOfMonth();
+
+            // 将最后一天转换为 LocalDateTime,并设置为当天的最后一秒 (23:59:59.999)
+            endTime = lastDayOfMonth.atTime(LocalTime.MAX);
+        }
+
+        List<BalanceChangeRecord> list = balanceChangeRecordService.list(new LambdaQueryWrapper<BalanceChangeRecord>()
+                .eq(changeType != null, BalanceChangeRecord::getChangeType, changeType)
+                .between(startTime != null, BalanceChangeRecord::getCreateTime, startTime, endTime)
+                .eq(BalanceChangeRecord::getAppUserId, userId));
+
+        List<Long> orderIds = list.stream().map(BalanceChangeRecord::getOrderId).collect(Collectors.toList());
+        R<List<Order>> r = remoteOrderGoodsClient.getOrderListByIds(orderIds);
+        if (!R.isSuccess(r)){
+            return R.fail(r.getMsg());
+        }
+        List<Order> orderList = r.getData();
+        list.forEach(bc -> {
+            orderList.stream().filter(o -> o.getId().equals(bc.getOrderId())).findFirst().ifPresent(o -> {
+                Long appUserId = o.getAppUserId();
+                AppUser appUser = appUserService.getById(appUserId);
+                bc.setUserName(appUser.getName());
+                bc.setAmount(o.getPaymentAmount());
+            });
+        });
+        return R.ok(list);
     }
 
 //    /**

--
Gitblit v1.7.1