| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | private final MallMemberBankMapper mallMemberBankMapper; |
| | | private final MallMemberWithdrawMapper mallMemberWithdrawMapper; |
| | | private final IApiMallMemberService mallMemberService; |
| | | private final MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | |
| | | @Override |
| | | public ScoreSignVo scoreSign() { |
| | |
| | | ScoreSignVo scoreSign = new ScoreSignVo(); |
| | | scoreSign.setMineScore(wallet.getPrizeScore().intValue()); |
| | | |
| | | DataDictionaryCustom signScpreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SIGN_SCORE.getType(), DataDictionaryEnum.SIGN_SCORE.getCode()); |
| | | MallScoreSignRecord mallScoreSignRecord = mallScoreSignRecordMapper.selectRecentSignRecord(member.getId()); |
| | | if (mallScoreSignRecord == null) { |
| | | scoreSign.setHasSignDays(0); |
| | | } else { |
| | | mallScoreSignRecord = judgeScoreIsContinuity(mallScoreSignRecord); |
| | | scoreSign.setHasSignDays(mallScoreSignRecord.getTotalCnt()); |
| | | } |
| | | |
| | | DataDictionaryCustom signScpreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SCORE_SIGN_SETTING.getType(), DataDictionaryEnum.SCORE_SIGN_SETTING.getCode()); |
| | | if (signScpreDic != null) { |
| | | scoreSign.setSetting(Integer.parseInt(signScpreDic.getValue())); |
| | | scoreSign.setSetting(JSONObject.parseObject(signScpreDic.getValue(), ScoreSettingDto.class)); |
| | | } |
| | | return scoreSign; |
| | | } |
| | |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | BigDecimal voucherCntMember = mallMemberWallet.getVoucherCnt(); |
| | | if(voucherCntMember.compareTo(voucherCnt) < 0){ |
| | | throw new FebsException("绿色积分不足"); |
| | | throw new FebsException("数量不足"); |
| | | } |
| | | |
| | | DataDictionaryCustom scorePriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | |
| | | voucherAmount, |
| | | MoneyFlowTypeEnum.VOUCHER_SALE.getValue(), |
| | | voucherNo, |
| | | FlowTypeEnum.VOUCHER_AMOUNT.getValue()); |
| | | FlowTypeEnum.BALANCE.getValue()); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void withdrawal(WithdrawalDto withdrawalDto) { |
| | | |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = mallMemberMapper.selectById(memberId); |
| | | if (StrUtil.isBlank(mallMember.getTradePassword())) { |
| | |
| | | } |
| | | |
| | | if (withdrawalDto.getAmount().compareTo(cashOutSettingVo.getMinCashOut()) < 0) { |
| | | throw new FebsException("最小提现金额为"+cashOutSettingVo.getMinCashOut().setScale(2,BigDecimal.ROUND_DOWN)); |
| | | throw new FebsException("最小提现金额为"+cashOutSettingVo.getMinCashOut().setScale(2, RoundingMode.DOWN)); |
| | | } |
| | | |
| | | MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(withdrawalDto.getBankId()); |
| | |
| | | } |
| | | |
| | | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | // 可提现 |
| | | BigDecimal canMoney = wallet.getVoucherAmount(); |
| | | BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId); |
| | | |
| | | BigDecimal canMoney = wallet.getCommission(); |
| | | if (profit != null) { |
| | | if(canMoney.compareTo(BigDecimal.ZERO) > 0) { |
| | | canMoney = canMoney.subtract(profit); |
| | | } |
| | | } |
| | | |
| | | if(withdrawalDto.getAmount().compareTo(canMoney) > 0) { |
| | | throw new FebsException("金额不足"); |
| | | } |
| | | |
| | | walletService.reduce(withdrawalDto.getAmount(), memberId, "voucherAmount"); |
| | | int flag = walletService.reduce(withdrawalDto.getAmount(), memberId, "commission"); |
| | | if (flag == 2) { |
| | | throw new FebsException("请刷新页面后重新提现"); |
| | | } |
| | | |
| | | String orderNo = MallUtils.getOrderNum("W"); |
| | | |
| | | MallMemberWithdraw withdraw = new MallMemberWithdraw(); |
| | |
| | | withdraw.setAmount(withdrawalDto.getAmount()); |
| | | withdraw.setStatus(1); |
| | | withdraw.setAmountFee(BigDecimal.ZERO); |
| | | withdraw.setRemark(AppContants.MEMBER_WITHDRAW_VOUCHER_AMOUNT); |
| | | withdraw.setWtihdrawTypeId(mallMemberBank.getId()); |
| | | mallMemberWithdrawMapper.insert(withdraw); |
| | | |
| | | mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.VOUCHER_AMOUNT.getValue()); |
| | | mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.COMMISSION.getValue()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void sign() { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | |
| | | DataDictionaryCustom signScoreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SIGN_SCORE.getType(), |
| | | DataDictionaryEnum.SIGN_SCORE.getCode()); |
| | | if (signScoreDic == null) { |
| | | throw new FebsException("签到活动未开启"); |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SCORE_SIGN_SETTING.getType(), DataDictionaryEnum.SCORE_SIGN_SETTING.getCode()); |
| | | if (dic == null) { |
| | | throw new FebsException("暂未设置积分"); |
| | | } |
| | | Integer signScore = Integer.parseInt(signScoreDic.getValue()); |
| | | |
| | | MallScoreSignRecord mallScoreSignRecord = mallScoreSignRecordMapper.selectRecentSignRecord(member.getId()); |
| | | if (mallScoreSignRecord == null) { |
| | |
| | | } |
| | | |
| | | if (mallScoreSignRecord.getSignTime() != null && DateUtil.betweenDay(mallScoreSignRecord.getSignTime(), new Date(), true) == 0) { |
| | | throw new FebsException("今日已签到"); |
| | | throw new FebsException("今天已签到"); |
| | | } |
| | | /** |
| | | * 用户注册时间开始计算 |
| | | * 判断签到时间是否大于规定的signScoreDays,超出则获得的积分数为signScoreCnt |
| | | */ |
| | | // Integer count = mallScoreSignRecordMapper.selectCountByMemberId(member.getId()); |
| | | DataDictionaryCustom signScoreDaysDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SIGN_SCORE_DAYS.getType(), |
| | | DataDictionaryEnum.SIGN_SCORE_DAYS.getCode()); |
| | | Integer signScoreDays = Integer.parseInt(signScoreDaysDic.getValue()); |
| | | |
| | | MallMember mallMember = mallMemberMapper.selectById(member.getId()); |
| | | Date createdTime = mallMember.getCreatedTime(); |
| | | mallScoreSignRecord = judgeScoreIsContinuity(mallScoreSignRecord); |
| | | |
| | | DateTime dateTime = DateUtil.offsetDay(createdTime, signScoreDays); |
| | | /** |
| | | * 签到时间不在系统设置的第一个阶段,则获取签到设置-签到积分后续获得积分数量 |
| | | */ |
| | | if(DateUtil.compare(dateTime, new Date()) < 0){ |
| | | DataDictionaryCustom signScoreCntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SIGN_SCORE_CNT.getType(), |
| | | DataDictionaryEnum.SIGN_SCORE_CNT.getCode()); |
| | | Integer signScoreCnt = Integer.parseInt(signScoreCntDic.getValue()); |
| | | signScore = signScoreCnt; |
| | | ScoreSettingDto scoreSetting = JSONObject.parseObject(dic.getValue(),ScoreSettingDto.class); |
| | | int days = mallScoreSignRecord.getTotalCnt() == null ? 1 : mallScoreSignRecord.getTotalCnt() + 1; |
| | | switch (days) { |
| | | case 1: |
| | | if (scoreSetting.getSignInOne() == null) { |
| | | throw new FebsException("积分未设置"); |
| | | } |
| | | mallScoreSignRecord.setScore(scoreSetting.getSignInOne()); |
| | | break; |
| | | case 2: |
| | | if (scoreSetting.getSignInTwo() == null) { |
| | | throw new FebsException("积分未设置"); |
| | | } |
| | | mallScoreSignRecord.setScore(scoreSetting.getSignInTwo()); |
| | | break; |
| | | case 3: |
| | | if (scoreSetting.getSignInThree() == null) { |
| | | throw new FebsException("积分未设置"); |
| | | } |
| | | mallScoreSignRecord.setScore(scoreSetting.getSignInThree()); |
| | | break; |
| | | case 4: |
| | | if (scoreSetting.getSignInFour() == null) { |
| | | throw new FebsException("积分未设置"); |
| | | } |
| | | mallScoreSignRecord.setScore(scoreSetting.getSignInFour()); |
| | | break; |
| | | case 5: |
| | | if (scoreSetting.getSignInFive() == null) { |
| | | throw new FebsException("积分未设置"); |
| | | } |
| | | mallScoreSignRecord.setScore(scoreSetting.getSignInFive()); |
| | | break; |
| | | case 6: |
| | | if (scoreSetting.getSignInSix() == null) { |
| | | throw new FebsException("积分未设置"); |
| | | } |
| | | mallScoreSignRecord.setScore(scoreSetting.getSignInSix()); |
| | | break; |
| | | case 7: |
| | | if (scoreSetting.getSignInSeven() == null) { |
| | | throw new FebsException("积分未设置"); |
| | | } |
| | | mallScoreSignRecord.setScore(scoreSetting.getSignInSeven()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | mallScoreSignRecord.setMemberId(member.getId()); |
| | | mallScoreSignRecord.setTotalCnt(signScore); |
| | | mallScoreSignRecord.setTotalCnt(days); |
| | | mallScoreSignRecord.setSignTime(new Date()); |
| | | mallScoreSignRecord.setScore(signScore); |
| | | mallScoreSignRecordMapper.insert(mallScoreSignRecord); |
| | | |
| | | BigDecimal amount = BigDecimal.valueOf(mallScoreSignRecord.getScore()); |
| | | walletService.add(amount, member.getId(), "prizeScore"); |
| | | mallMoneyFlowService.addMoneyFlow( |
| | | member.getId(), |
| | | amount, |
| | | MoneyFlowTypeEnum.SCORE_SIGN.getValue(), |
| | | null, |
| | | FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), amount, MoneyFlowTypeEnum.SCORE_SIGN.getValue(), null, FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | } |
| | | } |