yujian
2020-04-23 83bb6e0580b646c5d89da1cdb4085787c8136822
Merge remote-tracking branch 'origin/div' into div
10个文件已删除
30个文件已修改
1个文件已添加
2311 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/InviteOrderSubsidyDebtMapper.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/InviteOrderSubsidyDebtRepayHistoryMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceOrderUserMapMapper.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/vip/TeamUserLevelStatisticMapper.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/body/OrderMQMsg.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/order/HongBaoAddResult.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/money/InviteOrderSubsidyDebt.java 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/money/InviteOrderSubsidyDebtRepayHistory.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceOrderUserMap.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/order/OrderShareIncomeJob.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/order/OrderTeamDividentsJob.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/order/OrderTeamIncomeJob.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/money/InviteOrderSubsidyDebtMapper.xml 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/money/InviteOrderSubsidyDebtRepayHistoryMapper.xml 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceOrderUserMapMapper.xml 126 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/money/InviteOrderSubsidyDebtServiceImpl.java 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/money/tb/TaoBaoWeiQuanDrawBackServiceImpl.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImpl.java 298 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderHongBaoMoneyComputeServiceImpl.java 174 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderUserMapServiceImpl.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/TeamUserLevelStatisticServiceImpl.java 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/money/InviteOrderSubsidyDebtService.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/HongBaoV2Service.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/InviteOrderSubsidyService.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderHongBaoMoneyComputeService.java 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderMoneySettleService.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsSourceOrderUserMapService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/vip/TeamUserLevelStatisticService.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java 148 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsSourceManager.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamSubsidyManager.java 217 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/Constant.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/factory/order/dividents/TeamDividentsSourceOrderFactory.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/InviteOrderSubsidyMessageListener.java 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/OrderDividentsMessageListener.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/rocket/consumer.xml 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/InviteOrderSubsidyDebtMapper.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/money/InviteOrderSubsidyDebtRepayHistoryMapper.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/dividents/TeamDividentsSourceOrderUserMapMapper.java
@@ -64,7 +64,18 @@
     */
    long countCanSendSourceUidByPreSendTime(@Param("preSendTime") Date preSendTime);
    /**
     * 源用户相关订单失效
     * @Title: invalidOrderBySourceUid
     * @Description:
     * @param sourceUid
     * @param beiZhu
     * @param stateList
     * @return
     * int 返回类型
     * @throws
     */
    int invalidOrderBySourceUid(@Param("sourceUid") Long sourceUid, @Param("beiZhu") String beiZhu,
            @Param("stateList") List<Integer> stateList);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/vip/TeamUserLevelStatisticMapper.java
@@ -1,8 +1,22 @@
package com.yeshi.fanli.dao.mybatis.user.vip;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
public interface TeamUserLevelStatisticMapper extends BaseMapper<TeamUserLevelStatistic> {
    /**
     * 根据用户列表查询
     * @Title: listByUids
     * @Description:
     * @param uidList
     * @return
     * List<TeamUserLevelStatistic> 返回类型
     * @throws
     */
    List<TeamUserLevelStatistic> listByUids(@Param("uidList") List<Long> uidList);
}
fanli/src/main/java/com/yeshi/fanli/dto/mq/order/body/OrderMQMsg.java
@@ -22,9 +22,10 @@
    private boolean valid;
    private int delayHour;// 延时的时间(小时记)
    private Date staticticDate;// 统计到的时间
    private boolean miandan;
    public OrderMQMsg(String orderId, Integer type, Long uid, int handleType, boolean valid, int delayHour,
            Date staticticDate) {
            Date staticticDate, boolean miandan) {
        super();
        this.orderId = orderId;
        this.type = type;
@@ -33,6 +34,7 @@
        this.valid = valid;
        this.delayHour = delayHour;
        this.staticticDate = staticticDate;
        this.miandan = miandan;
    }
    public Date getStaticticDate() {
@@ -94,4 +96,12 @@
    public void setValid(boolean valid) {
        this.valid = valid;
    }
    public boolean isMiandan() {
        return miandan;
    }
    public void setMiandan(boolean miandan) {
        this.miandan = miandan;
    }
}
fanli/src/main/java/com/yeshi/fanli/dto/order/HongBaoAddResult.java
New file
@@ -0,0 +1,36 @@
package com.yeshi.fanli.dto.order;
public class HongBaoAddResult {
    public final static int CODE_ADD=1;
    public final static int CODE_UPDATE=2;
    public final static int CODE_ADD_AND_UPDATE=12;
    private int resultCode;
    private boolean miandan;
    public HongBaoAddResult() {
    }
    public HongBaoAddResult(int resultCode, boolean miandan) {
        this.resultCode = resultCode;
        this.miandan = miandan;
    }
    public int getResultCode() {
        return resultCode;
    }
    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }
    public boolean isMiandan() {
        return miandan;
    }
    public void setMiandan(boolean miandan) {
        this.miandan = miandan;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/money/InviteOrderSubsidyDebt.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/entity/money/InviteOrderSubsidyDebtRepayHistory.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/entity/order/dividents/TeamDividentsSourceOrderUserMap.java
@@ -40,6 +40,8 @@
    private BigDecimal money;
    @Column(name = "sou_pre_send_time")
    private Date preSendTime;
    @Column(name = "sou_send_time")
    private Date sendTime;
    @Column(name = "sou_create_time")
    private Date createTime;
    @Column(name = "sou_update_time")
@@ -47,6 +49,14 @@
    @Column(name = "sou_beizhu")
    private String beiZhu;
    public Date getSendTime() {
        return sendTime;
    }
    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }
    public Long getId() {
        return id;
    }
fanli/src/main/java/com/yeshi/fanli/job/order/OrderShareIncomeJob.java
@@ -9,7 +9,6 @@
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.fanli.service.inter.order.OrderProcessService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceUserService;
import com.yeshi.fanli.service.manger.order.TeamDividentsManager;
import com.yeshi.fanli.util.TimeUtil;
@@ -21,8 +20,6 @@
    @Resource
    private TeamDividentsManager teamDividentsManager;
    @Resource
    private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
    @Resource
    private TeamDividentsSourceUserService teamDividentsSourceUserService;
fanli/src/main/java/com/yeshi/fanli/job/order/OrderTeamDividentsJob.java
@@ -13,7 +13,6 @@
import com.yeshi.fanli.dto.mq.UidDateDTO;
import com.yeshi.fanli.entity.money.TeamEincomeRecord;
import com.yeshi.fanli.service.inter.money.TeamEincomeRecordService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderUserMapService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceUserService;
import com.yeshi.fanli.service.manger.money.TeamEincomeManager;
@@ -29,8 +28,6 @@
    @Resource
    private TeamDividentsManager teamDividentsManager;
    @Resource
    private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
    @Resource
    private TeamDividentsSourceOrderUserMapService teamDividentsSourceOrderUserMapService;
fanli/src/main/java/com/yeshi/fanli/job/order/OrderTeamIncomeJob.java
@@ -14,7 +14,6 @@
import com.yeshi.fanli.entity.money.TeamEincomeRecord;
import com.yeshi.fanli.service.inter.money.TeamEincomeRecordService;
import com.yeshi.fanli.service.inter.order.OrderProcessService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceUserService;
import com.yeshi.fanli.service.manger.order.TeamDividentsManager;
import com.yeshi.fanli.util.StringUtil;
@@ -27,9 +26,6 @@
    @Resource
    private TeamDividentsManager teamDividentsManager;
    @Resource
    private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
    @Resource
    private TeamDividentsSourceUserService teamDividentsSourceUserService;
fanli/src/main/java/com/yeshi/fanli/mapping/money/InviteOrderSubsidyDebtMapper.xml
File was deleted
fanli/src/main/java/com/yeshi/fanli/mapping/money/InviteOrderSubsidyDebtRepayHistoryMapper.xml
File was deleted
fanli/src/main/java/com/yeshi/fanli/mapping/order/dividents/TeamDividentsSourceOrderUserMapMapper.xml
@@ -19,13 +19,14 @@
        <result column="sou_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
        <result column="sou_beizhu" property="beiZhu" jdbcType="VARCHAR" />
        <result column="sou_send_time" property="sendTime" jdbcType="TIMESTAMP" />
        <association property="sourceOrder" column="sou_source_order_id"
            javaType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder">
            <id column="sou_source_order_id" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu
    <sql id="Base_Column_List">sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu,sou_send_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
