KKSU
2024-04-17 829f629756e5402bcd3e9f6ef1f9c6dbffbabb11
src/main/java/com/xcong/excoin/modules/yunding/service/Impl/YunDingServiceImpl.java
@@ -1,7 +1,6 @@
package com.xcong.excoin.modules.yunding.service.Impl;
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.StrUtil;
@@ -42,7 +41,6 @@
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Slf4j
@@ -65,6 +63,8 @@
    private MemberDao memberDao;
    @Autowired
    private YunDingProducter yunDingProducter;
    @Autowired
    private RedisUtils redisUtils;
    @Override
    public Result findAllInfo() {
@@ -107,8 +107,16 @@
            for(YdProductVo ydProductVo : records){
                ydProductVo.setProfitT(prifitT);
                if(ydProductVo.getTotalT().compareTo(BigDecimal.ZERO) < 1) {
                if(ydProductVo.getSurplusT().compareTo(BigDecimal.ZERO) < 1) {
                    ydProductVo.setStatus(2);
                }
                Integer shelvesDays = ydProductVo.getShelvesDays();
                String proUnit = ydProductVo.getProUnit();
                if(shelvesDays == 0){
                    ydProductVo.setShelvesDaysStr("待定");
                }else{
                    ydProductVo.setShelvesDaysStr(proUnit+"+"+shelvesDays);
                }
            }
        }
@@ -135,10 +143,19 @@
        /**
         *产出规则
         */
        Date date = DateUtil.date();
        ydProductVo.setNowTime(date);
        //上架天数
        Integer shelvesDays = ydProductVo.getShelvesDays();
        String proUnit = ydProductVo.getProUnit();
        if(shelvesDays == 0){
            ydProductVo.setGetType(2);
            ydProductVo.setShelvesDaysStr("待定");
        }else{
            ydProductVo.setGetType(1);
            ydProductVo.setShelvesDaysStr(proUnit+"+"+shelvesDays);
        }
        Date date = DateUtil.date();
        ydProductVo.setNowTime(date);
        Date workTime = DateUtil.offsetDay(date, shelvesDays);
        ydProductVo.setWorkTime(workTime);
        //服务周期
@@ -146,10 +163,8 @@
        Date endTime = DateUtil.offsetDay(workTime, proCycle);
        ydProductVo.setEndTime(endTime);
        if (ydProductVo.getTotalT().compareTo(BigDecimal.ZERO) < 1) {
        if (ydProductVo.getSurplusT().compareTo(BigDecimal.ZERO) < 1) {
            ydProductVo.setStatus(2);
        } else {
            ydProductVo.setStatus(1);
        }
        return Result.ok(ydProductVo);
    }
@@ -229,12 +244,14 @@
                quantityOwn = quantityOwn + ydOrderEntity.getQuantity();
            }
        }
        if(quantityOwn >= limitedNum){
        int quantityInt = quantity.intValue();
        if(quantityOwn + quantityInt > limitedNum){
            return Result.fail("产品限购"+limitedNum);
        }
        if (quantity.compareTo(BigDecimal.valueOf(ydProductEntity.getLimitedNum())) < 1) {
            return Result.fail("产品限购" + ydProductEntity.getLimitedNum());
        }
//        if (quantity.compareTo(BigDecimal.valueOf(ydProductEntity.getLimitedNum())) < 1) {
//            return Result.fail("产品限购" + ydProductEntity.getLimitedNum());
//        }
        BigDecimal salePrice = ydProductEntity.getSalePrice();
        //剩余产品数量
        BigDecimal surplusT = ydProductEntity.getSurplusT();
@@ -278,7 +295,6 @@
                "USDT", 1, 3, ydOrderEntity.getId());
        yunDingProducter.sendYunDingUsdtProfit(ydOrderEntity.getId());
        yunDingProducter.sendYunDingAutoAgent(ydOrderEntity.getMemberId());
        return Result.ok("支付成功");
    }
@@ -309,7 +325,7 @@
        MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
        Long memberId = memberEntity.getId();
//        Long memberId = 442L;
//        Long memberId = 447L;
        OrderAllInfoVo orderAllInfoVo = new OrderAllInfoVo();
        DecimalFormat decimalFormat = new DecimalFormat("0.0000#");
        //历史总收益
@@ -335,7 +351,12 @@
        if(CollUtil.isNotEmpty(PowerNowQuery)){
            for(YdOrderEntity order : PowerNowQuery){
                int quantity = order.getQuantity();
                powerNow = powerNow + quantity;
                Long productId = order.getProductId();
                YdProductEntity ydProductEntity = ydProductDao.selectById(productId);
                if("XCH".equals(ydProductEntity.getCoin())){
                    Integer proNum = ydProductEntity.getProNum();
                    powerNow = powerNow + quantity*proNum;
                }
            }
        }
        orderAllInfoVo.setPowerNow(powerNow);
@@ -349,7 +370,12 @@
        if(CollUtil.isNotEmpty(powerReradyQuerys)){
            for(YdOrderEntity order : powerReradyQuerys){
                int quantity = order.getQuantity();
                powerReady = powerReady + quantity;
                Long productId = order.getProductId();
                YdProductEntity ydProductEntity = ydProductDao.selectById(productId);
                if("XCH".equals(ydProductEntity.getCoin())){
                    Integer proNum = ydProductEntity.getProNum();
                    powerReady = powerReady + quantity*proNum;
                }
            }
        }
        orderAllInfoVo.setPowerReady(powerReady);
