admin
2020-04-13 457265eb82265650cf6c87519803975f23bd2fd3
订单统计与返利到账集成测试相关的bug修改
1个文件已删除
27个文件已修改
2个文件已添加
1001 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/HongBaoV2Mapper.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/TeamEincomeRecordMapper.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/OrderTopicTagEnum.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/body/OrderWeiQuanMQMsg.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/body/TeamRewardPreRecieveMQMsg.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/order/dividents/UserDividentsDayDTO.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/order/OrderTeamRewardException.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/order/dividents/TeamDividentsSourceOrderException.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/hongbao/HongBaoV2Mapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/money/TeamEincomeRecordMapper.xml 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImplV2.java 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderHongBaoMoneyComputeServiceImpl.java 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java 77 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/tb/TaoBaoWeiQuanOrderServiceImpl.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/InviteOrderSubsidyService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderHongBaoMoneyComputeService.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderMoneySettleService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderProcessService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java 251 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManagerV2.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamSubsidyManager.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/Constant.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/factory/order/dividents/TeamDividentsSourceOrderFactory.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/InviteOrderSubsidyMessageListener.java 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/OrderDividentsMessageListener.java 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/user/UserLevelUtil.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/HongBaoV2Mapper.java
@@ -28,6 +28,7 @@
     * @return
     */
    List<HongBaoV2> listChildrenByIds(@Param("idList") List<Long> idList);
    /**
     * 获取奖金列表(1.4.9之前)
     * 
@@ -133,8 +134,9 @@
     * @param count
     * @return
     */
    List<HongBaoV2> listCanBalanceHongBaoByTypeAndUid(@Param("types") List<Integer> type, @Param("uid") Long uid, @Param("orderType") Integer orderType,
            @Param("start") long start, @Param("count") int count);
    List<HongBaoV2> listCanBalanceHongBaoByTypeAndUid(@Param("types") List<Integer> type, @Param("uid") Long uid,
            @Param("orderType") Integer orderType, @Param("maxDate") Date maxPreGetTime, @Param("start") long start,
            @Param("count") int count);
    /**
     * 计算可以结算红包的数量
@@ -143,7 +145,8 @@
     * @param uid
     * @return
     */
    long countCanBalanceHongBaoByTypeAndUid(@Param("types") List<Integer> type, @Param("uid") Long uid, @Param("orderType") Integer orderType);
    long countCanBalanceHongBaoByTypeAndUid(@Param("types") List<Integer> type, @Param("uid") Long uid,
            @Param("orderType") Integer orderType, @Param("maxDate") Date maxPreGetTime);
    /**
     * 根据用户ID,订单状态和结算时间统计邀请赚的订单数量
@@ -232,8 +235,8 @@
     * @return
     */
    List<HongBaoV2> listByStateAndTypeAndUid(@Param("stateList") List<Integer> stateList,
            @Param("typeList") List<Integer> typeList, @Param("uid") Long uid,@Param("start") long start,@Param("count")int count);
            @Param("typeList") List<Integer> typeList, @Param("uid") Long uid, @Param("start") long start,
            @Param("count") int count);
    
    /**
     * 根据ID批量查询
@@ -242,13 +245,11 @@
     */
    List<HongBaoV2> listByIds(@Param("idList") List<Long> idList);
    
    /**
     * 根据订单交易id查询红包
     * @param idList
     * @return
     */
    List<HongBaoDTO> listByOrderTradeId(@Param("tradeId") String tradeId);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/TeamEincomeRecordMapper.java
@@ -3,14 +3,18 @@
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.money.TeamEincomeRecord;
public interface TeamEincomeRecordMapper extends BaseMapper<TeamEincomeRecord> {
    TeamEincomeRecord selectByUidAndPreRecieveTimeAndType(Long uid, Date preRecieveTime, int type);
    TeamEincomeRecord selectByUidAndPreRecieveTimeAndType(@Param("uid") Long uid,
            @Param("preRecieveTime") Date preRecieveTime, @Param("type") int type);
    
    TeamEincomeRecord    selectByPrimaryKeyForUpdate(Long id);
    List<TeamEincomeRecord> listByUidAndPreRecieveTimeAndState(Long uid, Date preRecieveTime, int state);
    List<TeamEincomeRecord> listByUidAndPreRecieveTimeAndState(@Param("uid") Long uid,
            @Param("preRecieveTime") Date preRecieveTime, @Param("state") int state);
}
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/OrderTopicTagEnum.java
@@ -4,6 +4,7 @@
import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg;
import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.dto.mq.order.body.TeamRewardPreRecieveMQMsg;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
public enum OrderTopicTagEnum {
@@ -18,7 +19,7 @@
    banLiShopOrderRefund(BanLiShopOrderMQMsg.class), // 板栗商城订单退款
    banLiShopOrderPaid(BanLiShopOrderMQMsg.class), // 商城订单支付成功
    taoBaoOrderWeiQuan(TaoBaoWeiQuanOrder.class),// 淘宝维权订单
    teamRewardPreRecieved(OrderMoneyRecievedMQMsg.class);//团队奖金预到账
    teamRewardPreRecieved(TeamRewardPreRecieveMQMsg.class);//团队奖金预到账
    private final Class<?> clazz;
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/body/OrderWeiQuanMQMsg.java
New file
@@ -0,0 +1,52 @@
package com.yeshi.fanli.dto.mq.order.body;
import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
/**
 * 订单确认收货消息
 *
 * @author Administrator
 *
 */
public class OrderWeiQuanMQMsg extends BaseMQMsgBody {
    private String orderNo;
    private String tradeId;
    private Integer sourceType;
    public OrderWeiQuanMQMsg(String orderNo, String tradeId, Integer sourceType) {
        this.orderNo = orderNo;
        this.tradeId = tradeId;
        this.sourceType = sourceType;
    }
    public OrderWeiQuanMQMsg() {
    }
    public String getOrderNo() {
        return orderNo;
    }
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    public String getTradeId() {
        return tradeId;
    }
    public void setTradeId(String tradeId) {
        this.tradeId = tradeId;
    }
    public Integer getSourceType() {
        return sourceType;
    }
    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }
}
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/body/TeamRewardPreRecieveMQMsg.java
New file
@@ -0,0 +1,71 @@
package com.yeshi.fanli.dto.mq.order.body;
import java.util.Date;
import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
/**
 * 团队奖金预到账消息
 * @author Administrator
 *
 */
