src/main/java/cc/mrbird/febs/mall/controller/ApiMallMemberController.java
@@ -116,4 +116,10 @@ memberService.bindPhone(accountAndCodeDto); return new FebsResponse().success().message("绑定成功"); } @ApiOperation(value = "可提现金额") @GetMapping(value = "/canWithdrawal") public FebsResponse canWithdrawal() { return new FebsResponse().success().data(memberService.canMoney()); } } src/main/java/cc/mrbird/febs/mall/mapper/MallMoneyFlowMapper.java
@@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Param; import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -30,4 +31,6 @@ List<MallMoneyFlow> selectMoneyFlowProfitByDate(@Param("date") Date date); int updateIsReturnByMemberId(@Param("isReturn") Integer isReturn, @Param("memberId") Long memberId); BigDecimal selectProfitByDateAndMemberId(Long memberId); } src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java
@@ -45,9 +45,10 @@ @Autowired private IApiMallMemberService memberService; @Scheduled(cron = "0 0 1 * * ?") @Scheduled(cron = "0 1 0 * * ?") @Transactional(rollbackFor = Exception.class) public void profitJob() { log.info("推荐人返利执行"); DateTime yesterday = DateUtil.yesterday(); List<MallMoneyFlow> flows = moneyFlowMapper.selectMoneyFlowProfitByDate(yesterday); src/main/java/cc/mrbird/febs/mall/service/IApiMallMemberService.java
@@ -40,4 +40,6 @@ MallMemberPayment findMemberPayment(); void bindPhone(AccountAndCodeDto accountAndCodeDto); BigDecimal canMoney(); } src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
@@ -388,6 +388,17 @@ throw new FebsException("未设置收款方式"); } BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId); MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); if (profit != null) { // 可提现 BigDecimal canMoney = wallet.getBalance().subtract(profit); if(withdrawalDto.getAmount().compareTo(canMoney) > 0) { throw new FebsException("提现金额不足"); } } walletService.reduceBalance(withdrawalDto.getAmount(), memberId); String orderNo = MallUtils.getOrderNum("W"); this.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1); @@ -426,4 +437,19 @@ member.setBindPhone(accountAndCodeDto.getAccount()); this.baseMapper.updateById(member); } @Override public BigDecimal canMoney() { Long memberId = LoginUserUtil.getLoginUser().getId(); MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId); BigDecimal canMoney = wallet.getBalance(); if (profit != null) { if(canMoney.compareTo(BigDecimal.ZERO) > 0) { canMoney = canMoney.subtract(profit); } } return canMoney; } } src/main/resources/mapper/modules/MallMoneyFlowMapper.xml
@@ -84,7 +84,7 @@ <select id="selectMoneyFlowProfitByDate" resultType="cc.mrbird.febs.mall.entity.MallMoneyFlow"> select a.member_id, sum(a.amount) amount from mall_money_flow a where a.type in (1, 2) and date_format(now(), '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d') where a.type in (1, 2) and date_format(a.created_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d') and is_return is null group by a.member_id; </select> @@ -94,4 +94,8 @@ set is_return=#{isReturn} where member_id=#{memberId} and type in (1, 2) </update> <select id="selectProfitByDateAndMemberId" resultType="java.math.BigDecimal"> select sum(a.amount) from mall_money_flow a where member_id=#{memberId} and type in (1,2) and date_format(a.CREATED_TIME, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d'); </select> </mapper>