CouponMapper.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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.platform.yijia.dao.CouponMapper">
  4. <!--优惠券-->
  5. <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.Coupon">
  6. <id column="id" jdbcType="INTEGER" property="couponId" />
  7. <result column="station_id" jdbcType="INTEGER" property="stationId" />
  8. <result column="coupon_remark" jdbcType="VARCHAR" property="couponRemark" />
  9. <result column="coupon_name" jdbcType="VARCHAR" property="couponName" />
  10. <result column="coupon_type" jdbcType="VARCHAR" property="couponType" />
  11. <result column="coupon_threshold_amt" jdbcType="DECIMAL" property="couponThresholdAmt" />
  12. <result column="oil_name" jdbcType="VARCHAR" property="oilName" />
  13. <result column="oil_type" jdbcType="VARCHAR" property="oilType" />
  14. <result column="coupon_amt" jdbcType="DECIMAL" property="couponAmt" />
  15. <result column="coupon_num" jdbcType="INTEGER" property="couponNum" />
  16. <result column="effective_time_type" jdbcType="VARCHAR" property="effectiveTimeType" />
  17. <result column="effective_time_start" jdbcType="TIMESTAMP" property="effectiveTimeStart" />
  18. <result column="effective_time_end" jdbcType="TIMESTAMP" property="effectiveTimeEnd" />
  19. <result column="effective_day_num" jdbcType="INTEGER" property="effectiveDayNum" />
  20. <result column="coupon_receive_num" jdbcType="INTEGER" property="couponReceiveNum" />
  21. <result column="coupon_hold_num" jdbcType="INTEGER" property="couponHoldNum" />
  22. <result column="coupon_cumulative_num" jdbcType="INTEGER" property="couponCumulativeNum" />
  23. <result column="coupon_use_num" jdbcType="INTEGER" property="couponUseNum" />
  24. <result column="open_platform" jdbcType="VARCHAR" property="openPlatform" />
  25. <result column="grant_status" jdbcType="VARCHAR" property="grantStatus" />
  26. <result column="status" jdbcType="VARCHAR" property="status" />
  27. <result column="create_by" jdbcType="VARCHAR" property="createBy" />
  28. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  29. <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
  30. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  31. <result column="del_flag" jdbcType="VARCHAR" property="delFlag" />
  32. <result column="coupon_details" jdbcType="VARCHAR" property="couponDetails" />
  33. <result column="verification" jdbcType="VARCHAR" property="verification" />
  34. <result column="is_card_flag" jdbcType="VARCHAR" property="isCardFlag" />
  35. <result column="is_grade_flag" jdbcType="VARCHAR" property="isGradeFlag" />
  36. <result column="is_market_flag" jdbcType="VARCHAR" property="isMarketFlag" />
  37. <result column="available_control" jdbcType="VARCHAR" property="availableControl" />
  38. <result column="appointed_days" jdbcType="VARCHAR" property="appointedDays" />
  39. <result column="cycle_days" jdbcType="VARCHAR" property="cycleDays" />
  40. <result column="coupon_issue_id" jdbcType="VARCHAR" property="couponIssueId" />
  41. <result column="show_id" jdbcType="INTEGER" property="showId" />
  42. <result column="issue_type" jdbcType="VARCHAR" property="issueType" />
  43. <result column="issue_name" jdbcType="VARCHAR" property="issueName" />
  44. <result column="discount_threshold_amt" jdbcType="DECIMAL" property="discountThresholdAmt" />
  45. <collection property="couponVerificationList" select="selectCouponVerificationInfo"
  46. column="{param_station_id = station_id, param_coupon_id = id}" ofType="com.platform.yijia.pojo.CouponVerification"/>
  47. </resultMap>
  48. <!--发放方式,优惠劵信息-->
  49. <resultMap id="CouponIssueBaseResultMap" type="com.platform.yijia.pojo.CouponIssue">
  50. <result column="coupon_issue_id" jdbcType="VARCHAR" property="couponIssueId" />
  51. <result column="issue_type" jdbcType="VARCHAR" property="issueType" />
  52. <result column="issue_name" jdbcType="VARCHAR" property="issueName" />
  53. <result column="discount_threshold_amt" jdbcType="DECIMAL" property="discountThresholdAmt" />
  54. <result column="status" jdbcType="VARCHAR" property="status" />
  55. <result column="station_id" jdbcType="INTEGER" property="stationId" />
  56. <result column="create_by" jdbcType="VARCHAR" property="createBy" />
  57. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  58. <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
  59. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  60. <result column="show_id" jdbcType="VARCHAR" property="showId" />
  61. <result column="available_control" jdbcType="VARCHAR" property="availableControl" />
  62. <result column="appointed_days" jdbcType="TIMESTAMP" property="appointedDays" />
  63. <result column="cycle_days" jdbcType="VARCHAR" property="cycleDays" />
  64. <result column="give_limit" jdbcType="INTEGER" property="giveLimit" />
  65. <result column="give_count" jdbcType="INTEGER" property="giveCount" />
  66. </resultMap>
  67. <!--用户优惠券-->
  68. <resultMap id="UserCouponsBaseResultMap" type="com.platform.yijia.pojo.UserCoupon">
  69. <result column="id" jdbcType="VARCHAR" property="id" />
  70. <result column="coupon_id" jdbcType="VARCHAR" property="couponId" />
  71. <result column="union_id" jdbcType="VARCHAR" property="unionId" />
  72. <result column="coupon_is_used" jdbcType="VARCHAR" property="couponIsUsed" />
  73. <result column="coupon_no" jdbcType="VARCHAR" property="couponNo" />
  74. <result column="coupon_is_effective" jdbcType="VARCHAR" property="couponIsEffective" />
  75. <result column="get_coupon_time" jdbcType="TIMESTAMP" property="getCouponTime" />
  76. <result column="coupon_effective_time" jdbcType="TIMESTAMP" property="couponEffectiveTime" />
  77. <result column="verification_time" jdbcType="TIMESTAMP" property="verificationTime" />
  78. <result column="station_id" jdbcType="INTEGER" property="stationId" />
  79. <result column="coupon_name" jdbcType="VARCHAR" property="couponName" />
  80. <result column="coupon_type" jdbcType="VARCHAR" property="couponType" />
  81. <result column="coupon_details" jdbcType="VARCHAR" property="couponDetails" />
  82. <result column="coupon_threshold_amt" jdbcType="DECIMAL" property="couponThresholdAmt" />
  83. <result column="oil_name" jdbcType="VARCHAR" property="oilName" />
  84. <result column="oil_type" jdbcType="VARCHAR" property="oilType" />
  85. <result column="coupon_remark" jdbcType="VARCHAR" property="couponRemark" />
  86. <result column="coupon_amt" jdbcType="DECIMAL" property="couponAmt" />
  87. <result column="coupon_num" jdbcType="INTEGER" property="couponNum" />
  88. <result column="effective_time_type" jdbcType="VARCHAR" property="effectiveTimeType" />
  89. <result column="effective_time_start" jdbcType="TIMESTAMP" property="effectiveTimeStart" />
  90. <result column="effective_time_end" jdbcType="TIMESTAMP" property="effectiveTimeEnd" />
  91. <result column="effective_day_num" jdbcType="INTEGER" property="effectiveDayNum" />
  92. <result column="coupon_receive_num" jdbcType="INTEGER" property="couponReceiveNum" />
  93. <result column="coupon_cumulative_num" jdbcType="INTEGER" property="couponCumulativeNum" />
  94. <result column="coupon_use_num" jdbcType="INTEGER" property="couponUseNum" />
  95. <result column="open_platform" jdbcType="VARCHAR" property="openPlatform" />
  96. <result column="grant_status" jdbcType="VARCHAR" property="grantStatus" />
  97. <result column="status" jdbcType="VARCHAR" property="status" />
  98. <result column="create_by" jdbcType="VARCHAR" property="createBy" />
  99. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  100. <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
  101. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  102. <result column="del_flag" jdbcType="VARCHAR" property="delFlag" />
  103. <result column="coupon_details" jdbcType="VARCHAR" property="couponDetails" />
  104. <result column="verification" jdbcType="VARCHAR" property="verification" />
  105. <result column="is_card_flag" jdbcType="VARCHAR" property="isCardFlag" />
  106. <result column="is_grade_flag" jdbcType="VARCHAR" property="isGradeFlag" />
  107. <result column="is_market_flag" jdbcType="VARCHAR" property="isMarketFlag" />
  108. <result column="available_control" jdbcType="VARCHAR" property="availableControl" />
  109. <result column="appointed_days" jdbcType="VARCHAR" property="appointedDays" />
  110. <result column="cycle_days" jdbcType="VARCHAR" property="cycleDays" />
  111. <result column="issue_name" jdbcType="VARCHAR" property="issueName" />
  112. <result column="canUse" jdbcType="VARCHAR" property="canUse" />
  113. <collection property="couponVerificationList" select="selectCouponVerificationInfo"
  114. column="{param_station_id = station_id, param_coupon_id = coupon_id}" ofType="com.platform.yijia.pojo.CouponVerification"/>
  115. </resultMap>
  116. <!---->
  117. <resultMap id="CouponUserGiveCountBaseResultMap" type="com.platform.yijia.pojo.CouponUserGiveCount">
  118. <result column="id" jdbcType="INTEGER" property="id" />
  119. <result column="union_id" jdbcType="VARCHAR" property="unionId" />
  120. <result column="station_id" jdbcType="INTEGER" property="stationId" />
  121. <result column="coupon_issue_id" jdbcType="VARCHAR" property="couponIssueId" />
  122. <result column="issue_give_count" jdbcType="INTEGER" property="issueGiveCount" />
  123. <result column="crete_time" jdbcType="TIMESTAMP" property="creteTime" />
  124. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  125. <result column="give_count" jdbcType="INTEGER" property="giveCount" />
  126. <result column="issueStatus" jdbcType="VARCHAR" property="issueStatus" />
  127. </resultMap>
  128. <!-- 核销站点-->
  129. <resultMap id="CouponVerificationBaseResultMap" type="com.platform.yijia.pojo.CouponVerification">
  130. <result column="dept_id" jdbcType="INTEGER" property="verification" />
  131. <result column="dept_name" jdbcType="VARCHAR" property="verificationName" />
  132. </resultMap>
  133. <sql id="UserCoupon_Base_Column_List">
  134. T1.id, T1.coupon_is_used, T1.coupon_no, T2.id AS coupon_id, T2.station_id, T2.coupon_name, T2.coupon_remark, T2.coupon_type, T2.coupon_threshold_amt, T2.oil_name, T2.oil_type, T2.coupon_amt, T2.effective_time_type,
  135. T2.effective_time_start, T2.effective_time_end, T2.effective_day_num, T2.coupon_cumulative_num, T2.coupon_use_num,
  136. T2.open_platform, T2.status, T2.create_by, T2.create_time, T2.update_by, T2.update_time, T2.del_flag, T2.coupon_details, T2.verification,
  137. T2.is_card_flag, T2.is_grade_flag, T2.is_market_flag, T2.edit_flag, T2.available_control, T2.appointed_days, T2.cycle_days
  138. </sql>
  139. <sql id="Coupon_Base_Column_List">
  140. T2.id, T2.station_id, T2.coupon_name, T2.coupon_type, T2.coupon_remark, T2.coupon_threshold_amt, T2.oil_name, T2.oil_type, T2.coupon_amt, T2.coupon_num, T2.effective_time_type,
  141. T2.effective_time_start, T2.effective_time_end, T2.effective_day_num, T2.coupon_receive_num, T2.coupon_hold_num, T2.coupon_cumulative_num, T2.coupon_use_num,
  142. T2.open_platform, T2.status, T2.create_by, T2.create_time, T2.update_by, T2.update_time, T2.del_flag, T2.coupon_details, T2.verification,
  143. T2.is_card_flag, T2.is_grade_flag, T2.is_market_flag, T2.edit_flag, T2.available_control, T2.appointed_days, T2.cycle_days
  144. </sql>
  145. <!--查询优惠券模板信息-->
  146. <select id="selectCouponTemplateInfo" parameterType="com.platform.yijia.pojo.Coupon" resultMap="BaseResultMap">
  147. SELECT
  148. <include refid="Coupon_Base_Column_List"/>
  149. FROM coupon_info AS T2
  150. <where>
  151. <if test="couponId !=null">
  152. T2.id = #{couponId}
  153. </if>
  154. </where>
  155. </select>
  156. <!--更新优惠券模板-->
  157. <update id="updateCouponInfo" parameterType="com.platform.yijia.pojo.Coupon">
  158. UPDATE coupon_info
  159. <set>
  160. <if test="couponCumulativeNum != null">
  161. coupon_cumulative_num = #{couponCumulativeNum},
  162. </if>
  163. <if test="couponUseNum != null">
  164. coupon_use_num = #{couponUseNum},
  165. </if>
  166. </set>
  167. <where>
  168. <if test="stationId !=null">
  169. AND station_id = #{stationId}
  170. </if>
  171. <if test="couponId !=null">
  172. AND id = #{couponId}
  173. </if>
  174. </where>
  175. </update>
  176. <!--查询领取方式信息-->
  177. <select id="selectCouponIssueList" parameterType="com.platform.yijia.pojo.CouponIssue" resultMap="CouponIssueBaseResultMap">
  178. SELECT
  179. id AS coupon_issue_id,
  180. issue_name,
  181. issue_type,
  182. discount_threshold_amt,
  183. status,
  184. station_id,
  185. create_by,
  186. create_time,
  187. update_by,
  188. update_time,
  189. show_id,
  190. available_control,
  191. appointed_days,
  192. cycle_days,
  193. give_count,
  194. give_limit
  195. FROM coupon_issue
  196. <where>
  197. <if test="stationId !=null ">
  198. station_id = #{stationId}
  199. </if>
  200. <if test="couponIssueId !=null ">
  201. AND id = #{couponIssueId}
  202. </if>
  203. <if test="issueType !=null ">
  204. AND issue_type = #{issueType}
  205. </if>
  206. <if test="status !=null ">
  207. AND status = #{status}
  208. </if>
  209. </where>
  210. </select>
  211. <!--获取油站所分发的加油券-->
  212. <select id="selectStaGrantCouponList" parameterType="com.platform.yijia.pojo.Coupon" resultMap="BaseResultMap">
  213. SELECT
  214. T2.id AS coupon_issue_id,
  215. T2.issue_name,
  216. T2.issue_type,
  217. T2.discount_threshold_amt,
  218. T2.station_id,
  219. T2.show_id,
  220. T3.id,
  221. T3.coupon_name,
  222. T3.coupon_amt,
  223. T3.coupon_threshold_amt,
  224. T3.coupon_type,
  225. T3.oil_name,
  226. T3.use_discount_type,
  227. T3.effective_time_type,
  228. T3.effective_time_start,
  229. T3.effective_time_end,
  230. T3.effective_day_num,
  231. T3.coupon_receive_num,
  232. T3.coupon_hold_num,
  233. T3.coupon_cumulative_num,
  234. T3.coupon_use_num,
  235. T3.coupon_remark,
  236. T3.open_platform,
  237. T3.coupon_details,
  238. T3.grant_status,
  239. T3.status,
  240. T3.create_time,
  241. T3.is_card_flag,
  242. T3.is_grade_flag,
  243. T3.is_market_flag,
  244. T3.available_control,
  245. T3.appointed_days,
  246. T3.edit_flag,
  247. T3.verification,
  248. T3.cycle_days
  249. FROM coupon_issue_relation AS T1
  250. LEFT JOIN coupon_issue AS T2 ON T1.issue_id = T2.id
  251. LEFT JOIN coupon_info AS T3 ON T1.coupon_id = T3.id
  252. <where>
  253. T2.status = "1"
  254. AND T3.del_flag = "0"
  255. AND T3.status = "1"
  256. <if test="stationId !=null">
  257. AND T2.station_id = #{stationId}
  258. AND T3.station_id = #{stationId}
  259. </if>
  260. <if test="couponIssueId !=null">
  261. AND T1.issue_id = #{couponIssueId}
  262. </if>
  263. <if test="issueType !=null">
  264. AND T2.issue_type = #{issueType}
  265. </if>
  266. </where>
  267. </select>
  268. <!--查询核销站点信息-->
  269. <select id="selectCouponVerificationInfo" parameterType="java.util.HashMap" resultMap="CouponVerificationBaseResultMap">
  270. SELECT
  271. T2.dept_id,
  272. T2.dept_name
  273. FROM
  274. coupon_info AS T1
  275. LEFT JOIN sys_dept AS T2 ON FIND_IN_SET(T2.dept_id, T1.verification)
  276. WHERE
  277. T1.station_id = #{param_station_id}
  278. AND T1.coupon_type = "3"
  279. AND T1.id = #{param_coupon_id}
  280. </select>
  281. <!--获取用户进入领取页面的次数-->
  282. <select id="selectCouponUserGiveCount" parameterType="com.platform.yijia.pojo.CouponUserGiveCount" resultMap="CouponUserGiveCountBaseResultMap">
  283. SELECT
  284. T1.id,
  285. T1.union_id,
  286. T1.station_id,
  287. T1.coupon_issue_id,
  288. T1.issue_give_count,
  289. T1.crete_time,
  290. T1.update_time,
  291. T2.give_count,
  292. T2.status AS issueId
  293. FROM
  294. coupon_user_give_count AS T1
  295. LEFT JOIN coupon_issue AS T2 ON T1.coupon_issue_id = T2.id
  296. <where>
  297. <if test="unionId !=null and unionId !=''">
  298. T1.union_id = #{unionId}
  299. </if>
  300. <if test="stationId !=null">
  301. AND T1.station_id = #{stationId}
  302. </if>
  303. <if test="couponIssueId !=null and couponIssueId !=''">
  304. AND T1.coupon_issue_id = #{couponIssueId}
  305. </if>
  306. <if test="id !=null">
  307. AND T1.id = #{id}
  308. </if>
  309. </where>
  310. </select>
  311. <!-- 更新用户进入页面次数-->
  312. <update id="updateCouponUserGiveCount" parameterType="com.platform.yijia.pojo.CouponUserGiveCount">
  313. UPDATE
  314. coupon_user_give_count
  315. <set>
  316. <if test="issueGiveCount != null">
  317. issue_give_count = #{issueGiveCount},
  318. </if>
  319. <if test="updateTime != null">
  320. update_time = #{updateTime},
  321. </if>
  322. </set>
  323. <where>
  324. <if test="unionId !=null and unionId !=''">
  325. union_id = #{unionId}
  326. </if>
  327. <if test="stationId !=null">
  328. AND station_id = #{stationId}
  329. </if>
  330. <if test="couponIssueId !=null and couponIssueId !=''">
  331. AND coupon_issue_id = #{couponIssueId}
  332. </if>
  333. <if test="id !=null">
  334. AND id = #{id}
  335. </if>
  336. </where>
  337. </update>
  338. <!-- 更新用户优惠券信息-->
  339. <update id="updateCouponUserInfo" parameterType="com.platform.yijia.pojo.UserCoupon">
  340. UPDATE coupon_user
  341. <set>
  342. <if test="updateTime != null">
  343. update_time = #{updateTime},
  344. </if>
  345. <if test="couponIsUsed != null">
  346. coupon_is_used = #{couponIsUsed},
  347. </if>
  348. <if test="verificationTime != null">
  349. verification_time = #{verificationTime},
  350. </if>
  351. </set>
  352. <where>
  353. <if test="unionId !=null and unionId !=''">
  354. union_id = #{unionId}
  355. </if>
  356. <if test="stationId !=null">
  357. AND station_id = #{stationId}
  358. </if>
  359. <if test="couponNo !=null and couponNo !=''">
  360. AND coupon_no = #{couponNo}
  361. </if>
  362. <if test="id !=null">
  363. AND id = #{id}
  364. </if>
  365. </where>
  366. </update>
  367. <!--核销记录-->
  368. <insert id="addCouponVerificationRecord" parameterType="com.platform.yijia.pojo.CouponVerification" >
  369. INSERT INTO coupon_verification_record
  370. <trim prefix="(" suffix=")" suffixOverrides=",">
  371. <if test="couponUserId !=null">
  372. coupon_user_id,
  373. </if>
  374. <if test="verification !=null">
  375. verification,
  376. </if>
  377. <if test="createTime !=null">
  378. create_time,
  379. </if>
  380. </trim>
  381. <trim prefix="values (" suffix=")" suffixOverrides=",">
  382. <if test="couponUserId !=null">
  383. #{couponUserId},
  384. </if>
  385. <if test="verification !=null">
  386. #{verification},
  387. </if>
  388. <if test="createTime !=null">
  389. #{createTime},
  390. </if>
  391. </trim>
  392. </insert>
  393. <!-- 更新核销用户信息-->
  394. <update id="updateCouponVerificationUser" parameterType="com.platform.yijia.pojo.CouponVerificationUser">
  395. UPDATE coupon_verification_user
  396. <set>
  397. <if test="mobilePhone != null">
  398. mobile_phone = #{mobilePhone},
  399. </if>
  400. </set>
  401. <where>
  402. <if test="unionId !=null and unionId !=''">
  403. union_id = #{unionId}
  404. </if>
  405. </where>
  406. </update>
  407. <!--核销人员-->
  408. <insert id="addCouponVerificationUser" parameterType="com.platform.yijia.pojo.CouponVerificationUser" >
  409. INSERT INTO coupon_verification_user
  410. <trim prefix="(" suffix=")" suffixOverrides=",">
  411. <if test="unionId !=null">
  412. union_id,
  413. </if>
  414. <if test="mobilePhone !=null">
  415. mobile_phone,
  416. </if>
  417. <if test="createTime !=null">
  418. create_time,
  419. </if>
  420. </trim>
  421. <trim prefix="values (" suffix=")" suffixOverrides=",">
  422. <if test="unionId !=null">
  423. #{unionId},
  424. </if>
  425. <if test="mobilePhone !=null">
  426. #{mobilePhone},
  427. </if>
  428. <if test="createTime !=null">
  429. #{createTime},
  430. </if>
  431. </trim>
  432. </insert>
  433. <!--查询核销站点信息-->
  434. <select id="selectCouponVerificationUserInfo" parameterType="com.platform.yijia.pojo.CouponVerificationUser" resultType="com.platform.yijia.pojo.CouponVerificationUser">
  435. SELECT
  436. T1.union_id AS unionId,
  437. T1.mobile_phone AS mobilePhone,
  438. T3.ji_bie AS jiBie,
  439. T2.dept_id AS stationId
  440. FROM coupon_verification_user AS T1
  441. LEFT JOIN sys_user AS T2 ON T1.mobile_phone = T2.phonenumber
  442. LEFT JOIN sys_dept AS T3 ON T2.dept_id = T3.dept_id
  443. <where>
  444. T3.ji_bie = "1" OR T3.ji_bie = "2"
  445. <if test="unionId !=null and unionId !=''">
  446. AND T1.union_id = #{unionId}
  447. </if>
  448. </where>
  449. </select>
  450. <!--新增用户进入领取页面的次数-->
  451. <insert id="addCouponUserGiveCount" parameterType="com.platform.yijia.pojo.CouponUserGiveCount" >
  452. INSERT INTO coupon_user_give_count
  453. <trim prefix="(" suffix=")" suffixOverrides=",">
  454. <if test="unionId !=null">
  455. union_id,
  456. </if>
  457. <if test="stationId !=null">
  458. station_id,
  459. </if>
  460. <if test="couponIssueId !=null">
  461. coupon_issue_id,
  462. </if>
  463. <if test="issueGiveCount !=null">
  464. issue_give_count,
  465. </if>
  466. <if test="creteTime !=null">
  467. crete_time,
  468. </if>
  469. <if test="updateTime !=null">
  470. update_time,
  471. </if>
  472. </trim>
  473. <trim prefix="values (" suffix=")" suffixOverrides=",">
  474. <if test="unionId !=null">
  475. #{unionId},
  476. </if>
  477. <if test="stationId !=null">
  478. #{stationId},
  479. </if>
  480. <if test="couponIssueId !=null">
  481. #{couponIssueId},
  482. </if>
  483. <if test="issueGiveCount !=null">
  484. #{issueGiveCount},
  485. </if>
  486. <if test="creteTime !=null">
  487. #{creteTime},
  488. </if>
  489. <if test="updateTime !=null">
  490. #{updateTime},
  491. </if>
  492. </trim>
  493. </insert>
  494. <!--获取用户某个加油券信息-->
  495. <select id="selectUserCouponInfo" parameterType="com.platform.yijia.pojo.UserCoupon" resultMap="UserCouponsBaseResultMap">
  496. SELECT
  497. <include refid="UserCoupon_Base_Column_List"/>
  498. FROM coupon_user AS T1
  499. LEFT JOIN coupon_info AS T2 ON T1.coupon_id = T2.id
  500. <where>
  501. <if test="id !=null">
  502. T1.id = #{id}
  503. </if>
  504. <if test="couponNo !=null">
  505. AND T1.coupon_no = #{couponNo}
  506. </if>
  507. <if test="unionId !=null">
  508. AND T1.union_id = #{unionId}
  509. </if>
  510. </where>
  511. </select>
  512. <!--用户已领取的该优惠券数量-->
  513. <select id="selectUserCouponCount" parameterType="com.platform.yijia.pojo.UserCoupon" resultType="int">
  514. SELECT
  515. COUNT(*)
  516. FROM
  517. coupon_user
  518. <where>
  519. coupon_is_effective ="1"
  520. <if test="unionId !=null and unionId !=''">
  521. AND coupon_id = #{couponId}
  522. </if>
  523. <if test="unionId !=null and unionId !=''">
  524. AND union_id = #{unionId}
  525. </if>
  526. <if test="couponIsUsed !=null and couponIsUsed !=''">
  527. AND coupon_is_used = #{couponIsUsed}
  528. </if>
  529. <if test="stationId !=null and stationId !=''">
  530. AND station_id = #{stationId}
  531. </if>
  532. </where>
  533. </select>
  534. <!--获取用户所拥有的加油券-->
  535. <select id="selectUserCoupons" parameterType="com.platform.yijia.pojo.UserCoupon" resultMap="UserCouponsBaseResultMap">
  536. SELECT
  537. T1.id,
  538. T1.union_id,
  539. T1.coupon_id,
  540. T1.coupon_no,
  541. T1.coupon_is_effective,
  542. T1.coupon_is_used,
  543. T1.get_coupon_time,
  544. T1.coupon_effective_time,
  545. T3.issue_name,
  546. T2.station_id,
  547. T2.oil_name,
  548. T2.oil_type,
  549. T2.coupon_remark,
  550. T2.coupon_name,
  551. T2.coupon_threshold_amt,
  552. T2.coupon_amt,
  553. T2.coupon_type,
  554. T2.coupon_details,
  555. T2.effective_time_type,
  556. T2.effective_time_start,
  557. T2.effective_time_end,
  558. T2.effective_day_num,
  559. T2.status,
  560. T2.create_time,
  561. T2.is_card_flag,
  562. T2.is_grade_flag,
  563. T2.is_market_flag,
  564. T2.available_control,
  565. CASE
  566. WHEN T2.available_control ='0' THEN CASE WHEN ( NOW() - T1.coupon_effective_time &lt;= 0) THEN 'true' ELSE 'false' END
  567. WHEN T2.available_control ='1' THEN CASE WHEN LOCATE(DATE_FORMAT(NOW(), '%w'), T2.cycle_days) THEN 'true' ELSE 'false' END
  568. WHEN T2.available_control ='2' THEN CASE WHEN LOCATE(DATE_FORMAT(NOW(), '%e')-1, T2.cycle_days) THEN 'true' ELSE 'false' END
  569. WHEN T2.available_control ='3' THEN CASE WHEN LOCATE(DATE_FORMAT(NOW(), '%Y-%d-%m'), T2.appointed_days) THEN 'true' ELSE 'false' END
  570. END AS canUse,
  571. T2.appointed_days,
  572. T2.edit_flag,
  573. T2.verification,
  574. T2.cycle_days
  575. FROM coupon_user AS T1
  576. LEFT JOIN coupon_info AS T2 ON T1.coupon_id = T2.id
  577. LEFT JOIN coupon_issue AS T3 ON T1.issue_id = T3.id
  578. <where>
  579. T2.status = "1"
  580. AND T2.del_flag = "0"
  581. <if test="stationId !=null and stationId !=''">
  582. AND T1.station_id = #{stationId}
  583. </if>
  584. <if test="noVerificationVerFlag !=null and noVerificationVerFlag =='0'.toString()">
  585. AND T2.coupon_type &lt;&gt; "3"
  586. </if>
  587. <if test="couponIsUsed !=null and couponIsUsed !=''">
  588. AND T1.coupon_is_used = #{couponIsUsed}
  589. </if>
  590. <if test="unionId !=null and unionId !=''">
  591. AND T1.union_id = #{unionId}
  592. </if>
  593. <if test="oilName !=null and oilName !=''">
  594. AND FIND_IN_SET(#{oilName}, T2.oil_name)
  595. </if>
  596. <choose>
  597. <when test="expireFlag !=null and expireFlag == '0'.toString()">
  598. AND T1.coupon_effective_time &gt;= #{currentTime}
  599. </when>
  600. <when test="expireFlag !=null and expireFlag == '1'.toString()">
  601. AND T1.coupon_effective_time &lt; #{currentTime}
  602. </when>
  603. </choose>
  604. </where>
  605. </select>
  606. <!--查询已核销的优惠券-->
  607. <select id="selectCouponVerificationList" parameterType="com.platform.yijia.pojo.UserCoupon" resultMap="UserCouponsBaseResultMap">
  608. SELECT
  609. T1.id,
  610. T1.union_id,
  611. T1.coupon_id,
  612. T1.coupon_no,
  613. T1.coupon_is_effective,
  614. T1.coupon_is_used,
  615. T1.get_coupon_time,
  616. T1.coupon_effective_time,
  617. T1.verification_time,
  618. T3.issue_name,
  619. T2.station_id,
  620. T2.oil_name,
  621. T2.oil_type,
  622. T2.coupon_name,
  623. T2.coupon_remark,
  624. T2.coupon_threshold_amt,
  625. T2.coupon_amt,
  626. T2.coupon_type,
  627. T2.coupon_details,
  628. T2.effective_time_type,
  629. T2.effective_time_start,
  630. T2.effective_time_end,
  631. T2.effective_day_num,
  632. T2.status,
  633. T2.create_time,
  634. T2.is_card_flag,
  635. T2.is_grade_flag,
  636. T2.is_market_flag,
  637. T2.available_control,
  638. CASE
  639. WHEN T2.available_control ='0' THEN CASE WHEN ( NOW() - T1.coupon_effective_time &lt;= 0) THEN 'true' ELSE 'false' END
  640. WHEN T2.available_control ='1' THEN CASE WHEN LOCATE(DATE_FORMAT(NOW(), '%w'), T2.cycle_days) THEN 'true' ELSE 'false' END
  641. WHEN T2.available_control ='2' THEN CASE WHEN LOCATE(DATE_FORMAT(NOW(), '%e')-1, T2.cycle_days) THEN 'true' ELSE 'false' END
  642. WHEN T2.available_control ='3' THEN CASE WHEN LOCATE(DATE_FORMAT(NOW(), '%Y-%d-%m'), T2.appointed_days) THEN 'true' ELSE 'false' END
  643. END AS canUse,
  644. T2.appointed_days,
  645. T2.edit_flag,
  646. T2.verification,
  647. T2.cycle_days
  648. FROM coupon_user AS T1
  649. LEFT JOIN coupon_info AS T2 ON T1.coupon_id = T2.id
  650. LEFT JOIN coupon_issue AS T3 ON T1.issue_id = T3.id
  651. LEFT JOIN sys_dept AS T4 ON T1.station_id = T4.dept_id
  652. <where>
  653. <if test="stationId !=null and stationId !=''">
  654. AND T1.station_id = #{stationId} OR FIND_IN_SET(#{stationId}, T2.verification)
  655. </if>
  656. <if test="groupId !=null and groupId !=''">
  657. AND T4.parent_id = #{groupId}
  658. </if>
  659. <if test="couponType !=null and couponType !=''">
  660. AND T2.coupon_type = #{couponType}
  661. </if>
  662. <if test="couponIsUsed !=null and couponIsUsed !=''">
  663. AND T1.coupon_is_used = #{couponIsUsed}
  664. </if>
  665. <if test="unionId !=null and unionId !=''">
  666. AND T1.union_id = #{unionId}
  667. </if>
  668. <if test="oilName !=null and oilName !=''">
  669. AND FIND_IN_SET(#{oilName}, T2.oil_name)
  670. </if>
  671. </where>
  672. </select>
  673. <!--用户获取优惠券-->
  674. <insert id="addUserCoupon" parameterType="com.platform.yijia.pojo.UserCoupon" >
  675. INSERT INTO coupon_user
  676. <trim prefix="(" suffix=")" suffixOverrides=",">
  677. <if test="unionId !=null">
  678. union_id,
  679. </if>
  680. <if test="couponId !=null">
  681. coupon_id,
  682. </if>
  683. <if test="issueId !=null">
  684. issue_id,
  685. </if>
  686. <if test="couponNo !=null">
  687. coupon_no,
  688. </if>
  689. <if test="couponIsUsed !=null">
  690. coupon_is_used,
  691. </if>
  692. <if test="couponIsEffective !=null">
  693. coupon_is_effective,
  694. </if>
  695. <if test="getCouponTime !=null">
  696. get_coupon_time,
  697. </if>
  698. <if test="stationId !=null">
  699. station_id,
  700. </if>
  701. <if test="couponEffectiveTime !=null">
  702. coupon_effective_time,
  703. </if>
  704. </trim>
  705. <trim prefix="values (" suffix=")" suffixOverrides=",">
  706. <if test="unionId !=null">
  707. #{unionId},
  708. </if>
  709. <if test="couponId !=null">
  710. #{couponId},
  711. </if>
  712. <if test="issueId !=null">
  713. #{issueId},
  714. </if>
  715. <if test="couponNo !=null">
  716. #{couponNo},
  717. </if>
  718. <if test="couponIsUsed !=null">
  719. #{couponIsUsed},
  720. </if>
  721. <if test="couponIsEffective !=null">
  722. #{couponIsEffective},
  723. </if>
  724. <if test="getCouponTime !=null">
  725. #{getCouponTime},
  726. </if>
  727. <if test="stationId !=null">
  728. #{stationId},
  729. </if>
  730. <if test="couponEffectiveTime !=null">
  731. #{couponEffectiveTime},
  732. </if>
  733. </trim>
  734. </insert>
  735. </mapper>