@@ -452,13 +478,13 @@
        MemberWalletCoinEntity xch = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, "XCH");
        BigDecimal totalBalance = xch.getTotalBalance();
        BigDecimal subtractTotalBalance = totalBalance.subtract(xchNum);
        if(BigDecimal.ZERO.compareTo(subtractTotalBalance) >= 0){
        if(BigDecimal.ZERO.compareTo(subtractTotalBalance) > 0){
            return Result.fail("XCH数量不足");
        }
        BigDecimal availableBalance = xch.getAvailableBalance();
        BigDecimal subtractAvailableBalance = availableBalance.subtract(xchNum);
        if(BigDecimal.ZERO.compareTo(subtractAvailableBalance) >= 0){
        if(BigDecimal.ZERO.compareTo(subtractAvailableBalance) > 0){
            return Result.fail("XCH数量不足");
        }
        //xch减少
@@ -583,11 +609,96 @@
        memberEntity.setAgentLevel(id.intValue());
        LoginUserUtils.resetAppLoginUser(memberEntity);
        yunDingProducter.sendYunDingAutoAgent(memberId);
        yunDingProducter.sendYunDingUsdtProfit(orderEntity.getId());
        return Result.ok("购买成功");
    }
    @Override
    public Result getXchPrice() {
        log.info("获取XCH当前价");
        BigDecimal xchNewPrices = BigDecimal.ZERO;
        String xchNewPrice = redisUtils.getString("XCH_NEW_PRICE");
        if(StrUtil.isNotEmpty(xchNewPrice)){
            xchNewPrices = new BigDecimal(xchNewPrice);
        }
        return Result.ok(xchNewPrices);
    }
    @Override
    public Result getTeamList(TeamInfoDto teamInfoDto) {
        log.info("获取团队信息");
        MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
        Long memberId = memberEntity.getId();
//        Long memberId = 444L;
//        MemberEntity memberEntity = memberDao.selectById(memberId);
        /**
         * 获取团队总人数,总购买数
         *      详细列表
         *
         */
        TeamVo teamVo = new TeamVo();
        //团队总人数
        int memberNum = 0;
        String inviteId = memberEntity.getInviteId();
        List<MemberEntity> memberEntityList = ydOrderDao.selectMemberByInviteId(inviteId);
        if(CollUtil.isNotEmpty(memberEntityList)){
            memberNum = memberEntityList.size();
        }
        teamVo.setMemberNum(memberNum);
        //购买总算力
        int allPower =0;
        List<YdOrderEntity> ydOrderEntitys = ydOrderDao.selectListByMemberIdAndElse(inviteId);
        if(CollUtil.isNotEmpty(ydOrderEntitys)){
            for(YdOrderEntity ydOrderEntity : ydOrderEntitys){
                Long productId = ydOrderEntity.getProductId();
                YdProductEntity ydProductEntity = ydProductDao.selectById(productId);
                if("XCH".equals(ydProductEntity.getCoin())){
                    Integer proNum = ydProductEntity.getProNum();
                    Integer quantity = ydOrderEntity.getQuantity();
                    allPower = allPower + proNum*quantity;
                }
            }
        }
        teamVo.setAllPower(allPower);
        //详细列表
        Page<TeamInfoVo> page = new Page<>(teamInfoDto.getPageNum(), teamInfoDto.getPageSize());
        IPage<TeamInfoVo> teamInfoVos = ydOrderDao.getTeamInfoList(page, memberEntity);
        List<TeamInfoVo> records = teamInfoVos.getRecords();
        if(CollUtil.isNotEmpty(records)){
            for(TeamInfoVo teamInfoVo : records){
                String phone = teamInfoVo.getInvitephone();
                if(StrUtil.isNotEmpty(phone)){
                    teamInfoVo.setInvitephone(StrUtil.subSufByLength(phone,4));
                }
                //下属团队人数
                int memberNumInvite = 0;
                List<MemberEntity> memberEntityInviteList = ydOrderDao.selectMemberByInviteId(phone);
                if(CollUtil.isNotEmpty(memberEntityInviteList)){
                    memberNumInvite = memberEntityInviteList.size();
                }
                teamInfoVo.setMemberNum(memberNumInvite);
                //下属团队总算力
                int powerNum =0;
                List<YdOrderEntity> ydOrderEntityLevel = ydOrderDao.selectListByMemberIdAndElse(inviteId);
                if(CollUtil.isNotEmpty(ydOrderEntityLevel)){
                    for(YdOrderEntity ydOrderEntity : ydOrderEntityLevel){
                        Long productId = ydOrderEntity.getProductId();
                        YdProductEntity ydProductEntity = ydProductDao.selectById(productId);
                        if("XCH".equals(ydProductEntity.getCoin())){
                            Integer proNum = ydProductEntity.getProNum();
                            Integer quantity = ydOrderEntity.getQuantity();
                            powerNum = powerNum + proNum*quantity;
                        }
                    }
                }
                teamInfoVo.setPowerNum(powerNum);
            }
        }
        teamVo.setTeamInfoVos(records);
        return Result.ok(teamVo);
    }
    /**
     * 去加减币币账户余额,减少产品的剩余数目