public class TeamRewardPreRecieveMQMsg extends BaseMQMsgBody {
    private String key;
    private Long uid;
    private Integer sourceType;
    private Date preGetTime;
    private Date createTime;
    public TeamRewardPreRecieveMQMsg(String key, Long uid, Integer sourceType, Date preGetTime, Date createTime) {
        super();
        this.key = key;
        this.uid = uid;
        this.sourceType = sourceType;
        this.preGetTime = preGetTime;
        this.createTime = createTime;
    }
    public TeamRewardPreRecieveMQMsg() {
    }
    public Date getPreGetTime() {
        return preGetTime;
    }
    public void setPreGetTime(Date preGetTime) {
        this.preGetTime = preGetTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getKey() {
        return key;
    }
    public void setKey(String key) {
        this.key = key;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public Integer getSourceType() {
        return sourceType;
    }
    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }
}
fanli/src/main/java/com/yeshi/fanli/dto/order/dividents/UserDividentsDayDTO.java
@@ -1,13 +1,15 @@
package com.yeshi.fanli.dto.order.dividents;
import java.util.Date;
public class UserDividentsDayDTO {
    private Long uid;
    private String day;
    private Date preGetTime;
    public UserDividentsDayDTO(Long uid, String day) {
    public UserDividentsDayDTO(Long uid, Date preGetTime) {
        super();
        this.uid = uid;
        this.day = day;
        this.preGetTime = preGetTime;
    }
    public Long getUid() {
@@ -18,12 +20,12 @@
        this.uid = uid;
    }
    public String getDay() {
        return day;
    public Date getPreGetTime() {
        return preGetTime;
    }
    public void setDay(String day) {
        this.day = day;
    public void setPreGetTime(Date preGetTime) {
        this.preGetTime = preGetTime;
    }
}
fanli/src/main/java/com/yeshi/fanli/exception/order/OrderTeamRewardException.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/exception/order/dividents/TeamDividentsSourceOrderException.java
@@ -6,6 +6,8 @@
     
    private static final long serialVersionUID = 1L;
    
    public static int CODE_EXIST=1;
    public TeamDividentsSourceOrderException(int code, String msg) {
        super(code, msg);
    }
fanli/src/main/java/com/yeshi/fanli/mapping/hongbao/HongBaoV2Mapper.xml
@@ -236,7 +236,7 @@
        (hb_state=1 or hb_state=2) and
        hb_pre_get_time IS NOT NULL AND
        hb_pre_get_time>0 AND
        NOW()>=hb_pre_get_time limit
        #{maxDate}>=hb_pre_get_time limit
        #{start},#{count}
    </select>
@@ -260,7 +260,7 @@
        (hb_state=1 or hb_state=2) and
        hb_pre_get_time IS NOT NULL AND
        hb_pre_get_time>0 AND
        NOW()>=hb_pre_get_time
        #{maxDate}>=hb_pre_get_time
    </select>
fanli/src/main/java/com/yeshi/fanli/mapping/money/TeamEincomeRecordMapper.xml
@@ -94,4 +94,32 @@
        </set>
        where ti_id = #{id,jdbcType=BIGINT}
    </update>
    <select id="selectByUidAndPreRecieveTimeAndType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_income where ti_uid = #{uid} and ti_type=#{type}
        and ti_pre_recieve_time=#{preRecieveTime}
    </select>
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_income where ti_id = #{id,jdbcType=BIGINT} for
        update
    </select>
    <select id="listByUidAndPreRecieveTimeAndState" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_income where ti_uid = #{uid} and
        ti_pre_recieve_time=#{preRecieveTime} and ti_state=#{state}
    </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImplV2.java
@@ -22,7 +22,6 @@
import com.yeshi.fanli.entity.order.InviteOrderSubsidy;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
import com.yeshi.fanli.exception.order.OrderTeamRewardException;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
@@ -84,9 +83,8 @@
        return inviteOrderSubsidyMapper.listByOrderNoAndType(orderNo, type);
    }
    @Transactional(rollbackFor = Exception.class)
    private void addOrderSubsidy(InviteOrderSubsidy orderSubsidy)
            throws InviteOrderSubsidyException, OrderTeamRewardException, CommonOrderException {
            throws InviteOrderSubsidyException, CommonOrderException {
        if (orderSubsidy.getMoney() == null || StringUtil.isNullOrEmpty(orderSubsidy.getOrderNo())
                || orderSubsidy.getSourceType() == null || orderSubsidy.getUid() == null)
            throw new InviteOrderSubsidyException(1, "数据不完整");
@@ -121,7 +119,7 @@
            // 必须是自购订单才返利
            HongBaoV2 parent = hongBaoV2Service.selectByPrimaryKey(list.get(0).getHongBaoV2().getId());
            if (parent != null
                    && (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS || parent.getType() == HongBaoV2.TYPE_ZIGOU)) {// 不是超级会员的自购/分享才补贴
                    && (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS || parent.getType() == HongBaoV2.TYPE_ZIGOU)) {//
                List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
                if (orderList == null || orderList.size() == 0)
@@ -154,7 +152,7 @@
                    }
                    List<HongBaoV2> hbList = hongBaoV2Service.listByIds(idList);
                    Integer state = null;
                    Integer state = InviteOrderSubsidy.STATE_UNKNOWN;
                    // 产生改订单的返利总金额
                    BigDecimal totalBuyFanLiMoney = new BigDecimal(0);
@@ -163,15 +161,8 @@
                        if (v2.getState() == HongBaoV2.STATE_BUKELINGQU || v2.getState() == HongBaoV2.STATE_KELINGQU
                                || v2.getState() == HongBaoV2.STATE_YILINGQU)
                            totalBuyFanLiMoney = totalBuyFanLiMoney.add(v2.getMoney());
                        if (state == null && (v2.getState() == HongBaoV2.STATE_KELINGQU
                                || v2.getState() == HongBaoV2.STATE_YILINGQU)) {// 红包状态为已领取或者是待领取,则设置为补贴有效
                            state = InviteOrderSubsidy.STATE_VALID;
                        }
                    }
                    if (state == null)
                        state = InviteOrderSubsidy.STATE_UNKNOWN;
                    // 计算奖励金
                    for (Iterator<Long> its = uidHongBaoMap.keySet().iterator(); its.hasNext();) {
                        Long uid = its.next();
@@ -205,13 +196,24 @@
                            try {
                                addOrderSubsidy(orderSubsidy);
                            } catch (OrderTeamRewardException e) {
                                throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
                            } catch (CommonOrderException e) {
                                throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
                            }
                        }
                    }
                    boolean isSettle = false;
                    if (orderList != null)
                        for (CommonOrder commonOrder : orderList) {
                            if (commonOrder.getState() == CommonOrder.STATE_JS
                                    || commonOrder.getState() == CommonOrder.STATE_WQ) {
                                isSettle = true;
                                break;
                            }
                        }
                    if (isSettle) {
                        validByOrderIdAndSourceType(orderId, sourceType);
                    }
                }
            }
        }
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderHongBaoMoneyComputeServiceImpl.java
@@ -11,10 +11,15 @@
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.user.UserLevelUtil;
@Service
public class OrderHongBaoMoneyComputeServiceImpl implements OrderHongBaoMoneyComputeService {
    static long newRuleTime = TimeUtil.convertToTimeTemp(Constant.NEW_ORDER_FANLI_RULE_TIME, "yyyy-MM-dd");
    @Resource
    private HongBaoManageService hongBaoManageService;
@@ -29,8 +34,19 @@
        return getBaseCommission(order);
    }
    private UserLevelEnum getCommonUserLevel(Date time, UserLevelEnum userLevel) {
        if (userLevel == null)
            return UserLevelEnum.daRen;
        if (time.getTime() < newRuleTime)
            return UserLevelUtil.getOldLevel(userLevel);
        else
            return userLevel;
    }
    // 获取基础佣金
    private BigDecimal getBaseCommission(CommonOrder order) {
        if (order.getThirdCreateTime().getTime() >= newRuleTime) {
        BigDecimal rate = hongBaoManageService.getBaseFanliRate(order.getThirdCreateTime().getTime());
        if (order.getState() == CommonOrder.STATE_JS || order.getState() == CommonOrder.STATE_WQ)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.geteIncome()), new BigDecimal(100));
@@ -38,12 +54,8 @@
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.getEstimate()), new BigDecimal(100));
        else
            return null;
    }
    @Override
    public BigDecimal computeFanliMoney(CommonOrder order, UserLevelEnum userLevel) {
        BigDecimal rate = hongBaoManageService.getBaseFanliRate(order.getThirdCreateTime().getTime())
                .add(getOfficialSubsidyRate(order.getThirdCreateTime(), userLevel, false));
        } else {
            BigDecimal rate = hongBaoManageService.getFanLiRate(order.getThirdCreateTime().getTime());
        if (order.getState() == CommonOrder.STATE_JS || order.getState() == CommonOrder.STATE_WQ)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.geteIncome()), new BigDecimal(100));
        else if (order.getEstimate() != null)
@@ -51,11 +63,28 @@
        else
            return null;
    }
    }
    @Override
    public BigDecimal computeFanliMoney(CommonOrder order, UserLevelEnum userLevel) {
        BigDecimal rate = hongBaoManageService.getBaseFanliRate(order.getThirdCreateTime().getTime())
                .add(getOfficialSubsidyRate(order.getThirdCreateTime(),
                        getCommonUserLevel(order.getThirdCreateTime(), userLevel), false));
        if (order.getState() == CommonOrder.STATE_JS || order.getState() == CommonOrder.STATE_WQ)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.geteIncome()), new BigDecimal(100));
        else if (order.getEstimate() != null)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.getEstimate()), new BigDecimal(100));
        else
            return null;
    }
    @Override
    public BigDecimal computeShareMoney(CommonOrder order, UserLevelEnum userLevel) {
        BigDecimal rate = hongBaoManageService.getBaseFanliRate(order.getThirdCreateTime().getTime())
                .add(getOfficialSubsidyRate(order.getThirdCreateTime(), userLevel, true));
                .add(getOfficialSubsidyRate(order.getThirdCreateTime(),
                        getCommonUserLevel(order.getThirdCreateTime(), userLevel), true));
        if (order.getState() == CommonOrder.STATE_JS || order.getState() == CommonOrder.STATE_WQ)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.geteIncome()), new BigDecimal(100));
        else if (order.getEstimate() != null)
@@ -66,32 +95,29 @@
    @Override
    public BigDecimal computeFirstInviteMoney(CommonOrder order, UserLevelEnum buyer) {
        if (buyer == UserLevelEnum.superVIP) {
            BigDecimal rate = hongBaoManageService.getByKeyAndMaxTime("new_share_vip_21",
                    order.getThirdCreateTime().getTime());
            BigDecimal fanLiMoney = computeFanliMoney(order, buyer);
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, fanLiMoney), new BigDecimal(100));
        }
        BigDecimal rate = hongBaoManageService.getByKeyAndMaxTime("new_invite_6", order.getThirdCreateTime().getTime());
        if (order.getState() == CommonOrder.STATE_JS || order.getState() == CommonOrder.STATE_WQ)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.geteIncome()), new BigDecimal(100));
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                    new BigDecimal(100));
        else if (order.getEstimate() != null)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.getEstimate()), new BigDecimal(100));
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                    new BigDecimal(100));
        else
            return null;
    }
    @Override
    public BigDecimal computeSecondInviteMoney(CommonOrder order, UserLevelEnum buyer) {
        if (buyer == UserLevelEnum.superVIP)
        if (buyer == UserLevelEnum.superVIP || buyer == UserLevelEnum.tearcher)
            return null;
        BigDecimal rate = hongBaoManageService.getByKeyAndMaxTime("new_invite_7", order.getThirdCreateTime().getTime());
        if (order.getState() == CommonOrder.STATE_JS || order.getState() == CommonOrder.STATE_WQ)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.geteIncome()), new BigDecimal(100));
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                    new BigDecimal(100));
        else if (order.getEstimate() != null)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, order.getEstimate()), new BigDecimal(100));
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                    new BigDecimal(100));
        else
            return null;
    }