@@ -42,9 +43,9 @@
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_team_dividents_source_order_user
        (sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu)
        (sou_id,sou_source_order_id,sou_source_uid,sou_target_uid,sou_state,sou_type,sou_rate,sou_money,sou_pre_send_time,sou_create_time,sou_update_time,sou_beizhu,sou_send_time)
        values
        (#{id,jdbcType=BIGINT},#{sourceOrder.id,jdbcType=BIGINT},#{sourceUid,jdbcType=BIGINT},#{targetUid,jdbcType=BIGINT},#{state,jdbcType=INTEGER},#{type,jdbcType=INTEGER},#{rate,jdbcType=DECIMAL},#{money,jdbcType=DECIMAL},#{preSendTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{beiZhu,jdbcType=VARCHAR})
        (#{id,jdbcType=BIGINT},#{sourceOrder.id,jdbcType=BIGINT},#{sourceUid,jdbcType=BIGINT},#{targetUid,jdbcType=BIGINT},#{state,jdbcType=INTEGER},#{type,jdbcType=INTEGER},#{rate,jdbcType=DECIMAL},#{money,jdbcType=DECIMAL},#{preSendTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{beiZhu,jdbcType=VARCHAR},#{sendTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap"
@@ -63,6 +64,7 @@
            <if test="createTime != null">sou_create_time,</if>
            <if test="updateTime != null">sou_update_time,</if>
            <if test="beiZhu != null">sou_beizhu,</if>
            <if test="sendTime != null">sou_send_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -78,13 +80,13 @@
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="sendTime != null">#{sendTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">update yeshi_ec_team_dividents_source_order_user set
        sou_source_order_id = #{sourceOrder.id,jdbcType=BIGINT},sou_source_uid
        =
        #{sourceUid,jdbcType=BIGINT},sou_target_uid =
        = #{sourceUid,jdbcType=BIGINT},sou_target_uid =
        #{targetUid,jdbcType=BIGINT},sou_state =
        #{state,jdbcType=INTEGER},sou_type = #{type,jdbcType=INTEGER},sou_rate
        = #{rate,jdbcType=DECIMAL},sou_money =
@@ -92,7 +94,8 @@
        #{preSendTime,jdbcType=TIMESTAMP},sou_create_time =
        #{createTime,jdbcType=TIMESTAMP},sou_update_time =
        #{updateTime,jdbcType=TIMESTAMP},sou_beizhu =
        #{beiZhu,jdbcType=VARCHAR} where sou_id = #{id,jdbcType=BIGINT}
        #{beiZhu,jdbcType=VARCHAR} ,sou_send_time
        =#{sendTime,jdbcType=TIMESTAMP} where sou_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrderUserMap">
@@ -110,112 +113,77 @@
            <if test="createTime != null">sou_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">sou_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="beiZhu != null">sou_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="sendTime !=null">sou_send_time =#{sendTime,jdbcType=TIMESTAMP},</if>
        </set>
        where sou_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="invalidOrderBySourceUid">
        update yeshi_ec_team_dividents_source_order_user
        <set>
            sou_state=4,
            sou_update_time=now(),
            sou_beizhu=#{beiZhu},
        </set>
        where sou_source_uid=#{sourceUid}
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state">sou_state=#{state}</foreach>
        </if>
    </update>
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order_user where sou_id =
        #{0} for
        from yeshi_ec_team_dividents_source_order_user where sou_id = #{0} for
        update
    </select>
    <select id="list" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_team_dividents_source_order_user where
        1=1
        <if test="sourceOrderId!=null">
            and sou_source_order_id=#{sourceOrderId}
        </if>
        <if test="sourceUid!=null">
            and sou_source_uid=#{sourceUid}
        </if>
        <if test="targetUid!=null">
            and sou_target_uid=#{targetUid}
        </if>
        <if test="preSendTime!=null">
            and sou_pre_send_time=#{preSendTime}
        </if>
        from yeshi_ec_team_dividents_source_order_user where 1=1
        <if test="sourceOrderId!=null">and sou_source_order_id=#{sourceOrderId}</if>
        <if test="sourceUid!=null">and sou_source_uid=#{sourceUid}</if>
        <if test="targetUid!=null">and sou_target_uid=#{targetUid}</if>
        <if test="preSendTime!=null">and sou_pre_send_time=#{preSendTime}</if>
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state"></foreach>
            sou_state=#{state}
                close=")" item="state">sou_state=#{state}</foreach>
        </if>
        <if test="typeList!=null">
            <foreach collection="typeList" open=" and (" separator=" or "
                close=")" item="type"></foreach>
            sou_type=#{type}
                close=")" item="type">sou_type=#{type}</foreach>
        </if>
        limit #{start},#{count}
    </select>
    <select id="count" resultType="java.lang.Long">
        select
        count(*)
        from yeshi_ec_team_dividents_source_order_user where
        select count(*) from yeshi_ec_team_dividents_source_order_user where
        1=1
        <if test="sourceOrderId!=null">
            and sou_source_order_id=#{sourceOrderId}
        </if>
        <if test="sourceUid!=null">
            and sou_source_uid=#{sourceUid}
        </if>
        <if test="targetUid!=null">
            and sou_target_uid=#{targetUid}
        </if>
        <if test="preSendTime!=null">
            and sou_pre_send_time=#{preSendTime}
        </if>
        <if test="sourceOrderId!=null">and sou_source_order_id=#{sourceOrderId}</if>
        <if test="sourceUid!=null">and sou_source_uid=#{sourceUid}</if>
        <if test="targetUid!=null">and sou_target_uid=#{targetUid}</if>
        <if test="preSendTime!=null">and sou_pre_send_time=#{preSendTime}</if>
        <if test="stateList!=null">
            <foreach collection="stateList" open=" and (" separator=" or "
                close=")" item="state"></foreach>
            sou_state=#{state}
                close=")" item="state">sou_state=#{state}</foreach>
        </if>
        <if test="typeList!=null">
            <foreach collection="typeList" open=" and (" separator=" or "
                close=")" item="type"></foreach>
            sou_type=#{type}
                close=")" item="type">sou_type=#{type}</foreach>
        </if>
    </select>
    <select id="listCanSendSourceUidByPreSendTime" resultType="java.lang.Long">
        SELECT DISTINCT(o.`sou_source_uid`) FROM
    <select id="listCanSendSourceUidByPreSendTime" resultType="java.lang.Long">SELECT
        DISTINCT(o.`sou_source_uid`) FROM
        `yeshi_ec_team_dividents_source_order_user` o WHERE o.`sou_state`=2
        AND o.`sou_pre_send_time`=#{preSendTime} limit #{start},#{count}
    </select>
    <select id="countCanSendSourceUidByPreSendTime" resultType="java.lang.Long">
        SELECT count(DISTINCT(o.`sou_source_uid`)) FROM
    <select id="countCanSendSourceUidByPreSendTime" resultType="java.lang.Long">SELECT
        count(DISTINCT(o.`sou_source_uid`)) FROM
        `yeshi_ec_team_dividents_source_order_user` o WHERE o.`sou_state`=2
        AND o.`sou_pre_send_time`=#{preSendTime} limit #{start},#{count}
        AND o.`sou_pre_send_time`=#{preSendTime}
    </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/money/InviteOrderSubsidyDebtServiceImpl.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/service/impl/money/tb/TaoBaoWeiQuanDrawBackServiceImpl.java
@@ -34,7 +34,6 @@
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.money.InviteOrderSubsidyDebtService;
import com.yeshi.fanli.service.inter.money.UserMoneyDebtService;
import com.yeshi.fanli.service.inter.money.UserMoneyDetailService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
@@ -80,8 +79,6 @@
    @Resource
    private UserMoneyService userMoneyService;
    @Resource
    private InviteOrderSubsidyDebtService inviteOrderSubsidyDebtService;
    @Resource
    private UserMoneyDetailService userMoneyDetailService;
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -37,7 +37,6 @@
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.jd.JDOrder;
import com.yeshi.fanli.entity.jd.JDOrderItem;
import com.yeshi.fanli.entity.money.InviteOrderSubsidyDebt;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
import com.yeshi.fanli.entity.order.CommonOrderTradeIdMap;
@@ -60,7 +59,6 @@
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemCouponService;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.money.InviteOrderSubsidyDebtService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
@@ -137,9 +135,6 @@
    @Resource
    private InviteOrderSubsidyService inviteOrderSubsidyService;
    @Resource
    private InviteOrderSubsidyDebtService inviteOrderSubsidyDebtService;
    @Resource
    private UserVIPInfoService userVIPInfoService;
@@ -595,13 +590,14 @@
            if (HongBaoV2.TYPE_ZIGOU == hongBaoType) {
                // 奖励订单、免单 使用记录
                if (sourceType == null) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, null, uid, vip, acceptData, hongBao);
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, null, uid, vip, acceptData,
                            hongBao);
                } else if (sourceType == Constant.SOURCE_TYPE_TAOBAO) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordTB, uid, vip,
                            acceptData, hongBao);
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordTB, uid, vip, acceptData,
                            hongBao);
                } else if (sourceType == Constant.SOURCE_TYPE_JD) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordJD, uid, vip,
                            acceptData, hongBao);
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordJD, uid, vip, acceptData,
                            hongBao);
                } else if (sourceType == Constant.SOURCE_TYPE_PDD) {
                    couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordPDD, uid, vip,
                            acceptData, hongBao);
@@ -627,7 +623,8 @@
     * @param signList
     */
    private void couponFactory(CommonOrderVO order, boolean hasRewardCoupon, Integer hongBaoState, Integer hongBaoType,
            List<UserSystemCouponRecord> list, Long uid, boolean vip, AcceptData acceptData, BigDecimal hongBao) throws Exception {
            List<UserSystemCouponRecord> list, Long uid, boolean vip, AcceptData acceptData, BigDecimal hongBao)
            throws Exception {
        // 是否免单商品
        boolean freeOrder = false;
@@ -726,10 +723,10 @@
        }
        // 使用奖励券 金额额限制
        if (hongBao.compareTo(Constant.REWARD_COUPON_LIMIT_MONEY) > 0){
        if (hongBao.compareTo(Constant.REWARD_COUPON_LIMIT_MONEY) > 0) {
            return;
        }
        // 是否可使用奖励券
        if (!rewardSuccess && !freeOrder && HongBaoV2.TYPE_ZIGOU == hongBaoType
                && HongBaoV2.STATE_YILINGQU == hongBaoState && !vip && CommonOrder.STATE_WQ != order.getState()) {
@@ -2043,7 +2040,6 @@
            orderStateMap.put("fontColor", "#666666");
            order.setOrderState(orderStateMap);
            // 订单标识
            List<String> signList = new ArrayList<String>();
            /* 订单返利类型 转换 */
@@ -2074,23 +2070,6 @@
                order.setOrderOrigin("3");
                order.setHongBaoTypePic(CommonOrder.TYPE_INVITE);
                signList.add(CommonOrder.TYPE_INVITE);
                // 红包加上补贴金额
                InviteOrderSubsidy orderSubsidy = inviteOrderSubsidyService.getByOrderNoAndType(uid, orderNo,
                        sourceType);
                if (orderSubsidy != null && orderSubsidy.getMoney() != null) {
                    BigDecimal subsidyMoney = orderSubsidy.getMoney();
                    // 维权金额
                    InviteOrderSubsidyDebt subsidyDebt = inviteOrderSubsidyDebtService
                            .getBySourceId(orderSubsidy.getId());
                    if (subsidyDebt != null && subsidyDebt.getOriginMoney() != null) {
                        subsidyMoney = subsidyMoney.subtract(subsidyDebt.getOriginMoney());
                    }
                    // 最终补贴
                    if (subsidyMoney.compareTo(new BigDecimal(0)) > 0) {
                        hongBao = hongBao.add(subsidyMoney);
                    }
                }
            }
            order.setSignList(signList);
@@ -2135,7 +2114,8 @@
            order.setAccountState(stateMap);
            Map<String, String> hongBaoMap = new HashMap<String, String>();
            hongBaoMap.put("content", hongBaoState_Str + "收益 ¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
            hongBaoMap.put("content",
                    hongBaoState_Str + "收益 ¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
            hongBaoMap.put("fontColor", hongbaoInfoFontColor);
            order.setHongBaoInfo(hongBaoMap);
@@ -2179,7 +2159,7 @@
                        text = "免单中";
                    } else if (UserSystemCouponRecord.STATE_SUCCESS == state) {
                        text = "已免单";
                    }
                    }
                }
                break;
            }
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java
@@ -26,6 +26,7 @@
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.HongBaoDTO;
import com.yeshi.fanli.dto.order.HongBaoAddResult;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
@@ -150,11 +151,13 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException {
    public HongBaoAddResult addHongBao(List<CommonOrder> commonOrderList, int type)
            throws HongBaoException, UserAccountException {
        Set<Integer> stateSet = new HashSet<>();// 订单状态Set
        if (commonOrderList != null && commonOrderList.size() > 0) {
            int orderType = commonOrderList.get(0).getSourceType();
            boolean miandan = false;
            Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
            int goodsCount = 0;
            boolean hasAdd = false;
@@ -166,7 +169,7 @@
                    throw new HongBaoException(1, "订单信息不完整");
                HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                if (hongBaoOrder == null) {
                    saveHongBao(commonOrder, type, notificationMap);
                    miandan = saveHongBao(commonOrder, type, notificationMap);
                    hasAdd = true;
                } else {
                    boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
@@ -204,22 +207,24 @@
                        break;
                    case HongBaoV2.TYPE_YIJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money,new BigDecimal(0), goodsCount, commonOrder.getState(),
                                commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                                commonOrder.getThirdCreateTime());
                        break;
                    case HongBaoV2.TYPE_ERJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,     commonOrder.getPayment(), money,new BigDecimal(0),
                                goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                                commonOrder.getThirdCreateTime());
                        break;
                    case HongBaoV2.TYPE_SHARE_YIJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money,new BigDecimal(0), goodsCount, commonOrder.getState(),
                                commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                                commonOrder.getThirdCreateTime());
                    case HongBaoV2.TYPE_SHARE_ERJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,     commonOrder.getPayment(), money,new BigDecimal(0),
                                goodsCount,  commonOrder.getState(), commonOrder.getThirdCreateTime());
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
                                commonOrder.getThirdCreateTime());
                        break;
                    }
                }
