| | |
| | | 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.other.api.feignClient.OrderClient; |
| | | 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 feignClient.RemoteOrderClient; |
| | | import feignClient.RemoteOrderGoodsClient; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import model.Order; |
| | | import model.OrderGood; |
| | | 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.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.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api(tags = "小程序-个人中心-我的钱包") |
| | |
| | | private RemoteOrderGoodsClient remoteOrderGoodsClient; |
| | | @Resource |
| | | private AppUserService appUserService; |
| | | @Resource |
| | | private VipSettingService vipSettingService; |
| | | |
| | | /** |
| | | * 钱包详情 |
| | |
| | | @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); |
| | | } |
| | | |
| | |
| | | @RequestParam(required = false) Integer changeType, |
| | | @ApiParam(value = "创建时间") |
| | | @RequestParam(required = false) |
| | | @DateTimeFormat(pattern = "yyyy-MM") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | LocalDate createTime) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | |
| | | LocalDateTime localDateTime = null; |
| | | LocalDateTime startTime = null; |
| | | LocalDateTime endTime = null; |
| | | if (createTime != null) { |
| | | LocalTime specificTime = LocalTime.of(0, 0); |
| | | localDateTime = createTime.atTime(specificTime); |
| | | // 将 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) |
| | | .eq(createTime != null, BalanceChangeRecord::getCreateTime, localDateTime) |
| | | .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()); |
| | | 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(); |
| | | } |
| | | |
| | | } |