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.
 
 
 
 
 

226 lines
8.6 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="order_id" jdbcType="BIGINT" property="orderId"/>
  8. <result column="coupon_id" jdbcType="BIGINT" property="couponId"/>
  9. <result column="remain_people" jdbcType="INTEGER" property="remainPeople"/>
  10. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  11. <result column="update_date" jdbcType="TIMESTAMP" property="createDate"/>
  12. <result column="expired_date" jdbcType="TIMESTAMP" property="createDate"/>
  13. <result column="status" jdbcType="SMALLINT" property="status"/>
  14. <result column="user_id" jdbcType="BIGINT" property="userId"/>
  15. </resultMap>
  16. <sql id="allColumns">
  17. `id`,`tenant_id`,`order_id`,`coupon_id`,`remain_people`,`create_date`,`update_date`,`expired_date`,`status`,`user_id`
  18. </sql>
  19. <sql id="dynamicWhereConditions">
  20. where 1 = 1
  21. <if test=" null != id ">
  22. and `id` = #{id}
  23. </if>
  24. <if test=" null != tenantId ">
  25. and `tenant_id` = #{tenantId}
  26. </if>
  27. <if test=" null != orderId ">
  28. and `order_id` = #{orderId}
  29. </if>
  30. <if test=" null != userId ">
  31. and `coupon_id` = #{couponId}
  32. </if>
  33. <if test=" null != pressValue ">
  34. and `remain_people` = #{remainPeople}
  35. </if>
  36. <if test=" null != createDate ">
  37. and `create_date` = #{createDate}
  38. </if>
  39. <if test=" null != ids ">
  40. and id in
  41. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  42. #{idItem}
  43. </foreach>
  44. </if>
  45. <if test=" null != sortColumns">order by ${sortColumns}</if>
  46. </sql>
  47. <select id="queryRemainOne" parameterType="com.iformall.domain.po.WxOrderGroup" resultType="hashmap">
  48. select o.press_end_date expiredDate,o.order_group_id orderGroupId,c.nick_name nickName,
  49. c.avatar_url avatarUrl,o.id orderId,o.product_id couponId
  50. from wx_order o
  51. left join wx_c_user c on o.c_user_id=c.id
  52. where o.tenant_id=#{tenantId} and o.id=#{orderId}
  53. </select>
  54. <select id="queryOrderGroup" parameterType="com.iformall.domain.po.WxOrder" resultType="hashmap">
  55. select o.id orderId,o.order_status orderStatus,o.order_group_id orderGroupId,c.title,c.sub_title subTitle,
  56. c.sale_price salePrice,c.cover_img coverImg,g.remain_people remainPeople,c.id couponId,g.expired_date
  57. expiredDate,g.status,g.user_id firstUser,u.nick_name nickName,u.avatar_url avatarUrl,o.tenant_id tenantId,
  58. o.coupon_channel_id couponChannelId,c.press_limit_num pressLimitNum,
  59. (select status from wx_coupon_channel where id=o.coupon_channel_id) couponStatus
  60. from wx_order o
  61. left join wx_coupon c on o.product_id=c.id
  62. left join wx_order_group g on o.order_group_id=g.id
  63. left join wx_c_user u on o.c_user_id=u.id
  64. where o.tenant_id=#{tenantId} and c.type=9
  65. <if test=" null != cUserId ">
  66. and o.c_user_id=#{cUserId}
  67. </if>
  68. <if test=" null != id ">
  69. and o.id=#{id}
  70. </if>
  71. <if test=" null != orderGroupId ">
  72. and o.order_group_id=#{orderGroupId}
  73. </if>
  74. and o.order_status in(10,11,12,13,14,15,16)
  75. order by o.id desc,o.order_status
  76. </select>
  77. <update id="updateOrderGroup" parameterType="com.iformall.domain.po.WxOrderGroup">
  78. update wx_order_group set remain_people=remain_people-1,status=#{status},update_date=#{updateDate} where id=#{id} and remain_people>0
  79. </update>
  80. <select id="queryOrderGroupMarketingList" parameterType="com.iformall.domain.vo.WxOrderGroupMarketing"
  81. resultType="com.iformall.domain.vo.WxOrderGroupMarketing">
  82. SELECT c.tenant_id, c.id, c.cover_img, c.title,
  83. IFNULL(og.group_total_count,0) as group_total_count,
  84. IFNULL(og2.group_success_count,0) as group_success_count,
  85. IFNULL(o.success_people,0) as success_people,
  86. IFNULL(co.verify_count,0) as verify_count,
  87. IFNULL(o2.total_people,0) as total_people,
  88. ROUND(IFNULL((og2.group_success_count / og.group_total_count), 0) * 100) group_transfer_ratio,
  89. ROUND(IFNULL((co.verify_count / o.success_people), 0) * 100) verify_ratio,
  90. ROUND(c.price / 100, 2) price,
  91. ROUND(c.sale_price / 100, 2) sale_price
  92. FROM wx_coupon c
  93. left join (SELECT count(*) group_total_count, coupon_id FROM wx_order_group group by coupon_id) og on og.coupon_id = c.id
  94. 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
  95. 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
  96. 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
  97. 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
  98. WHERE type = 9
  99. <if test=" null != tenantId">
  100. and c.tenant_id=#{tenantId}
  101. </if>
  102. <if test=" null != couponId and ''!=couponId">
  103. and c.coupon_id=#{couponId}
  104. </if>
  105. <if test=" null != title and ''!=title">
  106. and c.title like concat('%',#{title},'%')
  107. </if>
  108. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  109. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  110. </select>
  111. <select id="queryOrderGroupSuccessCountAndTime" parameterType="hashmap" resultType="hashmap">
  112. select count(*) total,DATE_FORMAT(create_date,'%Y-%m-%d') time from wx_coupon_order
  113. where coupon_type=9
  114. <if test=" null != tenantId">
  115. and tenant_id=#{tenantId}
  116. </if>
  117. <if test=" null != startdate and null!=enddate ">
  118. and create_date BETWEEN #{startdate} and #{enddate}
  119. </if>
  120. <if test=" null != couponId ">
  121. and coupon_id=#{couponId}
  122. </if>
  123. group by time
  124. </select>
  125. <select id="queryOrderGroupVerifyCountAndTime" parameterType="hashmap" resultType="hashmap">
  126. select count(*) total,DATE_FORMAT(create_date,'%Y-%m-%d') time
  127. from wx_coupon_order where coupon_type=9 and coupon_order_status=1
  128. <if test=" null != tenantId">
  129. and tenant_id=#{tenantId}
  130. </if>
  131. <if test=" null != startdate and null!=enddate ">
  132. and create_date BETWEEN #{startdate} and #{enddate}
  133. </if>
  134. <if test=" null != couponId ">
  135. and coupon_id=#{couponId}
  136. </if>
  137. group by time
  138. </select>
  139. <select id="queryOrderGroupCount" parameterType="hashmap" resultType="long">
  140. select count(*) total from wx_order_group
  141. <where>
  142. <if test=" null != tenantId">
  143. and tenant_id=#{tenantId}
  144. </if>
  145. <if test=" null != startdate and null!=enddate ">
  146. and create_date BETWEEN #{startdate} and #{enddate}
  147. </if>
  148. </where>
  149. </select>
  150. <select id="queryOrderGroupCountHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.vo.WxCouponStatisVo">
  151. select DATE_FORMAT(create_date,'%Y-%m-%d') xtime,count(*) xcount
  152. from wx_order_group
  153. <where>
  154. <if test=" null != tenantId">
  155. and tenant_id=#{tenantId}
  156. </if>
  157. <if test=" null != startdate and null!=enddate ">
  158. and create_date BETWEEN #{startdate} and #{enddate}
  159. </if>
  160. </where>
  161. group by xtime
  162. </select>
  163. <select id="queryOrderGroupSuccessCount" parameterType="hashmap" resultType="long">
  164. select count(*) total from wx_order_group where status=11
  165. <if test=" null != tenantId">
  166. and tenant_id=#{tenantId}
  167. </if>
  168. <if test=" null != startdate and null!=enddate ">
  169. and create_date BETWEEN #{startdate} and #{enddate}
  170. </if>
  171. </select>
  172. <select id="queryOrderGroupPeopleCount" parameterType="hashmap" resultType="long">
  173. select count(*) from (select id from wx_order where order_group_id!=0
  174. <if test=" null != tenantId">
  175. and tenant_id=#{tenantId}
  176. </if>
  177. <if test=" null != startdate and null!=enddate ">
  178. and create_date BETWEEN #{startdate} and #{enddate}
  179. </if>
  180. ) g
  181. </select>
  182. <select id="queryOrderGroupVerifyCount" parameterType="hashmap" resultType="long">
  183. select count(*) total from wx_coupon_order where coupon_type=9 and coupon_order_status=1
  184. <if test=" null != tenantId">
  185. and tenant_id=#{tenantId}
  186. </if>
  187. <if test=" null != startdate and null!=enddate ">
  188. and create_date BETWEEN #{startdate} and #{enddate}
  189. </if>
  190. <if test=" null != couponId ">
  191. and coupon_id=#{couponId}
  192. </if>
  193. </select>
  194. <select id="queryOrderGroupSuccessPeopleCount" parameterType="hashmap" resultType="long">
  195. select count(*) from wx_order where order_status=11
  196. <if test=" null != tenantId">
  197. and tenant_id=#{tenantId}
  198. </if>
  199. <if test=" null != startdate and null!=enddate ">
  200. and create_date BETWEEN #{startdate} and #{enddate}
  201. </if>
  202. </select>
  203. </mapper>