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.
 
 
 
 
 

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