CmSvipHistoryMapper.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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.caimei.modules.supervip.dao.CmSvipHistoryDao">
  4. <sql id="cmSvipHistoryColumns">
  5. a.id AS "id",
  6. a.userId AS "userId",
  7. a.packageId AS "packageId",
  8. a.beginTime AS "beginTime",
  9. a.endTime AS "endTime",
  10. a.payWay AS "payWay",
  11. a.payType AS "payType",
  12. a.price AS "price",
  13. a.userBeans AS "userBeans",
  14. a.payTime AS "payTime"
  15. </sql>
  16. <sql id="cmSvipHistoryJoins">
  17. </sql>
  18. <insert id="giveVip">
  19. insert into cm_svip_user (userId, beginTime, endTime, delFlag, updateTime)
  20. values (#{userId}, #{beginTime}, #{endTime}, 0, #{beginTime})
  21. </insert>
  22. <insert id="insertHistory">
  23. insert into cm_svip_history(userId, packageId, beginTime, endTime, payStatus, payWay, price, userBeans, payTime)
  24. values (#{userId}, 0, #{beginTime}, #{endTime}, 1, #{payWay}, 0, 0, #{payTime})
  25. </insert>
  26. <update id="updateVip">
  27. UPDATE cm_svip_user
  28. SET
  29. <if test="beginTime != null">
  30. beginTime = #{beginTime},
  31. </if>
  32. endTime = #{endTime},
  33. updateTime = now()
  34. WHERE userId = #{userId}
  35. </update>
  36. <select id="get" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  37. SELECT
  38. <include refid="cmSvipHistoryColumns"/>
  39. FROM cm_svip_history a
  40. <include refid="cmSvipHistoryJoins"/>
  41. WHERE a.id = #{id}
  42. </select>
  43. <select id="findList" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  44. SELECT
  45. <include refid="cmSvipHistoryColumns"/>
  46. FROM cm_svip_history a
  47. <include refid="cmSvipHistoryJoins"/>
  48. <where>
  49. <if test="userId != null and userId != ''">
  50. AND a.userId = #{userId}
  51. </if>
  52. <if test="packageId != null and packageId != ''">
  53. AND a.packageId = #{packageId}
  54. </if>
  55. <if test="beginTime != null and beginTime != ''">
  56. AND a.beginTime = #{beginTime}
  57. </if>
  58. <if test="endTime != null and endTime != ''">
  59. AND a.endTime = #{endTime}
  60. </if>
  61. <if test="payTime != null and payTime != ''">
  62. AND a.payTime = #{payTime}
  63. </if>
  64. </where>
  65. <choose>
  66. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  67. ORDER BY ${page.orderBy}
  68. </when>
  69. <otherwise>
  70. </otherwise>
  71. </choose>
  72. </select>
  73. <select id="findAllList" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  74. SELECT
  75. <include refid="cmSvipHistoryColumns"/>
  76. FROM cm_svip_history a
  77. <include refid="cmSvipHistoryJoins"/>
  78. <where>
  79. </where>
  80. <choose>
  81. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  82. ORDER BY ${page.orderBy}
  83. </when>
  84. <otherwise>
  85. </otherwise>
  86. </choose>
  87. </select>
  88. <select id="findHistory" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  89. select
  90. cs.userId,
  91. cs.packageId,
  92. u.name as clubName,
  93. u.userName as linkMan,
  94. u.bindMobile as mobile,
  95. cs.beginTime,
  96. cs.price,
  97. cs.payWay,
  98. cs.payType,
  99. cs.userBeans,
  100. cs.payTime,
  101. cs.endTime
  102. from cm_svip_history cs
  103. LEFT JOIN club cb ON cs.userId = cb.userId
  104. left join user u on cs.userId = u.userID
  105. left join cm_svip_package cp on cp.id = cs.packageId
  106. where cs.userId = #{userId}
  107. AND cs.payStatus = '1'
  108. <if test="startPayTime != null and startPayTime != '' and endPayTime != null and endPayTime != ''">
  109. and (cs.payTime between #{startPayTime} and #{endPayTime})
  110. </if>
  111. <if test="startEndTime != null and startEndTime != '' and endEndTime != null and endEndTime != ''">
  112. and (cs.endTime between #{startEndTime} and #{endEndTime})
  113. </if>
  114. <if test="packageId != null and packageId != 0">
  115. and cp.duration = #{packageId}
  116. </if>
  117. <if test="packageId == 0">
  118. and cs.packageId = 0
  119. </if>
  120. <if test='status == "1"'>
  121. and (NOW() between cs.beginTime and cs.endTime)
  122. </if>
  123. <if test='status == "2"'>
  124. and NOW() > cs.endTime
  125. </if>
  126. <if test='status == "3"'>
  127. and cs.beginTime > NOW()
  128. </if>
  129. order by cs.payTime desc
  130. </select>
  131. <select id="findEndTime" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  132. select beginTime, endTime, updateTime
  133. from cm_svip_user
  134. where userId = #{userId}
  135. and endTime > now()
  136. </select>
  137. <select id="superFind" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  138. SELECT u.name as clubName, u.username as linkMan, u.bindMobile as mobile,
  139. cs.userId,cs.beginTime,cs.endTime,cs.packageId
  140. FROM cm_svip_history cs
  141. LEFT JOIN club cb ON cs.userId = cb.userId
  142. LEFT JOIN cm_svip_user cu ON cs.userId = cu.userId
  143. left join user u on cs.userId = u.userID
  144. left join cm_svip_package cp on cp.id = cs.packageId
  145. <where>
  146. AND cs.payStatus = '1'
  147. <if test="clubName != null and clubName != ''">
  148. and u.name like concat('%',#{clubName},'%')
  149. </if>
  150. <if test="linkMan != null and linkMan != ''">
  151. and u.username like concat('%',#{linkMan},'%')
  152. </if>
  153. <if test="mobile != null and mobile != ''">
  154. and u.bindMobile LIKE concat('%',#{mobile},'%')
  155. </if>
  156. <if test="startPayTime !=null and startPayTime != '' and endPayTime !=null and endPayTime!=''">
  157. and (cs.payTime between #{startPayTime} and #{endPayTime})
  158. </if>
  159. <if test="startEndTime !=null and startEndTime!='' and endEndTime!=null and endEndTime!=''">
  160. and (cu.endTime between #{startEndTime} and #{endEndTime})
  161. </if>
  162. <if test="packageId !=null and packageId != '' and packageId != 0">
  163. and cp.duration = #{packageId}
  164. </if>
  165. <if test="packageId == 0">
  166. and cs.packageId = 0
  167. </if>
  168. <if test='status == "1"'>
  169. and cu.endTime > NOW()
  170. </if>
  171. <if test='status == "2"'>
  172. and now() > cu.endTime
  173. </if>
  174. </where>
  175. group by cs.userId
  176. order by cs.payTime DESC
  177. </select>
  178. <select id="findOutEndTime" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  179. select beginTime, endTime, updateTime
  180. from cm_svip_user
  181. where userId = #{userId}
  182. and beginTime > now()
  183. </select>
  184. <select id="findPackage" resultType="java.lang.Integer">
  185. select id
  186. from cm_svip_package
  187. where duration = #{pac}
  188. </select>
  189. <select id="findDuration" resultType="java.lang.Integer">
  190. select duration
  191. from cm_svip_package
  192. where id = #{packageId}
  193. </select>
  194. <select id="findVipUser" resultType="com.caimei.modules.supervip.entity.CmSvipHistory">
  195. select beginTime, endTime, updateTime, userId
  196. from cm_svip_user
  197. where userId = #{userId}
  198. and delflag = 0
  199. </select>
  200. </mapper>