Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

284 linhas
12 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="createDate"/>
  13. <result column="expired_date" jdbcType="TIMESTAMP" property="createDate"/>
  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. from wx_order o
  74. left join wx_coupon c on o.product_id=c.id
  75. left join wx_order_group g on o.order_group_id=g.id
  76. left join wx_c_user_basic_info u on o.c_user_id=u.id
  77. where c.type=9
  78. <if test=" null != tenantId and '' != tenantId">
  79. and o.`tenant_id` = #{tenantId}
  80. </if>
  81. <if test=" null != parentTenantId and '' != parentTenantId">
  82. and o.`parent_tenant_id` = #{parentTenantId}
  83. </if>
  84. <if test=" null != cUserId ">
  85. and o.c_user_id=#{cUserId}
  86. </if>
  87. <if test=" null != id ">
  88. and o.id=#{id}
  89. </if>
  90. <if test=" null != orderGroupId ">
  91. and o.order_group_id=#{orderGroupId}
  92. </if>
  93. and o.order_status in(10,11,12,13,14,15,16,98,99)
  94. order by o.id desc,o.order_status
  95. </select>
  96. <update id="updateOrderGroup" parameterType="com.iformall.domain.po.WxOrderGroup">
  97. update wx_order_group set remain_people=remain_people-1,status=#{status},update_date=#{updateDate} where id=#{id} and remain_people>0
  98. </update>
  99. <select id="queryOrderGroupMarketingList" parameterType="com.iformall.domain.vo.WxOrderGroupMarketing"
  100. resultType="com.iformall.domain.vo.WxOrderGroupMarketing">
  101. SELECT c.tenant_id,c.parent_tenant_id, c.id, c.cover_img, c.title,
  102. IFNULL(og.group_total_count,0) as group_total_count,
  103. IFNULL(og2.group_success_count,0) as group_success_count,
  104. IFNULL(o.success_people,0) as success_people,
  105. IFNULL(co.verify_count,0) as verify_count,
  106. IFNULL(o2.total_people,0) as total_people,
  107. ROUND(IFNULL((og2.group_success_count / og.group_total_count), 0) * 100) group_transfer_ratio,
  108. ROUND(IFNULL((co.verify_count / o.success_people), 0) * 100) verify_ratio,
  109. ROUND(c.price / 100, 2) price,
  110. ROUND(c.sale_price / 100, 2) sale_price
  111. FROM wx_coupon c
  112. left join (SELECT count(*) group_total_count, coupon_id FROM wx_order_group group by coupon_id) og on og.coupon_id = c.id
  113. left join (SELECT count(*) group_success_count, coupon_id FROM wx_order_group WHERE status = 11 group by coupon_id) og2 on og2.coupon_id = c.id
  114. left join (SELECT count(*) success_people, product_id FROM wx_order WHERE order_status = 11 group by product_id ) o on o.product_id = c.id
  115. left join (SELECT count(*) verify_count, coupon_id FROM wx_coupon_order WHERE coupon_type = 9 AND coupon_order_status = 1 group by coupon_id ) co on co.coupon_id = c.id
  116. left join (SELECT count(*) total_people, product_id FROM wx_order WHERE order_group_id != 0 group by product_id ) o2 on o2.product_id = c.id
  117. WHERE type = 9
  118. <if test=" null != tenantId and '' != tenantId">
  119. and c.`tenant_id` = #{tenantId}
  120. </if>
  121. <if test=" null != parentTenantId and '' != parentTenantId">
  122. and c.`parent_tenant_id` = #{parentTenantId}
  123. </if>
  124. <if test=" null != couponId and ''!=couponId">
  125. and c.coupon_id=#{couponId}
  126. </if>
  127. <if test=" null != title and ''!=title">
  128. and c.title like concat('%',#{title},'%')
  129. </if>
  130. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  131. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  132. </select>
  133. <select id="queryOrderGroupSuccessCountAndTime" parameterType="hashmap" resultType="hashmap">
  134. select count(1) total,DATE_FORMAT(create_date,'%Y-%m-%d') time from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  135. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  136. </foreach>) wx_coupon_order
  137. where coupon_type=9
  138. <if test=" null != tenantId and '' != tenantId">
  139. and `tenant_id` = #{tenantId}
  140. </if>
  141. <if test=" null != parentTenantId and '' != parentTenantId">
  142. and `parent_tenant_id` = #{parentTenantId}
  143. </if>
  144. <if test=" null != startdate and null!=enddate ">
  145. and create_date BETWEEN #{startdate} and #{enddate}
  146. </if>
  147. <if test=" null != couponId ">
  148. and coupon_id=#{couponId}
  149. </if>
  150. group by time
  151. </select>
  152. <select id="queryOrderGroupVerifyCountAndTime" parameterType="hashmap" resultType="hashmap">
  153. select count(1) total,DATE_FORMAT(create_date,'%Y-%m-%d') time
  154. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  155. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  156. </foreach>) wx_coupon_order where coupon_type=9 and coupon_order_status=1
  157. <if test=" null != tenantId and '' != tenantId">
  158. and `tenant_id` = #{tenantId}
  159. </if>
  160. <if test=" null != parentTenantId and '' != parentTenantId">
  161. and `parent_tenant_id` = #{parentTenantId}
  162. </if>
  163. <if test=" null != startdate and null!=enddate ">
  164. and create_date BETWEEN #{startdate} and #{enddate}
  165. </if>
  166. <if test=" null != couponId ">
  167. and coupon_id=#{couponId}
  168. </if>
  169. group by time
  170. </select>
  171. <select id="queryOrderGroupCount" parameterType="hashmap" resultType="long">
  172. select count(1) total from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  173. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  174. </foreach>) wx_order_group
  175. <where>
  176. <if test=" null != tenantId and '' != tenantId">
  177. and `tenant_id` = #{tenantId}
  178. </if>
  179. <if test=" null != parentTenantId and '' != parentTenantId">
  180. and `parent_tenant_id` = #{parentTenantId}
  181. </if>
  182. <if test=" null != startdate and null!=enddate ">
  183. and create_date BETWEEN #{startdate} and #{enddate}
  184. </if>
  185. </where>
  186. </select>
  187. <select id="queryOrderGroupCountHistory" resultType="com.iformall.domain.vo.WxCouponStatisVo">
  188. select DATE_FORMAT(create_date,'%Y-%m-%d') xtime,count(*) xcount
  189. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  190. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  191. </foreach>) wx_order_group
  192. <where>
  193. <if test=" null != wxCoupon.startdate and null!= wxCoupon.enddate ">
  194. and create_date BETWEEN #{wxCoupon.startdate} and #{wxCoupon.enddate}
  195. </if>
  196. </where>
  197. group by xtime
  198. </select>
  199. <select id="queryOrderGroupSuccessCount" parameterType="hashmap" resultType="long">
  200. select count(1) total from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  201. SELECT * from wx_order_group${tenantEntity.shardTableSuffix}
  202. </foreach>) wx_order_group where status=11
  203. <if test=" null != tenantId and '' != tenantId">
  204. and `tenant_id` = #{tenantId}
  205. </if>
  206. <if test=" null != parentTenantId and '' != parentTenantId">
  207. and `parent_tenant_id` = #{parentTenantId}
  208. </if>
  209. <if test=" null != startdate and null!=enddate ">
  210. and create_date BETWEEN #{startdate} and #{enddate}
  211. </if>
  212. </select>
  213. <select id="queryOrderGroupPeopleCount" parameterType="hashmap" resultType="long">
  214. select count(1) from (select id from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  215. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  216. </foreach>) wx_order where order_group_id!=0
  217. <if test=" null != tenantId and '' != tenantId">
  218. and `tenant_id` = #{tenantId}
  219. </if>
  220. <if test=" null != parentTenantId and '' != parentTenantId">
  221. and `parent_tenant_id` = #{parentTenantId}
  222. </if>
  223. <if test=" null != startdate and null!=enddate ">
  224. and create_date BETWEEN #{startdate} and #{enddate}
  225. </if>
  226. ) g
  227. </select>
  228. <select id="queryOrderGroupVerifyCount" parameterType="hashmap" resultType="long">
  229. select count(1) total from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  230. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  231. </foreach>) wx_coupon_order where coupon_type=9 and coupon_order_status=1
  232. <if test=" null != tenantId and '' != tenantId">
  233. and `tenant_id` = #{tenantId}
  234. </if>
  235. <if test=" null != parentTenantId and '' != parentTenantId">
  236. and `parent_tenant_id` = #{parentTenantId}
  237. </if>
  238. <if test=" null != startdate and null!=enddate ">
  239. and create_date BETWEEN #{startdate} and #{enddate}
  240. </if>
  241. <if test=" null != couponId ">
  242. and coupon_id=#{couponId}
  243. </if>
  244. </select>
  245. <select id="queryOrderGroupSuccessPeopleCount" parameterType="hashmap" resultType="long">
  246. select count(1) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  247. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  248. </foreach>) wx_order where order_status=11
  249. <if test=" null != tenantId and '' != tenantId">
  250. and `tenant_id` = #{tenantId}
  251. </if>
  252. <if test=" null != parentTenantId and '' != parentTenantId">
  253. and `parent_tenant_id` = #{parentTenantId}
  254. </if>
  255. <if test=" null != startdate and null!=enddate ">
  256. and create_date BETWEEN #{startdate} and #{enddate}
  257. </if>
  258. </select>
  259. </mapper>