CouponMapper.xml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.cyksj.mapper.manage.coupon.CouponMapper">
  4. <insert id="batchSendCouponToUsers">
  5. insert into
  6. coupon_user(`user_id`,`coupon_id`,`channel`,`valid_start_time`,`valid_end_time`,`status`,`created_time`,`update_time`)
  7. values
  8. <foreach collection="userIds" item="userId" separator=",">
  9. (#{userId},#{couponId},#{channel},#{validStartTime},#{validEndTime},#{status},now(),now())
  10. </foreach>
  11. ON DUPLICATE KEY UPDATE coupon_id = VALUES(coupon_id)
  12. </insert>
  13. <select id="checkExCode" resultType="com.cyksj.model.dto.CouponPopularizeDto">
  14. select cp.id as couponId,
  15. cdp.id as popularizeId,
  16. cdp.user_id,
  17. cdp.distribute_id,
  18. cp.goods_sku_ids,
  19. cp.type,
  20. cp.use_scope,
  21. cp.scope,
  22. cdp.coupon_id as popularizeCouponId,
  23. cdp.is_general,
  24. cp.goods_type,
  25. cp.reduce_money,
  26. cp.reduce_condition,
  27. cp.discount,
  28. cp.valid_days,
  29. cp.valid_hours,
  30. cp.valid_start_time,
  31. cp.valid_end_time,
  32. cp.is_valid_time
  33. from `coupon` cp
  34. left join (select id, distribute_id,coupon_id, ex_code, user_id, is_general
  35. from `coupon_distribute_popularize`
  36. where deleted is true) cdp
  37. on cdp.coupon_id = cp.id
  38. where cp.deleted is true
  39. and (cp.ex_code = #{couponExCode} or cdp.ex_code = #{couponExCode}) limit 1
  40. </select>
  41. <select id="getRenewCouponBySkuId" resultType="com.cyksj.model.entity.Coupon">
  42. select c.id
  43. from coupon c
  44. inner join coupon_sku cs on cs.coupon_id = c.id and c.deleted is true and cs.deleted is true and
  45. cs.sku_id = #{skuId} and c.use_scope = 'renew'
  46. <if test="couponIds.size()>0">
  47. and c.id not in
  48. <foreach collection="couponIds" item="item" open="(" separator="," close=")">
  49. #{item}
  50. </foreach>
  51. </if>
  52. and c.classification_id = 8
  53. and (select count(*) from coupon_user where user_id = #{userId} and coupon_id = c.id) = 0
  54. order by discount desc limit 1
  55. </select>
  56. <select id="getCouponNameByIds" resultType="java.lang.String">
  57. select group_concat(name) from coupon where id in
  58. <foreach collection="list" item="item" open="(" separator="," close=")">
  59. #{item}
  60. </foreach>
  61. </select>
  62. </mapper>