@@ -118,45 +144,6 @@
        BigDecimal officialSubsidyRate = getOfficialSubsidyRate(placeOrderTime, buyerUserLevel, false);
        return MoneyBigDecimalUtil.div(fanLiMoney.multiply(baseRate).multiply(rate),
                baseRate.add(officialSubsidyRate).multiply(new BigDecimal(100)));
    }
    @Override
    public BigDecimal computeFirstTeamReward(BigDecimal money, Date placeOrderTime, UserLevelEnum userLevel) {
        if (userLevel != UserLevelEnum.superVIP)
            return null;
        BigDecimal firstRate = getTeamRewardRate(placeOrderTime, userLevel, true);
        if (firstRate == null)
            return null;
        BigDecimal reward = MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(firstRate, money), new BigDecimal(100));
        return reward;
    }
    /**
     * 计算二级团队奖励
     * @Title: computeSecondTeamReward
     * @Description:
     * @param secondTeamSubsidy 购买者上两级团队补贴
     * @param userLevel 当前用户的等级
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal computeSecondTeamReward(BigDecimal secondTeamSubsidy, Date placeOrderTime,
            UserLevelEnum userLevel) {
        if (userLevel != UserLevelEnum.superVIP)
            return null;
        // 获取奖励比例
        BigDecimal secondRate = getTeamRewardRate(placeOrderTime, userLevel, false);
        if (secondRate == null)
            return null;
        BigDecimal secondReward = MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(secondRate, secondTeamSubsidy),
                new BigDecimal(100));
        return secondReward;
    }
    /**
@@ -203,36 +190,6 @@
            key = String.format("official_subsidy_share_%s", userLevel.getLevel());
        else
            key = String.format("official_subsidy_zigou_%s", userLevel.getLevel());
        BigDecimal rate = null;
        if (date != null)
            rate = hongBaoManageService.getByKeyAndMaxTime(key, date.getTime());
        else
            rate = new BigDecimal(hongBaoManageService.get(key));
        return rate;
    }
    /**
     * 获取团队奖励比例
     * @Title: getTeamRewardRate
     * @Description:
     * @param date
     * @param userLevel
     * @param first
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    private BigDecimal getTeamRewardRate(Date date, UserLevelEnum userLevel, boolean first) {
        if (userLevel == null)
            return null;
        if (userLevel != UserLevelEnum.superVIP)
            return new BigDecimal(0);
        String key = null;
        if (first)
            key = "team_reward_6_10";
        else
            key = "team_reward_7_10";
        BigDecimal rate = null;
        if (date != null)
            rate = hongBaoManageService.getByKeyAndMaxTime(key, date.getTime());
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -29,6 +29,7 @@
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.dto.mq.order.body.TeamRewardPreRecieveMQMsg;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.money.TeamRewardDebt;
@@ -52,7 +53,6 @@
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.manger.money.TeamEincomeManager;
import com.yeshi.fanli.service.manger.order.TeamRewardManager;
import com.yeshi.fanli.service.manger.order.TeamSubsidyManager;
import com.yeshi.fanli.util.Constant;
@@ -123,7 +123,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void inviteSettleTB(Long uid) throws OrderMoneySettleException {
    public void inviteSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_TAOBAO;
        List<Integer> types = new ArrayList<>();
@@ -131,13 +131,13 @@
        types.add(HongBaoV2.TYPE_ERJI);
        types.add(HongBaoV2.TYPE_SHARE_YIJI);
        types.add(HongBaoV2.TYPE_SHARE_ERJI);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
        List<HongBaoV2> hongBaoList = new ArrayList<>();
        // 1000条数据为1页
        int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
        for (int i = 0; i < page; i++) {
            List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
                    i * 1000, 1000);
                    maxPregetTime, i * 1000, 1000);
            if (tempHongBaoList != null && tempHongBaoList.size() > 0)
                hongBaoList.addAll(tempHongBaoList);
        }
@@ -161,12 +161,13 @@
            }
        }
        // 邀请赚到账事务消息
        OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
                sourceType, null, null, new Date(), 0);
        String taskKey = getTaskKey(uid);
        TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
                new Date());
        Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
        String taskKey = getTaskKey(uid);
        msg.setKey(taskKey);
        // 添加事务消息
        try {
@@ -174,14 +175,16 @@
                @Override
                public TransactionStatus execute(Message arg0, Object arg1) {
                    try {
                        fanliInvite(hongBaoList, uid, Constant.SOURCE_TYPE_TAOBAO, taskKey);
                        fanliInvite(hongBaoList, uid, Constant.SOURCE_TYPE_TAOBAO, taskKey, maxPregetTime);
                    } catch (Exception e) {
                        e.printStackTrace();
                        return TransactionStatus.RollbackTransaction;
                    }
                    return TransactionStatus.CommitTransaction;
                }
            }, null);
        } catch (Exception e) {
            e.printStackTrace();
            LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
        }
        System.out.println(new Gson().toJson(mqMsg));
@@ -189,7 +192,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void inviteSettleJD(Long uid) throws OrderMoneySettleException {
    public void inviteSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_JD;
        List<Integer> types = new ArrayList<>();
@@ -197,13 +200,13 @@
        types.add(HongBaoV2.TYPE_ERJI);
        types.add(HongBaoV2.TYPE_SHARE_YIJI);
        types.add(HongBaoV2.TYPE_SHARE_ERJI);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
        List<HongBaoV2> hongBaoList = new ArrayList<>();
        // 1000条数据为1页
        int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
        for (int i = 0; i < page; i++) {
            List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
                    i * 1000, 1000);
                    maxPregetTime, i * 1000, 1000);
            if (tempHongBaoList != null && tempHongBaoList.size() > 0)
                hongBaoList.addAll(tempHongBaoList);
        }
@@ -228,10 +231,11 @@
        }
        // 邀请赚到账事务消息
        OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
                sourceType, null, null, new Date(), 0);
        Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
        String taskKey = getTaskKey(uid);
        TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
                new Date());
        Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
        msg.setKey(taskKey);
        // 添加事务消息
        try {
@@ -239,7 +243,7 @@
                @Override
                public TransactionStatus execute(Message arg0, Object arg1) {
                    try {
                        fanliInvite(hongBaoList, uid, sourceType, taskKey);
                        fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
                    } catch (Exception e) {
                        e.printStackTrace();
                        return TransactionStatus.RollbackTransaction;
@@ -254,7 +258,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void inviteSettlePDD(Long uid) throws OrderMoneySettleException {
    public void inviteSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
        // 查询UID的一二级邀请赚
        int sourceType = Constant.SOURCE_TYPE_PDD;
        List<Integer> types = new ArrayList<>();
@@ -262,13 +266,13 @@
        types.add(HongBaoV2.TYPE_ERJI);
        types.add(HongBaoV2.TYPE_SHARE_YIJI);
        types.add(HongBaoV2.TYPE_SHARE_ERJI);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
        List<HongBaoV2> hongBaoList = new ArrayList<>();
        // 1000条数据为1页
        int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
        for (int i = 0; i < page; i++) {
            List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
                    i * 1000, 1000);
                    maxPregetTime, i * 1000, 1000);
            if (tempHongBaoList != null && tempHongBaoList.size() > 0)
                hongBaoList.addAll(tempHongBaoList);
        }
@@ -293,10 +297,10 @@
        }
        // 邀请赚到账事务消息
        OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
                sourceType, null, null, new Date(), 0);
        Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
        String taskKey = getTaskKey(uid);
        TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
                new Date());
        Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
        msg.setKey(taskKey);
        // 添加事务消息
        try {
@@ -304,7 +308,7 @@
                @Override
                public TransactionStatus execute(Message arg0, Object arg1) {
                    try {
                        fanliInvite(hongBaoList, uid, sourceType, taskKey);
                        fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
                    } catch (Exception e) {
                        return TransactionStatus.RollbackTransaction;
                    }
@@ -319,6 +323,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void shareSettleTB(Long uid) throws OrderMoneySettleException {
        Date maxPregetTime = new Date();
        /**
         * 处理分享赚
         */
@@ -327,13 +332,13 @@
        // 查询UID的分享赚订单
        types.add(HongBaoV2.TYPE_SHARE_GOODS);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
        List<HongBaoV2> hongBaoList = new ArrayList<>();
        // 1000条数据为1页
        int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
        for (int i = 0; i < page; i++) {
            List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
                    i * 1000, 1000);
                    maxPregetTime, i * 1000, 1000);
            if (tempHongBaoList != null && tempHongBaoList.size() > 0)
                hongBaoList.addAll(tempHongBaoList);
        }
@@ -365,6 +370,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void shareSettleJD(Long uid) throws OrderMoneySettleException {
        Date maxPregetTime = new Date();
        /**
         * 处理分享赚
         */
@@ -373,13 +379,13 @@
        // 查询UID的分享赚订单
        types.add(HongBaoV2.TYPE_SHARE_GOODS);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
        List<HongBaoV2> hongBaoList = new ArrayList<>();
        // 1000条数据为1页
        int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
        for (int i = 0; i < page; i++) {
            List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
                    i * 1000, 1000);
                    maxPregetTime, i * 1000, 1000);
            if (tempHongBaoList != null && tempHongBaoList.size() > 0)
                hongBaoList.addAll(tempHongBaoList);
        }
@@ -406,6 +412,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void shareSettlePDD(Long uid) throws OrderMoneySettleException {
        Date maxPregetTime = new Date();
        /**
         * 处理分享赚
         */
@@ -414,13 +421,13 @@
        // 查询UID的分享赚订单
        types.add(HongBaoV2.TYPE_SHARE_GOODS);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
        long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
        List<HongBaoV2> hongBaoList = new ArrayList<>();
        // 1000条数据为1页
        int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
        for (int i = 0; i < page; i++) {
            List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
                    i * 1000, 1000);
                    maxPregetTime, i * 1000, 1000);
            if (tempHongBaoList != null && tempHongBaoList.size() > 0)
                hongBaoList.addAll(tempHongBaoList);
        }
