From 27408731d4d6857b025294822d6298b7d721a10e Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 19 十二月 2024 09:57:57 +0800
Subject: [PATCH] 合并代码
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WalletController.java | 122 ++++++++++++++++++++++++++++++++--------
1 files changed, 97 insertions(+), 25 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 e6c1e7f..d8f9645 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,62 +1,134 @@
package com.ruoyi.account.controller;
+import cn.hutool.core.collection.CollectionUtil;
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.core.web.domain.AjaxResult;
+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.math.BigDecimal;
+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 {
@Resource
private BalanceChangeRecordService balanceChangeRecordService;
+ @Resource
+ 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 = {"小程序-个人中心-我的钱包-钱包详情"})
- public AjaxResult detail() {
- Long userId = SecurityUtils.getUserId();
- // TODO 查询钱包详情
- WalletVO walletVO = new WalletVO();
- return AjaxResult.success(walletVO);
+ @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 AjaxResult 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 AjaxResult.success(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());
+ if (CollectionUtil.isNotEmpty(orderIds)){
+ 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);
}
-// /**
-// * 充值
-// */
-// @GetMapping("recharge")
-// @ApiOperation(value = "充值", notes = "钱包充值")
-// public AjaxResult recharge(@ApiParam(value = "充值金额", required = true) @RequestParam BigDecimal amount) {
-// Long userId = SecurityUtils.getUserId();
-// String openId;
-// // 商户号
-// String partnerTradeNo;
-// // TODO 充值
-// return AjaxResult.success();
-// }
+ /**
+ * 充值
+ */
+ @GetMapping("recharge")
+ @ApiOperation(value = "充值", notes = "钱包充值")
+ public R<Void> recharge(@ApiParam(value = "充值金额", required = true) @RequestParam BigDecimal amount) {
+ LoginUser loginUserApplet = tokenService.getLoginUserApplet();
+ AppUser appUser = appUserService.getById(loginUserApplet.getUserid());
+ String wxOpenid = appUser.getWxOpenid();
+ // 商户号
+ String partnerTradeNo;
+ // TODO 充值
+ return R.ok();
+ }
}
--
Gitblit v1.7.1