@@ -227,14 +232,14 @@
            int resultCode = 0;
            if (hasAdd && hasUpdate)
                return 12;
                return new HongBaoAddResult(HongBaoAddResult.CODE_ADD_AND_UPDATE, miandan);
            else if (hasAdd)
                return 1;
                return new HongBaoAddResult(HongBaoAddResult.CODE_ADD, miandan);
            else if (hasUpdate)
                return 2;
            return resultCode;
                return new HongBaoAddResult(HongBaoAddResult.CODE_UPDATE, miandan);
            return new HongBaoAddResult(resultCode, miandan);
        }
        return 0;
        return new HongBaoAddResult(0, false);
    }
    private int getOrderState(Set<Integer> states) {
@@ -264,7 +269,8 @@
            return false;
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
            BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
            BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
                    commonOrder.getCreateTime().getTime());
            // 免单处理
            boolean mianDan = false;
            List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
@@ -518,7 +524,8 @@
                    && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))
                fanliRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
            else
                fanliRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
                fanliRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
                        commonOrder.getCreateTime().getTime());
            List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService
                    .listByOrderIdAndUid(commonOrder.getUserInfo().getId(), commonOrder.getOrderNo());
@@ -639,10 +646,11 @@
    }
    @Transactional(rollbackFor = Exception.class)
    private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
    private boolean saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
            throws HongBaoException, UserAccountException {
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
            BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
            BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
                    commonOrder.getCreateTime().getTime());
            // 查询是否有免单计划
            BigDecimal mianDanMoney = null;
            if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
@@ -743,7 +751,7 @@
                BigDecimal firstRate = hongBaoManageService
                        .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank());
                if (firstRate.compareTo(new BigDecimal(0)) <= 0)
                    return;
                    return mianDanMoney != null;
                HongBaoV2 firstHongbao = new HongBaoV2();
                firstHongbao.setUserInfo(boss);
                firstHongbao.setUrank(boss.getRank());
@@ -769,7 +777,7 @@
                }
                // 返利为0的不通知
                if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
                    return;
                    return mianDanMoney != null;
                hongBaoV2Mapper.insertSelective(firstHongbao);
                // 用户通知
@@ -796,7 +804,7 @@
                    BigDecimal secondRate = hongBaoManageService
                            .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank());
                    if (secondRate.compareTo(new BigDecimal(0)) <= 0)
                        return;
                        return mianDanMoney != null;
                    HongBaoV2 secondHongbao = new HongBaoV2();
                    secondHongbao.setUserInfo(boss);
                    secondHongbao.setUrank(boss.getRank());
@@ -822,7 +830,7 @@
                    // 返利为0的不统计
                    if (secondHongbao.getMoney() == null || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
                        return;
                        return mianDanMoney != null;
                    hongBaoV2Mapper.insertSelective(secondHongbao);
@@ -846,18 +854,19 @@
                }
            }
            return mianDanMoney != null;
        } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
            // 分享赚不加入失效的订单
            if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
                return;
                return false;
            // 分享赚
            BigDecimal shareRate = null;
            if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO
                    && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))// 来自于淘礼金的分享
                shareRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
            else
                shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,commonOrder.getCreateTime().getTime());
                shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
                        commonOrder.getCreateTime().getTime());
            // 判断订单分享活动是否开启
            if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.shareGoodsActivityOpen.getKey()))) {
@@ -1015,6 +1024,8 @@
            }
        } else
            throw new HongBaoException(2, "type错误");
        return false;
    }
    @Override
fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImpl.java
@@ -1,319 +1,21 @@
package com.yeshi.fanli.service.impl.order;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.order.InviteOrderSubsidyMapper;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.HongBaoOrder;
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.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMapService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.service.manger.user.UserLevelManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.user.UserLevelUtil;
@Service
public class InviteOrderSubsidyServiceImpl implements InviteOrderSubsidyService {
    @Resource
    private InviteOrderSubsidyMapper inviteOrderSubsidyMapper;
    @Resource
    private HongBaoV2Service hongBaoV2Service;
    @Resource
    private HongBaoOrderService hongBaoOrderService;
    @Resource
    private OrderHongBaoMapService orderHongBaoMapService;
    @Resource
    private CommonOrderService commonOrderService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private UserVIPInfoService userVIPInfoService;
    @Resource
    private UserLevelManager userLevelManager;
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
    @Override
    public InviteOrderSubsidy getByOrderNoAndType(Long uid, String orderNo, Integer type) {
        return inviteOrderSubsidyMapper.getByOrderNoAndType(uid, orderNo, type);
    }
    @Override
    public InviteOrderSubsidy getByOrderNoAndTypeForUpdate(Long uid, String orderNo, Integer type) {
        return inviteOrderSubsidyMapper.getByOrderNoAndTypeForUpdate(uid, orderNo, type);
    }
    @Override
    public List<InviteOrderSubsidy> listByOrderNoAndType(String orderNo, Integer type) {
        return inviteOrderSubsidyMapper.listByOrderNoAndType(orderNo, type);
    }
    private void addOrderSubsidy(InviteOrderSubsidy orderSubsidy)
            throws InviteOrderSubsidyException, CommonOrderException {
        if (orderSubsidy.getMoney() == null || StringUtil.isNullOrEmpty(orderSubsidy.getOrderNo())
                || orderSubsidy.getSourceType() == null || orderSubsidy.getUid() == null)
            throw new InviteOrderSubsidyException(1, "数据不完整");
        InviteOrderSubsidy old = getByOrderNoAndType(orderSubsidy.getUid(), orderSubsidy.getOrderNo(),
                orderSubsidy.getSourceType());
        if (old != null) {// 修改
            if (old.getState() == InviteOrderSubsidy.STATE_INVALID
                    || old.getState() == InviteOrderSubsidy.STATE_SUBSIDIZED)
                return;
            // 修改状态
            InviteOrderSubsidy update = new InviteOrderSubsidy(old.getId());
            update.setMoney(orderSubsidy.getMoney());
            if (old.getState() == InviteOrderSubsidy.STATE_UNKNOWN) {// 状态未确定之前才可以更改原始补贴资金
                update.setOriginalMoney(orderSubsidy.getOriginalMoney());
            }
            update.setState(orderSubsidy.getState());
            update.setUpdateTime(new Date());
            inviteOrderSubsidyMapper.updateByPrimaryKeySelective(update);
        } else {// 添加
            if (orderSubsidy.getCreateTime() == null)
                orderSubsidy.setCreateTime(new Date());
            inviteOrderSubsidyMapper.insertSelective(orderSubsidy);
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addOrUpdateByOrder(String orderId, int sourceType) throws InviteOrderSubsidyException {
        List<HongBaoOrder> list = hongBaoOrderService.listByOrderIdAndSourceType(orderId, sourceType);
        if (list != null && list.size() > 0) {
            // 必须是自购订单才返利
            HongBaoV2 parent = hongBaoV2Service.selectByPrimaryKey(list.get(0).getHongBaoV2().getId());
            if (parent != null
                    && (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS || parent.getType() == HongBaoV2.TYPE_ZIGOU)) {//
                List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
                if (orderList == null || orderList.size() == 0)
                    throw new InviteOrderSubsidyException(10, "订单为空");
                CommonOrder firstOrder = orderList.get(0);
                Date placeOrderTime = firstOrder.getThirdCreateTime();
                if (placeOrderTime.getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME)
                    return;
                int urank = firstOrder.getUrank();
                UserLevelEnum buyerUserLevel = UserLevelUtil.getByOrderRank(urank);
                if (buyerUserLevel == null)
                    throw new InviteOrderSubsidyException(11, "用户等级为空");
                List<Long> idList = new ArrayList<>();
                for (HongBaoOrder ho : list)
                    if (ho.getHongBaoV2() != null)
                        idList.add(ho.getHongBaoV2().getId());
                // 查询该订单号下的所有子红包
                List<HongBaoV2> children = hongBaoV2Service.listChildrenByIds(idList);
                if (children != null && children.size() > 0) {
                    Map<Long, Integer> uidHongBaoMap = new ConcurrentHashMap<>();
                    for (HongBaoV2 v2 : children) {// 按用户ID统计红包
                        Long uid = v2.getUserInfo().getId();
                        if (v2.getState() == HongBaoV2.STATE_BUKELINGQU || v2.getState() == HongBaoV2.STATE_KELINGQU
                                || v2.getState() == HongBaoV2.STATE_YILINGQU) {
                            uidHongBaoMap.put(uid, v2.getType());
                        }
                    }
                    List<HongBaoV2> hbList = hongBaoV2Service.listByIds(idList);
                    Integer state = InviteOrderSubsidy.STATE_UNKNOWN;
                    // 产生改订单的返利总金额
                    BigDecimal totalBuyFanLiMoney = new BigDecimal(0);
                    // 计算总返利
                    for (HongBaoV2 v2 : hbList) {
                        if (v2.getState() == HongBaoV2.STATE_BUKELINGQU || v2.getState() == HongBaoV2.STATE_KELINGQU
                                || v2.getState() == HongBaoV2.STATE_YILINGQU)
                            totalBuyFanLiMoney = totalBuyFanLiMoney.add(v2.getMoney());
                    }
                    // 计算奖励金
                    for (Iterator<Long> its = uidHongBaoMap.keySet().iterator(); its.hasNext();) {
                        Long uid = its.next();
                        UserLevelEnum userLevel = userLevelManager.getUserLevel(uid, placeOrderTime);
                        int type = uidHongBaoMap.get(uid);
                        if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_ERJI
                                || type == HongBaoV2.TYPE_SHARE_YIJI || type == HongBaoV2.TYPE_SHARE_ERJI) {
                            BigDecimal money = null;
                            if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_SHARE_YIJI)
                                money = orderHongBaoMoneyComputeService.computeFirstTeamSubsidy(totalBuyFanLiMoney,
                                        placeOrderTime, buyerUserLevel, userLevel);
                            else
                                money = orderHongBaoMoneyComputeService.computeSecondTeamSubsidy(totalBuyFanLiMoney,
                                        placeOrderTime, buyerUserLevel, userLevel);
                            if (money == null)
                                continue;
                            InviteOrderSubsidy orderSubsidy = new InviteOrderSubsidy();
                            orderSubsidy.setMoney(money);
                            orderSubsidy.setOriginalMoney(money);
                            orderSubsidy.setUid(uid);
                            orderSubsidy.setOrderNo(orderId);
                            orderSubsidy.setSourceType(sourceType);
                            orderSubsidy.setState(state);
                            if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_SHARE_YIJI)
                                orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_ONE);
                            else
                                orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_TWO);
                            try {
                                addOrderSubsidy(orderSubsidy);
                            } 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);
                    }
                }
            }
        }
    }
    @Override
    public long countByOrderIdAndSourceType(String orderId, int sourceType) {
        return inviteOrderSubsidyMapper.countByOrderNoAndType(orderId, sourceType);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void invalidByOrderIdAndSourceType(String orderId, int sourceType) {
        List<InviteOrderSubsidy> list = inviteOrderSubsidyMapper.listByOrderNoAndType(orderId, sourceType);
        if (list != null && list.size() > 0)
            for (InviteOrderSubsidy subsidy : list) {
                if (subsidy.getState() == InviteOrderSubsidy.STATE_UNKNOWN
                        || subsidy.getState() == InviteOrderSubsidy.STATE_VALID) {
                    InviteOrderSubsidy update = new InviteOrderSubsidy(subsidy.getId());
                    update.setState(InviteOrderSubsidy.STATE_INVALID);
                    update.setUpdateTime(new Date());
                    update.setInValidTime(new Date());
                    inviteOrderSubsidyMapper.updateByPrimaryKeySelective(update);
                }
            }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void validByOrderIdAndSourceType(String orderId, int sourceType) throws InviteOrderSubsidyException {
        // 查询预计到账时间
        List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
        if (orderList == null || orderList.size() == 0)
            throw new InviteOrderSubsidyException(31, "订单不存在");
        if (orderList.get(0).getSettleTime() == null)
            throw new InviteOrderSubsidyException(32, "订单尚未确认收货");
        // 确认收货时间的下月25号到账
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(orderList.get(0).getSettleTime());
        calendar.add(Calendar.MONTH, 1);
        Date preGetTime = new Date(TimeUtil.convertToTimeTemp(
                calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
        List<InviteOrderSubsidy> list = inviteOrderSubsidyMapper.listByOrderNoAndType(orderId, sourceType);
        if (list != null && list.size() > 0)
            for (InviteOrderSubsidy subsidy : list) {
                if (subsidy.getState() == InviteOrderSubsidy.STATE_UNKNOWN) {
                    InviteOrderSubsidy update = new InviteOrderSubsidy(subsidy.getId());
                    update.setState(InviteOrderSubsidy.STATE_VALID);
                    update.setUpdateTime(new Date());
                    update.setValidTime(new Date());
                    update.setPreGetTime(preGetTime);
                    inviteOrderSubsidyMapper.updateByPrimaryKeySelective(update);
                }
            }
    }
    @Override
    public void settleById(Long id, BigDecimal money) {
        InviteOrderSubsidy orderSubsidy = new InviteOrderSubsidy(id);
        orderSubsidy.setMoney(money);
        orderSubsidy.setState(InviteOrderSubsidy.STATE_SUBSIDIZED);
        orderSubsidy.setUpdateTime(new Date());
        inviteOrderSubsidyMapper.updateByPrimaryKeySelective(orderSubsidy);
    }
    @Override
    public BigDecimal sumRecievedMoneyByUid(long uid, Integer level) {
        BigDecimal money = inviteOrderSubsidyMapper.sumRecievedMoneyByUid(uid, level);
        if (money == null) {
            money = new BigDecimal(0);
        }
        return money;
    }
    @Override
    public BigDecimal sumValidMoneyByUidAndDate(long uid, Integer day, Integer level) {
        BigDecimal money = inviteOrderSubsidyMapper.sumValidMoneyByUidAndDate(uid, day, level);
        if (money == null) {
            money = new BigDecimal(0);
        }
        return money;
    }
    @Override
    public BigDecimal sumMoneyByUidAndDateAndState(long uid, Integer day, Integer level, Integer state) {
        BigDecimal money = inviteOrderSubsidyMapper.sumMoneyByUidAndDateAndState(uid, day, level, state);
        if (money == null) {
            money = new BigDecimal(0);
        }
        return money;
    }
    @Override
    public List<InviteOrderSubsidy> listByOrderNoAndTypeAndUid(String orderNo, Integer type, Long uid) {
        return inviteOrderSubsidyMapper.listByOrderNoAndTypeAndUid(orderNo, type, uid);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderHongBaoMoneyComputeServiceImpl.java
@@ -95,89 +95,53 @@
    }
    @Override
    public BigDecimal computeFirstInviteMoney(CommonOrder order, UserLevelEnum buyer) {
        BigDecimal rate = hongBaoManageService.getByKeyAndMaxTime("new_invite_6", order.getThirdCreateTime().getTime());
        if (buyer == UserLevelEnum.superVIP || buyer == UserLevelEnum.tearcher)
            rate = hongBaoManageService.getByKeyAndMaxTime("new_invite_vip_6", order.getThirdCreateTime().getTime());
        if (rate.compareTo(new BigDecimal(0)) == 0)
            return null;
        if (order.getState() == CommonOrder.STATE_JS || order.getState() == CommonOrder.STATE_WQ)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                    new BigDecimal(100));
        else if (order.getEstimate() != null)
            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 || 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, getBaseCommission(order)),
                    new BigDecimal(100));
        else if (order.getEstimate() != null)
            return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                    new BigDecimal(100));
        else
            return null;
    }
    @Override
    public BigDecimal computeFirstTeamSubsidy(BigDecimal fanLiMoney, Date placeOrderTime, UserLevelEnum buyerUserLevel,
            UserLevelEnum userLevel) {
        BigDecimal rate = getTeamSubsidyRate(placeOrderTime, buyerUserLevel, userLevel, true);
        if (rate == null || rate.compareTo(new BigDecimal(0)) == 0)
            return null;
        BigDecimal baseRate = hongBaoManageService.getBaseFanliRate(placeOrderTime.getTime());
        BigDecimal officialSubsidyRate = getOfficialSubsidyRate(placeOrderTime, buyerUserLevel, false);
        return MoneyBigDecimalUtil.div(fanLiMoney.multiply(baseRate).multiply(rate),
                baseRate.add(officialSubsidyRate).multiply(new BigDecimal(100)));
    }
    @Override
    public BigDecimal computeSecondTeamSubsidy(BigDecimal fanLiMoney, Date placeOrderTime, UserLevelEnum buyerUserLevel,
            UserLevelEnum userLevel) {
        BigDecimal rate = getTeamSubsidyRate(placeOrderTime, buyerUserLevel, userLevel, false);
        if (rate == null || rate.compareTo(new BigDecimal(0)) == 0)
            return null;
        BigDecimal baseRate = hongBaoManageService.getBaseFanliRate(placeOrderTime.getTime());
        BigDecimal officialSubsidyRate = getOfficialSubsidyRate(placeOrderTime, buyerUserLevel, false);
        return MoneyBigDecimalUtil.div(fanLiMoney.multiply(baseRate).multiply(rate),
                baseRate.add(officialSubsidyRate).multiply(new BigDecimal(100)));
    }
    /**
     * 获取粉丝的补贴比例
     * @Title: getSecondTeamSubsidy
     * @Description:
     * @param date
     * @param buyerUserLevel
     * @param userLevel
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    @Override
    public BigDecimal getTeamSubsidyRate(Date date, UserLevelEnum buyerUserLevel, UserLevelEnum userLevel,
            boolean direct) {
        String key = null;
        if (direct)
            key = String.format("team_subsidy_6_pre_%s_%s", buyerUserLevel.getLevel(), userLevel.getLevel());
        else
            key = String.format("team_subsidy_7_pre_%s_%s", buyerUserLevel.getLevel(), userLevel.getLevel());
    public BigDecimal computeFirstInviteMoney(CommonOrder order, UserLevelEnum buyer,
            List<UserTeamLevel> bossLevelList) {
        BigDecimal rate = null;
        if (date != null)
            rate = hongBaoManageService.getByKeyAndMaxTime(key, date.getTime());
        else
            rate = new BigDecimal(hongBaoManageService.get(key));
        return rate;
        if (order.getThirdCreateTime().getTime() >= Constant.NEW_ORDER_FANLI_RULE_TIME) {
            rate = getTeamRewardRate(buyer, bossLevelList, order.getThirdCreateTime(), 1).getRate();
            if (rate == null)
                return null;
            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 {// 老的返利比例
            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, getBaseCommission(order)),
                        new BigDecimal(100));
            else if (order.getEstimate() != null)
                return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                        new BigDecimal(100));
        }
        return null;
    }
    @Override
    public BigDecimal computeSecondInviteMoney(CommonOrder order, UserLevelEnum buyer,
            List<UserTeamLevel> bossLevelList) {
        BigDecimal rate = null;
        if (order.getThirdCreateTime().getTime() >= Constant.NEW_ORDER_FANLI_RULE_TIME) {
            rate = getTeamRewardRate(buyer, bossLevelList, order.getThirdCreateTime(), 2).getRate();
            if (rate == null)
                return null;
            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 {// 老的返利比例
            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, getBaseCommission(order)),
                        new BigDecimal(100));
            else if (order.getEstimate() != null)
                return MoneyBigDecimalUtil.div(MoneyBigDecimalUtil.mul(rate, getBaseCommission(order)),
                        new BigDecimal(100));
        }
        return null;
    }
    /**
@@ -205,22 +169,16 @@
        return rate;
    }
    private BigDecimal getRateByLevel(UserLevelEnum level) {
        if (level == UserLevelEnum.daRen)
            return new BigDecimal(58);
        else if (level == UserLevelEnum.normalVIP)
            return new BigDecimal(66);
        else if (level == UserLevelEnum.highVIP)
            return new BigDecimal(78);
        else if (level == UserLevelEnum.superVIP)
            return new BigDecimal(85);
        else if (level == UserLevelEnum.tearcher)
            return new BigDecimal(86);
        return null;
    private BigDecimal getRateByLevel(UserLevelEnum level, Date date) {
        BigDecimal baseRate = hongBaoManageService.getBaseFanliRate(date.getTime());
        BigDecimal subsidyRate = getOfficialSubsidyRate(date, level, false);
        return baseRate.add(subsidyRate);
    }
    @Override
    public UserTeamRate getTeamRewardRate(UserLevelEnum buyerLevel, List<UserTeamLevel> bossLevelList,
    public UserTeamRate getTeamRewardRate(UserLevelEnum buyerLevel, List<UserTeamLevel> bossLevelList, Date date,
            int deep) {
        if (deep == 1) {// 直接邀请人奖金
            UserTeamLevel boss = bossLevelList.get(0);
@@ -233,8 +191,8 @@
            } else if (buyerLevel == UserLevelEnum.normalVIP && boss.getLevel() == UserLevelEnum.normalVIP) {
                rate = new BigDecimal(9);
            } else {
                BigDecimal bossRate = getRateByLevel(boss.getLevel());
                BigDecimal buyerRate = getRateByLevel(buyerLevel);
                BigDecimal bossRate = getRateByLevel(boss.getLevel(), date);
                BigDecimal buyerRate = getRateByLevel(buyerLevel, date);
                rate = bossRate.subtract(buyerRate);
                if (rate.compareTo(new BigDecimal(0)) < 0)
                    rate = new BigDecimal(0);
@@ -246,8 +204,8 @@
            if (bossLevelList == null || bossLevelList.size() < 2)
                return null;
            BigDecimal buyerRate = getRateByLevel(buyerLevel);
            BigDecimal firstRate = getTeamRewardRate(buyerLevel, bossLevelList, 1).getRate();
            BigDecimal buyerRate = getRateByLevel(buyerLevel, date);
            BigDecimal firstRate = getTeamRewardRate(buyerLevel, bossLevelList, date, 1).getRate();
            UserTeamLevel boss = bossLevelList.get(1);
            UserTeamLevel firstBoss = bossLevelList.get(0);
@@ -267,7 +225,7 @@
            }
            // 极差计算法
            if (rate == null) {
                rate = getRateByLevel(boss.getLevel()).subtract(buyerRate).subtract(firstRate);
                rate = getRateByLevel(boss.getLevel(), date).subtract(buyerRate).subtract(firstRate);
                if (rate.compareTo(new BigDecimal(0)) < 0)
                    rate = new BigDecimal(0);
            }
@@ -279,25 +237,25 @@
    @Override
    public List<UserTeamRate> getTeamRewardMoreThan2LevelRates(UserLevelEnum buyerLevel,
            List<UserTeamLevel> bossLevelList) {
            List<UserTeamLevel> bossLevelList, Date date) {
        if (bossLevelList == null || bossLevelList.size() < 3)
            return null;
        UserTeamRate firstBoss = getTeamRewardRate(buyerLevel, bossLevelList, 1);
        UserTeamRate firstBoss = getTeamRewardRate(buyerLevel, bossLevelList, date, 1);
        if (firstBoss == null)
            return null;
        UserTeamRate secondBoss = getTeamRewardRate(buyerLevel, bossLevelList, 2);
        UserTeamRate secondBoss = getTeamRewardRate(buyerLevel, bossLevelList, date, 2);
        if (secondBoss == null)
            return null;
        BigDecimal buyerRate = getRateByLevel(buyerLevel);
        BigDecimal buyerRate = getRateByLevel(buyerLevel, date);
        BigDecimal totalRate = firstBoss.getRate().add(secondBoss.getRate()).add(buyerRate);
        List<UserTeamRate> rateList = new ArrayList<>();
        for (int i = 2; i < bossLevelList.size(); i++) {
            BigDecimal rate = getRateByLevel(bossLevelList.get(i).getLevel());
            BigDecimal rate = getRateByLevel(bossLevelList.get(i).getLevel(), date);
            if (rate.compareTo(totalRate) > 0) {
                BigDecimal subRate = rate.subtract(totalRate);
                totalRate = subRate.add(totalRate);// 累计分成比例
@@ -310,8 +268,8 @@
    // 团队分红
    @Override
    public List<UserTeamRate> getTeamDividentsRates(UserLevelEnum buyerLevel,
            List<UserTeamLevel> bossLevelList) {
    public List<UserTeamRate> getTeamDividentsRates(UserLevelEnum buyerLevel, List<UserTeamLevel> bossLevelList,
            Date date) {
        List<UserTeamRate> rateList = new ArrayList<>();
        List<UserTeamLevel> levelList = new ArrayList<>();
@@ -395,7 +353,7 @@
    @Override
    public UserTeamRate getTearcherSubsidy(UserLevelEnum buyerLevel, BigDecimal money,
            List<UserTeamLevel> bossLevelList) {
            List<UserTeamLevel> bossLevelList, Date date) {
        // TODO Auto-generated method stub
        return null;
    }
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -53,7 +53,6 @@
import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.manger.order.TeamRewardManager;
import com.yeshi.fanli.service.manger.order.TeamSubsidyManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.cmq.HongBaoRecieveCMQManager;
@@ -108,8 +107,6 @@
    @Resource
    private TeamRewardManager teamRewardManager;
    @Resource
    private TeamSubsidyManager teamSubsidyManager;
    // 下级被封禁,红包失效
    private void invalidHongBaoForbidden(Long id) {
@@ -819,20 +816,6 @@
        }
    }
    /**
     * 邀请补贴结算
     *
     * @param orderId
     * @param sourceType
     * @throws ParamsException
     * @throws TeamEincomeRecordException
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void inviteSubsidySettle(Long uid, String taskKey, Date maxPreGetTime)
            throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException {
        teamSubsidyManager.addToTeamEincome(uid, taskKey, maxPreGetTime);
    }
    private String getTaskKey(Long uid) {
        return uid + "-" + UUID.randomUUID().toString();
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -35,11 +35,11 @@
import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.dto.order.CommonOrderAddResultDTO;
import com.yeshi.fanli.dto.order.HongBaoAddResult;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
import com.yeshi.fanli.entity.elme.ElmeHongBaoOrderMap;
import com.yeshi.fanli.entity.elme.ElmeOrder;
import com.yeshi.fanli.entity.jd.JDOrder;
@@ -1388,16 +1388,16 @@
    private void addHongBaoWithMQ(List<CommonOrderAddResultDTO> commonOrderList, String orderId, Long uid,
            int sourceType, int hongBaoType) {
        final List<CommonOrder> coList = convertCommonOrder(commonOrderList);
        int resultCode = 0;
        HongBaoAddResult result = null;
        try {
            long time = TimeUtil.convertToTimeTemp("2019-12-06", "yyyy-MM-dd");
            if (!Constant.IS_TEST)
                time = TimeUtil.convertToTimeTemp("2019-12-20", "yyyy-MM-dd");
            if (coList.get(0).getThirdCreateTime().getTime() < time)
                resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType);
                result = hongBaoV2Service.addHongBao(coList, hongBaoType);
            else
                resultCode = hongBaoV2AddManager.addHongBao(coList, hongBaoType);
                result = hongBaoV2AddManager.addHongBao(coList, hongBaoType);
        } catch (HongBaoException e) {
            try {
                LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + orderId);
@@ -1408,9 +1408,9 @@
        }
        if (!Constant.IS_TEST)
            if (resultCode == 1) {// 只发送新增消息
            if (result.getResultCode() == HongBaoAddResult.CODE_ADD) {// 只发送新增消息
                OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid, OrderMQMsg.HANDLE_TYPE_ADD,
                        isCommonOrderValid(coList), 0, new Date());
                        isCommonOrderValid(coList), 0, new Date(), result.isMiandan());
                Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderStatistic, mqMsg);
                producer.send(msg);
            }
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderServiceImpl.java
@@ -25,8 +25,7 @@
    public TeamDividentsSourceOrder addTeamDividentsSourceOrder(TeamDividentsSourceOrder order)
            throws TeamDividentsSourceOrderException, ParamsException {
        if (order == null || order.getMoney() == null || StringUtil.isNullOrEmpty(order.getOrderNo())
                || order.getSourceType() == null || order.getState() == null || order.getUid() == null
                || order.getPreSendTime() == null)
                || order.getSourceType() == null || order.getState() == null || order.getUid() == null)
            throw new ParamsException(1, "参数不完整");
        TeamDividentsSourceOrder sourceOrder = selectByOrderNoSourceType(order.getOrderNo(), order.getSourceType());
fanli/src/main/java/com/yeshi/fanli/service/impl/order/dividents/TeamDividentsSourceOrderUserMapServiceImpl.java
@@ -37,6 +37,7 @@
            TeamDividentsSourceOrderUserMap update = new TeamDividentsSourceOrderUserMap();
            update.setId(id);
            update.setState(TeamDividentsSourceOrderUserMap.STATE_YILINGQU);
            update.setSendTime(new Date());
            update.setUpdateTime(new Date());
            teamDividentsSourceOrderUserMapMapper.updateByPrimaryKeySelective(update);
        }
@@ -118,6 +119,14 @@
            }
    }
    @Override
    public void invalidOrderBySourceUid(Long sourceUid, String beiZhu) {
        List<Integer> stateList = new ArrayList<>();
        stateList.add(TeamDividentsSourceOrderUserMap.STATE_FK);
        stateList.add(TeamDividentsSourceOrderUserMap.STATE_JS);
        teamDividentsSourceOrderUserMapMapper.invalidOrderBySourceUid(sourceUid, beiZhu, stateList);
    }
    @Transactional
    @Override
    public void orderSettle(Long sourceOrderId, Date preSendTime, BigDecimal income) {
@@ -128,9 +137,10 @@
                    TeamDividentsSourceOrderUserMap update = new TeamDividentsSourceOrderUserMap();
                    update.setId(map.getId());
                    update.setMoney(MoneyBigDecimalUtil.div(income.multiply(map.getRate()), new BigDecimal(100), 4));
                    update.setMoney(MoneyBigDecimalUtil.div(income.multiply(map.getRate()), new BigDecimal(100), 3));
                    update.setUpdateTime(new Date());
                    update.setState(TeamDividentsSourceOrderUserMap.STATE_JS);
                    update.setPreSendTime(preSendTime);
                    teamDividentsSourceOrderUserMapMapper.updateByPrimaryKeySelective(update);
                }
            }
@@ -145,7 +155,7 @@
                if (map.getState() == TeamDividentsSourceOrderUserMap.STATE_FK) {
                    TeamDividentsSourceOrderUserMap update = new TeamDividentsSourceOrderUserMap();
                    update.setId(map.getId());
                    update.setMoney(MoneyBigDecimalUtil.div(income.multiply(map.getRate()), new BigDecimal(100), 4));
                    update.setMoney(MoneyBigDecimalUtil.div(income.multiply(map.getRate()), new BigDecimal(100), 3));
                    update.setUpdateTime(new Date());
                    teamDividentsSourceOrderUserMapMapper.updateByPrimaryKeySelective(update);
                }
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/TeamUserLevelStatisticServiceImpl.java
@@ -1,7 +1,10 @@
package com.yeshi.fanli.service.impl.user.vip;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@@ -23,10 +26,9 @@
    @Resource
    private TeamUserLevelStatisticMapper teamUserLevelStatisticMapper;
    @Resource
    private UserInviteValidRecordService userInviteValidRecordService;
    @Override
    public TeamUserLevelStatistic selectByUid(Long uid) {
@@ -34,25 +36,51 @@
    }
    @Override
    public List<TeamUserLevelStatistic> listByUids(List<Long> uids) {
        List<TeamUserLevelStatistic> resultList = new ArrayList<>();
        List<TeamUserLevelStatistic> list = teamUserLevelStatisticMapper.listByUids(uids);
        // 放入Map中
        Map<Long, TeamUserLevelStatistic> map = new HashMap<>();
        if (list != null)
            for (TeamUserLevelStatistic s : list) {
                map.put(s.getId(), s);
            }
        for (Long uid : uids) {
            if (map.get(uid) == null) {
                initData(uid);
                TeamUserLevelStatistic statistic = selectByUid(uid);
                resultList.add(statistic);
            } else {
                resultList.add(map.get(uid));
            }
        }
        return null;
    }
    @Override
    public void initData(Long uid) {
        int pageSize = 1000;
        // 直接粉丝统计
        int daRenFirstCount = 0;
        int highFirstCount = 0;
        int superFirstCount = 0;
        int tearcherFirstCount = 0;
        for (int i = 0; i < 100; i ++) {
        for (int i = 0; i < 100; i++) {
            List<UserInviteValidRecord> list = userInviteValidRecordService.listFirstTeam(i * pageSize, pageSize, uid);
            if (list == null || list.size() == 0) {
                break;
            }
            for (UserInviteValidRecord ts : list) {
                UserLevelEnum level = userLevelManager.getUserLevel(ts.getWorkerId());
                if (level == UserLevelEnum.daRen) {
                    daRenFirstCount++;
                }  else if (level == UserLevelEnum.highVIP) {
                } else if (level == UserLevelEnum.highVIP) {
                    highFirstCount++;
                } else if (level == UserLevelEnum.superVIP) {
                    superFirstCount++;
@@ -61,19 +89,18 @@
                }
            }
        }
        // 间接粉丝统计
        int daRenSecondCount = 0;
        int highSecondCount = 0;
        int superSecondCount = 0;
        int tearcherSecondCount = 0;
        for (int i = 0; i < 100; i ++) {
        for (int i = 0; i < 100; i++) {
            List<UserInviteValidRecord> list = userInviteValidRecordService.listSecondTeam(i * pageSize, pageSize, uid);
            if (list == null || list.size() == 0) {
                break;
            }
            for (UserInviteValidRecord ts : list) {
                UserLevelEnum level = userLevelManager.getUserLevel(ts.getWorkerId());
                if (level == UserLevelEnum.daRen) {
fanli/src/main/java/com/yeshi/fanli/service/inter/money/InviteOrderSubsidyDebtService.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/service/inter/order/HongBaoV2Service.java
@@ -5,6 +5,7 @@
import java.util.List;
import com.yeshi.fanli.dto.HongBaoDTO;
import com.yeshi.fanli.dto.order.HongBaoAddResult;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.exception.order.HongBaoException;
@@ -34,7 +35,7 @@
     * @return 0-未添加也未更新 1-只添加 2-只更新 12-有添加也有更新
     * @throws HongBaoException
     */
    public int addHongBao(List<CommonOrder> commonOrder, int type) throws HongBaoException,UserAccountException ;
    public HongBaoAddResult addHongBao(List<CommonOrder> commonOrder, int type) throws HongBaoException,UserAccountException ;
    /**
     * 奖金列表(1.4.9之前的版本)
fanli/src/main/java/com/yeshi/fanli/service/inter/order/InviteOrderSubsidyService.java
@@ -1,11 +1,6 @@
package com.yeshi.fanli.service.inter.order;
import java.math.BigDecimal;
import java.util.List;
import com.yeshi.fanli.entity.order.InviteOrderSubsidy;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
public interface InviteOrderSubsidyService {
@@ -18,78 +13,4 @@
     * @return
     */
    public InviteOrderSubsidy getByOrderNoAndType(Long uid, String orderNo, Integer type);
    public List<InviteOrderSubsidy> listByOrderNoAndType(String orderNo, Integer type);
    public List<InviteOrderSubsidy> listByOrderNoAndTypeAndUid(String orderNo, Integer type,Long uid);
    /**
     * 查询补贴(加锁)
     * @param uid
     * @param orderNo
     * @param type
     * @return
     */
    public InviteOrderSubsidy getByOrderNoAndTypeForUpdate(Long uid, String orderNo, Integer type);
    /**
     * 添加或修改(按照订单号与来源)
     *
     * @param orderId
     * @param sourceType
     */
    public void addOrUpdateByOrder(String orderId, int sourceType)
            throws InviteOrderSubsidyException, CommonOrderException;
    /**
     * 根据订单号与来源查询
     *
     * @param orderId
     * @param sourceType
     * @return
     */
    public long countByOrderIdAndSourceType(String orderId, int sourceType);
    /**
     * 使订单号对应的数据失效
     *
     * @param orderId
     * @param sourceType
     */
    public void invalidByOrderIdAndSourceType(String orderId, int sourceType);
    /**
     * 使订单号对应的数据有效
     * @param orderId
     * @param sourceType
     */
    public void validByOrderIdAndSourceType(String orderId, int sourceType) throws InviteOrderSubsidyException;
    /**
     * 结算金额
     * @param id
     * @param money
     */
    public void settleById(Long id, BigDecimal money);
    /**
     * 统计已到账金额
     * @param uid
     * @param level
     * @return
     */
    public BigDecimal sumRecievedMoneyByUid(long uid, Integer level);
    /**
     * 统计有效金额
     * @param uid
     * @param day
     * @param level
     * @return
     */
    public BigDecimal sumValidMoneyByUidAndDate(long uid, Integer day, Integer level);
    public BigDecimal sumMoneyByUidAndDateAndState(long uid, Integer day, Integer level, Integer state);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderHongBaoMoneyComputeService.java
