Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

1209 строки
48 KiB

  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.iformall.mapper.WxCouponOrderMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponOrder">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  7. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  8. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  9. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  10. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  11. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  12. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  13. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  14. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  15. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  16. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  17. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  18. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund" />
  19. <result column="verify_type" jdbcType="INTEGER" property="verifyType" />
  20. </resultMap>
  21. <sql id="allColumns">
  22. `id`,`tenant_id`,`coupon_id`,`coupon_type`,`c_user_id`,`owner_id`,`b_user_id`,`order_id`,`expired_time`,`coupon_order_status`,`create_date`,`update_date`,`coupon_price`, `auto_refund`, `verify_type`
  23. </sql>
  24. <sql id="dynamicWhereConditions">
  25. where 1 = 1
  26. <if test=" null != id ">
  27. and `id` = #{id}
  28. </if>
  29. <if test=" null != tenantId ">
  30. and `tenant_id` = #{tenantId}
  31. </if>
  32. <if test=" null != couponId ">
  33. and `coupon_id` = #{couponId}
  34. </if>
  35. <if test=" null != couponType ">
  36. and `coupon_type` = #{couponType}
  37. </if>
  38. <if test=" null != cUserId ">
  39. and `c_user_id` = #{cUserId}
  40. </if>
  41. <if test=" null != ownerId ">
  42. and `owner_id` = #{ownerId}
  43. </if>
  44. <if test=" null != bUserId ">
  45. and `b_user_id` = #{bUserId}
  46. </if>
  47. <if test=" null != orderId ">
  48. and `order_id` = #{orderId}
  49. </if>
  50. <if test=" null != expiredTime ">
  51. and `expired_time` = #{expiredTime}
  52. </if>
  53. <if test=" null != couponOrderStatus ">
  54. and `coupon_order_status` = #{couponOrderStatus}
  55. </if>
  56. <if test=" null != createDate ">
  57. and `create_date` = #{createDate}
  58. </if>
  59. <if test=" null != updateDate ">
  60. and `update_date` = #{updateDate}
  61. </if>
  62. <if test=" null != couponPrice ">
  63. and `coupon_price` = #{couponPrice}
  64. </if>
  65. <if test=" null != autoRefund ">
  66. and `auto_refund` = #{autoRefund}
  67. </if>
  68. <if test=" null != ids ">
  69. and id in
  70. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  71. #{idItem}
  72. </foreach>
  73. </if>
  74. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  75. </sql>
  76. <select id="findList" parameterType="com.iformall.domain.po.WxCouponOrder" resultMap="BaseResultMap">
  77. select <include refid="allColumns" /> from wx_coupon_order
  78. <include refid="dynamicWhereConditions" />
  79. </select>
  80. <update id="updateVerifyCouponOrder" parameterType="com.iformall.domain.po.WxCouponOrder">
  81. update wx_coupon_order
  82. set `coupon_order_status` = #{couponOrderStatus},
  83. `b_user_id` = #{bUserId},
  84. `update_date` = #{updateDate},
  85. `verify_type` = #{verifyType}
  86. where `tenant_id`=#{tenantId}
  87. and id=#{id} and `b_user_id` is null
  88. </update>
  89. <update id="updateVerifyCouponOrderStatus" parameterType="com.iformall.domain.po.WxCouponOrder">
  90. update wx_coupon_order
  91. set `coupon_order_status` = #{couponOrderStatus},
  92. `b_user_id` = #{bUserId},
  93. `update_date` = #{updateDate},
  94. `verify_type` = #{verifyType}
  95. where 1=1
  96. and `tenant_id`=#{tenantId}
  97. and id=#{id}
  98. <if test=" null == #{bUserId} ">
  99. and `b_user_id` is null
  100. </if>
  101. <if test=" null != #{bUserId} ">
  102. and `b_user_id` = #{bUserId}
  103. </if>
  104. </update>
  105. <update id="updateVerifyCouponOrderStatusForMicroPay" parameterType="com.iformall.domain.po.WxCouponOrder">
  106. update wx_coupon_order
  107. set `coupon_order_status` = #{couponOrderStatus},
  108. `b_user_id` = #{bUserId},
  109. `update_date` = #{updateDate},
  110. `verify_type` = #{verifyType}
  111. where 1=1
  112. and `tenant_id`=#{tenantId}
  113. and id=#{id}
  114. </update>
  115. <update id="cancelVerifyCouponOrder" parameterType="com.iformall.domain.po.WxCouponOrder">
  116. update wx_coupon_order
  117. set `coupon_order_status` = #{couponOrderStatus},
  118. `b_user_id` = null,
  119. `update_date` = #{updateDate},
  120. `verify_type` = null
  121. where `tenant_id`=#{tenantId}
  122. and id=#{id}
  123. </update>
  124. <select id="couponDataMap" resultType="com.iformall.domain.vo.MarkingCouponDataReportVo" parameterType="hashmap">
  125. SELECT DATE_FORMAT(create_date,'%m/%d') as createTime,
  126. COUNT(DISTINCT c_user_id) as couponUserCount,
  127. count(*) as couponCount,
  128. (select Count(*)
  129. from wx_coupon_order c
  130. where coupon_order_status=1
  131. AND DATE_FORMAT(create_date,'%m/%d')=createTime
  132. AND tenant_id=#{tenantId}
  133. AND c.update_date &gt;= #{startTime}
  134. AND c.update_date &lt;= #{endTime}) as verifyCount,
  135. (select Count(DISTINCT c_user_id)
  136. from wx_coupon_order d
  137. where coupon_order_status=1
  138. AND DATE_FORMAT(create_date,'%m/%d')=createTime
  139. AND tenant_id=#{tenantId}
  140. AND d.update_date &gt;= #{startTime}
  141. AND d.update_date &lt;= #{endTime}) as verifyUserCount
  142. from wx_coupon_order
  143. where tenant_id=#{tenantId}
  144. AND create_date &gt;= #{startTime}
  145. AND create_date &lt;= #{endTime}
  146. GROUP BY createTime
  147. </select>
  148. <select id="couponDataList" resultType="com.iformall.domain.vo.MarkingCouponDataReportVo" parameterType="hashmap">
  149. SELECT createTime,couponId,couponCount,couponUserCount,verifyCount,verifyUserCount
  150. from view_coupon_data
  151. where view_coupon_data.tenant_id=#{tenantId}
  152. <if test="startTime != null">
  153. and view_coupon_data.createTime &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d')
  154. </if>
  155. <if test="endTime != null">
  156. and view_coupon_data.createTime &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d')
  157. </if>
  158. <if test="couponType != null">
  159. and view_coupon_data.couponType = #{couponType}
  160. </if>
  161. <if test="couponTitle != null">
  162. and view_coupon_data.couponTitle like concat('%', #{couponTitle},'%')
  163. </if>
  164. order by view_coupon_data.createTime desc
  165. </select>
  166. <select id="touchUsersReportList" resultType="com.iformall.domain.vo.TouchUsersReportVo" parameterType="com.iformall.domain.dto.MarkingCouponDataReportDto">
  167. SELECT xTime, tenant_id, pv, uv, couponCount, userCount, verifyCount, verifyUserCount
  168. FROM view_touch_user
  169. WHERE view_touch_user.tenant_id=#{tenantId}
  170. <if test="startTime != null">
  171. and view_touch_user.xTime &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d')
  172. </if>
  173. <if test="endTime != null">
  174. and view_touch_user.xTime &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d')
  175. </if>
  176. GROUP BY xTime
  177. order by xTime desc
  178. </select>
  179. <select id="queryForSceneRepotyHistoryVerified" resultType="com.iformall.domain.vo.MarkingSceneDataVo" parameterType="hashmap">
  180. select DATE_FORMAT(update_date,'%Y-%m-%d') xTime, count(c.id) triggerCount
  181. from wx_coupon_order c
  182. where c.tenant_id = #{tenantId}
  183. and c.coupon_order_status = 1
  184. <if test=" null != startTime and null != endTime">
  185. and c.update_date BETWEEN #{startTime} and #{endTime}
  186. </if>
  187. group by xTime
  188. </select>
  189. <select id="queryForSceneRepotyHistoryOrdered" resultType="com.iformall.domain.vo.MarkingSceneDataVo" parameterType="hashmap">
  190. select DATE_FORMAT(update_date,'%Y-%m-%d') xTime, count(c.id) triggerCount
  191. from wx_coupon_order c
  192. where c.tenant_id = #{tenantId}
  193. <if test=" null != startTime and null != endTime">
  194. and c.create_date BETWEEN #{startTime} and #{endTime}
  195. </if>
  196. group by xTime
  197. </select>
  198. <select id="queryForSceneRepotyMechantHistoryOrdered" resultType="com.iformall.domain.vo.MarkingSceneDataVo" parameterType="hashmap">
  199. select DATE_FORMAT(update_date,'%Y-%m-%d') xTime, count(c.id) triggerCount
  200. from wx_coupon_order c left join wx_coupon_action_log cal on cal.tenant_id = c.tenant_id
  201. where cal.coupon_order_id=c.id
  202. and c.tenant_id=#{tenantId}
  203. <if test=" null != channelType and null != channelType">
  204. and cal.channel_type=#{channelType}
  205. </if>
  206. <if test=" null != startTime and null != endTime">
  207. and c.create_date BETWEEN #{startTime} and #{endTime}
  208. </if>
  209. group by xTime
  210. </select>
  211. <select id="queryPriceTotal" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="java.lang.Integer" >
  212. SELECT IFNULL(SUM(coupon_price),0) from wx_coupon_order
  213. where 1=1
  214. <if test=" null != tenantId">
  215. and tenant_id = #{tenantId}
  216. </if>
  217. <if test=" null != couponOrderStatus">
  218. and coupon_order_status = #{couponOrderStatus}
  219. </if>
  220. <if test=" null != cUserId">
  221. and c_user_id = #{cUserId}
  222. </if>
  223. <if test=" null != couponId ">
  224. and coupon_id = #{couponId}
  225. </if>
  226. <if test=" null != couponType ">
  227. and coupon_type = #{couponType}
  228. </if>
  229. <if test=" null != startTime">
  230. and create_date &gt;= #{startTime}
  231. </if>
  232. <if test=" null != endTime">
  233. and create_date &lt;= #{endTime}
  234. </if>
  235. </select>
  236. <select id="findCount" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="java.lang.Integer">
  237. select COUNT(*) FROM wx_coupon_order co
  238. <if test=" null != businessId ">
  239. inner join wx_coupon c
  240. on c.id = co.coupon_id
  241. and c.business = #{businessId}
  242. <if test=" null != subBusinessId ">
  243. and c.sub_business = #{subBusinessId}
  244. </if>
  245. </if>
  246. where 1=1
  247. <if test=" null != tenantId">
  248. and co.tenant_id = #{tenantId}
  249. </if>
  250. <if test=" null != couponOrderStatus">
  251. and co.coupon_order_status = #{couponOrderStatus}
  252. </if>
  253. <if test=" null != cUserId">
  254. and co.c_user_id = #{cUserId}
  255. </if>
  256. <if test=" null != couponId ">
  257. and co.coupon_id = #{couponId}
  258. </if>
  259. <if test=" null != couponType ">
  260. and co.coupon_type = #{couponType}
  261. </if>
  262. <if test=" 1 == couponOrderStatus">
  263. <if test=" null != startTime">
  264. and co.update_date &gt;= #{startTime}
  265. </if>
  266. <if test=" null != endTime">
  267. and co.update_date &lt;= #{endTime}
  268. </if>
  269. <if test=" 0 == timeSlot">
  270. and date_format(co.update_date,'%H:%m') &gt;= '06:00'
  271. and date_format(co.update_date,'%H:%m') &lt; '18:00'
  272. and date_format(co.update_date,'%w') in (1,2,3,4,5)
  273. </if>
  274. <if test=" 1 == timeSlot">
  275. and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
  276. and date_format(co.update_date,'%w') in (1,2,3,4))
  277. or
  278. ((date_format(co.update_date,'%H:%m') &lt; '06:00')
  279. and date_format(co.update_date,'%w') in (1,2,3,4,5)))
  280. </if>
  281. <if test=" 2 == timeSlot">
  282. and date_format(co.update_date,'%H:%m') &gt;= '06:00'
  283. and date_format(co.update_date,'%H:%m') &lt; '18:00'
  284. and date_format(co.update_date,'%w') in (0,6)
  285. </if>
  286. <if test=" 3 == timeSlot">
  287. and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
  288. and date_format(co.update_date,'%w') in (5,6,0))
  289. or
  290. ((date_format(co.update_date,'%H:%m') &lt; '06:00')
  291. and date_format(co.update_date,'%w') in (6,0)))
  292. </if>
  293. </if>
  294. <if test=" 1 != couponOrderStatus">
  295. <if test=" null != startTime">
  296. and co.create_date &gt;= #{startTime}
  297. </if>
  298. <if test=" null != endTime">
  299. and co.create_date &lt;= #{endTime}
  300. </if>
  301. <if test=" 0 == timeSlot">
  302. and date_format(co.create_date,'%H:%m') &gt;= '06:00'
  303. and date_format(co.create_date,'%H:%m') &lt; '18:00'
  304. and date_format(co.create_date,'%w') in (1,2,3,4,5)
  305. </if>
  306. <if test=" 1 == timeSlot">
  307. and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
  308. and date_format(co.create_date,'%w') in (1,2,3,4))
  309. or
  310. ((date_format(co.create_date,'%H:%m') &lt; '06:00')
  311. and date_format(co.create_date,'%w') in (1,2,3,4,5)))
  312. </if>
  313. <if test=" 2 == timeSlot">
  314. and date_format(co.create_date,'%H:%m') &gt;= '06:00'
  315. and date_format(co.create_date,'%H:%m') &lt; '18:00'
  316. and date_format(co.create_date,'%w') in (0,6)
  317. </if>
  318. <if test=" 3 == timeSlot">
  319. and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
  320. and date_format(co.create_date,'%w') in (5,6,0))
  321. or
  322. ((date_format(co.create_date,'%H:%m') &lt; '06:00')
  323. and date_format(co.create_date,'%w') in (6,0)))
  324. </if>
  325. </if>
  326. </select>
  327. <select id="getCountByBusinessId" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="hashmap">
  328. select c.business, COUNT(c.business) bu_count
  329. FROM wx_coupon_order co
  330. inner join wx_coupon c on c.id = co.coupon_id
  331. where 1=1
  332. <if test=" null != tenantId">
  333. and co.tenant_id = #{tenantId}
  334. </if>
  335. <if test=" null != couponOrderStatus">
  336. and co.coupon_order_status = #{couponOrderStatus}
  337. </if>
  338. <if test=" null != cUserId">
  339. and co.c_user_id = #{cUserId}
  340. </if>
  341. <if test=" null != couponId ">
  342. and co.coupon_id = #{couponId}
  343. </if>
  344. <if test=" null != couponType ">
  345. and co.coupon_type = #{couponType}
  346. </if>
  347. <if test=" 1 == couponOrderStatus">
  348. <if test=" null != startTime">
  349. and co.update_date &gt;= #{startTime}
  350. </if>
  351. <if test=" null != endTime">
  352. and co.update_date &lt;= #{endTime}
  353. </if>
  354. <if test=" 0 == timeSlot">
  355. and date_format(co.update_date,'%H:%m') &gt;= '06:00'
  356. and date_format(co.update_date,'%H:%m') &lt; '18:00'
  357. and date_format(co.update_date,'%w') in (1,2,3,4,5)
  358. </if>
  359. <if test=" 1 == timeSlot">
  360. and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
  361. and date_format(co.update_date,'%w') in (1,2,3,4))
  362. or
  363. ((date_format(co.update_date,'%H:%m') &lt; '06:00')
  364. and date_format(co.update_date,'%w') in (1,2,3,4,5)))
  365. </if>
  366. <if test=" 2 == timeSlot">
  367. and date_format(co.update_date,'%H:%m') &gt;= '06:00'
  368. and date_format(co.update_date,'%H:%m') &lt; '18:00'
  369. and date_format(co.update_date,'%w') in (0,6)
  370. </if>
  371. <if test=" 3 == timeSlot">
  372. and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
  373. and date_format(co.update_date,'%w') in (5,6,0))
  374. or
  375. ((date_format(co.update_date,'%H:%m') &lt; '06:00')
  376. and date_format(co.update_date,'%w') in (6,0)))
  377. </if>
  378. </if>
  379. <if test=" 1 != couponOrderStatus">
  380. <if test=" null != startTime">
  381. and co.create_date &gt;= #{startTime}
  382. </if>
  383. <if test=" null != endTime">
  384. and co.create_date &lt;= #{endTime}
  385. </if>
  386. <if test=" 0 == timeSlot">
  387. and date_format(co.create_date,'%H:%m') &gt;= '06:00'
  388. and date_format(co.create_date,'%H:%m') &lt; '18:00'
  389. and date_format(co.create_date,'%w') in (1,2,3,4,5)
  390. </if>
  391. <if test=" 1 == timeSlot">
  392. and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
  393. and date_format(co.create_date,'%w') in (1,2,3,4))
  394. or
  395. ((date_format(co.create_date,'%H:%m') &lt; '06:00')
  396. and date_format(co.create_date,'%w') in (1,2,3,4,5)))
  397. </if>
  398. <if test=" 2 == timeSlot">
  399. and date_format(co.create_date,'%H:%m') &gt;= '06:00'
  400. and date_format(co.create_date,'%H:%m') &lt; '18:00'
  401. and date_format(co.create_date,'%w') in (0,6)
  402. </if>
  403. <if test=" 3 == timeSlot">
  404. and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
  405. and date_format(co.create_date,'%w') in (5,6,0))
  406. or
  407. ((date_format(co.create_date,'%H:%m') &lt; '06:00')
  408. and date_format(co.create_date,'%w') in (6,0)))
  409. </if>
  410. </if>
  411. group by c.business
  412. </select>
  413. <select id="getCountBySubBusinessId" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="hashmap">
  414. select c.sub_business, COUNT(c.sub_business) bu_count
  415. FROM wx_coupon_order co
  416. <if test=" null != businessId ">
  417. inner join wx_coupon c on c.id = co.coupon_id and c.business = #{businessId}
  418. </if>
  419. where 1=1
  420. <if test=" null != tenantId">
  421. and co.tenant_id = #{tenantId}
  422. </if>
  423. <if test=" null != couponOrderStatus">
  424. and co.coupon_order_status = #{couponOrderStatus}
  425. </if>
  426. <if test=" null != cUserId">
  427. and co.c_user_id = #{cUserId}
  428. </if>
  429. <if test=" null != couponId ">
  430. and co.coupon_id = #{couponId}
  431. </if>
  432. <if test=" null != couponType ">
  433. and co.coupon_type = #{couponType}
  434. </if>
  435. <if test=" 1 == couponOrderStatus">
  436. <if test=" null != startTime">
  437. and co.update_date &gt;= #{startTime}
  438. </if>
  439. <if test=" null != endTime">
  440. and co.update_date &lt;= #{endTime}
  441. </if>
  442. <if test=" 0 == timeSlot">
  443. and date_format(co.update_date,'%H:%m') &gt;= '06:00'
  444. and date_format(co.update_date,'%H:%m') &lt; '18:00'
  445. and date_format(co.update_date,'%w') in (1,2,3,4,5)
  446. </if>
  447. <if test=" 1 == timeSlot">
  448. and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
  449. and date_format(co.update_date,'%w') in (1,2,3,4))
  450. or
  451. ((date_format(co.update_date,'%H:%m') &lt; '06:00')
  452. and date_format(co.update_date,'%w') in (1,2,3,4,5)))
  453. </if>
  454. <if test=" 2 == timeSlot">
  455. and date_format(co.update_date,'%H:%m') &gt;= '06:00'
  456. and date_format(co.update_date,'%H:%m') &lt; '18:00'
  457. and date_format(co.update_date,'%w') in (0,6)
  458. </if>
  459. <if test=" 3 == timeSlot">
  460. and ((date_format(co.update_date,'%H:%m') &gt;= '18:00'
  461. and date_format(co.update_date,'%w') in (5,6,0))
  462. or
  463. ((date_format(co.update_date,'%H:%m') &lt; '06:00')
  464. and date_format(co.update_date,'%w') in (6,0)))
  465. </if>
  466. </if>
  467. <if test=" 1 != couponOrderStatus">
  468. <if test=" null != startTime">
  469. and co.create_date &gt;= #{startTime}
  470. </if>
  471. <if test=" null != endTime">
  472. and co.create_date &lt;= #{endTime}
  473. </if>
  474. <if test=" 0 == timeSlot">
  475. and date_format(co.create_date,'%H:%m') &gt;= '06:00'
  476. and date_format(co.create_date,'%H:%m') &lt; '18:00'
  477. and date_format(co.create_date,'%w') in (1,2,3,4,5)
  478. </if>
  479. <if test=" 1 == timeSlot">
  480. and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
  481. and date_format(co.create_date,'%w') in (1,2,3,4))
  482. or
  483. ((date_format(co.create_date,'%H:%m') &lt; '06:00')
  484. and date_format(co.create_date,'%w') in (1,2,3,4,5)))
  485. </if>
  486. <if test=" 2 == timeSlot">
  487. and date_format(co.create_date,'%H:%m') &gt;= '06:00'
  488. and date_format(co.create_date,'%H:%m') &lt; '18:00'
  489. and date_format(co.create_date,'%w') in (0,6)
  490. </if>
  491. <if test=" 3 == timeSlot">
  492. and ((date_format(co.create_date,'%H:%m') &gt;= '18:00'
  493. and date_format(co.create_date,'%w') in (5,6,0))
  494. or
  495. ((date_format(co.create_date,'%H:%m') &lt; '06:00')
  496. and date_format(co.create_date,'%w') in (6,0)))
  497. </if>
  498. </if>
  499. group by c.sub_business
  500. </select>
  501. <select id="queryPriceTotalGroup" resultType="com.iformall.domain.vo.CUserDateAmountVo" >
  502. SELECT DATE_FORMAT(create_date,'%Y-%m-%d') as xTime,IFNULL(SUM(coupon_price),0) as price from wx_coupon_order
  503. where tenant_id=#{tenantId}
  504. AND create_date &gt;= #{startTime} and create_date &lt; #{endTime} GROUP BY xTime
  505. </select>
  506. <select id="findExpiredFreeCouponOrderByValidDate" parameterType="com.iformall.domain.po.WxCouponOrder" resultMap="BaseResultMap">
  507. select <include refid="allColumns" /> from wx_coupon_order
  508. where expired_time >= date_sub(curdate(),interval 360 day) and expired_time &lt; now() and coupon_price = 0 and coupon_order_status = 0
  509. </select>
  510. <select id="findExpiredCouponOrderByValidDate" parameterType="com.iformall.domain.po.WxCouponOrder" resultMap="BaseResultMap">
  511. select <include refid="allColumns" /> from wx_coupon_order
  512. where expired_time >= date_sub(curdate(),interval 360 day) and expired_time &lt; now() and coupon_price &gt; 0 and coupon_order_status = 0
  513. </select>
  514. <resultMap id="BVoResultMap" type="com.iformall.domain.vo.WxCouponOrderBVo">
  515. <id column="id" jdbcType="BIGINT" property="id" />
  516. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  517. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  518. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  519. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  520. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  521. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  522. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  523. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  524. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  525. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  526. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  527. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  528. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  529. <result column="type" jdbcType="INTEGER" property="type" />
  530. <result column="title" jdbcType="VARCHAR" property="title" />
  531. <result column="sale_price" jdbcType="INTEGER" property="salePrice" />
  532. <result column="use_price" jdbcType="INTEGER" property="usePrice" />
  533. <result column="price" jdbcType="INTEGER" property="price" />
  534. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund" />
  535. <result column="business" jdbcType="INTEGER" property="business"/>
  536. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  537. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  538. <result column="name" jdbcType="VARCHAR" property="bUserName" />
  539. <result column="bphone" jdbcType="VARCHAR" property="bUserPhone" />
  540. <result column="phone" jdbcType="VARCHAR" property="cUserPhone" />
  541. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
  542. <result column="verify_merchant_name" jdbcType="VARCHAR" property="verifyMerchantName"/>
  543. <collection column="{productId=coupon_id}" property="merchantVoList"
  544. ofType="com.iformall.domain.vo.WxMerchantVo"
  545. javaType="java.util.List"
  546. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantNameList" >
  547. </collection>
  548. </resultMap>
  549. <resultMap id="AdminBVoResultMap" type="com.iformall.domain.vo.WxCouponOrderBVo">
  550. <id column="id" jdbcType="BIGINT" property="id" />
  551. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  552. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  553. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  554. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  555. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  556. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  557. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  558. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  559. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  560. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  561. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  562. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  563. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  564. <result column="type" jdbcType="INTEGER" property="type" />
  565. <result column="title" jdbcType="VARCHAR" property="title" />
  566. <result column="sale_price" jdbcType="INTEGER" property="salePrice" />
  567. <result column="use_price" jdbcType="INTEGER" property="usePrice" />
  568. <result column="price" jdbcType="INTEGER" property="price" />
  569. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund" />
  570. <result column="business" jdbcType="INTEGER" property="business"/>
  571. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  572. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  573. <result column="name" jdbcType="VARCHAR" property="bUserName" />
  574. <result column="bphone" jdbcType="VARCHAR" property="bUserPhone" />
  575. <result column="phone" jdbcType="VARCHAR" property="cUserPhone" />
  576. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
  577. <result column="verify_merchant_name" jdbcType="VARCHAR" property="verifyMerchantName"/>
  578. </resultMap>
  579. <sql id="allAdminCouponOrderListColumns">
  580. <!--
  581. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,
  582. c.title,c.sale_price,c.use_price,c.price,c.unit,c.auto_refund,c.business,c.subsidy_type,ms.subsidy subsidy_num,
  583. (case when com.mc=1 then
  584. (select m.name from wx_merchant m, wx_coupon_merchant cm
  585. where m.id = cm.merchant_id and cm.product_id=co.coupon_id and cm.status = 0) else '[多商户通用]' end) as merchant_name,
  586. (case when com.mc = 1 then (select m.id from wx_merchant m,
  587. wx_coupon_merchant cm where m.id = cm.merchant_id and cm.product_id = co.coupon_id
  588. and cm.status = 0) else 0 end) as merchant_id,
  589. cu.phone,bu.verify_merchant_name,cal.channel_type
  590. (case when couc.mc = 1 then m1.name else '[多商户通用]' end) as merchant_name,
  591. (case when couc.mc = 1 then m1.id else 0 end) as merchant_id,
  592. cu.phone,m2.name as verify_merchant_name,cal.channel_type
  593. -->
  594. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,
  595. co.create_date,co.update_date,co.coupon_price, c.title,c.sale_price,c.use_price,c.price,
  596. c.unit,c.auto_refund,c.business,c.subsidy_type,ms.subsidy subsidy_num,
  597. (CASE WHEN couc.mc = 1 THEN m1.name ELSE '[多商户通用]' END) AS merchant_name,
  598. (CASE WHEN couc.mc = 1 THEN m1.id ELSE 0 END) AS merchant_id,
  599. cu.phone,m2.name AS verify_merchant_name,cal.channel_type
  600. </sql>
  601. <sql id="allAdminCouponOrderDetailColumns">
  602. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,
  603. c.type,c.title,c.sale_price,c.use_price,c.price,c.unit,c.auto_refund,c.business,c.subsidy_type,ms.subsidy subsidy_num,
  604. bu.name, bu.phone as bphone,
  605. cu.phone,
  606. m.name as merchant_name,m.id as merchant_id
  607. </sql>
  608. <select id="findListOfAdmin" parameterType="com.iformall.domain.vo.WxCouponOrderBVo" resultMap="AdminBVoResultMap">
  609. select <include refid="allAdminCouponOrderListColumns" />
  610. <!--
  611. from wx_coupon_order co
  612. inner join wx_coupon c on c.id = co.coupon_id
  613. inner join (select tco.id as tcoid,
  614. (select count(*) from wx_coupon_merchant tcm
  615. where tcm.product_id = tco.coupon_id
  616. and tcm.status = 0) as mc
  617. from wx_coupon_order tco) com on com.tcoid = co.id
  618. inner join wx_c_user cu on cu.id=co.c_user_id
  619. left join (
  620. select bu.id as bu_id,m.name as verify_merchant_name
  621. from wx_merchant_b_user bu inner join wx_merchant m on bu.merchant_id=m.id
  622. where bu.tenant_id = #{tenantId}
  623. ) bu on bu.bu_id = co.b_user_id
  624. left join wx_merchant_subsidy ms on co.id = ms.coupon_order_id and ms.type = 1
  625. left join wx_coupon_action_log cal on co.id = cal.coupon_order_id and co.coupon_id = cal.coupon_id
  626. -->
  627. <!--
  628. from (select wcm.product_id,wcm.merchant_id,count(1) as mc from wx_coupon_merchant wcm where status = 0 and wcm.tenant_id = #{tenantId} group by product_id) couc
  629. right join (select co.id,co.tenant_id,co.coupon_id,co.c_user_id,co.b_user_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price from wx_coupon_order co where co.tenant_id = #{tenantId}) co on co.coupon_id = couc.product_id
  630. inner join wx_c_user cu on cu.id=co.c_user_id
  631. left join wx_coupon c on c.id = co.coupon_id
  632. left join wx_merchant m1 on m1.id = couc.merchant_id
  633. left join wx_merchant_subsidy ms on co.id = ms.coupon_order_id and ms.type = 1
  634. left join wx_merchant_b_user mbu on mbu.id = co.b_user_id
  635. left join wx_merchant m2 on m2.id = mbu.merchant_id
  636. left join wx_coupon_action_log cal on cal.coupon_order_id = co.id and cal.coupon_id = co.coupon_id
  637. where 1=1-->
  638. FROM (
  639. SELECT wcm.product_id,wcm.merchant_id,COUNT(1) AS mc
  640. FROM wx_coupon_merchant wcm
  641. WHERE STATUS = 0 AND wcm.tenant_id = #{tenantId} GROUP BY product_id) couc
  642. RIGHT JOIN (
  643. SELECT co.id,co.tenant_id,co.coupon_id,co.c_user_id,co.b_user_id,co.coupon_type,
  644. co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price
  645. FROM wx_coupon_order co
  646. WHERE co.tenant_id = #{tenantId}) co
  647. ON co.coupon_id = couc.product_id
  648. INNER JOIN wx_c_user cu ON cu.id=co.c_user_id
  649. LEFT JOIN wx_coupon c ON c.id = co.coupon_id
  650. LEFT JOIN wx_merchant m1 ON m1.id = couc.merchant_id
  651. LEFT JOIN wx_merchant_subsidy ms ON co.id = ms.coupon_order_id AND ms.type = 1
  652. LEFT JOIN wx_merchant_b_user mbu ON mbu.id = co.b_user_id LEFT JOIN wx_merchant m2 ON m2.id = mbu.merchant_id
  653. LEFT JOIN wx_coupon_action_log cal ON cal.coupon_order_id = co.id AND cal.coupon_id = co.coupon_id
  654. where 1=1
  655. <choose>
  656. <when test=" null != couponType">
  657. and co.coupon_type = #{couponType}
  658. </when>
  659. <otherwise>
  660. and co.coupon_type &lt; 100
  661. </otherwise>
  662. </choose>
  663. <if test=" null != tenantId ">
  664. and co.tenant_id = #{tenantId}
  665. </if>
  666. <if test=" null != couponOrderStatus ">
  667. and co.coupon_order_status = #{couponOrderStatus}
  668. </if>
  669. <if test=" null != merchantName and merchantName!=''">
  670. and (case when couc.mc=1
  671. then
  672. m1.name
  673. <!--(select m.name from wx_merchant m, wx_coupon_merchant cm
  674. where m.id = cm.merchant_id
  675. and cm.product_id=co.coupon_id
  676. and cm.status = 0)-->
  677. else'[多商户通用]' end)
  678. like concat('%', #{merchantName},'%')
  679. </if>
  680. <if test="startDate != null">
  681. AND co.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  682. </if>
  683. <if test="endDate != null">
  684. AND co.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  685. </if>
  686. <if test="verifyStartDate != null">
  687. AND co.update_date &gt; #{verifyStartDate,jdbcType=TIMESTAMP}
  688. </if>
  689. <if test="verifyEndDate != null">
  690. AND co.update_date &lt; #{verifyEndDate,jdbcType=TIMESTAMP}
  691. </if>
  692. <if test=" null != id ">
  693. and co.id = #{id}
  694. </if>
  695. <if test=" null != couponId ">
  696. and c.id = #{couponId}
  697. </if>
  698. <if test=" null != business ">
  699. and c.business = #{business}
  700. </if>
  701. <if test=" null != verifyMerchantName and ''!= verifyMerchantName ">
  702. and bu.verify_merchant_name = #{verifyMerchantName}
  703. </if>
  704. <if test="null!=building">
  705. and co.coupon_id in(
  706. select cm.product_id from wx_merchant_shop ms left join wx_merchant m on ms.merchant_id=m.id
  707. left join wx_shop s on ms.shop_id=s.id
  708. left join wx_coupon_merchant cm on ms.merchant_id=cm.merchant_id
  709. where ms.is_del=0 and s.building=#{building}
  710. <if test=" null != tenantId ">
  711. and ms.tenant_id=#{tenantId}
  712. </if>
  713. <if test="null!=floor">
  714. and s.floor=#{floor}
  715. </if>
  716. )
  717. </if>
  718. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  719. <if test=" null == sortColumns">order by co.create_date desc,co.id desc</if>
  720. </select>
  721. <select id="findDetailOfAdmin" parameterType="java.lang.Long" resultMap="BVoResultMap">
  722. select <include refid="allAdminCouponOrderDetailColumns" />
  723. from wx_coupon c, wx_coupon_order co
  724. left join wx_c_user cu on cu.id = co.c_user_id
  725. left join wx_merchant_b_user bu on co.b_user_id = bu.id
  726. left join wx_merchant m on m.id = bu.merchant_id
  727. left join wx_merchant_subsidy ms on co.id = ms.coupon_order_id and ms.type = 1
  728. where co.id = #{id}
  729. and c.id = co.coupon_id
  730. </select>
  731. <sql id="allBUserVerifiedCouponOrderColumns">
  732. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,
  733. c.type,c.title,c.sale_price,c.use_price,c.price,c.unit,
  734. bu.name,
  735. cu.phone
  736. </sql>
  737. <sql id="allBUserOrderedCouponOrderColumns">
  738. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,
  739. c.type,c.title,c.sale_price,c.use_price,c.price,c.unit,
  740. cu.phone
  741. </sql>
  742. <select id="findListOfOrderedByDateForBUser" parameterType="map" resultMap="BVoResultMap">
  743. select <include refid="allBUserOrderedCouponOrderColumns" />
  744. from wx_coupon_order co,wx_coupon c,wx_c_user cu,wx_coupon_merchant cm,
  745. (select tco.id as tcoid,
  746. (select count(*) from wx_coupon_merchant tcm
  747. where tcm.product_id = tco.coupon_id
  748. and tcm.status = 0) as mc
  749. from wx_coupon_order tco) com
  750. where com.mc = 1
  751. and com.tcoid = co.id
  752. and cm.merchant_id = #{merchantId}
  753. and cm.product_id = c.id
  754. and cm.status = 0
  755. and co.coupon_id = c.id
  756. and cu.id = co.c_user_id
  757. <if test="startDate != null">
  758. AND co.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  759. </if>
  760. <if test="endDate != null">
  761. AND co.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  762. </if>
  763. order by co.create_date desc
  764. </select>
  765. <select id="findListOfVerifiedByDateForBUser" parameterType="map" resultMap="BVoResultMap">
  766. select <include refid="allBUserVerifiedCouponOrderColumns" />
  767. from wx_coupon_order co,wx_coupon c,wx_c_user cu,wx_merchant_b_user bu
  768. where co.coupon_id = c.id
  769. and cu.id = co.c_user_id
  770. and bu.id = co.b_user_id
  771. and bu.merchant_id = #{merchantId}
  772. <if test="startDate != null">
  773. AND co.update_date &gt; #{startDate,jdbcType=TIMESTAMP}
  774. </if>
  775. <if test="endDate != null">
  776. AND co.update_date &lt; #{endDate,jdbcType=TIMESTAMP}
  777. </if>
  778. AND co.coupon_order_status = '1'
  779. order by co.update_date desc
  780. </select>
  781. <sql id="allCouponOrderColumns">
  782. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price
  783. </sql>
  784. <select id="findListOfOrderedByDate" parameterType="map" resultMap="BaseResultMap">
  785. select <include refid="allCouponOrderColumns" />
  786. from wx_coupon_order co,wx_coupon_merchant cm,
  787. (select tco.id as tcoid,
  788. (select count(*) from wx_coupon_merchant tcm
  789. where tcm.product_id = tco.coupon_id
  790. and tcm.status = 0)
  791. as mc
  792. from wx_coupon_order tco) com
  793. where com.mc = 1
  794. and com.tcoid = co.id
  795. and cm.status = 0
  796. and cm.merchant_id = #{merchantId}
  797. and cm.product_id = co.coupon_id
  798. <if test="startDate != null">
  799. AND co.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  800. </if>
  801. <if test="endDate != null">
  802. AND co.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  803. </if>
  804. </select>
  805. <select id="findListOfVerifiedByDate" parameterType="map" resultMap="BaseResultMap">
  806. select <include refid="allCouponOrderColumns" />
  807. from wx_coupon_order co, wx_merchant_b_user mbu
  808. where mbu.id = co.b_user_id
  809. <if test="merchantId != null">
  810. and mbu.merchant_id = #{merchantId}
  811. </if>
  812. <if test="startDate != null">
  813. AND co.update_date &gt; #{startDate,jdbcType=TIMESTAMP}
  814. </if>
  815. <if test="endDate != null">
  816. AND co.update_date &lt; #{endDate,jdbcType=TIMESTAMP}
  817. </if>
  818. AND co.coupon_order_status = '1'
  819. </select>
  820. <sql id="allCUserCouponOrderListColumns">
  821. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type,
  822. c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.valid_type,c.valid_start_date,c.valid_end_date,c.auto_refund,
  823. cal.channel_type as send_channel_type
  824. </sql>
  825. <sql id="allCUserCouponOrderDetailColumns">
  826. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type,
  827. c.type,c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.detail,c.remark,c.valid_type,c.valid_start_date,c.valid_end_date,c.auto_refund
  828. </sql>
  829. <sql id="simpleCUserCouponOrderDetailColumns">
  830. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type
  831. </sql>
  832. <resultMap id="CVoResultMap" type="com.iformall.domain.vo.WxCouponOrderCVo">
  833. <id column="id" jdbcType="BIGINT" property="id" />
  834. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  835. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  836. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  837. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  838. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  839. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  840. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  841. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  842. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  843. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  844. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  845. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  846. <result column="verify_type" jdbcType="INTEGER" property="verifyType" />
  847. <result column="type" jdbcType="INTEGER" property="type" />
  848. <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
  849. <result column="title" jdbcType="VARCHAR" property="title" />
  850. <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
  851. <result column="sale_price" jdbcType="INTEGER" property="salePrice" />
  852. <result column="use_price" jdbcType="INTEGER" property="usePrice" />
  853. <result column="detail" jdbcType="VARCHAR" property="detail" />
  854. <result column="price" jdbcType="INTEGER" property="price" />
  855. <result column="unit" jdbcType="INTEGER" property="unit" />
  856. <result column="remark" jdbcType="VARCHAR" property="remark" />
  857. <result column="valid_type" jdbcType="INTEGER" property="validType" />
  858. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  859. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  860. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund" />
  861. <result column="send_channel_type" jdbcType="INTEGER" property="sendChannelType" />
  862. <collection column="{productId=coupon_id}" property="merchantVoList"
  863. ofType="com.iformall.domain.vo.WxMerchantVo"
  864. javaType="java.util.List"
  865. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  866. </collection>
  867. </resultMap>
  868. <select id="findListOfCUser" parameterType="com.iformall.domain.vo.WxCouponOrderCVo" resultMap="CVoResultMap">
  869. select <include refid="allCUserCouponOrderListColumns" />
  870. from wx_coupon c,wx_coupon_order co
  871. left join wx_coupon_action_log cal on cal.coupon_order_id = co.id
  872. where 1=1
  873. and co.coupon_id = c.id
  874. and co.coupon_type != 5
  875. and co.coupon_type != 51
  876. and co.coupon_type &lt; 100
  877. <if test="cUserId != null">
  878. and co.c_user_id = #{cUserId}
  879. </if>
  880. <if test="ownerId != null">
  881. and co.owner_id = #{ownerId}
  882. </if>
  883. <if test="tenantId != null">
  884. and co.tenant_id = #{tenantId}
  885. </if>
  886. <if test="couponOrderStatus != null and 0 == couponOrderStatus">
  887. AND (co.coupon_order_status = #{couponOrderStatus} OR co.coupon_order_status = 100 )
  888. </if>
  889. <if test="couponOrderStatus != null and 0 != couponOrderStatus">
  890. AND co.coupon_order_status = #{couponOrderStatus}
  891. </if>
  892. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  893. </select>
  894. <select id="findDetailOfCUser" parameterType="java.lang.Long" resultMap="CVoResultMap">
  895. select <include refid="allCUserCouponOrderDetailColumns" />
  896. from wx_coupon_order co, wx_coupon c
  897. where co.coupon_id = c.id
  898. and co.id = #{id}
  899. </select>
  900. <select id="findSimpleDetailOfCUser" parameterType="java.lang.Long" resultMap="CVoResultMap">
  901. select <include refid="simpleCUserCouponOrderDetailColumns" />
  902. from wx_coupon_order co
  903. where co.id = #{id}
  904. </select>
  905. <select id="findAvailCouponOrder" parameterType="java.util.Map" resultMap="CVoResultMap">
  906. select <include refid="allCUserCouponOrderDetailColumns" />
  907. from wx_coupon_order co
  908. inner join wx_coupon c on c.id = co.coupon_id
  909. inner join wx_coupon_merchant cm on cm.product_id = co.coupon_id
  910. where co.tenant_id = #{tenantId}
  911. and co.c_user_id = #{cUserId}
  912. and co.coupon_order_status = 0
  913. and cm.merchant_id = #{merchantId}
  914. and co.expired_time > now()
  915. and c.type in (1, 2, 6)
  916. union
  917. select <include refid="allCUserCouponOrderDetailColumns" />
  918. from wx_coupon_order co
  919. inner join wx_coupon c on c.id = co.coupon_id
  920. inner join wx_coupon_merchant cm on cm.product_id = co.coupon_id
  921. inner join pos_coupon_order_verify pco on pco.coupon_order_id = co.id
  922. where co.tenant_id = #{tenantId}
  923. and co.c_user_id = #{cUserId}
  924. and co.coupon_order_status = 100
  925. and cm.merchant_id = #{merchantId}
  926. and co.expired_time > now()
  927. and c.type in (1, 2, 6)
  928. <if test="posOrderId != null">
  929. and pco.pos_order_id = #{posOrderId}
  930. </if>
  931. </select>
  932. <sql id="allCUserCouponOrderCarListColumns">
  933. co.id,co.coupon_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type,
  934. c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,
  935. json_extract(car.vendor_params,'$.id') as coupon_free_id
  936. </sql>
  937. <resultMap id="CCarVoResultMap" type="com.iformall.domain.vo.WxCouponOrderCarCVo">
  938. <id column="id" jdbcType="BIGINT" property="id" />
  939. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  940. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  941. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  942. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  943. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  944. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  945. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  946. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  947. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  948. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  949. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  950. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  951. <result column="verify_type" jdbcType="INTEGER" property="verifyType" />
  952. <result column="type" jdbcType="INTEGER" property="type" />
  953. <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
  954. <result column="title" jdbcType="VARCHAR" property="title" />
  955. <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
  956. <result column="sale_price" jdbcType="INTEGER" property="salePrice" />
  957. <result column="use_price" jdbcType="INTEGER" property="usePrice" />
  958. <result column="detail" jdbcType="VARCHAR" property="detail" />
  959. <result column="price" jdbcType="INTEGER" property="price" />
  960. <result column="remark" jdbcType="VARCHAR" property="remark" />
  961. <result column="coupon_free_id" jdbcType="INTEGER" property="couponFreeId"/>
  962. <collection column="{productId=coupon_id}" property="merchantVoList"
  963. ofType="com.iformall.domain.vo.WxMerchantVo"
  964. javaType="java.util.List"
  965. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  966. </collection>
  967. </resultMap>
  968. <select id="findCarListOfCUser" parameterType="com.iformall.domain.vo.WxCouponOrderCarCVo" resultMap="CCarVoResultMap">
  969. select <include refid="allCUserCouponOrderCarListColumns" />
  970. from wx_coupon_order co, wx_coupon c, wx_coupon_car car
  971. where co.coupon_id = c.id
  972. and co.coupon_id = car.id
  973. and c.type in (5,51)
  974. <if test="cUserId != null">
  975. and co.c_user_id = #{cUserId}
  976. </if>
  977. <if test="tenantId != null">
  978. and co.tenant_id = #{tenantId}
  979. </if>
  980. <if test="id != null">
  981. and co.id = #{id}
  982. </if>
  983. <if test="couponOrderStatus != null and 0 == couponOrderStatus ">
  984. AND ( co.coupon_order_status = #{couponOrderStatus} OR co.coupon_order_status = 100 )
  985. </if>
  986. <if test="couponOrderStatus != null and 0 != couponOrderStatus ">
  987. AND co.coupon_order_status = #{couponOrderStatus}
  988. </if>
  989. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  990. </select>
  991. <resultMap id="CCardVoResultMap" type="com.iformall.domain.vo.WxCardCVo">
  992. <id column="id" jdbcType="BIGINT" property="id" />
  993. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  994. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  995. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  996. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  997. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  998. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  999. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  1000. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  1001. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  1002. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  1003. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  1004. <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
  1005. <result column="title" jdbcType="VARCHAR" property="title" />
  1006. <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
  1007. <result column="detail" jdbcType="VARCHAR" property="detail" />
  1008. <result column="unit" jdbcType="INTEGER" property="unit" />
  1009. <result column="remark" jdbcType="VARCHAR" property="remark" />
  1010. <result column="amount" jdbcType="INTEGER" property="amount" />
  1011. <result column="remaining_amount" jdbcType="INTEGER" property="remainingAmount" />
  1012. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  1013. <collection column="{productId=coupon_id}" property="merchantVoList"
  1014. ofType="com.iformall.domain.vo.WxMerchantVo"
  1015. javaType="java.util.List"
  1016. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  1017. </collection>
  1018. <collection column="{cardId=id}" property="cardSpendList"
  1019. ofType="com.iformall.domain.vo.WxCardSpendVo"
  1020. javaType="java.util.List"
  1021. select="com.iformall.mapper.WxCardSpendMapper.findCardSpendVoList" >
  1022. </collection>
  1023. </resultMap>
  1024. <sql id="allCUserCardListColumns">
  1025. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,
  1026. c.cover_img,c.title,c.sub_title,c.detail,c.unit,c.remark,
  1027. a.amount,a.remaining_amount,a.support_transfer
  1028. </sql>
  1029. <sql id="allCUserCardDetailColumns">
  1030. co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,
  1031. c.cover_img,c.title,c.sub_title,c.sale_price,c.price,c.unit,c.detail,c.remark,
  1032. a.amount,a.remaining_amount,a.support_transfer
  1033. </sql>
  1034. <select id="findCardListOfCUser" parameterType="com.iformall.domain.vo.WxCardCVo" resultMap="CCardVoResultMap">
  1035. select c.* from (
  1036. select id,tenant_id,0 coupon_id,0 coupon_type,expired_time,`status`as
  1037. coupon_order_status,create_date,update_date,'' cover_img,title,'' sub_title,'' detail,0 unit,
  1038. '' remark,amount,remain_amount as remaining_amount,0 support_transfer
  1039. from wx_card_transfer_info where 1=1
  1040. <if test="tenantId != null">
  1041. and tenant_id = #{tenantId}
  1042. </if>
  1043. <if test="ownerId != null">
  1044. and from_user = #{ownerId}
  1045. </if>
  1046. <choose>
  1047. <when test="couponOrderStatus != null">
  1048. and status = #{couponOrderStatus}
  1049. </when>
  1050. <otherwise>
  1051. and status=8
  1052. </otherwise>
  1053. </choose>
  1054. union
  1055. select
  1056. <include refid="allCUserCardListColumns"/>
  1057. from wx_coupon_order co
  1058. inner join wx_coupon c on co.coupon_id = c.id
  1059. inner join wx_card_info a on co.id=a.id
  1060. where 1=1
  1061. and co.coupon_type = 100
  1062. <if test="tenantId != null">
  1063. and co.tenant_id = #{tenantId}
  1064. </if>
  1065. <if test="cUserId != null">
  1066. and co.c_user_id = #{cUserId}
  1067. </if>
  1068. <if test="ownerId != null">
  1069. and co.owner_id = #{ownerId}
  1070. </if>
  1071. <if test="couponOrderStatus != null">
  1072. and co.coupon_order_status = #{couponOrderStatus}
  1073. </if>
  1074. <if test=" null != statusS ">
  1075. and co.coupon_order_status in
  1076. <foreach collection="statusS" index="index" item="sItem" open="(" separator="," close=")">
  1077. #{sItem}
  1078. </foreach>
  1079. </if>
  1080. ) c
  1081. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  1082. </select>
  1083. <select id="findCardDetailOfCUser" parameterType="java.lang.Long" resultMap="CCardVoResultMap">
  1084. select <include refid="allCUserCardDetailColumns" />
  1085. from wx_coupon_order co,wx_coupon c, wx_card_info a
  1086. where co.coupon_id = c.id and co.id = a.id
  1087. and co.id = #{id}
  1088. </select>
  1089. </mapper>