OrderDonMapper.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 distinct s.* from (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})s
  45. inner join `groups_relation` gr
  46. on gr.user_id = s.user_id
  47. inner join `groups_trips` gt
  48. on gt.id = gr.groups_id
  49. inner join `goods_don` g on g.id in
  50. <foreach collection="goodsIds" item="item" open="(" separator="," close=")">
  51. #{item}
  52. </foreach>
  53. where g.title = #{appleOne} and gr.status = 'validity'
  54. </select>
  55. <select id="selectNoPaymentRealGoods" resultType="com.cyksj.model.entity.RealGoodsInterestUser">
  56. select s.*
  57. from (select od.id as orderId,
  58. od.user_id,
  59. gd.id as goods_id,
  60. od.sku_id,
  61. od.money,
  62. concat(od.user_id, gd.id) as groupBy,
  63. od.created_time as orderCreatedTime
  64. from `order_don` od
  65. left join `goods_don` gd on gd.id = od.goods_id
  66. left join `real_goods_interest_user` ru on ru.user_id = od.user_id
  67. and ru.goods_id = od.goods_id
  68. where gd.type = 2
  69. and od.status = 'close'
  70. and ru.id is null
  71. group by od.id, od.user_id, gd.id, od.sku_id, od.money, od.created_time) s
  72. where not EXISTS(
  73. select id from `order_don` where user_id = s.user_id and goods_id = s.goods_id and status !='close')
  74. </select>
  75. <select id="getOrderDetail" resultType="com.cyksj.model.manage.views.OrderDonView">
  76. select od.*,
  77. gdk.spec_val,
  78. gd.title,
  79. gd.logo,
  80. gd.type as goodsDonType
  81. from `order_don` od
  82. left join `goods_don_sku` gdk on gdk.id = od.sku_id
  83. left join `goods_don` gd on gd.id = od.goods_id
  84. where od.id = #{orderId}
  85. </select>
  86. <select id="selectPlatBrokenLineMoney" resultType="com.cyksj.model.views.BrokenLineObjView">
  87. select min(curdate) as firstDate,
  88. max(curdate) as lastDate
  89. from (select cast(sum(od.money)/100 as decimal(10,2)) as curdateMoney,
  90. date_format(od.created_time,'%Y-%m-%d') curdate from order_don od
  91. where od.status not in ('noPayment','close','refund')
  92. group by od.goods_id,date_format(od.created_time,'%Y-%m-%d'))s
  93. where 1 = 1
  94. <if test="first != null">
  95. and curdate >= #{first}
  96. </if>
  97. <if test="end != null">
  98. and curdate &lt;= #{end}
  99. </if>
  100. </select>
  101. <select id="selectPersonDistributeBrokenLine" resultType="com.cyksj.model.views.BrokenLineObjView">
  102. select min(curdate) as firstDate,
  103. max(curdate) as lastDate
  104. from (select date_format(od.created_time,'%Y-%m-%d') curdate,
  105. count(od.id) curdateOrderCount
  106. from distribute_waiting_send_points dw
  107. left join order_don od on od.id = dw.order_id
  108. where dw.shared_id = #{userId}
  109. and od.is_distribute is true
  110. and dw.send_status not in ('not_exist', 'close')
  111. group by od.goods_id, date_format(od.created_time, '%Y-%m-%d'))s
  112. where 1 = 1
  113. <if test="first != null">
  114. and curdate >= #{first}
  115. </if>
  116. <if test="end != null">
  117. and curdate &lt;= #{end}
  118. </if>
  119. </select>
  120. </mapper>