TopOldOrderMapper.xml 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608
  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.check_time DESC ,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,cb.business_name,cpt.project_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,cb.business_name,cpt.project_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,cb.business_name,cpt.project_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,cb.business_name,cpt.project_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,cb.business_name,cpt.project_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 old_customer_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="java.math.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`.`project_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. <if test="startTime != null and startTime != ''">
  1319. AND vo.check_time &gt;= #{startTime}
  1320. </if>
  1321. <if test="endTime != null and endTime != ''">
  1322. AND vo.check_time &lt;= #{endTime}
  1323. </if>
  1324. <if test="tenantId != null and tenantId != ''">
  1325. AND vo.tenant_id = #{tenantId}
  1326. </if>
  1327. <if test="createSysUserId != null and createSysUserId != ''">
  1328. AND vo.create_sys_user_id = #{createSysUserId}
  1329. </if>
  1330. <if test="customerId != null and customerId != ''">
  1331. AND vo.old_customer_id = #{customerId}
  1332. </if>
  1333. <if test="businessName != null and businessName != ''">
  1334. AND (
  1335. SELECT
  1336. count(*)
  1337. FROM
  1338. (
  1339. SELECT
  1340. `otg`.`order_sn` AS `order_sn`,
  1341. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1342. FROM
  1343. `top_old_order_goods` `otg`
  1344. ) ouu
  1345. WHERE
  1346. ouu.order_sn = vo.order_sn
  1347. AND ouu.business_name = #{businessName}
  1348. ) >0
  1349. </if>
  1350. </select>
  1351. <select id="getTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1352. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">
  1353. SELECT
  1354. vo.*,
  1355. st.tenant_name
  1356. FROM
  1357. (
  1358. SELECT
  1359. allu.tenant_id,
  1360. SUM(order_num2) order_num
  1361. <if test="tenantId != null and tenantId != ''">
  1362. , allu.create_sys_user_id,allu.create_username
  1363. </if>
  1364. FROM
  1365. (
  1366. SELECT
  1367. tenant_id,
  1368. COUNT( * ) order_num2
  1369. <if test="tenantId != null and tenantId != ''">
  1370. , create_sys_user_id,any_value(create_username) as create_username
  1371. </if>
  1372. FROM
  1373. top_old_order
  1374. WHERE
  1375. 1 = 1
  1376. AND `status` = 1
  1377. AND check_status = 1
  1378. AND old_customer_id IS NOT NULL
  1379. <if test="startTime != null and startTime != ''">
  1380. AND check_time &gt;= #{startTime}
  1381. </if>
  1382. <if test="endTime != null and endTime != ''">
  1383. AND check_time &lt;= #{endTime}
  1384. </if>
  1385. <if test="tenantId != null and tenantId != ''">
  1386. AND tenant_id = #{tenantId}
  1387. </if>
  1388. <if test="customerId != null and customerId != ''">
  1389. AND old_customer_id = #{customerId}
  1390. </if>
  1391. GROUP BY
  1392. tenant_id
  1393. <if test="tenantId != null and tenantId != ''">
  1394. , create_sys_user_id
  1395. </if>
  1396. UNION ALL
  1397. SELECT
  1398. og.tenant_id,
  1399. COUNT( * ) order_num2
  1400. <if test="tenantId != null and tenantId != ''">
  1401. ,'' AS create_sys_user_id, '' as create_username
  1402. </if>
  1403. FROM
  1404. `order` o
  1405. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1406. WHERE
  1407. o.`status` = 1
  1408. AND o.order_status = 1
  1409. AND og.refund_status != 2
  1410. AND (
  1411. o.input_order_sn IS NULL
  1412. 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
  1413. <if test="startTime != null and startTime != ''">
  1414. AND o.create_time &gt;= #{startTime}
  1415. </if>
  1416. <if test="endTime != null and endTime != ''">
  1417. AND o.create_time &lt;= #{endTime}
  1418. </if>
  1419. <if test="tenantId != null and tenantId != ''">
  1420. AND o.tenant_id = #{tenantId}
  1421. </if>
  1422. <if test="customerId != null and customerId != ''">
  1423. AND o.tenant_id = #{customerId}
  1424. </if>
  1425. AND og.pay_status != 1
  1426. GROUP BY
  1427. og.tenant_id
  1428. ) allu
  1429. GROUP BY
  1430. allu.tenant_id
  1431. <if test="tenantId != null and tenantId != ''">
  1432. , allu.create_sys_user_id,allu.create_username
  1433. </if>
  1434. ORDER BY
  1435. order_num DESC
  1436. ) vo
  1437. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  1438. </select>
  1439. <select id="getSingleTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1440. resultType="java.lang.Long">
  1441. SELECT
  1442. (IFNULL(COUNT( DISTINCT order_sn),0)+(
  1443. SELECT
  1444. IFNULL(COUNT(DISTINCT o.order_sn),0) AS orderNum
  1445. FROM
  1446. `order` o
  1447. WHERE
  1448. o.`status` = 1
  1449. AND o.order_status = 1
  1450. AND (
  1451. o.input_order_sn IS NULL
  1452. 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
  1453. <if test="startTime != null and startTime != ''">
  1454. AND o.create_time &gt;= #{startTime}
  1455. </if>
  1456. <if test="endTime != null and endTime != ''">
  1457. AND o.create_time &lt;= #{endTime}
  1458. </if>
  1459. <if test="tenantId != null and tenantId != ''">
  1460. AND o.tenant_id = #{tenantId}
  1461. </if>
  1462. <if test="customerId != null and customerId != ''">
  1463. AND o.tenant_id = #{customerId}
  1464. </if>
  1465. <if test="createSysUserId != null and createSysUserId != ''">
  1466. AND 1=0
  1467. </if>
  1468. <if test="businessName != null and businessName != ''">
  1469. AND (
  1470. SELECT
  1471. count(*)
  1472. FROM
  1473. (
  1474. SELECT
  1475. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1476. g.goods_id,
  1477. og.order_sn
  1478. FROM
  1479. order_goods og LEFT JOIN `goods` `g` on og.goods_id = `g`.goods_id
  1480. LEFT JOIN `course_education_type` `cet` ON `g`.`education_type_id` = `cet`.`id`
  1481. LEFT JOIN `course_project_type` `cpt` ON `g`.`project_id` = `cpt`.`id`
  1482. LEFT JOIN `course_business` `cb` ON `g`.`business_id` = `cb`.`id`
  1483. ) oug
  1484. WHERE
  1485. o.order_sn = oug.order_sn
  1486. AND oug.business_name = #{businessName}
  1487. )>0
  1488. </if>
  1489. ))
  1490. FROM
  1491. top_old_order too
  1492. WHERE
  1493. 1 = 1
  1494. AND `status` = 1
  1495. AND check_status = 1
  1496. AND old_customer_id IS NOT NULL
  1497. <if test="startTime != null and startTime != ''">
  1498. AND check_time &gt;= #{startTime}
  1499. </if>
  1500. <if test="endTime != null and endTime != ''">
  1501. AND check_time &lt;= #{endTime}
  1502. </if>
  1503. <if test="tenantId != null and tenantId != ''">
  1504. AND tenant_id = #{tenantId}
  1505. </if>
  1506. <if test="customerId != null and customerId != ''">
  1507. AND old_customer_id = #{customerId}
  1508. </if>
  1509. <if test="createSysUserId != null and createSysUserId != ''">
  1510. AND create_sys_user_id = #{createSysUserId}
  1511. </if>
  1512. <if test="businessName != null and businessName != ''">
  1513. AND (
  1514. SELECT
  1515. count(*)
  1516. FROM
  1517. (
  1518. SELECT
  1519. `otg`.`order_sn` AS `order_sn`,
  1520. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1521. FROM
  1522. `top_old_order_goods` `otg`
  1523. ) ouu
  1524. WHERE
  1525. ouu.order_sn = too.order_sn
  1526. AND ouu.business_name = #{businessName}
  1527. ) >0
  1528. </if>
  1529. </select>
  1530. <select id="getNumStatisticsTotalWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1531. resultType="java.math.BigDecimal">
  1532. SELECT
  1533. (IFNULL(COUNT(too.order_id),0)+(
  1534. SELECT
  1535. IFNULL(COUNT(o.order_id),0) AS orderNum
  1536. FROM
  1537. `order` o
  1538. WHERE
  1539. o.`status` = 1
  1540. AND o.order_status = 1
  1541. AND (
  1542. o.input_order_sn IS NULL
  1543. 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
  1544. <if test="startTime != null and startTime != ''">
  1545. AND o.create_time &gt;= #{startTime}
  1546. </if>
  1547. <if test="endTime != null and endTime != ''">
  1548. AND o.create_time &lt;= #{endTime}
  1549. </if>
  1550. <if test="tenantId != null and tenantId != ''">
  1551. AND o.tenant_id = #{tenantId}
  1552. </if>
  1553. <if test="customerId != null and customerId != ''">
  1554. AND o.tenant_id = #{customerId}
  1555. </if>
  1556. <if test="businessName != null and businessName != ''">
  1557. AND (
  1558. SELECT
  1559. count(*)
  1560. FROM
  1561. (
  1562. SELECT
  1563. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1564. g.goods_id,
  1565. og.order_sn
  1566. FROM
  1567. order_goods og LEFT JOIN `goods` `g` on og.goods_id = `g`.goods_id
  1568. LEFT JOIN `course_education_type` `cet` ON `g`.`education_type_id` = `cet`.`id`
  1569. LEFT JOIN `course_project_type` `cpt` ON `g`.`project_id` = `cpt`.`id`
  1570. LEFT JOIN `course_business` `cb` ON `g`.`business_id` = `cb`.`id`
  1571. ) oug
  1572. WHERE
  1573. o.order_sn = oug.order_sn
  1574. AND oug.business_name = #{businessName}
  1575. )>0
  1576. </if>
  1577. )) AS orderNum
  1578. FROM
  1579. top_old_order too
  1580. WHERE
  1581. too.`status` = 1
  1582. AND too.check_status = 1
  1583. AND too.old_customer_id IS NOT NULL
  1584. <if test="startTime != null and startTime != ''">
  1585. AND too.check_time &gt;= #{startTime}
  1586. </if>
  1587. <if test="endTime != null and endTime != ''">
  1588. AND too.check_time &lt;= #{endTime}
  1589. </if>
  1590. <if test="tenantId != null and tenantId != ''">
  1591. AND too.tenant_id = #{tenantId}
  1592. </if>
  1593. <if test="customerId != null and customerId != ''">
  1594. AND too.old_customer_id = #{customerId}
  1595. </if>
  1596. <if test="businessName != null and businessName != ''">
  1597. AND (
  1598. SELECT
  1599. count(*)
  1600. FROM
  1601. (
  1602. SELECT
  1603. `otg`.`order_sn` AS `order_sn`,
  1604. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1605. FROM
  1606. `top_old_order_goods` `otg`
  1607. ) ouu
  1608. WHERE
  1609. ouu.order_sn = too.order_sn
  1610. AND ouu.business_name = #{businessName}
  1611. ) >0
  1612. </if>
  1613. </select>
  1614. <select id="getMoneyStatisticsWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1615. resultType="java.math.BigDecimal">
  1616. SELECT
  1617. IFNULL(SUM( too.order_received - too.order_refunded ),0)+ (
  1618. SELECT
  1619. IFNULL(SUM( og.goods_received ),0) AS money
  1620. FROM
  1621. `order` o
  1622. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1623. WHERE
  1624. o.`status` = 1
  1625. AND o.order_status = 1
  1626. AND og.refund_status != 2
  1627. AND og.pay_status != 1
  1628. AND (
  1629. o.input_order_sn IS NULL
  1630. 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
  1631. <if test="startTime != null and startTime != ''">
  1632. AND o.create_time &gt;= #{startTime}
  1633. </if>
  1634. <if test="endTime != null and endTime != ''">
  1635. AND o.create_time &lt;= #{endTime}
  1636. </if>
  1637. <if test="tenantId != null and tenantId != ''">
  1638. AND o.tenant_id = #{tenantId}
  1639. </if>
  1640. <if test="customerId != null and customerId != ''">
  1641. AND o.tenant_id = #{customerId}
  1642. </if>
  1643. <if test="createSysUserId != null and createSysUserId != ''">
  1644. AND 1=0
  1645. </if>
  1646. <if test="businessName != null and businessName != ''">
  1647. AND (
  1648. SELECT
  1649. count(*)
  1650. FROM
  1651. (
  1652. SELECT
  1653. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1654. g.goods_id
  1655. FROM
  1656. `goods` `g`
  1657. LEFT JOIN `course_education_type` `cet` ON `g`.`education_type_id` = `cet`.`id`
  1658. LEFT JOIN `course_project_type` `cpt` ON `g`.`project_id` = `cpt`.`id`
  1659. LEFT JOIN `course_business` `cb` ON `g`.`business_id` = `cb`.`id`
  1660. ) oug
  1661. WHERE
  1662. og.goods_id = oug.goods_id
  1663. AND oug.business_name = #{businessName}
  1664. )>0
  1665. </if>
  1666. ) AS money
  1667. FROM
  1668. top_old_order too
  1669. WHERE
  1670. too.`status` = 1
  1671. AND too.check_status = 1
  1672. AND too.old_customer_id IS NOT NULL
  1673. <if test="startTime != null and startTime != ''">
  1674. AND too.check_time &gt;= #{startTime}
  1675. </if>
  1676. <if test="endTime != null and endTime != ''">
  1677. AND too.check_time &lt;= #{endTime}
  1678. </if>
  1679. <if test="tenantId != null and tenantId != ''">
  1680. AND too.tenant_id = #{tenantId}
  1681. </if>
  1682. <if test="customerId != null and customerId != ''">
  1683. AND too.old_customer_id = #{customerId}
  1684. </if>
  1685. <if test="createSysUserId != null and createSysUserId != ''">
  1686. AND too.create_sys_user_id = #{createSysUserId}
  1687. </if>
  1688. <if test="businessName != null and businessName != ''">
  1689. AND (
  1690. SELECT
  1691. count(*)
  1692. FROM
  1693. (
  1694. SELECT
  1695. `otg`.`order_sn` AS `order_sn`,
  1696. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1697. FROM
  1698. `top_old_order_goods` `otg`
  1699. ) ouu
  1700. WHERE
  1701. ouu.order_sn = too.order_sn
  1702. AND ouu.business_name = #{businessName}
  1703. ) >0
  1704. </if>
  1705. </select>
  1706. <select id="getBusinessOrderMoney" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1707. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">
  1708. SELECT
  1709. allu.business_name,
  1710. SUM( allu.money ) money
  1711. FROM
  1712. (
  1713. SELECT
  1714. ouu.business_name,
  1715. IFNULL( SUM( oo.order_received - oo.order_refunded ), 0 ) money
  1716. FROM
  1717. (
  1718. SELECT
  1719. ou.order_sn,
  1720. ou.business_name
  1721. FROM
  1722. (
  1723. SELECT
  1724. `otg`.`order_sn` AS `order_sn`,
  1725. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1726. FROM
  1727. `top_old_order_goods` `otg`
  1728. ) ou
  1729. GROUP BY
  1730. ou.order_sn,
  1731. ou.business_name
  1732. ) ouu
  1733. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  1734. WHERE
  1735. oo.`status` = 1
  1736. AND oo.check_status = 1
  1737. AND oo.old_customer_id IS NOT NULL
  1738. <if test="startTime != null and startTime != ''">
  1739. AND oo.check_time &gt;= #{startTime}
  1740. </if>
  1741. <if test="endTime != null and endTime != ''">
  1742. AND oo.check_time &lt;= #{endTime}
  1743. </if>
  1744. <if test="tenantId != null and tenantId != ''">
  1745. AND oo.tenant_id = #{tenantId}
  1746. </if>
  1747. <if test="createSysUserId != null and createSysUserId != ''">
  1748. AND oo.create_sys_user_id = #{createSysUserId}
  1749. </if>
  1750. <if test="businessName != null and businessName != ''">
  1751. AND ouu.business_name = #{businessName}
  1752. </if>
  1753. <if test="customerId != null and customerId != ''">
  1754. AND oo.old_customer_id = #{customerId}
  1755. </if>
  1756. GROUP BY
  1757. ouu.business_name UNION ALL
  1758. SELECT
  1759. nou.business_name,
  1760. SUM( nou.goods_received ) AS money
  1761. FROM
  1762. (
  1763. SELECT
  1764. `og`.`order_sn` AS `order_sn`,
  1765. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1766. og.goods_received
  1767. FROM
  1768. ((((
  1769. `order` o
  1770. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1771. LEFT JOIN `goods` `g` ON ((
  1772. `og`.`goods_id` = `g`.`goods_id`
  1773. )))
  1774. LEFT JOIN `course_education_type` `cet` ON ((
  1775. `g`.`education_type_id` = `cet`.`id`
  1776. )))
  1777. LEFT JOIN `course_project_type` `cpt` ON ((
  1778. `g`.`project_id` = `cpt`.`id`
  1779. )))
  1780. LEFT JOIN `course_business` `cb` ON ((
  1781. `g`.`business_id` = `cb`.`id`
  1782. )))
  1783. WHERE
  1784. og.pay_status != 1
  1785. AND (
  1786. o.input_order_sn IS NULL
  1787. 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
  1788. <if test="startTime != null and startTime != ''">
  1789. AND og.create_time &gt;= #{startTime}
  1790. </if>
  1791. <if test="endTime != null and endTime != ''">
  1792. AND og.create_time &lt;= #{endTime}
  1793. </if>
  1794. <if test="tenantId != null and tenantId != ''">
  1795. AND og.tenant_id = #{tenantId}
  1796. </if>
  1797. <if test="createSysUserId != null and createSysUserId != ''">
  1798. AND 1=0
  1799. </if>
  1800. <if test="customerId != null and customerId != ''">
  1801. AND og.tenant_id = #{customerId}
  1802. </if>
  1803. AND og.refund_status != 2
  1804. ) nou
  1805. WHERE 1=1
  1806. <if test="businessName != null and businessName != ''">
  1807. AND nou.business_name = #{businessName}
  1808. </if>
  1809. GROUP BY
  1810. nou.business_name
  1811. ) allu
  1812. GROUP BY
  1813. allu.business_name
  1814. ORDER BY
  1815. money DESC
  1816. </select>
  1817. <select id="getBusinessOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1818. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">
  1819. SELECT
  1820. allu.business_name,
  1821. SUM( allu.order_num ) order_num
  1822. FROM
  1823. (
  1824. SELECT
  1825. ouu.business_name,
  1826. IFNULL(COUNT(DISTINCT ouu.order_sn ),0) order_num
  1827. FROM
  1828. (
  1829. SELECT
  1830. `otg`.`order_sn` AS `order_sn`,
  1831. `otg`.`order_goods_id` AS `order_goods_id`,
  1832. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1833. FROM
  1834. `top_old_order_goods` `otg`
  1835. ) ouu
  1836. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  1837. WHERE
  1838. oo.`status` = 1
  1839. AND oo.check_status = 1
  1840. AND oo.old_customer_id IS NOT NULL
  1841. <if test="startTime != null and startTime != ''">
  1842. AND oo.check_time &gt;= #{startTime}
  1843. </if>
  1844. <if test="endTime != null and endTime != ''">
  1845. AND oo.check_time &lt;= #{endTime}
  1846. </if>
  1847. <if test="tenantId != null and tenantId != ''">
  1848. AND oo.tenant_id = #{tenantId}
  1849. </if>
  1850. <if test="createSysUserId != null and createSysUserId != ''">
  1851. AND oo.create_sys_user_id = #{createSysUserId}
  1852. </if>
  1853. <if test="customerId != null and customerId != ''">
  1854. AND oo.old_customer_id = #{customerId}
  1855. </if>
  1856. GROUP BY
  1857. ouu.business_name UNION ALL
  1858. SELECT
  1859. nou.business_name,
  1860. COUNT(DISTINCT nou.order_sn ) order_num
  1861. FROM
  1862. (
  1863. SELECT
  1864. `og`.`order_sn` AS `order_sn`,
  1865. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  1866. og.order_goods_id
  1867. FROM
  1868. ((((
  1869. `order` o
  1870. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1871. LEFT JOIN `goods` `g` ON ((
  1872. `og`.`goods_id` = `g`.`goods_id`
  1873. )))
  1874. LEFT JOIN `course_education_type` `cet` ON ((
  1875. `g`.`education_type_id` = `cet`.`id`
  1876. )))
  1877. LEFT JOIN `course_project_type` `cpt` ON ((
  1878. `g`.`project_id` = `cpt`.`id`
  1879. )))
  1880. LEFT JOIN `course_business` `cb` ON ((
  1881. `g`.`business_id` = `cb`.`id`
  1882. )))
  1883. WHERE
  1884. og.pay_status != 1
  1885. AND og.refund_status != 2
  1886. AND (
  1887. o.input_order_sn IS NULL
  1888. 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
  1889. <if test="startTime != null and startTime != ''">
  1890. AND og.create_time &gt;= #{startTime}
  1891. </if>
  1892. <if test="endTime != null and endTime != ''">
  1893. AND og.create_time &lt;= #{endTime}
  1894. </if>
  1895. <if test="tenantId != null and tenantId != ''">
  1896. AND og.tenant_id = #{tenantId}
  1897. </if>
  1898. <if test="customerId != null and customerId != ''">
  1899. AND og.tenant_id = #{customerId}
  1900. </if>
  1901. <if test="createSysUserId != null and createSysUserId != ''">
  1902. AND 1=0
  1903. </if>
  1904. ) nou
  1905. GROUP BY
  1906. nou.business_name
  1907. ) allu
  1908. where 1=1
  1909. <if test="businessName != null and businessName != ''">
  1910. AND allu.business_name = #{businessName}
  1911. </if>
  1912. GROUP BY
  1913. allu.business_name
  1914. ORDER BY
  1915. order_num DESC
  1916. </select>
  1917. <select id="getOrderGoodsNumStatisticsTotalWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1918. resultType="java.lang.Long">
  1919. SELECT
  1920. IFNULL(COUNT( DISTINCT og.order_sn ),0)+ (
  1921. SELECT
  1922. IFNULL(COUNT( DISTINCT otg.order_sn ),0) order_num
  1923. FROM
  1924. `top_old_order_goods` `otg`
  1925. LEFT JOIN top_old_order oo ON otg.order_sn = oo.order_sn
  1926. WHERE
  1927. oo.`status` = 1
  1928. AND oo.check_status = 1
  1929. AND oo.old_customer_id IS NOT NULL
  1930. <if test="startTime != null and startTime != ''">
  1931. AND oo.check_time &gt;= #{startTime}
  1932. </if>
  1933. <if test="endTime != null and endTime != ''">
  1934. AND oo.check_time &lt;= #{endTime}
  1935. </if>
  1936. <if test="tenantId != null and tenantId != ''">
  1937. AND oo.tenant_id = #{tenantId}
  1938. </if>
  1939. <if test="createNo != null and createNo != ''">
  1940. AND oo.create_no = #{createNo}
  1941. </if>
  1942. <if test="customerId != null and customerId != ''">
  1943. AND oo.old_customer_id = #{customerId}
  1944. </if>
  1945. <if test="createSysUserId != null and createSysUserId != ''">
  1946. AND oo.create_sys_user_id = #{createSysUserId}
  1947. </if>
  1948. )
  1949. order_num
  1950. FROM
  1951. `order` o
  1952. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  1953. WHERE
  1954. o.`status` = 1
  1955. AND o.order_status = 1
  1956. AND og.refund_status != 2
  1957. AND og.pay_status != 1
  1958. AND (
  1959. o.input_order_sn IS NULL
  1960. 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
  1961. <if test="startTime != null and startTime != ''">
  1962. AND og.create_time &gt;= #{startTime}
  1963. </if>
  1964. <if test="endTime != null and endTime != ''">
  1965. AND og.create_time &lt;= #{endTime}
  1966. </if>
  1967. <if test="tenantId != null and tenantId != ''">
  1968. AND og.tenant_id = #{tenantId}
  1969. </if>
  1970. <if test="createSysUserId != null and createSysUserId != ''">
  1971. AND 1=0
  1972. </if>
  1973. <if test="customerId != null and customerId != ''">
  1974. AND og.tenant_id = #{customerId}
  1975. </if>
  1976. </select>
  1977. <select id="getBusinessList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  1978. resultType="string">
  1979. SELECT
  1980. allu.business_name
  1981. FROM
  1982. (
  1983. SELECT
  1984. ouu.business_name,
  1985. IFNULL( SUM( oo.order_received - oo.order_refunded ), 0 ) money
  1986. FROM
  1987. (
  1988. SELECT
  1989. ou.order_sn,
  1990. ou.business_name
  1991. FROM
  1992. (
  1993. SELECT
  1994. `otg`.`order_sn` AS `order_sn`,
  1995. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  1996. FROM
  1997. `top_old_order_goods` `otg`
  1998. ) ou
  1999. GROUP BY
  2000. ou.order_sn,
  2001. ou.business_name
  2002. ) ouu
  2003. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  2004. WHERE
  2005. oo.`status` = 1
  2006. AND oo.check_status = 1
  2007. GROUP BY
  2008. ouu.business_name UNION ALL
  2009. SELECT
  2010. nou.business_name,
  2011. SUM( nou.goods_received ) AS money
  2012. FROM
  2013. (
  2014. SELECT
  2015. `og`.`order_sn` AS `order_sn`,
  2016. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  2017. og.goods_received
  2018. FROM
  2019. ((((
  2020. `order` o
  2021. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2022. LEFT JOIN `goods` `g` ON ((
  2023. `og`.`goods_id` = `g`.`goods_id`
  2024. )))
  2025. LEFT JOIN `course_education_type` `cet` ON ((
  2026. `g`.`education_type_id` = `cet`.`id`
  2027. )))
  2028. LEFT JOIN `course_project_type` `cpt` ON ((
  2029. `g`.`project_id` = `cpt`.`id`
  2030. )))
  2031. LEFT JOIN `course_business` `cb` ON ((
  2032. `g`.`business_id` = `cb`.`id`
  2033. )))
  2034. WHERE
  2035. og.pay_status != 1
  2036. AND (
  2037. o.input_order_sn IS NULL
  2038. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1
  2039. )
  2040. AND o.tenant_id IS NOT NULL
  2041. AND og.refund_status != 2
  2042. ) nou
  2043. WHERE
  2044. 1 = 1
  2045. GROUP BY
  2046. nou.business_name
  2047. ) allu
  2048. WHERE
  2049. allu.business_name IS NOT NULL
  2050. GROUP BY
  2051. allu.business_name
  2052. ORDER BY
  2053. SUM( allu.money ) DESC
  2054. </select>
  2055. <select id="getOrderTenant" parameterType="java.lang.String" resultType="java.lang.String">
  2056. SELECT tenant_id FROM top_old_order WHERE old_customer_id = #{customerId} LIMIT 1
  2057. </select>
  2058. <select id="getCustomerList" resultType="com.zhongzheng.modules.top.order.vo.TopOrderCustomerVo">
  2059. SELECT
  2060. too.old_customer_id as customerId,
  2061. ( SELECT purchase_org FROM v_top_order vto WHERE vto.old_customer_id = too.old_customer_id LIMIT 1 ) as customerName
  2062. FROM
  2063. v_top_order too
  2064. WHERE
  2065. too.`status` = 1
  2066. AND too.old_customer_id IS NOT NULL
  2067. GROUP BY
  2068. too.old_customer_id
  2069. </select>
  2070. <select id="getTenantDetailList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  2071. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
  2072. SELECT
  2073. vo.*,
  2074. st.tenant_name
  2075. FROM
  2076. (
  2077. SELECT
  2078. allu.tenant_id,
  2079. ANY_VALUE(allu.order_type) order_type,
  2080. SUM( allu.money2 ) money,
  2081. SUM(order_num2) order_num
  2082. <if test="tenantId != null and tenantId != ''">
  2083. , allu.create_sys_user_id,allu.create_username
  2084. </if>
  2085. FROM
  2086. (
  2087. SELECT
  2088. tenant_id,
  2089. 1 AS order_type,
  2090. SUM( order_received - order_refunded ) money2,
  2091. COUNT( * ) order_num2
  2092. <if test="tenantId != null and tenantId != ''">
  2093. , create_sys_user_id,any_value(create_username) as create_username
  2094. </if>
  2095. FROM
  2096. top_old_order too
  2097. WHERE
  2098. 1 = 1
  2099. AND `status` = 1
  2100. AND check_status = 1
  2101. AND old_customer_id IS NOT NULL
  2102. <if test="startTime != null and startTime != ''">
  2103. AND check_time &gt;= #{startTime}
  2104. </if>
  2105. <if test="endTime != null and endTime != ''">
  2106. AND check_time &lt;= #{endTime}
  2107. </if>
  2108. <if test="tenantId != null and tenantId != ''">
  2109. AND tenant_id = #{tenantId}
  2110. </if>
  2111. <if test="customerId != null and customerId != ''">
  2112. AND old_customer_id = #{customerId}
  2113. </if>
  2114. <if test="createSysUserId != null and createSysUserId != ''">
  2115. AND too.create_sys_user_id = #{createSysUserId}
  2116. </if>
  2117. <if test="businessName != null and businessName != ''">
  2118. AND (
  2119. SELECT
  2120. count(*)
  2121. FROM
  2122. (
  2123. SELECT
  2124. `otg`.`order_sn` AS `order_sn`,
  2125. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  2126. FROM
  2127. `top_old_order_goods` `otg`
  2128. ) ouu
  2129. WHERE
  2130. ouu.order_sn = too.order_sn
  2131. AND ouu.business_name = #{businessName}
  2132. ) >0
  2133. </if>
  2134. AND tenant_id IS NOT NULL
  2135. GROUP BY
  2136. tenant_id
  2137. <if test="tenantId != null and tenantId != ''">
  2138. , create_sys_user_id
  2139. </if>
  2140. UNION ALL
  2141. SELECT
  2142. og.tenant_id,
  2143. 2 AS order_type,
  2144. IFNULL( SUM( og.goods_received ), 0 ) money2,
  2145. COUNT(DISTINCT o.order_sn) order_num2
  2146. <if test="tenantId != null and tenantId != ''">
  2147. ,'' AS create_sys_user_id, '' as create_username
  2148. </if>
  2149. FROM
  2150. `order` o
  2151. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2152. WHERE
  2153. o.`status` = 1
  2154. AND o.order_status = 1
  2155. AND og.refund_status != 2
  2156. AND (
  2157. o.input_order_sn IS NULL
  2158. 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
  2159. <if test="startTime != null and startTime != ''">
  2160. AND o.create_time &gt;= #{startTime}
  2161. </if>
  2162. <if test="endTime != null and endTime != ''">
  2163. AND o.create_time &lt;= #{endTime}
  2164. </if>
  2165. <if test="tenantId != null and tenantId != ''">
  2166. AND o.tenant_id = #{tenantId}
  2167. </if>
  2168. <if test="customerId != null and customerId != ''">
  2169. AND o.tenant_id = #{customerId}
  2170. </if>
  2171. <if test="createSysUserId != null and createSysUserId != ''">
  2172. AND 1=0
  2173. </if>
  2174. <if test="businessName != null and businessName != ''">
  2175. AND (
  2176. SELECT
  2177. count(*)
  2178. FROM
  2179. (
  2180. SELECT
  2181. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  2182. g.goods_id
  2183. FROM
  2184. `goods` `g`
  2185. LEFT JOIN `course_education_type` `cet` ON `g`.`education_type_id` = `cet`.`id`
  2186. LEFT JOIN `course_project_type` `cpt` ON `g`.`project_id` = `cpt`.`id`
  2187. LEFT JOIN `course_business` `cb` ON `g`.`business_id` = `cb`.`id`
  2188. ) oug
  2189. WHERE
  2190. oug.goods_id = og.goods_id
  2191. AND oug.business_name = #{businessName}
  2192. )>0
  2193. </if>
  2194. AND o.tenant_id IS NOT NULL
  2195. AND og.pay_status != 1
  2196. GROUP BY
  2197. og.tenant_id
  2198. ) allu
  2199. GROUP BY
  2200. allu.tenant_id
  2201. <if test="tenantId != null and tenantId != ''">
  2202. , allu.create_sys_user_id,allu.create_username
  2203. </if>
  2204. ORDER BY
  2205. tenant_id DESC
  2206. ) vo
  2207. LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
  2208. </select>
  2209. <select id="getBusinessDetailList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
  2210. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
  2211. SELECT
  2212. allu.business_name,
  2213. SUM( allu.money ) money,
  2214. SUM( allu.order_num ) order_num
  2215. FROM
  2216. (
  2217. SELECT
  2218. ouu.business_name,
  2219. IFNULL( SUM( oo.order_received - oo.order_refunded ), 0 ) money,
  2220. 1 AS order_type,
  2221. COUNT( * ) order_num
  2222. FROM
  2223. (
  2224. SELECT
  2225. ou.order_sn,
  2226. ou.business_name
  2227. FROM
  2228. (
  2229. SELECT
  2230. `otg`.`order_sn` AS `order_sn`,
  2231. concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
  2232. FROM
  2233. `top_old_order_goods` `otg`
  2234. ) ou
  2235. GROUP BY
  2236. ou.order_sn,
  2237. ou.business_name
  2238. ) ouu
  2239. LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
  2240. WHERE
  2241. oo.`status` = 1
  2242. AND oo.check_status = 1
  2243. AND oo.old_customer_id IS NOT NULL
  2244. <if test="startTime != null and startTime != ''">
  2245. AND oo.check_time &gt;= #{startTime}
  2246. </if>
  2247. <if test="endTime != null and endTime != ''">
  2248. AND oo.check_time &lt;= #{endTime}
  2249. </if>
  2250. <if test="tenantId != null and tenantId != ''">
  2251. AND oo.tenant_id = #{tenantId}
  2252. </if>
  2253. <if test="createNo != null and createNo != ''">
  2254. AND oo.create_no = #{createNo}
  2255. </if>
  2256. <if test="createSysUserId != null and createSysUserId != ''">
  2257. AND oo.create_sys_user_id = #{createSysUserId}
  2258. </if>
  2259. <if test="businessName != null and businessName != ''">
  2260. AND ouu.business_name = #{businessName}
  2261. </if>
  2262. <if test="customerId != null and customerId != ''">
  2263. AND oo.old_customer_id = #{customerId}
  2264. </if>
  2265. GROUP BY
  2266. ouu.business_name UNION ALL
  2267. SELECT
  2268. nou.business_name,
  2269. SUM( nou.goods_received ) AS money,
  2270. 2 AS order_type,
  2271. COUNT(DISTINCT nou.order_sn ) order_num
  2272. FROM
  2273. (
  2274. SELECT
  2275. `og`.`order_sn` AS `order_sn`,
  2276. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  2277. og.goods_received
  2278. FROM
  2279. ((((
  2280. `order` o
  2281. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2282. LEFT JOIN `goods` `g` ON ((
  2283. `og`.`goods_id` = `g`.`goods_id`
  2284. )))
  2285. LEFT JOIN `course_education_type` `cet` ON ((
  2286. `g`.`education_type_id` = `cet`.`id`
  2287. )))
  2288. LEFT JOIN `course_project_type` `cpt` ON ((
  2289. `g`.`project_id` = `cpt`.`id`
  2290. )))
  2291. LEFT JOIN `course_business` `cb` ON ((
  2292. `g`.`business_id` = `cb`.`id`
  2293. )))
  2294. WHERE
  2295. og.pay_status != 1
  2296. AND (
  2297. o.input_order_sn IS NULL
  2298. 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
  2299. <if test="startTime != null and startTime != ''">
  2300. AND og.create_time &gt;= #{startTime}
  2301. </if>
  2302. <if test="endTime != null and endTime != ''">
  2303. AND og.create_time &lt;= #{endTime}
  2304. </if>
  2305. <if test="tenantId != null and tenantId != ''">
  2306. AND og.tenant_id = #{tenantId}
  2307. </if>
  2308. <if test="createNo != null and createNo != ''">
  2309. AND 1=0
  2310. </if>
  2311. <if test="createSysUserId != null and createSysUserId != ''">
  2312. AND 1=0
  2313. </if>
  2314. <if test="customerId != null and customerId != ''">
  2315. AND o.tenant_id = #{customerId}
  2316. </if>
  2317. AND og.refund_status != 2
  2318. ) nou
  2319. WHERE 1=1
  2320. <if test="businessName != null and businessName != ''">
  2321. AND nou.business_name = #{businessName}
  2322. </if>
  2323. GROUP BY
  2324. nou.business_name
  2325. ) allu
  2326. GROUP BY
  2327. allu.business_name
  2328. ORDER BY
  2329. order_num DESC
  2330. </select>
  2331. <select id="getStatisticsTenantView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  2332. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  2333. SELECT
  2334. COUNT(DISTINCT a.order_id) AS orderNum,
  2335. SUM(a.money) AS money,
  2336. any_value(a.timeStr) AS orderTime,
  2337. any_value(a.create_username) AS create_username,
  2338. any_value(a.tenant_name) AS tenant_name,
  2339. <if test="viewSign != null and viewSign == 1">
  2340. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
  2341. </if>
  2342. <if test="viewSign != null and viewSign == 2">
  2343. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
  2344. </if>
  2345. <if test="viewSign != null and viewSign == 3">
  2346. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
  2347. </if>
  2348. FROM (
  2349. SELECT
  2350. too.order_id as order_id,
  2351. too.check_time as timeStr,
  2352. too.order_received - too.order_refunded as money,
  2353. too.create_username,
  2354. st.tenant_name
  2355. FROM
  2356. top_old_order too LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  2357. WHERE
  2358. too.`status` = 1
  2359. AND too.check_status = 1
  2360. AND too.old_customer_id IS NOT NULL
  2361. <if test="startTime != null and startTime != ''">
  2362. AND too.check_time &gt;= #{startTime}
  2363. </if>
  2364. <if test="endTime != null and endTime != ''">
  2365. AND too.check_time &lt;= #{endTime}
  2366. </if>
  2367. <if test="tenantId != null and tenantId != ''">
  2368. AND too.tenant_id = #{tenantId}
  2369. </if>
  2370. <if test="createNo != null and createNo != ''">
  2371. AND too.create_no = #{createNo}
  2372. </if>
  2373. <if test="createSysUserId != null and createSysUserId != ''">
  2374. AND too.create_sys_user_id = #{createSysUserId}
  2375. </if>
  2376. UNION ALL
  2377. SELECT
  2378. o.order_id as order_id,
  2379. o.create_time as timeStr,
  2380. og.goods_received as money,
  2381. null as create_username,
  2382. st.tenant_name
  2383. FROM
  2384. `order` o
  2385. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2386. LEFT JOIN sys_tenant st ON o.tenant_id = st.tenant_id
  2387. WHERE
  2388. o.`status` = 1
  2389. AND o.order_status = 1
  2390. AND og.refund_status != 2
  2391. AND og.pay_status != 1
  2392. AND (
  2393. o.input_order_sn IS NULL
  2394. OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0
  2395. )
  2396. <if test="startTime != null and startTime != ''">
  2397. AND o.create_time &gt;= #{startTime}
  2398. </if>
  2399. <if test="endTime != null and endTime != ''">
  2400. AND o.create_time &lt;= #{endTime}
  2401. </if>
  2402. <if test="tenantId != null and tenantId != ''">
  2403. AND o.tenant_id = #{tenantId}
  2404. </if>
  2405. <if test="createSysUserId != null and createSysUserId != ''">
  2406. AND 1=0
  2407. </if>
  2408. ) a WHERE 1=1
  2409. <if test="viewSign != null and viewSign == 1">
  2410. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
  2411. </if>
  2412. <if test="viewSign != null and viewSign == 2">
  2413. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
  2414. </if>
  2415. <if test="viewSign != null and viewSign == 3">
  2416. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
  2417. </if>
  2418. ORDER BY timeStr
  2419. </select>
  2420. <select id="getStatisticsBusinessView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  2421. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  2422. SELECT
  2423. COUNT(a.order_sn) AS orderNum,
  2424. SUM(a.money) AS money,
  2425. any_value(a.timeStr) AS orderTime,
  2426. any_value(a.create_username) AS create_username,
  2427. any_value(a.tenant_name) AS tenant_name,
  2428. <if test="viewSign != null and viewSign == 1">
  2429. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
  2430. </if>
  2431. <if test="viewSign != null and viewSign == 2">
  2432. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
  2433. </if>
  2434. <if test="viewSign != null and viewSign == 3">
  2435. DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
  2436. </if>
  2437. FROM (
  2438. SELECT
  2439. too.order_sn,
  2440. concat(
  2441. substr(( SELECT otg.business_full_name FROM `top_old_order_goods` `otg` WHERE otg.order_sn = too.order_sn LIMIT 1 ), 5, 4 ),
  2442. '-',(
  2443. SELECT
  2444. otg.business_name
  2445. FROM
  2446. `top_old_order_goods` `otg`
  2447. WHERE
  2448. otg.order_sn = too.order_sn
  2449. LIMIT 1
  2450. )
  2451. ) AS `business_name`,
  2452. too.order_received - too.order_refunded AS money,
  2453. too.check_time as timeStr,
  2454. too.create_username,
  2455. st.tenant_name
  2456. FROM
  2457. top_old_order too
  2458. LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id
  2459. WHERE
  2460. too.`status` = 1
  2461. AND too.check_status = 1
  2462. <if test="startTime != null and startTime != ''">
  2463. AND too.check_time &gt;= #{startTime}
  2464. </if>
  2465. <if test="endTime != null and endTime != ''">
  2466. AND too.check_time &lt;= #{endTime}
  2467. </if>
  2468. <if test="tenantId != null and tenantId != ''">
  2469. AND too.tenant_id = #{tenantId}
  2470. </if>
  2471. <if test="createSysUserId != null and createSysUserId != ''">
  2472. AND too.create_sys_user_id = #{createSysUserId}
  2473. </if>
  2474. UNION ALL
  2475. SELECT
  2476. `og`.`order_sn` AS `order_sn`,
  2477. concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
  2478. og.goods_received as money,
  2479. og.create_time as timeStr,
  2480. null as create_username,
  2481. st.tenant_name
  2482. FROM
  2483. ((((
  2484. `order` o
  2485. LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
  2486. LEFT JOIN sys_tenant st ON o.tenant_id = st.tenant_id
  2487. LEFT JOIN `goods` `g` ON ((
  2488. `og`.`goods_id` = `g`.`goods_id`
  2489. )))
  2490. LEFT JOIN `course_education_type` `cet` ON ((
  2491. `g`.`education_type_id` = `cet`.`id`
  2492. )))
  2493. LEFT JOIN `course_project_type` `cpt` ON ((
  2494. `g`.`project_id` = `cpt`.`id`
  2495. )))
  2496. LEFT JOIN `course_business` `cb` ON ((
  2497. `g`.`business_id` = `cb`.`id`
  2498. )))
  2499. WHERE
  2500. og.pay_status != 1
  2501. AND (
  2502. o.input_order_sn IS NULL
  2503. 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
  2504. <if test="startTime != null and startTime != ''">
  2505. AND og.create_time &gt;= #{startTime}
  2506. </if>
  2507. <if test="endTime != null and endTime != ''">
  2508. AND og.create_time &lt;= #{endTime}
  2509. </if>
  2510. <if test="tenantId != null and tenantId != ''">
  2511. AND og.tenant_id = #{tenantId}
  2512. </if>
  2513. <if test="createSysUserId != null and createSysUserId != ''">
  2514. AND 1=0
  2515. </if>
  2516. <if test="customerId != null and customerId != ''">
  2517. AND og.tenant_id = #{customerId}
  2518. </if>
  2519. AND og.refund_status != 2
  2520. ) a WHERE 1=1
  2521. <if test="businessName != null and businessName != ''">
  2522. AND a.business_name = #{businessName}
  2523. </if>
  2524. <if test="viewSign != null and viewSign == 1">
  2525. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
  2526. </if>
  2527. <if test="viewSign != null and viewSign == 2">
  2528. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
  2529. </if>
  2530. <if test="viewSign != null and viewSign == 3">
  2531. GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
  2532. </if>
  2533. </select>
  2534. <select id="getTenantCreateList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
  2535. resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
  2536. SELECT
  2537. create_username,
  2538. create_sys_user_id
  2539. FROM
  2540. top_old_order
  2541. WHERE
  2542. 1=1
  2543. <if test="tenantId != null and tenantId != ''">
  2544. AND tenant_id = #{tenantId}
  2545. </if>
  2546. AND create_sys_user_id IS NOT NULL
  2547. GROUP BY
  2548. create_sys_user_id,
  2549. create_username
  2550. </select>
  2551. </mapper>