TopOldOrderMapper.xml 97 KB

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