@@ -71,7 +71,8 @@
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal computeFirstInviteMoney(CommonOrder order, UserLevelEnum buyer);
    public BigDecimal computeFirstInviteMoney(CommonOrder order, UserLevelEnum buyer,
            List<UserTeamLevel> bossLevelList);
    /**
     * 计算间接粉丝邀请奖金
@@ -82,47 +83,8 @@
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal computeSecondInviteMoney(CommonOrder order, UserLevelEnum buyer);
    /**
     * 计算直接粉丝团队补贴
     * @Title: computeFirstTeamSubsidy
     * @Description:
     * @param order
     * @param buyerUserLevel
     * @param userLevel
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal computeFirstTeamSubsidy(BigDecimal fanLiMoney, Date placeOrderTime, UserLevelEnum buyerUserLevel,
            UserLevelEnum userLevel);
    /**
     * 计算间接粉丝团队补贴
     * @Title: computeSecondTeamSubsidy
     * @Description:
     * @param order
     * @param buyerUserLevel
     * @param userLevel
     * @return
     * BigDecimal 返回类型
     * @throws
     */
    public BigDecimal computeSecondTeamSubsidy(BigDecimal fanLiMoney, Date placeOrderTime, UserLevelEnum buyerUserLevel,
            UserLevelEnum userLevel);
    /**
     * 计算团队补贴
     * @param date 下单时间
     * @param buyerUserLevel 下单时 下单人当时等级
     * @param userLevel 下单时 上级人对应等级
     * @param direct 是否直接邀请关系
     * @return
     */
    public BigDecimal getTeamSubsidyRate(Date date, UserLevelEnum buyerUserLevel, UserLevelEnum userLevel,
            boolean direct);
    public BigDecimal computeSecondInviteMoney(CommonOrder order, UserLevelEnum buyer,
            List<UserTeamLevel> bossLevelList);
    /**
     * 获取团队奖金
@@ -136,7 +98,7 @@
     * BigDecimal 返回类型
     * @throws
     */
    public UserTeamRate getTeamRewardRate(UserLevelEnum buyerLevel, List<UserTeamLevel> bossLevelList,
    public UserTeamRate getTeamRewardRate(UserLevelEnum buyerLevel, List<UserTeamLevel> bossLevelList, Date date,
            int deep);
    /**
@@ -152,7 +114,7 @@
     * @throws
     */
    public List<UserTeamRate> getTeamRewardMoreThan2LevelRates(UserLevelEnum buyerLevel,
            List<UserTeamLevel> bossLevelList);
            List<UserTeamLevel> bossLevelList, Date date);
    /**
     * 获取分红
@@ -165,8 +127,8 @@
     * List<UserTeamMoney> 返回类型
     * @throws
     */
    public List<UserTeamRate> getTeamDividentsRates(UserLevelEnum buyerLevel,
            List<UserTeamLevel> bossLevelList);
    public List<UserTeamRate> getTeamDividentsRates(UserLevelEnum buyerLevel, List<UserTeamLevel> bossLevelList,
            Date date);
    /**
     * 获取资深导师 补贴
@@ -179,7 +141,7 @@
     * UserTeamMoney 返回类型
     * @throws
     */
    public UserTeamRate getTearcherSubsidy(UserLevelEnum buyerLevel, BigDecimal rate,
            List<UserTeamLevel> bossLevelList);
    public UserTeamRate getTearcherSubsidy(UserLevelEnum buyerLevel, BigDecimal rate, List<UserTeamLevel> bossLevelList,
            Date date);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/order/OrderMoneySettleService.java
