OrderDonMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. <if test="goodsId != null">
  134. and goods_id = #{goodsId}
  135. </if>
  136. and status not in ('close', 'noPayment')) s1
  137. ,
  138. (select count(*) as refundCount, ifnull(sum(money),0) as refundMoney
  139. from order_don
  140. where popularize_id = #{popularizeId}
  141. <if test="startTime != null and startTime != ''">
  142. and created_time >= #{startTime}
  143. </if>
  144. <if test="endTime != null and endTime != ''">
  145. and created_time &lt; #{endTime}
  146. </if>
  147. <if test="goodsId != null">
  148. and goods_id = #{goodsId}
  149. </if>
  150. and status = 'refund')
  151. s2
  152. </select>
  153. <select id="selectThisMonthAppleOneMoney" resultType="java.math.BigDecimal">
  154. select cast(ifnull((sum(money),0) - ifnull(sum(refund_money),0))/100 as decimal(10,2)) from `order_don` where sku_id in
  155. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  156. #{item}
  157. </foreach>
  158. and status not in ('close','noPayment') and created_time between #{startDate} and #{endDate}
  159. </select>
  160. <select id="selectThisMonthDistributeOrderMoney" resultType="java.math.BigDecimal">
  161. select cast((ifnull(sum(money),0) - ifnull(sum(refund_money),0))/100 as decimal(10,2)) from `order_don` where sku_id in
  162. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  163. #{item}
  164. </foreach>
  165. and status not in ('close','noPayment') and is_distribute = 1
  166. and created_time between #{startDate} and #{endDate}
  167. </select>
  168. <select id="getOrderDetailByGoodsType" resultType="java.util.Map">
  169. select count(id) as orderNum,
  170. ifnull(sum(money),0) as money
  171. from order_don where goods_id in (select id from `goods_don` where type = #{type})
  172. and status not in
  173. <foreach collection="noOrderStatus" item="item" open="(" separator="," close=")">
  174. #{item}
  175. </foreach>
  176. <if test="startDate != null">
  177. and created_time >= #{startDate}
  178. </if>
  179. <if test="endDate != null">
  180. and created_time &lt; #{endDate}
  181. </if>
  182. </select>
  183. <select id="getBackgroundDataView" resultType="com.cyksj.model.views.BackgroundDataView">
  184. select count(distinct user_id) as totalNumOfUser,
  185. count(id) as totalNumOfOrder,
  186. cast(ifnull(sum(money),0)/100 as decimal(11,2)) as totalOrderAmount,
  187. count(if(status = 'refund',1,NULL)) as totalNumOfRefundOrder,
  188. cast(sum(ifnull(refund_money,0))/100 as decimal(11,2)) as totalRefundAmount
  189. from `order_don` where status not in
  190. <foreach collection="noOrderStatus" item="item" open="(" separator="," close=")">
  191. #{item}
  192. </foreach>
  193. <if test="startDate != null">
  194. and created_time >= #{startDate}
  195. </if>
  196. <if test="endDate != null">
  197. and created_time &lt; #{endDate}
  198. </if>
  199. </select>
  200. <select id="statisticsUsedBalance" resultType="java.math.BigDecimal">
  201. select cast(ifnull(sum(balance),0)/100 as decimal(11,2)) from order_don where status not in
  202. <foreach collection="noOrderAllStatus" item="item" open="(" separator="," close=")">
  203. #{item}
  204. </foreach>
  205. <if test="startDate != null">
  206. and created_time >= #{startDate}
  207. </if>
  208. <if test="endDate != null">
  209. and created_time &lt; #{endDate}
  210. </if>
  211. </select>
  212. <select id="selectYhShopDistributeOrderDetail" resultType="java.util.Map">
  213. select count(*) as numOfDsOrder,
  214. ifnull(sum(money),0) as dsMoney
  215. from `order_don` where yhs_id > 0 and status not in ('close','noPayment','refund')
  216. <if test="startDate != null">
  217. and created_time >= #{startDate}
  218. </if>
  219. <if test="endDate != null">
  220. and created_time &lt; #{endDate}
  221. </if>
  222. </select>
  223. <select id="selectCountActiveCodeOrderByAcId" resultType="java.lang.Integer">
  224. select count(distinct o.id)
  225. from (select user_id from corp_user where ac_id = #{acId} and user_id != 0) s
  226. left join order_don o
  227. on o.user_id = s.user_Id
  228. where o.status not in ('close', 'noPayment', 'refund')
  229. </select>
  230. <select id="selectActiveCodeOrderDetail" resultType="java.util.Map">
  231. select count(distinct if(o.status != 'refund', o.id, null)) as orderNum,
  232. sum(money) - sum(ifnull(refund_money, 0)) as orderMoney
  233. from (select user_id from corp_user where ac_id = #{acId} and user_id != 0) s
  234. left join order_don o
  235. on o.user_id = s.user_Id
  236. where o.status not in ('close', 'noPayment')
  237. <if test="startTime != null">
  238. and o.created_time >= #{startTime}
  239. </if>
  240. <if test="endTime != null">
  241. and o.created_time &lt; #{endTime}
  242. </if>
  243. </select>
  244. <select id="getOriRenewOrderMoney" resultType="java.math.BigDecimal">
  245. select cast(ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as decimal(10,2)) from order_don
  246. where status not in ('close','noPayment')
  247. <if test="startDate != null">
  248. and created_time >= #{startDate}
  249. </if>
  250. <if test="endDate != null">
  251. and created_time &lt; #{endDate}
  252. </if>
  253. and order_type = 2
  254. </select>
  255. <select id="getTotalMoney" resultType="java.math.BigDecimal">
  256. select cast(ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as decimal(10,2)) from order_don
  257. where status not in ('close','noPayment')
  258. <if test="startDate != null">
  259. and created_time >= #{startDate}
  260. </if>
  261. <if test="endDate != null">
  262. and created_time &lt; #{endDate}
  263. </if>
  264. </select>
  265. <select id="getClearRenewOrderMoney" resultType="java.math.BigDecimal">
  266. select cast(ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) as decimal(10,2)) from
  267. user_ticket_cleared_record utr inner join order_don o
  268. on o.user_id = utr.user_id and o.goods_id = utr.goods_id and utr.source = 'self'
  269. where order_type = 1 and o.created_time > utr.start_time and o.status not in ('close', 'noPayment')
  270. <if test="startDate != null">
  271. and utr.created_time >= #{startDate}
  272. and o.created_time >= #{startDate}
  273. </if>
  274. <if test="endDate != null">
  275. and utr.created_time &lt; #{endDate}
  276. and o.created_time &lt; #{endDate}
  277. </if>
  278. </select>
  279. <select id="selectDsPlatBrokenLineMoney" resultType="com.cyksj.model.views.BrokenLineObjView">
  280. select min(curdate) as firstDate,
  281. max(curdate) as lastDate
  282. from (select cast(sum(od.money)/100 as decimal(10,2)) as curdateMoney,
  283. date_format(od.created_time,'%Y-%m-%d') curdate from (select order_id from distribute_waiting_send_points where
  284. shared_id = #{sharedId}) dp inner join order_don od
  285. on od.id = dp.order_id
  286. where od.status not in ('noPayment','close','refund')
  287. group by od.goods_id,date_format(od.created_time,'%Y-%m-%d'))s
  288. where 1 = 1
  289. <if test="first != null">
  290. and curdate >= #{first}
  291. </if>
  292. <if test="end != null">
  293. and curdate &lt; #{end}
  294. </if>
  295. </select>
  296. <select id="getTagUserData" resultType="com.cyksj.model.views.UserOrderDetailView">
  297. select count(if(status != 'refund', 1, NULL)) as numOfOrder,
  298. cast((sum(money) - sum(ifnull(refund_money, 0))) / 100 as decimal(10,2)) as orderMoney,
  299. count(if(status != 'refund' and o.goods_id = 15,1,NULL)) as numOfEpOrder,
  300. cast((sum(if(o.goods_id = 15,money,0)) - sum(ifnull(if(o.goods_id = 15,refund_money,0), 0))) / 100 as decimal(10,2)) as epOrderMoney,
  301. count(distinct corpUserId) as numOfUser
  302. from (select cu.id as corpUserId,
  303. cu.user_id,
  304. date_format(s.created_time, '%Y-%m-%d') as joinTime
  305. from (select relation_id,
  306. min(ct.created_time) as created_time
  307. from `corp_user_tag` ct
  308. where tag_id = #{tagIdStr}
  309. group by ct.relation_id
  310. <if test="startTime != null">
  311. having min(ct.created_time) >= #{startTime}
  312. </if>
  313. <if test="endTime != null">
  314. and min(ct.created_time) &lt; #{endTime}
  315. </if>) s
  316. left join corp_user_follow_relation cufr on cufr.id = s.relation_id
  317. left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
  318. left join corp_user cu on cu.id = ca.corp_user_id) s
  319. left join order_don o on o.user_id = s.user_id and o.user_id != 0
  320. and o.status not in ('close', 'noPayment')
  321. and o.money > 0
  322. and date_format(o.created_time, '%Y-%m-%d') >= joinTime
  323. <if test="consumeStTime != null">
  324. and o.created_time >= #{consumeStTime}
  325. </if>
  326. <if test="consumeEtTime != null">
  327. and o.created_time &lt; #{consumeEtTime}
  328. </if>
  329. </select>
  330. <select id="getTagUserDataPage" resultType="com.cyksj.model.views.UserOrderDetailView">
  331. select joinTime as `date`,
  332. count(DISTINCT corpUserId) as numOfUser,
  333. count(if(status != 'refund', 1, NULL)) as numOfOrder,
  334. cast((ifnull(sum(money), 0) - sum(ifnull(refund_money, 0))) / 100 as decimal(10,2)) as orderMoney
  335. from (select cu.id as corpUserId,
  336. cu.user_id,
  337. date_format(s.created_time, '%Y-%m-%d') joinTime
  338. from (select relation_id,
  339. min(ct.created_time) as created_time
  340. from `corp_user_tag` ct
  341. where tag_id = #{tagIdStr}
  342. group by ct.relation_id) s
  343. left join corp_user_follow_relation cufr on cufr.id = s.relation_id
  344. left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
  345. left join corp_user cu on cu.id = ca.corp_user_id) s
  346. left join order_don o on o.user_id = s.user_id and o.user_id != 0
  347. and o.status not in ('close','noPayment')
  348. and date_format(o.created_time, '%Y-%m-%d') = joinTime
  349. and o.money > 0
  350. group by joinTime
  351. order by joinTime desc
  352. </select>
  353. <select id="getTagUserTimeOrderData" resultType="com.cyksj.model.views.CorpTagUserOrderDataView">
  354. select o.id as order_id,o.user_id,
  355. (select nickname from user u where u.id = o.user_id limit 1),
  356. o.order_no,o.goods_id,g.title,o.sku_id,sku.spec_val,
  357. o.money/100 as money,o.created_time
  358. from (select cu.id as corpUserId,
  359. cu.user_id,
  360. date_format(s.created_time, '%Y-%m-%d') joinTime
  361. from (select relation_id,
  362. min(ct.created_time) as created_time
  363. from `corp_user_tag` ct
  364. where tag_id = #{tagIdStr}
  365. group by ct.relation_id) s
  366. left join corp_user_follow_relation cufr on cufr.id = s.relation_id
  367. left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
  368. left join corp_user cu on cu.id = ca.corp_user_id) s
  369. inner join order_don o on o.user_id = s.user_id and o.user_id != 0
  370. and o.status not in ('close', 'noPayment','refund')
  371. and date_format(o.created_time, '%Y-%m-%d') = joinTime
  372. and o.money > 0
  373. <if test="toDate != null and toDate != ''">
  374. and date_format(o.created_time,'%Y-%m-%d') = #{toDate}
  375. </if>
  376. left join goods_don g on g.id = o.goods_id
  377. left join goods_don_sku sku on sku.id = o.sku_id
  378. order by o.created_time desc
  379. </select>
  380. <select id="getRealGoodsSourceData" resultType="com.cyksj.model.views.RealGoodsSourceData">
  381. select label_source,
  382. count(*) as orders,
  383. sum(money) as orderMoney
  384. from order_don o
  385. left join user_distribute_shared us on us.user_id = o.user_id
  386. where goods_id = 15
  387. and status not in ('close', 'noPayment', 'refund')
  388. <if test="startDate != null">
  389. and o.created_time >= #{startDate}
  390. </if>
  391. <if test="endDate != null">
  392. and o.created_time &lt; #{endDate}
  393. </if>
  394. <if test="isGeneral != null and isGeneral">
  395. and us.id is null
  396. </if>
  397. and o.label_source != ''
  398. group by o.label_source
  399. </select>
  400. <select id="selectMaxRefundGoodsName" resultType="java.lang.String">
  401. select (select title from goods_don where id = o.goods_id limit 1)
  402. from (select distinct order_id from refund_order_don where operator = #{operator}
  403. and refund_method not in ('EX_CODE'
  404. , 'balance')) rd inner join order_don o
  405. on o.id = rd.order_id
  406. <if test="startTime != null">
  407. and o.created_time >= #{startTime}
  408. </if>
  409. <if test="endTime != null">
  410. and o.created_time &lt; #{endTime}
  411. </if>
  412. group by o.goods_id
  413. order by count(*) desc limit 1
  414. </select>
  415. <select id="selectOrderRelate" resultType="com.cyksj.model.entity.OrderDonCustomerServiceRelate">
  416. select cms_user_id, (select nickname from cms_user where id = odr.cms_user_id limit 1) as nickname
  417. from order_don_customer_service_relate odr
  418. where order_id = #{orderId} limit 1
  419. </select>
  420. <select id="selectSubChannelOrderMoney" resultType="java.math.BigDecimal">
  421. select sum(o.money) - sum(ifnull(o.refund_money, 0))
  422. from distribute_waiting_send_points dp
  423. inner join order_don o on o.id = dp.order_id
  424. where dp.shared_id = #{sharedId}
  425. and o.goods_id != 15
  426. and o.status not in ('close', 'noPayment')
  427. and o.created_time > #{invitedTime}
  428. and o.created_time &lt; #{limitTime}
  429. </select>
  430. <select id="getPastRecord" resultType="com.cyksj.model.views.UserOrderDetailView">
  431. select date_format(o.created_time,'%Y-%m-%d') as `date`,
  432. count(if(status != 'refund', 1, NULL)) as numOfOrder,
  433. cast((ifnull(sum(money),0) - sum(ifnull(refund_money, 0))) / 100 as decimal(10,2)) as orderMoney
  434. from (select cu.id as corpUserId,
  435. cu.user_id,
  436. date_format(s.created_time, '%Y-%m-%d') joinTime
  437. from (select relation_id,
  438. min(ct.created_time) as created_time
  439. from `corp_user_tag` ct
  440. where tag_id = #{tagIdStr}
  441. group by ct.relation_id) s
  442. left join corp_user_follow_relation cufr on cufr.id = s.relation_id
  443. left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
  444. left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0)s
  445. inner join order_don o on o.user_id = s.user_id
  446. and o.status not in ('close','noPayment')
  447. and date_format(o.created_time, '%Y-%m-%d') >= joinTime
  448. and o.money > 0
  449. group by date_format(o.created_time,'%Y-%m-%d')
  450. order by date_format(o.created_time,'%Y-%m-%d') desc
  451. </select>
  452. </mapper>