优惠券重写
This commit is contained in:
@@ -5,29 +5,97 @@
|
||||
<resultMap type="com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord" id="TbActivateInRecordMap">
|
||||
<result property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="vipUserId" column="vip_user_id" jdbcType="INTEGER"/>
|
||||
<result property="couponId" column="coupon_id" jdbcType="INTEGER"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="type" column="type" jdbcType="INTEGER"/>
|
||||
<result property="proId" column="pro_id" jdbcType="INTEGER"/>
|
||||
<result property="fullAmount" column="full_amount" jdbcType="INTEGER"/>
|
||||
<result property="discountAmount" column="discount_amount" jdbcType="INTEGER"/>
|
||||
<result property="num" column="num" jdbcType="INTEGER"/>
|
||||
<result property="overNum" column="over_num" jdbcType="INTEGER"/>
|
||||
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
|
||||
<result property="sourceActId" column="source_act_id" jdbcType="INTEGER"/>
|
||||
<result property="sourceFlowId" column="source_flow_id" jdbcType="INTEGER"/>
|
||||
<result property="useStartTime" column="use_start_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="useEndTime" column="use_end_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="couponJson" column="coupon_json" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
, vip_user_id, pro_id, num, over_num, shop_id, source_act_id, source_flow_id, create_time, update_time </sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, num, over_num, shop_id, source_act_id, source_flow_id, use_start_time, use_end_time, create_time, update_time, coupon_json </sql>
|
||||
|
||||
<!--查询单个-->
|
||||
<select id="queryById" resultMap="TbActivateInRecordMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
<include refid="Base_Column_List"/>
|
||||
|
||||
from tb_activate_in_record
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="queryByVipIdAndShopId" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo">
|
||||
SELECT
|
||||
inRecord.coupon_id as couponId,
|
||||
pro.id as proId,
|
||||
CASE
|
||||
WHEN inRecord.type = 1 THEN inRecord.NAME
|
||||
WHEN inRecord.type = 2 THEN pro.NAME
|
||||
END AS `name`,
|
||||
inRecord.type,
|
||||
inRecord.over_num as num,
|
||||
inRecord.use_end_time as endTime
|
||||
FROM
|
||||
tb_activate_in_record inRecord
|
||||
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}
|
||||
WHERE
|
||||
inRecord.vip_user_id = #{vipUserId}
|
||||
and inRecord.shop_id = #{shopId}
|
||||
and inRecord.over_num != 0
|
||||
and inRecord.use_start_time < now()
|
||||
and inRecord.use_end_time > now()
|
||||
order by inRecord.use_end_time asc
|
||||
</select>
|
||||
|
||||
<select id="queryByVipIdAndShopIdExpire" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo">
|
||||
SELECT
|
||||
CASE
|
||||
WHEN inRecord.type = 1 THEN inRecord.NAME
|
||||
WHEN inRecord.type = 2 THEN pro.NAME
|
||||
END AS `name`,
|
||||
inRecord.type,
|
||||
inRecord.over_num as num,
|
||||
inRecord.use_end_time as endTime
|
||||
FROM
|
||||
tb_activate_in_record inRecord
|
||||
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}
|
||||
WHERE
|
||||
inRecord.vip_user_id = #{vipUserId}
|
||||
and inRecord.shop_id = #{shopId}
|
||||
and inRecord.over_num != 0
|
||||
and inRecord.use_end_time < now()
|
||||
order by inRecord.use_end_time asc
|
||||
</select>
|
||||
|
||||
<select id="queryByVipIdAndShopIdIn" resultMap="TbActivateInRecordMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>,
|
||||
CASE
|
||||
WHEN inRecord.type = 1 THEN inRecord.NAME
|
||||
WHEN inRecord.type = 2 THEN pro.NAME
|
||||
END AS `name`
|
||||
FROM
|
||||
tb_activate_in_record inRecord
|
||||
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}
|
||||
WHERE
|
||||
inRecord.vip_user_id = #{vipUserId}
|
||||
and inRecord.shop_id = #{shopId}
|
||||
and inRecord.over_num != 0
|
||||
and inRecord.use_end_time < now()
|
||||
order by inRecord.use_end_time asc
|
||||
</select>
|
||||
|
||||
<!--查询剩余商品优惠卷数量-->
|
||||
<select id="countCouponNum" resultType="INTEGER">
|
||||
SELECT
|
||||
@@ -37,60 +105,10 @@
|
||||
INNER JOIN tb_shop_user vip ON record.vip_user_id = vip.id AND vip.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="queryByVipIdAndShopId" resultType="com.chaozhanggui.system.cashierservice.entity.TbProduct">
|
||||
SELECT
|
||||
tb_product.*, sum(tb_activate_in_record.over_num) as limitNumber
|
||||
FROM
|
||||
tb_activate_in_record
|
||||
LEFT JOIN tb_product ON tb_activate_in_record.pro_id = tb_product.id
|
||||
WHERE
|
||||
vip_user_id = #{vipUserId} and tb_activate_in_record.shop_id = #{shopId}
|
||||
group by tb_activate_in_record.pro_id
|
||||
</select>
|
||||
|
||||
<select id="queryVipPro" resultType="com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo">
|
||||
SELECT tb_product.name as detail,
|
||||
0 as status,
|
||||
sum(tb_activate_in_record.over_num) as num,
|
||||
tb_activate_in_record.shop_id as shopId,
|
||||
<choose>
|
||||
<when test="shopName != null and shopName != ''">#{shopName}</when>
|
||||
<otherwise>''</otherwise>
|
||||
</choose> AS shopName,
|
||||
2 as type
|
||||
FROM tb_activate_in_record
|
||||
LEFT JOIN tb_product ON tb_activate_in_record.pro_id = tb_product.id
|
||||
WHERE vip_user_id = #{vipUserId}
|
||||
and tb_activate_in_record.shop_id = #{shopId}
|
||||
and tb_activate_in_record.over_num!=0
|
||||
group by tb_activate_in_record.pro_id
|
||||
</select>
|
||||
|
||||
<select id="queryByVipIdAndShopIdAndProId" resultType="INTEGER">
|
||||
SELECT
|
||||
sum(tb_activate_in_record.num)
|
||||
FROM
|
||||
tb_activate_in_record
|
||||
WHERE
|
||||
vip_user_id = #{vipUserId} and shop_id = #{shopId} and pro_id = #{productId}
|
||||
</select>
|
||||
|
||||
<select id="queryAllByVipIdAndShopIdAndProId" resultMap="TbActivateInRecordMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from tb_activate_in_record
|
||||
WHERE
|
||||
vip_user_id = #{vipUserId}
|
||||
and shop_id = #{shopId}
|
||||
and pro_id = #{productId}
|
||||
and over_num > 0
|
||||
order by create_time
|
||||
</select>
|
||||
|
||||
<!--查询指定行数据-->
|
||||
<select id="queryAll" resultMap="TbActivateInRecordMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
<include refid="Base_Column_List"/>
|
||||
|
||||
from tb_activate_in_record
|
||||
<where>
|
||||
@@ -100,9 +118,24 @@
|
||||
<if test="vipUserId != null">
|
||||
and vip_user_id = #{vipUserId}
|
||||
</if>
|
||||
<if test="couponId != null">
|
||||
and coupon_id = #{couponId}
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
and name = #{name}
|
||||
</if>
|
||||
<if test="type != null">
|
||||
and type = #{type}
|
||||
</if>
|
||||
<if test="proId != null">
|
||||
and pro_id = #{proId}
|
||||
</if>
|
||||
<if test="fullAmount != null">
|
||||
and full_amount = #{fullAmount}
|
||||
</if>
|
||||
<if test="discountAmount != null">
|
||||
and discount_amount = #{discountAmount}
|
||||
</if>
|
||||
<if test="num != null">
|
||||
and num = #{num}
|
||||
</if>
|
||||
@@ -118,31 +151,36 @@
|
||||
<if test="sourceFlowId != null">
|
||||
and source_flow_id = #{sourceFlowId}
|
||||
</if>
|
||||
<if test="useStartTime != null">
|
||||
and use_start_time = #{useStartTime}
|
||||
</if>
|
||||
<if test="useEndTime != null">
|
||||
and use_end_time = #{useEndTime}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
and create_time = #{createTime}
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
and update_time = #{updateTime}
|
||||
</if>
|
||||
<if test="couponJson != null and couponJson != ''">
|
||||
and coupon_json = #{couponJson}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<!--新增所有列-->
|
||||
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into tb_activate_in_record(vip_user_id, pro_id, num, over_num, shop_id, source_act_id, source_flow_id,
|
||||
create_time, update_time)
|
||||
values (#{vipUserId}, #{proId}, #{num}, #{overNum}, #{shopId}, #{sourceActId}, #{sourceFlowId}, #{createTime},
|
||||
#{updateTime})
|
||||
insert into tb_activate_in_record(vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, num, over_num, shop_id, source_act_id, source_flow_id, use_start_time, use_end_time, create_time, update_time, coupon_json)
|
||||
values (#{vipUserId}, #{couponId}, #{name}, #{type}, #{proId}, #{fullAmount}, #{discountAmount}, #{num}, #{overNum}, #{shopId}, #{sourceActId}, #{sourceFlowId}, #{useStartTime}, #{useEndTime}, #{createTime}, #{updateTime}, #{couponJson})
|
||||
</insert>
|
||||
|
||||
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into tb_activate_in_record(vip_user_id, pro_id, num, over_num, shop_id, source_act_id, source_flow_id,
|
||||
create_time, update_time)
|
||||
insert into tb_activate_in_record(vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, num, over_num, shop_id, source_act_id, source_flow_id, use_start_time, use_end_time, create_time, update_time, coupon_json)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#{entity.vipUserId}, #{entity.proId}, #{entity.num}, #{entity.overNum}, #{entity.shopId},
|
||||
#{entity.sourceActId}, #{entity.sourceFlowId}, #{entity.createTime}, #{entity.updateTime})
|
||||
(#{entity.vipUserId}, #{entity.couponId}, #{entity.name}, #{entity.type}, #{entity.proId}, #{entity.fullAmount}, #{entity.discountAmount}, #{entity.num}, #{entity.overNum}, #{entity.shopId}, #{entity.sourceActId}, #{entity.sourceFlowId}, #{entity.useStartTime}, #{entity.useEndTime}, #{entity.createTime}, #{entity.updateTime}, #{entity.couponJson})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
@@ -153,9 +191,24 @@
|
||||
<if test="vipUserId != null">
|
||||
vip_user_id = #{vipUserId},
|
||||
</if>
|
||||
<if test="couponId != null">
|
||||
coupon_id = #{couponId},
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="type != null">
|
||||
type = #{type},
|
||||
</if>
|
||||
<if test="proId != null">
|
||||
pro_id = #{proId},
|
||||
</if>
|
||||
<if test="fullAmount != null">
|
||||
full_amount = #{fullAmount},
|
||||
</if>
|
||||
<if test="discountAmount != null">
|
||||
discount_amount = #{discountAmount},
|
||||
</if>
|
||||
<if test="num != null">
|
||||
num = #{num},
|
||||
</if>
|
||||
@@ -171,28 +224,28 @@
|
||||
<if test="sourceFlowId != null">
|
||||
source_flow_id = #{sourceFlowId},
|
||||
</if>
|
||||
<if test="useStartTime != null">
|
||||
use_start_time = #{useStartTime},
|
||||
</if>
|
||||
<if test="useEndTime != null">
|
||||
use_end_time = #{useEndTime},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="couponJson != null and couponJson != ''">
|
||||
coupon_json = #{couponJson},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
<update id="updateOverNumById">
|
||||
update tb_activate_in_record
|
||||
set
|
||||
over_num = #{overNum}
|
||||
where id = #{id};
|
||||
</update>
|
||||
|
||||
|
||||
<!--通过主键删除-->
|
||||
<delete id="deleteById">
|
||||
delete
|
||||
from tb_activate_in_record
|
||||
where id = #{id}
|
||||
delete from tb_activate_in_record where id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user