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.
 
 
 
 
 

297 line
13 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.WxOrderGroupMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxOrderGroup">
  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="order_id" jdbcType="BIGINT" property="orderId"/>
  9. <result column="coupon_id" jdbcType="BIGINT" property="couponId"/>
  10. <result column="remain_people" jdbcType="INTEGER" property="remainPeople"/>
  11. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  12. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  13. <result column="expired_date" jdbcType="TIMESTAMP" property="expiredDate"/>
  14. <result column="status" jdbcType="SMALLINT" property="status"/>
  15. <result column="user_id" jdbcType="BIGINT" property="userId"/>
  16. </resultMap>
  17. <sql id="allColumns">
  18. `id`,`tenant_id`,`parent_tenant_id`,`order_id`,`coupon_id`,`remain_people`,`create_date`,`update_date`,`expired_date`,`status`,`user_id`
  19. </sql>
  20. <sql id="dynamicWhereConditions">
  21. where 1 = 1
  22. <if test=" null != id ">
  23. and `id` = #{id}
  24. </if>
  25. <if test=" null != tenantId and '' != tenantId">
  26. and `tenant_id` = #{tenantId}
  27. </if>
  28. <if test=" null != parentTenantId and '' != parentTenantId">
  29. and `parent_tenant_id` = #{parentTenantId}
  30. </if>
  31. <if test=" null != orderId ">
  32. and `order_id` = #{orderId}
  33. </if>
  34. <if test=" null != userId ">
  35. and `coupon_id` = #{couponId}
  36. </if>
  37. <if test=" null != pressValue ">
  38. and `remain_people` = #{remainPeople}
  39. </if>
  40. <if test=" null != createDate ">
  41. and `create_date` = #{createDate}
  42. </if>
  43. <if test=" null != ids ">
  44. and id in
  45. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  46. #{idItem}
  47. </foreach>
  48. </if>
  49. <if test=" null != sortColumns">order by ${sortColumns}</if>
  50. </sql>
  51. <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  52. select <include refid="allColumns"/> from wx_order_group where id = #{id} and tenant_id = #{tenantId}
  53. </select>
  54. <select id="queryRemainOne" parameterType="com.iformall.domain.po.WxOrderGroup" resultType="hashmap">
  55. select o.press_end_date expiredDate,o.order_group_id orderGroupId,c.nick_name nickName,
  56. c.avatar_url avatarUrl,o.id orderId,o.product_id couponId
  57. from wx_order o
  58. left join wx_c_user_basic_info c on o.c_user_id=c.id
  59. where o.id=#{orderId}
  60. <if test=" null != tenantId and '' != tenantId">
  61. and o.`tenant_id` = #{tenantId}
  62. </if>
  63. <if test=" null != parentTenantId and '' != parentTenantId">
  64. and o.`parent_tenant_id` = #{parentTenantId}
  65. </if>
  66. </select>
  67. <select id="queryOrderGroup" parameterType="com.iformall.domain.po.WxOrder" resultType="hashmap">
  68. select o.id orderId,o.order_status orderStatus,o.order_group_id orderGroupId,c.title,c.sub_title subTitle,
  69. c.sale_price salePrice,c.cover_img coverImg,g.remain_people remainPeople,c.id couponId,g.expired_date
  70. expiredDate,g.status,g.user_id firstUser,u.nick_name nickName,u.avatar_url avatarUrl,o.tenant_id tenantId,o.parent_tenant_id parentTenantId,
  71. o.coupon_channel_id couponChannelId,c.press_limit_num pressLimitNum,
  72. (select status from wx_coupon_channel where id=o.coupon_channel_id) couponStatus,
  73. o.compose_order_type composeOrderType
  74. from wx_order o
  75. left join wx_coupon c on o.product_id=c.id
  76. left join wx_order_group g on o.order_group_id=g.id
  77. left join wx_c_user_basic_info u on o.c_user_id=u.id
  78. where c.type=9
  79. <if test=" null != tenantId and '' != tenantId">
  80. and o.`tenant_id` = #{tenantId}
  81. </if>
  82. <if test=" null != parentTenantId and '' != parentTenantId">
  83. and o.`parent_tenant_id` = #{parentTenantId}
  84. </if>
  85. <if test=" null != cUserId ">
  86. and o.c_user_id=#{cUserId}
  87. </if>
  88. <if test=" null != id ">
  89. and o.id=#{id}
  90. </if>
  91. <if test=" null != orderGroupId ">
  92. and o.order_group_id=#{orderGroupId}
  93. </if>
  94. and o.order_status in(10,11,12,13,14,15,16,98,99)
  95. order by o.id desc,o.order_status
  96. </select>
  97. <update id="updateOrderGroup" parameterType="com.iformall.domain.po.WxOrderGroup">
  98. update wx_order_group set remain_people=remain_people-1,status=#{status},update_date=#{updateDate} where id=#{id} and remain_people>0
  99. </update>
  100. <select id="queryOrderGroupMarketingList"
  101. resultType="com.iformall.domain.vo.WxOrderGroupMarketing">
  102. SELECT c.tenant_id,c.parent_tenant_id, c.id, c.cover_img, c.title,
  103. IFNULL(og.group_total_count,0) as group_total_count,
  104. IFNULL(og2.group_success_count,0) as group_success_count,
  105. IFNULL(o.success_people,0) as success_people,
  106. IFNULL(co.verify_count,0) as verify_count,
  107. IFNULL(o2.total_people,0) as total_people,
  108. ROUND(IFNULL((og2.group_success_count / og.group_total_count), 0) * 100) group_transfer_ratio,
  109. ROUND(IFNULL((co.verify_count / o.success_people), 0) * 100) verify_ratio,
  110. ROUND(c.price / 100, 2) price,
  111. ROUND(c.sale_price / 100, 2) sale_price
  112. FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  113. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  114. </foreach>) c
  115. left join (SELECT count(*) group_total_count, coupon_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  116. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  117. </foreach>) wx_order_group group by coupon_id) og on og.coupon_id = c.id
  118. left join (SELECT count(*) group_success_count, coupon_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  119. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  120. </foreach>) wx_order_group WHERE status = 11 group by coupon_id) og2 on og2.coupon_id = c.id
  121. left join (SELECT count(*) success_people, product_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  122. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  123. </foreach>) wx_order WHERE order_status = 11 group by product_id ) o on o.product_id = c.id
  124. left join (SELECT count(*) verify_count, coupon_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  125. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  126. </foreach>) wx_coupon_order WHERE coupon_type = 9 AND coupon_order_status = 1 group by coupon_id ) co on co.coupon_id = c.id
  127. left join (SELECT count(*) total_people, product_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  128. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  129. </foreach>) wx_order WHERE order_group_id != 0 group by product_id ) o2 on o2.product_id = c.id
  130. WHERE type = 9
  131. <if test=" null != marketing.tenantId and '' != marketing.tenantId">
  132. and c.`tenant_id` = #{marketing.tenantId}
  133. </if>
  134. <if test=" null != marketing.parentTenantId and '' != marketing.parentTenantId">
  135. and c.`parent_tenant_id` = #{marketing.parentTenantId}
  136. </if>
  137. <if test=" null != marketing.couponId and '' != marketing.couponId">
  138. and c.coupon_id=#{marketing.couponId}
  139. </if>
  140. <if test=" null != marketing.title and '' != marketing.title">
  141. and c.title like concat('%',#{marketing.title},'%')
  142. </if>
  143. <if test=" null != marketing.sortColumns"> order by ${marketing.sortColumns} </if>
  144. <if test=" null == marketing.sortColumns">order by c.status asc,c.create_date desc</if>
  145. </select>
  146. <select id="queryOrderGroupSuccessCountAndTime" parameterType="hashmap" resultType="hashmap">
  147. select count(1) total,DATE_FORMAT(create_date,'%Y-%m-%d') time from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  148. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  149. </foreach>) wx_coupon_order
  150. where coupon_type=9
  151. <if test=" null != tenantId and '' != tenantId">
  152. and `tenant_id` = #{tenantId}
  153. </if>
  154. <if test=" null != parentTenantId and '' != parentTenantId">
  155. and `parent_tenant_id` = #{parentTenantId}
  156. </if>
  157. <if test=" null != startdate and null!=enddate ">
  158. and create_date BETWEEN #{startdate} and #{enddate}
  159. </if>
  160. <if test=" null != couponId ">
  161. and coupon_id=#{couponId}
  162. </if>
  163. group by time
  164. </select>
  165. <select id="queryOrderGroupVerifyCountAndTime" parameterType="hashmap" resultType="hashmap">
  166. select count(1) total,DATE_FORMAT(create_date,'%Y-%m-%d') time
  167. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  168. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  169. </foreach>) wx_coupon_order where coupon_type=9 and coupon_order_status=1
  170. <if test=" null != tenantId and '' != tenantId">
  171. and `tenant_id` = #{tenantId}
  172. </if>
  173. <if test=" null != parentTenantId and '' != parentTenantId">
  174. and `parent_tenant_id` = #{parentTenantId}
  175. </if>
  176. <if test=" null != startdate and null!=enddate ">
  177. and create_date BETWEEN #{startdate} and #{enddate}
  178. </if>
  179. <if test=" null != couponId ">
  180. and coupon_id=#{couponId}
  181. </if>
  182. group by time
  183. </select>
  184. <select id="queryOrderGroupCount" parameterType="hashmap" resultType="long">
  185. select count(1) total from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  186. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  187. </foreach>) wx_order_group
  188. <where>
  189. <if test=" null != tenantId and '' != tenantId">
  190. and `tenant_id` = #{tenantId}
  191. </if>
  192. <if test=" null != parentTenantId and '' != parentTenantId">
  193. and `parent_tenant_id` = #{parentTenantId}
  194. </if>
  195. <if test=" null != startdate and null!=enddate ">
  196. and create_date BETWEEN #{startdate} and #{enddate}
  197. </if>
  198. </where>
  199. </select>
  200. <select id="queryOrderGroupCountHistory" resultType="com.iformall.domain.vo.WxCouponStatisVo">
  201. select DATE_FORMAT(create_date,'%Y-%m-%d') xtime,count(*) xcount
  202. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  203. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  204. </foreach>) wx_order_group
  205. <where>
  206. <if test=" null != wxCoupon.startdate and null!= wxCoupon.enddate ">
  207. and create_date BETWEEN #{wxCoupon.startdate} and #{wxCoupon.enddate}
  208. </if>
  209. </where>
  210. group by xtime
  211. </select>
  212. <select id="queryOrderGroupSuccessCount" parameterType="hashmap" resultType="long">
  213. select count(1) total from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  214. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  215. </foreach>) wx_order_group where status=11
  216. <if test=" null != tenantId and '' != tenantId">
  217. and `tenant_id` = #{tenantId}
  218. </if>
  219. <if test=" null != parentTenantId and '' != parentTenantId">
  220. and `parent_tenant_id` = #{parentTenantId}
  221. </if>
  222. <if test=" null != startdate and null!=enddate ">
  223. and create_date BETWEEN #{startdate} and #{enddate}
  224. </if>
  225. </select>
  226. <select id="queryOrderGroupPeopleCount" parameterType="hashmap" resultType="long">
  227. select count(1) from (select id from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  228. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  229. </foreach>) wx_order where order_group_id!=0
  230. <if test=" null != tenantId and '' != tenantId">
  231. and `tenant_id` = #{tenantId}
  232. </if>
  233. <if test=" null != parentTenantId and '' != parentTenantId">
  234. and `parent_tenant_id` = #{parentTenantId}
  235. </if>
  236. <if test=" null != startdate and null!=enddate ">
  237. and create_date BETWEEN #{startdate} and #{enddate}
  238. </if>
  239. ) g
  240. </select>
  241. <select id="queryOrderGroupVerifyCount" parameterType="hashmap" resultType="long">
  242. select count(1) total from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  243. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  244. </foreach>) wx_coupon_order where coupon_type=9 and coupon_order_status=1
  245. <if test=" null != tenantId and '' != tenantId">
  246. and `tenant_id` = #{tenantId}
  247. </if>
  248. <if test=" null != parentTenantId and '' != parentTenantId">
  249. and `parent_tenant_id` = #{parentTenantId}
  250. </if>
  251. <if test=" null != startdate and null!=enddate ">
  252. and create_date BETWEEN #{startdate} and #{enddate}
  253. </if>
  254. <if test=" null != couponId ">
  255. and coupon_id=#{couponId}
  256. </if>
  257. </select>
  258. <select id="queryOrderGroupSuccessPeopleCount" parameterType="hashmap" resultType="long">
  259. select count(1) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  260. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  261. </foreach>) wx_order where order_status=11
  262. <if test=" null != tenantId and '' != tenantId">
  263. and `tenant_id` = #{tenantId}
  264. </if>
  265. <if test=" null != parentTenantId and '' != parentTenantId">
  266. and `parent_tenant_id` = #{parentTenantId}
  267. </if>
  268. <if test=" null != startdate and null!=enddate ">
  269. and create_date BETWEEN #{startdate} and #{enddate}
  270. </if>
  271. </select>
  272. </mapper>