chenjiahe
2024-01-23 ff63b8c7713325272122368ccec10ef1d6760017
再生俱乐部提交
2个文件已修改
279 ■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/tool/club/UserCluebMemberTool.java 104 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/util/api/OrderPayMoneyUtil.java 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/tool/club/UserCluebMemberTool.java
@@ -21,6 +21,7 @@
import com.hx.util.DateUtil;
import java.util.*;
import java.util.stream.Collectors;
/**用户俱乐部会员
 * @author CJH
@@ -102,8 +103,6 @@
        sqlSentence.sqlSentence("SELECT id,type,commonId,goodsNo,goodsName,usedTotal,hasReNum FROM order_item WHERE isDel = 0 AND orderId = #{m.orderId}",values);
        List<OrderItem> orderItemList = commonService.selectList(OrderItemMapper.class,sqlSentence);
        //已经算了疗程数的项目编号
        Set<String> mateSkuNoSet = new HashSet<>();
        //总疗程数,所有的项目疗程数总和
        int cureNum = 0;
@@ -112,7 +111,6 @@
        List<OrderItemSon> orderItemSonList;
        List<CardEquity> cardEquityList;
        List<CardItemInfo> cardItemInfoList;
        int cureItemMax;
        int cureItemNum;
        int deductionSurp;
        int deductionNum;
@@ -139,32 +137,70 @@
                cardItemInfoMapList = getCardItemInfoList(orderItem.getCommonId(),commonService);
                for(CardEquity cardEquity:cardEquityList){
                    cardItemInfoList = cardItemInfoMapList.get(cardEquity.getId());
                    if(cardItemInfoList==null || cardItemInfoList.size()==0){
                    if(cardItemInfoList == null || cardItemInfoList.size()==0){
                        continue;
                    }
                    //判断权益类型
                    if(cardEquity.getEquityType().equals(CardEquity.EQUITY_TYPE_PROJECT)){
                        for(CardItemInfo cardItemInfo:cardItemInfoList){
                            //固定项目类型
                            if(cardItemInfo.getUserNum() != null){
                                cureNum = cureNum+cardItemInfo.getUserNum()*cardItemInfo.getMaxNum()*orderItem.getBuyNum();
                            if(skuNoSet.contains(cardItemInfo.getCommonCode())){
                                //固定项目类型
                                if(cardItemInfo.getUserNum() != null){
                                    cureNum = cureNum+cardItemInfo.getUserNum()*cardItemInfo.getMaxNum()*orderItem.getBuyNum();
                                }
                            }
                        }
                    }else if(cardEquity.getEquityType().equals(CardEquity.EQUITY_TYPE_TIME_CARD)){
                        //TODO 这里还没有做完
                        //只存储最大的一个疗程数
                        cureItemMax = 0;
                        //---次卡
                        //剩余抵扣次数
                        deductionSurp = cardEquity.getValue();
                        //次卡
                        //最小公倍数算法
                        minCommonMultiple(cardItemInfoList);
                        //排序,降序
                        cardItemInfoList = cardItemInfoList.stream().sorted(Comparator.comparing(CardItemInfo::getCommonMultiple).reversed())
                                .collect(Collectors.toList());
                        for(CardItemInfo cardItemInfo:cardItemInfoList){
                            if(cardItemInfo.getUserNum() != null){
                                deductionNum = cardEquity.getValue()/cardItemInfo.getEveryDrawNum();
                                cureItemNum = cardItemInfo.getUserNum()*deductionNum*orderItem.getBuyNum();
                                if(cureItemNum>cureItemMax){
                                    cureItemMax = cureItemMax;
                            if(deductionSurp <= 0){
                                break;
                            }
                            if(skuNoSet.contains(cardItemInfo.getCommonCode())){
                                if(cardItemInfo.getUserNum() != null){
                                    //计算可购买数量,注意,这不是折扣数量
                                    if(cardItemInfo.getEveryDrawNum() > 0){
                                        deductionNum = cardEquity.getValue()/cardItemInfo.getEveryDrawNum();
                                    }else{
                                        deductionNum = 0;
                                    }
                                    //算出总疗程,并叠加到总规则总疗程里面
                                    cureNum = cureNum+cardItemInfo.getUserNum()*deductionNum*orderItem.getBuyNum();
                                    //剩下划扣次数
                                    deductionSurp = deductionSurp - deductionNum*cardItemInfo.getEveryDrawNum();
                                }
                            }
                        }
                    }else if(cardEquity.getEquityType().equals(CardEquity.EQUITY_TYPE_N_M)){
                        //已算的条目数量
                        cureItemNum = 0;
                        //---N选M
                        //先算各疗程总数
                        for(CardItemInfo cardItemInfo:cardItemInfoList){
                            if(cardItemInfo.getUserNum() != null){
                                cardItemInfo.setCommonMultiple(cardItemInfo.getMaxNum()*cardItemInfo.getUserNum());
                            }else{
                                cardItemInfo.setCommonMultiple(0);
                            }
                        }
                        //排序,降序
                        cardItemInfoList = cardItemInfoList.stream().sorted(Comparator.comparing(CardItemInfo::getCommonMultiple).reversed())
                                .collect(Collectors.toList());
                        for(CardItemInfo cardItemInfo:cardItemInfoList){
                            if(cureItemNum >= cardEquity.getValue()){
                                break;
                            }
                            if(skuNoSet.contains(cardItemInfo.getCommonCode())){
                                cureNum = cureNum+cardItemInfo.getCommonMultiple();
                                cureItemNum++;
                            }
                        }
                    }
@@ -280,6 +316,42 @@
        commonService.insert(UserClubMemberMapper.class,userClubMember);
    }
    /**获取最小公倍数*/
    public static void minCommonMultiple(List<CardItemInfo> cardItemInfoList){
        //先获取最大的一个数字
        int max = 0;
        for(CardItemInfo cardItemInfo:cardItemInfoList){
            if(max<cardItemInfo.getEveryDrawNum()){
                max = cardItemInfo.getEveryDrawNum();
            }
        }
        //求最小的公倍数
        boolean b;
        while (true){
            b = true;
            for(CardItemInfo cardItemInfo:cardItemInfoList){
                if(max%cardItemInfo.getEveryDrawNum()!=0){
                    b = false;
                    break;
                }
            }
            if(b){
                break;
            }else{
                max++;
            }
        }
        //求出他们之间,谁的疗程数最多
        for(CardItemInfo cardItemInfo:cardItemInfoList){
            if(cardItemInfo.getUserNum() != null){
                cardItemInfo.setCommonMultiple(cardItemInfo.getUserNum()*max/cardItemInfo.getEveryDrawNum());
            }else{
                cardItemInfo.setCommonMultiple(0);
            }
        }
    }
}
phi_platform_user/src/main/java/com/hx/phip/util/api/OrderPayMoneyUtil.java
@@ -2059,76 +2059,120 @@
            return null;
        }
        //邀请人
        User inviteeUser=commonService.selectOneByKey(UserMapper.class,orderInfo.getInviteeId());
        if(inviteeUser==null){
            logger.info("老带新邀请人不存在:订单号:{}",ordersTotal.getOrderNo());
            return null;
        }
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        //判断有没有再生会员俱乐部的会员信息
        //判断有没有再生会员俱乐部的会员信息,邀请人的
        values.put("type",UserClubMember.TYPE_REGENERATION);
        values.put("userId",UserClubMember.TYPE_REGENERATION);
        values.put("userId",inviteeUser.getId());
        values.put("newDate",new Date());
        sqlSentence.sqlSentence("SELECT * FROM user_club_member WHERE isDel = 0 AND type = #{m.type} AND userId = #{m.userId}" +
                " AND (durationType = 0 OR (durationType = 1 AND startTime >= #{m.newDate} AND #{m.newDate} <= endTime)) ORDER BY endTime DESC LIMIT 1",values);
                " AND (durationType = 0 OR (durationType = 1 AND startTime >= #{m.newDate} AND #{m.newDate} <= endTime)) ORDER BY durationType ASC,endTime DESC LIMIT 1",values);
        UserClubMember userClubMember = commonService.selectOneByKey(UserClubMemberMapper.class,sqlSentence);
        //没有等级就默认潜客
        if(StringUtils.isNull(inviteeUser.getUserLevel())){
            inviteeUser.setUserLevel("潜客");
        }
        //计算用户返佣金额,并赠送增值金(新客)
        List<String> lowMemerLeveList = Arrays.asList("潜客","准会员", "普卡", "银卡");
        List<String> highMemerLeveList = Arrays.asList("金卡", "钻石卡", "黑卡","黑钻卡");
        //邀请人的获取比例%
        Integer inviterPercent = null;
        //被邀请人获得比例%
        Integer beInviterPercent = null;
        if(userClubMember != null){
            //有俱乐部会员优先处理
        }else{
        }
        //邀请人的获取比例
        int inviterPercent;
        //常规老带新规则
        if(ordersTotal.getOrderInfo().getIsOldBringNew() !=null && ordersTotal.getOrderInfo().getIsOldBringNew().equals(BaseEntity.YES)){
            //
        }else{
            //
        }
        try{
            //统计订单现金总金额
            BigDecimal moneyPay=orderInfo.getSnapPayTotal();
            logger.info("处理老带新:moneyPay:{}",moneyPay);
            BigDecimal beInviterMoney=BigDecimal.ZERO;
            BigDecimal inviterMoney=BigDecimal.ZERO;
            String newUserName=ordersTotal.getUserName()+"("+ordersTotal.getUserLevel()+")";
            String oldUserName="";
            //计算用户返佣金额,并赠送增值金(新客)
            List<String> lowMemerLeveList = Arrays.asList("潜客","准会员", "普卡", "银卡");
            List<String> highMemerLeveList = Arrays.asList("金卡", "钻石卡", "黑卡","黑钻卡");
            //赠送老客
            if(StringUtils.noNull(orderInfo.getInviteeId()) ){
                //处理老带新(禅道为准,禅道号176)
                //1.潜客、准会员、普卡、银卡:邀请人增值金百分比:8%,被邀请人增值金百分比:2%
                //2.金卡、钻卡、黑卡、黑钻卡:邀请人增值金百分比:10%,被邀请人增值金百分比:5%
                User inviteeUser=commonService.selectOneByKey(UserMapper.class,orderInfo.getInviteeId());
                if(inviteeUser!=null){
                    if(StringUtils.isNull(inviteeUser.getUserLevel())){
                        inviteeUser.setUserLevel("潜客");
                    }
                    oldUserName=inviteeUser.getName()+"("+inviteeUser.getUserLevel()+")";
                    if(StringUtils.noNull(inviteeUser.getUserLevel()) && lowMemerLeveList.contains(inviteeUser.getUserLevel())&& moneyPay.compareTo(BigDecimal.ZERO)==1){
                        inviterMoney= OrderPayMoneyUtil.inviterGivingOldNew(ordersTotal, user, moneyPay, 8, commonService);
                        beInviterMoney = OrderPayMoneyUtil.beInviterGivingOldNew(ordersTotal, user, moneyPay, 2, commonService);
                    }else if(StringUtils.noNull(inviteeUser.getUserLevel()) &&highMemerLeveList.contains(inviteeUser.getUserLevel())&& moneyPay.compareTo(BigDecimal.ZERO)==1){
                        inviterMoney = OrderPayMoneyUtil.inviterGivingOldNew(ordersTotal, user, moneyPay, 10, commonService);
                        beInviterMoney = OrderPayMoneyUtil.beInviterGivingOldNew(ordersTotal, user, moneyPay, 5, commonService);
                    }
            if(ordersTotal.getOrderInfo().getIsOldBringNew() !=null && ordersTotal.getOrderInfo().getIsOldBringNew().equals(BaseEntity.YES)){
                //----初复诊订单
                inviterPercent = 10;
                if(StringUtils.noNull(inviteeUser.getUserLevel()) &&highMemerLeveList.contains(inviteeUser.getUserLevel())){
                    //邀请人高级会员等级
                    beInviterPercent = 5;
                }else{
                    beInviterPercent = 2;
                }
            }else{
                //-----复购订单
                //查找被邀请人下单(初诊单)
                //复购单数量,是有现金消费的复购单
                values.clear();
                values.put("userId",user.getId());
                values.put("newId",ordersTotal.getId());
                sqlSentence.sqlSentence("SELECT ot.id,ot.payTime,(SELECT COUNT(*) FROM orders_total a" +
                        " JOIN orders_info info2 ON info2.orderId = a.id" +
                        " WHERE a.isDel = 0 AND a.userId = #{m.userId} AND a.status IN(2,3,9)" +
                        " AND a.payStatus = 3 AND info2.isBothTheOne = 3 AND a.snapPayTotal > 0 AND a.id != #{m.newId}) AS num" +
                        " FROM orders_total ot" +
                        " JOIN orders_info info ON info.orderId = ot.id" +
                        " WHERE ot.isDel = 0 AND ot.userId = #{m.userId} AND ot.status IN(2,3,9)" +
                        " AND ot.payStatus = 3 AND info.isBothTheOne IN(1,2) AND ot.id != #{m.newId} ORDER BY ot.payTime ASC LIMIT 1",values);
                OrdersTotal firstOrder = commonService.selectOne(OrdersTotalMapper.class,sqlSentence);
                if(firstOrder == null){
                    logger.info("再生俱乐部老带新没有找到初复诊订单:{}",ordersTotal.getOrderNo());
                    return null;
                }
                //第一次和第二次的复购单有返佣,且是初诊单时间的6个月内的复购单
                if(firstOrder.getNum() >= 2){
                    logger.info("再生俱乐部老带新复购单数量:{}",firstOrder.getNum());
                    return null;
                }
                inviterPercent = 5;
            }
            object =new JSONObject();
            object.put("oldUserName",oldUserName);//邀请人名称
            object.put("inviterMoney",inviterMoney);//邀请人返佣金额
            object.put("newUserName",newUserName);//被邀请人名称
            object.put("beInviterMoney",beInviterMoney);//被邀请人返佣金额
        }catch (Exception e){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"处理老带新失败!异常原因:{}"+e.getMessage());
        }else{
            //常规老带新规则
            if(ordersTotal.getOrderInfo().getIsOldBringNew() ==null || !ordersTotal.getOrderInfo().getIsOldBringNew().equals(BaseEntity.YES)){
                return null;
            }
            //处理老带新(禅道为准,禅道号176)
            //1.潜客、准会员、普卡、银卡:邀请人增值金百分比:8%,被邀请人增值金百分比:2%
            //2.金卡、钻卡、黑卡、黑钻卡:邀请人增值金百分比:10%,被邀请人增值金百分比:5%
            if(StringUtils.noNull(inviteeUser.getUserLevel()) &&highMemerLeveList.contains(inviteeUser.getUserLevel())){
                //邀请人高级会员等级
                inviterPercent = 10;
                beInviterPercent = 5;
            }else{
                inviterPercent = 8;
                beInviterPercent = 2;
            }
        }
        //-----以下是返佣计算,到账和数据整合程序
        //统计订单现金总金额
        BigDecimal moneyPay=orderInfo.getSnapPayTotal();
        orderNodeBuilder.append("-老带新现金金额:¥").append(moneyPay);
        BigDecimal beInviterMoney = BigDecimal.ZERO;
        BigDecimal inviterMoney = BigDecimal.ZERO;
        //开始返佣到账
        if(moneyPay.compareTo(BigDecimal.ZERO) > 0){
            if(inviterPercent != null){
                //邀请人
                inviterMoney= OrderPayMoneyUtil.inviterGivingOldNew(ordersTotal, user, moneyPay, inviterPercent, commonService);
            }
            if(beInviterPercent != null){
                //被邀请人
                beInviterMoney = OrderPayMoneyUtil.beInviterGivingOldNew(ordersTotal, user, moneyPay, beInviterPercent, commonService);
            }
        }
        orderNodeBuilder.append("-老客获得返佣:¥").append(inviterMoney);
        orderNodeBuilder.append("-新客获得返佣:¥").append(beInviterMoney);
        object =new JSONObject();
        object.put("oldUserName",inviteeUser.getName()+"("+inviteeUser.getUserLevel()+")");//邀请人名称
        object.put("inviterMoney",inviterMoney);//邀请人返佣金额
        object.put("newUserName",ordersTotal.getUserName()+"("+ordersTotal.getUserLevel()+")");//被邀请人名称
        object.put("beInviterMoney",beInviterMoney);//被邀请人返佣金额
        orderNodeBuilder.append("-结束处理老带新");
        return object;
    }
