No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

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