TbCouponUserMapper.xml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.sqx.modules.coupon.dao.TbCouponUserDao">
  4. <select id="selectCouponList" resultType="com.sqx.modules.coupon.entity.TbCouponUser">
  5. select * from tb_coupon_user where user_id = #{userId} and status = 0
  6. <if test="format!=null and format!=''">
  7. and date_format(expiration_time,'%Y-%m-%d') &gt; date_format(#{format},'%Y-%m-%d')
  8. </if>
  9. <if test="minMoney!=null and minMoney!=''">
  10. and ((min_money &lt;= #{minMoney} and shop_id=0) or (min_money &lt;= #{minMoney} and shop_id=#{shopId}))
  11. </if>
  12. order by expiration_time asc
  13. </select>
  14. <select id="CouponList" resultType="com.sqx.modules.coupon.entity.TbCouponUser">
  15. select * from tb_coupon_user where user_id = #{userId}
  16. <if test="status!=null">
  17. and status = #{status}
  18. </if>
  19. order by create_time desc
  20. </select>
  21. <update id="updateExpiration">
  22. update tb_coupon_user set status = 2 where status = 0 and date_format(expiration_time,'%Y-%m-%d %H:%i:%S') &lt; date_format(now(),'%Y-%m-%d %H:%i:%S')
  23. </update>
  24. <select id="selectCouponByUserId" resultType="com.sqx.modules.coupon.entity.TbCouponUser">
  25. select tcu.*, tu.nick_name as nickName, tu.avatar as avatar, tu.phone as phone,g.shop_name as shopName
  26. from tb_coupon_user tcu
  27. left join tb_user tu on tcu.user_id = tu.user_id
  28. left join goods_shop g on g.shop_id=tcu.shop_id
  29. where 1 = 1
  30. <if test="userId!=null">
  31. and tcu.user_id = #{userId}
  32. </if>
  33. <if test="status!=null">
  34. and tcu.status = #{status}
  35. </if>
  36. <if test="phone!=null and phone!=''">
  37. and tu.phone = #{phone}
  38. </if>
  39. <if test="shopName!=null and shopName!=''">
  40. and g.shop_name like concat('%',#{shopName},'%')
  41. </if>
  42. <if test="shopId!=null">
  43. and tcu.shop_id=#{shopId}
  44. </if>
  45. <if test="shopFlag!=null and shopFlag == 1">
  46. and g.shop_id is null
  47. </if>
  48. <if test="shopFlag!=null and shopFlag == 2">
  49. and g.shop_id is not null
  50. </if>
  51. order by tcu.create_time desc
  52. </select>
  53. <select id="selectCountCoupon" resultType="int">
  54. select count(*) from tb_coupon_user where user_id = #{userId} and status = 0
  55. </select>
  56. <insert id="giveCoupon">
  57. insert into tb_coupon_user (user_id, coupon_name, coupon_picture, create_time, expiration_time, min_money, goods_type, money, status, end_time, shop_id) values
  58. <foreach collection="userIdList" item="item" separator=",">
  59. (#{item}, #{couponName}, #{couponPicture}, #{createTime}, #{expirationTime}, #{minMoney}, #{goodsType}, #{money}, #{status}, #{endTime}, #{shopId})
  60. </foreach>
  61. </insert>
  62. </mapper>