admin
2018-12-25 4cb15e222cd7d099d533ccbeb7f9a8cd99bf180c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<mapper namespace="com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.order.CommonOrder">
    <id column="co_id" property="id" jdbcType="BIGINT"/>
    <result column="co_order_no" property="orderNo" jdbcType="VARCHAR"/>
    <result column="co_source_type" property="sourceType" jdbcType="INTEGER"/>
    <result column="co_source_position" property="sourcePosition" jdbcType="VARCHAR"/>
    <result column="co_count" property="count" jdbcType="INTEGER"/>
    <result column="co_state" property="state" 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"/>
    <result column="co_settlement" property="settlement" jdbcType="DECIMAL"/>
    <result column="co_third_create_time" property="thirdCreateTime" jdbcType="TIMESTAMP"/>
    <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP"/>
    <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    
    <association property="userInfo" column="co_uid" 
        javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
        <id column="co_uid" property="id" jdbcType="BIGINT" />
    </association>    
    
    <association property="commonOrderGoods" column="co_order_goods_id" 
        javaType="com.yeshi.fanli.entity.order.CommonOrderGoods">
        <id column="co_order_goods_id" property="id" jdbcType="BIGINT" />
    </association>    
  </resultMap>
  
  <resultMap id="ResultMap" type="com.yeshi.fanli.vo.order.CommonOrderVO">
    <id column="co_id" property="id" jdbcType="BIGINT"/>
    <result column="co_order_no" property="orderNo" jdbcType="VARCHAR"/>
    <result column="co_source_type" property="sourceType" jdbcType="INTEGER"/>
    <result column="co_source_position" property="sourcePosition" jdbcType="VARCHAR"/>
    <result column="co_count" property="count" jdbcType="INTEGER"/>
    <result column="co_state" property="state" 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"/>
    <result column="co_settlement" property="settlement" jdbcType="DECIMAL"/>
    <result column="co_third_create_time" property="thirdCreateTime" jdbcType="TIMESTAMP"/>
    <result column="co_settle_time" property="settleTime" jdbcType="TIMESTAMP"/>
    <result column="co_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="co_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    
    <result column="totalMoney" property="hongBao" jdbcType="DECIMAL"/>
    <result column="hongBaoState" property="hongBaoState" jdbcType="INTEGER"/>
     <result column="hongBaoType" property="hongBaoType" jdbcType="INTEGER"/>
    <result column="accountTime" property="accountTime" jdbcType="TIMESTAMP"/>
    <result column="preAccountTime" property="preAccountTime" jdbcType="TIMESTAMP"/>
    
    <result column="totalCount" property="totalCount" jdbcType="INTEGER"/>
    <result column="totalSettlement" property="totalSettlement" jdbcType="DECIMAL"/>
     
    <association property="userInfo" column="co_uid" 
        resultMap="com.yeshi.fanli.dao.mybatis.UserInfoMapper.BaseResultMap">
    </association>    
    
    <association property="commonOrderGoods" column="co_order_goods_id" 
        resultMap="com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper.BaseResultMap">
    </association>    
    
    
  </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,cog_create_time,cog_update_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.order.CommonOrder" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_common_order (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,cog_create_time,cog_update_time) values (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{orderNo,jdbcType=VARCHAR},#{sourceType,jdbcType=INTEGER},#{sourcePosition,jdbcType=VARCHAR},#{commonOrderGoods.id,jdbcType=BIGINT},#{count,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{estimate,jdbcType=DECIMAL},#{eIncome,jdbcType=DECIMAL},#{payment,jdbcType=DECIMAL},#{settlement,jdbcType=DECIMAL},#{thirdCreateTime,jdbcType=TIMESTAMP},#{settleTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.order.CommonOrder" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_common_order
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">co_id,</if>
      <if test="userInfo != null">co_uid,</if>
      <if test="orderNo != null">co_order_no,</if>
      <if test="sourceType != null">co_source_type,</if>
      <if test="sourcePosition != null">co_source_position,</if>
      <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="estimate != null">co_estimate,</if>
      <if test="eIncome != null">co_eIncome,</if>
      <if test="payment != null">co_payment,</if>
      <if test="settlement != null">co_settlement,</if>
      <if test="thirdCreateTime != null">co_third_create_time,</if>
      <if test="settleTime != null">co_settle_time,</if>
      <if test="createTime != null">cog_create_time,</if>
      <if test="updateTime != null">cog_update_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
      <if test="orderNo != null">#{orderNo,jdbcType=VARCHAR},</if>
      <if test="sourceType != null">#{sourceType,jdbcType=INTEGER},</if>
      <if test="sourcePosition != null">#{sourcePosition,jdbcType=VARCHAR},</if>
      <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="estimate != null">#{estimate,jdbcType=DECIMAL},</if>
      <if test="eIncome != null">#{eIncome,jdbcType=DECIMAL},</if>
      <if test="payment != null">#{payment,jdbcType=DECIMAL},</if>
      <if test="settlement != null">#{settlement,jdbcType=DECIMAL},</if>
      <if test="thirdCreateTime != null">#{thirdCreateTime,jdbcType=TIMESTAMP},</if>
      <if test="settleTime != null">#{settleTime,jdbcType=TIMESTAMP},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.order.CommonOrder">update yeshi_ec_common_order set co_uid = #{userInfo.id,jdbcType=BIGINT},co_order_no = #{orderNo,jdbcType=VARCHAR},co_source_type = #{sourceType,jdbcType=INTEGER},co_source_position = #{sourcePosition,jdbcType=VARCHAR},co_order_goods_id = #{commonOrderGoods.id,jdbcType=BIGINT},co_count = #{count,jdbcType=INTEGER},co_state = #{state,jdbcType=INTEGER},co_estimate = #{estimate,jdbcType=DECIMAL},co_eIncome = #{eIncome,jdbcType=DECIMAL},co_payment = #{payment,jdbcType=DECIMAL},co_settlement = #{settlement,jdbcType=DECIMAL},co_third_create_time = #{thirdCreateTime,jdbcType=TIMESTAMP},co_settle_time = #{settleTime,jdbcType=TIMESTAMP},cog_create_time = #{createTime,jdbcType=TIMESTAMP},cog_update_time = #{updateTime,jdbcType=TIMESTAMP} where co_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.CommonOrder">update yeshi_ec_common_order
    <set>
      <if test="userInfo != null">co_uid=#{userInfo.id,jdbcType=BIGINT},</if>
      <if test="orderNo != null">co_order_no=#{orderNo,jdbcType=VARCHAR},</if>
      <if test="sourceType != null">co_source_type=#{sourceType,jdbcType=INTEGER},</if>
      <if test="sourcePosition != null">co_source_position=#{sourcePosition,jdbcType=VARCHAR},</if>
      <if test="commonOrderGoods != null">co_order_goods_id=#{commonOrderGoods.id,jdbcType=BIGINT},</if>
      <if test="count != null">co_count=#{count,jdbcType=INTEGER},</if>
      <if test="state != null">co_state=#{state,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>
      <if test="settlement != null">co_settlement=#{settlement,jdbcType=DECIMAL},</if>
      <if test="thirdCreateTime != null">co_third_create_time=#{thirdCreateTime,jdbcType=TIMESTAMP},</if>
      <if test="settleTime != null">co_settle_time=#{settleTime,jdbcType=TIMESTAMP},</if>
      <if test="createTime != null">cog_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">cog_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> 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 th.hb_state = #{state}
        </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 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND  (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
        </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>
    GROUP BY tc.`co_order_no`
    ORDER BY tc.co_create_time DESC
    LIMIT #{start},#{count}
  </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 th.hb_state = #{state}
        </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 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
        </if>
        <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND  (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
        </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>
  </select>
  
   <select id="listByOrderNoAndType" resultMap="ResultMap"  parameterType="java.util.List">
      SELECT 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.* 
      FROM  yeshi_ec_common_order_goods tg 
          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 tc.`co_order_no` = #{item.orderNo,jdbcType=VARCHAR})
    </foreach>
    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 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>
    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)
      <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>
    )A
  </select>
  
  
  <select id="countOrder" 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 1=1 
        <if test="uid != null">
           AND th.`hb_uid` = ${uid}
        </if>
        <if test ="isToday == 1">
            AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
  </select>
 
  <select id="countOrderMoney" resultType="java.lang.Long">
    SELECT  IFNULL(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} 
           AND <![CDATA[tc.`co_state` <> 4]]>
        <if test ="isToday == 1">
           AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
        </if>
    GROUP BY tc.`co_order_no`,tc.`co_source_type`
  </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 th.hb_type = #{type}
            </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>
        
        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 th.hb_type = #{type}
            </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>
            
        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 th.hb_type = #{type}
            </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>
        )A
  </select>
  
</mapper>