| | |
| | | import com.hx.util.DateUtil; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /**用户俱乐部会员 |
| | | * @author CJH |
| | |
| | | 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; |
| | | |
| | |
| | | List<OrderItemSon> orderItemSonList; |
| | | List<CardEquity> cardEquityList; |
| | | List<CardItemInfo> cardItemInfoList; |
| | | int cureItemMax; |
| | | int cureItemNum; |
| | | int deductionSurp; |
| | | int deductionNum; |
| | |
| | | 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++; |
| | | } |
| | | } |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |