yujian
2019-12-06 540d17e0d21a252162e9eccf021d223cdb331119
Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div
19个文件已修改
2个文件已添加
1298 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ShareController.java 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserMoneyController.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/S11Controller.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5S11Controller.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/CodePublishRecordMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dto/order/OrderHongBaoRateParams.java 95 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/CommonOrder.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/ShameUserInviteCodePublishJOB.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/integral/CodePublishRecordMapper.xml 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/config/HongBaoManageServiceImpl.java 131 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/CodePublishRecordServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/InviteOrderSubsidyService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/config/HongBaoManageService.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserInfoService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/integral/CodePublishRecordService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/manger/HongBaoV2AddManager.java 885 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ShareController.java
@@ -18,6 +18,7 @@
import org.yeshi.utils.taobao.TbImgUtil;
import com.fasterxml.jackson.core.util.VersionUtil;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.controller.client.v2.ShareControllerV2;
import com.yeshi.fanli.dto.share.ShareGoodsRecordDTO;
import com.yeshi.fanli.entity.accept.AcceptData;
@@ -512,7 +513,8 @@
            }
            data.put("count", count);
            data.put("result_list", list);
            data.put("result_list",
                    JsonUtil.getConvertBigDecimalToStringBuilder(new GsonBuilder()).create().toJson(list));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
@@ -1079,30 +1081,28 @@
                        data.put("clickUrl", ShareControllerV2.getERCodeContent(goods, taoBaoLink.getTaoToken()));
                    data.put("token", TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
                    String inviteCode=null;
                    UserInfoExtra extra=    userInfoExtraService.getUserInfoExtra(uid);
                    if(extra!=null)
                        inviteCode=extra.getInviteCode();
                    String inviteCode = null;
                    UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(uid);
                    if (extra != null)
                        inviteCode = extra.getInviteCode();
                    // 测试
                    List<String> commentTexts = new ArrayList<>();
                    String  commentTextStr=     configService.get("share_single_goods_comment_text");
                    if(!StringUtil.isNullOrEmpty(commentTextStr))
                    {
                        JSONArray arr=    JSONArray.fromObject(commentTextStr);
                        for(int i=0;i<arr.size();i++)
                        {
                            if(StringUtil.isNullOrEmpty(inviteCode))
                            {
                                if(arr.optString(i).contains("[邀请码]"))
                                {
                    String commentTextStr = configService.get("share_single_goods_comment_text");
                    if (!StringUtil.isNullOrEmpty(commentTextStr)) {
                        JSONArray arr = JSONArray.fromObject(commentTextStr);
                        for (int i = 0; i < arr.size(); i++) {
                            if (StringUtil.isNullOrEmpty(inviteCode)) {
                                if (arr.optString(i).contains("[邀请码]")) {
                                    continue;
                                }
                            }
                            if(StringUtil.isNullOrEmpty(inviteCode))
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK).replace("[淘口令]", data.optString("token")));
                            if (StringUtil.isNullOrEmpty(inviteCode))
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK)
                                        .replace("[淘口令]", data.optString("token")));
                            else
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK).replace("[邀请码]", inviteCode).replace("[淘口令]", data.optString("token")));
                                commentTexts.add(arr.optString(i).replace("[下载链接]", Constant.YINGYONGBAO_LINK)
                                        .replace("[邀请码]", inviteCode).replace("[淘口令]", data.optString("token")));
                        }
                    }
                    data.put("commentTexts", commentTexts);
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/UserMoneyController.java
@@ -4,6 +4,7 @@
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -35,6 +36,7 @@
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.VersionUtil;
@@ -110,7 +112,8 @@
            date = new Date(ca.getTimeInMillis() - 1);
        }
        List<UserMoneyDetailHistoryVO> list = userMoneyDetailService.listUserMoneyDetailForClient(uid, index, type, date);
        List<UserMoneyDetailHistoryVO> list = userMoneyDetailService.listUserMoneyDetailForClient(uid, index, type,
                date);
        long count = userMoneyDetailService.countUserMoneyDetailForClient(uid, index, type, date);
        GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
        gsonBuilder.registerTypeAdapter(UserMoneyDetailTypeEnum.class, new TypeAdapter<UserMoneyDetailTypeEnum>() {
@@ -311,7 +314,7 @@
            // 获取提现中的信息
            BigDecimal extractingMoney = extractService.sumVerifyingMoney(uid);
            if (extractingMoney.compareTo(new BigDecimal(0)) > 0)
                vo.setExtractingMoneyInfo("提现中:¥" + extractingMoney.setScale(2));
                vo.setExtractingMoneyInfo("提现中:¥" + extractingMoney.setScale(2, RoundingMode.HALF_UP));
            // 获取是否绑定了微信
            if (!StringUtil.isNullOrEmpty(user.getWxUnionId())) {
                vo.setBindingWX(true);
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/IntegralControllerV2.java
@@ -540,7 +540,7 @@
        }
        try {
            List<CodePublishRecord> list = codePublishRecordService.listValid((page - 1) * Constant.PAGE_SIZE,
            List<CodePublishRecord> list = codePublishRecordService.listValid(null, (page - 1) * Constant.PAGE_SIZE,
                    Constant.PAGE_SIZE);
            if (list == null) {
                list = new ArrayList<CodePublishRecord>();
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/S11Controller.java
@@ -60,7 +60,7 @@
        String token = redisManager.getCommonString(key);
        if (StringUtil.isNullOrEmpty(token)) {
            try {
                String link = TaoKeApiUtil.officialActivityConvert("19507100253", "1574664919372",
                String link = TaoKeApiUtil.officialActivityConvert("19507100253", "1574926757600",
                        info.getRelationId());
                if (!StringUtil.isNullOrEmpty(link)) {
                    token = TaoKeApiUtil.getTKToken("http://img.flqapp.com/resource/s12/banner.jpg", "【天猫双12】上亿红包等你来拆!---板栗快省", link);
fanli/src/main/java/com/yeshi/fanli/controller/h5/H5S11Controller.java
@@ -61,11 +61,11 @@
        token = redisManager.getCommonString(key);
        if (StringUtil.isNullOrEmpty(token)) {
            try {
                String link = TaoKeApiUtil.officialActivityConvert("19507100253", "1539329391766",
                String link = TaoKeApiUtil.officialActivityConvert("19507100253", "1574926757600",
                        info.getRelationId());
                if (!StringUtil.isNullOrEmpty(link)) {
                    token = TaoKeApiUtil.getTKToken("http://img.flqapp.com/resource/s11/banner.jpg",
                            "【天猫双11】上亿红包等你来拆!", link);
                            "【天猫双12】上亿红包等你来拆!", link);
                    if (!StringUtil.isNullOrEmpty(token))
                        redisManager.cacheCommonString(key, token, 60 * 60 * 24);// 缓存1天
                }
@@ -113,7 +113,7 @@
            token = redisManager.getCommonString(key);
        if (StringUtil.isNullOrEmpty(token)) {
            try {
                String link = TaoKeApiUtil.officialActivityConvert("19507100253", "1539329391766",
                String link = TaoKeApiUtil.officialActivityConvert("19507100253", "1574926757600",
                        info.getRelationId());
                if (!StringUtil.isNullOrEmpty(link)) {
                    token = TaoKeApiUtil.getTKToken("http://img.flqapp.com/resource/s11/banner.jpg",
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/integral/CodePublishRecordMapper.java
@@ -15,7 +15,7 @@
     * 
     * @return
     */
    List<CodePublishRecord> listValid(@Param("start") long start, @Param("count") int count,
    List<CodePublishRecord> listValid(@Param("uid") Long uid, @Param("start") long start, @Param("count") int count,
            @Param("validTime") long validTime);
    /**
fanli/src/main/java/com/yeshi/fanli/dto/order/OrderHongBaoRateParams.java
New file
@@ -0,0 +1,95 @@
package com.yeshi.fanli.dto.order;
import java.util.Date;
public class OrderHongBaoRateParams {
    private int level;// 0-产生订单本级 1-产生订单的上级 2-产生订单的上上级
    private int orderType;// 订单类型 分享/自购
    private boolean subsidy;// 是否为补贴
    private boolean vip;// 是否为vip
    private Boolean lastVIP;// 上级是否为VIP
    private Boolean superLastVIP;// 上上级是否为vip
    private Date orderCreateTime;// 订单创建时间
    // public RateParams(int level, int orderType, boolean subsidy, boolean
    // vip, Boolean lastVIP, Boolean superLastVIP,
    // Date orderCreateTime) {
    // this.level = level;
    // this.orderType = orderType;
    // this.subsidy = subsidy;
    // this.vip = vip;
    // this.lastVIP = lastVIP;
    // this.superLastVIP = superLastVIP;
    // this.orderCreateTime = orderCreateTime;
    // }
    public OrderHongBaoRateParams(int level, int orderType, boolean subsidy, boolean vip, Date orderCreateTime) {
        this.level = level;
        this.orderType = orderType;
        this.subsidy = subsidy;
        this.vip = vip;
        this.orderCreateTime = orderCreateTime;
    }
    public OrderHongBaoRateParams() {
    }
    public Date getOrderCreateTime() {
        return orderCreateTime;
    }
    public void setOrderCreateTime(Date orderCreateTime) {
        this.orderCreateTime = orderCreateTime;
    }
    public int getLevel() {
        return level;
    }
    public void setLevel(int level) {
        this.level = level;
    }
    public int getOrderType() {
        return orderType;
    }
    public void setOrderType(int orderType) {
        this.orderType = orderType;
    }
    public boolean isSubsidy() {
        return subsidy;
    }
    public void setSubsidy(boolean subsidy) {
        this.subsidy = subsidy;
    }
    public boolean isVip() {
        return vip;
    }
    public void setVip(boolean vip) {
        this.vip = vip;
    }
    public Boolean isLastVIP() {
        return lastVIP;
    }
    public void setLastVIP(Boolean lastVIP) {
        this.lastVIP = lastVIP;
    }
    public Boolean isSuperLastVIP() {
        return superLastVIP;
    }
    public void setSuperLastVIP(Boolean superLastVIP) {
        this.superLastVIP = superLastVIP;
    }
}
fanli/src/main/java/com/yeshi/fanli/entity/order/CommonOrder.java
@@ -36,6 +36,9 @@
    public final static String TYPE_INVITE = "http://ec-1255749512.file.myqcloud.com/resource/order/icon_invite.png";
    public final static String TYPE_SHARE = "http://ec-1255749512.file.myqcloud.com/resource/order/icon_share.png";
    public final static int ORDER_TYPE_ZIGOU = 1;// 自购
    public final static int ORDER_TYPE_SHARE = 20;// 分享
    @Column(name = "co_id")
    private Long id;
@@ -105,7 +108,7 @@
    @Column(name = "co_trade_id")
    private String tradeId;
    // 状态说明
    @Column(name = "co_state_desc")
    private String stateDesc;
fanli/src/main/java/com/yeshi/fanli/job/ShameUserInviteCodePublishJOB.java
@@ -70,6 +70,9 @@
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 查询用户是否近3天内发布过
            if (codePublishRecordService.listValid(userList.get(0).getId(), 0, 1).size() > 0)
                return;
            if (userList != null && userList.size() > 0) {
                codePublishRecordService.publishInviteCode(userList.get(0).getId());
            }
fanli/src/main/java/com/yeshi/fanli/mapping/integral/CodePublishRecordMapper.xml
@@ -67,17 +67,24 @@
    <select id="listValid" resultMap="BaseResultVOMap">
        SELECT p.*,u.`nick_name`,u.`portrait`,e.`uie_invite_code` FROM
        yeshi_ec_code_publish_record p
        LEFT JOIN `yeshi_ec_user` u ON u.`id` = p.`pr_uid`
        LEFT JOIN `yeshi_ec_user_info_extra` e ON e.`uie_uid` = p.`pr_uid`
        LEFT JOIN `yeshi_ec_user` u ON u.`id` =
        p.`pr_uid`
        LEFT JOIN `yeshi_ec_user_info_extra` e ON e.`uie_uid` =
        p.`pr_uid`
        WHERE TIMESTAMPDIFF(SECOND,p.`pr_create_time`,NOW())<![CDATA[<]]>
        #{validTime}
        <if test="uid!=null">
            and pr_uid=#{uid}
        </if>
        ORDER BY p.`pr_create_time` DESC
        LIMIT #{start},#{count}
    </select>
    <select id="listByMinTime" resultMap="BaseResultMap">
        SELECT * FROM yeshi_ec_code_publish_record p where p.`pr_create_time` >=
        SELECT * FROM
        yeshi_ec_code_publish_record p where p.`pr_create_time` >=
        #{minTime}
        ORDER BY p.`pr_create_time` DESC
        LIMIT #{start},#{count}
@@ -85,13 +92,15 @@
    <select id="countValid" resultType="Long">
        SELECT IFNULL(COUNT(pr_id),0) FROM yeshi_ec_code_publish_record
        WHERE TIMESTAMPDIFF(SECOND,`pr_create_time`,NOW())<![CDATA[<]]>
        WHERE
        TIMESTAMPDIFF(SECOND,`pr_create_time`,NOW())<![CDATA[<]]>
        #{validTime}
    </select>
    <select id="countValidRecord" resultType="Long">
        SELECT IFNULL(COUNT(pr_id),0) FROM yeshi_ec_code_publish_record
        WHERE pr_uid = #{uid} AND TIMESTAMPDIFF(SECOND,`pr_create_time`,NOW())<![CDATA[<]]>
        WHERE
        pr_uid = #{uid} AND TIMESTAMPDIFF(SECOND,`pr_create_time`,NOW())<![CDATA[<]]>
        #{validTime}
    </select>
fanli/src/main/java/com/yeshi/fanli/service/impl/order/HongBaoV2ServiceImpl.java
@@ -52,6 +52,7 @@
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
fanli/src/main/java/com/yeshi/fanli/service/impl/order/InviteOrderSubsidyServiceImpl.java
@@ -25,6 +25,7 @@
import com.yeshi.fanli.service.inter.order.OrderHongBaoMapService;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
@@ -50,6 +51,9 @@
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private UserVIPInfoService userVIPInfoService;
    @Override
    public InviteOrderSubsidy getByOrderNoAndType(Long uid, String orderNo, Integer type) {
        return inviteOrderSubsidyMapper.getByOrderNoAndType(uid, orderNo, type);
@@ -61,9 +65,8 @@
    }
    @Transactional
    @Override
    public void addOrderSubsidy(InviteOrderSubsidy orderSubsidy) throws InviteOrderSubsidyException {
        // 机制2020年生效
    private void addOrderSubsidy(InviteOrderSubsidy orderSubsidy) throws InviteOrderSubsidyException {
        //TODO 确定生效日期  机制2020年生效
        if (System.currentTimeMillis() < TimeUtil.convertToTimeTemp("2020-01-01", "yyyy-MM-dd")) {
            return;
        }
@@ -165,7 +168,9 @@
                            orderSubsidy.setOrderNo(orderId);
                            orderSubsidy.setSourceType(sourceType);
                            orderSubsidy.setState(state);
                            addOrderSubsidy(orderSubsidy);
                            // VIP用户才能补贴
                            if (userVIPInfoService.isVIP(uid))
                                addOrderSubsidy(orderSubsidy);
                        }
                    }
                }
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -77,6 +77,7 @@
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.manger.HongBaoV2AddManager;
import com.yeshi.fanli.util.CMQManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
@@ -158,6 +159,9 @@
    @Resource
    private OrderMoneySettleService orderMoneySettleService;
    @Resource
    private HongBaoV2AddManager hongBaoV2AddManager;
    /**
     * 是否是分享订单
@@ -1209,7 +1213,14 @@
        final List<CommonOrder> coList = convertCommonOrder(commonOrderList);
        int resultCode = 0;
        try {
            resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType);
            long time = TimeUtil.convertToTimeTemp("2019-12-06", "yyyy-MM-dd");
            if (!Constant.IS_TEST)
                time = TimeUtil.convertToTimeTemp("2020-01-01", "yyyy-MM-dd");
            if (coList.get(0).getThirdCreateTime().getTime() < time)
                resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType);
            else
                resultCode = hongBaoV2AddManager.addHongBao(coList, hongBaoType);
        } catch (HongBaoException e) {
            try {
                LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + orderId);
fanli/src/main/java/com/yeshi/fanli/service/impl/order/config/HongBaoManageServiceImpl.java
@@ -12,7 +12,10 @@
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.HongBaoManageMapper;
import com.yeshi.fanli.dto.order.OrderHongBaoRateParams;
import com.yeshi.fanli.entity.bus.user.HongBaoManage;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
@@ -34,6 +37,24 @@
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            hongBaoManage.getValue();
        return null;
    }
    /**
     * 根据键值与时间查询比例
     *
     * @param key
     * @param time
     * @return
     */
    public BigDecimal getByKeyAndMaxTime(String key, Long time) {
        if (time == null)
            time = System.currentTimeMillis();
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        return null;
    }
@@ -211,4 +232,114 @@
        return new BigDecimal(0);
    }
    @Override
    public BigDecimal getVIPFanLiRate(long time) {
        String key = "hongbao_goods_proportion_vip";
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return null;
    }
    @Override
    public BigDecimal getVIPShareRate(long time) {
        String key = "share_proportion_vip";
        HongBaoManage hongBaoManage = hongBaoManageMapper.selectByKeyAndMaxValidTime(key, time);
        if (hongBaoManage == null)
            hongBaoManage = hongBaoManageMapper.selectByKey(key);
        if (hongBaoManage != null)
            return new BigDecimal(hongBaoManage.getValue());
        LogHelper.error("获取返利分成比例出错");
        return null;
    }
    @Override
    public BigDecimal getVIPFanLiRate() {
        return getVIPFanLiRate(System.currentTimeMillis());
    }
    @Override
    public BigDecimal getVIPShareRate() {
        return getVIPShareRate(System.currentTimeMillis());
    }
    /**
     * 获取比例
     *
     * @param level
     *            0-本级 1-下级 2-下下级
     * @param orderType
     * @param isVip本级是否为VIP
     * @param isWorkerVip下级是否为VIP
     * @return
     */
    public BigDecimal getRate(OrderHongBaoRateParams params) throws HongBaoException {
        if (params == null)
            throw new HongBaoException(1, "比例参数错误");
        long time = params.getOrderCreateTime().getTime();
        if (params.getLevel() == 0) {// 本级
            if (params.getOrderType() == CommonOrder.ORDER_TYPE_ZIGOU) {
                if (params.isVip())
                    return getVIPFanLiRate(time);
                else
                    return getFanLiRate(time);
            } else {
                if (params.isVip())
                    return getVIPShareRate(time);
                else
                    return getShareRate(time);
            }
        } else if (params.getLevel() == 1) {// 上级
            if (params.getOrderType() == CommonOrder.ORDER_TYPE_ZIGOU) {// 自购
                if (params.isSubsidy()) {// 补贴比例
                    if (params.isVip()) {// 下级为会员不补贴
                        return new BigDecimal("0");
                    } else {
                        return getInviteFirstLevelSubsidyRate(time);
                    }
                } else {// 奖金比例
                    if (params.isVip()) {
                        return getByKeyAndMaxTime("new_invite_vip_6", time);
                    } else {
                        return getByKeyAndMaxTime("new_invite_6", time);
                    }
                }
            } else {// 分享
                if (params.isVip()) {
                    return getByKeyAndMaxTime("new_share_vip_21", time);
                } else {
                    return getByKeyAndMaxTime("new_share_21", time);
                }
            }
        } else if (params.getLevel() == 2) {// 上上级
            if (params.getOrderType() == CommonOrder.ORDER_TYPE_ZIGOU) {// 自购
                if (params.isSubsidy()) {// 补贴比例
                    if (params.isVip()) {// 下下级为会员不补贴
                        return new BigDecimal("0");
                    } else {
                        return getInviteSecondLevelSubsidyRate(time);
                    }
                } else {// 奖金比例
                    if (params.isVip())
                        return new BigDecimal("0");
                    else
                        return getByKeyAndMaxTime("new_invite_7", time);
                }
            } else {// 分享
                if (params.isVip())
                    return new BigDecimal("0");
                else
                    return getByKeyAndMaxTime("new_share_22", time);
            }
        }
        throw new HongBaoException(2, "未匹配到比例参数");
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java
@@ -671,4 +671,9 @@
        return userInfoMapper.getAutoExtractUserTo1212(start, count);
    }
    @Override
    public UserInfo selectAvailableByPrimaryKey(Long uid) {
        return userInfoMapper.selectAvailableByPrimaryKey(uid);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/CodePublishRecordServiceImpl.java
@@ -46,9 +46,9 @@
    }
    @Override
    public List<CodePublishRecord> listValid(long start, int count) {
    public List<CodePublishRecord> listValid(Long uid, long start, int count) {
        List<CodePublishRecord> listValid = codePublishRecordMapper.listValid(start, count,
        List<CodePublishRecord> listValid = codePublishRecordMapper.listValid(uid, start, count,
                CodePublishRecord.VALIDTIME);
        if (listValid == null || listValid.size() == 0) {
            return listValid;
fanli/src/main/java/com/yeshi/fanli/service/inter/order/InviteOrderSubsidyService.java
@@ -27,14 +27,6 @@
    public InviteOrderSubsidy getByOrderNoAndTypeForUpdate(Long uid, String orderNo, Integer type);
    
    
    /**
     * 添加订单补贴
     *
     * @param orderSubsidy
     * @throws OrderSubsidyException
     */
    public void addOrderSubsidy(InviteOrderSubsidy orderSubsidy) throws InviteOrderSubsidyException;
    /**
     * 添加或修改(按照订单号与来源)
fanli/src/main/java/com/yeshi/fanli/service/inter/order/config/HongBaoManageService.java
@@ -6,7 +6,9 @@
import org.springframework.cache.annotation.CacheEvict;
import com.yeshi.fanli.dto.order.OrderHongBaoRateParams;
import com.yeshi.fanli.entity.bus.user.HongBaoManage;
import com.yeshi.fanli.exception.order.HongBaoException;
public interface HongBaoManageService {
@@ -26,12 +28,28 @@
    public BigDecimal getFanLiRate(long time);
    /**
     * VIP用户返利比例
     *
     * @param time
     * @return
     */
    public BigDecimal getVIPFanLiRate(long time);
    /**
     * 获取分享订单返利比例
     * 
     * @param time
     * @return
     */
    public BigDecimal getShareRate(long time);
    /**
     * 获取VIP用户的分享比例
     *
     * @param time
     * @return
     */
    public BigDecimal getVIPShareRate(long time);
    /**
     * 获取返利订单返利比例
@@ -46,6 +64,20 @@
     * @return
     */
    public BigDecimal getShareRate();
    /**
     * 获取VIP返利订单返利比例
     *
     * @return
     */
    public BigDecimal getVIPFanLiRate();
    /**
     * 获取VIP分享订单返利比例
     *
     * @return
     */
    public BigDecimal getVIPShareRate();
    /**
     * 获取第一级的邀请赚比例
@@ -128,13 +160,22 @@
     * @return
     */
    public BigDecimal getInviteFirstLevelSubsidyRate(Long time);
    /**
     * 获取邀请二级补贴比例
     *
     * @param time
     * @return
     */
    public BigDecimal getInviteSecondLevelSubsidyRate(Long time);
    /**
     * 获取返利比例(订单处理时使用)
     *
     * @param params
     * @return
     * @throws HongBaoException
     */
    public BigDecimal getRate(OrderHongBaoRateParams params) throws HongBaoException;
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserInfoService.java
@@ -209,11 +209,21 @@
    public long countByType(int type);
    /**
     * 双12预售开启时,开启对休眠老用户的唤醒工作,在2019.1.1到2019.6.18期间产生过订单,并且2019.6.18号后未再活跃,并且账户余额大于1元,并且绑定了微信的用户有2468人
     * 双12预售开启时,开启对休眠老用户的唤醒工作,在2019.1.1到2019.6.18期间产生过订单,并且2019.6.18号后未再活跃,
     * 并且账户余额大于1元,并且绑定了微信的用户有2468人
     *
     * @param start
     * @param count
     * @return
     */
    public List<UserInfo> getAutoExtractUserTo1212(int start, int count);
    /**
     * 根据用户ID检索
     *
     * @param uid
     * @return
     */
    public UserInfo selectAvailableByPrimaryKey(Long uid);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/integral/CodePublishRecordService.java
@@ -12,7 +12,7 @@
     * 
     * @return
     */
    public List<CodePublishRecord> listValid(long start, int count);
    public List<CodePublishRecord> listValid(Long uid, long start, int count);
    /**
     * 根据最小时间查询
fanli/src/main/java/com/yeshi/fanli/service/manger/HongBaoV2AddManager.java
New file
@@ -0,0 +1,885 @@
package com.yeshi.fanli.service.manger;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper;
import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.order.OrderHongBaoRateParams;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.exception.user.UserAccountException;
import com.yeshi.fanli.exception.user.UserInfoException;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
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.UserVIPInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.TimeUtil;
@Component
public class HongBaoV2AddManager {
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
    @Resource
    private HongBaoOrderMapper hongBaoOrderMapper;
    @Resource
    private HongBaoV2Mapper hongBaoV2Mapper;
    @Resource
    private UserOrderMsgNotificationService userOrderMsgNotificationService;
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private CommonOrderService commonOrderService;
    @Resource
    private UserSystemCouponRecordService userSystemCouponRecordService;
    @Resource
    private UserSystemCouponService userSystemCouponService;
    @Resource
    private CommonOrderGoodsMapper commonOrderGoodsMapper;
    @Resource
    private UserVIPInfoService userVIPInfoService;
    // 保存红包
    public void saveHongBao1(CommonOrder commonOrder, int commonOrderType) throws HongBaoException, UserInfoException {
        // 查询上2级的信息
        long uid = commonOrder.getUserInfo().getId();
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
        if (user == null)
            throw new UserInfoException(1, "用户不存在");
        UserInfo lastUser = threeSaleSerivce.getBoss(uid);
        UserInfo superLastUser = null;
        if (lastUser != null) {
            lastUser = userInfoService.selectAvailableByPrimaryKey(lastUser.getId());
            if (lastUser != null)
                superLastUser = threeSaleSerivce.getBoss(lastUser.getId());
            if (superLastUser != null)
                superLastUser = userInfoService.selectAvailableByPrimaryKey(superLastUser.getId());
        }
        if (commonOrderType == CommonOrder.ORDER_TYPE_ZIGOU) {
            // 保存红包信息
        } else if (commonOrderType == CommonOrder.ORDER_TYPE_SHARE) {
        }
    }
    /**
     * 添加红包信息
     *
     * @param commonOrderList
     * @param type
     * @return
     * @throws HongBaoException
     * @throws UserAccountException
     */
    public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException {
        if (commonOrderList != null && commonOrderList.size() > 0) {
            int orderType = commonOrderList.get(0).getSourceType();
            Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
            int goodsCount = 0;
            boolean hasAdd = false;
            boolean hasUpdate = false;
            Set<Integer> stateSet = new HashSet<>();// 订单状态Set
            boolean isVIP = userVIPInfoService.isVIP(commonOrderList.get(0).getUserInfo().getId());
            for (CommonOrder commonOrder : commonOrderList) {
                stateSet.add(commonOrder.getState());
                goodsCount += commonOrder.getCount();
                if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null)
                    throw new HongBaoException(1, "订单信息不完整");
                HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
                if (hongBaoOrder == null) {
                    saveHongBao(commonOrder, type, isVIP, notificationMap);
                    hasAdd = true;
                } else {
                    boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
                    if (update)
                        hasUpdate = true;
                }
            }
            /**
             * 通知用户的返利情况
             */
            int state = getOrderState(stateSet);
            if (!Constant.IS_TEST) {
                if (hasAdd) {
                    Iterator<Integer> its = notificationMap.keySet().iterator();
                    while (its.hasNext()) {
                        Integer t = its.next();
                        HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
                        CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
                        String orderId = commonOrderList.get(0).getOrderNo();
                        Long uid = notify.getUserInfo().getId();
                        BigDecimal money = notify.getMoney();
                        switch (t) {
                        case HongBaoV2.TYPE_ZIGOU:
                            userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, state);
                            break;
                        case HongBaoV2.TYPE_SHARE_GOODS:
                            userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, state);
                            break;
                        case HongBaoV2.TYPE_YIJI:
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, state);
                            break;
                        case HongBaoV2.TYPE_ERJI:
                            userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, state);
                            break;
                        case HongBaoV2.TYPE_SHARE_YIJI:
                            userOrderMsgNotificationService.orderShareFirstLevelStatistic(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, goodsCount, state, notify.getBeizhu());
                            break;
                        }
                    }
                }
                // 添加新版本通知
                if (!hasAdd) {
                    Iterator<Integer> its = notificationMap.keySet().iterator();
                    while (its.hasNext()) {
                        Integer t = its.next();
                        HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
                        CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
                        String orderId = commonOrderList.get(0).getOrderNo();
                        Long uid = notify.getUserInfo().getId();
                        BigDecimal money = notify.getMoney();
                        switch (t) {
                        case HongBaoV2.TYPE_ZIGOU:
                            userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, state);
                            break;
                        case HongBaoV2.TYPE_SHARE_GOODS:
                            userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, state);
                            break;
                        case HongBaoV2.TYPE_YIJI:
                            userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, state);
                            break;
                        case HongBaoV2.TYPE_ERJI:
                            userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, state);
                            break;
                        case HongBaoV2.TYPE_SHARE_YIJI:
                            userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId, orderType,
                                    commonOrder.getPayment(), money, state);
                        }
                    }
                }
            }
            int resultCode = 0;
            if (hasAdd && hasUpdate)
                return 12;
            else if (hasAdd)
                return 1;
            else if (hasUpdate)
                return 2;
            return resultCode;
        }
        return 0;
    }
    private int getOrderState(Set<Integer> states) {
        if (states.size() == 1)
            return states.iterator().next();
        Iterator<Integer> its = states.iterator();
        while (its.hasNext()) {
            int tempState = its.next();
            if (tempState == CommonOrder.STATE_FK)
                return CommonOrder.STATE_FK;
            else if (tempState == CommonOrder.STATE_JS)
                return CommonOrder.STATE_JS;
        }
        return CommonOrder.STATE_SX;
    }
    @Transactional
    private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
            Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException, UserAccountException {
        System.out.println(commonOrder.getOrderNo());
        // 锁行
        HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBaoOrder.getHongBaoV2().getId());
        if (oldHongBao == null)
            throw new HongBaoException(10, "红包对象不存在");
        // 已经失效,已经领取,新老状态一致的红包不做处理
        if (oldHongBao.getState() == HongBaoV2.STATE_SHIXIAO || oldHongBao.getState() == HongBaoV2.STATE_YILINGQU)
            return false;
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
            BigDecimal fanliRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(0, type, false,
                    oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
            // 免单处理
            boolean mianDan = false;
            List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
                    commonOrder.getOrderNo());
            if (orderList != null && orderList.size() == 1) {// 只有1个订单才参与免单
                BigDecimal payMent = commonOrder.getPayment();
                if (commonOrder.getState() == CommonOrder.STATE_JS)
                    payMent = commonOrder.getSettlement();
                if (payMent.compareTo(new BigDecimal(10)) < 0) {
                    mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getSourceType(),
                            commonOrder.getOrderNo());
                }
            }
            HongBaoV2 hongBao = createFanLiUpdateHongBao(commonOrder, fanliRate, hongBaoOrder.getHongBaoV2().getId(),
                    mianDan);
            // 新老红包状态一致不处理
            if (oldHongBao.getState().intValue() == hongBao.getState())
                return false;
            if (hongBao.getState() == HongBaoV2.STATE_SHIXIAO) {
                if (mianDan) {
                    try {
                        userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
                    } catch (Exception e) {
                        e.printStackTrace();
                        throw new HongBaoException(12, "免单券退款出错");
                    }
                }
            }
            hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
            // 加入通知
            if (notificationMap.get(type) == null) {
                HongBaoV2 tempHongBao = new HongBaoV2(oldHongBao.getId());
                tempHongBao.setUserInfo(oldHongBao.getUserInfo());
                tempHongBao.setMoney(hongBao.getMoney());
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
                HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
                tempHongBaoOrder.getCommonOrder()
                        .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
                notificationMap.put(type, tempHongBaoOrder);
            }
            // 获取子红包
            List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
            if (children != null && children.size() > 0) {
                for (HongBaoV2 child : children) {
                    if (child.getState() == HongBaoV2.STATE_YILINGQU)
                        continue;
                    BigDecimal rate = null;
                    if (child.getType() == HongBaoV2.TYPE_YIJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                    } else if (child.getType() == HongBaoV2.TYPE_ERJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                    }
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(),
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))), commonOrder);
                    hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
                    // 加入通知
                    if (notificationMap.get(child.getType()) == null) {
                        HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
                        tempHongBao.setUserInfo(child.getUserInfo());
                        tempHongBao.setMoney(child.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
                    } else {
                        // 增加付款金额与资金
                        HongBaoOrder tempHongBaoOrder = notificationMap.get(child.getType());
                        tempHongBaoOrder.getCommonOrder().setPayment(
                                tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                        tempHongBaoOrder.getHongBaoV2()
                                .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney()));
                        notificationMap.put(child.getType(), tempHongBaoOrder);
                    }
                }
            } else {// 修复之前二级,三级订单未统计到的情况
                if (!mianDan) {
                    ThreeSale threeSale = threeSaleSerivce.selectByWorkerId(commonOrder.getUserInfo().getId());
                    if (threeSale != null && threeSale.getSucceedTime() != null
                            && threeSale.getSucceedTime() <= commonOrder.getThirdCreateTime().getTime()) {
                        UserInfo boss = threeSaleSerivce.getBoss(commonOrder.getUserInfo().getId());
                        if (boss != null) {
                            boss = userInfoService.selectAvailableByPrimaryKey(boss.getId());
                        }
                        if (boss != null) {
                            // 插入一级子红包
                            BigDecimal firstRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, type,
                                    false, oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                            if (firstRate != null && firstRate.compareTo(new BigDecimal(0)) > 0) {
                                HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder,
                                        HongBaoV2.TYPE_YIJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                                                firstRate.divide(new BigDecimal(100))));
                                if (firstHongbao != null)
                                    addInviteHongBao(firstHongbao, notificationMap, commonOrder);
                            }
                            boss = threeSaleSerivce.getBoss(boss.getId());
                            if (boss != null) {
                                boss = userInfoService.selectAvailableByPrimaryKey(boss.getId());
                            }
                            if (boss != null) {
                                // 二级红包
                                BigDecimal secondRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, type,
                                        false, oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                                if (secondRate != null && secondRate.compareTo(new BigDecimal(0)) > 0) {
                                    HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), oldHongBao, commonOrder,
                                            HongBaoV2.TYPE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                                                    secondRate.divide(new BigDecimal(100))));
                                    if (secondHongbao != null)
                                        addInviteHongBao(secondHongbao, notificationMap, commonOrder);
                                }
                            }
                        }
                    }
                }
            }
        } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
            BigDecimal fanliRate = hongBaoManageService.getRate(new OrderHongBaoRateParams(0, type, false,
                    oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
            HongBaoV2 hongBao = createShareUpdateHongBao(commonOrder, fanliRate, oldHongBao.getId());
            hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
            // 通知
            if (notificationMap.get(type) == null) {
                HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
                tempHongBao.setUserInfo(hongBaoOrder.getHongBaoV2().getUserInfo());
                tempHongBao.setMoney(hongBao.getMoney());
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
                HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
                tempHongBaoOrder.getCommonOrder()
                        .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
                notificationMap.put(type, tempHongBaoOrder);
            }
            // 获取子红包
            List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
            if (children != null)
                for (HongBaoV2 child : children) {
                    if (child.getState() == HongBaoV2.STATE_YILINGQU)
                        continue;
                    BigDecimal rate = null;
                    if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(1, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                    } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) {
                        rate = hongBaoManageService.getRate(new OrderHongBaoRateParams(2, oldHongBao.getType(), false,
                                oldHongBao.getUrank() == 100, commonOrder.getThirdCreateTime()));
                    }
                    HongBaoV2 childUpdate = createInviteUpdateHongBao(child, hongBao.getState(),
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))), commonOrder);
                    hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
                    // 添加通知
                    if (notificationMap.get(child.getType()) == null) {
                        HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
                        tempHongBao.setUserInfo(child.getUserInfo());
                        tempHongBao
                                .setMoney(childUpdate.getMoney() == null ? new BigDecimal(0) : childUpdate.getMoney());
                        CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                        tempCommonOrder.setPayment(commonOrder.getPayment());
                        notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
                    } else {
                        // 增加付款金额与资金
                        HongBaoOrder tempHongBaoOrder = notificationMap.get(child.getType());
                        if (commonOrder.getPayment() != null)
                            tempHongBaoOrder.getCommonOrder().setPayment(
                                    tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                        if (childUpdate.getMoney() != null)
                            tempHongBaoOrder.getHongBaoV2()
                                    .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(childUpdate.getMoney()));
                        notificationMap.put(child.getType(), tempHongBaoOrder);
                    }
                }
        } else
            throw new HongBaoException(2, "type错误");
        return true;
    }
    @Transactional
    private void saveHongBao(CommonOrder commonOrder, int type, boolean vip, Map<Integer, HongBaoOrder> notificationMap)
            throws HongBaoException, UserAccountException {
        if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
            BigDecimal fanliRate = hongBaoManageService
                    .getRate(new OrderHongBaoRateParams(0, type, false, vip, commonOrder.getThirdCreateTime()));
            // 查询是否有免单计划
            BigDecimal mianDanMoney = null;
            if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
                List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(commonOrder.getSourceType(),
                        commonOrder.getOrderNo());
                if (orderList != null && orderList.size() == 1) {// 只有1个订单才参与免单
                    BigDecimal payMent = commonOrder.getPayment();
                    if (commonOrder.getState() == CommonOrder.STATE_JS)
                        payMent = commonOrder.getSettlement();
                    CommonOrderGoods goods = commonOrderGoodsMapper
                            .selectByPrimaryKey(commonOrder.getCommonOrderGoods().getId());
                    if (goods != null) {
                        try {
                            if (userSystemCouponService.updateCouponRecordUsed(commonOrder.getUserInfo().getId(),
                                    commonOrder.getOrderNo(), payMent, Long.parseLong(goods.getGoodsId())))
                                mianDanMoney = payMent;
                        } catch (NumberFormatException e) {
                            throw new HongBaoException(10, "免单商品处理出错");
                        } catch (Exception e) {
                            e.printStackTrace();
                            throw new HongBaoException(11, "免单商品处理出错");
                        }
                    }
                }
            } else if (commonOrder.getState() == CommonOrder.STATE_SX) {// 设置免单券失效
                commonOrder.setPayment(new BigDecimal(0));// 订单失效后的付款金额设置为0
                try {
                    userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            HongBaoV2 hongBao = createFanLiHongBao(commonOrder, fanliRate, mianDanMoney, vip);
            if (hongBao == null)
                return;
            addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
            UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
            if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1级BOSS存在且红包未失效,免单不支持多级分销
                // 插入一级子红包
                BigDecimal firstRate = hongBaoManageService
                        .getRate(new OrderHongBaoRateParams(1, type, false, vip, commonOrder.getThirdCreateTime()));
                if (firstRate.compareTo(new BigDecimal(0)) <= 0)// 返利比例为0的不分成
                    return;
                HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder, HongBaoV2.TYPE_YIJI,
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
                addInviteHongBao(firstHongbao, notificationMap, commonOrder);
                // 插入二级子红包
                boss = threeSaleSerivce.getBoss(boss.getId());
                if (boss != null) {// 二级BOSS存在且是非会员订单
                    BigDecimal secondRate = hongBaoManageService
                            .getRate(new OrderHongBaoRateParams(2, type, false, vip, commonOrder.getThirdCreateTime()));
                    if (secondRate.compareTo(new BigDecimal(0)) <= 0)
                        return;
                    HongBaoV2 secondHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                            HongBaoV2.TYPE_ERJI,
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
                    addInviteHongBao(secondHongbao, notificationMap, commonOrder);
                }
            }
        } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
            // 分享赚不加入失效的订单
            if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
                return;
            // 分享赚
            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
                        .getRate(new OrderHongBaoRateParams(0, type, false, vip, commonOrder.getThirdCreateTime()));
            if (shareRate.compareTo(new BigDecimal(0)) <= 0)
                return;
            HongBaoV2 hongBao = createShareHongBao(commonOrder, shareRate,vip);
            if (hongBao == null)
                return;
            addFanLiOrShareHongBao(hongBao, commonOrder, notificationMap);
            // 4月17日后才有一级分享赚
            if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) {
                UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId());
                if (boss != null) {
                    BigDecimal firstLevelRate = hongBaoManageService
                            .getRate(new OrderHongBaoRateParams(1, type, false, vip, commonOrder.getThirdCreateTime()));
                    if (firstLevelRate == null || firstLevelRate.compareTo(new BigDecimal("0")) == 0)
                        return;
                    HongBaoV2 firstHongbao = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                            HongBaoV2.TYPE_SHARE_YIJI,
                            MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstLevelRate.divide(new BigDecimal(100))));
                    addInviteHongBao(firstHongbao, notificationMap, commonOrder);
                    // 二级分享赚
                    boss = threeSaleSerivce.getBoss(boss.getId());
                    if (boss != null) {
                        BigDecimal secondLevelRate = hongBaoManageService.getRate(
                                new OrderHongBaoRateParams(2, type, false, vip, commonOrder.getThirdCreateTime()));
                        if (secondLevelRate.compareTo(new BigDecimal(0)) <= 0)// 返利比例为0就不统计
                            return;
                        HongBaoV2 secondChild = createInviteHongBao(boss.getId(), hongBao, commonOrder,
                                HongBaoV2.TYPE_SHARE_ERJI, MoneyBigDecimalUtil.mul(hongBao.getMoney(),
                                        secondLevelRate.divide(new BigDecimal(100))));
                        addInviteHongBao(secondChild, notificationMap, commonOrder);
                    }
                }
            }
            // 修改统计数据
            Long goodsId = commonOrder.getCommonOrderGoods().getId();
            // 查询商品
            CommonOrderGoods goods = commonOrderGoodsMapper.selectByPrimaryKey(goodsId);
            HongBao hb = new HongBao();
            if (goods != null)
                hb.setAuctionId(Long.parseLong(goods.getGoodsId()));
            hb.setUserInfo(hongBao.getUserInfo());
            hb.setMoney(hongBao.getMoney());
            // TODO 更新分享记录数据
            // try {
            // userShareGoodsGroupService.updateOrderRecord(hb,
            // commonOrder.getSourceType());
            // } catch (UserShareGoodsRecordException e) {
            // try {
            // LogHelper.errorDetailInfo(e);
            // } catch (Exception e1) {
            // e1.printStackTrace();
            // }
            // }
        } else
            throw new HongBaoException(2, "type错误");
    }
    /**
     * 添加邀请赚红包
     *
     * @param child
     * @param notificationMap
     * @param commonOrder
     */
    private void addInviteHongBao(HongBaoV2 child, Map<Integer, HongBaoOrder> notificationMap,
            CommonOrder commonOrder) {
        if (child != null) {
            hongBaoV2Mapper.insertSelective(child);
            // 用户通知
            if (notificationMap.get(child.getType()) == null) {
                HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
                tempHongBao.setUserInfo(child.getUserInfo());
                tempHongBao.setMoney(child.getMoney());
                CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                tempCommonOrder.setPayment(commonOrder.getPayment());
                notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
                // 增加付款金额与资金
                HongBaoOrder tempHongBaoOrder = notificationMap.get(child.getType());
                tempHongBaoOrder.getCommonOrder()
                        .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney()));
                notificationMap.put(child.getType(), tempHongBaoOrder);
            }
        }
    }
    /**
     * 创建邀请红包
     *
     * @param uid
     * @param parent
     * @param commonOrder
     * @param hongBaoType
     * @param money
     * @return
     */
    private HongBaoV2 createInviteHongBao(Long uid, HongBaoV2 parent, CommonOrder commonOrder, int hongBaoType,
            BigDecimal money) {
        if (parent == null)
            return null;
        if (parent.getState() == HongBaoV2.STATE_SHIXIAO)
            return null;
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
        if (user == null)
            return null;
        boolean isVIP = userVIPInfoService.isVIP(uid);
        HongBaoV2 child = new HongBaoV2();
        child.setParent(parent);
        child.setType(hongBaoType);
        child.setMoney(money);
        if (commonOrder.getState() == CommonOrder.STATE_FK) {
            child.setState(HongBaoV2.STATE_BUKELINGQU);
        } else if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) {
            child.setState(HongBaoV2.STATE_KELINGQU);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(commonOrder.getSettleTime());
            calendar.add(Calendar.MONTH, 1);
            child.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
                    calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd")));
        }
        child.setUserInfo(user);
        child.setUrank(user.getRank());
        child.setVersion(2);
        child.setCreateTime(new Date());
        child.setOrderType(commonOrder.getSourceType());
        if (child.getMoney() == null)
            return null;
        if (child.getMoney().compareTo(new BigDecimal(0)) <= 0 && !isVIP)
            return null;
        return child;
    }
    /**
     *
     * @param commonOrder
     *            - 订单信息
     * @param fanliRate
     *            -返利比例
     * @param mianDanMoney
     *            免单金额
     * @param isVIP-是否为VIP订单
     * @return
     * @throws HongBaoException
     * @throws UserAccountException
     */
    private HongBaoV2 createFanLiHongBao(CommonOrder commonOrder, BigDecimal fanliRate, BigDecimal mianDanMoney,
            boolean isVIP) throws HongBaoException, UserAccountException {
        HongBaoV2 hongBao = new HongBaoV2();
        hongBao.setUserInfo(commonOrder.getUserInfo());
        hongBao.setCreateTime(new Date());
        hongBao.setType(HongBaoV2.TYPE_ZIGOU);
        hongBao.setVersion(2);
        if (commonOrder.getState() == CommonOrder.STATE_FK) {
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
        } else if (commonOrder.getState() == CommonOrder.STATE_JS || CommonOrder.STATE_WQ == commonOrder.getState()) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
            if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_PDD)// 拼多多15天半到账
                hongBao.setPreGetTime(new Date(
                        commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L + 1000 * 60 * 60 * 12L));
            else
                hongBao.setPreGetTime(new Date(commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L));
        } else if (commonOrder.getState() == CommonOrder.STATE_SX) {
            hongBao.setState(HongBaoV2.STATE_SHIXIAO);
            hongBao.setMoney(new BigDecimal(0));
        } else {
            throw new HongBaoException(3, "维权订单不能创建红包");
        }
        if (mianDanMoney != null)
            hongBao.setMoney(mianDanMoney);
        UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
        if (user == null)
            throw new UserAccountException(1001, "用户不存在/被封禁");
        if (isVIP) {
            hongBao.setUrank(100);// VIP的等级设置为100
        } else {
            hongBao.setUrank(user.getRank());
        }
        hongBao.setOrderType(commonOrder.getSourceType());
        return hongBao;
    }
    private HongBaoV2 createFanLiUpdateHongBao(CommonOrder commonOrder, BigDecimal fanliRate, Long hongBaoId,
            boolean mianDan) throws HongBaoException, UserAccountException {
        HongBaoV2 hongBao = new HongBaoV2(hongBaoId);
        hongBao.setUpdateTime(new Date());
        // 更改状态与资金
        if (commonOrder.getState() == CommonOrder.STATE_FK) {
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
            if (mianDan)
                hongBao.setMoney(commonOrder.getPayment());
        } else if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
            if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_PDD)// 拼多多15天过1个小时到账
                hongBao.setPreGetTime(new Date(
                        commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L + 1000 * 60 * 60 * 1L));
            else
                hongBao.setPreGetTime(new Date(commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L));
            if (mianDan)
                hongBao.setMoney(commonOrder.getSettlement().compareTo(commonOrder.getPayment()) <= 0
                        ? commonOrder.getSettlement() : commonOrder.getPayment());// 返利结算与付款较小的金额
        } else if (commonOrder.getState() == CommonOrder.STATE_SX) {
            hongBao.setState(HongBaoV2.STATE_SHIXIAO);
            hongBao.setMoney(new BigDecimal(0));
        }
        return hongBao;
    }
    /**
     * 分享赚更新
     *
     * @param commonOrder
     * @param fanliRate
     * @param hongBaoId
     * @param mianDan
     * @return
     * @throws HongBaoException
     * @throws UserAccountException
     */
    private HongBaoV2 createShareUpdateHongBao(CommonOrder commonOrder, BigDecimal fanliRate, Long hongBaoId)
            throws HongBaoException, UserAccountException {
        HongBaoV2 hongBao = new HongBaoV2(hongBaoId);
        hongBao.setUpdateTime(new Date());
        // 更改状态与资金
        if (commonOrder.getState() == CommonOrder.STATE_FK) {
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100))));
        } else if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100))));
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(commonOrder.getSettleTime());
            calendar.add(Calendar.MONTH, 1);
            hongBao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
                    calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd")));
        } else if (commonOrder.getState() == CommonOrder.STATE_SX) {
            hongBao.setState(HongBaoV2.STATE_SHIXIAO);
            hongBao.setMoney(new BigDecimal(0));
        }
        return hongBao;
    }
    private HongBaoV2 createInviteUpdateHongBao(HongBaoV2 oldChild, int mainHongBaoState, BigDecimal money,
            CommonOrder commonOrder) {
        HongBaoV2 childUpdate = new HongBaoV2(oldChild.getId());
        childUpdate.setState(mainHongBaoState);
        childUpdate.setUpdateTime(new Date());
        childUpdate.setMoney(money);
        // 以实际收入为准计算预估收益
        if (mainHongBaoState == HongBaoV2.STATE_KELINGQU) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(commonOrder.getSettleTime());
            calendar.add(Calendar.MONTH, 1);
            childUpdate.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
                    calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd")));
        }
        return childUpdate;
    }
    private void addFanLiOrShareHongBao(HongBaoV2 hongBao, CommonOrder commonOrder,
            Map<Integer, HongBaoOrder> notificationMap) {
        hongBaoV2Mapper.insertSelective(hongBao);
        // 添加红包与订单的映射
        HongBaoOrder hongBaoOrder = new HongBaoOrder();
        hongBaoOrder.setCommonOrder(commonOrder);
        hongBaoOrder.setCreateTime(new Date());
        hongBaoOrder.setHongBaoV2(hongBao);
        hongBaoOrderMapper.insertSelective(hongBaoOrder);
        // 加入通知
        if (notificationMap.get(hongBao.getType()) == null) {
            HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
            tempHongBao.setUserInfo(hongBao.getUserInfo());
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
            notificationMap.put(hongBao.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
        } else {
            // 增加付款金额与资金
            HongBaoOrder tempHongBaoOrder = notificationMap.get(hongBao.getType());
            tempHongBaoOrder.getCommonOrder()
                    .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
            tempHongBaoOrder.getHongBaoV2()
                    .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
            notificationMap.put(hongBao.getType(), tempHongBaoOrder);
        }
    }
    /**
     * 创建分享赚红包
     *
     * @param commonOrder
     * @param shareRate
     * @return
     * @throws HongBaoException
     * @throws UserAccountException
     */
    private HongBaoV2 createShareHongBao(CommonOrder commonOrder, BigDecimal shareRate, boolean isVip)
            throws HongBaoException, UserAccountException {
        HongBaoV2 hongBao = new HongBaoV2();
        hongBao.setCreateTime(new Date());
        hongBao.setType(HongBaoV2.TYPE_SHARE_GOODS);
        hongBao.setVersion(2);
        if (commonOrder.getState() == CommonOrder.STATE_FK) {
            hongBao.setState(HongBaoV2.STATE_BUKELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), shareRate.divide(new BigDecimal(100))));
        } else if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_WQ) {
            hongBao.setState(HongBaoV2.STATE_KELINGQU);
            hongBao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), shareRate.divide(new BigDecimal(100))));
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(commonOrder.getSettleTime());
            calendar.add(Calendar.MONTH, 1);
            hongBao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
                    calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd")));
        }
        UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
        if (user == null)
            throw new UserAccountException(1001, "用户不存在/被封禁");
        if (isVip)
            hongBao.setUrank(100);
        else
            hongBao.setUrank(user.getRank());
        hongBao.setUserInfo(user);
        hongBao.setOrderType(commonOrder.getSourceType());
        return hongBao;
    }
}