TopOldOrderMapper.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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"
  43. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  44. SELECT
  45. vto.*
  46. FROM
  47. <if test="businessFullName != null and businessFullName != '' and ((userCard == null or userCard == '') and (userName == null or userName == ''))">
  48. ( SELECT DISTINCT order_sn
  49. FROM `v_top_order_business` where INSTR( business_full_name,#{businessFullName} ) > 0
  50. ) a
  51. LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn
  52. </if>
  53. <if test="((userCard != null and userCard != '') or (userName != null and userName != '')) and (businessFullName == null or businessFullName == '')">
  54. ( SELECT DISTINCT order_sn
  55. FROM `v_top_order_card` where 1=1
  56. <if test="userCard != null and userCard != ''">
  57. AND user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  58. </if>
  59. <if test="userName != null and userName != ''">
  60. AND user_name LIKE CONCAT( '%', #{userName}, '%' )
  61. </if>
  62. ) a
  63. LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn
  64. </if>
  65. <if test="((userCard != null and userCard != '') or (userName != null and userName != '')) and businessFullName != null and businessFullName != ''">
  66. ( SELECT DISTINCT order_sn
  67. FROM (
  68. SELECT
  69. DISTINCT order_sn
  70. FROM
  71. ( SELECT order_sn FROM v_top_order_business WHERE INSTR( business_full_name,#{businessFullName} ) > 0 UNION
  72. ALL SELECT order_sn FROM v_top_order_card
  73. WHERE 1 = 1
  74. <if test="userCard != null and userCard != ''">
  75. AND user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  76. </if>
  77. <if test="userName != null and userName != ''">
  78. AND user_name LIKE CONCAT( '%', #{userName}, '%' )
  79. </if>
  80. ) b
  81. ) m
  82. ) a
  83. LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn
  84. </if>
  85. <if test="(userCard == null or userCard == '') and (businessFullName == null or businessFullName == '') and (userName == null or userName == '')">
  86. v_top_order vto
  87. </if>
  88. WHERE vto.`status` in (0,1)
  89. <if test="operationType != null">
  90. AND vto.operation_type = #{operationType}
  91. </if>
  92. <if test="checkStatus != null and checkStatus.size()!=0 ">
  93. AND vto.check_status in
  94. <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">
  95. #{item}
  96. </foreach>
  97. </if>
  98. <if test="refundStatus != null">
  99. AND vto.refund_status = #{refundStatus}
  100. </if>
  101. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  102. AND vto.refund_status in
  103. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  104. #{item}
  105. </foreach>
  106. </if>
  107. <if test="creditStatus != null and creditStatus == 0">
  108. AND vto.order_received <![CDATA[ < ]]> vto.pay_price
  109. </if>
  110. <if test="creditStatus != null and creditStatus == 1">
  111. AND vto.pay_price = vto.order_received
  112. </if>
  113. <if test="finishStatus != null">
  114. AND vto.finish_status = #{finishStatus}
  115. </if>
  116. <if test="invoiceStatus != null and invoiceStatus != ''">
  117. AND vto.invoice_status = #{invoiceStatus}
  118. </if>
  119. <if test="orderOrg != null and orderOrg != ''">
  120. AND vto.order_org LIKE CONCAT( '%', #{orderOrg}, '%' )
  121. </if>
  122. <if test="startTime != null and startTime != ''">
  123. AND vto.buy_time <![CDATA[ >= ]]> #{startTime}
  124. </if>
  125. <if test="endTime != null and endTime != ''">
  126. AND vto.buy_time <![CDATA[ <= ]]> #{endTime}
  127. </if>
  128. <if test="checkStartTime != null and checkStartTime != ''">
  129. AND vto.check_time <![CDATA[ >= ]]> #{checkStartTime}
  130. </if>
  131. <if test="checkEndTime != null and checkEndTime != ''">
  132. AND vto.check_time <![CDATA[ <= ]]> #{checkEndTime}
  133. </if>
  134. <if test="orderSn != null and orderSn != ''">
  135. AND vto.order_sn = #{orderSn}
  136. </if>
  137. <if test="tenantId != null and tenantId != ''">
  138. AND vto.tenant_id = #{tenantId}
  139. </if>
  140. <if test="orderSnList != null and orderSnList.size()!=0 ">
  141. AND vto.order_sn in
  142. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  143. #{item}
  144. </foreach>
  145. </if>
  146. <if test="keyword != null and keyword != ''">
  147. AND (
  148. vto.order_sn LIKE CONCAT( '%', #{keyword}, '%' )
  149. OR vto.create_no LIKE CONCAT( '%', #{keyword}, '%' )
  150. OR vto.purchase_org LIKE CONCAT( '%', #{keyword}, '%' ))
  151. </if>
  152. order by vto.create_time DESC
  153. </select>
  154. <select id="queryList_COUNT" resultType="Long">
  155. SELECT
  156. ((SELECT
  157. COUNT( DISTINCT ot.order_sn ) AS num
  158. FROM
  159. top_old_order ot
  160. LEFT JOIN top_old_order_goods otg ON ot.order_sn = otg.order_sn
  161. WHERE
  162. 1 = 1 AND ot.`status` = 1
  163. <if test="businessFullName != null and businessFullName != ''">
  164. AND INSTR( otg.business_full_name , #{businessFullName} ) > 0
  165. </if>
  166. <if test="userCard != null and userCard != ''">
  167. AND otg.user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  168. </if>
  169. <if test="operationType != null">
  170. AND ot.operation_type = #{operationType}
  171. </if>
  172. <if test="userName != null and userName != ''">
  173. AND otg.user_name LIKE CONCAT( '%', #{userName}, '%' )
  174. </if>
  175. <if test="checkStatus != null and checkStatus.size()!=0 ">
  176. AND ot.check_status in
  177. <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">
  178. #{item}
  179. </foreach>
  180. </if>
  181. <if test="refundStatus != null">
  182. AND ot.refund_status = #{refundStatus}
  183. </if>
  184. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  185. AND ot.refund_status in
  186. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  187. #{item}
  188. </foreach>
  189. </if>
  190. <if test="orderOrg != null and orderOrg != ''">
  191. AND ot.order_org LIKE CONCAT( '%', #{orderOrg}, '%' )
  192. </if>
  193. <if test="checkStartTime != null and checkStartTime != ''">
  194. AND ot.check_time <![CDATA[ >= ]]> #{checkStartTime}
  195. </if>
  196. <if test="checkEndTime != null and checkEndTime != ''">
  197. AND ot.check_time <![CDATA[ <= ]]> #{checkEndTime}
  198. </if>
  199. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  200. AND ot.order_received <![CDATA[ < ]]> ot.pay_price
  201. </if>
  202. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  203. AND ot.pay_price = ot.order_received
  204. </if>
  205. <if test="invoiceStatus != null and invoiceStatus != ''">
  206. AND ot.invoice_status = #{invoiceStatus}
  207. </if>
  208. <if test="startTime != null and startTime != ''">
  209. AND ot.create_time <![CDATA[ >= ]]> #{startTime}
  210. </if>
  211. <if test="endTime != null and endTime != ''">
  212. AND ot.create_time <![CDATA[ <= ]]> #{endTime}
  213. </if>
  214. <if test="orderSn != null and orderSn != ''">
  215. AND ot.order_sn = #{orderSn}
  216. </if>
  217. <if test="finishStatus != null">
  218. AND ot.finish_status = #{finishStatus}
  219. </if>
  220. <if test="tenantId != null and tenantId != ''">
  221. AND ot.tenant_id = #{tenantId}
  222. </if>
  223. <if test="orderSnList != null and orderSnList.size()!=0 ">
  224. AND ot.order_sn in
  225. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  226. #{item}
  227. </foreach>
  228. </if>
  229. <if test="keyword != null and keyword != ''">
  230. AND (
  231. ot.order_sn LIKE CONCAT( '%', #{keyword}, '%' )
  232. OR ot.create_no LIKE CONCAT( '%', #{keyword}, '%' )
  233. OR ot.purchase_org LIKE CONCAT( '%', #{keyword}, '%' ))
  234. </if>
  235. ) + (SELECT
  236. COUNT( DISTINCT o.order_sn ) AS num
  237. FROM
  238. `order` o
  239. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  240. LEFT JOIN `user` u ON o.user_id = u.user_id
  241. WHERE
  242. 1 = 1 AND o.`status` IN (0,1)
  243. AND ( `o`.`order_type` != 4 )
  244. AND (
  245. isnull( `o`.`input_order_sn` )
  246. OR (
  247. NOT (
  248. `o`.`input_order_sn` IN ( SELECT `top_old_order`.`input_order_sn` FROM `top_old_order` ))))
  249. <if test="businessFullName != null and businessFullName != ''">
  250. AND (
  251. SELECT
  252. COUNT(g.goods_id)
  253. FROM
  254. goods g
  255. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  256. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  257. LEFT JOIN course_business cb ON g.business_id = cb.id
  258. WHERE
  259. og.goods_id = g.goods_id
  260. AND
  261. INSTR( CONCAT('学校业务', cet.education_name, cb.business_name, cpt.project_name),#{businessFullName}) > 0) > 0
  262. </if>
  263. <if test="userCard != null and userCard != ''">
  264. AND u.id_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  265. </if>
  266. <if test="userName != null and userName != ''">
  267. AND u.realname LIKE CONCAT( '%', #{userName}, '%' )
  268. </if>
  269. <if test="checkStatus != null and checkStatus.size()!=0 ">
  270. AND o.check_status in
  271. <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">
  272. #{item}
  273. </foreach>
  274. </if>
  275. <if test="operationType != null">
  276. AND o.operation_type = #{operationType}
  277. </if>
  278. <if test="refundStatus != null">
  279. AND o.order_refund_status = #{refundStatus}
  280. </if>
  281. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  282. AND o.order_refund_status in
  283. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  284. #{item}
  285. </foreach>
  286. </if>
  287. <if test="orderOrg != null and orderOrg != ''">
  288. AND 'C端云学堂' LIKE CONCAT( '%', #{orderOrg}, '%' )
  289. </if>
  290. <if test="checkStartTime != null and checkStartTime != ''">
  291. AND o.pay_time <![CDATA[ >= ]]> #{checkStartTime}
  292. </if>
  293. <if test="checkEndTime != null and checkEndTime != ''">
  294. AND o.pay_time <![CDATA[ <= ]]> #{checkEndTime}
  295. </if>
  296. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  297. AND o.order_received <![CDATA[ < ]]> o.pay_price
  298. </if>
  299. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  300. AND o.pay_price = o.order_received
  301. </if>
  302. <if test="invoiceStatus != null and invoiceStatus != ''">
  303. AND o.invoice_status = #{invoiceStatus}
  304. </if>
  305. <if test="finishStatus != null">
  306. AND o.finish_status = #{finishStatus}
  307. </if>
  308. <if test="tenantId != null and tenantId != ''">
  309. AND o.tenant_id = #{tenantId}
  310. </if>
  311. <if test="startTime != null and startTime != ''">
  312. AND o.create_time <![CDATA[ >= ]]> #{startTime}
  313. </if>
  314. <if test="startTime == null">
  315. AND o.create_time <![CDATA[ > ]]> #{filtrationTime}
  316. </if>
  317. <if test="endTime != null and endTime != ''">
  318. AND o.create_time <![CDATA[ <= ]]> #{endTime}
  319. </if>
  320. <if test="orderSn != null and orderSn != ''">
  321. AND o.order_sn = #{orderSn}
  322. </if>
  323. <if test="orderSnList != null and orderSnList.size()!=0 ">
  324. AND o.order_sn in
  325. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  326. #{item}
  327. </foreach>
  328. </if>
  329. <if test="keyword != null and keyword != ''">
  330. AND o.order_sn LIKE CONCAT( '%', #{keyword}, '%' )
  331. </if>
  332. )) as number
  333. </select>
  334. <select id="queryById" parameterType="java.lang.String"
  335. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  336. SELECT *
  337. FROM v_top_order
  338. WHERE order_sn = #{orderSn}
  339. </select>
  340. <select id="queryBusinessBySn" parameterType="java.lang.String" resultType="java.lang.String">
  341. SELECT DISTINCT business_name
  342. FROM v_top_order_business
  343. WHERE order_sn = #{orderSn}
  344. </select>
  345. <select id="queryBusinessFullNameBySn" parameterType="java.lang.String" resultType="java.lang.String">
  346. SELECT DISTINCT business_full_name
  347. FROM top_old_order_goods
  348. WHERE order_sn = #{orderSn}
  349. AND `status` = 1
  350. AND check_status = 1
  351. </select>
  352. <select id="queryByOrderSns" parameterType="java.lang.String"
  353. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  354. SELECT * FROM v_top_order WHERE 1 =1
  355. <if test="orderSnList != null and orderSnList.size()!=0 ">
  356. AND order_sn in
  357. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  358. #{item}
  359. </foreach>
  360. </if>
  361. </select>
  362. <select id="queryReceiveUnSum" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  363. resultType="long">
  364. SELECT
  365. IFNULL(sum(
  366. too.order_uncollected),0)
  367. FROM
  368. top_old_order too
  369. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  370. LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn
  371. where too.check_status=1 AND too.order_uncollected >0
  372. <if test="tenantId != null and tenantId != ''">
  373. AND too.tenant_id = #{tenantId}
  374. </if>
  375. <if test="startTime != null and startTime != ''">
  376. AND too.buy_time <![CDATA[ >= ]]> #{startTime}
  377. </if>
  378. <if test="endTime != null and endTime != ''">
  379. AND too.buy_time <![CDATA[ <= ]]> #{endTime}
  380. </if>
  381. <if test="keyNo != null and keyNo != ''">
  382. AND (st.tenant_name like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  383. </if>
  384. <if test="creditStatus != null and creditStatus != ''">
  385. AND too.credit_status = #{creditStatus}
  386. </if>
  387. <if test="orderSn != null and orderSn != ''">
  388. AND too.order_sn = #{orderSn}
  389. </if>
  390. <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">
  391. AND
  392. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  393. (too.check_time BETWEEN #{item.startTime} and #{item.endTime})
  394. </foreach>
  395. </if>
  396. <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">
  397. AND
  398. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  399. (too.check_time NOT BETWEEN #{item.startTime} and #{item.endTime})
  400. </foreach>
  401. </if>
  402. ORDER BY too.buy_time DESC
  403. </select>
  404. <select id="queryReceiveList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  405. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  406. SELECT
  407. too.*,
  408. st.tenant_name,
  409. rn.id as note_id,
  410. rn.note_type,
  411. rn.day_time,
  412. rn.week_time,
  413. rn.month_time,
  414. rn.last_time,
  415. rn.exceed_type
  416. FROM
  417. top_old_order too
  418. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  419. LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn
  420. where too.check_status=1 AND too.order_uncollected >0
  421. <if test="operationType != null and operationType != ''">
  422. AND too.operation_type = #{operationType}
  423. </if>
  424. <if test="tenantId != null and tenantId != ''">
  425. AND too.tenant_id = #{tenantId}
  426. </if>
  427. <if test="startTime != null and startTime != ''">
  428. AND too.buy_time <![CDATA[ >= ]]> #{startTime}
  429. </if>
  430. <if test="endTime != null and endTime != ''">
  431. AND too.buy_time <![CDATA[ <= ]]> #{endTime}
  432. </if>
  433. <if test="keyNo != null and keyNo != ''">
  434. AND (st.tenant_name like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  435. </if>
  436. <if test="creditStatus != null and creditStatus != ''">
  437. AND too.credit_status = #{creditStatus}
  438. </if>
  439. <if test="orderSn != null and orderSn != ''">
  440. AND too.order_sn = #{orderSn}
  441. </if>
  442. <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">
  443. AND
  444. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  445. (too.check_time BETWEEN #{item.startTime} and #{item.endTime})
  446. </foreach>
  447. </if>
  448. <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">
  449. AND
  450. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  451. (too.check_time NOT BETWEEN #{item.startTime} and #{item.endTime})
  452. </foreach>
  453. </if>
  454. ORDER BY too.buy_time DESC
  455. </select>
  456. <select id="queryDivSellerList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  457. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  458. SELECT
  459. too.*,
  460. st.tenant_name,
  461. r.role_name,
  462. cl.check_status as divide_check_status
  463. FROM
  464. v_top_order too
  465. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  466. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  467. AND cl.check_sign = 1
  468. AND ( too.divide_model + 1 ) = cl.check_from
  469. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  470. where 1=1 AND too.divide_model = 2
  471. <if test="startTime != null and startTime != ''">
  472. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  473. </if>
  474. <if test="endTime != null and endTime != ''">
  475. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  476. </if>
  477. <if test="keyNo != null and keyNo != ''">
  478. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  479. </if>
  480. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  481. AND too.divide_status in
  482. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  483. #{item}
  484. </foreach>
  485. </if>
  486. <if test="divideStatus != null and divideStatus != ''">
  487. AND too.divide_status = #{divideStatus}
  488. </if>
  489. <if test="roleId != null and roleId != ''">
  490. AND cl.role_id = #{roleId}
  491. </if>
  492. ORDER BY too.order_id DESC
  493. </select>
  494. <select id="queryTenantList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  495. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  496. SELECT
  497. too.*,
  498. st.tenant_name,
  499. r.role_name,
  500. cl.check_status as divide_check_status
  501. FROM
  502. top_old_order too
  503. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  504. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  505. AND cl.check_sign = 1
  506. AND ( too.divide_model + 1 ) = cl.check_from
  507. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  508. where 1=1 AND too.divide_model = 1
  509. <if test="startTime != null and startTime != ''">
  510. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  511. </if>
  512. <if test="endTime != null and endTime != ''">
  513. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  514. </if>
  515. <if test="keyNo != null and keyNo != ''">
  516. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  517. </if>
  518. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  519. AND too.divide_status in
  520. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  521. #{item}
  522. </foreach>
  523. </if>
  524. <if test="divideStatus != null and divideStatus != ''">
  525. AND too.divide_status = #{divideStatus}
  526. </if>
  527. <if test="tenantId != null and tenantId != ''">
  528. AND too.tenant_id = #{tenantId}
  529. </if>
  530. <if test="roleId != null and roleId != ''">
  531. AND cl.role_id = #{roleId}
  532. </if>
  533. ORDER BY too.order_id DESC
  534. </select>
  535. <select id="tenantMoneyTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  536. resultType="BigDecimal">
  537. SELECT IFNULL(SUM(too.divide_company_money), 0)
  538. FROM v_top_order too
  539. WHERE too.divide_model = 1
  540. AND too.divide_status = 5
  541. </select>
  542. <select id="tenantSellerTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  543. resultType="BigDecimal">
  544. SELECT IFNULL(SUM(too.divide_seller_money), 0)
  545. FROM v_top_order too
  546. WHERE too.divide_model = 2
  547. AND too.divide_status = 5
  548. </select>
  549. <select id="queryListAll" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  550. SELECT *
  551. FROM v_top_order
  552. </select>
  553. <select id="getOrderBySn" parameterType="java.lang.String"
  554. resultType="com.zhongzheng.modules.top.goods.domain.TopOldOrder">
  555. SELECT *
  556. FROM v_top_order
  557. WHERE order_sn = #{orderSn}
  558. </select>
  559. <select id="logList" parameterType="com.zhongzheng.modules.top.financial.bo.TopOrderLogQueryBo"
  560. resultType="com.zhongzheng.modules.top.financial.vo.TopOrderLogVo">
  561. SELECT *
  562. FROM top_order_log
  563. WHERE order_sn = #{orderSn}
  564. </select>
  565. <select id="getRefundOrder" parameterType="java.lang.String"
  566. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  567. SELECT *
  568. FROM v_top_order_refund
  569. WHERE order_sn = #{orderSn}
  570. </select>
  571. <select id="getRefundOrderByBo" parameterType="com.zhongzheng.modules.top.financial.bo.RefundOrderBo"
  572. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  573. SELECT * FROM v_top_order_refund WHERE order_sn = #{orderSn} AND status = 1
  574. <if test="periodStatus != null and periodStatus != ''">
  575. AND period_status = #{periodStatus}
  576. </if>
  577. </select>
  578. <select id="getOrderSnByBusiness" parameterType="java.lang.String" resultType="java.lang.String">
  579. SELECT DISTINCT order_sn
  580. FROM v_top_order_business
  581. WHERE INSTR(business_full_name, #{businessName}) > 0
  582. </select>
  583. <select id="getOrderInvoiceList" parameterType="com.zhongzheng.modules.top.goods.vo.TopOldOrderInvoiceVo" resultType="java.lang.String">
  584. SELECT
  585. create_time AS applyUpTime,
  586. `status` AS invoiceStatus,
  587. update_time AS invoiceTime,
  588. oss_pdf_url AS ossPdfUrl,
  589. content
  590. FROM
  591. top_nuo_mplatform_log
  592. WHERE
  593. INSTR(order_no_list,#{orderSn})
  594. </select>
  595. <select id="getMoneyStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  596. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">
  597. SELECT
  598. *
  599. FROM
  600. (
  601. SELECT
  602. SUM( too.order_received - too.order_refunded ) AS money,
  603. too.old_customer_id AS customer_id,
  604. (
  605. SELECT
  606. tod.purchase_org
  607. FROM
  608. top_old_order tod
  609. WHERE
  610. tod.old_customer_id = too.old_customer_id
  611. AND tod.`status` = 1
  612. AND tod.check_status = 1
  613. LIMIT 1
  614. ) AS customer_name
  615. FROM
  616. top_old_order too
  617. WHERE
  618. too.`status` = 1
  619. AND too.check_status = 1
  620. AND too.old_customer_id IS NOT NULL
  621. <if test="startTime != null and startTime != ''">
  622. AND too.check_time &gt;= #{startTime}
  623. </if>
  624. <if test="endTime != null and endTime != ''">
  625. AND too.check_time &lt;= #{endTime}
  626. </if>
  627. <if test="customerId != null and customerId != ''">
  628. AND too.old_customer_id = #{customerId}
  629. </if>
  630. GROUP BY
  631. too.old_customer_id UNION ALL
  632. SELECT
  633. SUM( o.order_price ) AS money,
  634. o.tenant_id AS customer_id,
  635. ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name
  636. FROM
  637. `order` o
  638. WHERE
  639. o.`status` = 1
  640. AND o.order_status = 1
  641. AND (
  642. o.input_order_sn IS NULL
  643. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 0 ) AND o.tenant_id IS NOT NULL
  644. <if test="startTime != null and startTime != ''">
  645. AND o.create_time &gt;= #{startTime}
  646. </if>
  647. <if test="endTime != null and endTime != ''">
  648. AND o.create_time &lt;= #{endTime}
  649. </if>
  650. <if test="customerId != null and customerId != ''">
  651. AND o.tenant_id = #{customerId}
  652. </if>
  653. GROUP BY
  654. o.tenant_id
  655. ) a
  656. WHERE
  657. 1 = 1
  658. ORDER BY
  659. a.money DESC
  660. </select>
  661. <select id="getMoneyStatisticsTotal" parameterType="java.lang.Long"
  662. resultType="java.math.BigDecimal">
  663. SELECT
  664. (
  665. SELECT
  666. SUM( too.order_received - too.order_refunded ) AS money
  667. FROM
  668. top_old_order too
  669. WHERE
  670. too.`status` = 1
  671. AND too.check_status = 1
  672. AND too.old_customer_id IS NOT NULL
  673. <if test="startTime != null and startTime != ''">
  674. AND too.check_time &gt;= #{startTime}
  675. </if>
  676. <if test="endTime != null and endTime != ''">
  677. AND too.check_time &lt;= #{endTime}
  678. </if>
  679. ) + (
  680. SELECT
  681. SUM( o.order_price ) AS money
  682. FROM
  683. `order` o
  684. WHERE
  685. o.`status` = 1
  686. AND o.order_status = 1
  687. AND (
  688. o.input_order_sn IS NULL
  689. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 0 ) AND o.tenant_id IS NOT NULL
  690. <if test="startTime != null and startTime != ''">
  691. AND o.create_time &gt;= #{startTime}
  692. </if>
  693. <if test="endTime != null and endTime != ''">
  694. AND o.create_time &lt;= #{endTime}
  695. </if>
  696. ) money_total
  697. </select>
  698. <select id="getNumStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  699. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">
  700. SELECT
  701. *
  702. FROM
  703. (
  704. SELECT
  705. COUNT(too.order_id) AS orderNum,
  706. too.old_customer_id AS customer_id,
  707. (
  708. SELECT
  709. tod.purchase_org
  710. FROM
  711. top_old_order tod
  712. WHERE
  713. tod.old_customer_id = too.old_customer_id
  714. AND tod.`status` = 1
  715. AND tod.check_status = 1
  716. LIMIT 1
  717. ) AS customer_name
  718. FROM
  719. top_old_order too
  720. WHERE
  721. too.`status` = 1
  722. AND too.check_status = 1
  723. AND too.old_customer_id IS NOT NULL
  724. <if test="startTime != null and startTime != ''">
  725. AND too.check_time &gt;= #{startTime}
  726. </if>
  727. <if test="endTime != null and endTime != ''">
  728. AND too.check_time &lt;= #{endTime}
  729. </if>
  730. <if test="customerId != null and customerId != ''">
  731. AND too.old_customer_id = #{customerId}
  732. </if>
  733. GROUP BY
  734. too.old_customer_id UNION ALL
  735. SELECT
  736. COUNT(o.order_id) AS orderNum,
  737. o.tenant_id AS customer_id,
  738. ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name
  739. FROM
  740. `order` o
  741. WHERE
  742. o.`status` = 1
  743. AND o.order_status = 1
  744. AND (
  745. o.input_order_sn IS NULL
  746. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 0 ) AND o.tenant_id IS NOT NULL
  747. <if test="startTime != null and startTime != ''">
  748. AND o.create_time &gt;= #{startTime}
  749. </if>
  750. <if test="endTime != null and endTime != ''">
  751. AND o.create_time &lt;= #{endTime}
  752. </if>
  753. <if test="customerId != null and customerId != ''">
  754. AND o.tenant_id = #{customerId}
  755. </if>
  756. GROUP BY
  757. o.tenant_id
  758. ) a
  759. WHERE
  760. 1 = 1
  761. ORDER BY
  762. a.orderNum DESC
  763. </select>
  764. <select id="getNumStatisticsTotal" parameterType="java.lang.Long"
  765. resultType="java.lang.Long">
  766. SELECT
  767. (
  768. SELECT
  769. COUNT(too.order_id) AS orderNum
  770. FROM
  771. top_old_order too
  772. WHERE
  773. too.`status` = 1
  774. AND too.check_status = 1
  775. AND too.old_customer_id IS NOT NULL
  776. <if test="startTime != null and startTime != ''">
  777. AND too.check_time &gt;= #{startTime}
  778. </if>
  779. <if test="endTime != null and endTime != ''">
  780. AND too.check_time &lt;= #{endTime}
  781. </if>
  782. ) + (
  783. SELECT
  784. COUNT(o.order_id) AS orderNum
  785. FROM
  786. `order` o
  787. WHERE
  788. o.`status` = 1
  789. AND o.order_status = 1
  790. AND (
  791. o.input_order_sn IS NULL
  792. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 0 ) AND o.tenant_id IS NOT NULL
  793. <if test="startTime != null and startTime != ''">
  794. AND o.create_time &gt;= #{startTime}
  795. </if>
  796. <if test="endTime != null and endTime != ''">
  797. AND o.create_time &lt;= #{endTime}
  798. </if>
  799. ) num_total
  800. </select>
  801. <select id="getTenantStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  802. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">
  803. SELECT
  804. vo.*,
  805. st.tenant_name
  806. FROM
  807. (
  808. SELECT
  809. tenant_id,
  810. SUM( order_price ) total_price
  811. FROM
  812. v_top_order
  813. WHERE
  814. 1 = 1
  815. AND create_time BETWEEN #{startTime}
  816. AND #{endTime}
  817. <if test="tenantId != null and tenantId != ''">
  818. AND tenant_id = #{tenantId}
  819. </if>
  820. GROUP BY
  821. tenant_id
  822. ORDER BY
  823. total_price DESC
  824. ) vo
  825. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  826. </select>
  827. </mapper>