You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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