From a02bed07c8281ae0fda850921eb7443393c5fb0c Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期日, 29 十二月 2024 13:59:29 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master-v4' into master-v4

---
 src/main/resources/mapper/coupon/CouponTemplateMapperCustom.xml |  166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 164 insertions(+), 2 deletions(-)

diff --git a/src/main/resources/mapper/coupon/CouponTemplateMapperCustom.xml b/src/main/resources/mapper/coupon/CouponTemplateMapperCustom.xml
index 1fca610..485f9b1 100644
--- a/src/main/resources/mapper/coupon/CouponTemplateMapperCustom.xml
+++ b/src/main/resources/mapper/coupon/CouponTemplateMapperCustom.xml
@@ -33,9 +33,10 @@
         <result column="usage_time_num" property="usageTimeNum" />
         <result column="status" property="status" />
         <result column="point" property="point" />
-        <result column="vip_grade" property="vipGrade" />
-
+        <result column="member_id" property="memberId" />
     </resultMap>
+
+
     <update id="activeBatchCouponTemplate">
         update t_coupon_template set status='active',update_by=#{param.updateBy},update_time=now() where id in
         <foreach collection="param.idList" item="item" open="(" separator="," close=")">
@@ -55,6 +56,12 @@
             #{item}
         </foreach>
     </update>
+    <update id="expireHomeActivityCouponTemplate">
+        update t_coupon_template set status='expired'  where  category='activity' and get_type='home' and status='active'
+    </update>
+    <update id="expireActivityCouponTemplateAll">
+        update t_coupon_template set status='expired'  where category='activity' and  get_end_date &lt; NOW()
+    </update>
 
     <select id="getCouponTemplatePage" resultType="com.mzl.flower.dto.response.coupon.CouponTemplateVO">
         <include refid="QuerySql2"/>
@@ -67,6 +74,120 @@
     </select>
     <select id="getPointPage" resultType="com.mzl.flower.dto.response.coupon.CouponTemplateVO">
         <include refid="QueryPointSql" />