@@ -592,7 +599,7 @@
    }
    @Transactional
    private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key)
    private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key, Date maxPreGetTime)
            throws TeamEincomeRecordException, ParamsException, TeamRewardDebtException {
        List<Long> hbIdList = new ArrayList<>();
        BigDecimal invitemoney = new BigDecimal(0);
@@ -633,11 +640,8 @@
        // 邀请赚到账
        if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
            Calendar ca = Calendar.getInstance();
            Date date = new Date(TimeUtil.convertToTimeTemp(
                    ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
            // 获取当前的月份
            teamRewardManager.addToEincome(uid, date, invitemoney, sourceType);
            teamRewardManager.addToEincome(uid, maxPreGetTime, invitemoney, sourceType);
        }
        hongBaoV2SettleTempService.addTemp(hbIdList, key);
@@ -645,6 +649,7 @@
        // 所有的返利到账红包ID
        for (Long hongBaoId : hbIdList) {
            try {
                if (Constant.ENABLE_MQ)
                HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e);
@@ -863,9 +868,9 @@
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void inviteSubsidySettle(Long uid, String taskKey)
    public void inviteSubsidySettle(Long uid, String taskKey,Date maxPreGetTime)
            throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException {
        teamSubsidyManager.addToTeamEincome(uid, taskKey);
        teamSubsidyManager.addToTeamEincome(uid, taskKey,maxPreGetTime);
    }
    private String getTaskKey(Long uid) {
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -406,6 +406,7 @@
                    || hb.getPreGetTime().getTime() > System.currentTimeMillis())
                continue;
            try {
                if (Constant.ENABLE_MQ)
                CMQManager.getInstance().addFanLiMsgNew(hb);
            } catch (Exception e) {
                try {
@@ -520,6 +521,7 @@
            for (TaoBaoWeiQuanOrder order : orderList) {
                try {
                    if (order.getState().contains("维权成功")) {
                        if (Constant.ENABLE_MQ)
                        CMQManager.getInstance().addWeiQuanOrderMsg(order);
                    }
                } catch (Exception e) {
@@ -600,6 +602,7 @@
        while (its.hasNext()) {
            Long uid = its.next();
            try {
                if (Constant.ENABLE_MQ)
                CMQManager.getInstance().addFanLiTiChengMsg(uid);
            } catch (Exception e) {
                e.printStackTrace();
@@ -612,20 +615,21 @@
    @Transactional(rollbackFor = Exception.class)
    public void fanliInvaiteAndShare(Long uid) throws TaoBaoWeiQuanException {
        // 邀请赚到账
        Date now = new Date();
        try {
            orderMoneySettleService.inviteSettleTB(uid);
            orderMoneySettleService.inviteSettleTB(uid, now);
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
        try {
            orderMoneySettleService.inviteSettleJD(uid);
            orderMoneySettleService.inviteSettleJD(uid, now);
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
        //
        try {
            orderMoneySettleService.inviteSettlePDD(uid);
            orderMoneySettleService.inviteSettlePDD(uid, now);
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
@@ -645,6 +649,29 @@
        //
        try {
            orderMoneySettleService.shareSettlePDD(uid);
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void fanliPreInvaite(Long uid, Date maxPreGetTime) {
        // 邀请赚到账
        try {
            orderMoneySettleService.inviteSettleTB(uid, maxPreGetTime);
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
        try {
            orderMoneySettleService.inviteSettleJD(uid, maxPreGetTime);
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
        try {
            orderMoneySettleService.inviteSettlePDD(uid, maxPreGetTime);
        } catch (OrderMoneySettleException e) {
            e.printStackTrace();
        }
@@ -749,7 +776,7 @@
                    order.setOrderType(Constant.SOURCE_TYPE_TAOBAO);
                    order.setUserInfo(new UserInfo(uid));
                    try {
                        if (!Constant.IS_TEST)
                        if (Constant.ENABLE_MQ)
                            PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
                    } catch (Exception e) {
                    }
@@ -800,6 +827,7 @@
                    order.setOrderType(Constant.SOURCE_TYPE_TAOBAO);
                    order.setUserInfo(new UserInfo(uid));
                    try {
                        if (Constant.ENABLE_MQ)
                        PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
                    } catch (Exception e) {
                    }
@@ -922,6 +950,7 @@
                order.setOrderType(Constant.SOURCE_TYPE_JD);
                order.setUserInfo(new UserInfo(uid));
                try {
                    if (Constant.ENABLE_MQ)
                    PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
                } catch (Exception e) {
                }
@@ -953,6 +982,7 @@
                order.setOrderType(Constant.SOURCE_TYPE_JD);
                order.setUserInfo(new UserInfo(uid));
                try {
                    if (Constant.ENABLE_MQ)
                    PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
                } catch (Exception e) {
                }
@@ -1062,6 +1092,7 @@
                order.setOrderType(Constant.SOURCE_TYPE_PDD);
                order.setUserInfo(new UserInfo(uid));
                try {
                    if (Constant.ENABLE_MQ)
                    PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
                } catch (Exception e) {
                }
@@ -1095,6 +1126,7 @@
                order.setOrderType(Constant.SOURCE_TYPE_PDD);
                order.setUserInfo(new UserInfo(uid));
                try {
                    if (Constant.ENABLE_MQ)
                    PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
                } catch (Exception e) {
                }
@@ -1250,7 +1282,7 @@
    public List<HongBaoV2> getCanBalanceElmeFanliHongBao() {
        List<Integer> list = new ArrayList<>();
        list.add(HongBaoV2.TYPE_ELME);
        return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, null, 0, 1000);
        return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, null, new Date(), 0, 1000);
    }
    @Override
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderServiceImpl.java
@@ -31,7 +31,7 @@
        TeamDividentsSourceOrder sourceOrder = selectByOrderNoSourceType(order.getOrderNo(), order.getSourceType());
        if (sourceOrder != null)
            throw new TeamDividentsSourceOrderException(1, "订单已存在");
            throw new TeamDividentsSourceOrderException(TeamDividentsSourceOrderException.CODE_EXIST, "订单已存在");
        if (order.getCreateTime() == null)
            order.setCreateTime(new Date());
fanli/src/main/java/com/yeshi/fanli/service/impl/order/tb/TaoBaoWeiQuanOrderServiceImpl.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.impl.order.tb;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@@ -8,7 +9,12 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.BanLiShopOrderMQMsg;
import com.yeshi.fanli.dto.mq.order.body.OrderWeiQuanMQMsg;
import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail;
import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail.MsgTypeOrderTypeEnum;
import com.yeshi.fanli.entity.order.CommonOrder;
@@ -19,6 +25,8 @@
import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService;
import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
@Service
public class TaoBaoWeiQuanOrderServiceImpl implements TaoBaoWeiQuanOrderService {
@@ -37,15 +45,23 @@
    @Resource
    private UserOrderWeiQuanRecordService userOrderWeiQuanRecordService;
    @Resource(name = "producer")
    private Producer producer;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addWeiQuanOrder(TaoBaoWeiQuanOrder order) {
        if (order == null)
            return;
        boolean isAdd = false;
        boolean isUpdate = false;
        Long id = null;
        TaoBaoWeiQuanOrder taoBaoWeiQuanOrder = taoBaoWeiQuanOrderMapper
                .selectByOrderIdAndOrderItemId(order.getOrderId(), order.getOrderItemId());
        if (taoBaoWeiQuanOrder != null) {
            id = taoBaoWeiQuanOrder.getId();
            // 已经是最新的状态了
            if (taoBaoWeiQuanOrder.getState() != null && (taoBaoWeiQuanOrder.getState().contains("维权成功")))
                return;
@@ -59,7 +75,7 @@
            update.setUpdateTime(new Date());
            update.setWeiQuanFinishTime(order.getWeiQuanFinishTime());
            taoBaoWeiQuanOrderMapper.updateByPrimaryKeySelective(update);
            isUpdate = true;
            try {
                if (order.getState().contains("维权成功")) {
                    // 更改CommonOrder的状态
@@ -72,26 +88,6 @@
                        commonOrderService.updateByPrimaryKeySelective(updateCommonOrder);
                        userOrderWeiQuanRecordService.addTaoBaoWeiQuan(taoBaoWeiQuanOrder);
                    }
                    // 维权状态不需要消息
                    // List<MsgOrderDetail> msgList =
                    // msgOrderDetailService.listMsgOrderByOrderId(order.getOrderId());
                    // for (MsgOrderDetail msg : msgList) {
                    // if (msg.getType() == MsgTypeOrderTypeEnum.fanli) {
                    // userOrderMsgNotificationService.orderFanLiStateChanged(msg.getUser().getId(),
                    // order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null,
                    // null, CommonOrder.STATE_WQ);
                    // } else if (msg.getType() == MsgTypeOrderTypeEnum.invite)
                    // {
                    // userOrderMsgNotificationService.orderInviteStateChanged(msg.getUser().getId(),
                    // order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null,
                    // null, CommonOrder.STATE_WQ);
                    // } else if (msg.getType() == MsgTypeOrderTypeEnum.share) {
                    // userOrderMsgNotificationService.orderShareStateChanged(msg.getUser().getId(),
                    // order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, null,
                    // null, CommonOrder.STATE_WQ);
                    // }
                    // }
                }
            } catch (Exception e) {
@@ -100,6 +96,8 @@
            order.setCreateTime(new Date());
            order.setUpdateTime(new Date());
            taoBaoWeiQuanOrderMapper.insertSelective(order);
            id = order.getId();
            isAdd = true;
            if (order.getState().contains("维权成功")) {
                // 更改CommonOrder的状态
                CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
@@ -113,6 +111,18 @@
                }
            }
        }
        // 增加或修改
        if (isAdd || isUpdate) {
            if (id != null) {
                OrderWeiQuanMQMsg msg = new OrderWeiQuanMQMsg(order.getOrderId(), order.getOrderItemId(),
                        Constant.SOURCE_TYPE_TAOBAO);
                Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.taoBaoOrderWeiQuan,
                        msg);
                producer.send(message);
            }
        }
    }
    @Override
fanli/src/main/java/com/yeshi/fanli/service/inter/order/InviteOrderSubsidyService.java
@@ -6,7 +6,6 @@
import com.yeshi.fanli.entity.order.InviteOrderSubsidy;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
import com.yeshi.fanli.exception.order.OrderTeamRewardException;
public interface InviteOrderSubsidyService {
@@ -39,7 +38,7 @@
     * @param sourceType
     */
    public void addOrUpdateByOrder(String orderId, int sourceType)
            throws InviteOrderSubsidyException, OrderTeamRewardException, CommonOrderException;
            throws InviteOrderSubsidyException, CommonOrderException;
    /**
     * 根据订单号与来源查询
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderHongBaoMoneyComputeService.java
@@ -110,31 +110,6 @@
    public BigDecimal computeSecondTeamSubsidy(BigDecimal fanLiMoney, Date placeOrderTime, UserLevelEnum buyerUserLevel,
            UserLevelEnum userLevel);
    /**
     * 计算一级团队奖励
     * @Title: computeFirstTeamReward
     * @Description:
     * @param firstTeamSubsidy -购买者上一级团队补贴
     * @param secondTeamSubsidy-购买者上两级团队补贴
     * @param userLevel  当前用户的等级
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal computeFirstTeamReward(BigDecimal firstTeamSubsidy, Date placeOrderTime, UserLevelEnum userLevel);
    /**
     * 计算二级团队奖励
     * @Title: computeSecondTeamReward
     * @Description:
     * @param secondTeamSubsidy 购买者上两级团队补贴
     * @param userLevel 当前用户的等级
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal computeSecondTeamReward(BigDecimal secondTeamSubsidy, Date placeOrderTime,
            UserLevelEnum userLevel);
    /**
     * 计算团队补贴
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderMoneySettleService.java
@@ -1,5 +1,7 @@
package com.yeshi.fanli.service.inter.order;
import java.util.Date;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.OrderMoneySettleException;
import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
@@ -17,11 +19,11 @@
     * 
     * @param uid
     */
    public void inviteSettleTB(Long uid) throws OrderMoneySettleException;
    public void inviteSettleTB(Long uid,Date maxPregetTime) throws OrderMoneySettleException;
    public void inviteSettleJD(Long uid) throws OrderMoneySettleException;
    public void inviteSettleJD(Long uid,Date maxPregetTime) throws OrderMoneySettleException;
    public void inviteSettlePDD(Long uid) throws OrderMoneySettleException;
    public void inviteSettlePDD(Long uid,Date maxPregetTime) throws OrderMoneySettleException;
    /**
     * 分享赚结算
@@ -48,7 +50,7 @@
     * @param taskKey
     * @throws OrderMoneySettleException
     */
    public void inviteSubsidySettle(Long uid, String taskKey)
    public void inviteSubsidySettle(Long uid, String taskKey,Date maxPreGetTime)
            throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException;
}
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderProcessService.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.inter.order;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -9,7 +10,6 @@
import com.yeshi.fanli.entity.pdd.PDDOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.money.OrderMoneySettleException;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.exception.order.OrderItemException;
import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
@@ -71,6 +71,17 @@
    public void fanliInvaiteAndShare();
    /**
     * 结算团队收益
     * @Title: fanliInvaite
     * @Description:
     * @param maxPreGetTime
     * void 返回类型
     * @throws
     */
    public void fanliPreInvaite(Long uid, Date maxPreGetTime);
    /**
     * 分享赚与邀请赚返利
     */
    public void fanliInvaiteAndShare(Long uid) throws TaoBaoWeiQuanException;
fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java
@@ -19,7 +19,6 @@
import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper;
import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.order.OrderHongBaoRateParams;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserInfo;
@@ -27,9 +26,14 @@
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
import com.yeshi.fanli.exception.user.UserAccountException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
@@ -42,6 +46,7 @@
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.user.UserLevelUtil;
@Component
public class HongBaoV2AddManager {
@@ -82,6 +87,12 @@
    @Resource
    private UserLevelManager userLevelManager;
    @Resource
    private InviteOrderSubsidyService inviteOrderSubsidyService;
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
    /**
     * 添加红包信息
     * 
@@ -90,17 +101,29 @@
     * @return
     * @throws HongBaoException
     * @throws UserAccountException
     * @throws CommonOrderException
     * @throws OrderTeamRewardException
     * @throws InviteOrderSubsidyException
     */
    public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException {
        if (commonOrderList != null && commonOrderList.size() > 0) {
            int orderType = commonOrderList.get(0).getSourceType();
            String orderId = commonOrderList.get(0).getOrderNo();
            Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
            int goodsCount = 0;
            boolean hasAdd = false;
            boolean hasUpdate = false;
            Set<Integer> stateSet = new HashSet<>();// 订单状态Set
            UserLevelEnum userLevel = UserLevelUtil.getByOrderRank(commonOrderList.get(0).getUrank());
            if (userLevel == null)
                userLevel = UserLevelEnum.daRen;
            Date placeOrderDate = commonOrderList.get(0).getThirdCreateTime();
            for (CommonOrder commonOrder : commonOrderList) {
                stateSet.add(commonOrder.getState());
                goodsCount += commonOrder.getCount();
@@ -108,19 +131,46 @@
                    throw new HongBaoException(1, "订单信息不完整");
                HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                if (hongBaoOrder == null) {
                    saveHongBao(commonOrder, type, notificationMap);
                    saveHongBao(commonOrder, type, notificationMap, userLevel, placeOrderDate);
                    hasAdd = true;
                } else {
                    boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
                    if (update)
                    boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap, placeOrderDate);
                    if (update) {
                        hasUpdate = true;
                    }
                }
            }
            if (hasAdd) {
                try {
                    inviteOrderSubsidyService.addOrUpdateByOrder(orderId, orderType);
                } catch (InviteOrderSubsidyException e) {
                    throw new HongBaoException(201, "添加补贴出错");
                } catch (CommonOrderException e) {
                    throw new HongBaoException(202, "添加补贴出错");
                }
            }
            int state = getOrderState(stateSet);
            if (hasAdd || hasUpdate) {
                // 补贴失效
                if (state == CommonOrder.STATE_SX)
                    inviteOrderSubsidyService.invalidByOrderIdAndSourceType(orderId, orderType);
                else
                    try {
                        inviteOrderSubsidyService.addOrUpdateByOrder(orderId, orderType);
                    } catch (InviteOrderSubsidyException e) {
                        LogHelper.errorDetailInfo(e, "淘宝订单补贴更新失败", orderId);
                    } catch (CommonOrderException e) {
                        LogHelper.errorDetailInfo(e, "淘宝订单补贴更新失败", orderId);
                }
            }
            /**
             * 通知用户的返利情况
             */
            int state = getOrderState(stateSet);
            if (!Constant.IS_TEST) {
                if (hasAdd) {
                    Iterator<Integer> its = notificationMap.keySet().iterator();
@@ -128,45 +178,46 @@
                        Integer t = its.next();
                        HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
                        CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
                        String orderId = commonOrderList.get(0).getOrderNo();
                        Long uid = notify.getUserInfo().getId();
                        BigDecimal money = notify.getMoney();
                        switch (t) {
                        case HongBaoV2.TYPE_ZIGOU:
                            userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                                    commonOrder.getPayment(), money, goodsCount, state,
                                    commonOrder.getThirdCreateTime());
                            break;
                        case HongBaoV2.TYPE_SHARE_GOODS:
                            userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                                    commonOrder.getPayment(), money, goodsCount, state,
                                    commonOrder.getThirdCreateTime());
                            break;
                        case HongBaoV2.TYPE_YIJI:
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                                    commonOrder.getPayment(), money, goodsCount, state,
                                    commonOrder.getThirdCreateTime());
                            break;
                        case HongBaoV2.TYPE_ERJI:
                        
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,     commonOrder.getPayment(), money,
                                    goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, state,
                                    commonOrder.getThirdCreateTime());
                            break;
                        case HongBaoV2.TYPE_SHARE_YIJI:
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                                    commonOrder.getPayment(), money, goodsCount, state,
                                    commonOrder.getThirdCreateTime());
                            break;
                        case HongBaoV2.TYPE_SHARE_ERJI:
                        
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,     commonOrder.getPayment(), money,
                                    goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, state,
                                    commonOrder.getThirdCreateTime());
                            break;    
                            
@@ -203,19 +254,23 @@
    @Transactional(rollbackFor = Exception.class)
    private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
            Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException, UserAccountException {
            Map<Integer, HongBaoOrder> notificationMap, Date placeOrderTime)
            throws HongBaoException, UserAccountException {
        System.out.println(commonOrder.getOrderNo());
        // 锁行
        HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBaoOrder.getHongBaoV2().getId());
        if (oldHongBao == null)
            throw new HongBaoException(10, "红包对象不存在");
        UserLevelEnum buyerLevel = UserLevelUtil.getByOrderRank(oldHongBao.getUrank());
        if (buyerLevel == null)
            throw new HongBaoException(201, "用户等级为空");
        // 已经失效,已经领取,新老状态一致的红包不做处理
        if (oldHongBao.getState() == HongBaoV2.STATE_SHIXIAO || oldHongBao.getState() == HongBaoV2.STATE_YILINGQU)
            return false;
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
            BigDecimal fanliRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(0, type, false,
                    oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
            BigDecimal money = orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel);
            // 免单处理
            boolean mianDan = false;
            List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
@@ -231,7 +286,7 @@
                }
            }
            HongBaoV2 hongBao = createFanLiUpdateHongBao(commonOrder, fanliRate, hongBaoOrder.getHongBaoV2().getId(),
            HongBaoV2 hongBao = createFanLiUpdateHongBao(commonOrder, money, hongBaoOrder.getHongBaoV2().getId(),
                    mianDan);
            // 新老红包状态一致不处理
@@ -258,12 +313,14 @@
                tempHongBao.setMoney(hongBao.getMoney());
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
                HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
                tempHongBaoOrder.getCommonOrder()
                        .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
                notificationMap.put(type, tempHongBaoOrder);
@@ -275,17 +332,14 @@
                for (HongBaoV2 child : children) {
                    if (child.getState() == HongBaoV2.STATE_YILINGQU)
                        continue;
                    BigDecimal rate = null;
                    if (child.getType() == HongBaoV2.TYPE_YIJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                        money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                    } else if (child.getType() == HongBaoV2.TYPE_ERJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                    }
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(),
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))), commonOrder);
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder);
                    hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
                    // 加入通知
@@ -295,6 +349,7 @@
                        tempHongBao.setMoney(child.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                        notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
                    } else {
                        // 增加付款金额与资金
@@ -310,7 +365,7 @@
                if (!mianDan) {
                    ThreeSale threeSale = threeSaleSerivce.selectByWorkerId(commonOrder.getUserInfo().getId());
                    if (threeSale != null && threeSale.getSucceedTime() != null
                            && threeSale.getSucceedTime() <= commonOrder.getThirdCreateTime().getTime()) {
                            && threeSale.getSucceedTime() <= placeOrderTime.getTime()) {
                        UserInfo boss = threeSaleSerivce.getBoss(commonOrder.getUserInfo().getId());
                        if (boss != null) {
                            boss = userInfoService.selectAvailableByPrimaryKey(boss.getId());
@@ -318,12 +373,11 @@
                        if (boss != null) {
                            // 插入一级子红包
                            BigDecimal firstRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, type,
                                    false, oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                            if (firstRate != null && firstRate.compareTo(new BigDecimal(0)) > 0) {
                            money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                            UserLevelEnum bossUserLevel = userLevelManager.getUserLevel(boss.getId());
                            if (money != null) {
                                HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder,
                                        HongBaoV2.TYPE_YIJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                                                firstRate.divide(new BigDecimal(100))));
                                        HongBaoV2.TYPE_YIJI, money, bossUserLevel);
                                if (firstHongbao != null)
                                    addInviteHongBao(firstHongbao, null, notificationMap, commonOrder);
                            }
@@ -332,13 +386,12 @@
                                boss = userInfoService.selectAvailableByPrimaryKey(boss.getId());
                            }
                            if (boss != null) {
                                // 二级红包
                                BigDecimal secondRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, type,
                                        false, oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                                if (secondRate != null && secondRate.compareTo(new BigDecimal(0)) > 0) {
                                money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder,
                                        buyerLevel);
                                bossUserLevel = userLevelManager.getUserLevel(boss.getId());
                                if (money != null) {
                                    HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder,
                                            HongBaoV2.TYPE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                                                    secondRate.divide(new BigDecimal(100))));
                                            HongBaoV2.TYPE_ERJI, money, bossUserLevel);
                                    if (secondHongbao != null)
                                        addInviteHongBao(secondHongbao, null, notificationMap, commonOrder);
                                }
@@ -348,10 +401,10 @@
                }
            }
        } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
            BigDecimal fanliRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(0, type, false,
                    oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
            HongBaoV2 hongBao = createShareUpdateHongBao(commonOrder, fanliRate, oldHongBao.getId());
            BigDecimal money = orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, buyerLevel);
            HongBaoV2 hongBao = createShareUpdateHongBao(commonOrder, money, oldHongBao.getId());
            hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
            // 通知
            if (notificationMap.get(type) == null) {
@@ -360,6 +413,7 @@
                tempHongBao.setMoney(hongBao.getMoney());
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
@@ -378,16 +432,12 @@
                    if (child.getState() == HongBaoV2.STATE_YILINGQU)
                        continue;
                    BigDecimal rate = null;
                    if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                        money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                    } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                    }
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(),
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))), commonOrder);
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder);
                    hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
                    // 添加通知
                    if (notificationMap.get(child.getType()) == null) {
@@ -397,6 +447,7 @@
                                .setMoney(childUpdate.getMoney() == null ? new BigDecimal(0) : childUpdate.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                        notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
                    } else {
                        // 增加付款金额与资金
@@ -418,13 +469,10 @@
    }
    @Transactional(rollbackFor = Exception.class)
    private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
            throws HongBaoException, UserAccountException {
    private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap,
            UserLevelEnum buyerLevel, Date placeOrderDate) throws HongBaoException, UserAccountException {
        boolean vip = commonOrder.getUrank() != null && commonOrder.getUrank() == 100;
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
            BigDecimal fanliRate = hongBaoManageService
                    .getRate(new OrderHongBaoRateParams(0, type, false, vip, commonOrder.getThirdCreateTime()));
        if (type == HongBaoV2.TYPE_ZIGOU) {
            // 查询是否有免单计划
            BigDecimal mianDanMoney = null;
            if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
@@ -434,7 +482,6 @@
                    BigDecimal payMent = commonOrder.getPayment();
                    if (commonOrder.getState() == CommonOrder.STATE_JS)
                        payMent = commonOrder.getSettlement();
                    CommonOrderGoods goods = commonOrderGoodsMapper
                            .selectByPrimaryKey(commonOrder.getCommonOrderGoods().getId());
                    if (goods != null) {
@@ -459,33 +506,34 @@
                }
            }
            HongBaoV2 hongBao = createFanLiHongBao(commonOrder, fanliRate, mianDanMoney);
            HongBaoV2 hongBao = createFanLiHongBao(commonOrder,
                    orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel), mianDanMoney,
                    buyerLevel);
            if (hongBao == null)
                return;
            addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
            UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
            if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1级BOSS存在且红包未失效,免单不支持多级分销
                // 插入一级子红包
                BigDecimal firstRate = hongBaoManageService
                        .getRate(new OrderHongBaoRateParams(1, type, false, vip, commonOrder.getThirdCreateTime()));
                if (firstRate.compareTo(new BigDecimal(0)) <= 0)// 返利比例为0的不分成
                BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                if (money == null)// 返利资金为空不参与分成
                    return;
                UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId());
                HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, HongBaoV2.TYPE_YIJI,
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
                        money, bossLevel);
                addInviteHongBao(firstHongbao, null, notificationMap, commonOrder);
                // 插入二级子红包
                boss = threeSaleSerivce.getBoss(boss.getId());
                if (boss != null) {// 二级BOSS存在且是非会员订单
                    BigDecimal secondRate = hongBaoManageService
                            .getRate(new OrderHongBaoRateParams(2, type, false, vip, commonOrder.getThirdCreateTime()));
                    if (secondRate.compareTo(new BigDecimal(0)) <= 0)
                    money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                    bossLevel = userLevelManager.getUserLevel(boss.getId());
                    if (money == null)
                        return;
                    HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                            HongBaoV2.TYPE_ERJI,
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
                            HongBaoV2.TYPE_ERJI, money, bossLevel);
                    addInviteHongBao(secondHongbao, null, notificationMap, commonOrder);
                }
            }
