package com.stylefeng.guns.modular.api; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.modular.system.model.Withdrawal; import com.stylefeng.guns.modular.system.service.IUserInfoService; import com.stylefeng.guns.modular.system.service.IWithdrawalService; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.warpper.WithdrawalVo; import com.stylefeng.guns.modular.system.warpper.WithdrawalWarpper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 提现控制器 */ @Api @RestController @RequestMapping("") public class WithdrawalController { @Autowired private IWithdrawalService withdrawalService; @Autowired private IUserInfoService userInfoService; /** * 账户余额提现操作 * @param money * @param request * @return */ @ResponseBody @PostMapping("/api/withdrawal/withdrawal") @ApiOperation(value = "账户余额提现【1.1】", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "提现金额", name = "money", required = true, dataType = "double"), @ApiImplicitParam(value = "备注", name = "remark", required = true, dataType = "String"), @ApiImplicitParam(value = "语言类型(1=简体中文,2=英语,3=法语)", name = "language", required = false, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil withdrawal(Double money, String remark, Integer language, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return withdrawalService.withdrawal(money, uid, remark, language); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 获取历史提现数据 * @param pageNum * @param size * @param request * @return */ @ResponseBody @PostMapping("/api/withdrawal/queryWithdrawal") @ApiOperation(value = "获取历史提现数据【2.0】", tags = {"用户端-个人中心"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"), @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"), @ApiImplicitParam(value = "提现状态(1=待处理,2=已提现,3=提现失败)", name = "state", required = true, dataType = "int"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> queryWithdrawal(Integer pageNum, Integer size, Integer state, Integer language, HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List> list = withdrawalService.queryWithdrawal(uid, pageNum, size, state, language); List withdrawals = withdrawalService.selectList(new EntityWrapper().eq("userId", uid).eq("userType", 1).ne("flag", 3)); double withdrawn = withdrawals.stream().filter(s -> s.getState().compareTo(2) == 0).mapToDouble(Withdrawal::getMoney).sum(); double processing = withdrawals.stream().filter(s -> s.getState().compareTo(1) == 0).mapToDouble(Withdrawal::getMoney).sum(); double fail = withdrawals.stream().filter(s -> s.getState().compareTo(3) == 0).mapToDouble(Withdrawal::getMoney).sum(); for (Map map : list) { map.put("withdrawn", withdrawn); map.put("processing", processing); map.put("fail", fail); } return ResultUtil.success(WithdrawalWarpper.getWithdrawalWarpper(list)); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 内部调用审核提交结果的处理 * @param id 提现申请数据id * @param state 审核状态(1=同意,2=拒绝) * @return */ @ResponseBody @PostMapping("/base/withdrawal/queryWithdrawal") public ResultUtil withdrawalAudit(Integer id, Integer state){ try { return withdrawalService.withdrawalAudit(id, state); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } }