admin
2019-01-09 568cce9bd9b986c90aaeabe1a9a5ae5a6eefdaf3
Merge remote-tracking branch 'origin/master'
7个文件已修改
825 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/UserOrderController.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/CommonOrderMapper.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/order/CommonOrder.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml 671 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoWeiQuanDrawBackServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/order/CommonOrderService.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/UserOrderController.java
@@ -94,8 +94,11 @@
        
        try {
            long count = 0;
            int totalValid = 0;
            int totalProces = 0;
            int totalInvite = 0;
            long todayTotal = 0;
            BigDecimal todayMoney = new BigDecimal(0.00);
            BigDecimal todayMoney = null;
            
            // 查询列表
            List<CommonOrderVO> list = commonOrderService.getOrderByUid(page, uid, state, type, orderState,
@@ -109,26 +112,12 @@
            
            // 需要统计筛选信息 :未失效的总金额 以及订单
            if (needCount && page == 1) {
                Map<String, Object> countMap = commonOrderService.countMoneyGroupOrderNoByUid(uid, type,
                        orderNo, startTime, endTime, dateType);
                if (countMap != null) {
                    BigDecimal totalMoney = (BigDecimal) countMap.get("totalMoney");
                    if (totalMoney != null) {
                        todayMoney = totalMoney;// 当前查询所有订单已到账总金额
                    }
                    //当前查询所有已到账订单数量
                    todayTotal  = (long) countMap.get("totalRow");
                }
            }
            int totalValid = 0;
            int totalProces = 0;
            int totalInvite = 0;
            // 需要统计信息
            if (needCount && page == 1) {
                todayMoney = commonOrderService.countBonusOrderMoney(uid, type, dateType, startTime, endTime);
                todayTotal =  commonOrderService.countBonusOrderNumber(uid, type, dateType, startTime, endTime);
                // 统计有效的订单数量 、 失效订单数量 、维权订单数量
                Map<String, BigDecimal> countOrder = commonOrderService.countByUidAndOrderState(uid, type, 
                        startTime, endTime, dateType);
                
@@ -144,7 +133,12 @@
                    totalInvite = countOrder.get("totalInvite").intValue();
                }    
            }
            if (todayMoney == null) {
                todayMoney = new BigDecimal(0.00);
            }
            String helpUrl = configService.get("order_list_help");
            
            JSONObject data = new JSONObject();
@@ -204,7 +198,7 @@
            data.put("userInfo", userInfo);
            
            /* 总订单统计   */
            Map<String, BigDecimal> countOrder= commonOrderService.countOrderByHongBaoType(uid, null);
            Map<String, BigDecimal> countOrder= commonOrderService.countHistoryOrder(uid, null);
            int self = 0;
            if (countOrder.get("totalSelf") != null) {
                self = countOrder.get("totalSelf").intValue();
@@ -228,7 +222,7 @@
            data.put("invite", invite);
            
            /*  今日订单统计  */
            Map<String, BigDecimal> countToday= commonOrderService.countOrderByHongBaoType(uid, 1);
            Map<String, BigDecimal> countToday= commonOrderService.countHistoryOrder(uid, 1);
            
            int todaySelf = 0;
            if (countToday.get("totalSelf") != null) {
@@ -256,7 +250,7 @@
            data.put("today", todaydata);
            
            /*  昨日订单统计   */
            Map<String, BigDecimal> countYesterday= commonOrderService.countOrderByHongBaoType(uid, 2);
            Map<String, BigDecimal> countYesterday= commonOrderService.countHistoryOrder(uid, 2);
            int yesterdaySelf = 0;
            if (countYesterday.get("totalSelf") != null) {
                yesterdaySelf = countYesterday.get("totalSelf").intValue();
@@ -306,15 +300,15 @@
            
            JSONObject data = new JSONObject();
            // 分享统计
            BigDecimal sharemoney = commonOrderService.countOrderMoney(uid,2, dateType);
            BigDecimal sharemoney = commonOrderService.countBonusOrderMoney(uid,2, dateType, null, null);
            
            data.put("shareCount", commonOrderService.countOrder(uid, 2, dateType));
            data.put("shareCount", commonOrderService.countBonusOrderNumber(uid, 2, dateType, null, null));
            data.put("sharemoney", sharemoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
            
            // 邀请统计
            BigDecimal inviteMoney = commonOrderService.countOrderMoney(uid,3, dateType);
            BigDecimal inviteMoney = commonOrderService.countBonusOrderMoney(uid,3, dateType, null, null);
            
            data.put("inviteCount", commonOrderService.countOrder(uid, 3, dateType));
            data.put("inviteCount", commonOrderService.countBonusOrderNumber(uid, 3, dateType, null, null));
            data.put("inviteMoney", inviteMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
            
            data.put("showTiCheng", hongBaoService.getTotalTiChengCount(uid) > 0);
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/CommonOrderMapper.java
@@ -22,7 +22,7 @@
     * @return
     */
    List<CommonOrderVO> listGroupOrderNoByUid(@Param("start") long start, @Param("count") int count,
    List<CommonOrderVO> listUserOrder(@Param("start") long start, @Param("count") int count,
            @Param("uid") Long uid, @Param("state") Integer state, @Param("type") Integer type,
            @Param("orderState") Integer orderState, @Param("orderNo") String orderNo,
            @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("day") Integer day);
@@ -35,22 +35,10 @@
     * @param uid
     * @return
     */
    long countGroupOrderNoByUid(@Param("uid") Long uid, @Param("state") Integer state, @Param("type") Integer type,
    long countUserOrder(@Param("uid") Long uid, @Param("state") Integer state, @Param("type") Integer type,
            @Param("orderState") Integer orderState, @Param("orderNo") String orderNo,
            @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("day") Integer day);
    /**
     * 统计已到账金额 以及订单数量
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    Map<String, Object> countMoneyGroupOrderNoByUid(@Param("uid") Long uid, @Param("type") Integer type,
            @Param("orderNo") String orderNo, @Param("startTime") String startTime, @Param("endTime") String endTime,
            @Param("day") Integer day);
    /**
     * 根据用户ID,订单状态和订单结算时间统计订单的数量
@@ -70,15 +58,15 @@
     *            订单对象
     * @return
     */
    List<CommonOrderVO> listByOrderNoAndType(List<CommonOrderVO> list);
    List<CommonOrderVO> listOrderGoodsInfo(List<CommonOrderVO> list);
    /**
     * 统计订单-根据红包类型 自购 邀请 分享
     * 统计历史订单数量
     * 
     * @param uid
     * @return
     */
    Map<String, BigDecimal> countOrderByHongBaoType(@Param("uid") Long uid, @Param("day") Integer day);
    Map<String, BigDecimal> countHistoryOrder(@Param("uid") Long uid, @Param("day") Integer day);
    /**
     * 昨日总订单-根据红包类型 自购 邀请 分享
@@ -96,7 +84,8 @@
     * @param uid
     * @return
     */
    long countBonusOrder(@Param("uid") Long uid, @Param("type") Integer type, @Param("day") Integer day);
    long countBonusOrderNumber(@Param("uid") Long uid, @Param("type") Integer type, @Param("day") Integer day,
            @Param("startTime") String startTime, @Param("endTime") String endTime);
    /**
     * 奖金统计
@@ -104,10 +93,14 @@
     * @param uid
     * @return
     */
    BigDecimal countBonusOrderMoney(@Param("uid") Long uid, @Param("type") Integer type, @Param("day") Integer day);
    BigDecimal countBonusOrderMoney(@Param("uid") Long uid, @Param("type") Integer type, @Param("day") Integer day,
            @Param("startTime") String startTime, @Param("endTime") String endTime);
    int countByOrderNOAndOrderType(@Param("orderNO") String orderNO, @Param("orderType") int orderType);
    /**
     * 根据订单号与订单排序值获取详情
     * 
fanli/src/main/java/com/yeshi/fanli/entity/order/CommonOrder.java
@@ -25,7 +25,13 @@
    public final static int STATE_JS = 2;
    public final static int STATE_WQ = 3;
    public final static int STATE_SX = 4;
    // 整个订单状态 1-有效  2-部分有效/失效  3-失效
    public final static int STATE_WHOLE_ORDER_YOUXIAO = 1;
    public final static int STATE_WHOLE_ORDER_BUFENYOUXIAO = 2;
    public final static int STATE_WHOLE_ORDER_SHIXIAO = 3;
    // 订单红包类型图片
    public final static String TYPE_FANLI = "http://ec-1255749512.file.myqcloud.com/resource/order/icon_fanli.png";
    public final static String TYPE_INVITE = "http://ec-1255749512.file.myqcloud.com/resource/order/icon_invite.png";
@@ -66,6 +72,11 @@
    @Column(name = "co_state")
    private Integer state;
    // 整个订单状态:有效 、 部分有效/失效  、  失效
    @Expose
    @Column(name = "co_state_whole_order")
    private Integer stateWholeOrder;
    // 效果预估
    @Column(name = "co_estimate")
    private BigDecimal estimate;
@@ -245,4 +256,12 @@
        this.updateTime = updateTime;
    }
    public Integer getStateWholeOrder() {
        return stateWholeOrder;
    }
    public void setStateWholeOrder(Integer stateWholeOrder) {
        this.stateWholeOrder = stateWholeOrder;
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
@@ -10,6 +10,7 @@
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder" jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
@@ -41,6 +42,7 @@
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder" jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
@@ -71,6 +73,7 @@
            jdbcType="VARCHAR" />
        <result column="co_count" property="count" jdbcType="INTEGER" />
        <result column="co_state" property="state" jdbcType="INTEGER" />
        <result column="co_state_whole_order" property="stateWholeOrder" jdbcType="INTEGER" />
        <result column="co_estimate" property="estimate" jdbcType="DECIMAL" />
        <result column="co_eIncome" property="eIncome" jdbcType="DECIMAL" />
        <result column="co_payment" property="payment" jdbcType="DECIMAL" />
@@ -104,7 +107,7 @@
    </resultMap>
    <sql id="Base_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_order_by,co_create_time,co_update_time
    <sql id="Base_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_state_whole_order,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_order_by,co_create_time,co_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
@@ -155,6 +158,7 @@
            <if test="commonOrderGoods != null">co_order_goods_id,</if>
            <if test="count != null">co_count,</if>
            <if test="state != null">co_state,</if>
            <if test="stateWholeOrder != null">co_state_whole_order,</if>
            <if test="estimate != null">co_estimate,</if>
            <if test="eIncome != null">co_eIncome,</if>
            <if test="payment != null">co_payment,</if>
@@ -175,6 +179,7 @@
            <if test="commonOrderGoods != null">#{commonOrderGoods.id,jdbcType=BIGINT},</if>
            <if test="count != null">#{count,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="stateWholeOrder != null">#{stateWholeOrder,jdbcType=INTEGER},</if>
            <if test="estimate != null">#{estimate,jdbcType=DECIMAL},</if>
            <if test="eIncome != null">#{eIncome,jdbcType=DECIMAL},</if>
            <if test="payment != null">#{payment,jdbcType=DECIMAL},</if>
@@ -194,7 +199,8 @@
        #{sourcePosition,jdbcType=VARCHAR},co_order_goods_id =
        #{commonOrderGoods.id,jdbcType=BIGINT},co_count =
        #{count,jdbcType=INTEGER},co_state =
        #{state,jdbcType=INTEGER},co_estimate =
        #{state,jdbcType=INTEGER},co_state_whole_order =
        #{stateWholeOrder,jdbcType=INTEGER},co_estimate =
        #{estimate,jdbcType=DECIMAL},co_eIncome =
        #{eIncome,jdbcType=DECIMAL},co_payment =
        #{payment,jdbcType=DECIMAL},co_settlement =
@@ -217,6 +223,7 @@
            </if>
            <if test="count != null">co_count=#{count,jdbcType=INTEGER},</if>
            <if test="state != null">co_state=#{state,jdbcType=INTEGER},</if>
            <if test="stateWholeOrder != null">co_state_whole_order=#{stateWholeOrder,jdbcType=INTEGER},</if>
            <if test="estimate != null">co_estimate=#{estimate,jdbcType=DECIMAL},</if>
            <if test="eIncome != null">co_eIncome=#{eIncome,jdbcType=DECIMAL},</if>
            <if test="payment != null">co_payment=#{payment,jdbcType=DECIMAL},</if>
@@ -231,193 +238,119 @@
        where co_id = #{id,jdbcType=BIGINT}
    </update>
    <select id="listGroupOrderNoByUid" resultMap="ResultMap">
        SELECT COALESCE(SUM(th.`hb_money`),0)AS totalMoney,tc.*,th.hb_state AS
        hongBaoState, th.hb_type AS hongBaoType,
        th.hb_get_time AS
        accountTime,th.hb_get_time AS accountTime,th.hb_pre_get_time AS
        preAccountTime
        FROM yeshi_ec_common_order tc
        LEFT JOIN
        yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN
        yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = #{uid}
        <if test="state != null and state == 1">  <!-- 未到账 -->
            AND (th.hb_state = 1 or th.hb_state = 2)
        </if>
        <if test="state != null and state == 2"> <!-- 已到账 -->
            AND th.hb_state = 3
        </if>
        <if test="state != null and state == 3">  <!-- 红包已失效 -->
            AND th.hb_state =4
        </if>
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="orderNo != null">
            AND tc.co_order_no = #{orderNo}
        </if>
    <sql id="SELECT_PARAM_ORDER_STATE">
        <if test="orderState != null and orderState ==  1">
            AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
            <!-- 有效订单: 整个订单有效、 部分订单有效 -->
            AND (co.co_state_whole_order = 1 or co.co_state_whole_order = 2)
        </if>
        <if test="orderState != null and orderState ==  2">
            AND tc.co_state = 3 <!-- 维权订单 -->
            AND co.co_state = 3 <!-- 维权订单 -->
        </if>
        <if test="orderState != null and orderState ==  3">
            AND tc.co_state = 4 <!-- 失效订单 -->
            <!-- 整个订单失效 -->
            AND co.co_state_whole_order = 3
        </if>
    </sql>
    <sql id="SELECT_PARAM_ORDER_CREATE_TIME">
        <if test="startTime != null">
            AND <![CDATA[tc.co_create_time >= #{startTime}]]>
            AND <![CDATA[co.co_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null">
            AND <![CDATA[tc.co_create_time <= #{endTime}]]>
            AND <![CDATA[co.co_create_time <= #{endTime}]]>
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
            AND TO_DAYS(co.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
            AND TO_DAYS(NOW()) - TO_DAYS(co.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            AND DATE_FORMAT(co.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(co.`co_create_time`, '%Y%m')) = 1
        </if>
        GROUP BY tc.`co_order_no`,tc.co_source_type
        ORDER BY tc.co_create_time
        DESC
    </sql>
    <sql id="SELECT_PARAM_HONGBAO_TYPE">
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (v2.hb_type =1 or v2.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND v2.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7 OR v2.`hb_type` = 21 OR v2.`hb_type` = 22)
        </if>
    </sql>
    <sql id="SELECT_PARAM_HONGBAO_STATE">
        <if test="state != null and state == 1">  <!-- 未到账 -->
            AND (v2.hb_state = 1 or v2.hb_state = 2)
        </if>
        <if test="state != null and state == 2"> <!-- 已到账 -->
            AND v2.hb_state = 3
        </if>
        <if test="state != null and state == 3">  <!-- 红包已失效 -->
            AND v2.hb_state =4
        </if>
    </sql>
    <select id="listUserOrder" resultMap="ResultMap">
        <!-- 查询用户订单 -->
        SELECT COALESCE(SUM(hb.`hb_money`),0)AS totalMoney,hb.hb_state AS hongBaoState,hb.hb_type AS hongBaoType,
             hb.hb_get_time AS accountTime,hb.hb_get_time AS accountTime,hb.hb_pre_get_time AS preAccountTime,co.*
        FROM yeshi_ec_hongbao_order ho
        LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2 v2
                    WHERE v2.`hb_uid`= #{uid}
                        <include refid="SELECT_PARAM_HONGBAO_TYPE"/>  <!-- 红包类型 -->
                        <include refid="SELECT_PARAM_HONGBAO_STATE"/> <!-- 红包状态 -->
                )hb ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL AND co.co_id IS NOT NULL
              <include refid="SELECT_PARAM_ORDER_STATE"/>        <!-- 订单状态 -->
              <include refid="SELECT_PARAM_ORDER_CREATE_TIME"/>  <!-- 订单时间 -->
              <if test="orderNo != null and orderNo !='' ">
                AND co.co_order_no = #{orderNo}
              </if>
        GROUP BY co.`co_order_no`, co.`co_source_type`
        ORDER BY co.co_create_time DESC
        LIMIT ${start},${count}
    </select>
    <select id="countMoneyGroupOrderNoByUid" resultType="java.util.Map">
        SELECT COALESCE(SUM(A.moneys),0)AS totalMoney,COUNT(*) AS totalRow FROM
            (SELECT COALESCE(SUM(th.`hb_money`),0)AS moneys FROM yeshi_ec_common_order tc
            LEFT JOIN
            yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
            LEFT JOIN
            yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
                th.`hb_pid` = tr.`ho_hongbao_id` )
            WHERE th.`hb_uid` = #{uid}
            <if test="type != null and type == 1"> <!-- 自购订单 -->
                AND (th.hb_type =1 or th.hb_type =2)
            </if>
            <if test="type != null and type == 2"> <!-- 分享订单 -->
                AND th.`hb_type` = 20
            </if>
            <if test="type != null and type == 3"> <!-- 邀请订单 -->
                AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
            </if>
            <if test="orderNo != null">
                AND tc.co_order_no = #{orderNo}
            </if>
            <if test="startTime != null">
                AND <![CDATA[tc.co_create_time >= #{startTime}]]>
            </if>
            <if test="endTime != null">
                AND <![CDATA[tc.co_create_time <= #{endTime}]]>
            </if>
            <if test="day != null and day == 1"> <!-- 今天 -->
                AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
            </if>
            <if test="day != null and day == 2">  <!-- 昨天 -->
                AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
            </if>
            <if test="day != null and day == 3">  <!-- 本月 -->
                AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
                DATE_FORMAT(CURDATE(),'%Y%m')
            </if>
            <if test="day != null and day == 4">  <!-- 上月 -->
                AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
                DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
                <!-- 统计已收货 -->
                AND tc.`co_state` = 2
            </if>
            GROUP BY tc.`co_order_no`,tc.co_source_type)A
    <select id="countUserOrder" resultType="java.lang.Long">
        <!-- 统计用户订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0) FROM
            (SELECT ho.ho_id FROM yeshi_ec_hongbao_order ho
             LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2 v2
                    WHERE v2.`hb_uid`= #{uid}
                        <include refid="SELECT_PARAM_HONGBAO_TYPE"/>  <!-- 红包类型 -->
                        <include refid="SELECT_PARAM_HONGBAO_STATE"/> <!-- 红包状态 -->
                )hb ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
              LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
             WHERE hb.hb_id IS NOT NULL AND co.co_id IS NOT NULL
                     <include refid="SELECT_PARAM_ORDER_STATE"/>        <!-- 订单状态 -->
                   <include refid="SELECT_PARAM_ORDER_CREATE_TIME"/>  <!-- 订单时间 -->
                   <if test="orderNo != null and orderNo !='' ">
                        AND co.co_order_no = #{orderNo}
                   </if>
             GROUP BY co.`co_order_no`, co.`co_source_type`
        )A
    </select>
    <select id="countGroupOrderNoByUid" resultType="java.lang.Long">
        SELECT IFNULL(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0)
        FROM yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order tr ON
        tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN yeshi_ec_hongbao_v2 th ON
        (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = #{uid}
        <if test="state != null and state == 1">  <!-- 未到账 -->
            AND (th.hb_state = 1 or th.hb_state = 2)
        </if>
        <if test="state != null and state == 2">  <!-- 已到账 -->
            AND th.hb_state = 3
        </if>
        <if test="state != null and state == 3"> <!-- 红包已失效 -->
            AND th.hb_state =4
        </if>
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="orderState != null and orderState ==  1">
            AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
        </if>
        <if test="orderState != null and orderState == 2">
            AND tc.co_state = 3 <!-- 维权订单 -->
        </if>
        <if test="orderState != null and orderState ==  3">
            AND tc.co_state = 4 <!-- 失效订单 -->
        </if>
        <if test="orderNo != null">
            AND tc.co_order_no = #{orderNo}
        </if>
        <if test="startTime != null">
            AND <![CDATA[tc.co_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null">
            AND <![CDATA[tc.co_create_time <= #{endTime}]]>
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
        </if>
    </select>
    <select id="listByOrderNoAndType" resultMap="ResultMap"
        parameterType="java.util.List">
    <select id="listOrderGoodsInfo" resultMap="ResultMap"    parameterType="java.util.List">
         <!-- 查询用户订单商品信息 -->
        SELECT COALESCE(SUM(tc.`co_payment`),0)AS totalPayment,COALESCE(SUM(tc.`co_settlement`),0)AS totalSettlement,
            COALESCE(SUM(tc.`co_count`),0)AS totalCount,tc.`co_source_type`,tc.`co_order_no`,tg.*,tc.co_id
        FROM
        yeshi_ec_common_order_goods tg
        LEFT JOIN yeshi_ec_common_order tc ON
        tc.`co_order_goods_id` = tg.`cog_id`
        LEFT JOIN yeshi_ec_common_order tc ON tc.`co_order_goods_id` = tg.`cog_id`
        WHERE
        <foreach collection="list" item="item" separator=" OR ">
            (tc.`co_source_type` = #{item.sourceType,jdbcType=INTEGER} AND
@@ -426,320 +359,132 @@
        GROUP BY tc.`co_order_no`,tc.`co_order_goods_id`
    </select>
    <select id="countOrderByHongBaoType" resultType="java.util.HashMap">
        SELECT SUM(self)AS totalSelf, SUM(shared)AS totalShared ,SUM(invite)AS
        totalInvite FROM (
        SELECT IFNULL(COUNT(DISTINCT
        tc.`co_order_no`,tc.`co_source_type`),0) AS self,0 AS shared,0 AS
        invite FROM yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order
        tr ON tr.`ho_order_id` = tc.`co_id`
        LEFT
        JOIN yeshi_ec_hongbao_v2 th ON
        tr.`ho_hongbao_id` = th.`hb_id`
        WHERE
        th.`hb_uid` = ${uid}
        AND
        (th.`hb_type` = 1 OR th.`hb_type` = 2)
        <if test="day != null and day == 1">
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        UNION
        SELECT 0 AS self, IFNULL(COUNT(DISTINCT
        tc.`co_order_no`,tc.`co_source_type`),0) AS shared,0 AS invite FROM
        yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order tr ON
        tr.`ho_order_id` = tc.`co_id`
        LEFT
        JOIN yeshi_ec_hongbao_v2 th ON
        (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = ${uid}
        AND th.`hb_type` = 20
        <if test="day != null and day == 1">
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        UNION
        SELECT 0 AS self,0 AS shared,IFNULL(COUNT(DISTINCT
        tc.`co_order_no`,tc.`co_source_type`),0) AS invite FROM
        yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order tr ON
        tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN yeshi_ec_hongbao_v2 th ON
        (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = ${uid}
        AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22 )
        <if test="day != null and day == 1">
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
    <select id="countHistoryOrder" resultType="java.util.HashMap">
        <!-- 统计历史订单数量 -->
        SELECT SUM(A.self)AS totalSelf,SUM(A.shared)AS totalShared,SUM(A.invite)AS totalInvite
        FROM (
            <!-- 返利订单 -->
            SELECT IFNULL(COUNT(ho_id),0) AS self,0 AS shared,0 AS invite
            FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
                LEFT JOIN (
                SELECT * FROM yeshi_ec_hongbao_v2 v2
                WHERE v2.`hb_uid`= ${uid} AND (v2.`hb_type` = 1 OR v2.`hb_type` = 2)
            ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
            LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
            WHERE hb.hb_id IS NOT NULL <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
            GROUP BY co.`co_order_no`, co.`co_source_type`)YX
            UNION ALL
            <!-- 分享订单 -->
            SELECT 0 AS self,IFNULL(COUNT(ho_id),0) AS shared,0 AS invite
            FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
                LEFT JOIN (
                    SELECT * FROM yeshi_ec_hongbao_v2 v2
                    WHERE v2.`hb_uid`= ${uid} AND v2.`hb_type` = 20
                ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
                WHERE hb.hb_id IS NOT NULL <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
                GROUP BY co.`co_order_no`, co.`co_source_type`)WQ
            UNION ALL
            <!-- 邀请订单 -->
            SELECT 0 AS self,0 AS shared,IFNULL(COUNT(ho_id),0) AS invite
            FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
                LEFT JOIN (
                    SELECT * FROM yeshi_ec_hongbao_v2 v2
                    WHERE v2.`hb_uid`= ${uid}
                         AND (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7
                               OR v2.`hb_type` = 21 OR v2.`hb_type` = 22 )
                ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
                WHERE hb.hb_id IS NOT NULL  <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
                GROUP BY co.`co_order_no`, co.`co_source_type`)SX
        )A
    </select>
    <select id="countByUidAndOrderState" resultType="java.util.HashMap">
        SELECT SUM(valid)AS totalValid, SUM(proces)AS totalProces
        ,SUM(Invalid)AS totalInvite
        FROM (SELECT IFNULL(COUNT(DISTINCT
        tc.`co_order_no`,tc.`co_source_type`),0) AS valid,0 AS proces,0 AS
        Invalid
        FROM yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order
        tr ON tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN yeshi_ec_hongbao_v2 th ON
        (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = #{uid} AND
        (tc.`co_state` = 1 OR tc.`co_state` = 2)
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="startTime != null">
            AND <![CDATA[tc.co_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null">
            AND <![CDATA[tc.co_create_time <= #{endTime}]]>
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
        </if>
        UNION
        SELECT 0 AS valid,IFNULL(COUNT(DISTINCT
        tc.`co_order_no`,tc.`co_source_type`),0) AS proces,0 AS Invalid
        FROM
        yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order tr ON
        tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN yeshi_ec_hongbao_v2 th ON
        (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = #{uid} AND
        tc.`co_state` =3
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="startTime != null">
            AND <![CDATA[tc.co_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null">
            AND <![CDATA[tc.co_create_time <= #{endTime}]]>
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
        </if>
        UNION
        SELECT 0 AS valid,0 AS proces,IFNULL(COUNT(DISTINCT
        tc.`co_order_no`,tc.`co_source_type`),0) AS Invalid
        FROM
        yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order tr ON
        tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN yeshi_ec_hongbao_v2 th ON
        (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid`= #{uid} AND
        tc.`co_state` = 4
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="startTime != null">
            AND <![CDATA[tc.co_create_time >= #{startTime}]]>
        </if>
        <if test="endTime != null">
            AND <![CDATA[tc.co_create_time <= #{endTime}]]>
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
        </if>
        SELECT SUM(A.valid)AS totalValid, SUM(A.proces)AS totalProces,SUM(A.Invalid)AS totalInvite
        FROM (
            <!-- 有效订单 -->
            SELECT IFNULL(COUNT(ho_id),0) AS valid,0 AS proces,0 AS Invalid
            FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
            LEFT JOIN (
                SELECT * FROM yeshi_ec_hongbao_v2 v2
                WHERE v2.`hb_uid`=${uid} <include refid="SELECT_PARAM_HONGBAO_TYPE" />
            ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
            LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
            WHERE hb.hb_id IS NOT NULL  AND (co.`co_state_whole_order` =1 OR  co.`co_state_whole_order` = 2)
                <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
            GROUP BY co.`co_order_no`, co.`co_source_type`)YX
            UNION ALL
            <!-- 维权订单 -->
            SELECT 0 AS valid,IFNULL(COUNT(ho_id),0) AS proces,0 AS Invalid
            FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
                LEFT JOIN (
                    SELECT * FROM yeshi_ec_hongbao_v2 v2
                    WHERE v2.`hb_uid`=${uid} <include refid="SELECT_PARAM_HONGBAO_TYPE" />
                ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
                WHERE hb.hb_id IS NOT NULL AND (co.`co_state_whole_order` =1 OR  co.`co_state_whole_order` = 2)
                    <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
                GROUP BY co.`co_order_no`, co.`co_source_type`)WQ
            UNION ALL
            <!-- 失效订单 -->
            SELECT 0 AS valid,0 AS proces,IFNULL(COUNT(ho_id),0) AS Invalid
            FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
                LEFT JOIN (
                    SELECT * FROM yeshi_ec_hongbao_v2 v2
                    WHERE v2.`hb_uid`=${uid} <include refid="SELECT_PARAM_HONGBAO_TYPE" />
                ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
                WHERE hb.hb_id IS NOT NULL  AND co.`co_state_whole_order` = 3
                    <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
                GROUP BY co.`co_order_no`, co.`co_source_type`)SX
        )A
    </select>
    <select id="countBonusOrder" resultType="java.lang.Long">
        SELECT COALESCE(COUNT(DISTINCT
        tc.`co_order_no`,tc.`co_source_type`),0) FROM yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id`
        OR th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE 1=1
        <if test="uid != null">
            AND th.`hb_uid` = ${uid}
        </if>
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
        </if>
    <select id="countBonusOrderNumber" resultType="java.lang.Long">
        <!-- 奖金统计:订单数量 -->
        SELECT IFNULL(COUNT(ho_id),0)
        FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
                LEFT JOIN (
                    SELECT * FROM yeshi_ec_hongbao_v2 v2
                    WHERE v2.`hb_uid`=${uid} <include refid="SELECT_PARAM_HONGBAO_TYPE" />
                ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
                LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
                WHERE hb.hb_id IS NOT NULL
                    <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
                    <if test="day != null and day == 4">
                        AND co.`co_state` = 2 <!-- 上月 :统计已收货 -->
                    </if>
                GROUP BY co.`co_order_no`, co.`co_source_type`
        )A
    </select>
    <select id="countBonusOrderMoney" resultType="java.math.BigDecimal">
        SELECT COALESCE(SUM(th.`hb_money`),0)AS totalmoney FROM
        yeshi_ec_common_order tc
        LEFT JOIN yeshi_ec_hongbao_order tr ON
        tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN yeshi_ec_hongbao_v2 th ON
        (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = ${uid}
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
            <!-- 统计已收货 -->
            AND tc.`co_state` = 2
        </if>
    </select>
    <select id="listBonusOrder" resultMap="ResultMap">
        SELECT COALESCE(SUM(th.`hb_money`),0)AS totalMoney,tc.*,th.hb_state AS
        hongBaoState, th.hb_type AS hongBaoType,
        th.hb_get_time AS
        accountTime,th.hb_get_time AS accountTime,th.hb_pre_get_time AS
        preAccountTime
        FROM yeshi_ec_common_order tc
        LEFT JOIN
        yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
        LEFT JOIN
        yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
        th.`hb_pid` = tr.`ho_hongbao_id` )
        WHERE th.`hb_uid` = #{uid}
        <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
        </if>
        <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND th.`hb_type` = 20
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="orderState != null and orderState == 1">
            AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
        </if>
        <if test="orderState != null and orderState == 2">
            AND tc.co_state = 3 <!-- 维权订单 -->
        </if>
        <if test="orderState != null and orderState == 3">
            AND tc.co_state = 4 <!-- 失效订单 -->
        </if>
        <if test="day != null and day == 1"> <!-- 今天 -->
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
        <if test="day != null and day == 2">  <!-- 昨天 -->
            AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
        </if>
        <if test="day != null and day == 3">  <!-- 本月 -->
            AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
            DATE_FORMAT(CURDATE(),'%Y%m')
        </if>
        <if test="day != null and day == 4">  <!-- 上月 -->
            AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
            DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
        </if>
        GROUP BY tc.`co_order_no`,tc.co_source_type
        ORDER BY tc.co_create_time
        DESC
        LIMIT ${start},${count}
        <!-- 奖金统计:订单总返利金额 -->
        SELECT  COALESCE(SUM(hb.`hb_money`),0)AS totalmoney
        FROM yeshi_ec_hongbao_order ho
        LEFT JOIN (
            SELECT * FROM yeshi_ec_hongbao_v2 v2
            WHERE v2.`hb_uid`=${uid} <include refid="SELECT_PARAM_HONGBAO_TYPE" />
        ) hb  ON (hb.hb_id=ho.`ho_hongbao_id` OR hb.hb_pid=ho.`ho_hongbao_id`)
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL
            <include refid="SELECT_PARAM_ORDER_CREATE_TIME" />
            <if test="day != null and day == 4">
                AND co.`co_state` = 2 <!-- 上月 :统计已收货 -->
            </if>
    </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -81,14 +81,14 @@
    public List<CommonOrderVO> listGroupOrderNoByUid(long start, int count, Long uid, Integer state, Integer type,
            Integer orderState, String orderNo, String startTime, String endTime, Integer dateType)
            throws CommonOrderException {
        return commonOrderMapper.listGroupOrderNoByUid(start, count, uid, state, type, orderState, orderNo, startTime,
        return commonOrderMapper.listUserOrder(start, count, uid, state, type, orderState, orderNo, startTime,
                endTime, dateType);
    }
    @Override
    public long countGroupOrderNoByUid(Long uid, Integer state, Integer type, Integer orderState, String orderNo,
            String startTime, String endTime, Integer dateType) throws CommonOrderException {
        return commonOrderMapper.countGroupOrderNoByUid(uid, state, type, orderState, orderNo, startTime, endTime,
        return commonOrderMapper.countUserOrder(uid, state, type, orderState, orderNo, startTime, endTime,
                dateType);
    }
@@ -108,7 +108,7 @@
        }
        // 商品信息
        List<CommonOrderVO> listGoods = commonOrderMapper.listByOrderNoAndType(listOrder);
        List<CommonOrderVO> listGoods = commonOrderMapper.listOrderGoodsInfo(listOrder);
        // 订单商品为空
        if (listGoods == null || listGoods.size() == 0) {
            return listOrder;
@@ -121,18 +121,18 @@
    }
    @Override
    public Map<String, BigDecimal> countOrderByHongBaoType(Long uid, Integer day) {
        return commonOrderMapper.countOrderByHongBaoType(uid, day);
    public Map<String, BigDecimal> countHistoryOrder(Long uid, Integer day) {
        return commonOrderMapper.countHistoryOrder(uid, day);
    }
    @Override
    public long countOrder(Long uid, Integer type, Integer day) {
        return commonOrderMapper.countBonusOrder(uid, type, day);
    public long countBonusOrderNumber(Long uid, Integer type, Integer day, String startTime, String endTime) {
        return commonOrderMapper.countBonusOrderNumber(uid, type, day, startTime, endTime);
    }
    @Override
    public BigDecimal countOrderMoney(Long uid, Integer type, Integer day) {
        return commonOrderMapper.countBonusOrderMoney(uid, type, day);
    public BigDecimal countBonusOrderMoney(Long uid, Integer type, Integer day, String startTime, String endTime) {
        return commonOrderMapper.countBonusOrderMoney(uid, type, day, startTime, endTime);
    }
    @Override
@@ -427,11 +427,6 @@
        return commonOrderList;
    }
    @Override
    public Map<String, Object> countMoneyGroupOrderNoByUid(Long uid, Integer type, String orderNo, String startTime,
            String endTime, Integer day) {
        return commonOrderMapper.countMoneyGroupOrderNoByUid(uid, type, orderNo, startTime, endTime, day);
    }
    @Override
    public long countByUidAndOrderStateWithOrderBalanceTime(Long uid, int state, Date minDate, Date maxDate) {
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoWeiQuanDrawBackServiceImpl.java
@@ -105,7 +105,7 @@
        cv.setOrderNo(orderId);
        typeList.add(cv);
        List<CommonOrderVO> commonOrderList = commonOrderMapper.listByOrderNoAndType(typeList);
        List<CommonOrderVO> commonOrderList = commonOrderMapper.listOrderGoodsInfo(typeList);
        List<HongBaoV2> mainHongBaoList = new ArrayList<>();
        if (commonOrderList != null)
            for (CommonOrderVO vo : commonOrderList) {
@@ -227,7 +227,7 @@
        cv.setOrderNo(orderId);
        typeList.add(cv);
        List<CommonOrderVO> commonOrderList = commonOrderMapper.listByOrderNoAndType(typeList);
        List<CommonOrderVO> commonOrderList = commonOrderMapper.listOrderGoodsInfo(typeList);
        List<HongBaoV2> mainHongBaoList = new ArrayList<>();
        if (commonOrderList != null)
            for (CommonOrderVO vo : commonOrderList) {
@@ -355,7 +355,7 @@
        cv.setOrderNo(orderId);
        typeList.add(cv);
        List<CommonOrderVO> commonOrderList = commonOrderMapper.listByOrderNoAndType(typeList);
        List<CommonOrderVO> commonOrderList = commonOrderMapper.listOrderGoodsInfo(typeList);
        List<HongBaoV2> mainHongBaoList = new ArrayList<>();
        if (commonOrderList != null)
            for (CommonOrderVO vo : commonOrderList) {
fanli/src/main/java/com/yeshi/fanli/service/inter/order/CommonOrderService.java
@@ -5,8 +5,6 @@
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
import com.yeshi.fanli.exception.order.CommonOrderException;
@@ -82,7 +80,7 @@
     * @param uid
     * @return
     */
    public Map<String, BigDecimal> countOrderByHongBaoType(Long uid, Integer day);
    public Map<String, BigDecimal> countHistoryOrder(Long uid, Integer day);
    /**
     * 统计订单
@@ -90,7 +88,7 @@
     * @param uid
     * @return
     */
    public long countOrder(Long uid, Integer type, Integer isToday);
    public long countBonusOrderNumber(Long uid, Integer type, Integer isToday, String startTime, String endTime);
    /**
     * 统计订单
@@ -98,7 +96,7 @@
     * @param uid
     * @return
     */
    public BigDecimal countOrderMoney(Long uid, Integer type, Integer isToday);
    public BigDecimal countBonusOrderMoney(Long uid, Integer type, Integer isToday, String startTime, String endTime);
    /**
     * 根据条件统计
@@ -130,19 +128,6 @@
     */
    public List<CommonOrder> addTaoBaoOrder(List<TaoBaoOrder> taoBaoOrder, Long uid) throws CommonOrderException;
    /**
     * 根据提条件统计已到账金额
     *
     * @param uid
     * @param type
     * @param orderNo
     * @param startTime
     * @param endTime
     * @param day
     * @return
     */
    public Map<String, Object> countMoneyGroupOrderNoByUid(Long uid, Integer type, String orderNo, String startTime,
            String endTime, Integer day);
    /**
     * 根据用户ID,订单状态,结算时间统计订单数量