@@ -495,45 +543,48 @@
            if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
                return;
            // 分享赚
            BigDecimal shareRate = null;
            BigDecimal money = null;
            if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO
                    && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))// 来自于淘礼金的分享
                shareRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
            {
                BigDecimal shareRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
                if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ)
                    money = MoneyBigDecimalUtil.mul(commonOrder.geteIncome(),
                            MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100)));
            else
                shareRate = hongBaoManageService
                        .getRate(new OrderHongBaoRateParams(0, type, false, vip, commonOrder.getThirdCreateTime()));
                    money = MoneyBigDecimalUtil.mul(commonOrder.getEstimate(),
                            MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100)));
            } else
                money = orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, buyerLevel);
            if (shareRate.compareTo(new BigDecimal(0)) <= 0)
            if (money == null || money.compareTo(new BigDecimal(0)) <= 0)
                return;
            HongBaoV2 hongBao = createShareHongBao(commonOrder, shareRate, vip);
            HongBaoV2 hongBao = createShareHongBao(commonOrder, money, buyerLevel);
            if (hongBao == null)
                return;
            addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
            // 4月17日后才有一级分享赚
            if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) {
            if (placeOrderDate.getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) {
                UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
                if (boss != null) {
                    BigDecimal firstLevelRate = hongBaoManageService
                            .getRate(new OrderHongBaoRateParams(1, type, false, vip, commonOrder.getThirdCreateTime()));
                    if (firstLevelRate == null || firstLevelRate.compareTo(new BigDecimal("0")) == 0)
                    money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                    if (money == null)
                        return;
                    UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId());
                    HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                            HongBaoV2.TYPE_SHARE_YIJI,
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstLevelRate.divide(new BigDecimal(100))));
                            HongBaoV2.TYPE_SHARE_YIJI, money, bossLevel);
                    addInviteHongBao(firstHongbao, hongBao.getUserInfo().getNickName(), notificationMap, commonOrder);
                    // 二级分享赚
                    boss = threeSaleSerivce.getBoss(boss.getId());
                    if (boss != null) {
                        BigDecimal secondLevelRate = hongBaoManageService.getRate(
                                new OrderHongBaoRateParams(2, type, false, vip, commonOrder.getThirdCreateTime()));
                        if (secondLevelRate.compareTo(new BigDecimal(0)) <= 0)// 返利比例为0就不统计
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                        if (money == null)// 返利比例为0就不统计
                            return;
                        bossLevel = userLevelManager.getUserLevel(boss.getId());
                        HongBaoV2 secondChild = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                                HongBaoV2.TYPE_SHARE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                                        secondLevelRate.divide(new BigDecimal(100))));
                                HongBaoV2.TYPE_SHARE_ERJI, money, bossLevel);
                        addInviteHongBao(secondChild, null, notificationMap, commonOrder);
                    }
                }
