Helius
2021-07-15 5b69ea34662548b18c65884762c04ceebe023529
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
<?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.xzx.gc.order.mapper.RedPaperRuleMapper">
    <select id="getOne" resultType="com.xzx.gc.entity.RedPaperRule">
        select
        id,rule_name "ruleName",applicable_object "applicableObject",designated_user "designatedUser",
        designated_weight "designatedWeight",issuance_rules "issuanceRules",random_amount_average "randomAmountAverage",amount
        ,surplus_amount "surplusAmount"
        ,surplus_num "surplusNum",
        red_envelopes_num "redEnvelopesNum",
        start_time "startTime",end_time "endTime",status,create_time "createTime",update_time "updateTime",del_flag "delFlag",sharing_profit_type "sharingProfitType",
        share_ratio "shareRatio",
        rule_type "ruleType",conversion_per_unit "conversionPerUnit",conversion_per_unit_flag "conversionPerUnitFlag",product_type "productType",package_id "packageId",partner_id "partnerId"
        from xzx_user_redpaper_rule where  del_flag=0 and `status`=1 and ( #{now} between start_time and end_time)  and partner_id=#{partnerId}
        <if test="ruleType!=null and ruleType!=''">
            and rule_type=#{ruleType}
        </if>
        limit  1
    </select>
 
 
    <select id="queryByCondition" resultType="com.xzx.gc.entity.RedPaperRule">
        select
        t.*,(select a.partner_name from xzx_city_partner a where a.id=t.partner_id) as partnerName
        from xzx_user_redpaper_rule t
        where t.del_flag=0
        <if test="ruleName != null and ruleName != ''">
            and  t.rule_name =#{ruleName}
        </if>
 
        <if test="ruleType != null and ruleType != ''">
            and  t.rule_type =#{ruleType}
        </if>
        <if test="partnerId != null and partnerId != ''">
            and  t.partner_id =#{partnerId} and t.del_flag=0
        </if>
    </select>
    <delete id="batchDelXzxUserRedpaperRuleByIds">
        update xzx_user_redpaper_rule set del_flag = 1 where id  in
        <foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="queryRebateList" resultType="com.xzx.gc.model.admin.XzxPlatformCapitalInfoModel">
        select a.create_time,a.order_id,b.nick_name,b.mobile_phone,
        IFNULL(sum(c.weight),0) as designatedWeight,a.order_money,
        a.royalty_money,a.user_id,a.invited_user_id,
        (select d.applicable_object from xzx_user_redpaper_rule d where a.rule_id=d.id) as applicableObject
        from xzx_platform_capital_info a
        left join xzx_user_info b on b.user_id=a.user_id
        left join xzx_order_item_info c on c.order_id=a.order_id
        left join(
        select m.partner_id,n.order_id from xzx_user_other_info m
        LEFT JOIN xzx_order_info n on n.receiver=m.user_id
        )j on a.order_id = j.order_id
        where a.rule_type=3 and a.royalty_money>0
        and b.del_flag=0
 
        <if test="startTime != null and startTime != ''">
            and  a.create_time >=#{startTime}
        </if>
 
        <if test="endTime != null and endTime != ''">
            and  a.create_time &lt;=#{endTime}
        </if>
 
        <if test="mobilePhone != null and mobilePhone != ''">
            and  (b.mobile_phone like   concat("%",#{mobilePhone} ,"%") or  b.nick_name like concat("%",#{nickName} ,"%"))
        </if>
        <if test="partnerId != null and partnerId != ''">
            and  j.partner_id = #{partnerId}
        </if>
        <if test="partnerId==null or partnerId == ''">
            AND j.partner_id is NULL
        </if>
        <if test="partnerIds!= null and partnerIds.size() != 0">
            AND  j.partner_id in
 
            <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        group by a.order_id order by a.create_time desc
    </select>
    <select id="queryTotalAmountByParam" resultType="java.lang.String">
        select sum(a.royalty_money)
        from xzx_platform_capital_info a
        left join xzx_user_info b on b.user_id=a.user_id and b.del_flag=0
        left join(
        select m.partner_id,n.order_id from xzx_user_other_info m
        LEFT JOIN xzx_order_info n on n.receiver=m.user_id
        )j on a.order_id = j.order_id
        where a.rule_type=3
        <if test="startTime != null and startTime != ''">
            and  a.create_time >=#{startTime}
        </if>
 
        <if test="endTime != null and endTime != ''">
            and  a.create_time &lt;=#{endTime}
        </if>
 
        <if test="mobilePhone != null and mobilePhone != ''">
            and  (b.mobile_phone like   concat("%",#{mobilePhone} ,"%") or  b.nick_name like concat("%",#{nickName} ,"%"))
        </if>
 
        <if test="partnerIds!= null and partnerIds.size() != 0">
            AND  j.partner_id in
 
            <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="queryUserOrderIds" resultType="java.lang.String">
        select a.order_id from xzx_order_info a
        left join xzx_order_detail_info b on b.order_id=a.order_id
        where a.order_status in (4,5,7)
 
        <if test="completeTime != null and completeTime != ''">
            and  b.complete_time &lt;= #{completeTime}
        </if>
 
        <if test="userId != null and userId != ''">
            and  a.create_user_id = #{userId}
        </if>
    </select>
    <select id="queryAfterWeightByOrderIds" parameterType="java.util.List" resultType="java.lang.String">
        select sum(weight) from xzx_order_item_info where order_id in
        <foreach collection="orderIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="queryTotalOrderMoney" resultType="java.lang.String">
        select sum(money) from xzx_order_item_info where order_id in
        <foreach collection="orderIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="queryRedpaperList" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from  xzx_user_redpaper_rule
        where   rule_type =1
        and del_flag=0
        <if test="startTime != null and startTime != ''">
            and  end_time>=#{startTime}
        </if>
    </select>
    <select id="queryRedpaperListStartAndEnd" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from  xzx_user_redpaper_rule
        where   rule_type =#{ruleType}
        and del_flag=0 and status=1
        <if test="startTime != null and startTime != ''">
            and  (  (#{startTime} >=start_time and #{startTime} &lt;=end_time) or (#{startTime} &lt;=start_time and #{endTime} >=start_time ))
        </if>
        and partner_id=#{partnerId}
 
        <if test="id != null">
            and id!=#{id}
        </if>
 
    </select>
    <select id="queryShareListByTime" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from  xzx_user_redpaper_rule
        where   rule_type =2
        and del_flag=0
        <if test="startTime != null and startTime != ''">
            and  (end_time>=#{startTime} or end_time>=#{endTime})
        </if>
 
        <choose>
            <when test="partnerId != null and partnerId != ''">
                and  partner_id=#{partnerId}
            </when>
            <otherwise>
                and partner_id is null
            </otherwise>
        </choose>
    </select>
    <select id="queryCommListByTime" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from  xzx_user_redpaper_rule
        where   rule_type =8
        and del_flag=0
        <if test="startTime != null and startTime != ''">
            and  (end_time>=#{startTime} or end_time>=#{endTime})
        </if>
 
        <if test="id != null and id != ''">
            and  id!=#{id}
        </if>
    </select>
    <select id="queryRebateRulePriceList" resultType="com.xzx.gc.entity.RebateRule">
        select * from  xzx_rebate_rule_price
        where   rule_id =#{ruleId} and del_flag=0 order by sort asc
    </select>
    <select id="queryRebateRuleList" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from  xzx_user_redpaper_rule
        where   rule_type =3
        and del_flag=0
        <choose>
            <when test="partnerId != null and partnerId != ''">
                and  partner_id=#{partnerId}
            </when>
            <otherwise>
                and partner_id is null
            </otherwise>
        </choose>
 
        <if test="status != null">
            and  status=#{status}
        </if>
    </select>
    <select id="queryWeightRuleList" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from  xzx_user_redpaper_rule
        where   rule_type =5
        and del_flag=0
        <choose>
            <when test="partnerId != null and partnerId != ''">
                and  partner_id=#{partnerId}
            </when>
            <otherwise>
                and partner_id is null
            </otherwise>
        </choose>
 
        <if test="status != null">
            and  status=#{status}
        </if>
    </select>
    <select id="queryAccountList" resultType="com.xzx.gc.model.admin.CommissionModel">
        select a.create_time as commissionTime,a.flow_no as orderNo,sum(b.money) as orderMoney,
        a.hbb as commissionEarn,c.partner_name as partnerName,
        c.mobile_phone as mobile from xzx_platform_account_log a
        left join xzx_order_item_info b on a.flow_no=b.order_id
        inner join xzx_city_partner c on a.create_user_id=c.id
        where type=4 and c.id=#{partnerId}
 
        <if test="mobile != null and mobile != ''">
            and (c.partner_name like  concat("%",#{mobile} "%") or c.mobile_phone like concat("%",#{mobile} ,"%"))
        </if>
 
        <if test="startTime != null and startTime != ''">
            and a.create_time>=#{startTime}
        </if>
 
        <if test="endTime != null and endTime != ''">
            and a.create_time&lt;=#{endTime}
        </if>
        group by a.flow_no order by a.create_time desc
    </select>
    <select id="queryTotalCommissionMoney" resultType="java.lang.String">
        select
        IFNULL(sum(a.hbb),0) from xzx_platform_account_log a
        left join xzx_city_partner c on a.create_user_id=c.id
        where type=4
        <if test="mobile != null and mobile != ''">
            and (c.partner_name like  concat("%",#{mobile} "%") or c.mobile_phone like concat("%",#{mobile} ,"%"))
        </if>
 
        <if test="startTime != null and startTime != ''">
            and a.create_time>=#{startTime}
        </if>
 
        <if test="endTime != null and endTime != ''">
            and a.create_time&lt;=#{endTime}
        </if>
    </select>
    <select id="queryAccountListCount" resultType="java.lang.String">
        select count(k.count) from (select count(a.flow_no) as count from xzx_platform_account_log a
        left join xzx_order_item_info b on a.flow_no=b.order_id
        left join xzx_city_partner c on a.create_user_id=c.id
        where type=4
        <if test="mobile != null and mobile != ''">
            and (c.partner_name like concat("%",#{mobile} "%") or c.mobile_phone like concat("%",#{mobile} ,"%"))
        </if>
 
        <if test="startTime != null and startTime != ''">
            and a.create_time>=#{startTime}
        </if>
 
        <if test="endTime != null and endTime != ''">
            and a.create_time&lt;=#{endTime}
        </if>
        group by a.flow_no order by a.create_time desc
        )k
    </select>
 
    <delete id="deleteByRuleId">
        update xzx_rebate_rule_price  set del_flag=1  where rule_id =#{ruleId}
    </delete>
 
    <select id="queryRoyalRuleList" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from  xzx_user_redpaper_rule
        where   rule_type =7
 
        <if test="packageId != null and packageId != ''">
            and package_id=#{packageId}
        </if>
 
        <if test="partnerId != null and partnerId != ''">
            and partner_id=#{partnerId}
        </if>
 
        and del_flag=0
    </select>
 
    <select id="queryRoyalty" resultType="com.xzx.gc.model.admin.XzxUserRedpaperRuleModel">
        select * from xzx_user_redpaper_rule where rule_type=7 and del_flag=0
        <if test="partnerId != null and partnerId != ''">
            and partner_id =#{partnerId}
        </if>
        <if test="partnerId==null or partnerId == ''">
            AND partner_id is NULL
        </if>
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND partner_id in
            <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
 
    <select id="selectDistribRule" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from xzx_user_redpaper_rule where rule_type=9
    </select>
</mapper>