| | |
| | | |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jline.utils.Log; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | import java.text.DecimalFormat; |
| | | import java.text.Format; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Component |
| | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Autowired |
| | | private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | |
| | | @Autowired |
| | | private DappWalletService dappWalletService; |
| | | |
| | | /** |
| | | * 五分钟更新一次数据 |
| | | * 让挂机字表的状态为1:已生效 |
| | |
| | | igtOnHookPlanOrderItem.setState(1); |
| | | igtOnHookPlanOrderItemDao.updateById(igtOnHookPlanOrderItem); |
| | | if(2 == igtOnHookPlanOrderItem.getIsGoal()){ |
| | | //增加挂机主表的挂机总收益 |
| | | //如果中奖,增加挂机主表的挂机总收益 |
| | | Integer updateCount = igtOnHookPlanOrderDao.AddProfitById(igtOnHookPlanOrder.getId() |
| | | ,igtOnHookPlanOrderItem.getProfit()); |
| | | }else{ |
| | | //减少挂机剩余金额 |
| | | //如果不中奖,减少挂机剩余金额即减少本金 |
| | | Integer updateCount = igtOnHookPlanOrderDao.updateAvaAmountById(igtOnHookPlanOrder.getId() |
| | | ,igtOnHookPlanOrderItem.getAmount()); |
| | | } |
| | |
| | | IgtOnHookPlanOrderItem igtOnHookPlanOrderItem = igtOnHookPlanOrderItemDao.selectByOrderIdAndMemberIdAndState(orderId,memberId,2); |
| | | if(ObjectUtil.isEmpty(igtOnHookPlanOrderItem)){ |
| | | BigDecimal totalProfit = igtOnHookPlanOrderItemDao.selectTotalProfitByByOrderIdAndMemberIdAndState(orderId,memberId,1,2); |
| | | BigDecimal totalAmount = igtOnHookPlanOrderItemDao.selectTotalAmountByByOrderIdAndMemberIdAndState(orderId,memberId,1,2); |
| | | |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | String refererIds = dappMemberEntity.getRefererIds(); |
| | | List<String> refererIdList = StrUtil.split(refererIds, ",", -1, true, true); |
| | | //生成流水佣金和盈利分成和流水记录,返回剩余盈利 |
| | | BigDecimal profitSharingTotal = dappWalletService.updateLSYJYLFC(refererIdList, totalProfit); |
| | | //平台分成,返回剩余盈利 |
| | | BigDecimal systemTotal = dappWalletService.updatePTFC(memberId,totalProfit); |
| | | totalProfit = totalProfit.subtract(profitSharingTotal).subtract(systemTotal); |
| | | |
| | | //获取用户信息的是否盈利字段 |
| | | DappMemberEntity dappMember = dappMemberDao.selectById(memberId); |
| | | Integer isProfit = dappMember.getIsProfit() == null ? 1 : dappMember.getIsProfit(); |
| | | |
| | | BigDecimal totalAmount = igtOnHookPlanOrderItemDao.selectTotalAmountByByOrderIdAndMemberIdAndState(orderId,memberId,1,1); |
| | | igtOnHookPlanOrder.setState(2); |
| | | //一次挂机剩余的全部金额 |
| | | BigDecimal totalMoney = totalAmount.add(totalProfit).add(avaAmount); |
| | | BigDecimal totalMoney = BigDecimal.ZERO; |
| | | if(isProfit == 2){ |
| | | //设置成不盈利,只返回收益加剩余挂机总金额 |
| | | totalMoney = totalProfit.add(avaAmount); |
| | | }else{ |
| | | //设置成盈利,如果中奖,返回收益,如果没中奖,则返回本金,最后加上剩余总挂机金额 |
| | | totalMoney = totalProfit.add(totalAmount).add(avaAmount); |
| | | } |
| | | if(totalMoney.compareTo(planAmount)<=0){ |
| | | igtOnHookPlanOrder.setProfitState(2); |
| | | }else{ |
| | | igtOnHookPlanOrder.setProfitState(1); |
| | | } |
| | | igtOnHookPlanOrder.setProfit(totalProfit); |
| | | igtOnHookPlanOrderDao.updateById(igtOnHookPlanOrder); |
| | | |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | dappMemberEntity.setIsOnHook(3); |
| | | dappMemberDao.updateById(dappMemberEntity); |
| | | |
| | | DappWalletCoinEntity dappWalletCoinEntity = dappWalletCoinDao.selectByMemberId(memberId); |
| | | BigDecimal availableAmount = dappWalletCoinEntity.getAvailableAmount(); |
| | | //如果中奖,返回本金加收益加剩余投注金额 |
| | | BigDecimal total = totalProfit.add(totalAmount).add(igtOnHookPlanOrder.getAvaAmount()).setScale(4, BigDecimal.ROUND_DOWN); |
| | | dappWalletCoinDao.addTotalAndaddAvailableById(memberId,total); |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | if(isProfit == 2){ |
| | | //设置成不盈利,只返回收益加剩余挂机总金额 |
| | | total = totalProfit.add(igtOnHookPlanOrder.getAvaAmount()).setScale(4, BigDecimal.ROUND_DOWN); |
| | | }else{ |
| | | //设置成盈利,如果中奖,返回收益,如果没中奖,则返回本金,最后加上剩余总挂机金额 |
| | | total = totalProfit.add(totalAmount).add(igtOnHookPlanOrder.getAvaAmount()).setScale(4, BigDecimal.ROUND_DOWN); |
| | | } |
| | | dappWalletCoinDao.addTotalAndaddAvailableById(dappWalletCoinEntity.getId(),total); |
| | | |
| | | BigDecimal add = availableAmount.add(total); |
| | | |
| | | DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(memberId, availableAmount, total, add, "投注盈利", 5); |
| | | BigDecimal subtract = add.subtract(totalProfit); |
| | | DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(memberId, subtract, totalProfit, add, "投注盈利", 5); |
| | | dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Scheduled(cron = "0 0/1 * * * ? ") |
| | | public void updateMemberIsOnHook(){ |
| | |
| | | |
| | | @Scheduled(cron = "0 0/1 * * * ? ") |
| | | public void createAwardInfo(){ |
| | | Log.info("挂架开奖记录"); |
| | | Log.info("挂机开奖记录"); |
| | | /** |
| | | * 每天跑一次,直接生成全部的记录 |
| | | * 产生中奖记录 |
| | |
| | | String aWardTime = DateUtil.format(date, "yyyy-MM-dd"); |
| | | DateTime aWardTimeStart = DateUtil.parseDateTime(aWardTime + " 00:00:00"); |
| | | // DateTime dateTime = DateUtil.offsetMinute(aWardTimeStart, 5); |
| | | |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | String yyyyMMdd = sdf.format(date); |
| | | QueryWrapper<DappOnHookAward> dappOnHookAwardQueryWrapper = new QueryWrapper(); |
| | | dappOnHookAwardQueryWrapper.like("record_num",yyyyMMdd); |
| | | Integer selectCount = dappOnHookAwardDao.selectCount(dappOnHookAwardQueryWrapper); |
| | | if(0 < selectCount){ |
| | | return; |
| | | if(0 == selectCount){ |
| | | Format formatCount = new DecimalFormat("000"); |
| | | //一般都是将累加的数字当做一些单号的一部分,format要求string |
| | | int dayMillise = (24 * 60) / 5; |
| | | for(int i= 1;i <= dayMillise;i++){ |
| | | DappOnHookAward dappOnHookAward = new DappOnHookAward(); |
| | | int randomInt = RandomUtil.randomInt(10000, 99999); |
| | | dappOnHookAward.setAwardNum(Integer.toString(randomInt)); |
| | | dappOnHookAward.setState(2); |
| | | String str = formatCount.format(i); |
| | | dappOnHookAward.setRecordNum(yyyyMMdd+str); |
| | | dappOnHookAward.setAwardTime(aWardTimeStart); |
| | | dappOnHookAwardDao.insert(dappOnHookAward); |
| | | aWardTimeStart = DateUtil.offsetMinute(aWardTimeStart, 5); |
| | | } |
| | | } |
| | | Format formatCount = new DecimalFormat("000"); |
| | | //一般都是将累加的数字当做一些单号的一部分,format要求string |
| | | int dayMillise = (24 * 60) / 5; |
| | | for(int i= 1;i <= dayMillise;i++){ |
| | | DappOnHookAward dappOnHookAward = new DappOnHookAward(); |
| | | int randomInt = RandomUtil.randomInt(10000, 99999); |
| | | dappOnHookAward.setAwardNum(Integer.toString(randomInt)); |
| | | dappOnHookAward.setState(2); |
| | | String str = formatCount.format(i); |
| | | dappOnHookAward.setRecordNum(yyyyMMdd+str); |
| | | dappOnHookAward.setAwardTime(aWardTimeStart); |
| | | dappOnHookAwardDao.insert(dappOnHookAward); |
| | | aWardTimeStart = DateUtil.offsetMinute(aWardTimeStart, 5); |
| | | |
| | | DateTime tomorrow = DateUtil.tomorrow(); |
| | | String tomorrowTime = DateUtil.format(tomorrow, "yyyy-MM-dd"); |
| | | DateTime tomorrowTimeStart = DateUtil.parseDateTime(tomorrowTime + " 00:00:00"); |
| | | // DateTime dateTime = DateUtil.offsetMinute(aWardTimeStart, 5); |
| | | String tomorrowYyyyMMdd = sdf.format(tomorrow); |
| | | QueryWrapper<DappOnHookAward> tomorrowYyyyMMddWrapper = new QueryWrapper(); |
| | | tomorrowYyyyMMddWrapper.like("record_num",tomorrowYyyyMMdd); |
| | | Integer tomorrowSelectCount = dappOnHookAwardDao.selectCount(tomorrowYyyyMMddWrapper); |
| | | if(0 == tomorrowSelectCount){ |
| | | Format formatCount = new DecimalFormat("000"); |
| | | //一般都是将累加的数字当做一些单号的一部分,format要求string |
| | | int dayMilliseT = (24 * 60) / 5; |
| | | for(int i= 1;i <= dayMilliseT;i++){ |
| | | DappOnHookAward dappOnHookAward = new DappOnHookAward(); |
| | | int randomInt = RandomUtil.randomInt(10000, 99999); |
| | | dappOnHookAward.setAwardNum(Integer.toString(randomInt)); |
| | | dappOnHookAward.setState(2); |
| | | String str = formatCount.format(i); |
| | | dappOnHookAward.setRecordNum(tomorrowYyyyMMdd+str); |
| | | dappOnHookAward.setAwardTime(tomorrowTimeStart); |
| | | dappOnHookAwardDao.insert(dappOnHookAward); |
| | | tomorrowTimeStart = DateUtil.offsetMinute(tomorrowTimeStart, 5); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Value("${spring.profiles.active}") |
| | | private String active; |
| | | |
| | | @Scheduled(cron = "0 0/5 * * * ? ") |
| | | public void updateAwardInfo(){ |
| | |
| | | DappOnHookAward dappOnHookAward = dappOnHookAwardDao.selectByByAwardTime(yyyyMMddHHMM); |
| | | dappOnHookAward.setState(1); |
| | | dappOnHookAwardDao.updateById(dappOnHookAward); |
| | | String redisKey = "on_hook_award_id"; |
| | | String redisKey = ""; |
| | | if("prod".equals(active)){ |
| | | redisKey = "on_hook_award_id"; |
| | | }else{ |
| | | redisKey = "on_hook_award_id_test"; |
| | | } |
| | | String onHookAwardRedisId = redisUtils.getString(redisKey); |
| | | if(StrUtil.isBlank(onHookAwardRedisId)){ |
| | | redisUtils.set(redisKey,dappOnHookAward.getId().toString(),0L); |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 更新用户等级的条件 |
| | | * 一天跑一次,跑完之后进行分佣,和盈利分成 |
| | | * 1、三个有效的用户等级用户 |
| | | * 2、账户余额大于51 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ? ") |
| | | public void updateMemberLevel(){ |
| | | Log.info("更新用户代理等级"); |
| | | DateTime date = DateUtil.date(); |
| | | //查询账户总金额大于51的有效用户 |
| | | List<DappMemberEntity> dappMemberEntities = dappWalletCoinDao.selectTotalAmount(); |
| | | if(CollUtil.isEmpty(dappMemberEntities)){ |
| | | //没有账户金额大于51,则全部为会员 |
| | | dappMemberDao.updateIdentity(); |
| | | }else{ |
| | | List<DappMemberEntity> LEVEL_IB = getMemberLevelList(dappMemberEntities, DataDictionaryEnum.LEVEL_MB.getCode(), DataDictionaryEnum.LEVEL_IB.getCode()); |
| | | List<DappMemberEntity> LEVEL_FIB = getMemberLevelList(LEVEL_IB, DataDictionaryEnum.LEVEL_IB.getCode(), DataDictionaryEnum.LEVEL_FIB.getCode()); |
| | | List<DappMemberEntity> LEVEL_CIB = getMemberLevelList(LEVEL_FIB, DataDictionaryEnum.LEVEL_FIB.getCode(), DataDictionaryEnum.LEVEL_CIB.getCode()); |
| | | List<DappMemberEntity> LEVEL_AIB = getMemberLevelList(LEVEL_CIB, DataDictionaryEnum.LEVEL_CIB.getCode(), DataDictionaryEnum.LEVEL_AIB.getCode()); |
| | | List<DappMemberEntity> LEVEL_GIB = getMemberLevelList(LEVEL_AIB, DataDictionaryEnum.LEVEL_AIB.getCode(), DataDictionaryEnum.LEVEL_GIB.getCode()); |
| | | List<DappMemberEntity> LEVEL_BP = getMemberLevelList(LEVEL_GIB, DataDictionaryEnum.LEVEL_GIB.getCode(), DataDictionaryEnum.LEVEL_BP.getCode()); |
| | | List<DappMemberEntity> LEVEL_SP = getMemberLevelList(LEVEL_BP, DataDictionaryEnum.LEVEL_BP.getCode(), DataDictionaryEnum.LEVEL_SP.getCode()); |
| | | List<DappMemberEntity> LEVEL_GP = getMemberLevelList(LEVEL_SP, DataDictionaryEnum.LEVEL_SP.getCode(), DataDictionaryEnum.LEVEL_GP.getCode()); |
| | | } |
| | | } |
| | | |
| | | private List<DappMemberEntity> getMemberLevelList(List<DappMemberEntity> dappMemberEntities,String identity,String identityNext){ |
| | | List<DappMemberEntity> dappMemberEntitiesNext = new ArrayList<>(); |
| | | if(CollUtil.isNotEmpty(dappMemberEntities)){ |
| | | for(DappMemberEntity dappMemberEntity : dappMemberEntities){ |
| | | Long memberEntityId = dappMemberEntity.getId(); |
| | | String refererId = dappMemberEntity.getRefererId(); |
| | | String inviteId = dappMemberEntity.getInviteId(); |
| | | //下级是否存在三个账户总金额大于51的会员,并且代理等级为identity |
| | | List<DappMemberEntity> levelMbMembers = dappMemberDao.selectTotalAmountByRefererIdAndIdentity(inviteId,identity); |
| | | if(CollUtil.isNotEmpty(levelMbMembers) && 3 <= levelMbMembers.size()){ |
| | | //设置identityNext级别 |
| | | dappMemberDao.updateIdentityByMemberId(identityNext,memberEntityId); |
| | | //获取他的上级会员信息 |
| | | DappMemberEntity dappMemberEntityNext = dappMemberDao.selectMemberInfoByInviteId(refererId); |
| | | dappMemberEntitiesNext.add(dappMemberEntityNext); |
| | | } |
| | | } |
| | | } |
| | | return dappMemberEntitiesNext; |
| | | } |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | |
| | | DateTime date = DateUtil.date(); |