xiaoyong931011
2023-03-09 3ea3c013bb241c05d0e6a2c4344d9b708ffa1e61
src/main/java/cc/mrbird/febs/mall/service/impl/ScoreServiceImpl.java
@@ -51,21 +51,13 @@
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(member.getId());
        MallScoreSignRecord mallScoreSignRecord = mallScoreSignRecordMapper.selectRecentSignRecord(member.getId());
        ScoreSignVo scoreSign = new ScoreSignVo();
        scoreSign.setMineScore(wallet.getPrizeScore().intValue());
        if (mallScoreSignRecord == null) {
            scoreSign.setHasSignDays(0);
        } else {
            mallScoreSignRecord = judgeScoreIsContinuity(mallScoreSignRecord);
            scoreSign.setHasSignDays(mallScoreSignRecord.getTotalCnt());
        }
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SCORE_SIGN_SETTING.getType(), DataDictionaryEnum.SCORE_SIGN_SETTING.getCode());
        if (dic != null) {
            scoreSign.setSetting(JSONObject.parseObject(dic.getValue(), ScoreSettingDto.class));
        DataDictionaryCustom signScpreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.SIGN_SCORE.getType(), DataDictionaryEnum.SIGN_SCORE.getCode());
        if (signScpreDic != null) {
            scoreSign.setSetting(Integer.parseInt(signScpreDic.getValue()));
        }
        return scoreSign;
    }
@@ -89,9 +81,11 @@
    public void sign() {
        MallMember member = LoginUserUtil.getLoginUser();
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SCORE_SIGN_SETTING.getType(), DataDictionaryEnum.SCORE_SIGN_SETTING.getCode());
        if (dic == null) {
            throw new FebsException("暂未设置积分");
        DataDictionaryCustom signScoreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.SIGN_SCORE.getType(),
                DataDictionaryEnum.SIGN_SCORE.getCode());
        if (signScoreDic == null) {
            throw new FebsException("签到活动未开启");
        }
        MallScoreSignRecord mallScoreSignRecord = mallScoreSignRecordMapper.selectRecentSignRecord(member.getId());
@@ -100,65 +94,23 @@
        }
        if (mallScoreSignRecord.getSignTime() != null && DateUtil.betweenDay(mallScoreSignRecord.getSignTime(), new Date(), true) == 0) {
            throw new FebsException("今天已签到");
            throw new FebsException("今日已签到");
        }
        mallScoreSignRecord = judgeScoreIsContinuity(mallScoreSignRecord);
        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;
        }
        Integer signScore = Integer.parseInt(signScoreDic.getValue());
        mallScoreSignRecord.setMemberId(member.getId());
        mallScoreSignRecord.setTotalCnt(days);
        mallScoreSignRecord.setTotalCnt(signScore);
        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());
    }
}