TopOldOrderMapper.xml 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  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 ) = 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 ) = 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 ) = 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 ) = 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="getDetailStatisticsTotal" parameterType="java.lang.Long"
  802. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailTotalVo">
  803. SELECT
  804. ((
  805. SELECT
  806. SUM( too.order_received - too.order_refunded ) AS money
  807. FROM
  808. top_old_order too
  809. WHERE
  810. too.`status` = 1
  811. AND too.check_status = 1
  812. AND too.old_customer_id IS NOT NULL
  813. <if test="startTime != null and startTime != ''">
  814. AND too.check_time &gt;= #{startTime}
  815. </if>
  816. <if test="endTime != null and endTime != ''">
  817. AND too.check_time &lt;= #{endTime}
  818. </if>
  819. ) + (
  820. SELECT
  821. SUM( o.order_price ) AS money
  822. FROM
  823. `order` o
  824. WHERE
  825. o.`status` = 1
  826. AND o.order_status = 1
  827. AND (
  828. o.input_order_sn IS NULL
  829. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL
  830. <if test="startTime != null and startTime != ''">
  831. AND o.create_time &gt;= #{startTime}
  832. </if>
  833. <if test="endTime != null and endTime != ''">
  834. AND o.create_time &lt;= #{endTime}
  835. </if>
  836. )) moneyTotal,
  837. ((
  838. SELECT
  839. COUNT(too.order_id) AS orderNum
  840. FROM
  841. top_old_order too
  842. WHERE
  843. too.`status` = 1
  844. AND too.check_status = 1
  845. AND too.old_customer_id IS NOT NULL
  846. <if test="startTime != null and startTime != ''">
  847. AND too.check_time &gt;= #{startTime}
  848. </if>
  849. <if test="endTime != null and endTime != ''">
  850. AND too.check_time &lt;= #{endTime}
  851. </if>
  852. ) + (
  853. SELECT
  854. COUNT(o.order_id) AS orderNum
  855. FROM
  856. `order` o
  857. WHERE
  858. o.`status` = 1
  859. AND o.order_status = 1
  860. AND (
  861. o.input_order_sn IS NULL
  862. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL
  863. <if test="startTime != null and startTime != ''">
  864. AND o.create_time &gt;= #{startTime}
  865. </if>
  866. <if test="endTime != null and endTime != ''">
  867. AND o.create_time &lt;= #{endTime}
  868. </if>
  869. )) orderNumTotal
  870. </select>
  871. <select id="getStatisticsView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  872. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  873. SELECT
  874. COUNT(a.order_id) AS orderNum,
  875. SUM(a.money) AS money,
  876. any_value(a.timeStr) AS orderTime,
  877. <if test="viewSign != null and viewSign == 1">
  878. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
  879. </if>
  880. <if test="viewSign != null and viewSign == 2">
  881. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
  882. </if>
  883. <if test="viewSign != null and viewSign == 3">
  884. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
  885. </if>
  886. FROM (
  887. SELECT
  888. too.order_id as order_id,
  889. too.check_time as timeStr,
  890. too.order_received - too.order_refunded as money
  891. FROM
  892. top_old_order too
  893. WHERE
  894. too.`status` = 1
  895. AND too.check_status = 1
  896. <if test="startTime != null and startTime != ''">
  897. AND too.check_time &gt;= #{startTime}
  898. </if>
  899. <if test="endTime != null and endTime != ''">
  900. AND too.check_time &lt;= #{endTime}
  901. </if>
  902. <if test="customerId != null and customerId != ''">
  903. AND too.old_customer_id IS NOT NULL
  904. AND too.old_customer_id = #{customerId}
  905. </if>
  906. UNION ALL
  907. SELECT
  908. o.order_id as order_id,
  909. o.create_time as timeStr,
  910. o.order_price as money
  911. FROM
  912. `order` o
  913. WHERE
  914. o.`status` = 1
  915. AND o.order_status = 1
  916. AND (
  917. o.input_order_sn IS NULL
  918. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0
  919. )
  920. <if test="startTime != null and startTime != ''">
  921. AND o.create_time &gt;= #{startTime}
  922. </if>
  923. <if test="endTime != null and endTime != ''">
  924. AND o.create_time &lt;= #{endTime}
  925. </if>
  926. <if test="customerId != null and customerId != ''">
  927. AND o.tenant_id = #{customerId}
  928. AND o.tenant_id IS NOT NULL
  929. </if>
  930. ) a WHERE 1=1
  931. <if test="viewSign != null and viewSign == 1">
  932. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
  933. </if>
  934. <if test="viewSign != null and viewSign == 2">
  935. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
  936. </if>
  937. <if test="viewSign != null and viewSign == 3">
  938. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
  939. </if>
  940. </select>
  941. <select id="getDetailStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  942. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
  943. SELECT
  944. 1 AS orderType,
  945. COUNT(too.order_id) AS orderNum,
  946. SUM( too.order_received - too.order_refunded ) AS money,
  947. too.old_customer_id AS customer_id,
  948. (
  949. SELECT
  950. tod.purchase_org
  951. FROM
  952. top_old_order tod
  953. WHERE
  954. tod.old_customer_id = too.old_customer_id
  955. AND tod.`status` = 1
  956. AND tod.check_status = 1
  957. LIMIT 1
  958. ) AS customer_name
  959. FROM
  960. top_old_order too
  961. WHERE
  962. too.`status` = 1
  963. AND too.check_status = 1
  964. AND too.old_customer_id IS NOT NULL
  965. <if test="startTime != null and startTime != ''">
  966. AND too.check_time &gt;= #{startTime}
  967. </if>
  968. <if test="endTime != null and endTime != ''">
  969. AND too.check_time &lt;= #{endTime}
  970. </if>
  971. <if test="customerId != null and customerId != ''">
  972. AND too.old_customer_id = #{customerId}
  973. </if>
  974. <if test="businessName != null and businessName != ''">
  975. AND (SELECT COUNT(DISTINCT oog.order_sn) FROM top_old_order_goods oog WHERE too.order_sn = oog.order_sn AND INSTR(oog.business_full_name,#{businessName}) ) > 0
  976. </if>
  977. <if test="customerName != null and customerName != ''">
  978. AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
  979. </if>
  980. GROUP BY
  981. too.old_customer_id UNION ALL
  982. SELECT
  983. 2 AS orderType,
  984. COUNT(o.order_id) AS orderNum,
  985. SUM( o.order_price ) AS money,
  986. o.tenant_id AS customer_id,
  987. ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name
  988. FROM
  989. `order` o
  990. WHERE
  991. o.`status` = 1
  992. AND o.order_status = 1
  993. AND (
  994. o.input_order_sn IS NULL
  995. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL
  996. <if test="startTime != null and startTime != ''">
  997. AND o.create_time &gt;= #{startTime}
  998. </if>
  999. <if test="endTime != null and endTime != ''">
  1000. AND o.create_time &lt;= #{endTime}
  1001. </if>
  1002. <if test="customerId != null and customerId != ''">
  1003. AND o.tenant_id = #{customerId}
  1004. </if>
  1005. <if test="businessName != null and businessName != ''">
  1006. AND (
  1007. SELECT
  1008. COUNT(DISTINCT og.order_sn)
  1009. FROM order_goods og
  1010. LEFT JOIN goods g ON og.goods_id = g.goods_id
  1011. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  1012. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  1013. LEFT JOIN course_business cb ON g.business_id = cb.id
  1014. WHERE o.order_sn = og.order_sn
  1015. AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
  1016. </if>
  1017. <if test="customerName != null and customerName != ''">
  1018. AND (SELECT COUNT(s.tenant_id) FROM sys_tenant s WHERE o.tenant_id = s.tenant_id AND s.tenant_name LIKE CONCAT('%',#{customerName},'%')) > 0
  1019. </if>
  1020. GROUP BY
  1021. o.tenant_id
  1022. </select>
  1023. <select id="getTenantStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1024. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">
  1025. SELECT
  1026. vo.*,
  1027. st.tenant_name
  1028. FROM
  1029. (
  1030. SELECT
  1031. tenant_id,
  1032. SUM( order_received - order_refunded ) money
  1033. <if test="tenantId != null and tenantId != ''">
  1034. , create_no,any_value(create_username) as create_username
  1035. </if>
  1036. FROM
  1037. v_top_order
  1038. WHERE
  1039. 1 = 1
  1040. AND `status` = 1
  1041. AND check_status = 1
  1042. AND check_time BETWEEN #{startTime}
  1043. AND #{endTime}
  1044. <if test="tenantId != null and tenantId != ''">
  1045. AND tenant_id = #{tenantId}
  1046. </if>
  1047. GROUP BY
  1048. tenant_id
  1049. <if test="tenantId != null and tenantId != ''">
  1050. , create_no
  1051. </if>
  1052. ORDER BY
  1053. money DESC
  1054. ) vo
  1055. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  1056. </select>
  1057. <select id="getSingleTenantStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1058. resultType="BigDecimal">
  1059. SELECT
  1060. IFNULL(SUM( vo.order_received - vo.order_refunded ),0) money
  1061. FROM
  1062. v_top_order vo
  1063. WHERE
  1064. 1 = 1
  1065. AND vo.`status` = 1
  1066. AND vo.check_status = 1
  1067. AND vo.check_time BETWEEN #{startTime}
  1068. AND #{endTime}
  1069. <if test="tenantId != null and tenantId != ''">
  1070. AND vo.tenant_id = #{tenantId}
  1071. </if>
  1072. <if test="createNo != null and createNo != ''">
  1073. AND vo.create_no = #{createNo}
  1074. </if>
  1075. </select>
  1076. <select id="getTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1077. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">
  1078. SELECT
  1079. vo.*,
  1080. st.tenant_name
  1081. FROM
  1082. (
  1083. SELECT
  1084. tenant_id,
  1085. COUNT( * ) order_num
  1086. <if test="tenantId != null and tenantId != ''">
  1087. , create_no,any_value(create_username) as create_username
  1088. </if>
  1089. FROM
  1090. v_top_order
  1091. WHERE
  1092. 1 = 1
  1093. AND `status` = 1
  1094. AND check_status = 1
  1095. <if test="startTime != null and startTime != ''">
  1096. AND check_time &gt;= #{startTime}
  1097. </if>
  1098. <if test="endTime != null and endTime != ''">
  1099. AND check_time &lt;= #{endTime}
  1100. </if>
  1101. <if test="tenantId != null and tenantId != ''">
  1102. AND tenant_id = #{tenantId}
  1103. </if>
  1104. GROUP BY
  1105. tenant_id
  1106. <if test="tenantId != null and tenantId != ''">
  1107. , create_no
  1108. </if>
  1109. ORDER BY
  1110. order_num DESC
  1111. ) vo
  1112. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  1113. </select>
  1114. <select id="getSingleTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1115. resultType="java.lang.Long">
  1116. SELECT
  1117. IFNULL(COUNT( * ),0)
  1118. FROM
  1119. v_top_order
  1120. WHERE
  1121. 1 = 1
  1122. AND `status` = 1
  1123. AND check_status = 1
  1124. <if test="startTime != null and startTime != ''">
  1125. AND check_time &gt;= #{startTime}
  1126. </if>
  1127. <if test="endTime != null and endTime != ''">
  1128. AND check_time &lt;= #{endTime}
  1129. </if>
  1130. <if test="tenantId != null and tenantId != ''">
  1131. AND tenant_id = #{tenantId}
  1132. </if>
  1133. <if test="createNo != null and createNo != ''">
  1134. AND create_no = #{createNo}
  1135. </if>
  1136. </select>
  1137. <select id="getNumStatisticsTotalWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1138. resultType="java.lang.Long">
  1139. SELECT
  1140. IFNULL(COUNT(*),0)
  1141. FROM
  1142. v_top_order
  1143. WHERE
  1144. `status` = 1
  1145. AND check_status = 1
  1146. <if test="startTime != null and startTime != ''">
  1147. AND check_time &gt;= #{startTime}
  1148. </if>
  1149. <if test="endTime != null and endTime != ''">
  1150. AND check_time &lt;= #{endTime}
  1151. </if>
  1152. <if test="tenantId != null and tenantId != ''">
  1153. AND tenant_id = #{tenantId}
  1154. </if>
  1155. </select>
  1156. <select id="getMoneyStatisticsWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1157. resultType="java.math.BigDecimal">
  1158. SELECT
  1159. IFNULL(SUM( order_received - order_refunded ),0)
  1160. FROM
  1161. v_top_order
  1162. WHERE
  1163. `status` = 1
  1164. AND check_status = 1
  1165. <if test="startTime != null and startTime != ''">
  1166. AND check_time &gt;= #{startTime}
  1167. </if>
  1168. <if test="endTime != null and endTime != ''">
  1169. AND check_time &lt;= #{endTime}
  1170. </if>
  1171. <if test="tenantId != null and tenantId != ''">
  1172. AND tenant_id = #{tenantId}
  1173. </if>
  1174. </select>
  1175. <select id="getOrderTenant" parameterType="java.lang.Long" resultType="java.lang.Long">
  1176. SELECT tenant_id FROM top_old_order WHERE old_customer_id = #{customerId} LIMIT 1
  1177. </select>
  1178. </mapper>