OrderDonMapper.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.cyksj.mapper.OrderDonMapper">
  4. <update id="updateHasPaymentInterestRealGoods">
  5. update real_goods_interest_user
  6. set interest_status = 'hasPayment'
  7. where id in (select id
  8. from (select distinct ru.id
  9. from `real_goods_interest_user` ru
  10. left join `order_don` od on od.user_id = ru.user_id and od.goods_id = ru.goods_id
  11. where od.status not in ('close', 'noPayment')
  12. and ru.interest_status != 'hasPayment') s)
  13. </update>
  14. <update id="updateHasPaymentInterestRealGoodsPayTime">
  15. update real_goods_interest_user ru
  16. set ru.pay_time= (select if(pay_time is null,created_time,pay_time) from `order_don` od where od.user_id = ru.user_id and od.goods_id = ru.goods_id and od.status not in ('close','noPayment') order by money desc limit 1),
  17. ru.sku_id = (select sku_id from `order_don` od where od.user_id = ru.user_id and od.goods_id = ru.goods_id and od.status not in ('close','noPayment') order by money desc limit 1)
  18. where interest_status = 'hasPayment'
  19. and pay_time is null
  20. </update>
  21. <select id="exportOrderInfo" resultType="com.cyksj.model.excel.ExcelOrderDonInfo">
  22. SELECT o.order_no, o.real_name ,o.price,o.phone,o.source,o.pay_time ,u1.nickname as sharedName,u2.nickname as nickName
  23. from order_don o LEFT JOIN user u1 on o.shared_id = u1.id
  24. LEFT JOIN user u2 on o.user_id = u2.id
  25. where o.promotion_id = #{promotionId,jdbcType=BIGINT}
  26. and o.status = 'hasPayment'
  27. <if test="start != null and start != ''">
  28. and o.pay_time >= #{start,jdbcType=VARCHAR}
  29. </if>
  30. <if test="end != null and end != ''">
  31. and #{end,jdbcType=VARCHAR} >= o.pay_time
  32. </if>
  33. </select>
  34. <select id="getAppleOneOrderDons" resultType="com.cyksj.model.entity.OrderDon">
  35. select id,sku_id,user_id,money,is_distribute,`type` from `order_don`
  36. where sku_id in
  37. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  38. #{item}
  39. </foreach>
  40. and status not in
  41. <foreach collection="noOrderStatus" item="item" open="(" separator="," close=")">
  42. #{item}
  43. </foreach>
  44. and created_time between #{yesZeroDate} and #{thisZeroDate}
  45. </select>
  46. <select id="selectNoPaymentRealGoods" resultType="com.cyksj.model.entity.RealGoodsInterestUser">
  47. select s.*
  48. from (select od.id as orderId,
  49. od.user_id,
  50. gd.id as goods_id,
  51. od.sku_id,
  52. od.money,
  53. concat(od.user_id, gd.id) as groupBy,
  54. od.created_time as orderCreatedTime
  55. from `order_don` od
  56. left join `goods_don` gd on gd.id = od.goods_id
  57. left join `real_goods_interest_user` ru on ru.user_id = od.user_id
  58. and ru.goods_id = od.goods_id
  59. where gd.type = 2
  60. and od.status = 'close'
  61. and ru.id is null
  62. group by od.id, od.user_id, gd.id, od.sku_id, od.money, od.created_time) s
  63. where not EXISTS(
  64. select id from `order_don` where user_id = s.user_id and goods_id = s.goods_id and status !='close')
  65. </select>
  66. <select id="selectPlatBrokenLineMoney" resultType="com.cyksj.model.views.BrokenLineObjView">
  67. select min(curdate) as firstDate,
  68. max(curdate) as lastDate
  69. from (select cast(sum(od.money)/100 as decimal(10,2)) as curdateMoney,
  70. date_format(od.created_time,'%Y-%m-%d') curdate from order_don od
  71. where od.status not in ('noPayment','close','refund')
  72. group by od.goods_id,date_format(od.created_time,'%Y-%m-%d'))s
  73. where 1 = 1
  74. <if test="first != null">
  75. and curdate >= #{first}
  76. </if>
  77. <if test="end != null">
  78. and curdate &lt; #{end}
  79. </if>
  80. </select>
  81. <select id="selectPersonDistributeBrokenLine" resultType="com.cyksj.model.views.BrokenLineObjView">
  82. select min(curdate) as firstDate,
  83. max(curdate) as lastDate
  84. from (select date_format(od.created_time,'%Y-%m-%d') curdate,
  85. count(od.id) curdateOrderCount
  86. from distribute_waiting_send_points dw
  87. left join order_don od on od.id = dw.order_id
  88. where dw.shared_id = #{userId}
  89. and od.is_distribute is true
  90. and dw.send_status not in ('not_exist', 'close')
  91. group by od.goods_id, date_format(od.created_time, '%Y-%m-%d'))s
  92. where 1 = 1
  93. <if test="first != null">
  94. and curdate >= #{first}
  95. </if>
  96. <if test="end != null">
  97. and curdate &lt; #{end}
  98. </if>
  99. </select>
  100. <select id="selectChannelStatistics" resultType="com.cyksj.model.views.ChannelStatisticsView">
  101. select min(curdate) as firstDate,
  102. max(curdate) as lastDate
  103. from (select cast(sum(od.money)/100 as decimal(10,2)) as curdateMoney,
  104. date_format(od.created_time,'%Y-%m-%d') curdate from order_don od
  105. where od.status not in ('noPayment','close','refund')
  106. group by date_format(od.created_time,'%Y-%m-%d'))s
  107. where 1 = 1
  108. <if test="first != null">
  109. and curdate >= #{first}
  110. </if>
  111. <if test="end != null">
  112. and curdate &lt; #{end}
  113. </if>
  114. </select>
  115. <select id="selectCouponCodeUserNum" resultType="java.lang.Integer">
  116. select count(distinct user_id) from order_don where ds_popularize_id = #{dsPopularizeId}
  117. and status not in
  118. <foreach collection="noOrderAllStatus" item="item" open="(" separator="," close=")">
  119. #{item}
  120. </foreach>
  121. </select>
  122. <select id="countPopularizeOrderDetail" resultType="com.cyksj.model.views.ChannelPopularizeView">
  123. select *
  124. from (select count(*) as orderCount, ifnull(sum(money),0) as orderMoney
  125. from order_don
  126. where popularize_id = #{popularizeId}
  127. <if test="startTime != null and startTime != ''">
  128. and created_time >= #{startTime}
  129. </if>
  130. <if test="endTime != null and endTime != ''">
  131. and created_time &lt; #{endTime}
  132. </if>
  133. and status not in ('close', 'noPayment')) s1
  134. ,
  135. (select count(*) as refundCount, ifnull(sum(money),0) as refundMoney
  136. from order_don
  137. where popularize_id = #{popularizeId}
  138. <if test="startTime != null and startTime != ''">
  139. and created_time >= #{startTime}
  140. </if>
  141. <if test="endTime != null and endTime != ''">
  142. and created_time &lt; #{endTime}
  143. </if>
  144. and status = 'refund')
  145. s2
  146. </select>
  147. <select id="selectThisMonthAppleOneMoney" resultType="java.math.BigDecimal">
  148. select cast(ifnull((sum(money),0) - ifnull(sum(refund_money),0))/100 as decimal(10,2)) from `order_don` where sku_id in
  149. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  150. #{item}
  151. </foreach>
  152. and status not in ('close','noPayment') and created_time between #{startDate} and #{endDate}
  153. </select>
  154. <select id="selectThisMonthDistributeOrderMoney" resultType="java.math.BigDecimal">
  155. select cast((ifnull(sum(money),0) - ifnull(sum(refund_money),0))/100 as decimal(10,2)) from `order_don` where sku_id in
  156. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  157. #{item}
  158. </foreach>
  159. and status not in ('close','noPayment') and is_distribute = 1
  160. and created_time between #{startDate} and #{endDate}
  161. </select>
  162. <select id="getOrderDetailByGoodsType" resultType="java.util.Map">
  163. select count(id) as orderNum,
  164. ifnull(sum(money),0) as money
  165. from order_don where goods_id in (select id from `goods_don` where type = #{type})
  166. and status not in
  167. <foreach collection="noOrderStatus" item="item" open="(" separator="," close=")">
  168. #{item}
  169. </foreach>
  170. <if test="startDate != null">
  171. and created_time >= #{startDate}
  172. </if>
  173. <if test="endDate != null">
  174. and created_time &lt; #{endDate}
  175. </if>
  176. </select>
  177. <select id="selectYhShopDistributeOrderDetail" resultType="java.util.Map">
  178. select count(*) as numOfDsOrder,
  179. ifnull(sum(money),0) as dsMoney
  180. from `order_don` where yhs_id > 0 and status not in ('close','noPayment','refund')
  181. <if test="startDate != null">
  182. and created_time >= #{startDate}
  183. </if>
  184. <if test="endDate != null">
  185. and created_time &lt; #{endDate}
  186. </if>
  187. </select>
  188. </mapper>