@@ -586,6 +637,7 @@
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
@@ -610,7 +662,7 @@
     * @return
     */
    private HongBaoV2 createInviteHongBao(Long uid, HongBaoV2 parent, CommonOrder commonOrder, int hongBaoType,
            BigDecimal money) {
            BigDecimal money, UserLevelEnum userLevel) {
        if (parent == null)
            return null;
        if (parent.getState() == HongBaoV2.STATE_SHIXIAO)
@@ -618,8 +670,6 @@
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
        if (user == null)
            return null;
        UserLevelEnum level = userLevelManager.getUserLevel(uid);
        HongBaoV2 child = new HongBaoV2();
        child.setParent(parent);
@@ -638,11 +688,13 @@
        }
        child.setUserInfo(user);
        child.setUrank(level.getOrderRank());
        child.setUrank(user.getRank());
        child.setVersion(2);
        child.setCreateTime(new Date());
        child.setOrderType(commonOrder.getSourceType());
        if (child.getMoney() == null)
            return null;
        if (child.getMoney().compareTo(new BigDecimal(0)) <= 0 && userLevel == UserLevelEnum.daRen)
            return null;
        return child;
    }
@@ -655,22 +707,24 @@
     *            -返利比例
     * @param mianDanMoney
     *            免单金额
     * @param isVIP-是否为VIP订单
     * @return
     * @throws HongBaoException
     * @throws UserAccountException
     */
    private HongBaoV2 createFanLiHongBao(CommonOrder commonOrder, BigDecimal fanliRate, BigDecimal mianDanMoney) throws HongBaoException, UserAccountException {
    private HongBaoV2 createFanLiHongBao(CommonOrder commonOrder, BigDecimal money, BigDecimal mianDanMoney,
            UserLevelEnum userLevel) throws HongBaoException, UserAccountException {
        HongBaoV2 hongBao = new HongBaoV2();
        hongBao.setUserInfo(commonOrder.getUserInfo());
        hongBao.setCreateTime(new Date());
        hongBao.setType(HongBaoV2.TYPE_ZIGOU);
        hongBao.setVersion(2);
        hongBao.setMoney(money);
        if (commonOrder.getState() == CommonOrder.STATE_FK) {
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
        } else if (commonOrder.getState() == CommonOrder.STATE_JS || CommonOrder.STATE_WQ == commonOrder.getState()) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
            if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_PDD)// 拼多多15天半到账
                hongBao.setPreGetTime(new Date(
                        commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L + 1000 * 60 * 60 * 12L));
@@ -689,13 +743,7 @@
        UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
        if (user == null)
            throw new UserAccountException(1001, "用户不存在/被封禁");
        UserLevelEnum userLevel = userLevelManager.getUserLevel(commonOrder.getUserInfo().getId(),
                commonOrder.getThirdCreateTime());
        if (userLevel != null)
            hongBao.setUrank(userLevel.getOrderRank());
        else {
            hongBao.setUrank(user.getRank());
        }
        hongBao.setOrderType(commonOrder.getSourceType());
        return hongBao;
    }
