TopOldOrderMapper.xml 85 KB

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