| | |
| | | import cc.mrbird.febs.mall.mapper.MallMoneyFlowMapper; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberService; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | | import cc.mrbird.febs.mall.service.IMemberProfitService; |
| | | import cc.mrbird.febs.mall.service.impl.CommonService; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "system", name = "job", havingValue = "true") |
| | | public class ProfitJob { |
| | | |
| | | @Autowired |
| | | private MallMoneyFlowMapper moneyFlowMapper; |
| | | private IMemberProfitService memberProfitService; |
| | | |
| | | @Autowired |
| | | private MallMemberMapper memberMapper; |
| | | |
| | | @Autowired |
| | | private IApiMallMemberWalletService memberWalletService; |
| | | |
| | | @Autowired |
| | | private IApiMallMemberService memberService; |
| | | |
| | | @Scheduled(cron = "0 1 0 * * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | /** |
| | | * 代理分红 |
| | | */ |
| | | @Scheduled(cron = "0 30 0 * * ?") |
| | | public void profitJob() { |
| | | log.info("推荐人返利执行"); |
| | | DateTime yesterday = DateUtil.yesterday(); |
| | | List<MallMoneyFlow> flows = moneyFlowMapper.selectMoneyFlowProfitByDate(yesterday); |
| | | memberProfitService.agentProfit(null); |
| | | } |
| | | |
| | | if (CollUtil.isEmpty(flows)) { |
| | | return; |
| | | } |
| | | @Scheduled(cron = "0 30 1 * * ?") |
| | | public void storeAndDirectorJob() { |
| | | memberProfitService.storeAndDirectorProfit(null); |
| | | } |
| | | |
| | | for (MallMoneyFlow flow : flows) { |
| | | MallMember member = memberMapper.selectById(flow.getMemberId()); |
| | | /** |
| | | * 感恩奖 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ?") |
| | | public void thankfulJob() { |
| | | memberProfitService.thankfulProfit(null); |
| | | } |
| | | |
| | | List<MallMember> child = memberMapper.selectByIdAndNoLevel(member.getInviteId(), AgentLevelEnum.ZERO_LEVEL.name()); |
| | | if (CollUtil.isEmpty(child)) { |
| | | continue; |
| | | } |
| | | int size = child.size(); |
| | | BigDecimal needReturn = flow.getAmount().multiply(BigDecimal.valueOf(0.1)); |
| | | |
| | | String orderNo = MallUtils.getOrderNum("R"); |
| | | String remarkFormat = "{}, 用户:{}, 利润分红: {}"; |
| | | /** |
| | | * 静态分红 |
| | | */ |
| | | @Scheduled(cron = "0 0 0 * * ?") |
| | | public void staticProfitJob() { |
| | | memberProfitService.staticProfit(null); |
| | | } |
| | | |
| | | BigDecimal returnMoney = needReturn.divide(BigDecimal.valueOf(size), 2, RoundingMode.DOWN); |
| | | for (MallMember mallMember : child) { |
| | | memberWalletService.addBalance(returnMoney, mallMember.getId()); |
| | | |
| | | String remark = StrUtil.format(remarkFormat, DateUtil.format(yesterday, "yyyy-MM-dd"), member.getName(), returnMoney); |
| | | memberService.addMoneyFlow(mallMember.getId(), returnMoney, MoneyFlowTypeEnum.PARENT_BONUS.getValue(), orderNo, null, remark, member.getId(), null); |
| | | } |
| | | |
| | | String remark = StrUtil.format(remarkFormat, DateUtil.format(yesterday, "yyyy-MM-dd"), member.getName(), needReturn); |
| | | memberService.addMoneyFlow(member.getId(), needReturn.negate(), MoneyFlowTypeEnum.PARENT_BONUS.getValue(), orderNo, null, remark, null, null); |
| | | memberWalletService.reduceBalance(needReturn, member.getId()); |
| | | |
| | | moneyFlowMapper.updateIsReturnByMemberId(MallMoneyFlow.IS_RETURN_Y, flow.getMemberId()); |
| | | } |
| | | /** |
| | | * 排名奖 每月1号 |
| | | */ |
| | | @Scheduled(cron = "0 30 0 1 * ?") |
| | | public void rankJob() { |
| | | memberProfitService.rankProfit(); |
| | | } |
| | | } |