@@ -2143,10 +2187,12 @@
    public static BigDecimal inviterGivingOldNew(OrdersTotal ordersTotal, User user, BigDecimal moneyPay,int inviterPercent,CommonService commonService) {
        //赠送邀请人增值金
        //邀请人比例
        BigDecimal inviterRatio = new BigDecimal(inviterPercent).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
        BigDecimal inviterRatio = new BigDecimal(inviterPercent).divide(new BigDecimal(100),10,RoundingMode.HALF_UP);
        //邀请人赠送金额
        BigDecimal inviterMoney = moneyPay.multiply(inviterRatio);
        BigDecimal inviterMoney = moneyPay.multiply(inviterRatio).setScale(2,RoundingMode.HALF_UP);
        if(moneyPay.compareTo(BigDecimal.ZERO) < 1){
            return inviterMoney;
        }
        UserMoneyUtil.setNewUserMoneyUnclaimed(user.getInviteeId(),"老带新赠送(邀请人):邀请人增值金","结账处理老带新",ordersTotal.getOperatorId(),ordersTotal.getId(),ordersTotal.getAppIdCode(),ordersTotal.getId(),inviterMoney, UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT,commonService,UserMoneyUnclaimed.YES);
        return inviterMoney;
@@ -2162,9 +2208,12 @@
    public static BigDecimal beInviterGivingOldNew(OrdersTotal ordersTotal, User user, BigDecimal moneyPay,int beInviterPercent,CommonService commonService){
        //赠送被邀请人增值金
        //被邀请人比例
        BigDecimal beInviterRatio = new BigDecimal(beInviterPercent).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
        BigDecimal beInviterRatio = new BigDecimal(beInviterPercent).divide(new BigDecimal(100),10,RoundingMode.HALF_UP);
        //被邀请人金额
        BigDecimal beInviterMoney = moneyPay.multiply(beInviterRatio);
        BigDecimal beInviterMoney = moneyPay.multiply(beInviterRatio).setScale(2,RoundingMode.HALF_UP);
        if(beInviterMoney.compareTo(BigDecimal.ZERO)<1){
            return beInviterMoney;
        }
        //赠送被邀请人金额
        UserMoneyUtil.setNewUserMoneyUnclaimed(user.getId(),"老带新赠送(被邀请人):被邀请人增值金","结账处理老带新",ordersTotal.getOperatorId(),ordersTotal.getId(),ordersTotal.getAppIdCode(),ordersTotal.getId(),beInviterMoney, UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT,commonService,UserMoneyUnclaimed.YES);
        return beInviterMoney;