admin
2020-04-13 dd5b15229cb15459fa7c31ccea77dac28cbfafbd
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
<?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.HongBaoOrderMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.order.HongBaoOrder">
        <id column="ho_id" property="id" jdbcType="BIGINT" />
        <result column="ho_create_time" property="createTime" jdbcType="TIMESTAMP" />
 
        <association property="hongBaoV2" column="ho_hongbao_id"
            javaType="com.yeshi.fanli.entity.bus.user.HongBaoV2">
            <id column="ho_hongbao_id" property="id" jdbcType="BIGINT" />
        </association>
 
        <association property="commonOrder" column="ho_order_id"
            javaType="com.yeshi.fanli.entity.order.CommonOrder">
            <id column="ho_order_id" property="id" jdbcType="BIGINT" />
        </association>
 
    </resultMap>
 
 
    <resultMap id="BaseDetailResultMap" type="com.yeshi.fanli.entity.order.HongBaoOrder">
        <id column="ho_id" property="id" jdbcType="BIGINT" />
        <result column="ho_create_time" property="createTime" jdbcType="TIMESTAMP" />
 
        <association property="hongBaoV2"
            resultMap="com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper.BaseResultMap">
        </association>
 
        <association property="commonOrder"
            resultMap="com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper.BaseDetailResultMap">
        </association>
 
    </resultMap>
 
 
 
    <sql id="Base_Column_List">
        ho_id,ho_hongbao_id,ho_order_id,ho_create_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_order where ho_id = #{id,jdbcType=BIGINT}
    </select>
 
 
    <select id="selectByCommonOrderId" resultMap="BaseDetailResultMap"
        parameterType="java.lang.Long">
        select
        *
        from yeshi_ec_hongbao_order left join
        yeshi_ec_hongbao_v2 on hb_id=ho_hongbao_id left join
        yeshi_ec_common_order co on co_id=ho_order_id where ho_order_id =
        #{0}
    </select>
 
    <select id="selectByHongBaoId" resultMap="BaseDetailResultMap"
        parameterType="java.lang.Long">
        SELECT * FROM (SELECT * FROM yeshi_ec_hongbao_order ho
        WHERE
        ho.`ho_hongbao_id`=#{0} ) ho LEFT JOIN yeshi_ec_hongbao_v2 h ON
        h.`hb_id`=ho.`ho_hongbao_id` LEFT JOIN yeshi_ec_common_order o ON
        o.`co_id`=ho.`ho_order_id`
    </select>
 
 
 
    <select id="listFanLiOrder" resultMap="BaseDetailResultMap">
        SELECT * FROM (SELECT *
        FROM yeshi_ec_hongbao_v2 h WHERE h.`hb_uid`=#{uid} AND h.`hb_type`=1
        ORDER BY h.`hb_create_time` DESC LIMIT #{start},#{count}) hh LEFT JOIN
        yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id`=hh.hb_id
        LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` LEFT
        JOIN
        yeshi_ec_common_order_goods g ON
        g.`cog_id`=co.`co_order_goods_id`
    </select>
 
 
    <select id="countFanLiOrder" resultType="java.lang.Long"
        parameterType="java.lang.Long">
 
        SELECT COUNT(h.`hb_id`) FROM yeshi_ec_hongbao_v2 h WHERE
        h.`hb_uid`=#{0} AND
        h.`hb_type`=1
    </select>
 
 
    <select id="countByOrderNoAndHongBaoType" resultType="java.lang.Long">
        SELECT
        COUNT(ho.`ho_id`) FROM yeshi_ec_hongbao_order ho LEFT JOIN
        yeshi_ec_hongbao_v2 v ON ho.`ho_hongbao_id`=v.`hb_id` LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE
        co.`co_order_no`=#{orderNo} and v.`hb_type`=#{type} and
        co.`co_source_type`=#{sourceType}
    </select>
 
 
    <!-- 统计数据 -->
 
    <select id="countHongBaoOrderCountMoreByUid" resultType="java.lang.Integer">
        SELECT
        COUNT(*) FROM yeshi_ec_hongbao_v2 v WHERE v.`hb_uid`=#{uid} AND
        v.`hb_money`>=#{money} AND v.`hb_state`=3
    </select>
 
 
    <select id="countOrderCountMoneyMoreByUidAndMinTime" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT( h.id)) FROM
        (
        SELECT IF(v.`hb_pid` IS NOT
        NULL,v.`hb_pid`,v.`hb_id`) AS id FROM
        yeshi_ec_hongbao_v2 v WHERE
        v.`hb_uid`=#{uid}
        ) h LEFT JOIN yeshi_ec_hongbao_order ho ON
        h.id=ho.`ho_hongbao_id` LEFT
        JOIN yeshi_ec_common_order co ON
        co.`co_id`=ho.`ho_order_id` WHERE co.`co_third_create_time`>#{minTime}
        and
        (co.`co_estimate`>=#{money} OR co.`co_eIncome`>=#{money})
    </select>
 
    <select id="countWeiQuanOrderByUid" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM
        (
        SELECT IF(v.`hb_pid` IS NOT
        NULL,p.`hb_id`,v.`hb_id`) AS id FROM
        yeshi_ec_hongbao_v2 v LEFT JOIN
        yeshi_ec_hongbao_v2 p ON
        p.`hb_id`=v.`hb_pid` WHERE v.`hb_uid`=#{uid} and
        v.`hb_create_time`>=#{minTime}
        ) a
        LEFT JOIN yeshi_ec_hongbao_order ho
        ON ho.`ho_hongbao_id`=a.id LEFT
        JOIN yeshi_ec_common_order co ON
        co.co_id=ho.`ho_order_id`
        LEFT JOIN
        `yeshi_ec_taobao_weiqaun_order` wo
        ON
        wo.`tmo_order_item_id`=co.`co_trade_id`
        WHERE co.`co_id`>0 AND
        wo.`tmo_id`>0 and wo.tmo_state!='维权失败'
    </select>
 
    <select id="sumWeiQuanOrderFanAmountByUid" resultType="java.math.BigDecimal">
        SELECT
        SUM(wo.`tmo_fan_money`) FROM
        (
        SELECT IF(v.`hb_pid` IS
        NOT
        NULL,p.`hb_id`,v.`hb_id`) AS id FROM
        yeshi_ec_hongbao_v2 v LEFT
        JOIN
        yeshi_ec_hongbao_v2 p ON
        p.`hb_id`=v.`hb_pid` WHERE
        v.`hb_uid`=#{uid}
        ) a
        LEFT JOIN yeshi_ec_hongbao_order ho ON
        ho.`ho_hongbao_id`=a.id LEFT
        JOIN yeshi_ec_common_order co ON
        co.co_id=ho.`ho_order_id`
 
        LEFT JOIN
        `yeshi_ec_taobao_weiqaun_order` wo
        ON
        wo.`tmo_order_item_id`=co.`co_trade_id`
        WHERE co.`co_id`>0 AND
        wo.`tmo_id`>0 and co_third_create_time>=#{minTime}
    </select>
 
 
 
    <select id="countWeiQuanOrderWithMinCommision" resultType="java.lang.Integer">
 
        SELECT count(distinct(a.id)) FROM
        (
        SELECT IF(v.`hb_pid` IS
        NOT
        NULL,p.`hb_id`,v.`hb_id`) AS id FROM
        yeshi_ec_hongbao_v2 v LEFT
        JOIN
        yeshi_ec_hongbao_v2 p ON
        p.`hb_id`=v.`hb_pid` WHERE
        v.`hb_uid`=#{0}
        ) a
        LEFT JOIN yeshi_ec_hongbao_order ho ON
        ho.`ho_hongbao_id`=a.id LEFT
        JOIN yeshi_ec_common_order co ON
        co.co_id=ho.`ho_order_id`
 
        LEFT JOIN
        `yeshi_ec_taobao_weiqaun_order` wo
        ON
        wo.`tmo_order_item_id`=co.`co_trade_id`
        WHERE co.`co_id`>0 AND
        tmo_fan_money>=#{minMoney} and co_third_create_time>=#{minTime}
        wo.`tmo_id`>0 and wo
    </select>
 
    <select id="listByOrderIdAndSourceType" resultMap="BaseResultMap">
        SELECT ho.*
        FROM yeshi_ec_common_order co LEFT JOIN yeshi_ec_hongbao_order
        ho ON
        ho.`ho_order_id`=co.`co_id` WHERE co.`co_order_no`=#{orderId} AND
        co.`co_source_type`=#{sourceType} AND ho.`ho_id`>0
    </select>
    
    
    
    <select id="listDetailByOrderIdAndSourceType" resultMap="BaseDetailResultMap">
        SELECT ho.*,co.*,v.*,co_order_goods_id as cog_id
        FROM yeshi_ec_common_order co LEFT JOIN yeshi_ec_hongbao_order
        ho ON
        ho.`ho_order_id`=co.`co_id`
        left join yeshi_ec_hongbao_v2 v on v.hb_id=ho.ho_hongbao_id
        
         WHERE co.`co_order_no`=#{orderId} AND
        co.`co_source_type`=#{sourceType} AND ho.`ho_id`>0
    </select>
 
    
    <select id="listDetailByOrderIdAndSourceTypeAndUid" resultMap="BaseDetailResultMap">
        SELECT ho.*,co.*,v2.*,co_order_goods_id as cog_id FROM yeshi_ec_common_order co 
        LEFT JOIN yeshi_ec_hongbao_order ho ON ho.`ho_order_id`=co.`co_id`
        left join yeshi_ec_hongbao_v2 v2 ON IF(v2.hb_pid IS NULL,v2.hb_id,v2.hb_pid)=ho.`ho_hongbao_id`
         WHERE  v2.hb_uid =#{uid}  AND co.`co_order_no`=#{orderId} AND co.`co_source_type`=#{sourceType} AND ho.`ho_id`>0
    </select>
    
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_hongbao_order where ho_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.order.HongBaoOrder"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_hongbao_order
        (ho_id,ho_hongbao_id,ho_order_id,ho_create_time) values
        (#{id,jdbcType=BIGINT},#{hongBaoV2.id,jdbcType=BIGINT},#{commonOrder.id,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.order.HongBaoOrder"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_hongbao_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">ho_id,</if>
            <if test="hongBaoV2 != null">ho_hongbao_id,</if>
            <if test="commonOrder != null">ho_order_id,</if>
            <if test="createTime != null">ho_create_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="hongBaoV2 != null">#{hongBaoV2.id,jdbcType=BIGINT},</if>
            <if test="commonOrder != null">#{commonOrder.id,jdbcType=BIGINT},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.order.HongBaoOrder">update
        yeshi_ec_hongbao_order set ho_hongbao_id =
        #{hongBaoV2.id,jdbcType=BIGINT},ho_order_id =
        #{commonOrder.id,jdbcType=BIGINT},ho_create_time =
        #{createTime,jdbcType=TIMESTAMP} where ho_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.HongBaoOrder">
        update yeshi_ec_hongbao_order
        <set>
            <if test="hongBaoV2 != null">ho_hongbao_id=#{hongBaoV2.id,jdbcType=BIGINT},</if>
            <if test="commonOrder != null">ho_order_id=#{commonOrder.id,jdbcType=BIGINT},</if>
            <if test="createTime != null">ho_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
        </set>
        where ho_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>