mitao
2025-01-17 afa0dbb4f54e7244835dd67ec33c3e545f122f71
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?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.ruoyi.member.mapper.coupon.CouponMapper">
 
    <resultMap type="Coupon" id="CouponResult">
        <result property="couponId"    column="coupon_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="couponType"    column="coupon_type"    />
        <result property="couponStatus"    column="coupon_status"    />
        <result property="couponName"    column="coupon_name"    />
        <result property="sendType"    column="send_type"    />
        <result property="sendTimeType"    column="send_time_type"    />
        <result property="sendTime"    column="send_time"    />
        <result property="moneyThreshold"    column="money_threshold"    />
        <result property="discountMoney"    column="discount_money"    />
        <result property="discountPercent"    column="discount_percent"    />
        <result property="useScope"    column="use_scope"    />
        <result property="validTimeType"    column="valid_time_type"    />
        <result property="validStartTime"    column="valid_start_time"    />
        <result property="validEndTime"    column="valid_end_time"    />
        <result property="validDay"    column="valid_day"    />
        <result property="createTime"    column="create_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateUserId"    column="update_user_id"    />
    </resultMap>
 
    <sql id="selectCouponVo">
        select coupon_id, del_flag, coupon_type, coupon_status, coupon_name, send_type, send_time_type, send_time, money_threshold, discount_money, discount_percent, use_scope, valid_time_type, valid_start_time, valid_end_time, valid_day, create_time, create_user_id, update_time, update_user_id from t_coupon
    </sql>
 
    <select id="selectCouponList" parameterType="Coupon" resultMap="CouponResult">
        <include refid="selectCouponVo"/>
        <where>
            <if test="couponType != null "> and coupon_type = #{couponType}</if>
            <if test="couponStatus != null "> and coupon_status = #{couponStatus}</if>
            <if test="couponName != null  and couponName != ''"> and coupon_name like concat('%', #{couponName}, '%')</if>
            <if test="sendType != null "> and send_type = #{sendType}</if>
            <if test="sendTimeType != null "> and send_time_type = #{sendTimeType}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
            <if test="moneyThreshold != null "> and money_threshold = #{moneyThreshold}</if>
            <if test="discountMoney != null "> and discount_money = #{discountMoney}</if>
            <if test="discountPercent != null "> and discount_percent = #{discountPercent}</if>
            <if test="useScope != null "> and use_scope = #{useScope}</if>
            <if test="validTimeType != null "> and valid_time_type = #{validTimeType}</if>
            <if test="validStartTime != null "> and valid_start_time = #{validStartTime}</if>
            <if test="validEndTime != null "> and valid_end_time = #{validEndTime}</if>
            <if test="validDay != null "> and valid_day = #{validDay}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
        </where>
    </select>
 
    <select id="selectCouponByCouponId" parameterType="String" resultMap="CouponResult">
        <include refid="selectCouponVo"/>
        where coupon_id = #{couponId}
    </select>
 
    <insert id="insertCoupon" parameterType="Coupon">
        insert into t_coupon
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="couponId != null">coupon_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="couponType != null">coupon_type,</if>
            <if test="couponStatus != null">coupon_status,</if>
            <if test="couponName != null">coupon_name,</if>
            <if test="sendType != null">send_type,</if>
            <if test="sendTimeType != null">send_time_type,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="moneyThreshold != null">money_threshold,</if>
            <if test="discountMoney != null">discount_money,</if>
            <if test="discountPercent != null">discount_percent,</if>
            <if test="useScope != null">use_scope,</if>
            <if test="validTimeType != null">valid_time_type,</if>
            <if test="validStartTime != null">valid_start_time,</if>
            <if test="validEndTime != null">valid_end_time,</if>
            <if test="validDay != null">valid_day,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateUserId != null">update_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="couponId != null">#{couponId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="couponType != null">#{couponType},</if>
            <if test="couponStatus != null">#{couponStatus},</if>
            <if test="couponName != null">#{couponName},</if>
            <if test="sendType != null">#{sendType},</if>
            <if test="sendTimeType != null">#{sendTimeType},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="moneyThreshold != null">#{moneyThreshold},</if>
            <if test="discountMoney != null">#{discountMoney},</if>
            <if test="discountPercent != null">#{discountPercent},</if>
            <if test="useScope != null">#{useScope},</if>
            <if test="validTimeType != null">#{validTimeType},</if>
            <if test="validStartTime != null">#{validStartTime},</if>
            <if test="validEndTime != null">#{validEndTime},</if>
            <if test="validDay != null">#{validDay},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
        </trim>
    </insert>
 
    <update id="updateCoupon" parameterType="Coupon">
        update t_coupon
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="couponType != null">coupon_type = #{couponType},</if>
            <if test="couponStatus != null">coupon_status = #{couponStatus},</if>
            <if test="couponName != null">coupon_name = #{couponName},</if>
            <if test="sendType != null">send_type = #{sendType},</if>
            <if test="sendTimeType != null">send_time_type = #{sendTimeType},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="moneyThreshold != null">money_threshold = #{moneyThreshold},</if>
            <if test="discountMoney != null">discount_money = #{discountMoney},</if>
            <if test="discountPercent != null">discount_percent = #{discountPercent},</if>
            <if test="useScope != null">use_scope = #{useScope},</if>
            <if test="validTimeType != null">valid_time_type = #{validTimeType},</if>
            <if test="validStartTime != null">valid_start_time = #{validStartTime},</if>
            <if test="validEndTime != null">valid_end_time = #{validEndTime},</if>
            <if test="validDay != null">valid_day = #{validDay},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
        </trim>
        where coupon_id = #{couponId}
    </update>
 
    <delete id="deleteCouponByCouponId" parameterType="String">
        delete from t_coupon where coupon_id = #{couponId}
    </delete>
 
    <delete id="deleteCouponByCouponIds" parameterType="String">
        delete from t_coupon where coupon_id in
        <foreach item="couponId" collection="array" open="(" separator="," close=")">
            #{couponId}
        </foreach>
    </delete>
 
    <select id="pageMgtCoupon" resultType="com.ruoyi.member.domain.vo.MgtCouponPageVo">
        SELECT 
        tc.coupon_id  couponId,
        tc.coupon_name  couponName,
        CASE tc.coupon_type
        WHEN 1 THEN '满减'
        WHEN 2 THEN '折扣'
        WHEN 3 THEN '代金'
        WHEN 4 THEN '商品'
        END couponType,
        tc.valid_time_type  validTimeType,
        tc.valid_start_time  validStartTime,
        tc.valid_end_time  validEndTime,
        tc.valid_day  validDay,
        CASE tc.send_limit_flag
            WHEN 1 THEN tc.send_limit_number
            WHEN 0 THEN '无限制'
            END sendCount,
        CASE tc.use_scope
            WHEN 1 THEN '全部商品'
            WHEN 2 THEN '指定商品'
            END useScope,
        CASE tc.send_type
            WHEN 1 THEN '手动获取'
            ELSE '指定发放'
            END sendType,
        CASE tc.send_target
            WHEN 2 THEN '全部用户'
            WHEN 3 THEN '会员用户'
            WHEN 4 THEN '非会员用户'
            WHEN 5 THEN '自定义'
            ELSE ''
            END sendTarget,
        tc.money_threshold  moneyThreshold,
        tc.discount_money  discountMoney,
        tc.discount_percent  discountPercent,
        tc.create_time  createTime
        FROM t_coupon tc
        WHERE tc.del_flag = 0 AND tc.audit_status = 2
        <if test="param.shopId==null">
            AND tc.coupon_from = 1
        </if>
        <if test="param.shopId!=null and param.shopId!=''">
            AND tc.shop_id = #{param.shopId}
        </if>
        <if test="param.couponName!=null and param.couponName!=''">
            AND tc.coupon_name LIKE CONCAT('%',#{param.couponName},'%')
        </if>
        <if test="param.createStartTime!=null and param.createStartTime!=''">
            AND Date(tc.create_time) &gt;= #{param.createStartTime}
        </if>
        <if test="param.createEndTime!=null and param.createEndTime!=''">
            AND Date(tc.create_time) &lt;= #{param.createEndTime}
        </if>
        ORDER BY tc.create_time DESC
    </select>
    
    <select id="listMgtCouponSimpleVo" resultType="com.ruoyi.member.domain.vo.MgtCouponSimpleListVo">
        SELECT
            coupon_id couponId,
            coupon_name couponName
        FROM t_coupon
        WHERE del_flag = 0 AND coupon_status = 1 AND audit_status = 2
        <if test="param.shopId!=null and param.shopId!='' ">
            AND shop_id = #{param.shopId}
        </if>
 
    </select>
 
    <select id="pageMgtAuditCoupon" resultType="com.ruoyi.member.domain.vo.MgtCouponAuditPageVo">
        SELECT
        tc.coupon_id  couponId,
        tc.shop_id shopId,
        tc.coupon_name  couponName,
        tc.valid_time_type  validTimeType,
        tc.valid_start_time  validStartTime,
        tc.valid_end_time  validEndTime,
        tc.valid_day  validDay,
        CASE tc.coupon_type
        WHEN 1 THEN '满减'
        WHEN 2 THEN '折扣'
        WHEN 3 THEN '代金'
        WHEN 4 THEN '商品'
        END couponType,
        CASE tc.use_scope
        WHEN 1 THEN '全场通用'
        WHEN 2 THEN '指定商品'
        END useScope,
        CASE tc.send_type
        WHEN 1 THEN '手动领取'
        ELSE '指定发放'
        END sendType,
        CASE tc.send_target
        WHEN 2 THEN '全部用户'
        WHEN 3 THEN '会员用户'
        WHEN 4 THEN '非会员用户'
        WHEN 5 THEN '自定义'
        ELSE ''
        END sendTarget,
        tc.limit_number  limitNumber,
        tc.send_time  sendTime,
        tc.create_time  createTime,
        tc.money_threshold  moneyThreshold,
        tc.discount_money  discountMoney,
        tc.discount_percent  discountPercent,
        CASE tc.audit_status
            WHEN 2 THEN '审核通过'
            WHEN 3 THEN '审核拒绝'
            ELSE '审核中'
            END auditStatus
        FROM t_coupon tc
        WHERE tc.del_flag = 0 AND tc.coupon_from = 2
        <if test="param.auditStatus!=null and param.auditStatus!=''">
            AND tc.audit_status = #{param.auditStatus}
        </if>
        <if test="param.couponName!=null and param.couponName!=''">
            AND tc.coupon_name LIKE CONCAT('%',#{param.couponName},'%')
        </if>
        <if test="param.createStartTime!=null and param.createStartTime!=''">
            AND Date(tc.create_time) &gt;= #{param.createStartTime}
        </if>
        <if test="param.createEndTime!=null and param.createEndTime!=''">
            AND Date(tc.create_time) &lt;= #{param.createEndTime}
        </if>
        ORDER BY tc.create_time DESC
    </select>
 
    <update id="updateCouponTotal">
        UPDATE t_coupon_total set send_count = send_count + #{sendTotal}, send_user_count = send_user_count + #{sendPerson} WHERE coupon_id = #{couponId}
    </update>
 
    <select id="pagePlatformMerCoupon" resultType="com.ruoyi.member.domain.vo.MerCouponPageVo">
        SELECT
        tc.coupon_id  couponId,
        tc.coupon_name  couponName,
        tc.coupon_type  couponType,
        tc.valid_time_type  validTimeType,
        tc.valid_start_time  validStartTime,
        tc.valid_end_time  validEndTime,
        tc.valid_day  validDay,
        tct.send_count  sendCount,
        CASE tc.use_scope
        WHEN 1 THEN '全部商品'
        WHEN 2 THEN '指定商品'
        END useScope,
        CASE tc.send_type
        WHEN 1 THEN '手动获取'
        ELSE '指定发放'
        END sendType,
        CASE tc.send_target
        WHEN 2 THEN '全部用户'
        WHEN 3 THEN '会员用户'
        WHEN 4 THEN '非会员用户'
        WHEN 5 THEN '自定义'
        ELSE ''
        END sendTarget,
        tc.money_threshold  moneyThreshold,
        tc.discount_money  discountMoney,
        tc.discount_percent  discountPercent,
        tc.create_time  createTime,
        tc.propaganda_poster propagandaPoster,
        CASE WHEN tc.send_limit_flag = 1 THEN tc.send_limit_number ELSE NULL END sendLimitNumber,
        tc.limit_number limitNumber
        FROM t_coupon tc
        LEFT JOIN t_coupon_total tct ON tc.coupon_id = tct.coupon_id
        WHERE tc.del_flag = 0 AND tc.coupon_status = 1 AND tc.coupon_from = 1
    </select>
 
    <select id="pageShopMerCoupon" resultType="com.ruoyi.member.domain.vo.MerCouponPageVo">
        SELECT
            tc.coupon_id  couponId,
            tc.coupon_name  couponName,
            tc.coupon_type  couponType,
            tc.valid_time_type  validTimeType,
            tc.valid_start_time  validStartTime,
            tc.valid_end_time  validEndTime,
            tc.valid_day  validDay,
            tct.send_count  sendCount,
            CASE tc.use_scope
                WHEN 1 THEN '全部商品'
                WHEN 2 THEN '指定商品'
                END useScope,
            CASE tc.send_type
                WHEN 1 THEN '手动获取'
                ELSE '指定发放'
                END sendType,
            CASE tc.send_target
                WHEN 2 THEN '全部用户'
                WHEN 3 THEN '会员用户'
                WHEN 4 THEN '非会员用户'
                WHEN 5 THEN '自定义'
                ELSE ''
                END sendTarget,
            tc.money_threshold  moneyThreshold,
            tc.discount_money  discountMoney,
            tc.discount_percent  discountPercent,
            tc.create_time  createTime,
            tc.audit_reason auditReason,
            tc.limit_number limitNumber,
            CASE WHEN tc.send_limit_flag = 1 THEN tc.send_limit_number ELSE NULL END sendLimitNumber
        FROM t_coupon tc
                 LEFT JOIN t_coupon_total tct ON tc.coupon_id = tct.coupon_id
        WHERE tc.del_flag = 0 AND tc.coupon_status = 1 AND tc.coupon_from = 2 AND tc.shop_id = #{param.shopId}
        <if test="param.auditStatus != null and param.auditStatus != ''">
            AND tc.audit_status = #{param.auditStatus}
        </if>
        ORDER BY tc.create_time DESC
    </select>
 
    <select id="listUserUnGetCoupon" resultType="java.lang.String">
        SELECT
            tc.coupon_id
        FROM t_coupon tc
        LEFT JOIN t_member_coupon_record tmcr ON tc.coupon_id = tmcr.coupon_id AND tmcr.user_id = #{userId}
        WHERE tc.del_flag = 0 AND tc.coupon_status = 1 AND tc.audit_status=2 AND tc.send_type = 1 AND tmcr.limit_flag = 1
    </select>
 
    <select id="listUnGetCoupon" resultType="java.lang.String">
        SELECT
            tc.coupon_id
        FROM t_coupon tc
        INNER JOIN t_coupon_total tct ON tc.coupon_id = tct.coupon_id
        WHERE tc.del_flag = 0 AND tc.coupon_status = 1 AND tc.audit_status=2 AND tc.send_limit_flag = 1 AND tc.send_limit_number &lt;= tct.send_count
    </select>
 
    <select id="getAbleCouponPageVoList" resultType="com.ruoyi.member.domain.vo.AppGetAbleCouponPageVo">
        SELECT
            tc.coupon_id couponId,
            tc.coupon_name couponName,
            tc.coupon_type  couponType,
            tc.money_threshold moneyThreshold,
            tc.discount_money discountMoney,
            tc.discount_percent discountPercent,
            tc.shop_id shopId,
            CASE WHEN tc.coupon_type = 4 THEN tc.rel_goods_ids WHEN tc.use_scope = 2 THEN tc.rel_goods_ids ELSE NULL END relGoodsIds,
            CASE tc.valid_time_type WHEN 1 THEN CONCAT(DATE_FORMAT(tc.valid_start_time, '%Y.%m.%d'),'-',DATE_FORMAT(tc.valid_end_time, '%Y.%m.%d')) WHEN 2 THEN CONCAT('领取后',tc.valid_day,'天有效') ELSE NULL END validTime
        FROM t_coupon tc
        WHERE tc.del_flag = 0 AND tc.coupon_status = 1 AND tc.audit_status = 2 AND tc.send_type = 1 AND (tc.coupon_from = 1 OR (tc.coupon_from = 2 AND tc.shop_id = #{shopId}))
        AND IF(tc.valid_time_type = 1 , NOW() &lt; valid_end_time, 1 = 1)
        AND (tc.send_target = 2
             <if test="memberFlag != null and memberFlag = 1">
                 OR tc.send_target = 3
             </if>
             <if test="memberFlag != null and memberFlag = 0">
                 OR tc.send_target = 4
             </if>
             OR (tc.send_target = 5 AND FIND_IN_SET(#{userId},tc.rel_user_ids) &gt; 0)
             )
        <if test="unGetList != null and unGetList.size()>0">
            AND tc.coupon_id NOT IN
            <foreach collection="unGetList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY tc.create_time DESC
    </select>
</mapper>