TopOldOrderMapper.xml 100 KB

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