| | |
| | | package com.hx.phip.tool.user; |
| | | |
| | | import com.hx.common.service.CommonService; |
| | | import com.hx.exception.TipsException; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import com.hx.phiappt.model.cardItem.CardEquity; |
| | | import com.hx.phiappt.model.cardItem.CardItemInfo; |
| | | import com.hx.phiappt.model.consume.ConsumePayItem; |
| | | import com.hx.phiappt.model.order.OrderItem; |
| | | import com.hx.phiappt.model.order.OrdersTotal; |
| | | import com.hx.phiappt.model.user.UserCard; |
| | | import com.hx.phiappt.model.user.UserCardUsed; |
| | | import com.hx.phip.dao.mapper.OrderItemMapper; |
| | | import com.hx.phip.dao.mapper.OrdersTotalMapper; |
| | | import com.hx.phip.dao.mapper.UserCardUsedMapper; |
| | | import com.hx.phip.tool.order.OrderTool; |
| | | import com.hx.phip.vo.user.UserCardItemInfoVo; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | *用户卡包处理工具 |
| | |
| | | return userCardUsed; |
| | | } |
| | | |
| | | /**计算用户卡包购买时候的金额分摊方式-订单*/ |
| | | public static void userCardPay(UserCard userCard,CommonService commonService){ |
| | | //不是订单购买的卡包,跳出循环 |
| | | if(UserCard.SOURCE_TYPE_ORDER_ONE != userCard.getSourceType()){ |
| | | return; |
| | | } |
| | | |
| | | //通过购买这个卡项的订单来算单卡的钱是多少 |
| | | //查询已经退了多少钱,避免退超了支付方式金额 |
| | | |
| | | OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class,userCard.getSourceId()); |
| | | if(orderItem == null){ |
| | | throw new TipsException("获取订单子信息失败[895]"); |
| | | } |
| | | if(orderItem.getBuyNum().compareTo(0) < 1){ |
| | | throw new TipsException("获取订单子信息购买数量错误!"); |
| | | } |
| | | |
| | | //求单个金额 |
| | | BigDecimal total = orderItem.getActualTotal().divide(new BigDecimal(orderItem.getBuyNum()),2, RoundingMode.UP); |
| | | //金额不是0元以上,不处理 |
| | | if(total.compareTo(BigDecimal.ZERO) <= 0){ |
| | | return; |
| | | } |
| | | |
| | | /**获取订单支付方式*/ |
| | | List<ConsumePayItem> consumePayItemList = OrderTool.getOrderOnePay(userCard.getSourceId(),commonService); |
| | | |
| | | |
| | | consumePayItemList = consumePayItemList.stream().sorted(Comparator.comparing(ConsumePayItem::getpTotal)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | //求比率 |
| | | BigDecimal proportion = total.divide(orderItem.getActualTotal(),20,RoundingMode.HALF_UP); |
| | | for(ConsumePayItem consumePayItem:consumePayItemList){ |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |