| | |
| | | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion; |
| | | import cc.mrbird.febs.mall.dto.ApiMallScoreSignRecordDto; |
| | | import cc.mrbird.febs.mall.dto.ScoreSettingDto; |
| | | import cc.mrbird.febs.mall.entity.DataDictionaryCustom; |
| | | import cc.mrbird.febs.mall.entity.MallMember; |
| | | import cc.mrbird.febs.mall.entity.MallMemberWallet; |
| | | import cc.mrbird.febs.mall.entity.MallScoreSignRecord; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper; |
| | | import cc.mrbird.febs.mall.mapper.MallMemberMapper; |
| | | import cc.mrbird.febs.mall.mapper.MallMemberWalletMapper; |
| | | import cc.mrbird.febs.mall.mapper.MallScoreSignRecordMapper; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberService; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | | import cc.mrbird.febs.mall.service.IMallMoneyFlowService; |
| | | import cc.mrbird.febs.mall.service.IScoreService; |
| | | import cc.mrbird.febs.mall.vo.ApiMallScoreSignRecordVo; |
| | | import cc.mrbird.febs.mall.vo.ScoreSignVo; |
| | | import cn.hutool.core.date.DateField; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | private final MallScoreSignRecordMapper mallScoreSignRecordMapper; |
| | | private final IMallMoneyFlowService mallMoneyFlowService; |
| | | private final IApiMallMemberWalletService walletService; |
| | | private final MallMemberMapper mallMemberMapper; |
| | | |
| | | @Override |
| | | public ScoreSignVo scoreSign() { |
| | |
| | | |
| | | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(member.getId()); |
| | | |
| | | MallScoreSignRecord mallScoreSignRecord = mallScoreSignRecordMapper.selectRecentSignRecord(member.getId()); |
| | | |
| | | ScoreSignVo scoreSign = new ScoreSignVo(); |
| | | scoreSign.setMineScore(wallet.getPrizeScore().intValue()); |
| | | scoreSign.setHasSignDays(mallScoreSignRecord == null ? 0 : 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; |
| | | } |
| | | |
| | | @Override |
| | | public MallScoreSignRecord judgeScoreIsContinuity(MallScoreSignRecord mallScoreSignRecord) { |
| | | if (mallScoreSignRecord.getSignTime() == null) { |
| | | return mallScoreSignRecord; |
| | | } |
| | | |
| | | // 若最新签到日期,与当天相差大于一天,则更新数据库(避免定时器更新失败) |
| | | if (DateUtil.betweenDay(mallScoreSignRecord.getSignTime(), new Date(), true) > 1 || mallScoreSignRecord.getTotalCnt() == 7) { |
| | | mallScoreSignRecord.setTotalCnt(0); |
| | | mallScoreSignRecordMapper.updateById(mallScoreSignRecord); |
| | | } |
| | | return mallScoreSignRecord; |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiMallScoreSignRecordVo> findMallScoreSignRecordList(ApiMallScoreSignRecordDto apiMallScoreSignRecordDto) { |
| | | |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | IPage<ApiMallScoreSignRecordVo> page = new Page<>(apiMallScoreSignRecordDto.getPageNum(), apiMallScoreSignRecordDto.getPageSize()); |
| | | apiMallScoreSignRecordDto.setMemberId(member.getId()); |
| | | IPage<ApiMallScoreSignRecordVo> apiMallScoreSignRecordVos = mallScoreSignRecordMapper.selectApiOrderListInPage(page, apiMallScoreSignRecordDto); |
| | | return apiMallScoreSignRecordVos.getRecords(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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("签到活动未开启"); |
| | | } |
| | | Integer signScore = Integer.parseInt(signScoreDic.getValue()); |
| | | |
| | | MallScoreSignRecord mallScoreSignRecord = mallScoreSignRecordMapper.selectRecentSignRecord(member.getId()); |
| | | if (mallScoreSignRecord == null) { |
| | | mallScoreSignRecord = new MallScoreSignRecord(); |
| | | } |
| | | |
| | | if (mallScoreSignRecord.getSignTime() != null && DateUtil.between(mallScoreSignRecord.getSignTime(), new Date(), DateUnit.DAY) == 0) { |
| | | throw new FebsException("今天已签到"); |
| | | if (mallScoreSignRecord.getSignTime() != null && DateUtil.betweenDay(mallScoreSignRecord.getSignTime(), new Date(), true) == 0) { |
| | | 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()); |
| | | |
| | | 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; |
| | | MallMember mallMember = mallMemberMapper.selectById(member.getId()); |
| | | Date createdTime = mallMember.getCreatedTime(); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | } |