TopOldOrderMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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.zhongzheng.modules.top.goods.mapper.TopOldOrderMapper">
  6. <resultMap type="com.zhongzheng.modules.top.goods.domain.TopOldOrder" id="TopOrderResult">
  7. <result property="orderId" column="order_id"/>
  8. <result property="orderSn" column="order_sn"/>
  9. <result property="userId" column="user_id"/>
  10. <result property="orderPrice" column="order_price"/>
  11. <result property="orderGeneral" column="order_general"/>
  12. <result property="orderStatus" column="order_status"/>
  13. <result property="createTime" column="create_time"/>
  14. <result property="updateTime" column="update_time"/>
  15. <result property="payTime" column="pay_time"/>
  16. <result property="payType" column="pay_type"/>
  17. <result property="transid" column="transid"/>
  18. <result property="cancelTime" column="cancel_time"/>
  19. <result property="finishTime" column="finish_time"/>
  20. <result property="orderType" column="order_type"/>
  21. <result property="payPrice" column="pay_price"/>
  22. <result property="orderFrom" column="order_from"/>
  23. <result property="createUsername" column="create_username"/>
  24. <result property="status" column="status"/>
  25. <result property="createSysUserId" column="create_sys_user_id"/>
  26. <result property="inputOrderSn" column="input_order_sn"/>
  27. <result property="payStatus" column="pay_status"/>
  28. <result property="checkStatus" column="check_status"/>
  29. <result property="refundStatus" column="refund_status"/>
  30. <result property="creditStatus" column="credit_status"/>
  31. <result property="invoiceStatus" column="invoice_status"/>
  32. <result property="orderProfit" column="order_profit"/>
  33. <result property="orderCost" column="order_cost"/>
  34. <result property="orderRefund" column="order_refund"/>
  35. <result property="orderRefunded" column="order_refunded"/>
  36. <result property="orderUncollected" column="order_uncollected"/>
  37. <result property="orderReceived" column="order_received"/>
  38. <result property="remark" column="remark"/>
  39. <result property="costJson" column="cost_json"/>
  40. <result property="buyTime" column="buy_time"/>
  41. </resultMap>
  42. <select id="queryList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  43. SELECT
  44. vto.*
  45. FROM
  46. ( SELECT DISTINCT order_sn
  47. <if test="businessFullName != null and businessFullName != '' and (userCard == null or userCard == '')">
  48. FROM `v_top_order_business` where INSTR( business_full_name,#{businessFullName} ) > 0
  49. </if>
  50. <if test="(userCard != null and userCard != '') and (businessFullName == null or businessFullName == '')">
  51. FROM `v_top_order_card` where user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  52. </if>
  53. <if test="userCard != null and userCard != '' and businessFullName != null and businessFullName != ''">
  54. FROM (
  55. SELECT
  56. DISTINCT order_sn
  57. FROM
  58. ( SELECT order_sn FROM v_top_order_business WHERE INSTR( business_full_name,#{businessFullName} ) > 0 UNION ALL SELECT order_sn FROM v_top_order_card
  59. WHERE user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}) b
  60. ) m
  61. </if>
  62. <if test="(userCard == null or userCard == '') and (businessFullName == null or businessFullName == '')">
  63. FROM (
  64. SELECT
  65. DISTINCT order_sn
  66. FROM
  67. ( SELECT order_sn FROM v_top_order_business UNION ALL SELECT order_sn FROM v_top_order_card) b
  68. ) m
  69. </if>
  70. ) a
  71. LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn
  72. WHERE vto.`status` in (0,1)
  73. <if test="checkStatus != null">
  74. AND vto.check_status = #{checkStatus}
  75. </if>
  76. <if test="refundStatus != null">
  77. AND vto.refund_status = #{refundStatus}
  78. </if>
  79. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  80. AND vto.refund_status in
  81. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  82. #{item}
  83. </foreach>
  84. </if>
  85. <if test="creditStatus != null and creditStatus == 0">
  86. AND vto.order_received <![CDATA[ < ]]> vto.pay_price
  87. </if>
  88. <if test="creditStatus != null and creditStatus == 1">
  89. AND vto.pay_price = vto.order_received
  90. </if>
  91. <if test="invoiceStatus != null and invoiceStatus != ''">
  92. AND vto.invoice_status = #{invoiceStatus}
  93. </if>
  94. <if test="startTime != null and startTime != ''">
  95. AND vto.create_time <![CDATA[ >= ]]> #{startTime}
  96. </if>
  97. <if test="endTime != null and endTime != ''">
  98. AND vto.create_time <![CDATA[ <= ]]> #{endTime}
  99. </if>
  100. <if test="orderSn != null and orderSn != ''">
  101. AND vto.order_sn = #{orderSn}
  102. </if>
  103. <if test="orderSnList != null and orderSnList.size()!=0 ">
  104. AND vto.order_sn in
  105. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  106. #{item}
  107. </foreach>
  108. </if>
  109. <if test="keyword != null and keyword != ''">
  110. AND (
  111. vto.create_org LIKE CONCAT( '%', #{keyword}, '%' )
  112. -- OR vto.course_org LIKE CONCAT( '%', #{keyword}, '%' )
  113. OR vto.order_org LIKE CONCAT( '%', #{keyword}, '%' ))
  114. </if>
  115. order by vto.create_time DESC
  116. </select>
  117. <select id="queryList_COUNT" resultType="Long">
  118. SELECT
  119. ((SELECT
  120. COUNT( DISTINCT ot.order_sn ) AS num
  121. FROM
  122. top_old_order ot
  123. LEFT JOIN top_old_order_goods otg ON ot.order_sn = otg.order_sn
  124. WHERE
  125. 1 = 1
  126. <if test="businessFullName != null and businessFullName != ''">
  127. AND INSTR( otg.business_full_name , #{businessFullName} ) > 0
  128. </if>
  129. <if test="userCard != null and userCard != ''">
  130. AND otg.user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  131. </if>
  132. <if test="checkStatus != null and checkStatus != ''">
  133. AND ot.check_status = #{checkStatus}
  134. </if>
  135. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  136. AND ot.refund_status in
  137. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  138. #{item}
  139. </foreach>
  140. </if>
  141. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  142. AND ot.order_received <![CDATA[ < ]]> ot.pay_price
  143. </if>
  144. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  145. AND ot.pay_price = ot.order_received
  146. </if>
  147. <if test="invoiceStatus != null and invoiceStatus != ''">
  148. AND ot.invoice_status = #{invoiceStatus}
  149. </if>
  150. <if test="startTime != null and startTime != ''">
  151. AND ot.create_time <![CDATA[ >= ]]> #{startTime}
  152. </if>
  153. <if test="endTime != null and endTime != ''">
  154. AND ot.create_time <![CDATA[ <= ]]> #{endTime}
  155. </if>
  156. <if test="orderSn != null and orderSn != ''">
  157. AND ot.order_sn = #{orderSn}
  158. </if>
  159. <if test="orderSnList != null and orderSnList.size()!=0 ">
  160. AND ot.order_sn in
  161. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  162. #{item}
  163. </foreach>
  164. </if>
  165. <if test="keyword != null and keyword != ''">
  166. AND (
  167. ot.create_org LIKE CONCAT( '%', #{keyword}, '%' )
  168. OR ot.order_org LIKE CONCAT( '%', #{keyword}, '%' ))
  169. </if>
  170. ) + (SELECT
  171. COUNT( DISTINCT o.order_sn ) AS num
  172. FROM
  173. `order` o
  174. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  175. WHERE
  176. 1 = 1
  177. <if test="businessFullName != null and businessFullName != ''">
  178. AND (
  179. SELECT
  180. COUNT(g.goods_id)
  181. FROM
  182. goods g
  183. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  184. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  185. LEFT JOIN course_business cb ON g.business_id = cb.id
  186. WHERE
  187. og.goods_id = g.goods_id
  188. AND
  189. INSTR( CONCAT('学校业务', cet.education_name, cb.business_name, cpt.project_name),#{businessFullName}) > 0) > 0
  190. </if>
  191. <if test="userCard != null and userCard != ''">
  192. AND o.user_id = (SELECT user_id FROM `user` WHERE id_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler})
  193. </if>
  194. <if test="checkStatus != null and checkStatus != ''">
  195. AND o.check_status = #{checkStatus}
  196. </if>
  197. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  198. AND o.refund_status in
  199. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  200. #{item}
  201. </foreach>
  202. </if>
  203. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  204. AND o.order_received <![CDATA[ < ]]> o.pay_price
  205. </if>
  206. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  207. AND o.pay_price = o.order_received
  208. </if>
  209. <if test="invoiceStatus != null and invoiceStatus != ''">
  210. AND o.invoice_status = #{invoiceStatus}
  211. </if>
  212. <if test="startTime != null and startTime != ''">
  213. AND o.create_time <![CDATA[ >= ]]> #{startTime}
  214. </if>
  215. <if test="endTime != null and endTime != ''">
  216. AND o.create_time <![CDATA[ <= ]]> #{endTime}
  217. </if>
  218. <if test="orderSn != null and orderSn != ''">
  219. AND o.order_sn = #{orderSn}
  220. </if>
  221. <if test="orderSnList != null and orderSnList.size()!=0 ">
  222. AND o.order_sn in
  223. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  224. #{item}
  225. </foreach>
  226. </if>
  227. )) as number
  228. </select>
  229. <select id="queryById" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  230. SELECT * FROM v_top_order WHERE order_sn = #{orderSn}
  231. </select>
  232. <select id="queryBusinessBySn" parameterType="java.lang.String" resultType="java.lang.String">
  233. SELECT DISTINCT business_name FROM v_top_order_business WHERE order_sn = #{orderSn}
  234. </select>
  235. <select id="queryByOrderSns" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  236. SELECT * FROM v_top_order WHERE 1 =1
  237. <if test="orderSnList != null and orderSnList.size()!=0 ">
  238. AND order_sn in
  239. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  240. #{item}
  241. </foreach>
  242. </if>
  243. </select>
  244. <select id="queryReceiveList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  245. SELECT
  246. too.*,
  247. st.tenant_name,
  248. rn.id as note_id,
  249. rn.note_type,
  250. rn.day_time,
  251. rn.week_time,
  252. rn.month_time,
  253. rn.last_time
  254. FROM
  255. top_old_order too
  256. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  257. LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn
  258. where too.check_status=1 AND too.order_uncollected >0
  259. <if test="startTime != null and startTime != ''">
  260. AND too.buy_time <![CDATA[ >= ]]> #{startTime}
  261. </if>
  262. <if test="endTime != null and endTime != ''">
  263. AND too.buy_time <![CDATA[ <= ]]> #{endTime}
  264. </if>
  265. <if test="keyNo != null and keyNo != ''">
  266. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  267. </if>
  268. <if test="creditStatus != null and creditStatus != ''">
  269. AND too.credit_status = #{creditStatus}
  270. </if>
  271. <if test="orderSn != null and orderSn != ''">
  272. AND too.order_sn = #{orderSn}
  273. </if>
  274. <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">
  275. AND
  276. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  277. (too.check_time BETWEEN #{item.startTime} and #{item.endTime})
  278. </foreach>
  279. </if>
  280. <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">
  281. AND
  282. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  283. (too.check_time NOT BETWEEN #{item.startTime} and #{item.endTime})
  284. </foreach>
  285. </if>
  286. ORDER BY too.buy_time DESC
  287. </select>
  288. <select id="queryDivSellerList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  289. SELECT
  290. too.*,
  291. st.tenant_name,
  292. r.role_name,
  293. cl.check_status as divide_check_status
  294. FROM
  295. v_top_order too
  296. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  297. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  298. AND cl.check_sign = 1
  299. AND ( too.divide_model + 1 ) = cl.check_from
  300. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  301. where 1=1 AND too.divide_model = 2
  302. <if test="startTime != null and startTime != ''">
  303. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  304. </if>
  305. <if test="endTime != null and endTime != ''">
  306. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  307. </if>
  308. <if test="keyNo != null and keyNo != ''">
  309. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  310. </if>
  311. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  312. AND too.divide_status in
  313. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  314. #{item}
  315. </foreach>
  316. </if>
  317. <if test="divideStatus != null and divideStatus != ''">
  318. AND too.divide_status = #{divideStatus}
  319. </if>
  320. <if test="roleId != null and roleId != ''">
  321. AND cl.role_id = #{roleId}
  322. </if>
  323. ORDER BY too.order_id DESC
  324. </select>
  325. <select id="queryTenantList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  326. SELECT
  327. too.*,
  328. st.tenant_name,
  329. r.role_name,
  330. cl.check_status as divide_check_status
  331. FROM
  332. top_old_order too
  333. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  334. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  335. AND cl.check_sign = 1
  336. AND ( too.divide_model + 1 ) = cl.check_from
  337. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  338. where 1=1 AND too.divide_model = 1
  339. <if test="startTime != null and startTime != ''">
  340. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  341. </if>
  342. <if test="endTime != null and endTime != ''">
  343. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  344. </if>
  345. <if test="keyNo != null and keyNo != ''">
  346. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  347. </if>
  348. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  349. AND too.divide_status in
  350. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  351. #{item}
  352. </foreach>
  353. </if>
  354. <if test="divideStatus != null and divideStatus != ''">
  355. AND too.divide_status = #{divideStatus}
  356. </if>
  357. <if test="tenantId != null and tenantId != ''">
  358. AND too.tenant_id = #{tenantId}
  359. </if>
  360. <if test="roleId != null and roleId != ''">
  361. AND cl.role_id = #{roleId}
  362. </if>
  363. ORDER BY too.order_id DESC
  364. </select>
  365. <select id="tenantMoneyTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="BigDecimal">
  366. SELECT
  367. IFNULL( SUM( too.divide_company_money ), 0 )
  368. FROM
  369. v_top_order too
  370. WHERE
  371. too.divide_model = 1
  372. AND too.divide_status = 5
  373. </select>
  374. <select id="tenantSellerTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="BigDecimal">
  375. SELECT
  376. IFNULL( SUM( too.divide_seller_money ), 0 )
  377. FROM
  378. v_top_order too
  379. WHERE
  380. too.divide_model = 2
  381. AND too.divide_status = 5
  382. </select>
  383. <select id="queryListAll" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  384. SELECT * FROM v_top_order
  385. </select>
  386. <select id="getOrderBySn" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.domain.TopOldOrder">
  387. SELECT * FROM v_top_order WHERE order_sn = #{orderSn}
  388. </select>
  389. <select id="logList" parameterType="com.zhongzheng.modules.top.financial.bo.TopOrderLogQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopOrderLogVo">
  390. SELECT * FROM top_order_log WHERE order_sn = #{orderSn}
  391. </select>
  392. <select id="getRefundOrder" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  393. SELECT * FROM v_top_order_refund WHERE order_sn = #{orderSn}
  394. </select>
  395. <select id="getRefundOrderByBo" parameterType="com.zhongzheng.modules.top.financial.bo.RefundOrderBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  396. SELECT * FROM v_top_order_refund WHERE order_sn = #{orderSn} AND status = 1
  397. <if test="periodStatus != null and periodStatus != ''">
  398. AND period_status = #{periodStatus}
  399. </if>
  400. </select>
  401. </mapper>