TopOldOrderMapper.xml 99 KB

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