OrderDonMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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="getBackgroundDataView" resultType="com.cyksj.model.views.BackgroundDataView">
  178. select count(distinct user_id) as totalNumOfUser,
  179. count(id) as totalNumOfOrder,
  180. cast(ifnull(sum(money),0)/100 as decimal(11,2)) as totalOrderAmount,
  181. count(if(status = 'refund',1,NULL)) as totalNumOfRefundOrder,
  182. cast(sum(ifnull(refund_money,0))/100 as decimal(11,2)) as totalRefundAmount
  183. from `order_don` where status not in
  184. <foreach collection="noOrderStatus" item="item" open="(" separator="," close=")">
  185. #{item}
  186. </foreach>
  187. <if test="startDate != null">
  188. and created_time >= #{startDate}
  189. </if>
  190. <if test="endDate != null">
  191. and created_time &lt; #{endDate}
  192. </if>
  193. </select>
  194. <select id="statisticsUsedBalance" resultType="java.math.BigDecimal">
  195. select cast(ifnull(sum(balance),0)/100 as decimal(11,2)) from order_don where status not in
  196. <foreach collection="noOrderAllStatus" item="item" open="(" separator="," close=")">
  197. #{item}
  198. </foreach>
  199. <if test="startDate != null">
  200. and created_time >= #{startDate}
  201. </if>
  202. <if test="endDate != null">
  203. and created_time &lt; #{endDate}
  204. </if>
  205. </select>
  206. <select id="selectYhShopDistributeOrderDetail" resultType="java.util.Map">
  207. select count(*) as numOfDsOrder,
  208. ifnull(sum(money),0) as dsMoney
  209. from `order_don` where yhs_id > 0 and status not in ('close','noPayment','refund')
  210. <if test="startDate != null">
  211. and created_time >= #{startDate}
  212. </if>
  213. <if test="endDate != null">
  214. and created_time &lt; #{endDate}
  215. </if>
  216. </select>
  217. <select id="selectCountActiveCodeOrderByAcId" resultType="java.lang.Integer">
  218. select count(distinct o.id)
  219. from (select user_id from corp_user where ac_id = #{acId} and user_id != 0) s
  220. left join order_don o
  221. on o.user_id = s.user_Id
  222. where o.status not in ('close', 'noPayment', 'refund')
  223. </select>
  224. <select id="selectActiveCodeOrderDetail" resultType="java.util.Map">
  225. select count(distinct if(o.status != 'refund', o.id, null)) as orderNum,
  226. sum(money) - sum(ifnull(refund_money, 0)) as orderMoney
  227. from (select user_id from corp_user where ac_id = #{acId} and user_id != 0) s
  228. left join order_don o
  229. on o.user_id = s.user_Id
  230. where o.status not in ('close', 'noPayment')
  231. <if test="startTime != null">
  232. and o.created_time >= #{startTime}
  233. </if>
  234. <if test="endTime != null">
  235. and o.created_time &lt; #{endTime}
  236. </if>
  237. </select>
  238. <select id="getOriRenewOrderMoney" resultType="java.math.BigDecimal">
  239. select cast(ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as decimal(10,2)) from order_don
  240. where status not in ('close','noPayment')
  241. <if test="startDate != null">
  242. and created_time >= #{startDate}
  243. </if>
  244. <if test="endDate != null">
  245. and created_time &lt; #{endDate}
  246. </if>
  247. and order_type = 2
  248. </select>
  249. <select id="getTotalMoney" resultType="java.math.BigDecimal">
  250. select cast(ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as decimal(10,2)) from order_don
  251. where status not in ('close','noPayment')
  252. <if test="startDate != null">
  253. and created_time >= #{startDate}
  254. </if>
  255. <if test="endDate != null">
  256. and created_time &lt; #{endDate}
  257. </if>
  258. </select>
  259. <select id="getClearRenewOrderMoney" resultType="java.math.BigDecimal">
  260. select cast(ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) as decimal(10,2)) from
  261. user_ticket_cleared_record utr inner join order_don o
  262. on o.user_id = utr.user_id and o.goods_id = utr.goods_id and utr.source = 'self'
  263. where order_type = 1 and o.created_time > utr.start_time and o.status not in ('close', 'noPayment')
  264. <if test="startDate != null">
  265. and utr.created_time >= #{startDate}
  266. and o.created_time >= #{startDate}
  267. </if>
  268. <if test="endDate != null">
  269. and utr.created_time &lt; #{endDate}
  270. and o.created_time &lt; #{endDate}
  271. </if>
  272. </select>
  273. <select id="selectDsPlatBrokenLineMoney" resultType="com.cyksj.model.views.BrokenLineObjView">
  274. select min(curdate) as firstDate,
  275. max(curdate) as lastDate
  276. from (select cast(sum(od.money)/100 as decimal(10,2)) as curdateMoney,
  277. date_format(od.created_time,'%Y-%m-%d') curdate from (select order_id from distribute_waiting_send_points where
  278. shared_id = #{sharedId}) dp inner join order_don od
  279. on od.id = dp.order_id
  280. where od.status not in ('noPayment','close','refund')
  281. group by od.goods_id,date_format(od.created_time,'%Y-%m-%d'))s
  282. where 1 = 1
  283. <if test="first != null">
  284. and curdate >= #{first}
  285. </if>
  286. <if test="end != null">
  287. and curdate &lt; #{end}
  288. </if>
  289. </select>
  290. <select id="getTagUserData" resultType="com.cyksj.model.views.UserOrderDetailView">
  291. select count(if(status != 'refund', 1, NULL)) as numOfOrder, (sum(money) - sum(ifnull(refund_money, 0))) / 100
  292. as orderMoney,
  293. count(if(status != 'refund' and o.goods_id = 15,1,NULL)) as numOfEpOrder,
  294. (sum(if(o.goods_id = 15,money,0)) - sum(ifnull(if(o.goods_id = 15,refund_money,0), 0))) / 100 as epOrderMoney
  295. from (select cu.user_id
  296. from (select relation_id
  297. from `corp_user_tag` ct
  298. where tag_id = #{tagIdStr}
  299. <if test="startTime != null">
  300. and ct.created_time >= #{startTime}
  301. </if>
  302. <if test="endTime != null">
  303. and ct.created_time &lt; #{endTime}
  304. </if>) s
  305. left join corp_user_follow_relation cufr on cufr.id = s.relation_id
  306. left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
  307. left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0) s inner join order_don o on o.user_id =
  308. s.user_id
  309. and o.status not in ('close', 'noPayment')
  310. and o.money > 0
  311. and o.money > ifnull(o.refund_money,0)
  312. <if test="startTime != null">
  313. and o.created_time >= #{startTime}
  314. </if>
  315. </select>
  316. <select id="getTagUserDataPage" resultType="com.cyksj.model.views.UserOrderDetailView">
  317. select count(if(status != 'refund', 1, NULL)) as numOfOrder, (sum(money) - sum(ifnull(refund_money, 0))) / 100
  318. as orderMoney,date_format(o.created_time,'%Y-%m-%d') as date from (select cu.user_id
  319. from (select relation_id
  320. from `corp_user_tag` ct
  321. where tag_id = #{tagIdStr}
  322. <if test="startTime != null">
  323. and ct.created_time >= #{startTime}
  324. </if>
  325. <if test="endTime != null">
  326. and ct.created_time &lt; #{endTime}
  327. </if>) s
  328. left join corp_user_follow_relation cufr on cufr.id = s.relation_id
  329. left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
  330. left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0) s inner join order_don o on o.user_id =
  331. s.user_id
  332. and o.status not in ('close', 'noPayment')
  333. and o.money > 0
  334. and o.money > ifnull(o.refund_money,0)
  335. <if test="startTime != null">
  336. and o.created_time >= #{startTime}
  337. </if>
  338. group by date_format(o.created_time,'%Y-%m-%d')
  339. order by date_format(o.created_time,'%Y-%m-%d') desc
  340. </select>
  341. <select id="getTagUserTimeOrderData" resultType="com.cyksj.model.views.CorpTagUserOrderDataView">
  342. select o.id as order_id,o.user_id,
  343. (select nickname from user u where u.id = o.user_id limit 1),
  344. o.order_no,o.goods_id,g.title,o.sku_id,sku.spec_val,
  345. o.money/100 as money,o.created_time
  346. from (select
  347. cu.user_id
  348. from (select relation_id
  349. from `corp_user_tag` ct
  350. where tag_id = #{tagIdStr}
  351. <if test="startTime != null">
  352. and ct.created_time >= #{startTime}
  353. </if>
  354. <if test="endTime != null">
  355. and ct.created_time &lt; #{endTime}
  356. </if>) s
  357. left join corp_user_follow_relation cufr on cufr.id = s.relation_id
  358. left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
  359. left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0) s inner join order_don o on o.user_id =
  360. s.user_id
  361. and o.status not in ('close', 'noPayment','refund')
  362. and o.money > 0
  363. <if test="toDate != null and toDate != ''">
  364. and date_format(o.created_time,'%Y-%m-%d') = #{toDate}
  365. </if>
  366. left join goods_don g on g.id = o.goods_id
  367. left join goods_don_sku sku on sku.id = o.sku_id
  368. order by o.created_time desc
  369. </select>
  370. <select id="getRealGoodsSourceData" resultType="com.cyksj.model.views.RealGoodsSourceData">
  371. select label_source, sum(money) as orderMoney
  372. from order_don
  373. where goods_id = 15
  374. and status not in ('close', 'noPayment', 'refund')
  375. <if test="startDate != null">
  376. and created_time >= #{startDate}
  377. </if>
  378. <if test="endDate != null">
  379. and created_time &lt; #{endDate}
  380. </if>
  381. and label_source != ''
  382. group by label_source
  383. </select>
  384. </mapper>