| | |
| | | package com.ruoyi.user.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.api.entity.Withdraw; |
| | | import com.ruoyi.order.api.entity.WithdrawDetailVO; |
| | | import com.ruoyi.order.api.feignClient.WithdrawClient; |
| | | import com.ruoyi.system.api.model.LoginUserInfo; |
| | | import com.ruoyi.user.entity.Withdraw; |
| | | import com.ruoyi.user.service.WithdrawService; |
| | | import com.ruoyi.user.vo.WithdrawListVO; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.math.BigDecimal; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private WithdrawService withdrawService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private WithdrawClient withdrawClient; |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @GetMapping("/withdrawList") |
| | | @ApiOperation(value = "提现列表", tags = {"用户端-个人中心-提现"}) |
| | | public R<WithdrawListVO> withdrawList() { |
| | | public R<WithdrawListVO> withdrawList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | return R.ok(withdrawService.withdrawList(loginUser.getUserid())); |
| | | return R.ok(withdrawService.withdrawList(loginUser.getUserid(), pageNum, pageSize)); |
| | | } |
| | | |
| | | @GetMapping("/withdrawDetail") |
| | | @ApiOperation(value = "提现详情", tags = {"用户端-个人中心-提现"}) |
| | | public R<WithdrawListVO> withdrawDetail() { |
| | | public R<WithdrawDetailVO> withdrawDetail(@RequestParam String orderId) { |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | return R.ok(withdrawService.withdrawList(loginUser.getUserid())); |
| | | return withdrawClient.withdrawDetailByUser(orderId); |
| | | } |
| | | |
| | | @GetMapping("/confirmWithdraw") |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true) |
| | | }) |
| | | public R<Boolean> confirmWithdraw(@RequestParam Integer orderId) { |
| | | |
| | | public synchronized R<Boolean> confirmWithdraw(@RequestParam String orderId) { |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | return R.ok(withdrawService.confirmWithdraw(orderId, loginUser.getUserid())); |
| | | if (redisService.hasKey(orderId)) { |
| | | return R.fail("该笔订单已申请提现"); |
| | | // return R.repeatedSubmission("请勿重复提交!"); |
| | | } |
| | | redisService.setCacheObject(orderId, "1", 10L, TimeUnit.SECONDS); |
| | | Boolean b = withdrawService.confirmWithdraw(orderId, loginUser.getUserid()); |
| | | |
| | | if (b){ |
| | | return R.ok(); |
| | | }else { |
| | | return R.fail("该笔订单已申请提现"); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/withdrawRecord") |
| | | @ApiOperation(value = "提现记录", tags = {"用户端-个人中心-提现"}) |
| | | public R<List<Withdraw>> withdrawRecord() { |
| | | public R<Page<Withdraw>> withdrawRecord(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | return R.ok(withdrawService.lambdaQuery().eq(Withdraw::getUserId, loginUser.getUserid()) |
| | | .eq(Withdraw::getIsDelete, 0).orderByDesc(Withdraw::getCreateTime).list()); |
| | | Page<Withdraw> data = withdrawClient.withdrawRecordList(loginUser.getUserid(), pageNum, pageSize).getData(); |
| | | BigDecimal b = BigDecimal.ZERO; |
| | | if (null != data) { |
| | | for (Withdraw record : data.getRecords()) { |
| | | b = b.add(record.getApplyForMoney()); |
| | | } |
| | | } |
| | | return R.ok(data); |
| | | } |
| | | |
| | | } |