TopOldOrderMapper.xml 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485
  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="purchaseOrg != null and purchaseOrg != ''">
  123. AND vto.purchase_org LIKE CONCAT( '%', #{purchaseOrg}, '%' )
  124. </if>
  125. <if test="createSysUserId != null and createSysUserId != ''">
  126. AND vto.create_sys_user_id LIKE CONCAT( '%', #{createNo}, '%' )
  127. </if>
  128. <if test="startTime != null and startTime != ''">
  129. AND vto.buy_time <![CDATA[ >= ]]> #{startTime}
  130. </if>
  131. <if test="endTime != null and endTime != ''">
  132. AND vto.buy_time <![CDATA[ <= ]]> #{endTime}
  133. </if>
  134. <if test="checkStartTime != null and checkStartTime != ''">
  135. AND vto.check_time <![CDATA[ >= ]]> #{checkStartTime}
  136. </if>
  137. <if test="checkEndTime != null and checkEndTime != ''">
  138. AND vto.check_time <![CDATA[ <= ]]> #{checkEndTime}
  139. </if>
  140. <if test="orderSn != null and orderSn != ''">
  141. AND vto.order_sn = #{orderSn}
  142. </if>
  143. <if test="repairSign != null and repairSign != '' and repairSign == 1">
  144. AND vto.repair_money_total <![CDATA[ > ]]> 0
  145. </if>
  146. <if test="tenantId != null and tenantId != ''">
  147. AND vto.tenant_id = #{tenantId}
  148. </if>
  149. <if test="orderSnList != null and orderSnList.size()!=0 ">
  150. AND vto.order_sn in
  151. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  152. #{item}
  153. </foreach>
  154. </if>
  155. <if test="keyword != null and keyword != ''">
  156. AND (
  157. vto.order_sn LIKE CONCAT( '%', #{keyword}, '%' )
  158. OR vto.create_no LIKE CONCAT( '%', #{keyword}, '%' )
  159. OR vto.purchase_org LIKE CONCAT( '%', #{keyword}, '%' ))
  160. </if>
  161. order by vto.create_time DESC
  162. </select>
  163. <select id="queryList_COUNT" resultType="Long">
  164. SELECT
  165. ((SELECT
  166. COUNT( DISTINCT ot.order_sn ) AS num
  167. FROM
  168. top_old_order ot
  169. LEFT JOIN top_old_order_goods otg ON ot.order_sn = otg.order_sn
  170. WHERE
  171. 1 = 1 AND ot.`status` = 1
  172. <if test="businessFullName != null and businessFullName != ''">
  173. AND INSTR( otg.business_full_name , #{businessFullName} ) > 0
  174. </if>
  175. <if test="userCard != null and userCard != ''">
  176. AND otg.user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  177. </if>
  178. <if test="operationType != null">
  179. AND ot.operation_type = #{operationType}
  180. </if>
  181. <if test="userName != null and userName != ''">
  182. AND otg.user_name LIKE CONCAT( '%', #{userName}, '%' )
  183. </if>
  184. <if test="checkStatus != null and checkStatus.size()!=0 ">
  185. AND ot.check_status in
  186. <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">
  187. #{item}
  188. </foreach>
  189. </if>
  190. <if test="refundStatus != null">
  191. AND ot.refund_status = #{refundStatus}
  192. </if>
  193. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  194. AND ot.refund_status in
  195. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  196. #{item}
  197. </foreach>
  198. </if>
  199. <if test="orderOrg != null and orderOrg != ''">
  200. AND ot.order_org LIKE CONCAT( '%', #{orderOrg}, '%' )
  201. </if>
  202. <if test="purchaseOrg != null and purchaseOrg != ''">
  203. AND vto.purchase_org LIKE CONCAT( '%', #{purchaseOrg}, '%' )
  204. </if>
  205. <if test="createNo != null and createNo != ''">
  206. AND vto.create_no LIKE CONCAT( '%', #{createNo}, '%' )
  207. </if>
  208. <if test="checkStartTime != null and checkStartTime != ''">
  209. AND ot.check_time <![CDATA[ >= ]]> #{checkStartTime}
  210. </if>
  211. <if test="checkEndTime != null and checkEndTime != ''">
  212. AND ot.check_time <![CDATA[ <= ]]> #{checkEndTime}
  213. </if>
  214. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  215. AND ot.order_received <![CDATA[ < ]]> ot.pay_price
  216. </if>
  217. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  218. AND ot.pay_price = ot.order_received
  219. </if>
  220. <if test="invoiceStatus != null and invoiceStatus != ''">
  221. AND ot.invoice_status = #{invoiceStatus}
  222. </if>
  223. <if test="startTime != null and startTime != ''">
  224. AND ot.create_time <![CDATA[ >= ]]> #{startTime}
  225. </if>
  226. <if test="endTime != null and endTime != ''">
  227. AND ot.create_time <![CDATA[ <= ]]> #{endTime}
  228. </if>
  229. <if test="repairSign != null and repairSign != '' and repairSign == 1">
  230. AND ot.repair_money_total <![CDATA[ > ]]> 0
  231. </if>
  232. <if test="orderSn != null and orderSn != ''">
  233. AND ot.order_sn = #{orderSn}
  234. </if>
  235. <if test="finishStatus != null">
  236. AND ot.finish_status = #{finishStatus}
  237. </if>
  238. <if test="tenantId != null and tenantId != ''">
  239. AND ot.tenant_id = #{tenantId}
  240. </if>
  241. <if test="orderSnList != null and orderSnList.size()!=0 ">
  242. AND ot.order_sn in
  243. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  244. #{item}
  245. </foreach>
  246. </if>
  247. <if test="keyword != null and keyword != ''">
  248. AND (
  249. ot.order_sn LIKE CONCAT( '%', #{keyword}, '%' )
  250. OR ot.create_no LIKE CONCAT( '%', #{keyword}, '%' )
  251. OR ot.purchase_org LIKE CONCAT( '%', #{keyword}, '%' ))
  252. </if>
  253. ) + (SELECT
  254. COUNT( DISTINCT o.order_sn ) AS num
  255. FROM
  256. `order` o
  257. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  258. LEFT JOIN `user` u ON o.user_id = u.user_id
  259. WHERE
  260. 1 = 1 AND o.`status` IN (0,1)
  261. AND ( `o`.`order_type` != 4 )
  262. AND (
  263. isnull( `o`.`input_order_sn` )
  264. OR (
  265. NOT (
  266. `o`.`input_order_sn` IN ( SELECT `top_old_order`.`input_order_sn` FROM `top_old_order` ))))
  267. <if test="businessFullName != null and businessFullName != ''">
  268. AND (
  269. SELECT
  270. COUNT(g.goods_id)
  271. FROM
  272. goods g
  273. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  274. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  275. LEFT JOIN course_business cb ON g.business_id = cb.id
  276. WHERE
  277. og.goods_id = g.goods_id
  278. AND
  279. INSTR( CONCAT('学校业务', cet.education_name, cb.business_name, cpt.project_name),#{businessFullName}) > 0) > 0
  280. </if>
  281. <if test="userCard != null and userCard != ''">
  282. AND u.id_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  283. </if>
  284. <if test="userName != null and userName != ''">
  285. AND u.realname LIKE CONCAT( '%', #{userName}, '%' )
  286. </if>
  287. <if test="checkStatus != null and checkStatus.size()!=0 ">
  288. AND o.check_status in
  289. <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">
  290. #{item}
  291. </foreach>
  292. </if>
  293. <if test="operationType != null">
  294. AND o.operation_type = #{operationType}
  295. </if>
  296. <if test="refundStatus != null">
  297. AND o.order_refund_status = #{refundStatus}
  298. </if>
  299. <if test="refundStatusList != null and refundStatusList.size()!=0 ">
  300. AND o.order_refund_status in
  301. <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">
  302. #{item}
  303. </foreach>
  304. </if>
  305. <if test="orderOrg != null and orderOrg != ''">
  306. AND 'C端云学堂' LIKE CONCAT( '%', #{orderOrg}, '%' )
  307. </if>
  308. <if test="checkStartTime != null and checkStartTime != ''">
  309. AND o.pay_time <![CDATA[ >= ]]> #{checkStartTime}
  310. </if>
  311. <if test="checkEndTime != null and checkEndTime != ''">
  312. AND o.pay_time <![CDATA[ <= ]]> #{checkEndTime}
  313. </if>
  314. <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">
  315. AND o.order_received <![CDATA[ < ]]> o.pay_price
  316. </if>
  317. <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">
  318. AND o.pay_price = o.order_received
  319. </if>
  320. <if test="repairSign != null and repairSign != '' and repairSign == 1">
  321. AND o.order_id = 0
  322. </if>
  323. <if test="invoiceStatus != null and invoiceStatus != ''">
  324. AND o.invoice_status = #{invoiceStatus}
  325. </if>
  326. <if test="finishStatus != null">
  327. AND o.finish_status = #{finishStatus}
  328. </if>
  329. <if test="tenantId != null and tenantId != ''">
  330. AND o.tenant_id = #{tenantId}
  331. </if>
  332. <if test="startTime != null and startTime != ''">
  333. AND o.create_time <![CDATA[ >= ]]> #{startTime}
  334. </if>
  335. <if test="startTime == null">
  336. AND o.create_time <![CDATA[ > ]]> #{filtrationTime}
  337. </if>
  338. <if test="endTime != null and endTime != ''">
  339. AND o.create_time <![CDATA[ <= ]]> #{endTime}
  340. </if>
  341. <if test="orderSn != null and orderSn != ''">
  342. AND o.order_sn = #{orderSn}
  343. </if>
  344. <if test="orderSnList != null and orderSnList.size()!=0 ">
  345. AND o.order_sn in
  346. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  347. #{item}
  348. </foreach>
  349. </if>
  350. <if test="keyword != null and keyword != ''">
  351. AND o.order_sn LIKE CONCAT( '%', #{keyword}, '%' )
  352. </if>
  353. )) as number
  354. </select>
  355. <select id="queryById" parameterType="java.lang.String"
  356. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  357. SELECT *
  358. FROM v_top_order
  359. WHERE order_sn = #{orderSn}
  360. </select>
  361. <select id="queryBusinessBySn" parameterType="java.lang.String" resultType="java.lang.String">
  362. SELECT DISTINCT business_name
  363. FROM v_top_order_business
  364. WHERE order_sn = #{orderSn}
  365. </select>
  366. <select id="queryBusinessFullNameBySn" parameterType="java.lang.String" resultType="java.lang.String">
  367. SELECT DISTINCT business_full_name
  368. FROM top_old_order_goods
  369. WHERE order_sn = #{orderSn}
  370. AND `status` = 1
  371. AND check_status = 1
  372. </select>
  373. <select id="queryByOrderSns" parameterType="java.lang.String"
  374. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  375. SELECT * FROM v_top_order WHERE 1 =1
  376. <if test="orderSnList != null and orderSnList.size()!=0 ">
  377. AND order_sn in
  378. <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">
  379. #{item}
  380. </foreach>
  381. </if>
  382. </select>
  383. <select id="queryReceiveUnSum" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  384. resultType="long">
  385. SELECT
  386. IFNULL(sum(
  387. too.order_uncollected),0)
  388. FROM
  389. top_old_order too
  390. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  391. LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn
  392. where too.check_status=1 AND too.order_uncollected >0
  393. <if test="tenantId != null and tenantId != ''">
  394. AND too.tenant_id = #{tenantId}
  395. </if>
  396. <if test="startTime != null and startTime != ''">
  397. AND too.buy_time <![CDATA[ >= ]]> #{startTime}
  398. </if>
  399. <if test="endTime != null and endTime != ''">
  400. AND too.buy_time <![CDATA[ <= ]]> #{endTime}
  401. </if>
  402. <if test="keyNo != null and keyNo != ''">
  403. AND (st.tenant_name like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  404. </if>
  405. <if test="creditStatus != null and creditStatus != ''">
  406. AND too.credit_status = #{creditStatus}
  407. </if>
  408. <if test="orderSn != null and orderSn != ''">
  409. AND too.order_sn = #{orderSn}
  410. </if>
  411. <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">
  412. AND
  413. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  414. (too.check_time BETWEEN #{item.startTime} and #{item.endTime})
  415. </foreach>
  416. </if>
  417. <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">
  418. AND
  419. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  420. (too.check_time NOT BETWEEN #{item.startTime} and #{item.endTime})
  421. </foreach>
  422. </if>
  423. ORDER BY too.buy_time DESC
  424. </select>
  425. <select id="queryReceiveList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  426. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  427. SELECT
  428. too.*,
  429. st.tenant_name,
  430. rn.id as note_id,
  431. rn.note_type,
  432. rn.day_time,
  433. rn.week_time,
  434. rn.month_time,
  435. rn.last_time,
  436. rn.exceed_type
  437. FROM
  438. top_old_order too
  439. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  440. LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn
  441. where too.check_status=1 AND too.order_uncollected >0
  442. <if test="operationType != null and operationType != ''">
  443. AND too.operation_type = #{operationType}
  444. </if>
  445. <if test="tenantId != null and tenantId != ''">
  446. AND too.tenant_id = #{tenantId}
  447. </if>
  448. <if test="startTime != null and startTime != ''">
  449. AND too.buy_time <![CDATA[ >= ]]> #{startTime}
  450. </if>
  451. <if test="endTime != null and endTime != ''">
  452. AND too.buy_time <![CDATA[ <= ]]> #{endTime}
  453. </if>
  454. <if test="keyNo != null and keyNo != ''">
  455. AND (st.tenant_name like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  456. </if>
  457. <if test="creditStatus != null and creditStatus != ''">
  458. AND too.credit_status = #{creditStatus}
  459. </if>
  460. <if test="orderSn != null and orderSn != ''">
  461. AND too.order_sn = #{orderSn}
  462. </if>
  463. <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">
  464. AND
  465. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  466. (too.check_time BETWEEN #{item.startTime} and #{item.endTime})
  467. </foreach>
  468. </if>
  469. <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">
  470. AND
  471. <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">
  472. (too.check_time NOT BETWEEN #{item.startTime} and #{item.endTime})
  473. </foreach>
  474. </if>
  475. ORDER BY too.buy_time DESC
  476. </select>
  477. <select id="queryDivSellerList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  478. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  479. SELECT
  480. too.*,
  481. st.tenant_name,
  482. r.role_name,
  483. cl.check_status as divide_check_status
  484. FROM
  485. v_top_order too
  486. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  487. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  488. AND cl.check_sign = 1
  489. AND ( too.divide_model + 1 ) = cl.check_from
  490. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  491. where 1=1 AND too.divide_model = 2
  492. <if test="startTime != null and startTime != ''">
  493. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  494. </if>
  495. <if test="endTime != null and endTime != ''">
  496. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  497. </if>
  498. <if test="keyNo != null and keyNo != ''">
  499. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  500. </if>
  501. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  502. AND too.divide_status in
  503. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  504. #{item}
  505. </foreach>
  506. </if>
  507. <if test="divideStatus != null and divideStatus != ''">
  508. AND too.divide_status = #{divideStatus}
  509. </if>
  510. <if test="roleId != null and roleId != ''">
  511. AND cl.role_id = #{roleId}
  512. </if>
  513. ORDER BY too.order_id DESC
  514. </select>
  515. <select id="queryTenantList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  516. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  517. SELECT
  518. too.*,
  519. st.tenant_name,
  520. r.role_name,
  521. cl.check_status as divide_check_status
  522. FROM
  523. top_old_order too
  524. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  525. LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn
  526. AND cl.check_sign = 1
  527. AND ( too.divide_model + 1 ) = cl.check_from
  528. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  529. where 1=1 AND too.divide_model = 1
  530. <if test="startTime != null and startTime != ''">
  531. AND too.create_time <![CDATA[ >= ]]> #{startTime}
  532. </if>
  533. <if test="endTime != null and endTime != ''">
  534. AND too.create_time <![CDATA[ <= ]]> #{endTime}
  535. </if>
  536. <if test="keyNo != null and keyNo != ''">
  537. AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))
  538. </if>
  539. <if test="divideStatusList != null and divideStatusList.size()!=0 ">
  540. AND too.divide_status in
  541. <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">
  542. #{item}
  543. </foreach>
  544. </if>
  545. <if test="divideStatus != null and divideStatus != ''">
  546. AND too.divide_status = #{divideStatus}
  547. </if>
  548. <if test="tenantId != null and tenantId != ''">
  549. AND too.tenant_id = #{tenantId}
  550. </if>
  551. <if test="roleId != null and roleId != ''">
  552. AND cl.role_id = #{roleId}
  553. </if>
  554. ORDER BY too.order_id DESC
  555. </select>
  556. <select id="tenantMoneyTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  557. resultType="BigDecimal">
  558. SELECT IFNULL(SUM(too.divide_company_money), 0)
  559. FROM v_top_order too
  560. WHERE too.divide_model = 1
  561. AND too.divide_status = 5
  562. </select>
  563. <select id="tenantSellerTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"
  564. resultType="BigDecimal">
  565. SELECT IFNULL(SUM(too.divide_seller_money), 0)
  566. FROM v_top_order too
  567. WHERE too.divide_model = 2
  568. AND too.divide_status = 5
  569. </select>
  570. <select id="queryListAll" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">
  571. SELECT *
  572. FROM v_top_order
  573. </select>
  574. <select id="getOrderBySn" parameterType="java.lang.String"
  575. resultType="com.zhongzheng.modules.top.goods.domain.TopOldOrder">
  576. SELECT *
  577. FROM v_top_order
  578. WHERE order_sn = #{orderSn}
  579. </select>
  580. <select id="logList" parameterType="com.zhongzheng.modules.top.financial.bo.TopOrderLogQueryBo"
  581. resultType="com.zhongzheng.modules.top.financial.vo.TopOrderLogVo">
  582. SELECT *
  583. FROM top_order_log
  584. WHERE order_sn = #{orderSn}
  585. </select>
  586. <select id="getRefundOrder" parameterType="java.lang.String"
  587. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  588. SELECT *
  589. FROM v_top_order_refund
  590. WHERE order_sn = #{orderSn}
  591. </select>
  592. <select id="getRefundOrderByBo" parameterType="com.zhongzheng.modules.top.financial.bo.RefundOrderBo"
  593. resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">
  594. SELECT * FROM v_top_order_refund WHERE order_sn = #{orderSn} AND status = 1
  595. <if test="periodStatus != null and periodStatus != ''">
  596. AND period_status = #{periodStatus}
  597. </if>
  598. </select>
  599. <select id="getOrderSnByBusiness" parameterType="java.lang.String" resultType="java.lang.String">
  600. SELECT DISTINCT order_sn
  601. FROM v_top_order_business
  602. WHERE INSTR(business_full_name, #{businessName}) > 0
  603. </select>
  604. <select id="getOrderInvoiceList" parameterType="com.zhongzheng.modules.top.goods.vo.TopOldOrderInvoiceVo" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderInvoiceVo">
  605. SELECT
  606. create_time AS applyUpTime,
  607. `status` AS invoiceStatus,
  608. update_time AS invoiceTime,
  609. oss_pdf_url AS ossPdfUrl,
  610. content
  611. FROM
  612. top_nuo_mplatform_log
  613. WHERE
  614. INSTR(order_no_list,#{orderSn})
  615. </select>
  616. <select id="getMoneyStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  617. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">
  618. SELECT
  619. *
  620. FROM
  621. (
  622. SELECT
  623. SUM( too.order_received - too.order_refunded ) AS money,
  624. too.old_customer_id AS customer_id,
  625. (
  626. SELECT
  627. tod.purchase_org
  628. FROM
  629. top_old_order tod
  630. WHERE
  631. tod.old_customer_id = too.old_customer_id
  632. AND tod.`status` = 1
  633. AND tod.check_status = 1
  634. LIMIT 1
  635. ) AS customer_name
  636. FROM
  637. top_old_order too
  638. WHERE
  639. too.`status` = 1
  640. AND too.check_status = 1
  641. AND too.old_customer_id IS NOT NULL
  642. <if test="startTime != null and startTime != ''">
  643. AND too.check_time &gt;= #{startTime}
  644. </if>
  645. <if test="endTime != null and endTime != ''">
  646. AND too.check_time &lt;= #{endTime}
  647. </if>
  648. <if test="customerId != null and customerId != ''">
  649. AND too.old_customer_id = #{customerId}
  650. </if>
  651. <if test="tenantId != null and tenantId != ''">
  652. AND too.tenant_id = #{tenantId}
  653. </if>
  654. <if test="businessName != null and businessName != ''">
  655. 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
  656. </if>
  657. <if test="customerName != null and customerName != ''">
  658. AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
  659. </if>
  660. GROUP BY
  661. too.old_customer_id UNION ALL
  662. SELECT
  663. SUM( o.pay_price ) AS money,
  664. o.tenant_id AS customer_id,
  665. ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name
  666. FROM
  667. `order` o
  668. WHERE
  669. o.`status` = 1
  670. AND o.order_status = 1
  671. AND (
  672. o.input_order_sn IS NULL
  673. 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
  674. <if test="startTime != null and startTime != ''">
  675. AND o.create_time &gt;= #{startTime}
  676. </if>
  677. <if test="endTime != null and endTime != ''">
  678. AND o.create_time &lt;= #{endTime}
  679. </if>
  680. <if test="customerId != null and customerId != ''">
  681. AND o.tenant_id = #{customerId}
  682. </if>
  683. <if test="businessName != null and businessName != ''">
  684. AND (
  685. SELECT
  686. COUNT(DISTINCT og.order_sn)
  687. FROM order_goods og
  688. LEFT JOIN goods g ON og.goods_id = g.goods_id
  689. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  690. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  691. LEFT JOIN course_business cb ON g.business_id = cb.id
  692. WHERE o.order_sn = og.order_sn
  693. AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
  694. </if>
  695. <if test="tenantId != null and tenantId != ''">
  696. AND o.tenant_id = #{tenantId}
  697. </if>
  698. <if test="customerName != null and customerName != ''">
  699. 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
  700. </if>
  701. GROUP BY
  702. o.tenant_id
  703. ) a
  704. WHERE
  705. 1 = 1
  706. ORDER BY
  707. a.money DESC
  708. </select>
  709. <select id="getMoneyStatisticsTotal" parameterType="java.lang.Long"
  710. resultType="java.math.BigDecimal">
  711. SELECT
  712. (
  713. SELECT
  714. SUM( too.order_received - too.order_refunded ) AS money
  715. FROM
  716. top_old_order too
  717. WHERE
  718. too.`status` = 1
  719. AND too.check_status = 1
  720. AND too.old_customer_id IS NOT NULL
  721. <if test="startTime != null and startTime != ''">
  722. AND too.check_time &gt;= #{startTime}
  723. </if>
  724. <if test="endTime != null and endTime != ''">
  725. AND too.check_time &lt;= #{endTime}
  726. </if>
  727. ) + (
  728. SELECT
  729. SUM( o.pay_price ) AS money
  730. FROM
  731. `order` o
  732. WHERE
  733. o.`status` = 1
  734. AND o.order_status = 1
  735. AND (
  736. o.input_order_sn IS NULL
  737. 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
  738. <if test="startTime != null and startTime != ''">
  739. AND o.create_time &gt;= #{startTime}
  740. </if>
  741. <if test="endTime != null and endTime != ''">
  742. AND o.create_time &lt;= #{endTime}
  743. </if>
  744. ) money_total
  745. </select>
  746. <select id="getNumStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  747. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">
  748. SELECT
  749. *
  750. FROM
  751. (
  752. SELECT
  753. COUNT(too.order_id) AS orderNum,
  754. too.old_customer_id AS customer_id,
  755. (
  756. SELECT
  757. tod.purchase_org
  758. FROM
  759. top_old_order tod
  760. WHERE
  761. tod.old_customer_id = too.old_customer_id
  762. AND tod.`status` = 1
  763. AND tod.check_status = 1
  764. LIMIT 1
  765. ) AS customer_name
  766. FROM
  767. top_old_order too
  768. WHERE
  769. too.`status` = 1
  770. AND too.check_status = 1
  771. AND too.old_customer_id IS NOT NULL
  772. <if test="startTime != null and startTime != ''">
  773. AND too.check_time &gt;= #{startTime}
  774. </if>
  775. <if test="endTime != null and endTime != ''">
  776. AND too.check_time &lt;= #{endTime}
  777. </if>
  778. <if test="customerId != null and customerId != ''">
  779. AND too.old_customer_id = #{customerId}
  780. </if>
  781. <if test="tenantId != null and tenantId != ''">
  782. AND too.tenant_id = #{tenantId}
  783. </if>
  784. <if test="businessName != null and businessName != ''">
  785. 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
  786. </if>
  787. <if test="customerName != null and customerName != ''">
  788. AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
  789. </if>
  790. GROUP BY
  791. too.old_customer_id UNION ALL
  792. SELECT
  793. COUNT(o.order_id) AS orderNum,
  794. o.tenant_id AS customer_id,
  795. ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name
  796. FROM
  797. `order` o
  798. WHERE
  799. o.`status` = 1
  800. AND o.order_status = 1
  801. AND (
  802. o.input_order_sn IS NULL
  803. 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
  804. <if test="startTime != null and startTime != ''">
  805. AND o.create_time &gt;= #{startTime}
  806. </if>
  807. <if test="endTime != null and endTime != ''">
  808. AND o.create_time &lt;= #{endTime}
  809. </if>
  810. <if test="customerId != null and customerId != ''">
  811. AND o.tenant_id = #{customerId}
  812. </if>
  813. <if test="businessName != null and businessName != ''">
  814. AND (
  815. SELECT
  816. COUNT(DISTINCT og.order_sn)
  817. FROM order_goods og
  818. LEFT JOIN goods g ON og.goods_id = g.goods_id
  819. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  820. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  821. LEFT JOIN course_business cb ON g.business_id = cb.id
  822. WHERE o.order_sn = og.order_sn
  823. AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
  824. </if>
  825. <if test="tenantId != null and tenantId != ''">
  826. AND o.tenant_id = #{tenantId}
  827. </if>
  828. <if test="customerName != null and customerName != ''">
  829. 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
  830. </if>
  831. GROUP BY
  832. o.tenant_id
  833. ) a
  834. WHERE
  835. 1 = 1
  836. ORDER BY
  837. a.orderNum DESC
  838. </select>
  839. <select id="getNumStatisticsTotal" parameterType="java.lang.Long"
  840. resultType="java.lang.Long">
  841. SELECT
  842. (
  843. SELECT
  844. COUNT(too.order_id) AS orderNum
  845. FROM
  846. top_old_order too
  847. WHERE
  848. too.`status` = 1
  849. AND too.check_status = 1
  850. AND too.old_customer_id IS NOT NULL
  851. <if test="startTime != null and startTime != ''">
  852. AND too.check_time &gt;= #{startTime}
  853. </if>
  854. <if test="endTime != null and endTime != ''">
  855. AND too.check_time &lt;= #{endTime}
  856. </if>
  857. ) + (
  858. SELECT
  859. COUNT(o.order_id) AS orderNum
  860. FROM
  861. `order` o
  862. WHERE
  863. o.`status` = 1
  864. AND o.order_status = 1
  865. AND (
  866. o.input_order_sn IS NULL
  867. 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
  868. <if test="startTime != null and startTime != ''">
  869. AND o.create_time &gt;= #{startTime}
  870. </if>
  871. <if test="endTime != null and endTime != ''">
  872. AND o.create_time &lt;= #{endTime}
  873. </if>
  874. ) num_total
  875. </select>
  876. <select id="getDetailStatisticsTotal" parameterType="com.zhongzheng.modules.top.order.bo.TopDetailStatisticsTotal"
  877. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailTotalVo">
  878. SELECT
  879. ((
  880. SELECT
  881. IFNULL(SUM( too.order_received - too.order_refunded ),0) AS money
  882. FROM
  883. top_old_order too
  884. WHERE
  885. too.`status` = 1
  886. AND too.check_status = 1
  887. AND too.old_customer_id IS NOT NULL
  888. <if test="startTime != null and startTime != ''">
  889. AND too.check_time &gt;= #{startTime}
  890. </if>
  891. <if test="endTime != null and endTime != ''">
  892. AND too.check_time &lt;= #{endTime}
  893. </if>
  894. <if test="customerId != null and customerId != ''">
  895. AND too.old_customer_id = #{customerId}
  896. </if>
  897. <if test="tenantId != null and tenantId != ''">
  898. AND too.tenant_id = #{tenantId}
  899. </if>
  900. <if test="businessName != null and businessName != ''">
  901. 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
  902. </if>
  903. <if test="customerName != null and customerName != ''">
  904. AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
  905. </if>
  906. ) + (
  907. SELECT
  908. IFNULL(SUM( o.pay_price ),0) AS money
  909. FROM
  910. `order` o
  911. WHERE
  912. o.`status` = 1
  913. AND o.order_status = 1
  914. AND (
  915. o.input_order_sn IS NULL
  916. 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
  917. <if test="startTime != null and startTime != ''">
  918. AND o.create_time &gt;= #{startTime}
  919. </if>
  920. <if test="endTime != null and endTime != ''">
  921. AND o.create_time &lt;= #{endTime}
  922. </if>
  923. <if test="customerId != null and customerId != ''">
  924. AND o.tenant_id = #{customerId}
  925. </if>
  926. <if test="businessName != null and businessName != ''">
  927. AND (
  928. SELECT
  929. COUNT(DISTINCT og.order_sn)
  930. FROM order_goods og
  931. LEFT JOIN goods g ON og.goods_id = g.goods_id
  932. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  933. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  934. LEFT JOIN course_business cb ON g.business_id = cb.id
  935. WHERE o.order_sn = og.order_sn
  936. AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
  937. </if>
  938. <if test="tenantId != null and tenantId != ''">
  939. AND o.tenant_id = #{tenantId}
  940. </if>
  941. <if test="customerName != null and customerName != ''">
  942. 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
  943. </if>
  944. )) moneyTotal,
  945. ((
  946. SELECT
  947. COUNT(too.order_id) AS orderNum
  948. FROM
  949. top_old_order too
  950. WHERE
  951. too.`status` = 1
  952. AND too.check_status = 1
  953. AND too.old_customer_id IS NOT NULL
  954. <if test="startTime != null and startTime != ''">
  955. AND too.check_time &gt;= #{startTime}
  956. </if>
  957. <if test="endTime != null and endTime != ''">
  958. AND too.check_time &lt;= #{endTime}
  959. </if>
  960. <if test="customerId != null and customerId != ''">
  961. AND too.old_customer_id = #{customerId}
  962. </if>
  963. <if test="tenantId != null and tenantId != ''">
  964. AND too.tenant_id = #{tenantId}
  965. </if>
  966. <if test="businessName != null and businessName != ''">
  967. 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
  968. </if>
  969. <if test="customerName != null and customerName != ''">
  970. AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
  971. </if>
  972. ) + (
  973. SELECT
  974. COUNT(o.order_id) AS orderNum
  975. FROM
  976. `order` o
  977. WHERE
  978. o.`status` = 1
  979. AND o.order_status = 1
  980. AND (
  981. o.input_order_sn IS NULL
  982. 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
  983. <if test="startTime != null and startTime != ''">
  984. AND o.create_time &gt;= #{startTime}
  985. </if>
  986. <if test="endTime != null and endTime != ''">
  987. AND o.create_time &lt;= #{endTime}
  988. </if>
  989. <if test="customerId != null and customerId != ''">
  990. AND o.tenant_id = #{customerId}
  991. </if>
  992. <if test="businessName != null and businessName != ''">
  993. AND (
  994. SELECT
  995. COUNT(DISTINCT og.order_sn)
  996. FROM order_goods og
  997. LEFT JOIN goods g ON og.goods_id = g.goods_id
  998. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  999. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  1000. LEFT JOIN course_business cb ON g.business_id = cb.id
  1001. WHERE o.order_sn = og.order_sn
  1002. AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
  1003. </if>
  1004. <if test="tenantId != null and tenantId != ''">
  1005. AND o.tenant_id = #{tenantId}
  1006. </if>
  1007. <if test="customerName != null and customerName != ''">
  1008. 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
  1009. </if>
  1010. )) orderNumTotal
  1011. </select>
  1012. <select id="getStatisticsView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  1013. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  1014. SELECT
  1015. COUNT(a.order_id) AS orderNum,
  1016. SUM(a.money) AS money,
  1017. any_value(a.timeStr) AS orderTime,
  1018. <if test="viewSign != null and viewSign == 1">
  1019. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
  1020. </if>
  1021. <if test="viewSign != null and viewSign == 2">
  1022. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
  1023. </if>
  1024. <if test="viewSign != null and viewSign == 3">
  1025. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
  1026. </if>
  1027. FROM (
  1028. SELECT
  1029. too.order_id as order_id,
  1030. too.check_time as timeStr,
  1031. too.order_received - too.order_refunded as money
  1032. FROM
  1033. top_old_order too
  1034. WHERE
  1035. too.`status` = 1
  1036. AND too.check_status = 1
  1037. <if test="startTime != null and startTime != ''">
  1038. AND too.check_time &gt;= #{startTime}
  1039. </if>
  1040. <if test="endTime != null and endTime != ''">
  1041. AND too.check_time &lt;= #{endTime}
  1042. </if>
  1043. <if test="customerId != null and customerId != ''">
  1044. AND too.old_customer_id IS NOT NULL
  1045. AND too.old_customer_id = #{customerId}
  1046. </if>
  1047. UNION ALL
  1048. SELECT
  1049. o.order_id as order_id,
  1050. o.create_time as timeStr,
  1051. o.pay_price as money
  1052. FROM
  1053. `order` o
  1054. WHERE
  1055. o.`status` = 1
  1056. AND o.order_status = 1
  1057. AND (
  1058. o.input_order_sn IS NULL
  1059. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0
  1060. )
  1061. <if test="startTime != null and startTime != ''">
  1062. AND o.create_time &gt;= #{startTime}
  1063. </if>
  1064. <if test="endTime != null and endTime != ''">
  1065. AND o.create_time &lt;= #{endTime}
  1066. </if>
  1067. <if test="customerId != null and customerId != ''">
  1068. AND o.tenant_id = #{customerId}
  1069. AND o.tenant_id IS NOT NULL
  1070. </if>
  1071. ) a WHERE 1=1
  1072. <if test="viewSign != null and viewSign == 1">
  1073. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
  1074. </if>
  1075. <if test="viewSign != null and viewSign == 2">
  1076. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
  1077. </if>
  1078. <if test="viewSign != null and viewSign == 3">
  1079. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
  1080. </if>
  1081. </select>
  1082. <select id="getDetailStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  1083. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
  1084. SELECT
  1085. 1 AS orderType,
  1086. COUNT(too.order_id) AS orderNum,
  1087. SUM( too.order_received - too.order_refunded ) AS money,
  1088. too.old_customer_id AS customer_id,
  1089. (
  1090. SELECT
  1091. tod.purchase_org
  1092. FROM
  1093. top_old_order tod
  1094. WHERE
  1095. tod.old_customer_id = too.old_customer_id
  1096. AND tod.`status` = 1
  1097. AND tod.check_status = 1
  1098. LIMIT 1
  1099. ) AS customer_name
  1100. FROM
  1101. top_old_order too
  1102. WHERE
  1103. too.`status` = 1
  1104. AND too.check_status = 1
  1105. AND too.old_customer_id IS NOT NULL
  1106. <if test="startTime != null and startTime != ''">
  1107. AND too.check_time &gt;= #{startTime}
  1108. </if>
  1109. <if test="endTime != null and endTime != ''">
  1110. AND too.check_time &lt;= #{endTime}
  1111. </if>
  1112. <if test="customerId != null and customerId != ''">
  1113. AND too.old_customer_id = #{customerId}
  1114. </if>
  1115. <if test="tenantId != null and tenantId != ''">
  1116. AND too.tenant_id = #{tenantId}
  1117. </if>
  1118. <if test="businessName != null and businessName != ''">
  1119. 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
  1120. </if>
  1121. <if test="customerName != null and customerName != ''">
  1122. AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')
  1123. </if>
  1124. GROUP BY
  1125. too.old_customer_id UNION ALL
  1126. SELECT
  1127. 2 AS orderType,
  1128. COUNT(o.order_id) AS orderNum,
  1129. SUM( o.pay_price ) AS money,
  1130. o.tenant_id AS customer_id,
  1131. ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name
  1132. FROM
  1133. `order` o
  1134. WHERE
  1135. o.`status` = 1
  1136. AND o.order_status = 1
  1137. AND (
  1138. o.input_order_sn IS NULL
  1139. 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
  1140. <if test="startTime != null and startTime != ''">
  1141. AND o.create_time &gt;= #{startTime}
  1142. </if>
  1143. <if test="endTime != null and endTime != ''">
  1144. AND o.create_time &lt;= #{endTime}
  1145. </if>
  1146. <if test="customerId != null and customerId != ''">
  1147. AND o.tenant_id = #{customerId}
  1148. </if>
  1149. <if test="businessName != null and businessName != ''">
  1150. AND (
  1151. SELECT
  1152. COUNT(DISTINCT og.order_sn)
  1153. FROM order_goods og
  1154. LEFT JOIN goods g ON og.goods_id = g.goods_id
  1155. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  1156. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  1157. LEFT JOIN course_business cb ON g.business_id = cb.id
  1158. WHERE o.order_sn = og.order_sn
  1159. AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0
  1160. </if>
  1161. <if test="tenantId != null and tenantId != ''">
  1162. AND o.tenant_id = #{tenantId}
  1163. </if>
  1164. <if test="customerName != null and customerName != ''">
  1165. 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
  1166. </if>
  1167. GROUP BY
  1168. o.tenant_id
  1169. </select>
  1170. <select id="getTenantStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1171. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">
  1172. SELECT
  1173. vo.*,
  1174. st.tenant_name
  1175. FROM
  1176. (
  1177. SELECT
  1178. allu.tenant_id,
  1179. SUM( allu.money2 ) money
  1180. <if test="tenantId != null and tenantId != ''">
  1181. , allu.create_sys_user_id,allu.create_username
  1182. </if>
  1183. FROM
  1184. (
  1185. SELECT
  1186. tenant_id,
  1187. SUM( order_received - order_refunded ) money2
  1188. <if test="tenantId != null and tenantId != ''">
  1189. , create_sys_user_id,any_value(create_username) as create_username
  1190. </if>
  1191. FROM
  1192. top_old_order
  1193. WHERE
  1194. 1 = 1
  1195. AND `status` = 1
  1196. AND check_status = 1
  1197. AND old_customer_id IS NOT NULL
  1198. <if test="startTime != null and startTime != ''">
  1199. AND check_time &gt;= #{startTime}
  1200. </if>
  1201. <if test="endTime != null and endTime != ''">
  1202. AND check_time &lt;= #{endTime}
  1203. </if>
  1204. <if test="tenantId != null and tenantId != ''">
  1205. AND tenant_id = #{tenantId}
  1206. </if>
  1207. <if test="customerId != null and customerId != ''">
  1208. AND tenant_id = #{customerId}
  1209. </if>
  1210. GROUP BY
  1211. tenant_id
  1212. <if test="tenantId != null and tenantId != ''">
  1213. , create_sys_user_id
  1214. </if>
  1215. UNION ALL
  1216. SELECT
  1217. og.tenant_id,
  1218. IFNULL( SUM( og.goods_received ), 0 ) money2
  1219. <if test="tenantId != null and tenantId != ''">
  1220. ,'' AS create_sys_user_id, '' as create_username
  1221. </if>
  1222. FROM
  1223. `order` o
  1224. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1225. WHERE
  1226. o.`status` = 1
  1227. AND o.order_status = 1
  1228. AND og.refund_status != 2
  1229. AND (
  1230. o.input_order_sn IS NULL
  1231. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1232. <if test="startTime != null and startTime != ''">
  1233. AND o.create_time &gt;= #{startTime}
  1234. </if>
  1235. <if test="endTime != null and endTime != ''">
  1236. AND o.create_time &lt;= #{endTime}
  1237. </if>
  1238. <if test="tenantId != null and tenantId != ''">
  1239. AND o.tenant_id = #{tenantId}
  1240. </if>
  1241. <if test="customerId != null and customerId != ''">
  1242. AND o.tenant_id = #{customerId}
  1243. </if>
  1244. AND og.pay_status != 1
  1245. GROUP BY
  1246. og.tenant_id
  1247. ) allu
  1248. GROUP BY
  1249. allu.tenant_id
  1250. <if test="tenantId != null and tenantId != ''">
  1251. , allu.create_sys_user_id,allu.create_username
  1252. </if>
  1253. ORDER BY
  1254. money DESC
  1255. ) vo
  1256. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  1257. </select>
  1258. <select id="getSingleTenantStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1259. resultType="BigDecimal">
  1260. SELECT
  1261. (IFNULL(SUM( vo.order_received - vo.order_refunded ),0)+(
  1262. SELECT
  1263. IFNULL(SUM( og.goods_received ),0)
  1264. FROM
  1265. `order` o
  1266. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1267. WHERE
  1268. o.`status` = 1
  1269. AND o.order_status = 1
  1270. AND og.refund_status != 2
  1271. AND og.pay_status != 1
  1272. AND (
  1273. o.input_order_sn IS NULL
  1274. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1275. <if test="startTime != null and startTime != ''">
  1276. AND o.create_time &gt;= #{startTime}
  1277. </if>
  1278. <if test="endTime != null and endTime != ''">
  1279. AND o.create_time &lt;= #{endTime}
  1280. </if>
  1281. <if test="tenantId != null and tenantId != ''">
  1282. AND o.tenant_id = #{tenantId}
  1283. </if>
  1284. <if test="customerId != null and customerId != ''">
  1285. AND o.tenant_id = #{customerId}
  1286. </if>
  1287. <if test="createSysUserId != null and createSysUserId != ''">
  1288. AND 1=0
  1289. </if>
  1290. <if test="businessName != null and businessName != ''">
  1291. AND (
  1292. SELECT
  1293. count(*)
  1294. FROM
  1295. (
  1296. SELECT
  1297. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1298. g.goods_id
  1299. FROM
  1300. `goods` `g`
  1301. LEFT JOIN `course_education_type` `cet` ON `g`.`education_type_id` = `cet`.`id`
  1302. LEFT JOIN `course_project_type` `cpt` ON `g`.`education_type_id` = `cpt`.`id`
  1303. LEFT JOIN `course_business` `cb` ON `g`.`business_id` = `cb`.`id`
  1304. ) oug
  1305. WHERE
  1306. oug.goods_id = og.goods_id
  1307. AND oug.business_name = #{businessName}
  1308. )>0
  1309. </if>
  1310. )) money
  1311. FROM
  1312. top_old_order vo
  1313. WHERE
  1314. 1 = 1
  1315. AND vo.`status` = 1
  1316. AND vo.check_status = 1
  1317. AND vo.old_customer_id IS NOT NULL
  1318. AND vo.check_time BETWEEN #{startTime}
  1319. AND #{endTime}
  1320. <if test="tenantId != null and tenantId != ''">
  1321. AND vo.tenant_id = #{tenantId}
  1322. </if>
  1323. <if test="createSysUserId != null and createSysUserId != ''">
  1324. AND vo.create_sys_user_id = #{createSysUserId}
  1325. </if>
  1326. <if test="customerId != null and customerId != ''">
  1327. AND vo.tenant_id = #{customerId}
  1328. </if>
  1329. <if test="businessName != null and businessName != ''">
  1330. AND (
  1331. SELECT
  1332. count(*)
  1333. FROM
  1334. (
  1335. SELECT
  1336. `otg`.`order_sn` AS `order_sn`,
  1337. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1338. FROM
  1339. `top_old_order_goods` `otg`
  1340. ) ouu
  1341. WHERE
  1342. ouu.order_sn = vo.order_sn
  1343. AND ouu.business_name = #{businessName}
  1344. ) >0
  1345. </if>
  1346. </select>
  1347. <select id="getTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1348. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">
  1349. SELECT
  1350. vo.*,
  1351. st.tenant_name
  1352. FROM
  1353. (
  1354. SELECT
  1355. allu.tenant_id,
  1356. SUM(order_num2) order_num
  1357. <if test="tenantId != null and tenantId != ''">
  1358. , allu.create_sys_user_id,allu.create_username
  1359. </if>
  1360. FROM
  1361. (
  1362. SELECT
  1363. tenant_id,
  1364. COUNT( * ) order_num2
  1365. <if test="tenantId != null and tenantId != ''">
  1366. , create_sys_user_id,any_value(create_username) as create_username
  1367. </if>
  1368. FROM
  1369. top_old_order
  1370. WHERE
  1371. 1 = 1
  1372. AND `status` = 1
  1373. AND check_status = 1
  1374. AND old_customer_id IS NOT NULL
  1375. <if test="startTime != null and startTime != ''">
  1376. AND check_time &gt;= #{startTime}
  1377. </if>
  1378. <if test="endTime != null and endTime != ''">
  1379. AND check_time &lt;= #{endTime}
  1380. </if>
  1381. <if test="tenantId != null and tenantId != ''">
  1382. AND tenant_id = #{tenantId}
  1383. </if>
  1384. <if test="customerId != null and customerId != ''">
  1385. AND tenant_id = #{customerId}
  1386. </if>
  1387. GROUP BY
  1388. tenant_id
  1389. <if test="tenantId != null and tenantId != ''">
  1390. , create_sys_user_id
  1391. </if>
  1392. UNION ALL
  1393. SELECT
  1394. og.tenant_id,
  1395. COUNT( * ) order_num2
  1396. <if test="tenantId != null and tenantId != ''">
  1397. ,'' AS create_sys_user_id, '' as create_username
  1398. </if>
  1399. FROM
  1400. `order` o
  1401. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1402. WHERE
  1403. o.`status` = 1
  1404. AND o.order_status = 1
  1405. AND og.refund_status != 2
  1406. AND (
  1407. o.input_order_sn IS NULL
  1408. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1409. <if test="startTime != null and startTime != ''">
  1410. AND o.create_time &gt;= #{startTime}
  1411. </if>
  1412. <if test="endTime != null and endTime != ''">
  1413. AND o.create_time &lt;= #{endTime}
  1414. </if>
  1415. <if test="tenantId != null and tenantId != ''">
  1416. AND o.tenant_id = #{tenantId}
  1417. </if>
  1418. <if test="customerId != null and customerId != ''">
  1419. AND o.tenant_id = #{customerId}
  1420. </if>
  1421. AND og.pay_status != 1
  1422. GROUP BY
  1423. og.tenant_id
  1424. ) allu
  1425. GROUP BY
  1426. allu.tenant_id
  1427. <if test="tenantId != null and tenantId != ''">
  1428. , allu.create_sys_user_id,allu.create_username
  1429. </if>
  1430. ORDER BY
  1431. order_num DESC
  1432. ) vo
  1433. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  1434. </select>
  1435. <select id="getSingleTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1436. resultType="java.lang.Long">
  1437. SELECT
  1438. (IFNULL(COUNT( * ),0)+(
  1439. SELECT
  1440. IFNULL(COUNT(o.order_id),0) AS orderNum
  1441. FROM
  1442. `order` o
  1443. WHERE
  1444. o.`status` = 1
  1445. AND o.order_status = 1
  1446. AND (
  1447. o.input_order_sn IS NULL
  1448. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1449. <if test="startTime != null and startTime != ''">
  1450. AND o.create_time &gt;= #{startTime}
  1451. </if>
  1452. <if test="endTime != null and endTime != ''">
  1453. AND o.create_time &lt;= #{endTime}
  1454. </if>
  1455. <if test="tenantId != null and tenantId != ''">
  1456. AND o.tenant_id = #{tenantId}
  1457. </if>
  1458. <if test="customerId != null and customerId != ''">
  1459. AND o.tenant_id = #{customerId}
  1460. </if>
  1461. <if test="createSysUserId != null and createSysUserId != ''">
  1462. AND 1=0
  1463. </if>
  1464. ))
  1465. FROM
  1466. top_old_order
  1467. WHERE
  1468. 1 = 1
  1469. AND `status` = 1
  1470. AND check_status = 1
  1471. AND old_customer_id IS NOT NULL
  1472. <if test="startTime != null and startTime != ''">
  1473. AND check_time &gt;= #{startTime}
  1474. </if>
  1475. <if test="endTime != null and endTime != ''">
  1476. AND check_time &lt;= #{endTime}
  1477. </if>
  1478. <if test="tenantId != null and tenantId != ''">
  1479. AND tenant_id = #{tenantId}
  1480. </if>
  1481. <if test="customerId != null and customerId != ''">
  1482. AND tenant_id = #{customerId}
  1483. </if>
  1484. <if test="createSysUserId != null and createSysUserId != ''">
  1485. AND create_sys_user_id = #{createSysUserId}
  1486. </if>
  1487. </select>
  1488. <select id="getNumStatisticsTotalWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1489. resultType="java.lang.Long">
  1490. SELECT
  1491. (IFNULL(COUNT(too.order_id),0)+(
  1492. SELECT
  1493. IFNULL(COUNT(o.order_id),0) AS orderNum
  1494. FROM
  1495. `order` o
  1496. WHERE
  1497. o.`status` = 1
  1498. AND o.order_status = 1
  1499. AND (
  1500. o.input_order_sn IS NULL
  1501. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1502. <if test="startTime != null and startTime != ''">
  1503. AND o.create_time &gt;= #{startTime}
  1504. </if>
  1505. <if test="endTime != null and endTime != ''">
  1506. AND o.create_time &lt;= #{endTime}
  1507. </if>
  1508. <if test="tenantId != null and tenantId != ''">
  1509. AND o.tenant_id = #{tenantId}
  1510. </if>
  1511. <if test="customerId != null and customerId != ''">
  1512. AND o.tenant_id = #{customerId}
  1513. </if>
  1514. )) AS orderNum
  1515. FROM
  1516. top_old_order too
  1517. WHERE
  1518. too.`status` = 1
  1519. AND too.check_status = 1
  1520. AND too.old_customer_id IS NOT NULL
  1521. <if test="startTime != null and startTime != ''">
  1522. AND too.check_time &gt;= #{startTime}
  1523. </if>
  1524. <if test="endTime != null and endTime != ''">
  1525. AND too.check_time &lt;= #{endTime}
  1526. </if>
  1527. <if test="tenantId != null and tenantId != ''">
  1528. AND too.tenant_id = #{tenantId}
  1529. </if>
  1530. <if test="customerId != null and customerId != ''">
  1531. AND too.tenant_id = #{customerId}
  1532. </if>
  1533. </select>
  1534. <select id="getMoneyStatisticsWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1535. resultType="java.math.BigDecimal">
  1536. SELECT
  1537. IFNULL(SUM( too.order_received - too.order_refunded ),0)+ (
  1538. SELECT
  1539. IFNULL(SUM( og.goods_received ),0) AS money
  1540. FROM
  1541. `order` o
  1542. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1543. WHERE
  1544. o.`status` = 1
  1545. AND o.order_status = 1
  1546. AND og.refund_status != 2
  1547. AND og.pay_status != 1
  1548. AND (
  1549. o.input_order_sn IS NULL
  1550. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1551. <if test="startTime != null and startTime != ''">
  1552. AND o.create_time &gt;= #{startTime}
  1553. </if>
  1554. <if test="endTime != null and endTime != ''">
  1555. AND o.create_time &lt;= #{endTime}
  1556. </if>
  1557. <if test="tenantId != null and tenantId != ''">
  1558. AND o.tenant_id = #{tenantId}
  1559. </if>
  1560. <if test="customerId != null and customerId != ''">
  1561. AND o.tenant_id = #{customerId}
  1562. </if>
  1563. ) AS money
  1564. FROM
  1565. top_old_order too
  1566. WHERE
  1567. too.`status` = 1
  1568. AND too.check_status = 1
  1569. AND too.old_customer_id IS NOT NULL
  1570. <if test="startTime != null and startTime != ''">
  1571. AND too.check_time &gt;= #{startTime}
  1572. </if>
  1573. <if test="endTime != null and endTime != ''">
  1574. AND too.check_time &lt;= #{endTime}
  1575. </if>
  1576. <if test="tenantId != null and tenantId != ''">
  1577. AND too.tenant_id = #{tenantId}
  1578. </if>
  1579. <if test="customerId != null and customerId != ''">
  1580. AND too.old_customer_id = #{customerId}
  1581. </if>
  1582. </select>
  1583. <select id="getBusinessOrderMoney" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1584. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">
  1585. SELECT
  1586. allu.business_name,
  1587. SUM( allu.money ) money
  1588. FROM
  1589. (
  1590. SELECT
  1591. ouu.business_name,
  1592. IFNULL( SUM( oo.order_received - oo.order_refunded ), 0 ) money
  1593. FROM
  1594. (
  1595. SELECT
  1596. ou.order_sn,
  1597. ou.business_name
  1598. FROM
  1599. (
  1600. SELECT
  1601. `otg`.`order_sn` AS `order_sn`,
  1602. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1603. FROM
  1604. `top_old_order_goods` `otg`
  1605. ) ou
  1606. GROUP BY
  1607. ou.order_sn,
  1608. ou.business_name
  1609. ) ouu
  1610. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  1611. WHERE
  1612. oo.`status` = 1
  1613. AND oo.check_status = 1
  1614. AND oo.old_customer_id IS NOT NULL
  1615. <if test="startTime != null and startTime != ''">
  1616. AND oo.check_time &gt;= #{startTime}
  1617. </if>
  1618. <if test="endTime != null and endTime != ''">
  1619. AND oo.check_time &lt;= #{endTime}
  1620. </if>
  1621. <if test="tenantId != null and tenantId != ''">
  1622. AND oo.tenant_id = #{tenantId}
  1623. </if>
  1624. <if test="createSysUserId != null and createSysUserId != ''">
  1625. AND oo.create_sys_user_id = #{createSysUserId}
  1626. </if>
  1627. <if test="businessName != null and businessName != ''">
  1628. AND ouu.business_name = #{businessName}
  1629. </if>
  1630. <if test="customerId != null and customerId != ''">
  1631. AND oo.tenant_id = #{customerId}
  1632. </if>
  1633. GROUP BY
  1634. ouu.business_name UNION ALL
  1635. SELECT
  1636. nou.business_name,
  1637. SUM( nou.goods_received ) AS money
  1638. FROM
  1639. (
  1640. SELECT
  1641. `og`.`order_sn` AS `order_sn`,
  1642. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1643. og.goods_received
  1644. FROM
  1645. ((((
  1646. `order` o
  1647. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1648. LEFT JOIN `goods` `g` ON ((
  1649. `og`.`goods_id` = `g`.`goods_id`
  1650. )))
  1651. LEFT JOIN `course_education_type` `cet` ON ((
  1652. `g`.`education_type_id` = `cet`.`id`
  1653. )))
  1654. LEFT JOIN `course_project_type` `cpt` ON ((
  1655. `g`.`education_type_id` = `cpt`.`id`
  1656. )))
  1657. LEFT JOIN `course_business` `cb` ON ((
  1658. `g`.`business_id` = `cb`.`id`
  1659. )))
  1660. WHERE
  1661. og.pay_status != 1
  1662. AND (
  1663. o.input_order_sn IS NULL
  1664. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1665. <if test="startTime != null and startTime != ''">
  1666. AND og.create_time &gt;= #{startTime}
  1667. </if>
  1668. <if test="endTime != null and endTime != ''">
  1669. AND og.create_time &lt;= #{endTime}
  1670. </if>
  1671. <if test="tenantId != null and tenantId != ''">
  1672. AND og.tenant_id = #{tenantId}
  1673. </if>
  1674. <if test="createSysUserId != null and createSysUserId != ''">
  1675. AND 1=0
  1676. </if>
  1677. <if test="customerId != null and customerId != ''">
  1678. AND og.tenant_id = #{customerId}
  1679. </if>
  1680. AND og.refund_status != 2
  1681. ) nou
  1682. WHERE 1=1
  1683. <if test="businessName != null and businessName != ''">
  1684. AND nou.business_name = #{businessName}
  1685. </if>
  1686. GROUP BY
  1687. nou.business_name
  1688. ) allu
  1689. GROUP BY
  1690. allu.business_name
  1691. ORDER BY
  1692. money DESC
  1693. </select>
  1694. <select id="getBusinessOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1695. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">
  1696. SELECT
  1697. allu.business_name,
  1698. SUM( allu.order_num ) order_num
  1699. FROM
  1700. (
  1701. SELECT
  1702. ouu.business_name,
  1703. IFNULL(COUNT(DISTINCT ouu.order_sn ),0) order_num
  1704. FROM
  1705. (
  1706. SELECT
  1707. `otg`.`order_sn` AS `order_sn`,
  1708. `otg`.`order_goods_id` AS `order_goods_id`,
  1709. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1710. FROM
  1711. `top_old_order_goods` `otg`
  1712. ) ouu
  1713. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  1714. WHERE
  1715. oo.`status` = 1
  1716. AND oo.check_status = 1
  1717. AND oo.old_customer_id IS NOT NULL
  1718. <if test="startTime != null and startTime != ''">
  1719. AND oo.check_time &gt;= #{startTime}
  1720. </if>
  1721. <if test="endTime != null and endTime != ''">
  1722. AND oo.check_time &lt;= #{endTime}
  1723. </if>
  1724. <if test="tenantId != null and tenantId != ''">
  1725. AND oo.tenant_id = #{tenantId}
  1726. </if>
  1727. <if test="createSysUserId != null and createSysUserId != ''">
  1728. AND oo.create_sys_user_id = #{createSysUserId}
  1729. </if>
  1730. <if test="customerId != null and customerId != ''">
  1731. AND oo.tenant_id = #{customerId}
  1732. </if>
  1733. GROUP BY
  1734. ouu.business_name UNION ALL
  1735. SELECT
  1736. nou.business_name,
  1737. COUNT(DISTINCT nou.order_sn ) order_num
  1738. FROM
  1739. (
  1740. SELECT
  1741. `og`.`order_sn` AS `order_sn`,
  1742. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1743. og.order_goods_id
  1744. FROM
  1745. ((((
  1746. `order` o
  1747. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1748. LEFT JOIN `goods` `g` ON ((
  1749. `og`.`goods_id` = `g`.`goods_id`
  1750. )))
  1751. LEFT JOIN `course_education_type` `cet` ON ((
  1752. `g`.`education_type_id` = `cet`.`id`
  1753. )))
  1754. LEFT JOIN `course_project_type` `cpt` ON ((
  1755. `g`.`education_type_id` = `cpt`.`id`
  1756. )))
  1757. LEFT JOIN `course_business` `cb` ON ((
  1758. `g`.`business_id` = `cb`.`id`
  1759. )))
  1760. WHERE
  1761. og.pay_status != 1
  1762. AND og.refund_status != 2
  1763. AND (
  1764. o.input_order_sn IS NULL
  1765. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1766. <if test="startTime != null and startTime != ''">
  1767. AND og.create_time &gt;= #{startTime}
  1768. </if>
  1769. <if test="endTime != null and endTime != ''">
  1770. AND og.create_time &lt;= #{endTime}
  1771. </if>
  1772. <if test="tenantId != null and tenantId != ''">
  1773. AND og.tenant_id = #{tenantId}
  1774. </if>
  1775. <if test="customerId != null and customerId != ''">
  1776. AND og.tenant_id = #{customerId}
  1777. </if>
  1778. <if test="createSysUserId != null and createSysUserId != ''">
  1779. AND 1=0
  1780. </if>
  1781. ) nou
  1782. GROUP BY
  1783. nou.business_name
  1784. ) allu
  1785. where 1=1
  1786. <if test="businessName != null and businessName != ''">
  1787. AND allu.business_name = #{businessName}
  1788. </if>
  1789. GROUP BY
  1790. allu.business_name
  1791. ORDER BY
  1792. order_num DESC
  1793. </select>
  1794. <select id="getOrderGoodsNumStatisticsTotalWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1795. resultType="java.lang.Long">
  1796. SELECT
  1797. IFNULL(COUNT( og.order_goods_id ),0)+ (
  1798. SELECT
  1799. IFNULL(COUNT( otg.order_goods_id ),0) order_num
  1800. FROM
  1801. `top_old_order_goods` `otg`
  1802. LEFT JOIN top_old_order oo ON otg.order_sn = oo.order_sn
  1803. WHERE
  1804. oo.`status` = 1
  1805. AND oo.check_status = 1
  1806. AND oo.old_customer_id IS NOT NULL
  1807. <if test="startTime != null and startTime != ''">
  1808. AND oo.check_time &gt;= #{startTime}
  1809. </if>
  1810. <if test="endTime != null and endTime != ''">
  1811. AND oo.check_time &lt;= #{endTime}
  1812. </if>
  1813. <if test="tenantId != null and tenantId != ''">
  1814. AND oo.tenant_id = #{tenantId}
  1815. </if>
  1816. <if test="createNo != null and createNo != ''">
  1817. AND oo.create_no = #{createNo}
  1818. </if>
  1819. <if test="customerId != null and customerId != ''">
  1820. AND oo.tenant_id = #{customerId}
  1821. </if>
  1822. <if test="createSysUserId != null and createSysUserId != ''">
  1823. AND oo.create_sys_user_id = #{createSysUserId}
  1824. </if>
  1825. )
  1826. order_num
  1827. FROM
  1828. `order` o
  1829. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1830. WHERE
  1831. o.`status` = 1
  1832. AND o.order_status = 1
  1833. AND og.refund_status != 2
  1834. AND og.pay_status != 1
  1835. AND (
  1836. o.input_order_sn IS NULL
  1837. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  1838. <if test="startTime != null and startTime != ''">
  1839. AND og.create_time &gt;= #{startTime}
  1840. </if>
  1841. <if test="endTime != null and endTime != ''">
  1842. AND og.create_time &lt;= #{endTime}
  1843. </if>
  1844. <if test="tenantId != null and tenantId != ''">
  1845. AND og.tenant_id = #{tenantId}
  1846. </if>
  1847. <if test="createSysUserId != null and createSysUserId != ''">
  1848. AND 1=0
  1849. </if>
  1850. <if test="customerId != null and customerId != ''">
  1851. AND og.tenant_id = #{customerId}
  1852. </if>
  1853. </select>
  1854. <select id="getBusinessList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1855. resultType="string">
  1856. SELECT
  1857. allu.business_name
  1858. FROM
  1859. (
  1860. SELECT
  1861. ouu.business_name,
  1862. IFNULL( SUM( oo.order_received - oo.order_refunded ), 0 ) money
  1863. FROM
  1864. (
  1865. SELECT
  1866. ou.order_sn,
  1867. ou.business_name
  1868. FROM
  1869. (
  1870. SELECT
  1871. `otg`.`order_sn` AS `order_sn`,
  1872. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1873. FROM
  1874. `top_old_order_goods` `otg`
  1875. ) ou
  1876. GROUP BY
  1877. ou.order_sn,
  1878. ou.business_name
  1879. ) ouu
  1880. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  1881. WHERE
  1882. oo.`status` = 1
  1883. AND oo.check_status = 1
  1884. GROUP BY
  1885. ouu.business_name UNION ALL
  1886. SELECT
  1887. nou.business_name,
  1888. SUM( nou.goods_received ) AS money
  1889. FROM
  1890. (
  1891. SELECT
  1892. `og`.`order_sn` AS `order_sn`,
  1893. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1894. og.goods_received
  1895. FROM
  1896. ((((
  1897. `order` o
  1898. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1899. LEFT JOIN `goods` `g` ON ((
  1900. `og`.`goods_id` = `g`.`goods_id`
  1901. )))
  1902. LEFT JOIN `course_education_type` `cet` ON ((
  1903. `g`.`education_type_id` = `cet`.`id`
  1904. )))
  1905. LEFT JOIN `course_project_type` `cpt` ON ((
  1906. `g`.`education_type_id` = `cpt`.`id`
  1907. )))
  1908. LEFT JOIN `course_business` `cb` ON ((
  1909. `g`.`business_id` = `cb`.`id`
  1910. )))
  1911. WHERE
  1912. og.pay_status != 1
  1913. AND (
  1914. o.input_order_sn IS NULL
  1915. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1
  1916. )
  1917. AND o.tenant_id IS NOT NULL
  1918. AND og.refund_status != 2
  1919. ) nou
  1920. WHERE
  1921. 1 = 1
  1922. GROUP BY
  1923. nou.business_name
  1924. ) allu
  1925. WHERE
  1926. allu.business_name IS NOT NULL
  1927. GROUP BY
  1928. allu.business_name
  1929. ORDER BY
  1930. SUM( allu.money ) DESC
  1931. </select>
  1932. <select id="getOrderTenant" parameterType="java.lang.Long" resultType="java.lang.Long">
  1933. SELECT tenant_id FROM top_old_order WHERE old_customer_id = #{customerId} LIMIT 1
  1934. </select>
  1935. <select id="getCustomerList" resultType="com.zhongzheng.modules.top.order.vo.TopOrderCustomerVo">
  1936. SELECT
  1937. too.old_customer_id as customerId,
  1938. ( SELECT purchase_org FROM v_top_order vto WHERE vto.old_customer_id = too.old_customer_id LIMIT 1 ) as customerName
  1939. FROM
  1940. v_top_order too
  1941. WHERE
  1942. too.`status` = 1
  1943. AND too.old_customer_id IS NOT NULL
  1944. GROUP BY
  1945. too.old_customer_id
  1946. </select>
  1947. <select id="getTenantDetailList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1948. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
  1949. SELECT
  1950. vo.*,
  1951. st.tenant_name
  1952. FROM
  1953. (
  1954. SELECT
  1955. allu.tenant_id,
  1956. ANY_VALUE(allu.order_type) order_type,
  1957. SUM( allu.money2 ) money,
  1958. SUM(order_num2) order_num
  1959. <if test="tenantId != null and tenantId != ''">
  1960. , allu.create_sys_user_id,allu.create_username
  1961. </if>
  1962. FROM
  1963. (
  1964. SELECT
  1965. tenant_id,
  1966. 1 AS order_type,
  1967. SUM( order_received - order_refunded ) money2,
  1968. COUNT( * ) order_num2
  1969. <if test="tenantId != null and tenantId != ''">
  1970. , create_sys_user_id,any_value(create_username) as create_username
  1971. </if>
  1972. FROM
  1973. top_old_order too
  1974. WHERE
  1975. 1 = 1
  1976. AND `status` = 1
  1977. AND check_status = 1
  1978. AND old_customer_id IS NOT NULL
  1979. <if test="startTime != null and startTime != ''">
  1980. AND check_time &gt;= #{startTime}
  1981. </if>
  1982. <if test="endTime != null and endTime != ''">
  1983. AND check_time &lt;= #{endTime}
  1984. </if>
  1985. <if test="tenantId != null and tenantId != ''">
  1986. AND tenant_id = #{tenantId}
  1987. </if>
  1988. <if test="customerId != null and customerId != ''">
  1989. AND old_customer_id = #{customerId}
  1990. </if>
  1991. <if test="createSysUserId != null and createSysUserId != ''">
  1992. AND too.create_sys_user_id = #{createSysUserId}
  1993. </if>
  1994. <if test="businessName != null and businessName != ''">
  1995. AND (
  1996. SELECT
  1997. count(*)
  1998. FROM
  1999. (
  2000. SELECT
  2001. `otg`.`order_sn` AS `order_sn`,
  2002. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  2003. FROM
  2004. `top_old_order_goods` `otg`
  2005. ) ouu
  2006. WHERE
  2007. ouu.order_sn = too.order_sn
  2008. AND ouu.business_name = #{businessName}
  2009. ) >0
  2010. </if>
  2011. AND tenant_id IS NOT NULL
  2012. GROUP BY
  2013. tenant_id
  2014. <if test="tenantId != null and tenantId != ''">
  2015. , create_sys_user_id
  2016. </if>
  2017. UNION ALL
  2018. SELECT
  2019. og.tenant_id,
  2020. 2 AS order_type,
  2021. IFNULL( SUM( og.goods_received ), 0 ) money2,
  2022. COUNT( * ) order_num2
  2023. <if test="tenantId != null and tenantId != ''">
  2024. ,'' AS create_sys_user_id, '' as create_username
  2025. </if>
  2026. FROM
  2027. `order` o
  2028. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2029. WHERE
  2030. o.`status` = 1
  2031. AND o.order_status = 1
  2032. AND og.refund_status != 2
  2033. AND (
  2034. o.input_order_sn IS NULL
  2035. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  2036. <if test="startTime != null and startTime != ''">
  2037. AND o.create_time &gt;= #{startTime}
  2038. </if>
  2039. <if test="endTime != null and endTime != ''">
  2040. AND o.create_time &lt;= #{endTime}
  2041. </if>
  2042. <if test="tenantId != null and tenantId != ''">
  2043. AND o.tenant_id = #{tenantId}
  2044. </if>
  2045. <if test="customerId != null and customerId != ''">
  2046. AND o.old_customer_id = #{customerId}
  2047. </if>
  2048. <if test="createSysUserId != null and createSysUserId != ''">
  2049. AND 1=0
  2050. </if>
  2051. <if test="businessName != null and businessName != ''">
  2052. AND (
  2053. SELECT
  2054. count(*)
  2055. FROM
  2056. (
  2057. SELECT
  2058. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  2059. g.goods_id
  2060. FROM
  2061. `goods` `g`
  2062. LEFT JOIN `course_education_type` `cet` ON `g`.`education_type_id` = `cet`.`id`
  2063. LEFT JOIN `course_project_type` `cpt` ON `g`.`education_type_id` = `cpt`.`id`
  2064. LEFT JOIN `course_business` `cb` ON `g`.`business_id` = `cb`.`id`
  2065. ) oug
  2066. WHERE
  2067. oug.goods_id = og.goods_id
  2068. AND oug.business_name = #{businessName}
  2069. )>0
  2070. </if>
  2071. AND o.tenant_id IS NOT NULL
  2072. AND og.pay_status != 1
  2073. GROUP BY
  2074. og.tenant_id
  2075. ) allu
  2076. GROUP BY
  2077. allu.tenant_id
  2078. <if test="tenantId != null and tenantId != ''">
  2079. , allu.create_sys_user_id,allu.create_username
  2080. </if>
  2081. ORDER BY
  2082. tenant_id DESC
  2083. ) vo
  2084. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  2085. </select>
  2086. <select id="getBusinessDetailList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  2087. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
  2088. SELECT
  2089. allu.business_name,
  2090. SUM( allu.money ) money,
  2091. SUM( allu.order_num ) order_num
  2092. FROM
  2093. (
  2094. SELECT
  2095. ouu.business_name,
  2096. IFNULL( SUM( oo.order_received - oo.order_refunded ), 0 ) money,
  2097. 1 AS order_type,
  2098. COUNT( * ) order_num
  2099. FROM
  2100. (
  2101. SELECT
  2102. ou.order_sn,
  2103. ou.business_name
  2104. FROM
  2105. (
  2106. SELECT
  2107. `otg`.`order_sn` AS `order_sn`,
  2108. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  2109. FROM
  2110. `top_old_order_goods` `otg`
  2111. ) ou
  2112. GROUP BY
  2113. ou.order_sn,
  2114. ou.business_name
  2115. ) ouu
  2116. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  2117. WHERE
  2118. oo.`status` = 1
  2119. AND oo.check_status = 1
  2120. AND oo.old_customer_id IS NOT NULL
  2121. <if test="startTime != null and startTime != ''">
  2122. AND oo.check_time &gt;= #{startTime}
  2123. </if>
  2124. <if test="endTime != null and endTime != ''">
  2125. AND oo.check_time &lt;= #{endTime}
  2126. </if>
  2127. <if test="tenantId != null and tenantId != ''">
  2128. AND oo.tenant_id = #{tenantId}
  2129. </if>
  2130. <if test="createNo != null and createNo != ''">
  2131. AND oo.create_no = #{createNo}
  2132. </if>
  2133. <if test="createSysUserId != null and createSysUserId != ''">
  2134. AND oo.create_sys_user_id = #{createSysUserId}
  2135. </if>
  2136. <if test="businessName != null and businessName != ''">
  2137. AND ouu.business_name = #{businessName}
  2138. </if>
  2139. <if test="customerId != null and customerId != ''">
  2140. AND oo.old_customer_id = #{customerId}
  2141. </if>
  2142. GROUP BY
  2143. ouu.business_name UNION ALL
  2144. SELECT
  2145. nou.business_name,
  2146. SUM( nou.goods_received ) AS money,
  2147. 2 AS order_type,
  2148. COUNT(DISTINCT nou.order_sn ) order_num
  2149. FROM
  2150. (
  2151. SELECT
  2152. `og`.`order_sn` AS `order_sn`,
  2153. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  2154. og.goods_received
  2155. FROM
  2156. ((((
  2157. `order` o
  2158. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2159. LEFT JOIN `goods` `g` ON ((
  2160. `og`.`goods_id` = `g`.`goods_id`
  2161. )))
  2162. LEFT JOIN `course_education_type` `cet` ON ((
  2163. `g`.`education_type_id` = `cet`.`id`
  2164. )))
  2165. LEFT JOIN `course_project_type` `cpt` ON ((
  2166. `g`.`education_type_id` = `cpt`.`id`
  2167. )))
  2168. LEFT JOIN `course_business` `cb` ON ((
  2169. `g`.`business_id` = `cb`.`id`
  2170. )))
  2171. WHERE
  2172. og.pay_status != 1
  2173. AND (
  2174. o.input_order_sn IS NULL
  2175. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  2176. <if test="startTime != null and startTime != ''">
  2177. AND og.create_time &gt;= #{startTime}
  2178. </if>
  2179. <if test="endTime != null and endTime != ''">
  2180. AND og.create_time &lt;= #{endTime}
  2181. </if>
  2182. <if test="tenantId != null and tenantId != ''">
  2183. AND og.tenant_id = #{tenantId}
  2184. </if>
  2185. <if test="createNo != null and createNo != ''">
  2186. AND 1=0
  2187. </if>
  2188. <if test="createSysUserId != null and createSysUserId != ''">
  2189. AND 1=0
  2190. </if>
  2191. <if test="customerId != null and customerId != ''">
  2192. AND o.old_customer_id = #{customerId}
  2193. </if>
  2194. AND og.refund_status != 2
  2195. ) nou
  2196. WHERE 1=1
  2197. <if test="businessName != null and businessName != ''">
  2198. AND nou.business_name = #{businessName}
  2199. </if>
  2200. GROUP BY
  2201. nou.business_name
  2202. ) allu
  2203. GROUP BY
  2204. allu.business_name
  2205. ORDER BY
  2206. money DESC
  2207. </select>
  2208. <select id="getStatisticsTenantView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  2209. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  2210. SELECT
  2211. COUNT(DISTINCT a.order_id) AS orderNum,
  2212. SUM(a.money) AS money,
  2213. any_value(a.timeStr) AS orderTime,
  2214. any_value(a.create_username) AS create_username,
  2215. any_value(a.tenant_name) AS tenant_name,
  2216. <if test="viewSign != null and viewSign == 1">
  2217. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
  2218. </if>
  2219. <if test="viewSign != null and viewSign == 2">
  2220. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
  2221. </if>
  2222. <if test="viewSign != null and viewSign == 3">
  2223. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
  2224. </if>
  2225. FROM (
  2226. SELECT
  2227. too.order_id as order_id,
  2228. too.check_time as timeStr,
  2229. too.order_received - too.order_refunded as money,
  2230. too.create_username,
  2231. st.tenant_name
  2232. FROM
  2233. top_old_order too LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  2234. WHERE
  2235. too.`status` = 1
  2236. AND too.check_status = 1
  2237. AND too.old_customer_id IS NOT NULL
  2238. <if test="startTime != null and startTime != ''">
  2239. AND too.check_time &gt;= #{startTime}
  2240. </if>
  2241. <if test="endTime != null and endTime != ''">
  2242. AND too.check_time &lt;= #{endTime}
  2243. </if>
  2244. <if test="tenantId != null and tenantId != ''">
  2245. AND too.tenant_id = #{tenantId}
  2246. </if>
  2247. <if test="createNo != null and createNo != ''">
  2248. AND too.create_no = #{createNo}
  2249. </if>
  2250. <if test="createSysUserId != null and createSysUserId != ''">
  2251. AND too.create_sys_user_id = #{createSysUserId}
  2252. </if>
  2253. UNION ALL
  2254. SELECT
  2255. o.order_id as order_id,
  2256. o.create_time as timeStr,
  2257. og.goods_received as money,
  2258. null as create_username,
  2259. st.tenant_name
  2260. FROM
  2261. `order` o
  2262. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2263. LEFT JOIN sys_tenant st ON o.tenant_id = st.tenant_id
  2264. WHERE
  2265. o.`status` = 1
  2266. AND o.order_status = 1
  2267. AND og.refund_status != 2
  2268. AND og.pay_status != 1
  2269. AND (
  2270. o.input_order_sn IS NULL
  2271. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0
  2272. )
  2273. <if test="startTime != null and startTime != ''">
  2274. AND o.create_time &gt;= #{startTime}
  2275. </if>
  2276. <if test="endTime != null and endTime != ''">
  2277. AND o.create_time &lt;= #{endTime}
  2278. </if>
  2279. <if test="tenantId != null and tenantId != ''">
  2280. AND o.tenant_id = #{tenantId}
  2281. </if>
  2282. <if test="createSysUserId != null and createSysUserId != ''">
  2283. AND 1=0
  2284. </if>
  2285. ) a WHERE 1=1
  2286. <if test="viewSign != null and viewSign == 1">
  2287. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
  2288. </if>
  2289. <if test="viewSign != null and viewSign == 2">
  2290. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
  2291. </if>
  2292. <if test="viewSign != null and viewSign == 3">
  2293. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
  2294. </if>
  2295. ORDER BY timeStr
  2296. </select>
  2297. <select id="getStatisticsBusinessView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  2298. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  2299. SELECT
  2300. COUNT(a.order_sn) AS orderNum,
  2301. SUM(a.money) AS money,
  2302. any_value(a.timeStr) AS orderTime,
  2303. any_value(a.create_username) AS create_username,
  2304. any_value(a.tenant_name) AS tenant_name,
  2305. <if test="viewSign != null and viewSign == 1">
  2306. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
  2307. </if>
  2308. <if test="viewSign != null and viewSign == 2">
  2309. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
  2310. </if>
  2311. <if test="viewSign != null and viewSign == 3">
  2312. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
  2313. </if>
  2314. FROM (
  2315. SELECT
  2316. too.order_sn,
  2317. concat(
  2318. substr(( SELECT otg.business_full_name FROM `top_old_order_goods` `otg` WHERE otg.order_sn = too.order_sn LIMIT 1 ), 5, 4 ),
  2319. '-',(
  2320. SELECT
  2321. otg.business_name
  2322. FROM
  2323. `top_old_order_goods` `otg`
  2324. WHERE
  2325. otg.order_sn = too.order_sn
  2326. LIMIT 1
  2327. )
  2328. ) AS `business_name`,
  2329. too.order_received - too.order_refunded AS money,
  2330. too.check_time as timeStr,
  2331. too.create_username,
  2332. st.tenant_name
  2333. FROM
  2334. top_old_order too
  2335. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  2336. WHERE
  2337. too.`status` = 1
  2338. AND too.check_status = 1
  2339. <if test="startTime != null and startTime != ''">
  2340. AND too.check_time &gt;= #{startTime}
  2341. </if>
  2342. <if test="endTime != null and endTime != ''">
  2343. AND too.check_time &lt;= #{endTime}
  2344. </if>
  2345. <if test="tenantId != null and tenantId != ''">
  2346. AND too.tenant_id = #{tenantId}
  2347. </if>
  2348. <if test="createSysUserId != null and createSysUserId != ''">
  2349. AND too.create_sys_user_id = #{createSysUserId}
  2350. </if>
  2351. UNION ALL
  2352. SELECT
  2353. `og`.`order_sn` AS `order_sn`,
  2354. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  2355. og.goods_received as money,
  2356. og.create_time as timeStr,
  2357. null as create_username,
  2358. st.tenant_name
  2359. FROM
  2360. ((((
  2361. `order` o
  2362. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2363. LEFT JOIN sys_tenant st ON o.tenant_id = st.tenant_id
  2364. LEFT JOIN `goods` `g` ON ((
  2365. `og`.`goods_id` = `g`.`goods_id`
  2366. )))
  2367. LEFT JOIN `course_education_type` `cet` ON ((
  2368. `g`.`education_type_id` = `cet`.`id`
  2369. )))
  2370. LEFT JOIN `course_project_type` `cpt` ON ((
  2371. `g`.`education_type_id` = `cpt`.`id`
  2372. )))
  2373. LEFT JOIN `course_business` `cb` ON ((
  2374. `g`.`business_id` = `cb`.`id`
  2375. )))
  2376. WHERE
  2377. og.pay_status != 1
  2378. AND (
  2379. o.input_order_sn IS NULL
  2380. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
  2381. <if test="startTime != null and startTime != ''">
  2382. AND og.create_time &gt;= #{startTime}
  2383. </if>
  2384. <if test="endTime != null and endTime != ''">
  2385. AND og.create_time &lt;= #{endTime}
  2386. </if>
  2387. <if test="tenantId != null and tenantId != ''">
  2388. AND og.tenant_id = #{tenantId}
  2389. </if>
  2390. <if test="createSysUserId != null and createSysUserId != ''">
  2391. AND 1=0
  2392. </if>
  2393. <if test="customerId != null and customerId != ''">
  2394. AND og.tenant_id = #{customerId}
  2395. </if>
  2396. AND og.refund_status != 2
  2397. ) a WHERE 1=1
  2398. <if test="businessName != null and businessName != ''">
  2399. AND a.business_name = #{businessName}
  2400. </if>
  2401. <if test="viewSign != null and viewSign == 1">
  2402. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
  2403. </if>
  2404. <if test="viewSign != null and viewSign == 2">
  2405. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
  2406. </if>
  2407. <if test="viewSign != null and viewSign == 3">
  2408. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
  2409. </if>
  2410. </select>
  2411. <select id="getTenantCreateList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  2412. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  2413. SELECT
  2414. create_username,
  2415. create_sys_user_id
  2416. FROM
  2417. top_old_order
  2418. WHERE
  2419. 1=1
  2420. <if test="tenantId != null and tenantId != ''">
  2421. AND tenant_id = #{tenantId}
  2422. </if>
  2423. AND create_sys_user_id IS NOT NULL
  2424. GROUP BY
  2425. create_sys_user_id,
  2426. create_username
  2427. </select>
  2428. </mapper>