OrderInfoMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.miaxis.order.mapper.OrderInfoMapper">
  6. <resultMap type="OrderInfo" id="OrderInfoResult">
  7. <result property="id" column="id" />
  8. <result property="goodsId" column="goods_id" />
  9. <result property="goodsName" column="goods_name" />
  10. <result property="goodsType" column="goods_type" />
  11. <result property="userId" column="user_id" />
  12. <result property="userName" column="user_name" />
  13. <result property="logincode" column="logincode" />
  14. <result property="outTradeNo" column="out_trade_no" />
  15. <result property="outRefundNo" column="out_refund_no" />
  16. <result property="tradeType" column="trade_type" />
  17. <result property="successTime" column="success_time" />
  18. <result property="payType" column="pay_type" />
  19. <result property="createTime" column="create_time" />
  20. <result property="updateTime" column="update_time" />
  21. <result property="isShare" column="is_share" />
  22. <result property="dqbh" column="dqbh" />
  23. <result property="dqmc" column="dqmc" />
  24. <result property="school" column="school" />
  25. <result property="schoolName" column="school_name" />
  26. <result property="schoolCommission" column="school_commission" />
  27. <result property="phoneType" column="phone_type" />
  28. <result property="refundReason" column="refund_reason" />
  29. </resultMap>
  30. <sql id="selectOrderInfoVo">
  31. select * from order_info
  32. </sql>
  33. <select id="selectOrderInfoList" parameterType="OrderInfo" resultMap="OrderInfoResult">
  34. <include refid="selectOrderInfoVo"/>
  35. <where>
  36. <if test="isShare != null"> and is_share = #{isShare }</if>
  37. <if test="goodsName != null and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
  38. <if test="goodsType != null"> and goods_type = #{goodsType }</if>
  39. <if test="schoolName != null and schoolName != ''"> and school_name like concat('%', #{schoolName}, '%')</if>
  40. <if test="userId != null "> and user_id = #{userId}</if>
  41. <if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
  42. <if test="logincode != null and logincode != ''"> and logincode = #{logincode} </if>
  43. <if test="outTradeNo != null and outTradeNo != ''"> and out_trade_no = #{outTradeNo}</if>
  44. <if test="outRefundNo != null and outRefundNo != ''"> and out_refund_no = #{outRefundNo}</if>
  45. <if test="tradeType != null and tradeType != ''"> and trade_type = #{tradeType}</if>
  46. <if test="successTime != null "> and success_time = #{successTime}</if>
  47. <if test="payType != null "> and pay_type = #{payType}</if>
  48. </where>
  49. order by success_time desc
  50. </select>
  51. <select id="getByOutTradeNo" parameterType="string" resultType="com.miaxis.order.domain.OrderInfo">
  52. select * from order_info where out_trade_no =#{outTradeNo}
  53. </select>
  54. <!--
  55. <select id="selectSchoolOrderInfoList" parameterType="com.miaxis.order.dto.QuerySchoolOrderListDTO" resultType="com.miaxis.order.vo.QuerySchoolOrderListVo">
  56. select
  57. school,
  58. school_name,
  59. IFNULL(sum(school_commission),0) as school_commission,
  60. IFNULL(sum(total),0) as order_total,
  61. COUNT(DISTINCT logincode) as people_count,
  62. COUNT(id) as order_count
  63. <if test="isShare==1 and dqbh !='2108' ">
  64. ,
  65. IFNULL(COUNT(DISTINCT logincode),0)*49*100 as activation_commission,
  66. (IFNULL(COUNT(DISTINCT logincode),0)*49*100-sum(school_commission)) as subsidy_bak,
  67. (case
  68. when (IFNULL(COUNT(DISTINCT logincode),0)*49*100-sum(school_commission)) <![CDATA[ <= ]]> 0 then 0
  69. when (IFNULL(COUNT(DISTINCT logincode),0)*49*100-sum(school_commission)) <![CDATA[ > ]]> 0 then (IFNULL(COUNT(DISTINCT logincode),0)*49*100-sum(school_commission))
  70. else 0 end) as subsidy
  71. </if>
  72. from order_info
  73. <where>
  74. <if test="isShare != null">
  75. and is_share = #{isShare }
  76. </if>
  77. <if test="tradeType != null">
  78. and trade_type = #{tradeType }
  79. </if>
  80. <if test="dqbh != null and dqbh != ''">
  81. and dqbh = #{dqbh}
  82. </if>
  83. <if test="schoolName != null and schoolName != ''">
  84. and school_name like concat('%', #{schoolName}, '%')
  85. </if>
  86. <if test="startTime != null and startTime != ''">
  87. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  88. </if>
  89. <if test="endTime != null and endTime != '' ">
  90. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  91. </if>
  92. </where>
  93. group by school,school_name
  94. </select>
  95. -->
  96. <select id="selectSchoolOrderInfoList" parameterType="com.miaxis.order.dto.QuerySchoolOrderListDTO" resultType="com.miaxis.order.vo.QuerySchoolOrderListVo">
  97. SELECT *,
  98. CASE
  99. WHEN subsidy_bak <![CDATA[ <= ]]> 0 THEN 0
  100. WHEN subsidy_bak <![CDATA[ > ]]> 0 THEN subsidy_bak
  101. ELSE 0
  102. END AS subsidy
  103. FROM (
  104. SELECT
  105. school,
  106. school_name,
  107. IFNULL(SUM(fz_price), 0) AS fzMoney,
  108. IFNULL(SUM(school_commission), 0) AS school_commission,
  109. IFNULL(SUM(total), 0) AS order_total,
  110. COUNT(DISTINCT logincode) AS people_count,
  111. COUNT(id) AS order_count,
  112. IFNULL(COUNT(DISTINCT CASE WHEN dqbh NOT IN ('2108') THEN logincode END), 0) * 49 * 100 AS activation_commission,
  113. IFNULL(COUNT(DISTINCT CASE WHEN dqbh NOT IN ('2108') THEN logincode END), 0) * 49 * 100 - SUM(school_commission) AS subsidy_bak
  114. from order_info
  115. <where>
  116. <if test="isShare != null">
  117. and is_share = #{isShare }
  118. </if>
  119. <if test="tradeType != null">
  120. and trade_type = #{tradeType }
  121. </if>
  122. <if test="dqbh != null and dqbh != ''">
  123. and dqbh = #{dqbh}
  124. </if>
  125. <if test="schoolName != null and schoolName != ''">
  126. and school_name like concat('%', #{schoolName}, '%')
  127. </if>
  128. <if test="startTime != null and startTime != ''">
  129. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  130. </if>
  131. <if test="endTime != null and endTime != '' ">
  132. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  133. </if>
  134. </where>
  135. group by school,school_name) as subquery
  136. </select>
  137. <select id="selectSchoolOrderInfoExcel" resultType="com.miaxis.order.vo.QuerySchoolOrderListVo">
  138. select
  139. school,
  140. school_name,
  141. IFNULL(sum(school_commission)/100,0) as school_commission,
  142. IFNULL(sum(total)/100,0) as order_total,
  143. COUNT(DISTINCT logincode) as people_count,
  144. COUNT(id) as order_count
  145. <if test="isShare==1">
  146. ,
  147. IFNULL(COUNT(DISTINCT logincode),0)*49 as activation_commission,
  148. (IFNULL(COUNT(DISTINCT logincode),0)*49-sum(school_commission/100)) as subsidy_bak,
  149. (case
  150. when (IFNULL(COUNT(DISTINCT logincode),0)*49-sum(school_commission)/100) <![CDATA[ <= ]]> 0 then 0
  151. when (IFNULL(COUNT(DISTINCT logincode),0)*49-sum(school_commission)/100) <![CDATA[ > ]]> 0 then (IFNULL(COUNT(DISTINCT logincode),0)*49-sum(school_commission)/100)
  152. else 0 end) as subsidy
  153. </if>
  154. from order_info
  155. <where>
  156. <if test="isShare != null">
  157. and is_share = #{isShare }
  158. </if>
  159. <if test="tradeType != null">
  160. and trade_type = #{tradeType }
  161. </if>
  162. <if test="dqbh != null and dqbh != ''">
  163. and dqbh = #{dqbh}
  164. </if>
  165. <if test="schoolName != null and schoolName != ''">
  166. and school_name like concat('%', #{schoolName}, '%')
  167. </if>
  168. <if test="startTime != null and startTime !='' ">
  169. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  170. </if>
  171. <if test="endTime != null and endTime !=''">
  172. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  173. </if>
  174. </where>
  175. group by school,school_name
  176. </select>
  177. <select id="getTotalMoney" resultType="java.lang.Integer">
  178. select
  179. IFNULL(sum(total),0) as orderTotal
  180. from order_info
  181. <where>
  182. <if test="isShare != null">
  183. and is_share = #{isShare }
  184. </if>
  185. <if test="tradeType != null">
  186. and trade_type = #{tradeType }
  187. </if>
  188. <if test="dqbh != null and dqbh != ''">
  189. and dqbh = #{dqbh}
  190. </if>
  191. <if test="schoolName != null and schoolName != ''">
  192. and school_name like concat('%', #{schoolName}, '%')
  193. </if>
  194. <if test="startTime != null and startTime != ''">
  195. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  196. </if>
  197. <if test="endTime != null and endTime != ''">
  198. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  199. </if>
  200. </where>
  201. </select>
  202. <select id="getCommissionMoney" resultType="java.lang.Integer">
  203. select
  204. IFNULL(sum(school_commission),0) as commission
  205. from order_info
  206. <where>
  207. <if test="isShare != null">
  208. and is_share = #{isShare }
  209. </if>
  210. <if test="tradeType != null">
  211. and trade_type = #{tradeType }
  212. </if>
  213. <if test="dqbh != null and dqbh != ''">
  214. and dqbh = #{dqbh}
  215. </if>
  216. <if test="schoolName != null and schoolName != ''">
  217. and school_name like concat('%', #{schoolName}, '%')
  218. </if>
  219. <if test="startTime != null and startTime!=''">
  220. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  221. </if>
  222. <if test="endTime != null and endTime!=''">
  223. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  224. </if>
  225. </where>
  226. </select>
  227. <select id="getFzMoney" resultType="java.lang.Integer">
  228. select
  229. IFNULL(sum(fz_price),0) as fzMoney
  230. from order_info
  231. <where>
  232. <if test="isShare != null">
  233. and is_share = #{isShare }
  234. </if>
  235. <if test="tradeType != null">
  236. and trade_type = #{tradeType }
  237. </if>
  238. <if test="dqbh != null and dqbh != ''">
  239. and dqbh = #{dqbh}
  240. </if>
  241. <if test="schoolName != null and schoolName != ''">
  242. and school_name like concat('%', #{schoolName}, '%')
  243. </if>
  244. <if test="startTime != null and startTime!=''">
  245. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  246. </if>
  247. <if test="endTime != null and endTime!=''">
  248. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  249. </if>
  250. </where>
  251. </select>
  252. <select id="selectSchoolOrderDetailed" resultType="com.miaxis.order.domain.OrderInfo">
  253. select * from order_info
  254. <where>
  255. <if test="isShare != null">
  256. and is_share = #{isShare }
  257. </if>
  258. <if test="tradeType != null">
  259. and trade_type = #{tradeType }
  260. </if>
  261. <if test="schoolName != null and schoolName != ''">
  262. and school_name like concat('%', #{schoolName}, '%')
  263. </if>
  264. <if test="startTime != null and startTime!=''">
  265. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  266. </if>
  267. <if test="endTime != null and endTime!=''">
  268. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  269. </if>
  270. </where>
  271. order by success_time desc
  272. </select>
  273. <select id="selectSchoolOrderDetailedExcel" resultType="com.miaxis.order.vo.QuerySchoolOrderDetailedVo">
  274. select
  275. school_name,
  276. goods_name,user_name,logincode,out_trade_no,
  277. case when trade_type = 1 then '支付成功'
  278. when trade_type = 2 then '支付失败'
  279. when trade_type = 3 then '已退款' else '未知' end as trade_type,
  280. case when phone_type = 1 then '苹果' else '安卓' end as phone_type,
  281. IFNULL(total/100,0) as total,IFNULL(school_commission/100,0) as school_commission,
  282. success_time,
  283. case when is_share = 1 then '是' else '否' end as is_share
  284. from order_info
  285. <where>
  286. <if test="isShare != null">
  287. and is_share = #{isShare }
  288. </if>
  289. <if test="tradeType != null">
  290. and trade_type = #{tradeType }
  291. </if>
  292. <if test="schoolName != null and schoolName != ''">
  293. and school_name like concat('%', #{schoolName}, '%')
  294. </if>
  295. <if test="startTime != null and startTime != '' ">
  296. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ >= ]]> #{startTime}
  297. </if>
  298. <if test="endTime != null and endTime!='' ">
  299. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ <= ]]> #{endTime}
  300. </if>
  301. </where>
  302. order by success_time desc
  303. </select>
  304. <select id="getIncomeList" resultType="com.miaxis.order.vo.OrderIncomeVo">
  305. select
  306. (select sum(total) from order_info o where DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ >= ]]> #{startTime}
  307. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') )<![CDATA[ <= ]]> #{endTime}
  308. and trade_type = 1) as total,
  309. IFNULL(COUNT(DISTINCT logincode),0)*49 as activation_commission,
  310. sum(school_commission)/100 from order_info o
  311. where DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S') <![CDATA[ >= ]]> #{startTime}
  312. and DATE_FORMAT(success_time,'%Y-%m-%d %H:%i:%S')<![CDATA[ <= ]]> #{endTime}
  313. and is_share = 1
  314. and trade_type = 1
  315. </select>
  316. <select id="getByOutTradeNo" parameterType="string" resultType="com.miaxis.order.domain.OrderInfo">
  317. select * from order_info where out_trade_no =#{outTradeNo}
  318. </select>
  319. <select id="selectOrderInfoByWaitProfit" resultType="com.miaxis.order.domain.OrderInfo">
  320. SELECT *
  321. FROM order_info
  322. WHERE trade_type = 1
  323. AND profit_sharing = 1
  324. AND success_time <![CDATA[ <= ]]> DATE_SUB(NOW(), INTERVAL 10 MINUTE)
  325. ORDER BY success_time;
  326. </select>
  327. <select id="getOrderInfoByIds" parameterType="Long" resultType="com.miaxis.order.domain.OrderInfo">
  328. select * from order_info
  329. <where>
  330. id in
  331. <foreach collection="array" item="id" index="index" open="(" close=")" separator="," >
  332. #{id}
  333. </foreach>
  334. </where>
  335. </select>
  336. </mapper>