@@ -2,9 +2,7 @@
import java.util.Date;
import com.yeshi.fanli.exception.ParamsException;
import com.yeshi.fanli.exception.money.OrderMoneySettleException;
import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
/**
 * 订单资金结算服务
@@ -43,14 +41,5 @@
     * @param sourceType
     */
    public void ziGouSettle(String orderId, int sourceType, String taskKey) throws OrderMoneySettleException;
    /**
     * 邀请补贴结算
     * @param uid
     * @param taskKey
     * @throws OrderMoneySettleException
     */
    public void inviteSubsidySettle(Long uid, String taskKey, Date maxPreGetTime)
            throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException;
}
fanli/src/main/java/com/yeshi/fanli/service/inter/order/dividents/TeamDividentsSourceOrderUserMapService.java
@@ -121,6 +121,16 @@
    public void invalidBySourceOrderId(Long sourceOrderId);
    /**
     * 用户对应的订单失效
     * @Title: invalidOrderBySourceUid
     * @Description:
     * @param sourceUid
     * void 返回类型
     * @throws
     */
    public void invalidOrderBySourceUid(Long sourceUid,String beiZhu);
    /**
     * 订单结算
     * @Title: orderSettle
     * @Description: 
fanli/src/main/java/com/yeshi/fanli/service/inter/user/vip/TeamUserLevelStatisticService.java
@@ -1,5 +1,7 @@
package com.yeshi.fanli.service.inter.user.vip;
import java.util.List;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
/**
@@ -21,6 +23,17 @@
    public TeamUserLevelStatistic selectByUid(Long uid);
    /**
     * 根据列表查询
     * @Title: selectByUids
     * @Description:
     * @param uid
     * @return
     * List<TeamUserLevelStatistic> 返回类型
     * @throws
     */
    public List<TeamUserLevelStatistic> listByUids(List<Long> uids);
    /**
     * 初始化数据
     * @Title: initData
     * @Description: 
fanli/src/main/java/com/yeshi/fanli/service/manger/order/HongBaoV2AddManager.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.service.manger.order;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
@@ -19,19 +20,20 @@
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.HongBaoAddResult;
import com.yeshi.fanli.dto.order.UserTeamLevel;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.vip.TeamUserLevelStatistic;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
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.entity.order.InviteOrderSubsidy;
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;
@@ -41,6 +43,7 @@
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.service.manger.user.UserLevelManager;
import com.yeshi.fanli.util.Constant;
@@ -94,6 +97,9 @@
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
    @Resource
    private TeamUserLevelStatisticService teamUserLevelStatisticService;
    /**
     * 添加红包信息
     * 
@@ -106,7 +112,8 @@
     * @throws OrderTeamRewardException 
     * @throws InviteOrderSubsidyException 
     */
    public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException {
    public HongBaoAddResult addHongBao(List<CommonOrder> commonOrderList, int type)
            throws HongBaoException, UserAccountException {
        if (commonOrderList != null && commonOrderList.size() > 0) {
            int orderType = commonOrderList.get(0).getSourceType();
@@ -125,6 +132,8 @@
            Date placeOrderDate = commonOrderList.get(0).getThirdCreateTime();
            boolean miandan = false;
            for (CommonOrder commonOrder : commonOrderList) {
                stateSet.add(commonOrder.getState());
                goodsCount += commonOrder.getCount();
@@ -132,7 +141,7 @@
                    throw new HongBaoException(1, "订单信息不完整");
                HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                if (hongBaoOrder == null) {
                    saveHongBao(commonOrder, type, notificationMap, userLevel, placeOrderDate);
                    miandan = saveHongBao(commonOrder, type, notificationMap, userLevel, placeOrderDate);
                    hasAdd = true;
                } else {
                    boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap, placeOrderDate);
@@ -142,31 +151,8 @@
                }
            }
            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);
                    }
            }
            /**
             * 通知用户的返利情况
@@ -183,15 +169,6 @@
                    CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
                    Long uid = notify.getUserInfo().getId();
                    List<InviteOrderSubsidy> subsidyList = inviteOrderSubsidyService.listByOrderNoAndTypeAndUid(orderId,
                            orderType, uid);
                    BigDecimal subsidy = new BigDecimal(0);
                    if (subsidyList != null)
                        for (InviteOrderSubsidy s : subsidyList) {
                            if (s.getState() != InviteOrderSubsidy.STATE_INVALID)
                                subsidy = subsidy.add(s.getOriginalMoney());
                        }
                    BigDecimal money = notify.getMoney();
                    switch (t) {
                    case HongBaoV2.TYPE_ZIGOU:
@@ -207,27 +184,27 @@
                        break;
                    case HongBaoV2.TYPE_YIJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money, subsidy, goodsCount, state,
                                commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, state,
                                commonOrder.getThirdCreateTime());
                        break;
                    case HongBaoV2.TYPE_ERJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money, subsidy, goodsCount, state,
                                commonOrder.getPayment(), money,  new BigDecimal(0), goodsCount, state,
                                commonOrder.getThirdCreateTime());
                        break;
                    case HongBaoV2.TYPE_SHARE_YIJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money, subsidy, goodsCount, state,
                                commonOrder.getPayment(), money,  new BigDecimal(0), goodsCount, state,
                                commonOrder.getThirdCreateTime());
                        break;
                    case HongBaoV2.TYPE_SHARE_ERJI:
                        userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                commonOrder.getPayment(), money, subsidy, goodsCount, state,
                                commonOrder.getPayment(), money,  new BigDecimal(0), goodsCount, state,
                                commonOrder.getThirdCreateTime());
                        break;
@@ -239,14 +216,14 @@
            int resultCode = 0;
            if (hasAdd && hasUpdate)
                return 12;
                return new HongBaoAddResult(HongBaoAddResult.CODE_ADD_AND_UPDATE, miandan);
            else if (hasAdd)
                return 1;
                return new HongBaoAddResult(HongBaoAddResult.CODE_ADD, miandan);
            else if (hasUpdate)
                return 2;
            return resultCode;
                return new HongBaoAddResult(HongBaoAddResult.CODE_UPDATE, miandan);
            return new HongBaoAddResult(resultCode, miandan);
        }
        return 0;
        return new HongBaoAddResult(0, false);
    }
    private int getOrderState(Set<Integer> states) {
@@ -261,6 +238,24 @@
                return CommonOrder.STATE_JS;
        }
        return CommonOrder.STATE_SX;
    }
    private List<UserTeamLevel> getBossList(Long uid, int deep) {
        List<UserTeamLevel> resultList = new ArrayList<>();
        List<ThreeSale> threeSales = threeSaleSerivce.getMyBossDeepList(uid, deep);
        if (threeSales != null) {
            List<Long> uidList = new ArrayList<Long>();
            for (ThreeSale ts : threeSales)
                uidList.add(ts.getBoss().getId());
            List<TeamUserLevelStatistic> levelList = teamUserLevelStatisticService.listByUids(uidList);
            if (levelList != null)
                for (TeamUserLevelStatistic s : levelList) {
                    resultList.add(new UserTeamLevel(s.getId(), s.getLevel()));
                }
        }
        return resultList;
    }
    private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
@@ -339,14 +334,18 @@
            // 获取子红包
            List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
            if (children != null && children.size() > 0) {
                List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2);
                for (HongBaoV2 child : children) {
                    if (child.getState() == HongBaoV2.STATE_YILINGQU)
                        continue;
                    if (child.getType() == HongBaoV2.TYPE_YIJI) {
                        money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                        money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel,
                                bossList);
                    } else if (child.getType() == HongBaoV2.TYPE_ERJI) {
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel,
                                bossList);
                    }
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder);
@@ -382,8 +381,11 @@
                        }
                        if (boss != null) {
                            List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2);
                            // 插入一级子红包
                            money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                            money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel,
                                    bossList);
                            UserLevelEnum bossUserLevel = userLevelManager.getUserLevel(boss.getId());
                            if (money != null) {
                                HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder,
@@ -397,7 +399,7 @@
                            }
                            if (boss != null) {
                                money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder,
                                        buyerLevel);
                                        buyerLevel, bossList);
                                bossUserLevel = userLevelManager.getUserLevel(boss.getId());
                                if (money != null) {
                                    HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder,
@@ -437,15 +439,18 @@
            // 获取子红包
            List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
            if (children != null)
            if (children != null && children.size() > 0) {
                List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2);
                for (HongBaoV2 child : children) {
                    if (child.getState() == HongBaoV2.STATE_YILINGQU)
                        continue;
                    if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
                        money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                        money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel,
                                bossList);
                    } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) {
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel,
                                bossList);
                    }
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(), money, commonOrder);
                    hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
@@ -472,6 +477,7 @@
                    }
                }
            }
        } else
            throw new HongBaoException(2, "type错误");
@@ -479,7 +485,7 @@
    }
    @Transactional(rollbackFor = Exception.class)
    private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap,
    private boolean saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap,
            UserLevelEnum buyerLevel, Date placeOrderDate) throws HongBaoException, UserAccountException {
        if (type == HongBaoV2.TYPE_ZIGOU) {
@@ -520,13 +526,17 @@
                    orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, buyerLevel), mianDanMoney,
                    buyerLevel);
            if (hongBao == null)
                return;
                return mianDanMoney != null;
            addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
            UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
            if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1级BOSS存在且红包未失效,免单不支持多级分销
                BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2);
                BigDecimal money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel,
                        bossList);
                if (money == null)// 返利资金为空不参与分成
                    return;
                    return mianDanMoney != null;
                UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId());
@@ -538,10 +548,10 @@
                // 插入二级子红包
                boss = threeSaleSerivce.getBoss(boss.getId());
                if (boss != null) {// 二级BOSS存在且是非会员订单
                    money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                    money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel, bossList);
                    bossLevel = userLevelManager.getUserLevel(boss.getId());
                    if (money == null)
                        return;
                        return mianDanMoney != null;
                    HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                            HongBaoV2.TYPE_ERJI, money, bossLevel);
                    addInviteHongBao(secondHongbao, null, notificationMap, commonOrder);
@@ -551,7 +561,7 @@
        } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
            // 分享赚不加入失效的订单
            if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
                return;
                return false;
            // 分享赚
            BigDecimal money = null;
            if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO
@@ -568,18 +578,21 @@
                money = orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, buyerLevel);
            if (money == null || money.compareTo(new BigDecimal(0)) <= 0)
                return;
                return false;
            HongBaoV2 hongBao = createShareHongBao(commonOrder, money, buyerLevel);
            if (hongBao == null)
                return;
                return false;
            addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
            // 4月17日后才有一级分享赚
            if (placeOrderDate.getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) {
                UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
                if (boss != null) {
                    money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel);
                    List<UserTeamLevel> bossList = getBossList(hongBao.getUserInfo().getId(), 2);
                    money = orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder, buyerLevel, bossList);
                    if (money == null)
                        return;
                        return false;
                    UserLevelEnum bossLevel = userLevelManager.getUserLevel(boss.getId());
                    HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                            HongBaoV2.TYPE_SHARE_YIJI, money, bossLevel);
@@ -589,9 +602,10 @@
                    // 二级分享赚
                    boss = threeSaleSerivce.getBoss(boss.getId());
                    if (boss != null) {
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel);
                        money = orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder, buyerLevel,
                                bossList);
                        if (money == null)// 返利比例为0就不统计
                            return;
                            return false;
                        bossLevel = userLevelManager.getUserLevel(boss.getId());
                        HongBaoV2 secondChild = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                                HongBaoV2.TYPE_SHARE_ERJI, money, bossLevel);
@@ -624,6 +638,8 @@
            // }
        } else
            throw new HongBaoException(2, "type错误");
        return false;
    }
    /**
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamDividentsSourceManager.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.service.manger.order;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
@@ -63,6 +64,8 @@
        if (commonOrderList.get(0).getThirdCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME)
            return;
        Date placeOrderTime = commonOrderList.get(0).getThirdCreateTime();
        UserLevelEnum level = UserLevelUtil.getByOrderRank(commonOrderList.get(0).getUrank());
        if (level == null)
            level = UserLevelEnum.daRen;
@@ -85,7 +88,8 @@
            return;
        // 计算团队分红比例
        List<UserTeamRate> rateList = orderHongBaoMoneyComputeService.getTeamDividentsRates(level, bossList);
        List<UserTeamRate> rateList = orderHongBaoMoneyComputeService.getTeamDividentsRates(level, bossList,
                placeOrderTime);
        if (rateList != null)
            for (UserTeamRate rate : rateList) {
                BigDecimal money = MoneyBigDecimalUtil.div(rate.getRate().multiply(order.getMoney()),
@@ -100,7 +104,7 @@
                }
            }
        // 计算二级外分红比例
        rateList = orderHongBaoMoneyComputeService.getTeamRewardMoreThan2LevelRates(level, bossList);
        rateList = orderHongBaoMoneyComputeService.getTeamRewardMoreThan2LevelRates(level, bossList, placeOrderTime);
        if (rateList != null)
            for (UserTeamRate rate : rateList) {
                BigDecimal money = MoneyBigDecimalUtil.div(rate.getRate().multiply(order.getMoney()),
@@ -133,6 +137,12 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void invalidBySourceUid(Long sourceUid, String beiZhu) {
        // teamDividentsSourceOrderService.invalidOrderByUid(sourceUid, beiZhu);
        teamDividentsSourceOrderUserMapService.invalidOrderBySourceUid(sourceUid, beiZhu);
    }
    /**
     * 订单结算
     * @Title: orderSettle
fanli/src/main/java/com/yeshi/fanli/service/manger/order/TeamSubsidyManager.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/util/Constant.java
@@ -257,7 +257,7 @@
            "4c7b166fecb6d9f53837e993f2214673", "", "");
    // 新的规则生效时间
    public static final long NEW_ORDER_FANLI_RULE_TIME = TimeUtil.convertToTimeTemp("2020-04-18", "yyyy-MM-dd");
    public static final long NEW_ORDER_FANLI_RULE_TIME = TimeUtil.convertToTimeTemp("2020-04-14", "yyyy-MM-dd");
    // 使用奖励券最大金额限制
    public static final BigDecimal REWARD_COUPON_LIMIT_MONEY = new BigDecimal("10");
fanli/src/main/java/com/yeshi/fanli/util/factory/order/dividents/TeamDividentsSourceOrderFactory.java
@@ -13,11 +13,17 @@
public class TeamDividentsSourceOrderFactory {
    public static TeamDividentsSourceOrder create(List<CommonOrder> commonOrderList) {
        BigDecimal money = new BigDecimal(0);
        BigDecimal money = null;
        int orderState = CommonOrderUtil.getState(commonOrderList);
        if (orderState == CommonOrder.STATE_SX)
            return null;
        if (orderState == CommonOrder.STATE_FK) {
            money = CommonOrderUtil.computeEstimate(commonOrderList);
        } else {
            money = CommonOrderUtil.computeIncome(commonOrderList);
        }
        if (money.compareTo(new BigDecimal(0)) <= 0)
            return null;
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/InviteOrderSubsidyMessageListener.java
File was deleted
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/OrderDividentsMessageListener.java
@@ -44,9 +44,6 @@
public class OrderDividentsMessageListener implements MessageListener {
    @Resource
    private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
    @Resource
    private CommonOrderService commonOrderService;
    @Resource
@@ -76,7 +73,7 @@
                // 查询上级红包
                UserForbiddenMQMsg dto = new Gson().fromJson(new String(message.getBody()), UserForbiddenMQMsg.class);
                if (dto != null) {
                    teamDividentsSourceOrderService.invalidOrderByUid(dto.getUid(), "用户被封禁");
                    teamDividentsSourceManager.invalidBySourceUid(dto.getUid(), "用户被封禁");
                    return Action.CommitMessage;
                }
            }
fanli/src/main/resource/rocket/consumer.xml
@@ -2,36 +2,6 @@
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="inviteOrderSubsidyMsgListener"
        class="com.yeshi.fanli.util.rocketmq.consumer.order.InviteOrderSubsidyMessageListener"></bean> <!--Listener 配置 -->
    <!-- Group ID 订阅同一个 Topic,可以创建多个 ConsumerBean -->
    <bean id="inviteOrderSubsidyConsumer" class="com.aliyun.openservices.ons.api.bean.ConsumerBean"
        init-method="start" destroy-method="shutdown">
        <property name="properties"> <!--消费者配置信息 -->
            <props>
                <prop key="AccessKey">${rocketmq.AccessKey}</prop>
                <prop key="SecretKey">${rocketmq.SecretKey}</prop>
                <prop key="GROUP_ID">GID_INVITE_ORDER_SUBSIDY</prop>
                <prop key="NAMESRV_ADDR">${rocketmq.NAMESRV_ADDR}</prop>
                <!--将消费者线程数固定为 50 个 <prop key="ConsumeThreadNums">50</prop> -->
            </props>
        </property>
        <property name="subscriptionTable">
            <map>
                <!-- 订单补贴订阅 -->
                <entry value-ref="inviteOrderSubsidyMsgListener">
                    <key>
                        <bean class="com.aliyun.openservices.ons.api.bean.Subscription">
                            <property name="topic" value="TOPIC_ORDER" />
                            <property name="expression"
                                value="orderStatistic||orderUpdate||teamRewardPreRecieved" /><!--expression
                                即 Tag,可以设置成具体的 Tag,如 taga||tagb||tagc,也可设置成 *。 * 仅代表订阅所有 Tag,不支持通配 -->
                        </bean>
                    </key>
                </entry>
            </map>
        </property>
    </bean>
    <!-- 板栗商城订单消息订阅 -->
    <bean id="banLiShopOrderMessageListener"
@@ -222,13 +192,12 @@
                    <key>
                        <bean class="com.aliyun.openservices.ons.api.bean.Subscription">
                            <property name="topic" value="TOPIC_USER" />
                            <property name="expression"
                                value="userLevelChanged||threeSaleSeparate" />
                            <property name="expression" value="userLevelChanged||threeSaleSeparate" />
                        </bean>
                    </key>
                </entry>
                <!-- 订单到账  订单收货-->
                <!-- 订单到账 订单收货 -->
                <entry value-ref="userVIPMessageListener">
                    <key>
                        <bean class="com.aliyun.openservices.ons.api.bean.Subscription">
@@ -264,7 +233,7 @@
                    <key>
                        <bean class="com.aliyun.openservices.ons.api.bean.Subscription">
                            <property name="topic" value="TOPIC_ORDER" />
                            <property name="expression" value="orderConfirm||taoBaoOrderWeiQuan" />
                            <property name="expression" value="orderStatistic||taoBaoOrderWeiQuan" />
                        </bean>
                    </key>
                </entry>