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

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