TopOldOrderMapper.xml 98 KB

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