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

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