TopOldOrderMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 and 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="refundStatusList != null and refundStatusList.size()!=0 ">
  77. AND vto.refund_status in
  78. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  79. #{item}
  80. </foreach>
  81. </if>
  82. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  83. AND vto.order_received <![CDATA[ < ]]> vto.pay_price
  84. </if>
  85. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  86. AND vto.pay_price = vto.order_received
  87. </if>
  88. <if test="invoiceStatus != null and invoiceStatus != ''">
  89. AND vto.invoice_status = #{invoiceStatus}
  90. </if>
  91. <if test="startTime != null and startTime != ''">
  92. AND vto.create_time <![CDATA[ >= ]]> #{startTime}
  93. </if>
  94. <if test="endTime != null and endTime != ''">
  95. AND vto.create_time <![CDATA[ <= ]]> #{endTime}
  96. </if>
  97. <if test="orderSn != null and orderSn != ''">
  98. AND vto.order_sn = #{orderSn}
  99. </if>
  100. <if test="orderSnList != null and orderSnList.size()!=0 ">
  101. AND vto.order_sn in
  102. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  103. #{item}
  104. </foreach>
  105. </if>
  106. <if test="keyword != null and keyword != ''">
  107. AND (
  108. vto.create_org LIKE CONCAT( '%', #{keyword}, '%' )
  109. -- OR vto.course_org LIKE CONCAT( '%', #{keyword}, '%' )
  110. OR vto.order_org LIKE CONCAT( '%', #{keyword}, '%' ))
  111. </if>
  112. </select>
  113. <select id="queryList_COUNT" resultType="Long">
  114. SELECT
  115. ((SELECT
  116. COUNT( DISTINCT ot.order_sn ) AS num
  117. FROM
  118. top_old_order ot
  119. LEFT JOIN top_old_order_goods otg ON ot.order_sn = otg.order_sn
  120. WHERE
  121. 1 = 1
  122. <if test="businessFullName != null and businessFullName != ''">
  123. AND INSTR( otg.business_full_name , #{businessFullName} ) > 0
  124. </if>
  125. <if test="userCard != null and userCard != ''">
  126. AND otg.user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  127. </if>
  128. <if test="checkStatus != null and checkStatus != ''">
  129. AND ot.check_status = #{checkStatus}
  130. </if>
  131. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  132. AND ot.refund_status in
  133. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  134. #{item}
  135. </foreach>
  136. </if>
  137. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  138. AND ot.order_received <![CDATA[ < ]]> ot.pay_price
  139. </if>
  140. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  141. AND ot.pay_price = ot.order_received
  142. </if>
  143. <if test="invoiceStatus != null and invoiceStatus != ''">
  144. AND ot.invoice_status = #{invoiceStatus}
  145. </if>
  146. <if test="startTime != null and startTime != ''">
  147. AND ot.create_time <![CDATA[ >= ]]> #{startTime}
  148. </if>
  149. <if test="endTime != null and endTime != ''">
  150. AND ot.create_time <![CDATA[ <= ]]> #{endTime}
  151. </if>
  152. <if test="orderSn != null and orderSn != ''">
  153. AND ot.order_sn = #{orderSn}
  154. </if>
  155. <if test="orderSnList != null and orderSnList.size()!=0 ">
  156. AND ot.order_sn in
  157. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  158. #{item}
  159. </foreach>
  160. </if>
  161. <if test="keyword != null and keyword != ''">
  162. AND (
  163. ot.create_org LIKE CONCAT( '%', #{keyword}, '%' )
  164. OR ot.order_org LIKE CONCAT( '%', #{keyword}, '%' ))
  165. </if>
  166. ) + (SELECT
  167. COUNT( DISTINCT o.order_sn ) AS num
  168. FROM
  169. `order` o
  170. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  171. WHERE
  172. 1 = 1
  173. <if test="businessFullName != null and businessFullName != ''">
  174. AND (
  175. SELECT
  176. COUNT(g.goods_id)
  177. FROM
  178. goods g
  179. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  180. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  181. LEFT JOIN course_business cb ON g.business_id = cb.id
  182. WHERE
  183. og.goods_id = g.goods_id
  184. AND
  185. INSTR( CONCAT('学校业务', cet.education_name, cb.business_name, cpt.project_name),#{businessFullName}) > 0) > 0
  186. </if>
  187. <if test="userCard != null and userCard != ''">
  188. AND o.user_id = (SELECT user_id FROM `user` WHERE id_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler})
  189. </if>
  190. <if test="checkStatus != null and checkStatus != ''">
  191. AND o.check_status = #{checkStatus}
  192. </if>
  193. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  194. AND o.refund_status in
  195. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  196. #{item}
  197. </foreach>
  198. </if>
  199. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  200. AND o.order_received <![CDATA[ < ]]> o.pay_price
  201. </if>
  202. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  203. AND o.pay_price = o.order_received
  204. </if>
  205. <if test="invoiceStatus != null and invoiceStatus != ''">
  206. AND o.invoice_status = #{invoiceStatus}
  207. </if>
  208. <if test="startTime != null and startTime != ''">
  209. AND o.create_time <![CDATA[ >= ]]> #{startTime}
  210. </if>
  211. <if test="endTime != null and endTime != ''">
  212. AND o.create_time <![CDATA[ <= ]]> #{endTime}
  213. </if>
  214. <if test="orderSn != null and orderSn != ''">
  215. AND o.order_sn = #{orderSn}
  216. </if>
  217. <if test="orderSnList != null and orderSnList.size()!=0 ">
  218. AND o.order_sn in
  219. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  220. #{item}
  221. </foreach>
  222. </if>
  223. )) as number
  224. </select>
  225. <select id="queryById" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  226. SELECT * FROM v_top_order WHERE order_sn = #{orderSn}
  227. </select>
  228. <select id="queryBusinessBySn" parameterType="java.lang.String" resultType="java.lang.String">
  229. SELECT DISTINCT business_name FROM v_top_order_business WHERE order_sn = #{orderSn}
  230. </select>
  231. <select id="queryByOrderSns" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  232. SELECT * FROM v_top_order WHERE 1 =1
  233. <if test="orderSnList != null and orderSnList.size()!=0 ">
  234. AND order_sn in
  235. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  236. #{item}
  237. </foreach>
  238. </if>
  239. </select>
  240. <select id="queryReceiveList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  241. SELECT
  242. too.*,
  243. st.tenant_name,
  244. rn.id as note_id,
  245. rn.note_type,
  246. rn.day_time,
  247. rn.week_time,
  248. rn.month_time,
  249. rn.last_time
  250. FROM
  251. top_old_order too
  252. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  253. LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn
  254. where too.status=1
  255. <if test="startTime != null and startTime != ''">
  256. AND too.buy_time <![CDATA[ >= ]]> #{startTime}
  257. </if>
  258. <if test="endTime != null and endTime != ''">
  259. AND too.buy_time <![CDATA[ <= ]]> #{endTime}
  260. </if>
  261. <if test="keyNo != null and keyNo != ''">
  262. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  263. </if>
  264. <if test="creditStatus != null and creditStatus != ''">
  265. AND too.credit_status = #{creditStatus}
  266. </if>
  267. <if test="orderSn != null and orderSn != ''">
  268. AND too.order_sn = #{orderSn}
  269. </if>
  270. <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">
  271. AND
  272. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  273. (too.buy_time BETWEEN #{item.startTime} and #{item.endTime})
  274. </foreach>
  275. </if>
  276. <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">
  277. AND
  278. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  279. (too.buy_time NOT BETWEEN #{item.startTime} and #{item.endTime})
  280. </foreach>
  281. </if>
  282. ORDER BY too.buy_time DESC
  283. </select>
  284. <select id="queryDivSellerList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  285. SELECT
  286. too.*,
  287. st.tenant_name,
  288. r.role_name,
  289. cl.check_status as divide_check_status
  290. FROM
  291. v_top_order too
  292. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  293. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  294. AND cl.check_sign = 1
  295. AND ( too.divide_model + 1 ) = cl.check_from
  296. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  297. where 1=1 AND too.divide_model = 2
  298. <if test="startTime != null and startTime != ''">
  299. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  300. </if>
  301. <if test="endTime != null and endTime != ''">
  302. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  303. </if>
  304. <if test="keyNo != null and keyNo != ''">
  305. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  306. </if>
  307. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  308. AND too.divide_status in
  309. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  310. #{item}
  311. </foreach>
  312. </if>
  313. <if test="divideStatus != null and divideStatus != ''">
  314. AND too.divide_status = #{divideStatus}
  315. </if>
  316. <if test="roleId != null and roleId != ''">
  317. AND cl.role_id = #{roleId}
  318. </if>
  319. ORDER BY too.order_id DESC
  320. </select>
  321. <select id="queryTenantList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  322. SELECT
  323. too.*,
  324. st.tenant_name,
  325. r.role_name,
  326. cl.check_status as divide_check_status
  327. FROM
  328. top_old_order too
  329. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  330. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  331. AND cl.check_sign = 1
  332. AND ( too.divide_model + 1 ) = cl.check_from
  333. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  334. where 1=1 AND too.divide_model = 1
  335. <if test="startTime != null and startTime != ''">
  336. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  337. </if>
  338. <if test="endTime != null and endTime != ''">
  339. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  340. </if>
  341. <if test="keyNo != null and keyNo != ''">
  342. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  343. </if>
  344. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  345. AND too.divide_status in
  346. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  347. #{item}
  348. </foreach>
  349. </if>
  350. <if test="divideStatus != null and divideStatus != ''">
  351. AND too.divide_status = #{divideStatus}
  352. </if>
  353. <if test="tenantId != null and tenantId != ''">
  354. AND too.tenant_id = #{tenantId}
  355. </if>
  356. <if test="roleId != null and roleId != ''">
  357. AND cl.role_id = #{roleId}
  358. </if>
  359. ORDER BY too.order_id DESC
  360. </select>
  361. <select id="tenantMoneyTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="BigDecimal">
  362. SELECT
  363. IFNULL( SUM( too.divide_company_money ), 0 )
  364. FROM
  365. v_top_order too
  366. WHERE
  367. too.divide_model = 1
  368. AND too.divide_status = 5
  369. </select>
  370. <select id="tenantSellerTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo" resultType="BigDecimal">
  371. SELECT
  372. IFNULL( SUM( too.divide_seller_money ), 0 )
  373. FROM
  374. v_top_order too
  375. WHERE
  376. too.divide_model = 2
  377. AND too.divide_status = 5
  378. </select>
  379. <select id="queryListAll" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  380. SELECT * FROM v_top_order
  381. </select>
  382. <select id="getOrderBySn" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.domain.TopOldOrder">
  383. SELECT * FROM v_top_order WHERE order_sn = #{orderSn}
  384. </select>
  385. <select id="logList" parameterType="com.zhongzheng.modules.top.financial.bo.TopOrderLogQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopOrderLogVo">
  386. SELECT * FROM top_order_log WHERE order_sn = #{orderSn}
  387. </select>
  388. <select id="getRefundOrder" parameterType="java.lang.String" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  389. SELECT * FROM v_top_order_refund WHERE order_sn = #{orderSn}
  390. </select>
  391. <select id="getRefundOrderByBo" parameterType="com.zhongzheng.modules.top.financial.bo.RefundOrderBo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  392. SELECT * FROM v_top_order_refund WHERE order_sn = #{orderSn} AND status = 1
  393. <if test="periodStatus != null and periodStatus != ''">
  394. AND period_status = #{periodStatus}
  395. </if>
  396. </select>
  397. </mapper>