Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

1681 řádky
69 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 != 5 -->
  828. and co.coupon_type != 11
  829. <!-- and co.coupon_type != 12 -->
  830. <!-- and co.coupon_type != 51 -->
  831. and co.coupon_type &lt; 100
  832. </otherwise>
  833. </choose>
  834. <if test=" null != tenantId and '' != tenantId">
  835. and co.`tenant_id` = #{tenantId}
  836. </if>
  837. <if test=" null != parentTenantId and '' != parentTenantId">
  838. and co.`parent_tenant_id` = #{parentTenantId}
  839. </if>
  840. <if test=" null != cUserPhone and '' != cUserPhone">
  841. and cu.`phone` = #{cUserPhone}
  842. </if>
  843. <if test=" null != couponOrderStatus ">
  844. and co.coupon_order_status = #{couponOrderStatus}
  845. </if>
  846. <if test=" null != merchantName and merchantName!=''">
  847. and (case when couc.mc=1
  848. then
  849. m1.name
  850. <!--(select m.name from wx_merchant m, wx_coupon_merchant cm
  851. where m.id = cm.merchant_id
  852. and cm.product_id=co.coupon_id
  853. and cm.status = 0)-->
  854. else'[多商户通用]' end)
  855. like concat('%', #{merchantName},'%')
  856. </if>
  857. <if test="startDate != null">
  858. AND co.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  859. </if>
  860. <if test="endDate != null">
  861. AND co.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  862. </if>
  863. <if test="verifyStartDate != null">
  864. AND co.update_date &gt; #{verifyStartDate,jdbcType=TIMESTAMP}
  865. </if>
  866. <if test="verifyEndDate != null">
  867. AND co.update_date &lt; #{verifyEndDate,jdbcType=TIMESTAMP}
  868. </if>
  869. <if test=" null != id ">
  870. and co.id = #{id}
  871. </if>
  872. <if test=" null != orderId ">
  873. and co.order_id = #{orderId}
  874. </if>
  875. <if test=" null != couponId ">
  876. and c.id = #{couponId}
  877. </if>
  878. <if test=" null != title ">
  879. and c.title like concat('%', #{title},'%')
  880. </if>
  881. <if test=" null != type ">
  882. and c.`type` = #{type}
  883. </if>
  884. <if test=" null != business ">
  885. and c.business = #{business}
  886. </if>
  887. <if test=" null != sourceType ">
  888. and c.`source_type` = #{sourceType}
  889. </if>
  890. <if test=" null != verifyMerchantName and ''!= verifyMerchantName ">
  891. and bu.verify_merchant_name = #{verifyMerchantName}
  892. </if>
  893. <if test="null!=building">
  894. and co.coupon_id in(
  895. select cm.product_id from wx_merchant_shop ms left join wx_merchant m on ms.merchant_id=m.id
  896. left join wx_shop s on ms.shop_id=s.id
  897. left join wx_coupon_merchant cm on ms.merchant_id=cm.merchant_id
  898. where ms.is_del=0 and s.building=#{building}
  899. <if test=" null != tenantId and '' != tenantId">
  900. and ms.`tenant_id` = #{tenantId}
  901. </if>
  902. <if test=" null != parentTenantId and '' != parentTenantId">
  903. and ms.`parent_tenant_id` = #{parentTenantId}
  904. </if>
  905. <if test="null!=floor">
  906. and s.floor=#{floor}
  907. </if>
  908. )
  909. </if>
  910. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  911. <if test=" null == sortColumns">order by co.create_date desc,co.id desc</if>
  912. </select>
  913. <select id="findGoodsList" parameterType="com.iformall.domain.vo.WxCouponOrderBVo" resultMap="AdminBVoResultMap">
  914. select
  915. 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,
  916. 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,
  917. co.`freight_price`,co.`shipping_type`,co.`shipping_address`,co.`shipping_status`,co.`delivery_info`,
  918. c.type,c.title,c.sale_price,c.use_price,c.price,c.unit,c.auto_refund,c.business,c.subsidy_type,
  919. cu.phone
  920. FROM wx_coupon_order co
  921. left join wx_coupon_merchant wcm on co.coupon_id = wcm.product_id and wcm.merchant_id = #{merchantId}
  922. LEFT JOIN wx_c_user_basic_info cu ON cu.id=co.c_user_id
  923. LEFT JOIN wx_coupon c ON c.id = co.coupon_id
  924. where 1=1
  925. <choose>
  926. <when test=" null != couponType">
  927. and co.coupon_type = #{couponType}
  928. </when>
  929. <otherwise>
  930. <!-- and co.coupon_type != 5 -->
  931. and co.coupon_type != 11
  932. <!-- and co.coupon_type != 12 -->
  933. <!-- and co.coupon_type != 51 -->
  934. and co.coupon_type &lt; 100
  935. </otherwise>
  936. </choose>
  937. <if test=" null != tenantId and '' != tenantId">
  938. and co.`tenant_id` = #{tenantId}
  939. </if>
  940. <if test=" null != parentTenantId and '' != parentTenantId">
  941. and co.`parent_tenant_id` = #{parentTenantId}
  942. </if>
  943. <if test=" null != cUserPhone and '' != cUserPhone">
  944. and cu.`phone` = #{cUserPhone}
  945. </if>
  946. <if test=" null != couponOrderStatus ">
  947. and co.coupon_order_status = #{couponOrderStatus}
  948. </if>
  949. <if test=" null != shippingStatuss ">
  950. and co.`shipping_status` in
  951. <foreach collection="shippingStatuss" index="index" item="idItem" open="(" separator="," close=")">
  952. #{idItem}
  953. </foreach>
  954. </if>
  955. <if test="startDate != null">
  956. AND co.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  957. </if>
  958. <if test="endDate != null">
  959. AND co.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  960. </if>
  961. <if test="verifyStartDate != null">
  962. AND co.update_date &gt; #{verifyStartDate,jdbcType=TIMESTAMP}
  963. </if>
  964. <if test="verifyEndDate != null">
  965. AND co.update_date &lt; #{verifyEndDate,jdbcType=TIMESTAMP}
  966. </if>
  967. <if test=" null != id ">
  968. and co.id = #{id}
  969. </if>
  970. <if test=" null != orderId ">
  971. and co.order_id = #{orderId}
  972. </if>
  973. <if test=" null != couponId ">
  974. and c.id = #{couponId}
  975. </if>
  976. <if test=" null != title ">
  977. and c.title like concat('%', #{title},'%')
  978. </if>
  979. <if test=" null != type ">
  980. and c.`type` = #{type}
  981. </if>
  982. <if test=" null != business ">
  983. and c.business = #{business}
  984. </if>
  985. <if test=" null != sourceType ">
  986. and c.`source_type` = #{sourceType}
  987. </if>
  988. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  989. <if test=" null == sortColumns">order by co.create_date desc,co.id desc</if>
  990. </select>
  991. <select id="findDetailOfAdmin" parameterType="java.util.HashMap" resultMap="BVoResultMap">
  992. select <include refid="allAdminCouponOrderDetailColumns" />
  993. from wx_coupon c, wx_coupon_order co
  994. left join wx_c_user_basic_info cu on cu.id = co.c_user_id
  995. left join wx_merchant_b_user bu on co.b_user_id = bu.id
  996. left join wx_merchant m on m.id = bu.merchant_id
  997. left join wx_merchant_subsidy ms on co.id = ms.coupon_order_id and ms.type = 1
  998. where co.id = #{id} and co.tenant_id = #{tenantId} and cu.final_tenant_id = #{finalTenantId}
  999. and c.id = co.coupon_id
  1000. </select>
  1001. <sql id="allBUserVerifiedCouponOrderColumns">
  1002. 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,
  1003. co.`freight_price`,co.`shipping_type`,co.`shipping_address`,co.`shipping_status`,co.`delivery_info`,
  1004. c.type,c.title,c.sale_price,c.use_price,c.price,c.unit,
  1005. bu.name,
  1006. cu.phone
  1007. </sql>
  1008. <sql id="allBUserOrderedCouponOrderColumns">
  1009. 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,
  1010. co.`freight_price`,co.`shipping_type`,co.`shipping_address`,co.`shipping_status`,co.`delivery_info`,
  1011. c.type,c.title,c.sale_price,c.use_price,c.price,c.unit,
  1012. cu.phone
  1013. </sql>
  1014. <select id="findListOfOrderedByDateForBUser" parameterType="map" resultMap="BVoResultMap">
  1015. select <include refid="allBUserOrderedCouponOrderColumns" />
  1016. from wx_coupon_order co,wx_coupon c,wx_c_user_basic_info cu,wx_coupon_merchant cm,
  1017. (select tco.id as tcoid,
  1018. (select count(*) from wx_coupon_merchant tcm
  1019. where tcm.product_id = tco.coupon_id
  1020. and tcm.status = 0) as mc
  1021. from wx_coupon_order tco) com
  1022. where com.mc = 1
  1023. and com.tcoid = co.id
  1024. and cm.merchant_id = #{merchantId}
  1025. and co.tenant_id = #{tenantId}
  1026. and cm.product_id = c.id
  1027. and cm.status = 0
  1028. and co.coupon_id = c.id
  1029. and cu.id = co.c_user_id
  1030. <if test="startDate != null">
  1031. AND co.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  1032. </if>
  1033. <if test="endDate != null">
  1034. AND co.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  1035. </if>
  1036. order by co.create_date desc
  1037. </select>
  1038. <select id="findListOfVerifiedByDateForBUser" parameterType="map" resultMap="BVoResultMap">
  1039. select <include refid="allBUserVerifiedCouponOrderColumns" />
  1040. from wx_coupon_order co,wx_coupon c,wx_c_user_basic_info cu,wx_merchant_b_user bu
  1041. where co.coupon_id = c.id
  1042. and co.tenant_id = #{tenantId}
  1043. and cu.id = co.c_user_id
  1044. and bu.id = co.b_user_id
  1045. and bu.merchant_id = #{merchantId}
  1046. <if test="startDate != null">
  1047. AND co.update_date &gt; #{startDate,jdbcType=TIMESTAMP}
  1048. </if>
  1049. <if test="endDate != null">
  1050. AND co.update_date &lt; #{endDate,jdbcType=TIMESTAMP}
  1051. </if>
  1052. AND co.coupon_order_status = '1'
  1053. order by co.update_date desc
  1054. </select>
  1055. <sql id="allCouponOrderColumns">
  1056. 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,
  1057. 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,
  1058. co.`freight_price`,co.`shipping_type`,co.`shipping_address`,co.`shipping_status`,co.`delivery_info`
  1059. </sql>
  1060. <select id="findListOfOrderedByDate" parameterType="map" resultMap="BaseResultMap">
  1061. select <include refid="allCouponOrderColumns" />
  1062. from wx_coupon_order co,wx_coupon_merchant cm,
  1063. (select tco.id as tcoid,
  1064. (select count(*) from wx_coupon_merchant tcm
  1065. where tcm.product_id = tco.coupon_id
  1066. and tcm.status = 0)
  1067. as mc
  1068. from wx_coupon_order tco) com
  1069. where com.mc = 1
  1070. and co.tenant_id = #{tenantId}
  1071. and com.tcoid = co.id
  1072. and cm.status = 0
  1073. and cm.merchant_id = #{merchantId}
  1074. and cm.product_id = co.coupon_id
  1075. <if test="startDate != null">
  1076. AND co.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  1077. </if>
  1078. <if test="endDate != null">
  1079. AND co.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  1080. </if>
  1081. </select>
  1082. <select id="findListOfVerifiedByDate" parameterType="map" resultMap="BaseResultMap">
  1083. select <include refid="allCouponOrderColumns" />
  1084. from wx_coupon_order co, wx_merchant_b_user mbu
  1085. where mbu.id = co.b_user_id
  1086. and co.tenant_id = #{tenantId}
  1087. <if test="merchantId != null">
  1088. and mbu.merchant_id = #{merchantId}
  1089. </if>
  1090. <if test="startDate != null">
  1091. AND co.update_date &gt; #{startDate,jdbcType=TIMESTAMP}
  1092. </if>
  1093. <if test="endDate != null">
  1094. AND co.update_date &lt; #{endDate,jdbcType=TIMESTAMP}
  1095. </if>
  1096. AND co.coupon_order_status = '1'
  1097. </select>
  1098. <sql id="allCUserCouponOrderDetailColumns">
  1099. 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,
  1100. co.`freight_price`,co.`shipping_type`,co.`shipping_address`,co.`shipping_status`,co.`delivery_info`,
  1101. 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
  1102. </sql>
  1103. <sql id="simpleCUserCouponOrderDetailColumns">
  1104. 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,
  1105. co.`freight_price`,co.`shipping_type`,co.`shipping_address`,co.`shipping_status`,co.`delivery_info`
  1106. </sql>
  1107. <resultMap id="CVoResultMap" type="com.iformall.domain.vo.WxCouponOrderCVo">
  1108. <id column="id" jdbcType="BIGINT" property="id" />
  1109. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  1110. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  1111. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  1112. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  1113. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  1114. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  1115. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  1116. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  1117. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  1118. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  1119. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  1120. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  1121. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  1122. <result column="verify_type" jdbcType="INTEGER" property="verifyType" />
  1123. <result column="verify_remark" jdbcType="VARCHAR" property="verifyRemark" />
  1124. <result column="pay_vendor" jdbcType="INTEGER" property="payVendor" />
  1125. <result column="freight_price" jdbcType="INTEGER" property="freightPrice"/>
  1126. <result column="shipping_type" jdbcType="INTEGER" property="shippingType"/>
  1127. <result column="shipping_address" jdbcType="VARCHAR" property="shippingAddress"/>
  1128. <result column="shipping_status" jdbcType="INTEGER" property="shippingStatus"/>
  1129. <result column="delivery_info" jdbcType="VARCHAR" property="deliveryInfo"/>
  1130. <result column="type" jdbcType="INTEGER" property="type" />
  1131. <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
  1132. <result column="title" jdbcType="VARCHAR" property="title" />
  1133. <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
  1134. <result column="sale_price" jdbcType="INTEGER" property="salePrice" />
  1135. <result column="use_price" jdbcType="INTEGER" property="usePrice" />
  1136. <result column="detail" jdbcType="VARCHAR" property="detail" />
  1137. <result column="price" jdbcType="INTEGER" property="price" />
  1138. <result column="tail_price" jdbcType="INTEGER" property="tailPrice"/>
  1139. <result column="orig_price" jdbcType="INTEGER" property="origPrice"/>
  1140. <result column="unit" jdbcType="INTEGER" property="unit" />
  1141. <result column="remark" jdbcType="VARCHAR" property="remark" />
  1142. <result column="valid_type" jdbcType="INTEGER" property="validType" />
  1143. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  1144. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  1145. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund" />
  1146. <result column="pick_start_date" jdbcType="TIMESTAMP" property="pickStartDate"/>
  1147. <result column="pick_end_date" jdbcType="TIMESTAMP" property="pickEndDate"/>
  1148. <result column="send_channel_type" jdbcType="INTEGER" property="sendChannelType" />
  1149. <collection column="{productId=coupon_id,tenantId=tenant_id}" property="merchantVoList"
  1150. ofType="com.iformall.domain.vo.WxMerchantVo"
  1151. javaType="java.util.List"
  1152. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  1153. </collection>
  1154. </resultMap>
  1155. <resultMap id="CVoResultMapOptimize" type="com.iformall.domain.vo.WxCouponOrderCVo">
  1156. <id column="id" jdbcType="BIGINT" property="id" />
  1157. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  1158. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  1159. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  1160. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  1161. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  1162. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  1163. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  1164. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  1165. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  1166. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  1167. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  1168. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  1169. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  1170. <result column="verify_type" jdbcType="INTEGER" property="verifyType" />
  1171. <result column="verify_remark" jdbcType="VARCHAR" property="verifyRemark" />
  1172. <result column="pay_vendor" jdbcType="INTEGER" property="payVendor" />
  1173. <result column="freight_price" jdbcType="INTEGER" property="freightPrice"/>
  1174. <result column="shipping_type" jdbcType="INTEGER" property="shippingType"/>
  1175. <result column="shipping_address" jdbcType="VARCHAR" property="shippingAddress"/>
  1176. <result column="shipping_status" jdbcType="INTEGER" property="shippingStatus"/>
  1177. <result column="delivery_info" jdbcType="VARCHAR" property="deliveryInfo"/>
  1178. <result column="type" jdbcType="INTEGER" property="type" />
  1179. <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
  1180. <result column="title" jdbcType="VARCHAR" property="title" />
  1181. <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
  1182. <result column="sale_price" jdbcType="INTEGER" property="salePrice" />
  1183. <result column="use_price" jdbcType="INTEGER" property="usePrice" />
  1184. <result column="detail" jdbcType="VARCHAR" property="detail" />
  1185. <result column="price" jdbcType="INTEGER" property="price" />
  1186. <result column="unit" jdbcType="INTEGER" property="unit" />
  1187. <result column="remark" jdbcType="VARCHAR" property="remark" />
  1188. <result column="valid_type" jdbcType="INTEGER" property="validType" />
  1189. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  1190. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  1191. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund" />
  1192. <result column="send_channel_type" jdbcType="INTEGER" property="sendChannelType" />
  1193. </resultMap>
  1194. <!-- <select id="findListOfCUser" parameterType="com.iformall.domain.vo.WxCouponOrderCVo" resultMap="CVoResultMap">
  1195. select <include refid="allCUserCouponOrderListColumns" />
  1196. from wx_coupon c,wx_coupon_order co
  1197. left join wx_coupon_action_log cal on cal.coupon_order_id = co.id
  1198. where 1=1
  1199. and co.coupon_id = c.id
  1200. and co.coupon_type != 5
  1201. and co.coupon_type != 51
  1202. and co.coupon_type &lt; 100
  1203. <if test="cUserId != null">
  1204. and co.c_user_id = #{cUserId}
  1205. </if>
  1206. <if test="ownerId != null">
  1207. and co.owner_id = #{ownerId}
  1208. </if>
  1209. <if test="tenantId != null">
  1210. and co.tenant_id = #{tenantId}
  1211. </if>
  1212. <if test="couponOrderStatus != null and 0 == couponOrderStatus">
  1213. AND (co.coupon_order_status = #{couponOrderStatus} OR co.coupon_order_status = 100 )
  1214. </if>
  1215. <if test="couponOrderStatus != null and 0 != couponOrderStatus">
  1216. AND co.coupon_order_status = #{couponOrderStatus}
  1217. </if>
  1218. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  1219. </select> -->
  1220. <!-- <sql id="allCUserCouponOrderListColumns">
  1221. 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,
  1222. 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,
  1223. cal.channel_type as send_channel_type
  1224. </sql> -->
  1225. <sql id="allCUserCouponOrderListColumns">
  1226. 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,
  1227. co.`freight_price`,co.`shipping_type`,co.`shipping_address`,co.`shipping_status`,co.`delivery_info`,
  1228. 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
  1229. </sql>
  1230. <select id="findListOfCUserOptimize" parameterType="com.iformall.domain.vo.WxCouponOrderCVo" resultMap="CVoResultMapOptimize">
  1231. select <include refid="allCUserCouponOrderListColumns" />
  1232. from wx_coupon c,wx_coupon_order co
  1233. <!-- left join wx_coupon_action_log cal on cal.coupon_order_id = co.id -->
  1234. where 1=1
  1235. and co.coupon_id = c.id
  1236. <choose>
  1237. <when test=" null != couponType">
  1238. and co.coupon_type = #{couponType}
  1239. </when>
  1240. <otherwise>
  1241. and co.coupon_type != 5
  1242. and co.coupon_type != 11
  1243. and co.coupon_type != 12
  1244. and co.coupon_type != 51
  1245. and co.coupon_type &lt; 100
  1246. </otherwise>
  1247. </choose>
  1248. <if test="cUserId != null">
  1249. and co.c_user_id = #{cUserId}
  1250. </if>
  1251. <if test="ownerId != null">
  1252. and co.owner_id = #{ownerId}
  1253. </if>
  1254. <if test=" null != tenantId and '' != tenantId">
  1255. and co.`tenant_id` = #{tenantId}
  1256. </if>
  1257. <if test=" null != parentTenantId and '' != parentTenantId">
  1258. and co.`parent_tenant_id` = #{parentTenantId}
  1259. </if>
  1260. <if test="couponOrderStatus != null and 0 == couponOrderStatus">
  1261. AND (co.coupon_order_status = #{couponOrderStatus} OR co.coupon_order_status = 100 )
  1262. </if>
  1263. <if test="couponOrderStatus != null and 0 != couponOrderStatus">
  1264. AND co.coupon_order_status = #{couponOrderStatus}
  1265. </if>
  1266. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  1267. </select>
  1268. <select id="findDetailOfCUser" parameterType="java.util.HashMap" resultMap="CVoResultMap">
  1269. select <include refid="allCUserCouponOrderDetailColumns" />
  1270. from wx_coupon_order co, wx_coupon c
  1271. where co.coupon_id = c.id
  1272. and co.id = #{id} and co.tenant_id = #{tenantId}
  1273. </select>
  1274. <select id="findSimpleDetailOfCUser" parameterType="java.util.HashMap" resultMap="CVoResultMap">
  1275. select <include refid="simpleCUserCouponOrderDetailColumns" />
  1276. from wx_coupon_order co
  1277. where co.id = #{id} and co.tenant_id = #{tenantId}
  1278. </select>
  1279. <select id="findAvailCouponOrder" parameterType="java.util.Map" resultMap="CVoResultMap">
  1280. select <include refid="allCUserCouponOrderDetailColumns" />
  1281. from wx_coupon_order co
  1282. inner join wx_coupon c on c.id = co.coupon_id
  1283. inner join wx_coupon_merchant cm on cm.product_id = co.coupon_id
  1284. where co.c_user_id = #{cUserId}
  1285. and co.coupon_order_status = 0
  1286. <if test=" null != tenantId and '' != tenantId">
  1287. and co.`tenant_id` = #{tenantId}
  1288. </if>
  1289. <if test=" null != parentTenantId and '' != parentTenantId">
  1290. and co.`parent_tenant_id` = #{parentTenantId}
  1291. </if>
  1292. and cm.merchant_id = #{merchantId}
  1293. and co.expired_time > now()
  1294. and c.type in (1, 2, 6)
  1295. union
  1296. select <include refid="allCUserCouponOrderDetailColumns" />
  1297. from wx_coupon_order co
  1298. inner join wx_coupon c on c.id = co.coupon_id
  1299. inner join wx_coupon_merchant cm on cm.product_id = co.coupon_id
  1300. inner join pos_coupon_order_verify pco on pco.coupon_order_id = co.id
  1301. where co.c_user_id = #{cUserId}
  1302. and co.coupon_order_status = 100
  1303. <if test=" null != tenantId and '' != tenantId">
  1304. and co.`tenant_id` = #{tenantId}
  1305. </if>
  1306. <if test=" null != parentTenantId and '' != parentTenantId">
  1307. and co.`parent_tenant_id` = #{parentTenantId}
  1308. </if>
  1309. and cm.merchant_id = #{merchantId}
  1310. and co.expired_time > now()
  1311. and c.type in (1, 2, 6)
  1312. <if test="posOrderId != null">
  1313. and pco.pos_order_id = #{posOrderId}
  1314. </if>
  1315. </select>
  1316. <sql id="allCUserCouponOrderCarListColumns">
  1317. 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,
  1318. c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,
  1319. json_extract(car.vendor_params,'$.id') as coupon_free_id,car.vendor_params
  1320. </sql>
  1321. <resultMap id="CCarVoResultMap" type="com.iformall.domain.vo.WxCouponOrderCarCVo">
  1322. <id column="id" jdbcType="BIGINT" property="id" />
  1323. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  1324. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  1325. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  1326. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  1327. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  1328. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  1329. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  1330. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  1331. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  1332. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  1333. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  1334. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  1335. <result column="coupon_price" jdbcType="INTEGER" property="couponPrice" />
  1336. <result column="verify_type" jdbcType="INTEGER" property="verifyType" />
  1337. <result column="verify_remark" jdbcType="VARCHAR" property="verifyRemark" />
  1338. <result column="pay_vendor" jdbcType="INTEGER" property="payVendor" />
  1339. <result column="type" jdbcType="INTEGER" property="type" />
  1340. <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
  1341. <result column="title" jdbcType="VARCHAR" property="title" />
  1342. <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
  1343. <result column="sale_price" jdbcType="INTEGER" property="salePrice" />
  1344. <result column="use_price" jdbcType="INTEGER" property="usePrice" />
  1345. <result column="detail" jdbcType="VARCHAR" property="detail" />
  1346. <result column="price" jdbcType="INTEGER" property="price" />
  1347. <result column="remark" jdbcType="VARCHAR" property="remark" />
  1348. <result column="vendor_params" jdbcType="VARCHAR" property="vendorParams" />
  1349. <result column="coupon_free_id" jdbcType="INTEGER" property="couponFreeId"/>
  1350. <collection column="{productId=coupon_id,tenantId=tenant_id}" property="merchantVoList"
  1351. ofType="com.iformall.domain.vo.WxMerchantVo"
  1352. javaType="java.util.List"
  1353. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  1354. </collection>
  1355. </resultMap>
  1356. <select id="findCarListOfCUser" parameterType="com.iformall.domain.vo.WxCouponOrderCarCVo" resultMap="CCarVoResultMap">
  1357. select <include refid="allCUserCouponOrderCarListColumns" />
  1358. from wx_coupon_order co, wx_coupon c, wx_coupon_car car
  1359. where co.coupon_id = c.id
  1360. and co.coupon_id = car.id
  1361. and c.type in (5,51)
  1362. <if test="cUserId != null">
  1363. and co.c_user_id = #{cUserId}
  1364. </if>
  1365. <if test=" null != tenantId and '' != tenantId">
  1366. and co.`tenant_id` = #{tenantId}
  1367. </if>
  1368. <if test=" null != parentTenantId and '' != parentTenantId">
  1369. and co.`parent_tenant_id` = #{parentTenantId}
  1370. </if>
  1371. <if test="id != null">
  1372. and co.id = #{id}
  1373. </if>
  1374. <if test="couponOrderStatus != null and 0 == couponOrderStatus ">
  1375. AND ( co.coupon_order_status = #{couponOrderStatus} OR co.coupon_order_status = 100 )
  1376. </if>
  1377. <if test="couponOrderStatus != null and 0 != couponOrderStatus ">
  1378. AND co.coupon_order_status = #{couponOrderStatus}
  1379. </if>
  1380. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  1381. </select>
  1382. <resultMap id="CCardVoResultMap" type="com.iformall.domain.vo.WxCardCVo">
  1383. <id column="id" jdbcType="BIGINT" property="id" />
  1384. <result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
  1385. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  1386. <result column="coupon_type" jdbcType="INTEGER" property="couponType" />
  1387. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  1388. <result column="owner_id" jdbcType="BIGINT" property="ownerId" />
  1389. <result column="b_user_id" jdbcType="BIGINT" property="bUserId" />
  1390. <result column="order_id" jdbcType="BIGINT" property="orderId" />
  1391. <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  1392. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" />
  1393. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  1394. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  1395. <result column="cover_img" jdbcType="VARCHAR" property="coverImg" />
  1396. <result column="title" jdbcType="VARCHAR" property="title" />
  1397. <result column="sub_title" jdbcType="VARCHAR" property="subTitle" />
  1398. <result column="detail" jdbcType="VARCHAR" property="detail" />
  1399. <result column="unit" jdbcType="INTEGER" property="unit" />
  1400. <result column="remark" jdbcType="VARCHAR" property="remark" />
  1401. <result column="amount" jdbcType="INTEGER" property="amount" />
  1402. <result column="remaining_amount" jdbcType="INTEGER" property="remainingAmount" />
  1403. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  1404. <collection column="{productId=coupon_id,tenantId=tenant_id}" property="merchantVoList"
  1405. ofType="com.iformall.domain.vo.WxMerchantVo"
  1406. javaType="java.util.List"
  1407. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  1408. </collection>
  1409. <collection column="{cardId=id,tenantId=tenant_id}" property="cardSpendList"
  1410. ofType="com.iformall.domain.vo.WxCardSpendVo"
  1411. javaType="java.util.List"
  1412. select="com.iformall.mapper.WxCardSpendMapper.findCardSpendVoList" >
  1413. </collection>
  1414. </resultMap>
  1415. <sql id="allCUserCardListColumns">
  1416. 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,
  1417. c.cover_img,c.title,c.sub_title,c.detail,c.unit,c.remark,
  1418. a.amount,a.remaining_amount,a.support_transfer
  1419. </sql>
  1420. <sql id="allCUserCardDetailColumns">
  1421. 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,
  1422. c.cover_img,c.title,c.sub_title,c.sale_price,c.price,c.unit,c.detail,c.remark,
  1423. a.amount,a.remaining_amount,a.support_transfer
  1424. </sql>
  1425. <select id="findCardListOfCUser" parameterType="com.iformall.domain.vo.WxCardCVo" resultMap="CCardVoResultMap">
  1426. select c.* from (
  1427. select id,tenant_id,parent_tenant_id,0 coupon_id,0 coupon_type,expired_time,`status`as
  1428. coupon_order_status,create_date,update_date,'' cover_img,title,'' sub_title,'' detail,0 unit,
  1429. '' remark,amount,remain_amount as remaining_amount,0 support_transfer
  1430. from wx_card_transfer_info where 1=1
  1431. <if test=" null != tenantId and '' != tenantId">
  1432. and `tenant_id` = #{tenantId}
  1433. </if>
  1434. <if test=" null != parentTenantId and '' != parentTenantId">
  1435. and `parent_tenant_id` = #{parentTenantId}
  1436. </if>
  1437. <if test="ownerId != null">
  1438. and from_user = #{ownerId}
  1439. </if>
  1440. <choose>
  1441. <when test="couponOrderStatus != null">
  1442. and status = #{couponOrderStatus}
  1443. </when>
  1444. <otherwise>
  1445. and status=8
  1446. </otherwise>
  1447. </choose>
  1448. union
  1449. select
  1450. <include refid="allCUserCardListColumns"/>
  1451. from wx_coupon_order co
  1452. inner join wx_coupon c on co.coupon_id = c.id
  1453. inner join wx_card_info a on co.id=a.id
  1454. where 1=1
  1455. and co.coupon_type = 100
  1456. <if test=" null != tenantId and '' != tenantId">
  1457. and co.`tenant_id` = #{tenantId}
  1458. </if>
  1459. <if test=" null != parentTenantId and '' != parentTenantId">
  1460. and co.`parent_tenant_id` = #{parentTenantId}
  1461. </if>
  1462. <if test="cUserId != null">
  1463. and co.c_user_id = #{cUserId}
  1464. </if>
  1465. <if test="ownerId != null">
  1466. and co.owner_id = #{ownerId}
  1467. </if>
  1468. <if test="couponOrderStatus != null">
  1469. and co.coupon_order_status = #{couponOrderStatus}
  1470. </if>
  1471. <if test=" null != statusS ">
  1472. and co.coupon_order_status in
  1473. <foreach collection="statusS" index="index" item="sItem" open="(" separator="," close=")">
  1474. #{sItem}
  1475. </foreach>
  1476. </if>
  1477. ) c
  1478. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  1479. </select>
  1480. <select id="findCardDetailOfCUser" parameterType="java.util.HashMap" resultMap="CCardVoResultMap">
  1481. select <include refid="allCUserCardDetailColumns" />
  1482. from wx_coupon_order co,wx_coupon c, wx_card_info a
  1483. where co.coupon_id = c.id and co.id = a.id
  1484. and co.id = #{id} and co.tenant_id = #{tenantId}
  1485. </select>
  1486. <update id="cardDefer" parameterType="map">
  1487. 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)
  1488. </update>
  1489. <select id="cardDeferCouponOrderId" parameterType="java.util.HashMap" resultType="java.lang.Long">
  1490. select id from wx_coupon_order where coupon_id = #{couponId} and tenant_id = #{tenantId} and coupon_order_status in (4, 5)
  1491. </select>
  1492. <select id="findWriteOffCount" parameterType="com.iformall.domain.po.WxCouponOrder" resultType="java.lang.Integer">
  1493. select count(co.id)
  1494. from wx_coupon_order co
  1495. left join wx_merchant_b_user mbu on co.b_user_id = mbu.id
  1496. where 1 = 1
  1497. <if test=" null != tenantId and '' != tenantId">
  1498. and co.`tenant_id` = #{tenantId}
  1499. </if>
  1500. <if test=" null != parentTenantId and '' != parentTenantId">
  1501. and co.`parent_tenant_id` = #{parentTenantId}
  1502. </if>
  1503. <if test=" null != merchantId ">
  1504. and mbu.`merchant_id` = #{merchantId}
  1505. </if>
  1506. <if test=" null != couponType ">
  1507. and co.`coupon_type` = #{couponType}
  1508. </if>
  1509. <if test=" null != couponOrderStatus ">
  1510. and co.`coupon_order_status` = #{couponOrderStatus}
  1511. </if>
  1512. <if test=" null != sendMerchantId ">
  1513. and co.`send_merchant_id` = #{sendMerchantId}
  1514. </if>
  1515. <if test=" null != startTime ">
  1516. AND co.update_date &gt;= #{startTime}
  1517. </if>
  1518. <if test=" null != endTime ">
  1519. AND co.update_date &lt;= #{endTime}
  1520. </if>
  1521. </select>
  1522. </mapper>