+    </select>
+
+<!--    app活动优惠券-->
+    <select id="getActivityEffectList" resultType="com.mzl.flower.dto.response.coupon.CouponTemplateVO">
+
+        SELECT *
+        FROM t_coupon_template t
+        WHERE t.deleted = FALSE
+        <if test="param.category != null and param.category != '' and param.category == 'activity' ">
+            AND t.get_start_date &lt;= NOW()
+            AND NOW() &lt;= t.get_end_date
+        </if>
+
+        <if test="param.category != null and param.category != ''">
+            AND category =  #{param.category}
+        </if>
+        <if test="param.status != null and param.status != ''">
+            AND status =  #{param.status}
+        </if>
+        <if test="param.getType != null and param.getType != ''">
+            AND t.get_type =  #{param.getType}
+        </if>
+        ORDER BY t.create_time DESC
+
+    </select>
+    <select id="getCouponCustomerList"
+            resultType="com.mzl.flower.dto.response.coupon.CouponTemplateCustomerVO">
+        select ci.id,ci.name,u.tel
+        from t_coupon_template c
+        left JOIN t_coupon_template_customer cc
+        on c.id=cc.coupon_id
+        left join t_customer_info ci
+        on cc.custom_id=ci.id
+        left join t_user u
+        on ci.user_id=u.id
+        where c.deleted= false
+        and c.id=#{id}
+
+    </select>
+    <select id="getVipList" resultType="com.mzl.flower.dto.response.coupon.CouponTemplateVO">
+        <include refid="QuerySqlVip" />
+    </select>
+    <select id="getCouponTemplateVipPage" resultType="com.mzl.flower.dto.response.coupon.CouponTemplateVO">
+        <include refid="QuerySqlVip" />
+    </select>
+    <select id="getHomeActivityEffectAlert" resultType="com.mzl.flower.dto.response.coupon.CouponTemplateVO">
+        SELECT *
+        FROM t_coupon_template t
+        WHERE t.deleted = FALSE
+
+        <if test="param.category != null and param.category != '' and param.category == 'activity' ">
+            AND t.get_start_date &lt;= NOW()
+            AND NOW() &lt;= t.get_end_date
+        </if>
+
+        <if test="param.category != null and param.category != ''">
+            AND t.category =  #{param.category}
+        </if>
+        <if test="param.status != null and param.status != ''">
+            AND t.status =  #{param.status}
+        </if>
+        <if test="param.getType != null and param.getType != ''">
+            AND t.get_type =  #{param.getType}
+        </if>
+        ORDER BY t.create_time DESC
+        limit 1
+    </select>
+    <select id="getActivityEffectListWithMine"
+            resultType="com.mzl.flower.dto.response.coupon.CouponTemplateVO">
+        select t2.*,t2.get_limit,IFNULL(t2.get_limit- t2.getNum,0) as left_num  from (
+            SELECT
+                t.*,
+                (
+                    SELECT count( 1 )
+                    FROM t_coupon_record cr
+                    WHERE  cr.coupon_id = t.id AND cr.deleted = 0
+                    <if test="param.userId != null and param.userId != ''">
+                        AND cr.user_id = #{param.userId}
+                    </if>
+
+                ) AS getNum,
+                (
+                    SELECT min( cr.create_time )
+                    FROM t_coupon_record cr
+                    WHERE cr.coupon_id = t.id AND cr.deleted = 0
+                    <if test="param.userId != null and param.userId != ''">
+                        AND cr.user_id = #{param.userId}
+                    </if>
+                ) AS record_create_time
+            FROM
+            t_coupon_template t
+            WHERE
+            t.deleted = FALSE
+            <if test="param.category != null and param.category != '' and param.category == 'activity' ">
+                AND t.get_start_date &lt;= NOW()
+                AND NOW() &lt;= t.get_end_date
+            </if>
+
+            <if test="param.category != null and param.category != ''">
+                AND category =  #{param.category}
+            </if>
+            <if test="param.status != null and param.status != ''">
+                AND status =  #{param.status}
+            </if>
+            <if test="param.getType != null and param.getType != ''">
+                AND t.get_type =  #{param.getType}
+            </if>
+
+        ) t2
+
+        ORDER BY
+        left_num desc,
+        create_time DESC,
+        record_create_time ASC
     </select>
 
     <sql id="QueryPointSql">
@@ -129,4 +250,45 @@
         order by t.create_time desc
     </sql>
 
+    <sql id="QuerySqlVip">
+        select *
+        from (
+            select t.*,
+            create_by_user.nick_name as createByName,
+            IFNULL(get_num.cnt, 0) as getNum,
+            IFNULL(t.coupon_amount, 0) - IFNULL(get_num.cnt, 0) as unGetNum,
+            m.`name` as member_name
+            from t_coupon_template t
+            left join t_user create_by_user
+            on t.create_by =create_by_user.id
+            left join (select coupon_id,count(1) as cnt  from t_coupon_record where deleted=0 group by coupon_id) get_num
+            on t.id=get_num.coupon_id
+            left join t_member m
+            on t.member_id=m.id
+        ) t
+        where t.deleted=0
+        <if test="param.name != null and param.name != ''">
+            AND t.coupon_name like concat('%', #{param.name},'%')
+        </if>
+        <if test="param.couponDiscountType != null and param.couponDiscountType != ''">
+            AND t.coupon_discount_type =  #{param.couponDiscountType}
+        </if>
+        <if test="param.getType != null and param.getType != ''">
+            AND t.get_type =  #{param.getType}
+        </if>
+        <if test="param.getUserType != null and param.getUserType != ''">
+            AND t.get_user_type =  #{param.getUserType}
+        </if>
+        <if test="param.id != null and param.id != ''">
+            AND t.id =  #{param.id}
+        </if>
+        <if test="param.category != null and param.category != ''">
+            AND t.category =  #{param.category}
+        </if>
+        <if test="param.status != null and param.status != ''">
+            AND t.status =  #{param.status}
+        </if>
+        order by t.create_time desc
+    </sql>
+
 </mapper>

--
Gitblit v1.9.3