@@ -795,6 +843,7 @@
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
            tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
            notificationMap.put(hongBao.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
        } else {
            // 增加付款金额与资金
@@ -816,18 +865,17 @@
     * @throws HongBaoException
     * @throws UserAccountException
     */
    private HongBaoV2 createShareHongBao(CommonOrder commonOrder, BigDecimal shareRate, boolean isVip)
    private HongBaoV2 createShareHongBao(CommonOrder commonOrder, BigDecimal money, UserLevelEnum userLevel)
            throws HongBaoException, UserAccountException {
        HongBaoV2 hongBao = new HongBaoV2();
        hongBao.setCreateTime(new Date());
        hongBao.setType(HongBaoV2.TYPE_SHARE_GOODS);
        hongBao.setVersion(2);
        hongBao.setMoney(money);
        if (commonOrder.getState() == CommonOrder.STATE_FK) {
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), shareRate.divide(new BigDecimal(100))));
        } else if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), shareRate.divide(new BigDecimal(100))));
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(commonOrder.getSettleTime());
            calendar.add(Calendar.MONTH, 1);
@@ -837,12 +885,7 @@
        UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
        if (user == null)
            throw new UserAccountException(1001, "用户不存在/被封禁");
        UserLevelEnum userLevel = userLevelManager.getUserLevel(commonOrder.getUserInfo().getId(),
                commonOrder.getThirdCreateTime());
        if (userLevel != null)
            hongBao.setUrank(userLevel.getOrderRank());
        else
            hongBao.setUrank(user.getRank());
        hongBao.setUserInfo(user);
        hongBao.setOrderType(commonOrder.getSourceType());
        return hongBao;
fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManagerV2.java
@@ -169,8 +169,9 @@
                            break;
                        case HongBaoV2.TYPE_ERJI:
                        
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,     commonOrder.getPayment(), money,
                                    goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                                    commonOrder.getThirdCreateTime());
                            break;
@@ -181,8 +182,9 @@
                            break;
                        case HongBaoV2.TYPE_SHARE_ERJI:
                        
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,     commonOrder.getPayment(), money,
                                    goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
                                    commonOrder.getThirdCreateTime());
                            break;    
                        }
@@ -277,12 +279,14 @@
                tempHongBao.setMoney(hongBao.getMoney());
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
                HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
                tempHongBaoOrder.getCommonOrder()
                        .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
                notificationMap.put(type, tempHongBaoOrder);
