| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | | |
| | |
| | | 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; |