@@ -311,6 +315,7 @@
                        tempHongBao.setMoney(child.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                        notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
                    } else {
                        // 增加付款金额与资金
@@ -374,6 +379,7 @@
                tempHongBao.setMoney(hongBao.getMoney());
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
@@ -407,6 +413,7 @@
                                .setMoney(childUpdate.getMoney() == null ? new BigDecimal(0) : childUpdate.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                        notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
                    } else {
                        // 增加付款金额与资金
@@ -596,6 +603,7 @@
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
                notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
@@ -800,6 +808,7 @@
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
            tempCommonOrder.setThirdCreateTime(commonOrder.getThirdCreateTime());
            notificationMap.put(hongBao.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
        } else {
            // 增加付款金额与资金
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsManager.java
@@ -84,13 +84,14 @@
            level = UserLevelEnum.daRen;
        BigDecimal rate = getSourceOrderDividentsRate(level);
        TeamDividentsSourceOrder order = TeamDividentsSourceOrderFactory.create(commonOrderList, rate);
        if (order == null)
            return;
        try {
            teamDividentsSourceOrderService.addTeamDividentsSourceOrder(order);
        } catch (TeamDividentsSourceOrderException e) {
            e.printStackTrace();
        } catch (ParamsException e) {
            e.printStackTrace();
            throw new TeamDividentsSourceOrderException(101, "参数不完整");
        }
    }
    /**
@@ -189,6 +190,11 @@
            }
        }
        // 没有参与分红的用户
        if (uidLevel == null || uidLevel.size() == 0) {
            return;
        }
        BigDecimal perDivident = computePerDivident(uidLevel, totalMoney);
        for (Iterator<Long> its = uidLevel.keySet().iterator(); its.hasNext();) {
            Long uid = its.next();
@@ -256,9 +262,9 @@
     * @throws
     */
    @Transactional(rollbackFor = Exception.class)
    public void addToTeamEincome(Long uid, String day) throws TeamDividentsRecordException, TeamDividentsDebtException,
            UserMoneyDetailException, ParamsException, TeamEincomeRecordException {
        Date preSendTime = new Date(TimeUtil.convertToTimeTemp(day, "yyyy-MM-dd"));
    public void addToTeamEincome(Long uid, Date preSendTime) throws TeamDividentsRecordException,
            TeamDividentsDebtException, UserMoneyDetailException, ParamsException, TeamEincomeRecordException {
        String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
        BigDecimal money = teamDividentsSourceUserService.sumMoneyByUidAndDay(uid, day);
        // 查询需要扣除的资金
        List<TeamDividentsDebt> list = teamDividentsDebtService.listNeedRepayDebt(uid, preSendTime, 1, 1000);
@@ -339,7 +345,6 @@
        } else if (sourceOrder.getState() == TeamDividentsSourceOrder.STATE_CAN_SEND) {
            teamDividentsSourceOrderService.invalidOrder(orderNo, sourceType, "订单维权");
        }
    }
    /**
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamSubsidyManager.java
@@ -3,7 +3,6 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -25,7 +24,6 @@
import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
import com.yeshi.fanli.exception.order.OrderTeamRewardException;
import com.yeshi.fanli.exception.order.TaoBaoOrderException;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2SettleTempService;
import com.yeshi.fanli.service.inter.money.InviteOrderSubsidyDebtService;
@@ -36,7 +34,6 @@
import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
import com.yeshi.fanli.service.manger.money.TeamEincomeManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TimeUtil;
/**
 * 团队分红管理
@@ -71,7 +68,7 @@
    private TeamEincomeManager teamEincomeManager;
    public void addOrUpdateOrder(String orderNo, int sourceType)
            throws InviteOrderSubsidyException, OrderTeamRewardException, CommonOrderException {
            throws InviteOrderSubsidyException, CommonOrderException {
        inviteOrderSubsidyService.addOrUpdateByOrder(orderNo, sourceType);
    }
@@ -130,16 +127,12 @@
     * void 返回类型
     * @throws
     */
    @Transactional
    public void addToTeamEincome(Long uid, String taskKey)
    @Transactional(rollbackFor=Exception.class)
    public void addToTeamEincome(Long uid, String taskKey,Date preGetTime)
            throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException {
        // 查询key
        List<HongBaoV2SettleTemp> list = hongBaoV2SettleTempService.listByKey(taskKey);
        if (list != null && list.size() > 0) {
            Calendar ca = Calendar.getInstance();
            Date date = new Date(TimeUtil.convertToTimeTemp(
                    ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
            Integer sourceType = null;
            List<InviteOrderSubsidy> subsidyList = new ArrayList<>();
            for (HongBaoV2SettleTemp temp : list) {
@@ -163,7 +156,7 @@
                throw new OrderMoneySettleException(1, "订单类型未获取到");
            if (subsidyList.size() > 0) {
                BigDecimal debtMoney = inviteOrderSubsidyDebtService.getTotalDebtMoney(uid, date);
                BigDecimal debtMoney = inviteOrderSubsidyDebtService.getTotalDebtMoney(uid, preGetTime);
                BigDecimal originalDebtMoney = new BigDecimal(debtMoney.toString());// 总的欠款
                List<InviteOrderSubsidy> copySubsidyList = new ArrayList<>();
                copySubsidyList.addAll(subsidyList);
@@ -175,7 +168,7 @@
                BigDecimal bannce = null;
                if (repayMoney.compareTo(new BigDecimal(0)) > 0) {
                    try {
                        bannce = inviteOrderSubsidyDebtService.repayDebtByUid(uid, date, repayMoney);
                        bannce = inviteOrderSubsidyDebtService.repayDebtByUid(uid, preGetTime, repayMoney);
                        // 剩余的补贴金额
                    } catch (InviteOrderSubsidyDebtException e) {
                        throw new OrderMoneySettleException(2, "还款异常");
@@ -193,7 +186,7 @@
                }
                // 加入团队收益中间表
                teamEincomeManager.addTeamSubsidy(uid, date, totalMoney, sourceType);
                teamEincomeManager.addTeamSubsidy(uid, preGetTime, totalMoney, sourceType);
            }
        }
    }
fanli/src/main/java/com/yeshi/fanli/util/Constant.java
@@ -24,6 +24,8 @@
    public static boolean IS_TEST = true;
    public static boolean ENABLE_MQ = false;
    public static int PAGE_SIZE = 20;
    
    // 验证文本口令或链接uid
@@ -257,6 +259,10 @@
    public static final WXAPPInfo WXMP_APP_INFO=new WXAPPInfo("wxc22f3bd53cb25012", "4c7b166fecb6d9f53837e993f2214673", "", "");
    
    
    //新的规则生效时间
    public static final String NEW_ORDER_FANLI_RULE_TIME="2020-04-18";
    // 新人抽奖-最大次数
    public static final int MAX_COUNT_LOTTERY_NEWBIES = 5;
fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
@@ -1087,7 +1087,7 @@
                            String key = its.next();
                            UserDividentsDayDTO dto = map.get(key);
                            try {
                                teamDividentsManager.addToTeamEincome(dto.getUid(), dto.getDay());
                                teamDividentsManager.addToTeamEincome(dto.getUid(), dto.getPreGetTime());
                            } catch (Exception e) {
                                try {
                                    LogHelper.errorDetailInfo(e);
fanli/src/main/java/com/yeshi/fanli/util/factory/order/dividents/TeamDividentsSourceOrderFactory.java
@@ -5,7 +5,6 @@
import java.util.Date;
import java.util.List;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
@@ -20,15 +19,14 @@
        for (CommonOrder commonOrder : commonOrderList) {
            if (commonOrder.geteIncome() != null)
                money = money.add(commonOrder.geteIncome());
            if (commonOrder.getState() == CommonOrder.STATE_SX)
                invalidCount++;
        }
        if (money.compareTo(new BigDecimal(0)) <= 0)
        if (invalidCount >= commonOrderList.size())
            return null;
        if (invalidCount >= commonOrderList.size())
        if (money.compareTo(new BigDecimal(0)) <= 0)
            return null;
        BigDecimal dividents = MoneyBigDecimalUtil.div(money.multiply(rate), new BigDecimal(100));
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/InviteOrderSubsidyMessageListener.java
@@ -14,9 +14,12 @@
import com.google.gson.Gson;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg;
import com.yeshi.fanli.dto.mq.order.body.TeamRewardPreRecieveMQMsg;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.OrderMoneySettleException;
import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
import com.yeshi.fanli.exception.order.OrderTeamRewardException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.mq.MQUnSendInfoService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
@@ -80,9 +83,6 @@
                        } catch (InviteOrderSubsidyException e) {
                            e.printStackTrace();
                            LogHelper.errorDetailInfo(e, new Gson().toJson(dto), "");
                        } catch (OrderTeamRewardException e) {
                            e.printStackTrace();
                            LogHelper.errorDetailInfo(e, new Gson().toJson(dto), "");
                        } catch (CommonOrderException e) {
                            e.printStackTrace();
                            LogHelper.errorDetailInfo(e, new Gson().toJson(dto), "");
@@ -97,6 +97,21 @@
                        }
                    }
                }
            } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.teamRewardPreRecieved.name())) {// 团队奖金预到账
                TeamRewardPreRecieveMQMsg dto = new Gson().fromJson(new String(message.getBody()),
                        TeamRewardPreRecieveMQMsg.class);
                try {
                    teamSubsidyManager.addToTeamEincome(dto.getUid(), message.getKey(), dto.getPreGetTime());
                    return Action.CommitMessage;
                } catch (OrderMoneySettleException e) {
                    e.printStackTrace();
                } catch (TeamEincomeRecordException e) {
                    e.printStackTrace();
                } catch (ParamsException e) {
                    e.printStackTrace();
                }
                return Action.ReconsumeLater;
            }
        }
        return Action.CommitMessage;
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/OrderDividentsMessageListener.java
@@ -1,8 +1,6 @@
package com.yeshi.fanli.util.rocketmq.consumer.order;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
@@ -16,12 +14,11 @@
import com.google.gson.Gson;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg;
import com.yeshi.fanli.dto.mq.order.body.OrderWeiQuanMQMsg;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.UserForbiddenMQMsg;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.TeamDividentsDebtException;
import com.yeshi.fanli.exception.order.dividents.TeamDividentsSourceOrderException;
import com.yeshi.fanli.log.LogHelper;
@@ -29,7 +26,6 @@
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.service.manger.order.TeamDividentsManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
/**
@@ -76,40 +72,28 @@
                List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(dto.getSourceType(),
                        dto.getOrderNo());
                BigDecimal eincome = new BigDecimal(0);
                Date settleTime = null;
                for (CommonOrder order : commonOrderList) {
                    if (order.getState() == CommonOrder.STATE_JS)
                        eincome = eincome.add(order.geteIncome());
                    if (settleTime == null)
                        settleTime = order.getSettleTime();
                }
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(settleTime);
                calendar.add(Calendar.MONTH, 1);
                Date preSendTime = new Date(TimeUtil.convertToTimeTemp(
                        calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
                TeamDividentsSourceOrder sourceOrder = new TeamDividentsSourceOrder();
                sourceOrder.setMoney(eincome);
                sourceOrder.setOrderNo(dto.getOrderNo());
                sourceOrder.setPreSendTime(preSendTime);
                sourceOrder.setSourceType(dto.getSourceType());
                sourceOrder.setState(TeamDividentsSourceOrder.STATE_CAN_SEND);
                sourceOrder.setUid(dto.getSourceUid());
                try {
                    teamDividentsSourceOrderService.addTeamDividentsSourceOrder(sourceOrder);
                    teamDividentsManager.addDividentsSourceOrder(commonOrderList);
                }
                catch (TeamDividentsSourceOrderException e) {
                    if (e.getCode() == TeamDividentsSourceOrderException.CODE_EXIST)
                    return Action.CommitMessage;
                } catch (ParamsException e) {
                    else {
                    e.printStackTrace();
                } catch (TeamDividentsSourceOrderException e) {
                    e.printStackTrace();
                        return Action.ReconsumeLater;
                    }
                }
            } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.taoBaoOrderWeiQuan.name())) {
                TaoBaoWeiQuanOrder dto = new Gson().fromJson(new String(message.getBody()), TaoBaoWeiQuanOrder.class);
                OrderWeiQuanMQMsg dto = new Gson().fromJson(new String(message.getBody()), OrderWeiQuanMQMsg.class);
                try {
                    teamDividentsManager.weiQuan(dto.getOrderId(), Constant.SOURCE_TYPE_TAOBAO);
                    teamDividentsManager.weiQuan(dto.getOrderNo(), dto.getSourceType());
                    return Action.CommitMessage;
                } catch (TeamDividentsDebtException e) {
                    e.printStackTrace();
fanli/src/main/java/com/yeshi/fanli/util/user/UserLevelUtil.java
@@ -95,5 +95,23 @@
            return UserLevelEnum.highVIP;
        }
        return null;
    }
    /**
     * 获取2.1之前的用户等级(普通会员与高级会员降级为达人,导师降级为超级会员)
     * @Title: getOldLevel
     * @Description:
     * @param level
     * @return
     * UserLevelEnum 返回类型
     * @throws
     */
    public static UserLevelEnum getOldLevel(UserLevelEnum userLevel) {
        if (userLevel == null || userLevel == UserLevelEnum.normalVIP || userLevel == UserLevelEnum.highVIP) {
            return UserLevelEnum.daRen;
        } else if (userLevel == UserLevelEnum.tearcher)
            return UserLevelEnum.superVIP;
        return userLevel;
    }
}