TradeOrderMapper.xml 144 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.yc.ship.module.trade.dal.mysql.order.TradeOrderMapper">
  4. <resultMap id="MiddleWareDtoResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  5. <id property="id" column="id"/>
  6. <result property="orderNo" column="order_no"/>
  7. <result property="voyageId" column="voyage_id"/>
  8. <result property="bindId" column="bindId"/>
  9. <result property="isRead" column="isRead"/>
  10. <result property="sourceName" column="source_name"/>
  11. <result property="externalOrderNo" column="external_order_no"/>
  12. <result property="routePlanId" column="route_plan_id"/>
  13. <result property="routePlanName" column="route_plan_name"/>
  14. <result property="visitorType" column="visitor_type"/>
  15. <result property="travelDate" column="travel_date"/>
  16. <result property="sellMethod" column="sell_method"/>
  17. <result property="sourceName" column="source_name"/>
  18. <result property="sellerId" column="seller_id"/>
  19. <result property="memberId" column="member_id"/>
  20. <result property="amount" column="amount"/>
  21. <result property="payAmount" column="pay_amount"/>
  22. <result property="paymentStatus" column="pay_status"/>
  23. <result property="paymentType" column="payment_type"/>
  24. <result property="orderStatus" column="order_status"/>
  25. <result property="paymentDate" column="payment_date"/>
  26. <result property="areaManagerId" column="area_manager_id"/>
  27. <result property="storeName" column="store_name"/>
  28. <result property="contactName" column="contactName"/>
  29. <result property="shareName" column="share_name"/>
  30. <result property="isBind" column="is_bind"/>
  31. <result property="credentialNo" column="credentialNo"/>
  32. <result property="city" column="city"/>
  33. <result property="province" column="province"/>
  34. <result property="county" column="county"/>
  35. <result property="createTime" column="create_time"/>
  36. <result property="mobile" column="mobile"/>
  37. <result property="auditState" column="audit_state"/>
  38. <result property="storeId" column="store_id"/>
  39. <result property="sourceId" column="source_id"/>
  40. <result property="isMarketing" column="is_marketing"/>
  41. <result property="isMarketingUse" column="is_marketing_use"/>
  42. <result property="remark" column="remark"/>
  43. <result property="dispatchStatus" column="dispatch_status"/>
  44. <result property="isInvoice" column="is_invoice"/>
  45. <result property="isChangeOrder" column="is_change_order"/>
  46. <result property="refundAmount" column="refund_amount"/>
  47. <result property="confirmType" column="confirm_type"/>
  48. <result property="travelStatus" column="travel_status"/>
  49. <result property="finishStatus" column="finish_status"/>
  50. <result property="agencyGroupId" column="agency_group_id"/>
  51. <collection property="orderPayList" resultMap="orderPayList"/>
  52. <collection property="insuranceList" resultMap="insuranceResultMap"/>
  53. <collection property="contractList" resultMap="contractResultMap"/>
  54. </resultMap>
  55. <resultMap id="MiddleWareDtoResultMap2" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderPdaRespVO">
  56. <id property="id" column="id"/>
  57. <result property="orderNo" column="order_no"/>
  58. <result property="bindId" column="bindId"/>
  59. <result property="isRead" column="isRead"/>
  60. <result property="sourceName" column="source_name"/>
  61. <result property="externalOrderNo" column="external_order_no"/>
  62. <result property="routePlanId" column="route_plan_id"/>
  63. <result property="routePlanName" column="route_plan_name"/>
  64. <result property="visitorType" column="visitor_type"/>
  65. <result property="travelDate" column="travel_date"/>
  66. <result property="sellMethod" column="sell_method"/>
  67. <result property="sourceName" column="source_name"/>
  68. <result property="sellerId" column="seller_id"/>
  69. <result property="memberId" column="member_id"/>
  70. <result property="amount" column="amount"/>
  71. <result property="payAmount" column="pay_amount"/>
  72. <result property="paymentStatus" column="pay_status"/>
  73. <result property="paymentType" column="payment_type"/>
  74. <result property="orderStatus" column="order_status"/>
  75. <result property="paymentDate" column="payment_date"/>
  76. <result property="areaManagerId" column="area_manager_id"/>
  77. <result property="storeName" column="store_name"/>
  78. <result property="contactName" column="contactName"/>
  79. <result property="shareName" column="share_name"/>
  80. <result property="isBind" column="is_bind"/>
  81. <result property="credentialNo" column="credentialNo"/>
  82. <result property="city" column="city"/>
  83. <result property="province" column="province"/>
  84. <result property="county" column="county"/>
  85. <result property="createTime" column="create_time"/>
  86. <result property="mobile" column="mobile"/>
  87. <result property="auditState" column="audit_state"/>
  88. <result property="storeId" column="store_id"/>
  89. <result property="sourceId" column="source_id"/>
  90. <result property="isMarketing" column="is_marketing"/>
  91. <result property="isMarketingUse" column="is_marketing_use"/>
  92. <result property="remark" column="remark"/>
  93. <result property="dispatchStatus" column="dispatch_status"/>
  94. <result property="isInvoice" column="is_invoice"/>
  95. <result property="isChangeOrder" column="is_change_order"/>
  96. <result property="refundAmount" column="refund_amount"/>
  97. <result property="confirmType" column="confirm_type"/>
  98. <result property="travelStatus" column="travel_status"/>
  99. <result property="finishStatus" column="finish_status"/>
  100. <result property="agencyGroupId" column="agency_group_id"/>
  101. <collection property="orderPayList" resultMap="orderPayList"/>
  102. <collection property="insuranceList" resultMap="insuranceResultMap"/>
  103. <collection property="contractList" resultMap="contractResultMap"/>
  104. </resultMap>
  105. <resultMap id="orderPayList" type="com.yc.ship.module.trade.api.dto.TradeOrderPayDTO">
  106. <id property="id" column="payId"/>
  107. <result property="orderId" column="id"/>
  108. <result property="payAmount" column="payAmount"/>
  109. <result property="paymentNo" column="payment_no"/>
  110. <result property="payStatus" column="pay_status"/>
  111. <result property="paymentType" column="payment_type"/>
  112. <result property="paymentDate" column="payment_date"/>
  113. </resultMap>
  114. <resultMap id="insuranceResultMap" type="com.yc.ship.module.trade.dal.dataobject.insurance.InsuranceDO">
  115. <id property="id" column="insuranceId"/>
  116. <result property="orderId" column="id"/>
  117. <result property="policyNo" column="policy_no"/>
  118. <result property="proposalNo" column="proposal_no"/>
  119. <result property="insuranceNo" column="insurance_no"/>
  120. <result property="insuranceStatus" column="insurance_status"/>
  121. <result property="insuredNum" column="insured_num"/>
  122. <result property="insuranceEffectDate" column="insurance_effect_date"/>
  123. <result property="electronicPolicy" column="electronic_policy"/>
  124. </resultMap>
  125. <resultMap id="contractResultMap" type="com.yc.ship.module.trade.dal.dataobject.contract.ContractDO">
  126. <id property="id" column="contractId"/>
  127. <result property="orderId" column="id"/>
  128. <result property="contractNo" column="contract_no"/>
  129. <result property="status" column="status"/>
  130. <result property="touristsCount" column="tourists_count"/>
  131. <result property="contractUrl" column="contract_url"/>
  132. <result property="operateName" column="operate_name"/>
  133. <result property="signerName" column="signer_name"/>
  134. <result property="signerMobile" column="signer_mobile"/>
  135. <result property="signingTime" column="signing_time"/>
  136. <result property="signingUrl" column="signing_url"/>
  137. <result property="viewUrl" column="view_url"/>
  138. </resultMap>
  139. <resultMap id="RefundResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  140. <id property="id" column="id"/>
  141. <result property="orderNo" column="order_no"/>
  142. <result property="sourceName" column="source_name"/>
  143. <result property="externalOrderNo" column="external_order_no"/>
  144. <result property="routePlanId" column="route_plan_id"/>
  145. <result property="visitorType" column="visitor_type"/>
  146. <result property="travelDate" column="travel_date"/>
  147. <result property="sellMethod" column="sell_method"/>
  148. <result property="sourceName" column="source_name"/>
  149. <result property="sellerId" column="seller_id"/>
  150. <result property="memberId" column="member_id"/>
  151. <result property="amount" column="amount"/>
  152. <result property="payAmount" column="pay_amount"/>
  153. <result property="orderStatus" column="order_status"/>
  154. <result property="paymentDate" column="payment_date"/>
  155. <result property="contactName" column="contact_name"/>
  156. <result property="credentialNo" column="credential_no"/>
  157. <result property="mobile" column="mobile"/>
  158. <result property="remark" column="remark"/>
  159. <collection property="tradeDetailList" resultMap="tradeDetailResultMap"/>
  160. </resultMap>
  161. <resultMap id="tradeDetailResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  162. <id property="orderId" column="id"/>
  163. <result property="id" column="detailId"/>
  164. <result property="voucherCode" column="voucher_code"/>
  165. <result property="voucherStatus" column="voucher_status"/>
  166. <result property="productName" column="product_name"/>
  167. <result property="specType" column="spec_type"/>
  168. <collection property="visitors" resultMap="visitorResultMap"/>
  169. </resultMap>
  170. <resultMap id="visitorResultMap" type="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  171. <id property="detailId" column="detailId"/>
  172. <result property="id" column="visitorId"/>
  173. <result property="credentialNo" column="credential_no"/>
  174. <result property="credentialType" column="credential_type"/>
  175. <result property="name" column="name"/>
  176. </resultMap>
  177. <select id="getCategoryTreeList" resultType="com.yc.ship.module.product.api.dto.CategoryRespDTO">
  178. SELECT id,parent_id parentId,cate_name cateName,sort_num sortNum from product_category WHERE type = 1 AND use_status = 1 AND deleted = 0 AND tenant_id = #{tenantId} order by sort_num
  179. </select>
  180. <select id="getCategoryOTATreeList" resultType="com.yc.ship.module.product.api.dto.CategoryRespDTO">
  181. SELECT id,parent_id parentId,cate_name cateName,sort_num sortNum from product_category WHERE type = 1 AND use_status = 1 AND deleted = 0
  182. </select>
  183. <select id="selectTouristExportHead"
  184. resultType="java.util.Map">
  185. SELECT
  186. SUM(a.num) AS totalOrders,
  187. SUM(a.num1) AS adultNum,
  188. SUM(a.num2) AS childBabyNum,
  189. SUM(a.num3) AS withNum,
  190. SUM(a.num4) AS leaderNum,
  191. SUM(a.num5) AS babyNum,
  192. SUM(a.payAmount) AS totalPayAmount,
  193. SUM(a.actual_amount) AS totalActualAmount,
  194. SUM(a.deposi) as deposi,
  195. IFNULL((
  196. SELECT GROUP_CONCAT(CONCAT( nationalityName, '(', num, ')') SEPARATOR ' ')
  197. FROM (
  198. SELECT
  199. IFNULL(NULLIF(tv.nationality, ''), 1) AS nationalityCode,
  200. IFNULL(NULLIF(ar.name, ''), '中国') AS nationalityName,
  201. COUNT(1) AS num
  202. FROM trade_order td
  203. INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
  204. LEFT JOIN trade_visitor tv ON td.id = tv.order_id AND tv.deleted = 0
  205. LEFT JOIN trade_detail tdl ON tv.detail_id = tdl.id AND tdl.deleted = 0
  206. LEFT JOIN trade_order_room_model torm ON tv.room_index_id = torm.room_index_id AND torm.deleted = 0 AND td.id = torm.order_id
  207. LEFT JOIN resource_room_model rrm ON torm.room_model_id = rrm.id
  208. LEFT JOIN product_spu ps ON ps.id = tdl.product_id
  209. LEFT JOIN ota_distributor od ON od.id = td.source_id
  210. LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2 where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
  211. LEFT JOIN area ar ON tv.nationality = ar.id
  212. WHERE td.deleted = 0
  213. AND tou.deleted = 0
  214. AND tv.type IS NOT NULL
  215. <include refid="commonWhereConditions"/>
  216. GROUP BY nationalityCode
  217. ) nationality_stats
  218. ), '') AS nationalityStats,
  219. IFNULL((
  220. SELECT GROUP_CONCAT(CONCAT(roomName, '(', roomNum, ')') SEPARATOR ',')
  221. FROM (
  222. SELECT
  223. CONCAT(rrm.name, torm.floor, 'F') AS roomName,
  224. torm.floor AS floor,
  225. COUNT(DISTINCT torm.room_index_id) AS roomNum
  226. FROM trade_order td
  227. INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
  228. LEFT JOIN trade_visitor tv ON td.id = tv.order_id AND tv.deleted = 0
  229. LEFT JOIN trade_detail tdl ON tv.detail_id = tdl.id AND tdl.deleted = 0
  230. LEFT JOIN trade_order_room_model torm ON tv.room_index_id = torm.room_index_id AND torm.deleted = 0 AND td.id = torm.order_id
  231. LEFT JOIN resource_room_model rrm ON torm.room_model_id = rrm.id
  232. LEFT JOIN product_spu ps ON ps.id = tdl.product_id
  233. LEFT JOIN ota_distributor od ON od.id = td.source_id
  234. LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2 where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
  235. WHERE td.deleted = 0
  236. AND tou.deleted = 0
  237. AND tv.type IS NOT NULL
  238. <include refid="commonWhereConditions"/>
  239. GROUP BY rrm.name, torm.floor
  240. ORDER BY torm.floor
  241. ) room_stats
  242. ), '') AS roomStats,
  243. (
  244. SELECT COUNT(DISTINCT torm.room_index_id)
  245. FROM trade_order td
  246. INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
  247. LEFT JOIN trade_visitor tv ON td.id = tv.order_id AND tv.deleted = 0
  248. LEFT JOIN trade_detail tdl ON tv.detail_id = tdl.id AND tdl.deleted = 0
  249. LEFT JOIN trade_order_room_model torm ON tv.room_index_id = torm.room_index_id AND torm.deleted = 0 AND td.id = torm.order_id
  250. LEFT JOIN resource_room_model rrm ON torm.room_model_id = rrm.id
  251. LEFT JOIN product_spu ps ON ps.id = tdl.product_id
  252. LEFT JOIN ota_distributor od ON od.id = td.source_id
  253. LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2 where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
  254. WHERE td.deleted = 0
  255. AND tou.deleted = 0
  256. AND tv.type IS NOT NULL
  257. <include refid="commonWhereConditions"/>
  258. ) AS totalRooms
  259. FROM (
  260. SELECT
  261. COUNT(1) AS num,
  262. SUM(CASE WHEN tv.type IN ('adultPlus', 'adultTake') or tv.type IS NULL or tv.type = '' THEN 1 ELSE 0 END) AS num1,
  263. SUM(CASE WHEN tv.type IN ('childTake','childPlus','childNonTake') THEN 1 ELSE 0 END) AS num2,
  264. SUM(CASE WHEN tv.type = 'with' THEN 1 ELSE 0 END) AS num3,
  265. SUM(CASE WHEN tv.type = 'leader' THEN 1 ELSE 0 END) AS num4,
  266. SUM(CASE WHEN tv.type IN ('babyTake','babyPlus','babyNonTake') THEN 1 ELSE 0 END) AS num5,
  267. td.pay_amount AS payAmount,
  268. td.deposi,
  269. IFNULL(topay.actual_amount, 0) AS actual_amount
  270. FROM trade_order td
  271. INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
  272. LEFT JOIN trade_visitor tv ON td.id = tv.order_id AND tv.deleted = 0
  273. LEFT JOIN trade_detail tdl ON tv.detail_id = tdl.id AND tdl.deleted = 0
  274. LEFT JOIN product_spu ps ON ps.id = tdl.product_id
  275. LEFT JOIN ota_distributor od ON od.id = td.source_id
  276. LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2 where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
  277. left join trade_order_room_model torm on tv.room_index_id = torm.room_index_id and torm.deleted =0 AND td.id = torm.order_id
  278. LEFT JOIN (
  279. SELECT order_id, SUM(pay_amount) AS actual_amount
  280. FROM trade_order_pay
  281. WHERE pay_status = 1 or order_type = 2
  282. GROUP BY order_id
  283. ) topay ON td.id = topay.order_id
  284. WHERE
  285. td.deleted = 0
  286. AND tv.type IS NOT NULL
  287. <include refid="commonWhereConditions"/>
  288. GROUP BY td.id, td.pay_amount) a
  289. </select>
  290. <!-- 公共查询条件 -->
  291. <sql id="commonWhereConditions">
  292. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  293. AND td.order_status IN
  294. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  295. #{item}
  296. </foreach>
  297. </if>
  298. <if test="vo.tenantId!=null">
  299. AND td.tenant_id = #{vo.tenantId}
  300. </if>
  301. <choose>
  302. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  303. AND td.order_no LIKE CONCAT('%',#{vo.orderNo})
  304. </when>
  305. <when test="vo.orderNo != null and vo.orderNo != ''">
  306. AND td.order_no = #{vo.orderNo}
  307. </when>
  308. <otherwise>
  309. </otherwise>
  310. </choose>
  311. <if test="vo.memberId != null and vo.memberId != ''">
  312. AND td.member_id = #{vo.memberId}
  313. </if>
  314. <if test="vo.voyageId != null and vo.voyageId != ''">
  315. AND td.voyage_id = #{vo.voyageId}
  316. </if>
  317. <if test="vo.shipId != null and vo.shipId != ''">
  318. AND td.ship_id = #{vo.shipId}
  319. </if>
  320. <if test="vo.routeId != null and vo.routeId != ''">
  321. AND EXISTS (SELECT 1 FROM product_voyage top WHERE top.id = td.voyage_id AND top.route_id = #{vo.routeId})
  322. </if>
  323. <if test="vo.dispatchStatus != null">
  324. AND td.dispatch_status = #{vo.dispatchStatus}
  325. </if>
  326. <if test="vo.payType != null">
  327. AND EXISTS (SELECT 1 FROM trade_order_pay top WHERE top.order_id = td.id AND top.payment_type = #{vo.payType})
  328. </if>
  329. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  330. AND od.ota_category_id = #{vo.otaCateId}
  331. </if>
  332. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  333. AND od.ota_category_id IN
  334. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  335. #{item}
  336. </foreach>
  337. </if>
  338. <if test="vo.otaId != null and vo.otaId != ''">
  339. AND td.source_id = #{vo.otaId}
  340. </if>
  341. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  342. AND td.source_id IN
  343. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  344. #{item}
  345. </foreach>
  346. </if>
  347. <if test="vo.storeId != null and vo.storeId != ''">
  348. AND td.store_id = #{vo.storeId}
  349. </if>
  350. <if test="vo.productTag != null and vo.productTag != ''">
  351. AND ps.product_tag = #{vo.productTag}
  352. </if>
  353. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  354. AND ps.product_tag2 = #{vo.productTag2}
  355. </if>
  356. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  357. AND ps.product_tag3 = #{vo.productTag3}
  358. </if>
  359. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  360. AND ps.product_tag4 = #{vo.productTag4}
  361. </if>
  362. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  363. AND tdl.product_id IN
  364. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  365. #{item}
  366. </foreach>
  367. </if>
  368. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  369. AND td.external_order_no = #{vo.externalOrderNo}
  370. </if>
  371. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  372. AND EXISTS (SELECT tv.id FROM trade_visitor tv WHERE tv.detail_id = tdl.id AND tv.credential_no = #{vo.credentialNo})
  373. </if>
  374. <if test="vo.userName != null and vo.userName != ''">
  375. AND EXISTS (SELECT tv.id FROM trade_visitor tv WHERE tv.detail_id = tdl.id AND tv.name = #{vo.userName})
  376. </if>
  377. <choose>
  378. <when test="vo.mobile != null and vo.mobile.length() == 4">
  379. AND tou.mobile LIKE CONCAT('%',#{vo.mobile})
  380. </when>
  381. <when test="vo.mobile != null and vo.mobile != ''">
  382. AND tou.mobile = #{vo.mobile}
  383. </when>
  384. <otherwise>
  385. </otherwise>
  386. </choose>
  387. <if test="vo.contactName != null and vo.contactName != ''">
  388. AND tou.contact_name = #{vo.contactName}
  389. </if>
  390. <if test="vo.travelDate != null and vo.travelDate != ''">
  391. AND td.travel_date = #{vo.travelDate}
  392. </if>
  393. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  394. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  395. </if>
  396. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  397. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  398. </if>
  399. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  400. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  401. </if>
  402. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  403. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  404. </if>
  405. <if test="vo.orderDate != null and vo.orderDate != ''">
  406. AND td.create_time = #{vo.orderDate}
  407. </if>
  408. <if test="vo.sellerId != null and vo.sellerId != ''">
  409. AND td.seller_id = #{vo.sellerId}
  410. </if>
  411. <if test="vo.shareName != null and vo.shareName != ''">
  412. AND td.share_name LIKE CONCAT('%',#{vo.shareName},'%')
  413. </if>
  414. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  415. AND tdl.voucher_code = #{vo.voucherCode}
  416. </if>
  417. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  418. AND td.sell_method = #{vo.sellMethod}
  419. </if>
  420. <if test="vo.productName != null and vo.productName != ''">
  421. AND tdl.product_name LIKE CONCAT('%',#{vo.productName}, '%')
  422. </if>
  423. <if test="vo.isFullPay == 0">
  424. AND td.is_full_pay = #{vo.isFullPay}
  425. </if>
  426. <if test="vo.isComment != null">
  427. AND td.is_comment = #{vo.isComment}
  428. </if>
  429. <if test="vo.sourceId != null and vo.sourceId != ''">
  430. AND td.source_id = #{vo.sourceId}
  431. </if>
  432. <if test="vo.distributorId != null and vo.distributorId != ''">
  433. AND td.source_id = #{vo.distributorId}
  434. </if>
  435. <if test="vo.sourceName != null and vo.sourceName != ''">
  436. AND td.source_name LIKE CONCAT('%',#{vo.sourceName}, '%')
  437. </if>
  438. <if test="vo.travelStatus != null">
  439. AND td.travel_status = #{vo.travelStatus}
  440. </if>
  441. <if test="vo.roomModelId != null and vo.roomModelId != ''">
  442. AND torm.room_model_id = #{vo.roomModelId}
  443. </if>
  444. <if test="vo.floor != null and vo.floor != ''">
  445. AND torm.floor = #{vo.floor}
  446. </if>
  447. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  448. AND EXISTS (SELECT 1 FROM trade_refund tr WHERE tr.order_id=td.id AND tr.refund_status = 6 AND tr.refund_time BETWEEN #{vo.orderRefundDateStart} and #{vo.orderRefundDateEnd})
  449. </if>
  450. </sql>
  451. <select id="getDailyBusinessStatisticsPage"
  452. resultType="com.yc.ship.module.trade.controller.admin.business.vo.DailyBusinessStatisticsRespVO">
  453. select t.sourceId,
  454. t.sourceName,
  455. sum(t.freeNum) as freeNum,
  456. sum(t.freeCount) as freeCount,
  457. sum(t.actualAmount) as actualAmount,
  458. sum(t.totalCount) as totalCount,
  459. SUM(t.adultCount) AS adultCount,
  460. SUM(t.childCount) AS childCount,
  461. SUM(t.withCount) AS withCount,
  462. SUM(t.leaderCount) AS leaderCount,
  463. SUM(t.infantCount) AS infantCount,
  464. sum(t.validCount) as validCount from (SELECT
  465. DISTINCT td.id,
  466. td.source_id AS sourceId,
  467. td.source_name as sourceName,
  468. IFNULL(tot.free_num, 0) AS freeNum,
  469. CASE WHEN td.source_id IN ('2039225917977522177', '2041321150626263042','2042951563081805826') THEN COUNT(1) ELSE 0 END AS freeCount,
  470. IFNULL(topay.actual_amount, 0) AS actualAmount,
  471. COUNT(1) AS totalCount,
  472. SUM(CASE WHEN tv.type IN ('adultPlus', 'adultTake') THEN 1 ELSE 0 END) AS adultCount,
  473. SUM(CASE WHEN tv.type IN ('childTake','childPlus','childNonTake') THEN 1 ELSE 0 END) AS childCount,
  474. SUM(CASE WHEN tv.type = 'with' THEN 1 ELSE 0 END) AS withCount,
  475. SUM(CASE WHEN tv.type = 'leader' THEN 1 ELSE 0 END) AS leaderCount,
  476. SUM(CASE WHEN tv.type IN ('babyTake','babyPlus','babyNonTake') THEN 1 ELSE 0 END) AS infantCount,
  477. COUNT(1) - IFNULL(tot.free_num, 0) - CASE
  478. WHEN td.source_id IN ('2039225917977522177', '2041321150626263042', '2042951563081805826')
  479. THEN COUNT(1)
  480. ELSE 0
  481. END AS validCount
  482. FROM trade_order td
  483. INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
  484. LEFT JOIN trade_detail tdl ON td.id = tdl.order_id AND tdl.deleted = 0
  485. LEFT JOIN trade_visitor tv ON tdl.id = tv.detail_id AND tv.deleted = 0
  486. left join trade_order_total tot on td.id = tot.old_order_id and tot.deleted = 0
  487. LEFT JOIN (SELECT order_id, SUM(pay_amount) AS actual_amount
  488. FROM trade_order_pay
  489. WHERE pay_status = 1 and deleted=0 GROUP BY order_id) topay ON td.id = topay.order_id
  490. WHERE
  491. td.deleted = 0
  492. AND tv.type IS NOT NULL
  493. AND td.order_status in (1, 6, 9, 10, 13, 14, 15)
  494. <if test="vo.voyageId != null and vo.voyageId != ''">
  495. AND td.voyage_id = #{vo.voyageId}
  496. </if>
  497. <if test="vo.routeId != null and vo.routeId != ''">
  498. AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
  499. </if>
  500. GROUP BY td.id) t GROUP BY t.sourceId;
  501. </select>
  502. <select id="findOrderIdsByCondition" resultType="java.lang.Long">
  503. SELECT DISTINCT td.id
  504. FROM trade_order td
  505. INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
  506. LEFT JOIN trade_detail tdl ON td.id = tdl.order_id AND tdl.deleted = 0
  507. LEFT JOIN product_spu ps ON ps.id = tdl.product_id and ps.deleted=0
  508. LEFT JOIN ota_distributor od ON od.id = td.source_id and od.deleted=0
  509. LEFT JOIN product_voyage pv ON pv.id = td.voyage_id and pv.deleted=0
  510. <if test="vo.categoryIds != null and vo.categoryIds.size() > 0">
  511. INNER JOIN ota_distributor_category_his his
  512. ON his.distributor_id = od.id
  513. AND his.deleted = 0
  514. AND pv.boarding_time <![CDATA[ >= ]]> his.start_time
  515. /*AND pv.boarding_time <![CDATA[ <= ]]> IFNULL(his.end_time, NOW())*/
  516. AND (his.end_time IS NULL OR pv.boarding_time <![CDATA[ <= ]]> his.end_time)
  517. AND his.ota_category_id IN
  518. <foreach collection="vo.categoryIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  519. </if>
  520. LEFT JOIN trade_order_room_model torm ON torm.order_id = td.id and torm.deleted=0
  521. WHERE td.deleted = 0
  522. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  523. and td.order_status in
  524. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  525. #{item}
  526. </foreach>
  527. </if>
  528. <if test="vo.tenantId!=null">
  529. AND td.tenant_id = #{vo.tenantId}
  530. </if>
  531. <choose>
  532. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  533. AND td.order_no like concat('%',#{vo.orderNo})
  534. </when>
  535. <when test="vo.orderNo != null and vo.orderNo != ''">
  536. AND td.order_no = #{vo.orderNo}
  537. </when>
  538. <otherwise>
  539. </otherwise>
  540. </choose>
  541. <if test="vo.memberId != null and vo.memberId != ''">
  542. AND td.member_id = #{vo.memberId}
  543. </if>
  544. <if test="vo.voyageId != null and vo.voyageId != ''">
  545. AND td.voyage_id = #{vo.voyageId}
  546. </if>
  547. <if test="vo.shipId != null and vo.shipId != ''">
  548. AND td.ship_id = #{vo.shipId}
  549. </if>
  550. <if test="vo.routeId != null and vo.routeId != ''">
  551. AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
  552. </if>
  553. <if test="vo.dispatchStatus != null">
  554. AND td.dispatch_status = #{vo.dispatchStatus}
  555. </if>
  556. <if test="vo.payType != null">
  557. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  558. </if>
  559. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  560. AND od.ota_category_id = #{vo.otaCateId}
  561. </if>
  562. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  563. and od.ota_category_id in
  564. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  565. #{item}
  566. </foreach>
  567. </if>
  568. <if test="vo.otaId != null and vo.otaId != ''">
  569. AND td.source_id = #{vo.otaId}
  570. </if>
  571. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  572. AND td.source_id IN
  573. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  574. #{item}
  575. </foreach>
  576. </if>
  577. <if test="vo.storeId != null and vo.storeId != ''">
  578. AND td.store_id = #{vo.storeId}
  579. </if>
  580. <if test="vo.productTag != null and vo.productTag != ''">
  581. AND ps.product_tag = #{vo.productTag}
  582. </if>
  583. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  584. AND ps.product_tag2 = #{vo.productTag2}
  585. </if>
  586. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  587. AND ps.product_tag3 = #{vo.productTag3}
  588. </if>
  589. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  590. AND ps.product_tag4 = #{vo.productTag4}
  591. </if>
  592. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  593. AND tdl.product_id in
  594. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  595. #{item}
  596. </foreach>
  597. </if>
  598. <if test="vo.additiveIds!=null and vo.additiveIds.size()>0">
  599. and tdl.product_id in
  600. <foreach collection="vo.additiveIds" item="item" separator="," open="(" close=")">
  601. #{item}
  602. </foreach>
  603. </if>
  604. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  605. AND td.external_order_no = #{vo.externalOrderNo}
  606. </if>
  607. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  608. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  609. </if>
  610. <if test="vo.userName != null and vo.userName != ''">
  611. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  612. </if>
  613. <choose>
  614. <when test="vo.mobile != null and vo.mobile.length() == 4">
  615. AND tou.mobile like concat('%',#{vo.mobile})
  616. </when>
  617. <when test="vo.mobile != null and vo.mobile != ''">
  618. AND tou.mobile = #{vo.mobile}
  619. </when>
  620. <otherwise>
  621. </otherwise>
  622. </choose>
  623. <if test="vo.contactName != null and vo.contactName != ''">
  624. AND tou.contact_name = #{vo.contactName}
  625. </if>
  626. <if test="vo.travelDate != null and vo.travelDate != ''">
  627. AND td.travel_date = #{vo.travelDate}
  628. </if>
  629. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  630. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  631. </if>
  632. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  633. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  634. </if>
  635. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  636. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  637. </if>
  638. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  639. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  640. </if>
  641. <if test="vo.orderDate != null and vo.orderDate != ''">
  642. AND td.create_time = #{vo.orderDate}
  643. </if>
  644. <if test="vo.sellerId != null and vo.sellerId != ''">
  645. AND td.seller_id = #{vo.sellerId}
  646. </if>
  647. <if test="vo.shareName != null and vo.shareName != ''">
  648. AND td.share_name like concat('%',#{vo.shareName},'%')
  649. </if>
  650. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  651. AND tdl.voucher_code = #{vo.voucherCode}
  652. </if>
  653. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  654. AND td.sell_method = #{vo.sellMethod}
  655. </if>
  656. <if test="vo.productName != null and vo.productName != ''">
  657. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  658. </if>
  659. <if test="vo.isFullPay == 0">
  660. AND td.is_full_pay = #{vo.isFullPay}
  661. </if>
  662. <if test="vo.isComment != null">
  663. AND td.is_comment = #{vo.isComment}
  664. </if>
  665. <if test="vo.sourceId != null and vo.sourceId != ''">
  666. AND td.source_id = #{vo.sourceId}
  667. </if>
  668. <if test="vo.paymentStatus != null">
  669. AND td.pay_status = #{vo.paymentStatus}
  670. </if>
  671. <if test="vo.distributorId != null and vo.distributorId != ''">
  672. AND td.source_id = #{vo.distributorId}
  673. </if>
  674. <if test="vo.sourceName != null and vo.sourceName != ''">
  675. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  676. </if>
  677. <if test="vo.travelStatus != null">
  678. AND td.travel_status = #{vo.travelStatus}
  679. </if>
  680. <if test="vo.roomModelId != null and vo.roomModelId != ''">
  681. AND torm.room_model_id = #{vo.roomModelId}
  682. </if>
  683. <if test="vo.roomModelIds!=null and vo.roomModelIds.size()>0">
  684. and torm.room_model_id in
  685. <foreach collection="vo.roomModelIds" item="item" separator="," open="(" close=")">
  686. #{item}
  687. </foreach>
  688. </if>
  689. <if test="vo.floor != null and vo.floor != ''">
  690. AND torm.floor = #{vo.floor}
  691. </if>
  692. <if test="vo.isInsure != null and vo.isInsure != ''">
  693. AND td.is_insure = #{vo.isInsure}
  694. </if>
  695. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  696. AND exists (select 1 from trade_refund tr where tr.order_id=td.id and tr.refund_status = 6 and tr.refund_time BETWEEN #{vo.orderRefundDateStart} and #{vo.orderRefundDateEnd} )
  697. </if>
  698. ORDER BY
  699. <choose>
  700. <!-- 有前端排序:只使用前端多字段排序 -->
  701. <when test="vo.sortField != null and vo.sortField != '' and vo.sortOrder != null and vo.sortOrder != ''">
  702. <foreach collection="vo.sortField.split(',')" index="index" item="field" separator=",">
  703. <choose>
  704. <when test="field == 'orderSort'">td.order_sort</when>
  705. <when test="field == 'sourceName'">td.source_id</when>
  706. <when test="field == 'voyage.name'">
  707. (SELECT pv.name FROM product_voyage pv WHERE pv.id = td.voyage_id AND pv.deleted = 0)
  708. </when>
  709. <when test="field == 'totalPerson'">
  710. (SELECT COUNT(DISTINCT v1.id)
  711. FROM trade_visitor v1
  712. WHERE v1.order_id = td.id
  713. AND v1.deleted = 0)
  714. </when>
  715. </choose>
  716. ${vo.sortOrder.split(',')[index]}
  717. </foreach>
  718. </when>
  719. <!-- 无前端排序:默认排序 -->
  720. <otherwise>
  721. td.create_time DESC
  722. </otherwise>
  723. </choose>
  724. </select>
  725. <select id="findOrderDetailByIds"
  726. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  727. SELECT td.*,
  728. tins.res_msg,
  729. toa.audit_time auditTime,
  730. tou.contact_name,
  731. tou.credential_no,
  732. tou.mobile,
  733. count(tdl.id) num,
  734. sum(CASE WHEN tdl.voucher_status IN (1,2,3,4,6,8,9) THEN 1 ELSE 0 END) realnum,
  735. (tr.origin_amount - tr.refund_amount) feeAmount,
  736. tdl.product_name,
  737. tdl.spec_type,
  738. ifnull(tr.origin_amount - tr.refund_amount, 0) realAmount,
  739. tr.refund_amount refundAmount,
  740. ps.product_tag productTag,
  741. ps.product_tag2 productTag2
  742. FROM trade_order td
  743. INNER JOIN trade_order_user tou ON td.id = tou.order_id AND tou.deleted = 0
  744. LEFT JOIN trade_detail tdl ON td.id = tdl.order_id AND tdl.deleted = 0
  745. LEFT JOIN product_spu ps ON ps.id = tdl.product_id and ps.deleted = 0
  746. LEFT JOIN trade_order_audit toa ON toa.order_id = td.id AND toa.audit_status = 1 AND toa.deleted = 0
  747. LEFT JOIN (
  748. SELECT order_id,
  749. sum(refund_amount) refund_amount,
  750. sum(origin_amount) origin_amount
  751. FROM trade_refund
  752. WHERE refund_status = 6 AND refund_method != 2 AND deleted = 0
  753. GROUP BY order_id
  754. ) tr ON td.id = tr.order_id
  755. LEFT JOIN trade_insurance tins ON tins.order_id = td.id AND tins.deleted = 0
  756. WHERE td.id IN
  757. <foreach collection="ids" item="id" open="(" close=")" separator=",">
  758. #{id}
  759. </foreach>
  760. GROUP BY td.id
  761. ORDER BY
  762. <choose>
  763. <!-- 有前端排序:只使用前端多字段排序 -->
  764. <when test="vo.sortField != null and vo.sortField != '' and vo.sortOrder != null and vo.sortOrder != ''">
  765. <foreach collection="vo.sortField.split(',')" index="index" item="field" separator=",">
  766. <choose>
  767. <when test="field == 'orderSort'">td.order_sort</when>
  768. <when test="field == 'sourceName'">td.source_id</when>
  769. <when test="field == 'voyage.name'">
  770. (SELECT pv.name FROM product_voyage pv WHERE pv.id = td.voyage_id AND pv.deleted = 0)
  771. </when>
  772. <when test="field == 'totalPerson'">
  773. (SELECT COUNT(DISTINCT v1.id)
  774. FROM trade_visitor v1
  775. WHERE v1.order_id = td.id
  776. AND v1.deleted = 0)
  777. </when>
  778. </choose>
  779. ${vo.sortOrder.split(',')[index]}
  780. </foreach>
  781. </when>
  782. <!-- 无前端排序:默认排序 -->
  783. <otherwise>
  784. td.create_time DESC
  785. </otherwise>
  786. </choose>
  787. </select>
  788. <select id="getTradeOrderUserPage"
  789. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  790. SELECT td.*,tins.res_msg,toa.audit_time auditTime,tou.contact_name,tou.credential_no,tou.mobile,count(tdl.id) num,sum(CASE WHEN tdl.voucher_status in (1,2,3,4,6,8,9) THEN 1 ELSE 0 END) realnum,(tr.origin_amount-tr.refund_amount) feeAmount,tdl.product_name,tdl.spec_type,ifnull(tr.origin_amount-tr.refund_amount,0) realAmount
  791. ,tr.refund_amount refundAmount,
  792. ps.product_tag productTag,ps.product_tag2 productTag2,ps.product_tag3 productTag3,ps.product_tag4 productTag4
  793. FROM trade_order td
  794. INNER JOIN trade_order_user tou on td.id = tou.order_id
  795. left JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  796. left JOIN product_spu ps on ps.id = tdl.product_id
  797. LEFT JOIN ota_distributor od on od.id = td.source_id
  798. LEFT JOIN trade_order_audit toa on toa.order_id = td.id and toa.audit_status = 1
  799. LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2 where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
  800. LEFT JOIN trade_order_room_model torm on torm.order_id = td.id
  801. left join trade_insurance tins on tins.order_id = td.id
  802. where td.deleted = 0 and tou.deleted = 0 and (tins.deleted = 0 or tins.deleted is null)
  803. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  804. and td.order_status in
  805. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  806. #{item}
  807. </foreach>
  808. </if>
  809. <if test="vo.tenantId!=null">
  810. AND td.tenant_id = #{vo.tenantId}
  811. </if>
  812. <choose>
  813. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  814. AND td.order_no like concat('%',#{vo.orderNo})
  815. </when>
  816. <when test="vo.orderNo != null and vo.orderNo != ''">
  817. AND td.order_no = #{vo.orderNo}
  818. </when>
  819. <otherwise>
  820. </otherwise>
  821. </choose>
  822. <if test="vo.memberId != null and vo.memberId != ''">
  823. AND td.member_id = #{vo.memberId}
  824. </if>
  825. <if test="vo.voyageId != null and vo.voyageId != ''">
  826. AND td.voyage_id = #{vo.voyageId}
  827. </if>
  828. <if test="vo.shipId != null and vo.shipId != ''">
  829. AND td.ship_id = #{vo.shipId}
  830. </if>
  831. <if test="vo.routeId != null and vo.routeId != ''">
  832. AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
  833. </if>
  834. <if test="vo.dispatchStatus != null">
  835. AND td.dispatch_status = #{vo.dispatchStatus}
  836. </if>
  837. <if test="vo.payType != null">
  838. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  839. </if>
  840. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  841. AND od.ota_category_id = #{vo.otaCateId}
  842. </if>
  843. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  844. and od.ota_category_id in
  845. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  846. #{item}
  847. </foreach>
  848. </if>
  849. <if test="vo.otaId != null and vo.otaId != ''">
  850. AND td.source_id = #{vo.otaId}
  851. </if>
  852. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  853. AND td.source_id IN
  854. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  855. #{item}
  856. </foreach>
  857. </if>
  858. <if test="vo.storeId != null and vo.storeId != ''">
  859. AND td.store_id = #{vo.storeId}
  860. </if>
  861. <if test="vo.productTag != null and vo.productTag != ''">
  862. AND ps.product_tag = #{vo.productTag}
  863. </if>
  864. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  865. AND ps.product_tag2 = #{vo.productTag2}
  866. </if>
  867. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  868. AND ps.product_tag3 = #{vo.productTag3}
  869. </if>
  870. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  871. AND ps.product_tag4 = #{vo.productTag4}
  872. </if>
  873. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  874. AND tdl.product_id in
  875. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  876. #{item}
  877. </foreach>
  878. </if>
  879. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  880. AND td.external_order_no = #{vo.externalOrderNo}
  881. </if>
  882. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  883. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  884. </if>
  885. <if test="vo.userName != null and vo.userName != ''">
  886. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  887. </if>
  888. <choose>
  889. <when test="vo.mobile != null and vo.mobile.length() == 4">
  890. AND tou.mobile like concat('%',#{vo.mobile})
  891. </when>
  892. <when test="vo.mobile != null and vo.mobile != ''">
  893. AND tou.mobile = #{vo.mobile}
  894. </when>
  895. <otherwise>
  896. </otherwise>
  897. </choose>
  898. <if test="vo.contactName != null and vo.contactName != ''">
  899. AND tou.contact_name = #{vo.contactName}
  900. </if>
  901. <if test="vo.travelDate != null and vo.travelDate != ''">
  902. AND td.travel_date = #{vo.travelDate}
  903. </if>
  904. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  905. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  906. </if>
  907. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  908. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  909. </if>
  910. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  911. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  912. </if>
  913. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  914. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  915. </if>
  916. <if test="vo.orderDate != null and vo.orderDate != ''">
  917. AND td.create_time = #{vo.orderDate}
  918. </if>
  919. <if test="vo.sellerId != null and vo.sellerId != ''">
  920. AND td.seller_id = #{vo.sellerId}
  921. </if>
  922. <if test="vo.shareName != null and vo.shareName != ''">
  923. AND td.share_name like concat('%',#{vo.shareName},'%')
  924. </if>
  925. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  926. AND tdl.voucher_code = #{vo.voucherCode}
  927. </if>
  928. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  929. AND td.sell_method = #{vo.sellMethod}
  930. </if>
  931. <if test="vo.productName != null and vo.productName != ''">
  932. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  933. </if>
  934. <if test="vo.isFullPay == 0">
  935. AND td.is_full_pay = #{vo.isFullPay}
  936. </if>
  937. <if test="vo.isComment != null">
  938. AND td.is_comment = #{vo.isComment}
  939. </if>
  940. <if test="vo.sourceId != null and vo.sourceId != ''">
  941. AND td.source_id = #{vo.sourceId}
  942. </if>
  943. <if test="vo.paymentStatus != null">
  944. AND td.pay_status = #{vo.paymentStatus}
  945. </if>
  946. <if test="vo.distributorId != null and vo.distributorId != ''">
  947. AND td.source_id = #{vo.distributorId}
  948. </if>
  949. <if test="vo.sourceName != null and vo.sourceName != ''">
  950. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  951. </if>
  952. <if test="vo.travelStatus != null">
  953. AND td.travel_status = #{vo.travelStatus}
  954. </if>
  955. <if test="vo.roomModelId != null and vo.roomModelId != ''">
  956. AND torm.room_model_id = #{vo.roomModelId}
  957. </if>
  958. <if test="vo.floor != null and vo.floor != ''">
  959. AND torm.floor = #{vo.floor}
  960. </if>
  961. <if test="vo.isInsure != null and vo.isInsure != ''">
  962. AND td.is_insure = #{vo.isInsure}
  963. </if>
  964. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  965. AND exists (select 1 from trade_refund tr where tr.order_id=td.id and tr.refund_status = 6 and tr.refund_time BETWEEN #{vo.orderRefundDateStart} and #{vo.orderRefundDateEnd} )
  966. </if>
  967. GROUP BY td.id
  968. ORDER BY td.create_time DESC
  969. </select>
  970. <select id="getTradeOrderUserCount" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderCountRespVO">
  971. SELECT count(DISTINCT td.id) orderNum,sum(if(tdl.voucher_status in (1,2,3,4,6,8,9), quantity_of_one,0)) totalNum,
  972. sum(if(tdl.spec_type='full' and tdl.voucher_status in (1,2,3,4,6,8,9), quantity_of_one,0)) fullNum,
  973. sum(if(tdl.spec_type='half' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) halfNum,
  974. sum(if(tdl.spec_type='free' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) freeNum,
  975. sum(if(tdl.spec_type='common' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) commonNum,
  976. sum(if(tdl.spec_type='car_seat' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carSeatNum,
  977. sum(if(tdl.spec_type='car_yd' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carYdNum,
  978. sum(if(tdl.spec_type='other' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) otherNum,
  979. sum(if(tdl.spec_type='carrying_children' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carryingChildrenNum,
  980. sum(tdl.actual_price) totalPayAmount
  981. FROM trade_order td
  982. INNER JOIN trade_order_user tou on td.id = tou.order_id
  983. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  984. INNER JOIN product_spu ps on ps.id = tdl.product_id
  985. LEFT JOIN ota_distributor od on od.id = td.source_id
  986. where 1= 1
  987. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  988. and td.order_status in
  989. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  990. #{item}
  991. </foreach>
  992. </if>
  993. <if test="vo.tenantId!=null">
  994. AND td.tenant_id = #{vo.tenantId}
  995. </if>
  996. <choose>
  997. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  998. AND td.order_no like concat('%',#{vo.orderNo})
  999. </when>
  1000. <when test="vo.orderNo != null and vo.orderNo != ''">
  1001. AND td.order_no = #{vo.orderNo}
  1002. </when>
  1003. <otherwise>
  1004. </otherwise>
  1005. </choose>
  1006. <if test="vo.memberId != null and vo.memberId != ''">
  1007. AND td.member_id = #{vo.memberId}
  1008. </if>
  1009. <if test="vo.productTag != null and vo.productTag != ''">
  1010. AND ps.product_tag = #{vo.productTag}
  1011. </if>
  1012. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  1013. AND ps.product_tag2 = #{vo.productTag2}
  1014. </if>
  1015. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  1016. AND ps.product_tag3 = #{vo.productTag3}
  1017. </if>
  1018. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  1019. AND ps.product_tag4 = #{vo.productTag4}
  1020. </if>
  1021. <if test="vo.dispatchStatus != null">
  1022. AND td.dispatch_status = #{vo.dispatchStatus}
  1023. </if>
  1024. <if test="vo.payType != null">
  1025. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  1026. </if>
  1027. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  1028. AND od.ota_category_id = #{vo.otaCateId}
  1029. </if>
  1030. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  1031. AND (td.route_plan_id in
  1032. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1033. #{item}
  1034. </foreach>
  1035. or tdl.product_id in
  1036. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1037. #{item}
  1038. </foreach>
  1039. )
  1040. </if>
  1041. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  1042. AND tdl.product_id in
  1043. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1044. #{item}
  1045. </foreach>
  1046. </if>
  1047. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1048. and td.route_plan_id in
  1049. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1050. #{item}
  1051. </foreach>
  1052. </if>
  1053. <if test="vo.otaId != null and vo.otaId != ''">
  1054. AND td.source_id = #{vo.otaId}
  1055. </if>
  1056. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  1057. AND td.source_id IN
  1058. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  1059. #{item}
  1060. </foreach>
  1061. </if>
  1062. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  1063. and od.ota_category_id in
  1064. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  1065. #{item}
  1066. </foreach>
  1067. </if>
  1068. <if test="vo.storeId != null and vo.storeId != ''">
  1069. AND td.store_id = #{vo.storeId}
  1070. </if>
  1071. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  1072. AND td.external_order_no = #{vo.externalOrderNo}
  1073. </if>
  1074. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1075. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  1076. </if>
  1077. <if test="vo.userName != null and vo.userName != ''">
  1078. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  1079. </if>
  1080. <choose>
  1081. <when test="vo.mobile != null and vo.mobile.length() == 4">
  1082. AND tou.mobile like concat('%',#{vo.mobile})
  1083. </when>
  1084. <when test="vo.mobile != null and vo.mobile != ''">
  1085. AND tou.mobile = #{vo.mobile}
  1086. </when>
  1087. <otherwise>
  1088. </otherwise>
  1089. </choose>
  1090. <if test="vo.contactName != null and vo.contactName != ''">
  1091. AND tou.contact_name = #{vo.contactName}
  1092. </if>
  1093. <if test="vo.travelDate != null and vo.travelDate != ''">
  1094. AND td.travel_date = #{vo.travelDate}
  1095. </if>
  1096. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1097. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1098. </if>
  1099. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1100. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1101. </if>
  1102. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  1103. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  1104. </if>
  1105. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  1106. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  1107. </if>
  1108. <if test="vo.orderDate != null and vo.orderDate != ''">
  1109. AND td.create_time = #{vo.orderDate}
  1110. </if>
  1111. <if test="vo.sellerId != null and vo.sellerId != ''">
  1112. AND td.seller_id = #{vo.sellerId}
  1113. </if>
  1114. <if test="vo.shareName != null and vo.shareName != ''">
  1115. AND td.share_name like concat('%',#{vo.shareName},'%')
  1116. </if>
  1117. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1118. AND tdl.voucher_code = #{vo.voucherCode}
  1119. </if>
  1120. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  1121. AND td.sell_method = #{vo.sellMethod}
  1122. </if>
  1123. <if test="vo.productName != null and vo.productName != ''">
  1124. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1125. </if>
  1126. <if test="vo.isFullPay == 0">
  1127. AND td.is_full_pay = #{vo.isFullPay}
  1128. </if>
  1129. <if test="vo.isComment != null">
  1130. AND td.is_comment = #{vo.isComment}
  1131. </if>
  1132. <if test="vo.sourceId != null and vo.sourceId != ''">
  1133. AND td.source_id = #{vo.sourceId}
  1134. </if>
  1135. <if test="vo.sourceName != null and vo.sourceName != ''">
  1136. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  1137. </if>
  1138. <if test="vo.travelStatus != null">
  1139. AND td.travel_status = #{vo.travelStatus}
  1140. </if>
  1141. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  1142. AND exists (select 1 from trade_refund tr where tr.order_id=td.id and tr.refund_status = 6 and tr.refund_time BETWEEN #{vo.orderRefundDateStart} and #{vo.orderRefundDateEnd} )
  1143. </if>
  1144. </select>
  1145. <select id="getPaidOrderPage"
  1146. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1147. SELECT td.*, op.pay_amount payAmount, op.refund_amount refundAmount, op.pay_status paymentStatus, op.payment_type paymentType, op.payment_date paymentDate
  1148. FROM trade_order td
  1149. INNER JOIN trade_order_pay op on op.order_id = td.id
  1150. where td.order_status <![CDATA[ >= ]]> 6 and td.order_status <![CDATA[ <= ]]> 11
  1151. <if test="vo.orderNo != null and vo.orderNo != ''">
  1152. AND td.order_no = #{vo.orderNo}
  1153. </if>
  1154. <if test="vo.payType != null">
  1155. AND op.payment_type = #{vo.payType}
  1156. </if>
  1157. <if test="vo.storeId != null and vo.storeId != ''">
  1158. AND td.store_id = #{vo.storeId}
  1159. </if>
  1160. <if test="vo.travelDate != null and vo.travelDate != ''">
  1161. AND td.travel_date = #{vo.travelDate}
  1162. </if>
  1163. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1164. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1165. </if>
  1166. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1167. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1168. </if>
  1169. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  1170. AND op.payment_date <![CDATA[ >= ]]> #{vo.orderDateStart}
  1171. </if>
  1172. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  1173. AND op.payment_date <![CDATA[ <= ]]> #{vo.orderDateEnd}
  1174. </if>
  1175. <if test="vo.orderDate != null and vo.orderDate != ''">
  1176. AND td.create_time = #{vo.orderDate}
  1177. </if>
  1178. <if test="vo.sellerId != null and vo.sellerId != ''">
  1179. AND td.seller_id = #{vo.sellerId}
  1180. </if>
  1181. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  1182. AND td.sell_method = #{vo.sellMethod}
  1183. </if>
  1184. ORDER BY td.create_time DESC
  1185. </select>
  1186. <select id="getRefundDetailPage"
  1187. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  1188. SELECT td.*,tv.credential_no,tv.`name`,tv.mobile,tor.order_no
  1189. FROM trade_detail td
  1190. INNER JOIN trade_visitor tv on tv.detail_id = td.id
  1191. LEFT JOIN trade_order tor on tor.id = td.order_id
  1192. where 1= 1
  1193. <if test="vo.name != null and vo.name != ''">
  1194. AND tv.name = #{vo.name}
  1195. </if>
  1196. <if test="vo.orderNo != null and vo.orderNo != ''">
  1197. AND tor.order_no = #{vo.orderNo}
  1198. </if>
  1199. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1200. AND tv.credential_no = #{vo.credentialNo}
  1201. </if>
  1202. <if test="vo.mobile != null and vo.mobile != ''">
  1203. AND tv.mobile = #{vo.mobile}
  1204. </if>
  1205. <if test="vo.orderStatus != null and vo.orderStatus != ''">
  1206. AND tor.order_status = #{vo.orderStatus}
  1207. </if>
  1208. </select>
  1209. <select id="getRefundRecordPage"
  1210. resultType="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundRespVO">
  1211. SELECT tr.*,td.order_no, ou.mobile,td.travel_date, ou.contact_name ,tdl.product_name
  1212. FROM trade_refund tr
  1213. INNER JOIN trade_order td on tr.order_id = td.id
  1214. inner join product_voyage pv on td.voyage_id = pv.id
  1215. inner join trade_order_user ou on ou.order_id = td.id
  1216. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1217. LEFT JOIN ota_distributor od on od.id = td.source_id
  1218. where 1= 1
  1219. <if test="vo.shipId != null and vo.shipId != ''">
  1220. AND td.ship_id = #{vo.shipId}
  1221. </if>
  1222. <if test="vo.voyageId != null and vo.voyageId != ''">
  1223. AND td.voyage_id = #{vo.voyageId}
  1224. </if>
  1225. <if test="vo.routeId != null and vo.routeId != ''">
  1226. AND pv.route_id = #{vo.routeId}
  1227. </if>
  1228. <if test="vo.orderNo != null and vo.orderNo != ''">
  1229. AND td.order_no = #{vo.orderNo}
  1230. </if>
  1231. <if test="vo.refundStatus!=null and vo.refundStatus.size()>0">
  1232. and tr.refund_status in
  1233. <foreach collection="vo.refundStatus" item="item" separator="," open="(" close=")">
  1234. #{item}
  1235. </foreach>
  1236. </if>
  1237. <if test="vo.refundMethod != null and vo.refundMethod != ''">
  1238. AND tr.refund_method = #{vo.refundMethod}
  1239. </if>
  1240. <if test="vo.refundUserId!=null and vo.refundUserId.size()>0">
  1241. and tr.refund_user in
  1242. <foreach collection="vo.refundUserId" item="item" separator="," open="(" close=")">
  1243. #{item}
  1244. </foreach>
  1245. </if>
  1246. <if test="vo.refundChannel != null">
  1247. AND tr.refund_channel = #{vo.refundChannel}
  1248. </if>
  1249. <if test="vo.mobile != null and vo.mobile != ''">
  1250. AND ou.mobile = #{vo.mobile}
  1251. </if>
  1252. <if test="vo.sourceId != null and vo.sourceId != ''">
  1253. AND td.source_id = #{vo.sourceId}
  1254. </if>
  1255. <if test="vo.travelDate != null and vo.travelDate != ''">
  1256. AND td.travel_date = #{vo.travelDate}
  1257. </if>
  1258. <if test="vo.productName != null and vo.productName != ''">
  1259. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1260. </if>
  1261. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1262. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1263. </if>
  1264. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1265. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1266. </if>
  1267. <if test="vo.refundTime != null and vo.refundTime != ''">
  1268. AND tr.refund_time = #{vo.refundTime}
  1269. </if>
  1270. <if test="vo.refundTimeStart != null and vo.refundTimeStart != ''">
  1271. AND tr.refund_time <![CDATA[ >= ]]> #{vo.refundTimeStart}
  1272. </if>
  1273. <if test="vo.refundTimeEnd != null and vo.refundTimeEnd != ''">
  1274. AND tr.refund_time <![CDATA[ <= ]]> #{vo.refundTimeEnd}
  1275. </if>
  1276. <if test="vo.otaId != null and vo.otaId != ''">
  1277. AND td.source_id = #{vo.otaId}
  1278. </if>
  1279. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  1280. AND td.source_id IN
  1281. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  1282. #{item}
  1283. </foreach>
  1284. </if>
  1285. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  1286. and od.ota_category_id in
  1287. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  1288. #{item}
  1289. </foreach>
  1290. </if>
  1291. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  1292. AND tdl.product_id in
  1293. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1294. #{item}
  1295. </foreach>
  1296. </if>
  1297. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1298. and td.route_plan_id in
  1299. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1300. #{item}
  1301. </foreach>
  1302. </if>
  1303. group by tr.id
  1304. ORDER BY tr.create_time DESC
  1305. </select>
  1306. <select id="getOrderInfo" resultMap="MiddleWareDtoResultMap">
  1307. SELECT td.id,td.voyage_id,td.is_read isRead,td.pay_amount,td.order_no,td.external_order_no,td.visitor_type,td.travel_date,td.sell_method,td.source_id,td.source_name,td.store_id,td.seller_id,td.member_id,td.amount,td.order_status,td.remark,td.share_name,td.create_time,td.is_marketing,td.is_marketing_use,
  1308. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,tou.county,tou.province,tou.city,td.agency_group_id,
  1309. top.id payId,top.pay_amount payAmount,top.pay_status,top.payment_type,top.payment_date,top.payment_no,
  1310. td.store_name,td.is_invoice, td.confirm_type, td.travel_status, tr.refund_amount,td.finish_status,
  1311. ti.id insuranceId,ti.policy_no,ti.proposal_no,ti.insurance_no,ti.insurance_status,ti.insured_num,ti.insurance_effect_date,ti.electronic_policy,
  1312. tc.id contractId,tc.contract_no,tc.`status`,tc.tourists_count,tc.contract_url,tc.operate_name,tc.signer_name,tc.signer_mobile,tc.signing_time
  1313. FROM trade_order td
  1314. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1315. left JOIN trade_order_pay top on td.id = top.order_id AND top.pay_status = 1 and top.deleted = 0
  1316. left JOIN trade_insurance ti on td.id = ti.order_id
  1317. left JOIN trade_contract tc on td.id = tc.order_id
  1318. LEFT JOIN (select m2.order_id,sum(m1.refund_amount) refund_amount from trade_refund_detail m1
  1319. inner join trade_refund m2 on m1.refund_id = m2.id where m2.order_id = #{id} and m1.refund_status = 6 GROUP BY m2.order_id) tr on td.id = tr.order_id
  1320. where 1= 1
  1321. AND td.id = #{id}
  1322. </select>
  1323. <select id="getPdaOrderInfo" resultMap="MiddleWareDtoResultMap2">
  1324. SELECT td.id,td.is_read isRead,td.pay_amount,td.order_no,td.external_order_no,td.route_plan_id,rt.name route_plan_name,td.visitor_type,td.travel_date,td.sell_method,td.source_id,td.source_name,td.store_id,td.seller_id,td.member_id,td.amount,td.order_status,td.remark,td.share_name,td.create_time,td.is_bind,td.area_manager_id,td.is_marketing,td.is_marketing_use,
  1325. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,tou.county,tou.province,tou.city,td.is_change_order,td.agency_group_id,
  1326. top.id payId,top.pay_amount payAmount,top.pay_status,top.payment_type,top.payment_date,top.payment_no,
  1327. td.store_name,td.dispatch_status,td.is_invoice, td.confirm_type, td.travel_status, tr.refund_amount,td.finish_status,
  1328. ti.id insuranceId,ti.policy_no,ti.proposal_no,ti.insurance_no,ti.insurance_status,ti.insured_num,ti.insurance_effect_date,ti.electronic_policy,
  1329. tc.id contractId,tc.contract_no,tc.`status`,tc.tourists_count,tc.contract_url,tc.operate_name,tc.signer_name,tc.signer_mobile,tc.signing_time,tc.signing_url,tc.view_url
  1330. FROM trade_order td
  1331. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1332. left JOIN trade_order_pay top on td.id = top.order_id AND top.pay_status = 1 and top.deleted = 0
  1333. left JOIN trade_insurance ti on td.id = ti.order_id
  1334. left JOIN trade_contract tc on td.id = tc.order_id
  1335. left JOIN product_route_plan rt on rt.id = td.route_plan_id
  1336. LEFT JOIN (select m2.order_id,sum(m1.refund_amount) refund_amount from trade_refund_detail m1
  1337. inner join trade_refund m2 on m1.refund_id = m2.id where m2.order_id = #{id} and m1.refund_status = 6 GROUP BY m2.order_id) tr on td.id = tr.order_id
  1338. where 1= 1
  1339. AND td.id = #{id}
  1340. </select>
  1341. <select id="getMarketingApplyOrderPage" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1342. SELECT td.id,td.pay_amount,td.order_no,td.external_order_no,td.route_plan_id,td.visitor_type,td.travel_date,td.sell_method,td.source_name,td.source_id,td.seller_id,td.member_id,td.amount,td.order_status,td.remark,td.share_name,td.create_time,td.is_bind,td.area_manager_id,td.agency_group_id,
  1343. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  1344. td.store_name,td.store_id,pma.audit_state,pma.use_audit_state,pma.type auditType,pma.id marketingAuditId,pma.is_execute,pma.error_text,pmk.name marketingName,pmk.policy_type policyType,pma.remark auditRemark,pma.file_url fileUrl
  1345. FROM
  1346. product_marketing_audit pma
  1347. INNER JOIN trade_order td on pma.order_id = td.id
  1348. inner join trade_detail ttd on td.id = ttd.order_id
  1349. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  1350. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  1351. WHERE 1 = 1 AND td.order_status != 11 and
  1352. pma.travel_id in (SELECT DISTINCT travel_id FROM product_marketing_pm WHERE user_id = #{vo.userId} and deleted = 0)
  1353. <if test="vo.ids.size()>0">
  1354. and pma.travel_id in
  1355. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  1356. #{item}
  1357. </foreach>
  1358. </if>
  1359. <if test="vo.orderNo != null and vo.orderNo != ''">
  1360. AND td.order_no = #{vo.orderNo}
  1361. </if>
  1362. <if test="vo.policyType != null and vo.policyType != ''">
  1363. AND pmk.policy_type = #{vo.policyType}
  1364. </if>
  1365. <if test="vo.productName != null and vo.productName != ''">
  1366. AND ttd.product_name like concat('%',#{vo.productName}, '%')
  1367. </if>
  1368. <if test="vo.marketingName != null and vo.marketingName != ''">
  1369. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  1370. </if>
  1371. <if test="vo.isExecute != null and vo.isExecute != ''">
  1372. AND pma.is_execute = #{vo.isExecute}
  1373. </if>
  1374. <if test="vo.distributorId != null and vo.distributorId != ''">
  1375. AND pma.agency_id = #{vo.distributorId}
  1376. </if>
  1377. <if test="vo.storeId != null and vo.storeId != ''">
  1378. AND pma.store_id = #{vo.storeId}
  1379. </if>
  1380. <if test="vo.orderStartTime != null and vo.orderStartTime != ''">
  1381. AND td.travel_date <![CDATA[ >= ]]> #{vo.orderStartTime}
  1382. </if>
  1383. <if test="vo.orderEndTime != null and vo.orderEndTime != ''">
  1384. AND td.travel_date <![CDATA[ <= ]]> #{vo.orderEndTime}
  1385. </if>
  1386. <if test="vo.auditState != null ">
  1387. AND pma.audit_state = #{vo.auditState}
  1388. </if>
  1389. GROUP BY pma.id,td.id
  1390. order by pma.create_time desc
  1391. </select>
  1392. <select id="getStoresMarketingOrderPage" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeMarketOrderRespVO">
  1393. SELECT td.id,td.pay_amount,td.order_no,td.external_order_no,td.route_plan_id,td.visitor_type,td.travel_date,td.sell_method,td.source_name,td.source_id,td.seller_id,td.member_id,td.amount,td.order_status,td.remark,td.share_name,td.create_time,td.is_bind,td.area_manager_id,td.agency_group_id,
  1394. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  1395. td.store_name,td.store_id,pma.audit_state,pma.use_audit_state,pma.type auditType,pma.id marketingAuditId,pma.remark auditRemark,pma.is_execute,pma.error_text,pma.file_url fileUrl,if(pms.id is null,null, pmk.`name`) marketingName,if(pms.id is null,null, pmk.policy_type) policyType
  1396. FROM
  1397. product_marketing_audit pma
  1398. INNER JOIN trade_order td on pma.order_id = td.id
  1399. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  1400. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  1401. LEFT JOIN product_marketing_pool_spu pms on td.id = pms.order_id
  1402. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  1403. WHERE 1 = 1
  1404. <if test="vo.storeId != null">
  1405. and pma.store_id = #{vo.storeId}
  1406. </if>
  1407. <if test="vo.distributorId != null">
  1408. and td.source_id = #{vo.distributorId}
  1409. </if>
  1410. <if test="vo.ids.size()>0">
  1411. and pma.travel_id in
  1412. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  1413. #{item}
  1414. </foreach>
  1415. </if>
  1416. <if test="vo.isExecute != null">
  1417. and pma.is_execute = #{vo.isExecute}
  1418. </if>
  1419. <if test="vo.policyType != null and vo.policyType != ''">
  1420. AND pmk.policy_type = #{vo.policyType}
  1421. </if>
  1422. <if test="vo.marketingName != null and vo.marketingName != ''">
  1423. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  1424. </if>
  1425. <if test="vo.auditState != null">
  1426. and pma.audit_state = #{vo.auditState}
  1427. </if>
  1428. <if test="vo.useAuditState != null">
  1429. and pma.use_audit_state = #{vo.useAuditState}
  1430. </if>
  1431. <if test="vo.orderNo != null and vo.orderNo != ''">
  1432. AND td.order_no = #{vo.orderNo}
  1433. </if>
  1434. <if test="vo.travelDate != null and vo.travelDate != ''">
  1435. AND td.travel_date = #{vo.travelDate}
  1436. </if>
  1437. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1438. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1439. </if>
  1440. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1441. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1442. </if>
  1443. <if test="vo.productName != null and vo.productName != ''">
  1444. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1445. </if>
  1446. GROUP BY pma.id
  1447. order by pma.create_time desc
  1448. </select>
  1449. <select id="getStoresMarketingOrderDesc" resultType="java.util.Map">
  1450. SELECT td.id,td.pay_amount,td.order_no,td.external_order_no,td.route_plan_id,td.visitor_type,td.travel_date,td.sell_method,td.source_name,td.source_id,td.seller_id,td.member_id,td.amount,td.order_status,td.remark,td.share_name,td.create_time,td.is_bind,td.area_manager_id,td.agency_group_id,
  1451. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  1452. td.store_name,td.store_id,pma.audit_state,pma.use_audit_state,pma.type auditType,pma.id marketingAuditId,pma.remark auditRemark,pma.is_execute,pma.error_text,pma.file_url fileUrl
  1453. FROM
  1454. product_marketing_audit pma
  1455. INNER JOIN trade_order td on pma.order_id = td.id
  1456. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  1457. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  1458. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  1459. WHERE 1 = 1
  1460. <if test="vo.storeId != null">
  1461. and pma.store_id = #{vo.storeId}
  1462. </if>
  1463. <if test="vo.ids.size()>0">
  1464. and pma.travel_id in
  1465. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  1466. #{item}
  1467. </foreach>
  1468. </if>
  1469. <if test="vo.isExecute != null">
  1470. and pma.is_execute = #{vo.isExecute}
  1471. </if>
  1472. <if test="vo.policyType != null and vo.policyType != ''">
  1473. AND pmk.policy_type = #{vo.policyType}
  1474. </if>
  1475. <if test="vo.marketingName != null and vo.marketingName != ''">
  1476. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  1477. </if>
  1478. <if test="vo.auditState != null">
  1479. and pma.audit_state = #{vo.auditState}
  1480. </if>
  1481. <if test="vo.useAuditState != null">
  1482. and pma.use_audit_state = #{vo.useAuditState}
  1483. </if>
  1484. <if test="vo.orderNo != null and vo.orderNo != ''">
  1485. AND td.order_no = #{vo.orderNo}
  1486. </if>
  1487. <if test="vo.travelDate != null and vo.travelDate != ''">
  1488. AND td.travel_date = #{vo.travelDate}
  1489. </if>
  1490. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1491. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1492. </if>
  1493. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1494. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1495. </if>
  1496. <if test="vo.productName != null and vo.productName != ''">
  1497. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1498. </if>
  1499. GROUP BY pma.id
  1500. order by pma.create_time desc
  1501. </select>
  1502. <select id="selectBindMarketing" resultType="java.lang.Long">
  1503. SELECT tob.bind_id
  1504. FROM
  1505. trade_order_bind tob
  1506. WHERE
  1507. tob.type = 7 AND tob.deleted = 0 AND tob.order_id = #{orderId}
  1508. </select>
  1509. <select id="selectBindUseMarketing" resultType="java.lang.Long">
  1510. SELECT tob.bind_id
  1511. FROM
  1512. trade_order_bind tob
  1513. WHERE
  1514. tob.type = 8 AND tob.deleted = 0 AND tob.order_id = #{orderId}
  1515. </select>
  1516. <select id="selectOrderIdByOrderNo" resultType="java.lang.Long">
  1517. SELECT id FROM trade_order WHERE order_no = #{orderNo}
  1518. </select>
  1519. <select id="getRefundOrderInfo" resultMap="RefundResultMap">
  1520. SELECT td.id,td.order_no,td.external_order_no,td.route_plan_id,td.visitor_type,td.travel_date,td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,td.payment_date,td.remark,
  1521. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  1522. tdl.id detailId,tdl.voucher_code,tdl.voucher_status,tdl.product_name,tdl.spec_type,
  1523. tv.id visitorId,tv.credential_no,tv.credential_type,tv.`name`
  1524. FROM trade_order td
  1525. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1526. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  1527. INNER JOIN trade_visitor tv on tdl.id = tv.detail_id
  1528. where 1= 1
  1529. <if test="id != null and id != ''">
  1530. AND td.id = #{id}
  1531. </if>
  1532. </select>
  1533. <select id="getTradeOrderByExpire" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1534. select * from trade_order where order_status =14 and travel_date <![CDATA[ <= ]]> #{expiretime}
  1535. </select>
  1536. <select id="getPageRefundRecord"
  1537. resultType="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundRecordRespVO">
  1538. SELECT trr.*,td.order_no, td.id orderId, td.travel_date
  1539. FROM trade_refund_record trr
  1540. left join trade_order_pay top on trr.order_pay_id = top.id
  1541. left join trade_refund tr on trr.refund_id = tr.id
  1542. left join trade_order td on td.id = top.order_id
  1543. left join product_voyage pv on td.voyage_id = pv.id
  1544. LEFT JOIN ota_distributor od on od.id = td.source_id
  1545. where 1= 1
  1546. <if test="vo.shipId != null and vo.shipId != ''">
  1547. AND td.ship_id = #{vo.shipId}
  1548. </if>
  1549. <if test="vo.voyageId != null and vo.voyageId != ''">
  1550. AND td.voyage_id = #{vo.voyageId}
  1551. </if>
  1552. <if test="vo.routeId != null and vo.routeId != ''">
  1553. AND pv.route_id = #{vo.routeId}
  1554. </if>
  1555. <if test="vo.orderNo != null and vo.orderNo != ''">
  1556. AND td.order_no = #{vo.orderNo}
  1557. </if>
  1558. <if test="vo.refundNo != null and vo.refundNo != ''">
  1559. AND trr.refund_no = #{vo.refundNo}
  1560. </if>
  1561. <if test="vo.paymentNo != null and vo.paymentNo != ''">
  1562. AND trr.payment_no = #{vo.paymentNo}
  1563. </if>
  1564. <if test="vo.refundStatus != null and vo.refundStatus != ''">
  1565. AND trr.refund_status = #{vo.refundStatus}
  1566. </if>
  1567. <if test="vo.refundId != null and vo.refundId != ''">
  1568. AND trr.refund_id = #{vo.refundId}
  1569. </if>
  1570. <if test="vo.openId != null and vo.openId != ''">
  1571. AND trr.openId = #{vo.openId}
  1572. </if>
  1573. <if test="vo.otaId != null and vo.otaId != ''">
  1574. AND td.source_id = #{vo.otaId}
  1575. </if>
  1576. <!--<if test="vo.otaIds != null and vo.otaIds.size()>0">
  1577. AND td.source_id IN
  1578. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  1579. #{item}
  1580. </foreach>
  1581. </if>-->
  1582. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  1583. and od.ota_category_id in
  1584. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  1585. #{item}
  1586. </foreach>
  1587. </if>
  1588. <if test="vo.sourceId != null and vo.sourceId != ''">
  1589. AND td.source_id = #{vo.sourceId}
  1590. </if>
  1591. <if test="vo.travelDate != null and vo.travelDate != ''">
  1592. AND td.travel_date = #{vo.travelDate}
  1593. </if>
  1594. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1595. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1596. </if>
  1597. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1598. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1599. </if>
  1600. <if test="vo.refundTime != null and vo.refundTime != ''">
  1601. AND trr.refund_time = #{vo.refundTime}
  1602. </if>
  1603. <if test="vo.refundTimeStart != null and vo.refundTimeStart != ''">
  1604. AND trr.refund_time <![CDATA[ >= ]]> #{vo.refundTimeStart}
  1605. </if>
  1606. <if test="vo.refundTimeEnd != null and vo.refundTimeEnd != ''">
  1607. AND trr.refund_time <![CDATA[ <= ]]> #{vo.refundTimeEnd}
  1608. </if>
  1609. ORDER BY trr.create_time DESC
  1610. </select>
  1611. <select id="getPrintTemp"
  1612. resultType="com.yc.ship.module.trade.controller.admin.order.vo.otc.PrintRespVO">
  1613. SELECT pt.* FROM print_temp pt where pt.template_code = #{printTemp}
  1614. </select>
  1615. <select id="queryCanInvoicedOrderPage"
  1616. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1617. SELECT
  1618. o.order_no,
  1619. o.travel_date,
  1620. o.order_status,
  1621. o.amount,
  1622. o.create_time,
  1623. o.external_order_no,
  1624. o.id,
  1625. o.is_invoice,
  1626. o.item_id,
  1627. o.payment_date,
  1628. o.remark,
  1629. o.seller_id,
  1630. o.sell_method,
  1631. o.share_name,
  1632. o.source_id,
  1633. o.source_name,
  1634. o.store_id,
  1635. o.store_name,
  1636. o.visitor_type,
  1637. tou.contact_name,
  1638. tou.credential_no,
  1639. tou.mobile,
  1640. td.product_name,
  1641. count(
  1642. DISTINCT
  1643. CASE
  1644. WHEN (
  1645. td.voucher_status in (3,6,7,8)
  1646. OR ( td.voucher_status = 9 AND td.check_status = 1 )
  1647. ) THEN
  1648. td.id ELSE null
  1649. END
  1650. ) AS num,
  1651. o.pay_amount - SUM( ifnull(trd.refund_amount,0) ) - SUM(
  1652. CASE
  1653. WHEN ( td.voucher_status in (1,2) )
  1654. AND DATE_FORMAT( td.validity_end_date, '%Y-%c-%d' ) >= DATE_FORMAT( NOW( ), '%Y-%c-%d' ) THEN
  1655. td.actual_price ELSE 0
  1656. END
  1657. ) AS pay_amount
  1658. FROM
  1659. trade_order o
  1660. INNER JOIN trade_detail td ON td.order_id = o.id
  1661. LEFT JOIN trade_refund_detail trd ON trd.trade_detail_id = td.id
  1662. AND trd.refund_status = 6
  1663. INNER JOIN trade_order_user tou ON o.id = tou.order_id
  1664. LEFT JOIN trade_invoice_detail i ON i.order_no = o.order_no
  1665. LEFT JOIN trade_invoice ii ON i.invoice_id = ii.id AND ii.invoice_status IN (1,3)
  1666. INNER JOIN (select p2.order_no,p1.payment_type from trade_order_pay p1 inner join trade_order p2 on p1.order_id = p2.id where p1.pay_status=1 GROUP BY order_id) op ON op.order_no = o.order_no LEFT JOIN (select p2.order_no,p1.* from ota_bill_order p1 inner join trade_order p2 on p1.order_id = p2.id) obo ON obo.order_no = o.order_no
  1667. LEFT JOIN ota_bill_store obs ON obs.id = obo.bill_store_id AND obs.bill_status=1
  1668. where td.use_date >= DATE_SUB(NOW(), INTERVAL #{canInvoicedDay} DAY)
  1669. and o.is_invoice in (0,2) and o.deleted =0
  1670. and o.order_status in (1,6,7,8,9,11,12)
  1671. <if test="vo.orderNo != null and vo.orderNo != ''">
  1672. AND o.order_no = #{vo.orderNo}
  1673. </if>
  1674. <if test="vo.sourceId != null and vo.sourceId != ''">
  1675. AND o.source_id = #{vo.sourceId}
  1676. </if>
  1677. <if test="vo.storeId != null and vo.storeId != ''">
  1678. AND o.store_id = #{vo.storeId}
  1679. </if>
  1680. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1681. AND tou.credential_no = #{vo.credentialNo}
  1682. </if>
  1683. <if test="vo.mobile != null and vo.mobile != ''">
  1684. AND tou.mobile = #{vo.mobile}
  1685. </if>
  1686. <if test="vo.contactName != null and vo.contactName != ''">
  1687. AND tou.contact_name = #{vo.contactName}
  1688. </if>
  1689. <if test="vo.travelDate != null and vo.travelDate != ''">
  1690. AND o.travel_date = #{vo.travelDate}
  1691. </if>
  1692. <if test="vo.sellerId != null and vo.sellerId != ''">
  1693. AND o.seller_id = #{vo.sellerId}
  1694. </if>
  1695. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1696. AND td.voucher_code = #{vo.voucherCode}
  1697. </if>
  1698. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  1699. AND o.sell_method = #{vo.sellMethod}
  1700. </if>
  1701. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1702. AND td.use_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1703. </if>
  1704. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1705. AND td.use_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1706. </if>
  1707. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  1708. AND o.payment_date <![CDATA[ >= ]]> #{vo.orderDateStart}
  1709. </if>
  1710. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  1711. AND o.payment_date <![CDATA[ <= ]]> #{vo.orderDateEnd}
  1712. </if>
  1713. <if test="vo.productName != null and vo.productName != ''">
  1714. AND td.product_name like concat('%',#{vo.productName}, '%')
  1715. </if>
  1716. AND ii.id IS NULL
  1717. AND (op.payment_type != 6 OR (o.is_bill=2 AND obs.id IS NOT NULL))
  1718. AND date_format(NOW(), '%Y-%m-%d') > date_format(o.travel_date, '%Y-%m-%d')
  1719. GROUP BY
  1720. o.order_no
  1721. HAVING
  1722. SUM(CASE WHEN td.voucher_status IN (1,2) AND td.validity_end_date >= CURDATE() THEN 1 ELSE 0 END) = 0
  1723. AND pay_amount > 0
  1724. ORDER BY
  1725. o.travel_date DESC
  1726. </select>
  1727. <select id="getOrderByVoucherCode"
  1728. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1729. SELECT o.* FROM trade_order o
  1730. inner join trade_detail d on d.order_id = o.id
  1731. where (o.order_status = 6 or o.order_status = 7) and d.voucher_code = #{voucherCode} limit 1
  1732. </select>
  1733. <select id="getOrderByExternalOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1734. select t1.* from trade_order t1 inner join trade_supplier_order t2 on t1.id = t2.order_id where t2.trade_no=#{tradeNo} limit 1
  1735. </select>
  1736. <select id="getOtcOrderByExternalOrderNo" resultType="java.util.Map">
  1737. select t2.* from trade_order t1 inner join trade_supplier_order t2 on t1.id = t2.order_id where t1.order_no=#{tradeNo} limit 1
  1738. </select>
  1739. <select id="getTradeOrderByVoucherCode" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1740. SELECT o.* FROM trade_order o inner join trade_detail d on d.order_id = o.id where d.voucher_code = #{voucherCode} limit 1
  1741. </select>
  1742. <select id="getOrderByCardNo"
  1743. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1744. SELECT
  1745. o.*
  1746. FROM
  1747. trade_order o
  1748. INNER JOIN trade_detail d ON d.order_id = o.id
  1749. INNER JOIN trade_visitor v ON v.detail_id = d.id
  1750. WHERE
  1751. o.travel_date >= CURDATE()
  1752. and d.voucher_status in (1,2,3,4,8,9)
  1753. and v.credential_no = #{cardNo}
  1754. </select>
  1755. <select id="getOrderByDetailBase"
  1756. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1757. SELECT o.* FROM trade_order o
  1758. inner join trade_detail d on d.order_id = o.id
  1759. inner join trade_detail_base tdb on tdb.detail_id = d.id
  1760. where (o.order_status = 6 or o.order_status = 7) and tdb.id = #{baseId} limit 1
  1761. </select>
  1762. <select id="getAccountOrderPage"
  1763. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1764. SELECT td.*,tou.contact_name,tou.credential_no,tou.mobile,COUNT(tdl.id) num,tdl.product_name,tdl.spec_type
  1765. FROM trade_order td
  1766. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1767. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  1768. where 1= 1 AND td.order_status NOT IN (-2, -1, 0, 1, 2, 12) AND td.is_account = 0
  1769. <if test="vo.orderNo != null and vo.orderNo != ''">
  1770. AND td.order_no = #{vo.orderNo}
  1771. </if>
  1772. <if test="vo.contactName != null and vo.contactName != ''">
  1773. AND tou.contact_name = #{vo.contactName}
  1774. </if>
  1775. <if test="vo.travelDate != null and vo.travelDate != ''">
  1776. AND td.travel_date = #{vo.travelDate}
  1777. </if>
  1778. GROUP BY td.id
  1779. ORDER BY td.create_time DESC
  1780. </select>
  1781. <update id="updateOrderStatus">
  1782. UPDATE trade_order SET order_status = #{orderStatus}, sync_status = '0' WHERE id = #{orderId} and order_status != #{orderStatus}
  1783. </update>
  1784. <update id="updateOrderIsAccount">
  1785. UPDATE trade_order SET is_account = #{isAccount} , sync_status = '0' WHERE id = #{orderId}
  1786. </update>
  1787. <update id="updateOrderDeleted">
  1788. UPDATE trade_order SET deleted = #{deleted}, sync_status = '0' WHERE id = #{orderId}
  1789. </update>
  1790. <resultMap id="OrderAndDetailResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderPdaRespVO">
  1791. <id property="id" column="id"/>
  1792. <result property="orderNo" column="order_no"/>
  1793. <result property="sourceName" column="source_name"/>
  1794. <result property="externalOrderNo" column="external_order_no"/>
  1795. <result property="routePlanId" column="route_plan_id"/>
  1796. <result property="visitorType" column="visitor_type"/>
  1797. <result property="travelDate" column="travel_date"/>
  1798. <result property="sellMethod" column="sell_method"/>
  1799. <result property="sourceName" column="source_name"/>
  1800. <result property="sellerId" column="seller_id"/>
  1801. <result property="memberId" column="member_id"/>
  1802. <result property="amount" column="amount"/>
  1803. <result property="payAmount" column="pay_amount"/>
  1804. <result property="orderStatus" column="order_status"/>
  1805. <result property="paymentDate" column="payment_date"/>
  1806. <result property="contactName" column="contact_name"/>
  1807. <result property="credentialNo" column="credential_no"/>
  1808. <result property="mobile" column="mobile"/>
  1809. <result property="remark" column="remark"/>
  1810. <collection property="tradeDetailList" resultMap="tradeDetailMap"/>
  1811. </resultMap>
  1812. <resultMap id="tradeDetailMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  1813. <result property="id" column="detailId"/>
  1814. <result property="orderId" column="order_id"/>
  1815. <result property="voucherCode" column="voucher_code"/>
  1816. <result property="voucherStatus" column="voucher_status"/>
  1817. <result property="useDate" column="use_date"/>
  1818. <result property="validityStartDate" column="validity_start_date"/>
  1819. <result property="validityEndDate" column="validity_end_date"/>
  1820. <result property="usageDays" column="usage_days"/>
  1821. <result property="checkStatus" column="check_status"/>
  1822. <result property="takeStatus" column="take_status"/>
  1823. <result property="refundStatus" column="refund_status"/>
  1824. <result property="verifyTime" column="verify_time"/>
  1825. <result property="activateStatus" column="activate_status"/>
  1826. <result property="activateDays" column="activate_days"/>
  1827. <result property="activateTime" column="activate_time"/>
  1828. <result property="productId" column="product_id"/>
  1829. <result property="productName" column="product_name"/>
  1830. <result property="specType" column="spec_type"/>
  1831. <collection property="detailBaseList" resultMap="tradeDetailBaseResMap"/>
  1832. </resultMap>
  1833. <resultMap id="tradeDetailBaseResMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.DetailBaseRespVO">
  1834. <result property="id" column="detail_base_id"/>
  1835. <result property="detailId" column="detailId"/>
  1836. <result property="productBaseId" column="product_base_id"/>
  1837. <result property="productBaseName" column="product_base_name"/>
  1838. <result property="productBaseType" column="product_base_type"/>
  1839. <result property="productResourceId" column="product_resource_id"/>
  1840. <result property="productResourceName" column="product_resource_name"/>
  1841. <result property="supplierProductId" column="supplier_product_id"/>
  1842. <result property="supplierId" column="supplier_id"/>
  1843. <result property="supplierName" column="supplier_name"/>
  1844. <result property="isSystemDirect" column="is_system_direct"/>
  1845. <result property="useStatus" column="use_status"/>
  1846. <result property="checkStatus" column="base_check_status"/>
  1847. <result property="verifyTime" column="base_verify_time"/>
  1848. <result property="price" column="base_price"/>
  1849. <result property="usageCount" column="usage_count"/>
  1850. <result property="productResourcePrice" column="product_resource_price"/>
  1851. <result property="projectId" column="project_id"/>
  1852. <result property="projectName" column="project_name"/>
  1853. <result property="specificationId" column="specification_id"/>
  1854. <result property="specificationName" column="specification_name"/>
  1855. <result property="specType" column="base_spec_type"/>
  1856. <result property="supplierVoucherCode" column="supplier_voucher_code"/>
  1857. <result property="platSupplierOrderId" column="plat_supplier_order_id"/>
  1858. </resultMap>
  1859. <select id="getOrderAndDetailInfo" resultMap="OrderAndDetailResultMap">
  1860. SELECT distinct td.id,td.order_no,td.external_order_no,td.route_plan_id,td.visitor_type,td.travel_date,td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,td.payment_date,td.remark,
  1861. tou.contact_name,tou.credential_no,tou.mobile,
  1862. tdl.id detailId,tdl.voucher_code,tdl.voucher_status,tdl.product_name,tdl.spec_type,tdl.validity_start_date,tdl.validity_end_date,
  1863. tdb.id detail_base_id,tdb.detail_id,tdb.product_base_id,tdb.product_base_name,tdb.product_base_type,tdb.product_resource_id,tdb.product_resource_name,tdb.supplier_product_id,tdb.supplier_id,
  1864. tdb.supplier_name,tdb.is_system_direct,tdb.use_status,tdb.check_status base_check_status,tdb.verify_time base_verify_time,tdb.price base_price,tdb.usage_count,tdb.product_resource_price,tdb.project_id,tdb.project_name,
  1865. tdb.specification_id,tdb.specification_name,tdb.spec_type base_spec_type,tdb.supplier_voucher_code,tdb.plat_supplier_order_id
  1866. FROM trade_order td
  1867. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1868. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1869. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1870. inner join trade_detail_base tdb on tdl.id = tdb.detail_id
  1871. where 1= 1 and td.order_status >= 6 and td.order_status <![CDATA[ <= ]]> 9
  1872. and td.sell_method != 3 and td.sell_method != 4
  1873. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1874. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1875. <if test="channelId != null and channelId != ''">
  1876. and tdb.product_base_id in (select product_id from product_check_channel where channel_id=#{channelId} and deleted = 0)
  1877. </if>
  1878. <if test="orderNo != null and orderNo != ''">
  1879. AND td.order_no = #{orderNo}
  1880. </if>
  1881. <choose>
  1882. <when test="phone != null and phone.length() == 4">
  1883. AND tou.mobile like concat('%',#{phone})
  1884. </when>
  1885. <when test="phone != null and phone != ''">
  1886. AND tou.mobile = #{phone}
  1887. </when>
  1888. <otherwise>
  1889. </otherwise>
  1890. </choose>
  1891. <choose>
  1892. <when test="cardNo != null and cardNo.length() == 4">
  1893. AND tv.credential_no like concat('%',#{cardNo})
  1894. </when>
  1895. <when test="cardNo != null and cardNo != ''">
  1896. AND tv.credential_no = #{cardNo}
  1897. </when>
  1898. <otherwise>
  1899. </otherwise>
  1900. </choose>
  1901. ORDER BY td.travel_date DESC
  1902. </select>
  1903. <select id="getPlatOrderNo" resultType="java.lang.String">
  1904. select t3.order_no from trade_order t1
  1905. inner join trade_supplier_order t2 on t1.id = t2.order_id
  1906. inner join trade_order t3 on t2.trade_no = t3.external_order_no
  1907. where t1.order_no = #{orderNo}
  1908. </select>
  1909. <select id="getTotalPayByOrderNo" resultType="java.math.BigDecimal">
  1910. select sum(t2.pay_amount) from trade_order t1 inner join trade_order_pay t2 on t1.id = t2.order_id
  1911. where t1.order_no = #{orderNo} and t2.pay_status = 1
  1912. </select>
  1913. <select id="getCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1914. SELECT td.id,td.order_no,td.external_order_no,td.route_plan_id,td.travel_status,plan.name as route_plan_name,td.visitor_type,td.travel_date,
  1915. td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,
  1916. td.payment_date,td.remark, tou.contact_name,tou.credential_no,tou.mobile,td.is_add_order
  1917. FROM trade_order td
  1918. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1919. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1920. left join product_route_plan plan on td.route_plan_id = plan.id
  1921. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
  1922. left join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
  1923. </if>
  1924. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
  1925. left join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
  1926. </if>
  1927. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1928. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1929. </if>
  1930. where 1=1
  1931. <choose>
  1932. <when test="vo.orderStatus != null">
  1933. AND td.order_status = #{vo.orderStatus}
  1934. </when>
  1935. <otherwise>
  1936. and td.order_status in (6,7,8,9,10,13)
  1937. </otherwise>
  1938. </choose>
  1939. <choose>
  1940. <when test="vo.travelDate != null and vo.travelDate != ''">
  1941. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  1942. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  1943. </when>
  1944. <otherwise>
  1945. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1946. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1947. </otherwise>
  1948. </choose>
  1949. <choose>
  1950. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1951. AND td.order_no like concat('%',#{vo.orderNo})
  1952. </when>
  1953. <when test="vo.orderNo != null and vo.orderNo != ''">
  1954. AND td.order_no = #{vo.orderNo}
  1955. </when>
  1956. <otherwise>
  1957. </otherwise>
  1958. </choose>
  1959. <choose>
  1960. <when test="vo.phone != null and vo.phone.length() == 4">
  1961. AND tou.mobile like concat('%',#{vo.phone})
  1962. </when>
  1963. <when test="vo.phone != null and vo.phone != ''">
  1964. AND tou.mobile = #{vo.phone}
  1965. </when>
  1966. <otherwise>
  1967. </otherwise>
  1968. </choose>
  1969. <choose>
  1970. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  1971. AND tv.credential_no like concat('%',#{vo.credentialNo})
  1972. </when>
  1973. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  1974. AND tv.credential_no = #{vo.credentialNo}
  1975. </when>
  1976. <otherwise>
  1977. </otherwise>
  1978. </choose>
  1979. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  1980. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  1981. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  1982. </if>
  1983. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  1984. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  1985. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  1986. </if>
  1987. <if test="vo.travelStatus != null">
  1988. AND td.travel_status = #{vo.travelStatus}
  1989. </if>
  1990. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1991. AND tdl.voucher_code = #{vo.voucherCode}
  1992. </if>
  1993. <if test="vo.productName != null and vo.productName != ''">
  1994. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1995. </if>
  1996. <if test="vo.sellMethod != null">
  1997. AND td.sell_method = #{vo.sellMethod}
  1998. </if>
  1999. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  2000. AND (td.route_plan_id in
  2001. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  2002. #{item}
  2003. </foreach>
  2004. or tdl.product_id in
  2005. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  2006. #{item}
  2007. </foreach>
  2008. )
  2009. </if>
  2010. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  2011. AND tdl.product_id in
  2012. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  2013. #{item}
  2014. </foreach>
  2015. </if>
  2016. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  2017. and td.route_plan_id in
  2018. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  2019. #{item}
  2020. </foreach>
  2021. </if>
  2022. group by td.id
  2023. ORDER BY td.create_time DESC
  2024. </select>
  2025. <select id="countCheckOrder" resultType="java.lang.Integer">
  2026. SELECT count(DISTINCT td.id) num FROM trade_order td
  2027. INNER JOIN trade_detail tdl ON td.id = tdl.order_id
  2028. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  2029. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  2030. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  2031. </if>
  2032. where 1=1
  2033. <choose>
  2034. <when test="vo.orderStatus != null">
  2035. AND td.order_status = #{vo.orderStatus}
  2036. </when>
  2037. <otherwise>
  2038. and td.order_status in (6,7,8,9,10,13)
  2039. </otherwise>
  2040. </choose>
  2041. <choose>
  2042. <when test="vo.travelDate != null and vo.travelDate != ''">
  2043. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  2044. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  2045. </when>
  2046. <otherwise>
  2047. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  2048. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  2049. </otherwise>
  2050. </choose>
  2051. <choose>
  2052. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  2053. AND td.order_no like concat('%',#{vo.orderNo})
  2054. </when>
  2055. <when test="vo.orderNo != null and vo.orderNo != ''">
  2056. AND td.order_no = #{vo.orderNo}
  2057. </when>
  2058. <otherwise>
  2059. </otherwise>
  2060. </choose>
  2061. <choose>
  2062. <when test="vo.phone != null and vo.phone.length() == 4">
  2063. AND tou.mobile like concat('%',#{vo.phone})
  2064. </when>
  2065. <when test="vo.phone != null and vo.phone != ''">
  2066. AND tou.mobile = #{vo.phone}
  2067. </when>
  2068. <otherwise>
  2069. </otherwise>
  2070. </choose>
  2071. <choose>
  2072. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  2073. AND tv.credential_no like concat('%',#{vo.credentialNo})
  2074. </when>
  2075. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  2076. AND tv.credential_no = #{vo.credentialNo}
  2077. </when>
  2078. <otherwise>
  2079. </otherwise>
  2080. </choose>
  2081. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  2082. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  2083. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  2084. </if>
  2085. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  2086. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  2087. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  2088. </if>
  2089. <if test="vo.travelStatus != null">
  2090. AND td.travel_status = #{vo.travelStatus}
  2091. </if>
  2092. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  2093. AND tdl.voucher_code = #{vo.voucherCode}
  2094. </if>
  2095. <if test="vo.productName != null and vo.productName != ''">
  2096. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  2097. </if>
  2098. <if test="vo.sellMethod != null">
  2099. AND td.sell_method = #{vo.sellMethod}
  2100. </if>
  2101. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  2102. AND (td.route_plan_id in
  2103. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  2104. #{item}
  2105. </foreach>
  2106. or tdl.product_id in
  2107. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  2108. #{item}
  2109. </foreach>
  2110. )
  2111. </if>
  2112. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  2113. AND tdl.product_id in
  2114. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  2115. #{item}
  2116. </foreach>
  2117. </if>
  2118. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  2119. and td.route_plan_id in
  2120. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  2121. #{item}
  2122. </foreach>
  2123. </if>
  2124. </select>
  2125. <select id="selectStoreMachineProductList"
  2126. resultType="java.lang.Long">
  2127. SELECT t1.product_id FROM otc_agency_store_machine_product t1
  2128. where 1=1
  2129. <if test="vo.storeId != null and vo.storeId != ''">
  2130. AND t1.store_id = #{vo.storeId}
  2131. </if>
  2132. <if test="vo.machineId != null and vo.machineId != ''">
  2133. AND t1.machine_id = #{vo.machineId}
  2134. </if>
  2135. </select>
  2136. <select id="orderListByOta" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  2137. SELECT
  2138. t1.*
  2139. FROM
  2140. trade_order t1
  2141. inner join trade_detail t3 on t1.id = t3.order_id
  2142. inner join trade_visitor t4 on t3.id = t4.detail_id
  2143. INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
  2144. WHERE
  2145. t1.sell_method = 0
  2146. AND t1.order_status in (6,7,8,9,10,13)
  2147. AND t1.tenant_id = #{tenantId}
  2148. AND t1.travel_date = #{travelDate}
  2149. <if test="credentialNo != null and credentialNo != ''">
  2150. AND t4.credential_no = #{credentialNo}
  2151. </if>
  2152. <if test="mobile != null and mobile != ''">
  2153. AND t2.mobile = #{mobile}
  2154. </if>
  2155. ORDER BY
  2156. t1.payment_date DESC
  2157. </select>
  2158. <select id="orderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  2159. SELECT
  2160. t1.*
  2161. FROM
  2162. trade_order t1
  2163. INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
  2164. INNER JOIN trade_detail td on t1.id = td.order_id
  2165. INNER JOIN trade_visitor v on v.detail_id = td.id
  2166. WHERE
  2167. 1 = 1
  2168. <if test="orderStatus!=null and orderStatus.size()>0">
  2169. AND t1.order_status in
  2170. <foreach collection="orderStatus" item="item" separator="," open="(" close=")">
  2171. #{item}
  2172. </foreach>
  2173. </if>
  2174. AND t1.tenant_id = #{tenantId}
  2175. AND t1.travel_date = #{travelDate}
  2176. <if test="credentialNo != null and credentialNo != ''">
  2177. AND v.credential_no = #{credentialNo}
  2178. </if>
  2179. <if test="mobile != null and mobile != ''">
  2180. AND t2.mobile = #{mobile}
  2181. </if>
  2182. group by t1.id
  2183. ORDER BY
  2184. t1.payment_date DESC
  2185. </select>
  2186. <select id="queryOneByOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  2187. SELECT DISTINCT o2.*
  2188. FROM trade_order o
  2189. INNER JOIN trade_detail d on d.order_id = o.id
  2190. INNER JOIN trade_detail_base db ON db.detail_id = d.id
  2191. INNER JOIN trade_detail d2 ON db.supplier_voucher_code = d2.voucher_code
  2192. INNER JOIN trade_order o2 ON d2.order_id = o2.id
  2193. WHERE o.order_no = #{orderNo}
  2194. union all
  2195. SELECT o.* FROM trade_order o WHERE o.sell_method in (0,1,4,6,7) and o.order_no = #{orderNo}
  2196. </select>
  2197. <select id="updateAppletProductSellNum">
  2198. update applet_product t1 inner JOIN applet_product_group t2 ON t1.id = t2.applet_product_id
  2199. and t2.deleted =0
  2200. set t1.sell_num = t1.sell_num+#{sellNum} where t2.product_id = #{productId}
  2201. </select>
  2202. <select id="selectCanBindOrderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  2203. SELECT o.id,o.is_bind
  2204. FROM trade_order o
  2205. INNER JOIN trade_detail d ON d.order_id = o.id
  2206. INNER JOIN trade_order_user u on o.id = u.order_id
  2207. WHERE
  2208. o.order_status > 5 AND o.deleted = 0
  2209. AND (o.is_bind IS NULL or o.is_bind = 0 ) and o.id != #{vo.orderId}
  2210. AND o.travel_date = #{vo.travelDate}
  2211. AND d.product_id = #{vo.productId}
  2212. <if test="vo.routePlanId !=null">
  2213. And o.route_plan_id = #{vo.routePlanId}
  2214. </if>
  2215. AND u.mobile = #{vo.mobile}
  2216. GROUP BY o.id
  2217. </select>
  2218. <update id="deleteOrderById">
  2219. delete from trade_order where id = #{orderId}
  2220. </update>
  2221. <update id="deleteOrderByOrderNo">
  2222. update from trade_order where order_no = #{orderNo}
  2223. </update>
  2224. <select id="getInvoiceOrderCount" resultType="java.lang.Integer">
  2225. select count(1) num from trade_invoice t1 inner join trade_invoice_detail t2 on t1.id = t2.invoice_id
  2226. and t1.invoice_status in (1,3)
  2227. where t2.order_no = #{orderNo} and t1.deleted = 0
  2228. </select>
  2229. <select id="selectPlatPayAmountByOriginOrderNo" resultType="java.util.Map">
  2230. select sum(tod.pay_amount) totalPayAmount
  2231. from trade_order tod
  2232. where tod.external_origin_order_no =#{originOrderNo} and tod.order_status>=6
  2233. </select>
  2234. <select id="selectChangeCountByOrderId" resultType="java.lang.Integer">
  2235. select count(*) totalCount
  2236. from trade_order tod
  2237. inner join trade_order_bind tb on tod.id = tb.order_id and tb.type = 2 and tb.deleted =0
  2238. inner join trade_order tod1 on tod1.id = tb.bind_id
  2239. where tod.id = #{orderId} and tod1.order_status>=6
  2240. </select>
  2241. <update id="updateOrderFinishStatus">
  2242. update trade_order tod,
  2243. (select tod.id
  2244. from trade_order tod
  2245. inner join trade_detail td on tod.id = td.order_id
  2246. where tod.sell_method in
  2247. <foreach collection="sellMethodList" item="item" separator="," open="(" close=")">
  2248. #{item}
  2249. </foreach>
  2250. and tod.order_status >=6
  2251. and td.validity_end_date = #{endDate}
  2252. and not EXISTS (
  2253. select 1
  2254. from trade_detail td1
  2255. where td1.validity_end_date > #{endDate} and td1.order_id = tod.id and td1.refund_status != 1
  2256. )
  2257. ) t
  2258. set tod.finish_status = 1
  2259. where tod.id = t.id
  2260. </update>
  2261. <select id="getSupplierCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  2262. SELECT td.id,td.order_no,td.external_order_no,td.route_plan_id,plan.name as route_plan_name,td.visitor_type,td.travel_date,
  2263. td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,
  2264. td.payment_date,td.remark, tou.contact_name,tou.credential_no,tou.mobile
  2265. FROM trade_order td
  2266. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  2267. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  2268. INNER JOIN trade_detail_base tdb on tdb.detail_id = tdl.id
  2269. left join product_route_plan plan on td.route_plan_id = plan.id
  2270. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
  2271. inner join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
  2272. </if>
  2273. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
  2274. inner join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
  2275. </if>
  2276. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  2277. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  2278. </if>
  2279. where supplier_id in (
  2280. select t2.id from product_supplier_user t1 inner join product_supplier t2 on t1.supplier_id = t2.id
  2281. where t1.user_id=#{vo.userId} and t1.deleted =0
  2282. )
  2283. <choose>
  2284. <when test="vo.orderStatus != null">
  2285. AND td.order_status = #{vo.orderStatus}
  2286. </when>
  2287. <otherwise>
  2288. and td.order_status in (6,7,8,9,10,13)
  2289. </otherwise>
  2290. </choose>
  2291. <choose>
  2292. <when test="vo.travelDate != null and vo.travelDate != ''">
  2293. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  2294. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  2295. </when>
  2296. <otherwise>
  2297. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  2298. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  2299. </otherwise>
  2300. </choose>
  2301. <choose>
  2302. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  2303. AND td.order_no like concat('%',#{vo.orderNo})
  2304. </when>
  2305. <when test="vo.orderNo != null and vo.orderNo != ''">
  2306. AND td.order_no = #{vo.orderNo}
  2307. </when>
  2308. <otherwise>
  2309. </otherwise>
  2310. </choose>
  2311. <choose>
  2312. <when test="vo.phone != null and vo.phone.length() == 4">
  2313. AND tou.mobile like concat('%',#{vo.phone})
  2314. </when>
  2315. <when test="vo.phone != null and vo.phone != ''">
  2316. AND tou.mobile = #{vo.phone}
  2317. </when>
  2318. <otherwise>
  2319. </otherwise>
  2320. </choose>
  2321. <choose>
  2322. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  2323. AND tv.credential_no like concat('%',#{vo.credentialNo})
  2324. </when>
  2325. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  2326. AND tv.credential_no = #{vo.credentialNo}
  2327. </when>
  2328. <otherwise>
  2329. </otherwise>
  2330. </choose>
  2331. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  2332. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  2333. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  2334. </if>
  2335. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  2336. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  2337. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  2338. </if>
  2339. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  2340. AND tdl.voucher_code = #{vo.voucherCode}
  2341. </if>
  2342. <if test="vo.checkType != null and vo.checkType == 1">
  2343. AND tdb.use_status in (1,2)
  2344. </if>
  2345. <if test="vo.checkType != null and vo.checkType == 2">
  2346. AND tdb.use_status in (3,6,8)
  2347. </if>
  2348. <if test="vo.productName != null and vo.productName != ''">
  2349. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  2350. </if>
  2351. <if test="vo.sellMethod != null">
  2352. AND td.sell_method = #{vo.sellMethod}
  2353. </if>
  2354. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  2355. AND (td.route_plan_id in
  2356. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  2357. #{item}
  2358. </foreach>
  2359. or tdl.product_id in
  2360. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  2361. #{item}
  2362. </foreach>
  2363. )
  2364. </if>
  2365. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  2366. AND tdl.product_id in
  2367. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  2368. #{item}
  2369. </foreach>
  2370. </if>
  2371. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  2372. and td.route_plan_id in
  2373. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  2374. #{item}
  2375. </foreach>
  2376. </if>
  2377. group by td.id
  2378. ORDER BY td.create_time DESC
  2379. </select>
  2380. <select id="getOtaTradeOrderPage"
  2381. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  2382. SELECT td.*,tor.order_no,pbr.check_start_date,pbr.check_end_date
  2383. FROM trade_detail td
  2384. LEFT JOIN product_basic_rule pbr on td.product_id = pbr.id
  2385. LEFT JOIN trade_order tor on tor.id = td.order_id
  2386. where 1= 1 AND
  2387. EXISTS (select * from product_sale_channel sc where sc.product_id = td.product_id and sc.channel_id = 0)
  2388. <if test="vo.productName != null and vo.productName != ''">
  2389. AND td.product_name = #{vo.productName}
  2390. </if>
  2391. <if test="vo.orderNo != null and vo.orderNo != ''">
  2392. AND tor.order_no = #{vo.orderNo}
  2393. </if>
  2394. <if test="vo.orderStatus != null and vo.orderStatus != ''">
  2395. AND tor.order_status = #{vo.orderStatus}
  2396. </if>
  2397. <if test="vo.paymentDateStart != null">
  2398. AND tor.payment_date <![CDATA[ >= ]]> #{vo.paymentDateStart}
  2399. </if>
  2400. <if test="vo.paymentDateEnd != null">
  2401. AND tor.payment_date <![CDATA[ <= ]]> #{vo.paymentDateEnd}
  2402. </if>
  2403. <if test="vo.type == 1">
  2404. AND tor.source_id = #{distributorId}
  2405. </if>
  2406. GROUP BY td.voucher_code
  2407. ORDER BY td.create_time DESC
  2408. </select>
  2409. <select id="regionStatic" resultType="java.util.Map">
  2410. select t4.id,t4.`name`,t6.province,t6.city,count(DISTINCT t3.id) num from trade_order t1 inner join trade_detail t2 on t1.id = t2.order_id
  2411. inner join trade_visitor t3 on t2.visitor_id = t3.id
  2412. inner join ota_distributor t4 on t1.source_id = t4.id
  2413. inner join ota_distributor_region t5 on t4.id = t5.distributor_id
  2414. and (left(t3.credential_no,2) = t5.distributor_region_id or left(t3.credential_no,4) = t5.distributor_region_id)
  2415. inner join ota_region t6 on ((t5.distributor_region_id = province_code and LEVEL=1) or t5.distributor_region_id = left(t6.id,4) )
  2416. where t2.voucher_status in (1,2,3,4,6,8,9)
  2417. <if test="vo.startDate != null and vo.startDate!=''">
  2418. AND t2.use_date <![CDATA[ >= ]]> #{vo.startDate}
  2419. </if>
  2420. <if test="vo.endDate != null and vo.endDate!=''">
  2421. AND t2.use_date <![CDATA[ <= ]]> #{vo.endDate}
  2422. </if>
  2423. GROUP BY t4.id
  2424. order by num desc
  2425. </select>
  2426. <select id="queryOrderByLast" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  2427. SELECT * FROM trade_order WHERE order_no = #{orderNo} and deleted = 1 ORDER BY update_time DESC limit 1
  2428. </select>
  2429. <select id="queryOrderById" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  2430. SELECT * FROM trade_order WHERE id = #{orderId} ORDER BY update_time DESC limit 1
  2431. </select>
  2432. <select id="selectConfirmationCountry"
  2433. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderConfirmationCountryRespVO">
  2434. SELECT
  2435. t5.room_model_type_id,
  2436. t3.short_name room_model_short_name,
  2437. t3.NAME room_model_name,
  2438. ifnull( t1.nationality, 1 ) nationality,
  2439. ifnull( t4.NAME, '中国' ) nationality_name,
  2440. t1.room_model_id,
  2441. t1.type,
  2442. ifnull(t1.floor,'0') floor,
  2443. count( t1.id ) num,
  2444. ifnull(t2.actual_price,0) actual_price
  2445. FROM
  2446. trade_visitor t1
  2447. LEFT JOIN trade_detail t2 ON t1.id = t2.visitor_id
  2448. AND t2.product_type = 0
  2449. AND t1.deleted = 0
  2450. LEFT JOIN resource_room_model t3 ON t1.room_model_id = t3.id
  2451. AND t3.deleted = 0
  2452. LEFT JOIN area t4 ON t1.nationality = t4.id
  2453. LEFT JOIN trade_order_room_model t5 ON t1.room_index_id = t5.room_index_id
  2454. AND t5.deleted = 0
  2455. LEFT JOIN product_price_room_model_type t6 ON t5.room_model_type_id = t6.id
  2456. WHERE
  2457. t1.order_id = #{orderId}
  2458. GROUP BY
  2459. t1.room_model_id,
  2460. t1.floor,
  2461. t1.type,
  2462. t1.nationality,
  2463. t5.room_model_type_id
  2464. ORDER BY
  2465. floor DESC
  2466. </select>
  2467. <select id="getOrderCount" resultType="java.util.Map">
  2468. select GROUP_CONCAT(num,'*',name) name,sum(num1) num1,sum(num2) num2,sum(num3) num3,sum(num4) num4 from (
  2469. SELECT sum(CASE WHEN tv.type='adultPlus' or tv.type='adultTake' THEN 1 ELSE 0 END) num1,
  2470. sum(CASE WHEN tv.type='babyTake' or tv.type='babyPlus' or tv.type='babyNonTake' or tv.type='childTake' or tv.type='childPlus' or tv.type='childNonTake' THEN 1 ELSE 0 END) num2,
  2471. sum(CASE WHEN tv.type='with' THEN 1 ELSE 0 END) num3,
  2472. sum(CASE WHEN tv.type='leader' THEN 1 ELSE 0 END) num4,
  2473. CONCAT(rrm.short_name,'(',tv.floor,'F)') name ,count(1) num
  2474. FROM trade_order td
  2475. INNER JOIN trade_order_user tou on td.id = tou.order_id
  2476. left JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  2477. left join trade_visitor tv on tdl.id = tv.detail_id
  2478. left JOIN product_spu ps on ps.id = tdl.product_id
  2479. LEFT JOIN ota_distributor od on od.id = td.source_id
  2480. left join trade_order_room_model tm on tv.room_index_id = tm.room_index_id and tm.deleted =0 AND td.id = tm.order_id
  2481. left join resource_room_model rrm on tm.room_model_id = rrm.id
  2482. LEFT JOIN (select m2.order_id,sum(m2.refund_amount) refund_amount,sum(m2.origin_amount) origin_amount from trade_refund m2 where m2.refund_status = 6 and m2.refund_method !=2 GROUP BY m2.order_id) tr on td.id = tr.order_id
  2483. where td.deleted = 0 and tou.deleted = 0 and td.order_status >0 and tv.type is not null
  2484. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  2485. and td.order_status in
  2486. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  2487. #{item}
  2488. </foreach>
  2489. </if>
  2490. <if test="vo.tenantId!=null">
  2491. AND td.tenant_id = #{vo.tenantId}
  2492. </if>
  2493. <choose>
  2494. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  2495. AND td.order_no like concat('%',#{vo.orderNo})
  2496. </when>
  2497. <when test="vo.orderNo != null and vo.orderNo != ''">
  2498. AND td.order_no = #{vo.orderNo}
  2499. </when>
  2500. <otherwise>
  2501. </otherwise>
  2502. </choose>
  2503. <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
  2504. AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
  2505. </if>
  2506. <if test="vo.memberId != null and vo.memberId != ''">
  2507. AND td.member_id = #{vo.memberId}
  2508. </if>
  2509. <if test="vo.voyageId != null and vo.voyageId != ''">
  2510. AND td.voyage_id = #{vo.voyageId}
  2511. </if>
  2512. <if test="vo.shipId != null and vo.shipId != ''">
  2513. AND td.ship_id = #{vo.shipId}
  2514. </if>
  2515. <if test="vo.routeId != null and vo.routeId != ''">
  2516. AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
  2517. </if>
  2518. <if test="vo.dispatchStatus != null">
  2519. AND td.dispatch_status = #{vo.dispatchStatus}
  2520. </if>
  2521. <if test="vo.payType != null">
  2522. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  2523. </if>
  2524. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  2525. AND od.ota_category_id = #{vo.otaCateId}
  2526. </if>
  2527. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  2528. and od.ota_category_id in
  2529. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  2530. #{item}
  2531. </foreach>
  2532. </if>
  2533. <if test="vo.otaId != null and vo.otaId != ''">
  2534. AND td.source_id = #{vo.otaId}
  2535. </if>
  2536. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  2537. AND td.source_id IN
  2538. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  2539. #{item}
  2540. </foreach>
  2541. </if>
  2542. <if test="vo.storeId != null and vo.storeId != ''">
  2543. AND td.store_id = #{vo.storeId}
  2544. </if>
  2545. <if test="vo.productTag != null and vo.productTag != ''">
  2546. AND ps.product_tag = #{vo.productTag}
  2547. </if>
  2548. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  2549. AND ps.product_tag2 = #{vo.productTag2}
  2550. </if>
  2551. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  2552. AND ps.product_tag3 = #{vo.productTag3}
  2553. </if>
  2554. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  2555. AND ps.product_tag4 = #{vo.productTag4}
  2556. </if>
  2557. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  2558. AND tdl.product_id in
  2559. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  2560. #{item}
  2561. </foreach>
  2562. </if>
  2563. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  2564. AND td.external_order_no = #{vo.externalOrderNo}
  2565. </if>
  2566. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  2567. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  2568. </if>
  2569. <if test="vo.userName != null and vo.userName != ''">
  2570. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  2571. </if>
  2572. <choose>
  2573. <when test="vo.mobile != null and vo.mobile.length() == 4">
  2574. AND tou.mobile like concat('%',#{vo.mobile})
  2575. </when>
  2576. <when test="vo.mobile != null and vo.mobile != ''">
  2577. AND tou.mobile = #{vo.mobile}
  2578. </when>
  2579. <otherwise>
  2580. </otherwise>
  2581. </choose>
  2582. <if test="vo.contactName != null and vo.contactName != ''">
  2583. AND tou.contact_name = #{vo.contactName}
  2584. </if>
  2585. <if test="vo.travelDate != null and vo.travelDate != ''">
  2586. AND td.travel_date = #{vo.travelDate}
  2587. </if>
  2588. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  2589. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  2590. </if>
  2591. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  2592. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  2593. </if>
  2594. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  2595. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  2596. </if>
  2597. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  2598. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  2599. </if>
  2600. <if test="vo.orderDate != null and vo.orderDate != ''">
  2601. AND td.create_time = #{vo.orderDate}
  2602. </if>
  2603. <if test="vo.sellerId != null and vo.sellerId != ''">
  2604. AND td.seller_id = #{vo.sellerId}
  2605. </if>
  2606. <if test="vo.shareName != null and vo.shareName != ''">
  2607. AND td.share_name like concat('%',#{vo.shareName},'%')
  2608. </if>
  2609. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  2610. AND tdl.voucher_code = #{vo.voucherCode}
  2611. </if>
  2612. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  2613. AND td.sell_method = #{vo.sellMethod}
  2614. </if>
  2615. <if test="vo.productName != null and vo.productName != ''">
  2616. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  2617. </if>
  2618. <if test="vo.isFullPay == 0">
  2619. AND td.is_full_pay = #{vo.isFullPay}
  2620. </if>
  2621. <if test="vo.isComment != null">
  2622. AND td.is_comment = #{vo.isComment}
  2623. </if>
  2624. <if test="vo.sourceId != null and vo.sourceId != ''">
  2625. AND td.source_id = #{vo.sourceId}
  2626. </if>
  2627. <if test="vo.distributorId != null and vo.distributorId != ''">
  2628. AND td.source_id = #{vo.distributorId}
  2629. </if>
  2630. <if test="vo.sourceName != null and vo.sourceName != ''">
  2631. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  2632. </if>
  2633. <if test="vo.travelStatus != null">
  2634. AND td.travel_status = #{vo.travelStatus}
  2635. </if>
  2636. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  2637. AND exists (select 1 from trade_refund tr where tr.order_id=td.id and tr.refund_status = 6 and tr.refund_time BETWEEN #{vo.orderRefundDateStart} and #{vo.orderRefundDateEnd} )
  2638. </if>
  2639. GROUP BY rrm.short_name,tv.floor
  2640. ) p
  2641. </select>
  2642. <select id="selectTotalByOrderIds" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.OrderTotalRespVO">
  2643. select sum(adult_total_num) adultTotalNum, sum(child_total_num) childTotalNum, sum(baby_total_num) babyTotalNum,
  2644. sum(with_total_num) withTotalNum, sum(leader_total_num) leaderTotalNum, sum(free_num) freeNum,
  2645. sum(order_money) orderMoney, sum(real_money) realMoney, sum(other_money) otherMoney,
  2646. sum(adjust_total_money) adjustTotalMoney, sum(with_amount) withTotalNumMoney,
  2647. sum(leader_amount) leaderTotalMoney, sum(free_amount) freeAmount, sum(service_money) serviceMoney,
  2648. sum(up_floor_total_num) upFloorTotalNum, sum(up_floor_total_money) upFloorTotalMoney,
  2649. sum(plus_total_num) plusTotalNum, sum(collection_service_money) collectionServiceMoney,
  2650. sum(use_room_total_num) totalRoomNum,sum(free_amount) freeAmount from trade_order_total
  2651. where 1=1 and deleted = 0
  2652. AND old_order_id in
  2653. <foreach collection="orderIds" item="item" separator="," open="(" close=")">
  2654. #{item}
  2655. </foreach>
  2656. </select>
  2657. <!-- 查询游客名单导出基础信息(船名、航期、航向) -->
  2658. <select id="selectTouristExportBase" resultType="java.util.Map">
  2659. SELECT
  2660. rs.name as shipName,
  2661. pv.start_time as travelDate,
  2662. rr.direction as direction
  2663. FROM trade_order tor
  2664. LEFT JOIN product_voyage pv ON tor.voyage_id = pv.id
  2665. LEFT JOIN resource_ship rs ON pv.ship_id = rs.id
  2666. LEFT JOIN resource_route rr ON pv.route_id = rr.id
  2667. LEFT JOIN ota_distributor od on od.id = tor.source_id
  2668. WHERE tor.deleted = 0
  2669. <if test="vo.orderNo != null and vo.orderNo != ''">
  2670. AND tor.order_no = #{vo.orderNo}
  2671. </if>
  2672. <if test="vo.voyageId != null and vo.voyageId != ''">
  2673. AND tor.voyage_id = #{vo.voyageId}
  2674. </if>
  2675. <if test="vo.shipId != null and vo.shipId != ''">
  2676. AND pv.ship_id = #{vo.shipId}
  2677. </if>
  2678. <if test="vo.routeId != null and vo.routeId != ''">
  2679. AND pv.route_id = #{vo.routeId}
  2680. </if>
  2681. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  2682. AND pv.start_time &gt;= #{vo.travelDateStart}
  2683. </if>
  2684. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  2685. AND pv.start_time &lt;= #{vo.travelDateEnd}
  2686. </if>
  2687. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  2688. AND tor.create_time &gt;= #{vo.orderDateStart}
  2689. </if>
  2690. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  2691. AND tor.create_time &lt;= #{vo.orderDateEnd}
  2692. </if>
  2693. <if test="vo.orderStatus != null and vo.orderStatus.size() > 0">
  2694. AND tor.order_status IN
  2695. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  2696. #{item}
  2697. </foreach>
  2698. </if>
  2699. <if test="vo.otaId != null and vo.otaId != ''">
  2700. AND tor.source_id = #{vo.otaId}
  2701. </if>
  2702. <if test="vo.otaIds != null and vo.otaIds.size()>0">
  2703. AND tor.source_id IN
  2704. <foreach collection="vo.otaIds" item="item" separator="," open="(" close=")">
  2705. #{item}
  2706. </foreach>
  2707. </if>
  2708. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  2709. AND od.ota_category_id = #{vo.otaCateId}
  2710. </if>
  2711. <if test="vo.otaCateIds != null and vo.otaCateIds.size() > 0">
  2712. AND od.ota_category_id IN
  2713. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  2714. #{item}
  2715. </foreach>
  2716. </if>
  2717. <if test="vo.contactName != null and vo.contactName != ''">
  2718. AND tor.link_man LIKE CONCAT('%', #{vo.contactName}, '%')
  2719. </if>
  2720. <if test="vo.mobile != null and vo.mobile != ''">
  2721. AND tor.link_mobile = #{vo.mobile}
  2722. </if>
  2723. LIMIT 1
  2724. </select>
  2725. <select id="selectAppPage" resultType="com.yc.ship.module.trade.controller.app.otc.vo.AppTradeOrderRespNewVO">
  2726. select t1.id, t1.order_no, t3.img, t1.ship_id, t3.`name` ship_name, t3.short_name ship_short_name,t4.`name` route_name, t4.direction, t1.voyage_id, t2.`name` voyage_name,t2.boarding_time,t2.start_time,t2.leave_time, t1.order_status, t1.amount price from trade_order t1 LEFT JOIN product_voyage t2 on t1.voyage_id = t2.id
  2727. LEFT JOIN resource_ship t3 on t1.ship_id = t3.id
  2728. LEFT JOIN resource_route t4 on t2.route_id = t4.id
  2729. where t1.deleted = 0
  2730. and member_id = #{pageReqVO.memberId}
  2731. <if test="pageReqVO.orderStatus != null and pageReqVO.orderStatus != ''">
  2732. and order_status = #{pageReqVO.orderStatus}
  2733. </if>
  2734. order by t1.create_time desc
  2735. </select>
  2736. <select id="selectMyItinerary"
  2737. resultType="com.yc.ship.module.trade.controller.app.otc.vo.AppMyItineraryVO">
  2738. SELECT
  2739. t1.id order_id,
  2740. t1.order_no,
  2741. t1.ship_id,
  2742. t4.name ship_name,
  2743. t1.voyage_id,
  2744. t2.`name` voyage_name,
  2745. t2.route_id,
  2746. t3.`name` route_name,
  2747. t2.boarding_time,
  2748. t2.start_time,
  2749. t2.leave_time,
  2750. t3.direction,
  2751. t5.room_model_id,
  2752. t5.floor,
  2753. t5.room_id
  2754. FROM
  2755. trade_order t1
  2756. LEFT JOIN product_voyage t2 ON t1.voyage_id = t2.id
  2757. LEFT JOIN resource_route t3 ON t2.route_id = t3.id
  2758. LEFT JOIN resource_ship t4 ON t2.ship_id = t4.id
  2759. left join trade_visitor t5 on t1.id = t5.order_id
  2760. WHERE
  2761. t1.deleted = 0
  2762. and t1.order_status in (3,6,7,8,9)
  2763. <choose>
  2764. <when test="keyword != null and keyword != ''">
  2765. and (t5.mobile = #{keyword} or t5.credential_no = #{keyword})
  2766. </when>
  2767. <otherwise>
  2768. and member_id = #{memberId}
  2769. </otherwise>
  2770. </choose>
  2771. <if test="status != null and status != ''">
  2772. <if test="status == '1' or status == 1">
  2773. and t2.boarding_time > now()
  2774. </if>
  2775. <if test="status == '2' or status == 2">
  2776. and t2.boarding_time &lt;= now() and t2.leave_time > now()
  2777. </if>
  2778. <if test="status == '3' or status == 3">
  2779. and t2.leave_time &lt; now()
  2780. </if>
  2781. </if>
  2782. order by t2.boarding_time asc
  2783. </select>
  2784. <select id="selectTotal1ByOrderIds"
  2785. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.OrderTotalRespVO">
  2786. select sum(deposi) deposi, sum(damaged) damaged, sum(supplement_amount) supplement_amount,
  2787. sum(pay_amount) pay_amount, sum(real_pay_amount) real_pay_amount,sum(pay_amount - real_pay_amount) unpaid_amount from trade_order
  2788. where 1=1 and id in
  2789. <foreach collection="orderIds" item="item" separator="," open="(" close=")">
  2790. #{item}
  2791. </foreach>
  2792. </select>
  2793. <select id="selectItineraryDetail"
  2794. resultType="com.yc.ship.module.trade.controller.app.otc.vo.AppItineraryDetailVO">
  2795. SELECT
  2796. t1.id order_id,
  2797. t1.order_no,
  2798. t2.boarding_time,
  2799. t2.start_time,
  2800. t2.leave_time,
  2801. t2.route_id,
  2802. t3.`name` route_name,
  2803. t3.on_dock_id,
  2804. t4.`name` on_dock_name
  2805. FROM
  2806. trade_order t1
  2807. LEFT JOIN product_voyage t2 ON t1.voyage_id = t2.id
  2808. LEFT JOIN resource_route t3 ON t2.route_id = t3.id
  2809. LEFT JOIN resource_dock t4 ON t3.on_dock_id = t4.id
  2810. WHERE
  2811. 1=1 and
  2812. t1.id = #{orderId}
  2813. </select>
  2814. <select id="selectTotal2ByOrderIds"
  2815. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.OrderTotalRespVO">
  2816. SELECT
  2817. ifnull( sum( CASE WHEN type = 'adultTake' OR type = 'adultPlus' or type IS NULL or type = '' THEN num ELSE 0 END ), 0 ) AS adultTotalNum,
  2818. ifnull( sum( CASE WHEN type = 'childTake' OR type = 'childNonTake' OR type = 'childPlus' THEN num ELSE 0 END ), 0 ) AS childTotalNum,
  2819. ifnull( sum( CASE WHEN type = 'babyTake' OR type = 'babyNonTake' OR type = 'babyPlus' THEN num ELSE 0 END ), 0 ) AS babyTotalNum,
  2820. ifnull( sum( CASE WHEN type = 'leader' THEN num ELSE 0 END ), 0 ) AS leaderTotalNum,
  2821. ifnull( sum( CASE WHEN type = 'with' THEN num ELSE 0 END ), 0 ) AS withTotalNum,
  2822. ifnull( sum( num ), 0 ) AS totalNum
  2823. FROM
  2824. ( SELECT type, count( 1 ) num FROM trade_visitor WHERE deleted = 0
  2825. and order_id in
  2826. <foreach collection="orderIds" item="item" separator="," open="(" close=")">
  2827. #{item}
  2828. </foreach>
  2829. GROUP BY type ) a
  2830. </select>
  2831. <select id="selectCanBuyInsuranceOrder" resultType="java.lang.Long">
  2832. select id
  2833. from trade_order
  2834. where deleted = 0
  2835. and order_status in (1,6)
  2836. and (is_insure is null)
  2837. and travel_date BETWEEN now() and CONCAT(DATE_ADD(CURDATE(),INTERVAL 2 DAY), ' 23:59:59')
  2838. </select>
  2839. <select id="queryOrderLink" resultType="java.util.Map">
  2840. select distinct td.link_mobile from trade_order td
  2841. LEFT JOIN product_voyage pv ON td.voyage_id = pv.id
  2842. LEFT JOIN resource_route rr ON pv.route_id = rr.id
  2843. where DATE_FORMAT(td.travel_date, '%Y-%m-%d') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (-#{day}) DAY), '%Y-%m-%d')
  2844. and td.deleted='0' and td.link_mobile is not null and td.order_status in (0,1,2,3,6,7,8,9,12,13,14,15)
  2845. and rr.direction = #{direction} and td.voyage_id = #{voyageId}
  2846. </select>
  2847. <select id="queryOrderJzPhone" resultType="java.util.Map">
  2848. select distinct tzd.phone from trade_order td
  2849. left join trade_order_jz tz on tz.order_id = td.id
  2850. left join trade_order_jz_detail tzd on tzd.jz_id = tz.id and tzd.deleted='0'
  2851. LEFT JOIN product_voyage pv ON td.voyage_id = pv.id
  2852. LEFT JOIN resource_route rr ON pv.route_id = rr.id
  2853. where DATE_FORMAT(td.travel_date, '%Y-%m-%d') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (-#{day}) DAY), '%Y-%m-%d')
  2854. and td.deleted='0' and tzd.phone is not null and td.order_status in (0,1,2,3,6,7,8,9,12,13,14,15)
  2855. and rr.direction = #{direction} and td.voyage_id = #{voyageId}
  2856. </select>
  2857. <select id="queryOrderVisitorMobile" resultType="java.util.Map">
  2858. select distinct tv.mobile from trade_order td
  2859. left join trade_visitor tv on tv.order_id = td.id
  2860. LEFT JOIN product_voyage pv ON td.voyage_id = pv.id
  2861. LEFT JOIN resource_route rr ON pv.route_id = rr.id
  2862. where DATE_FORMAT(td.travel_date, '%Y-%m-%d') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (-#{day}) DAY), '%Y-%m-%d')
  2863. and td.deleted='0' and (tv.mobile is not null and tv.mobile !='') and tv.deleted='0'
  2864. and td.order_status in (0,1,2,3,6,7,8,9,12,13,14,15) and rr.direction = #{direction} and td.voyage_id = #{voyageId}
  2865. </select>
  2866. <select id="getTradeJz" resultType="java.util.Map">
  2867. select t1.use_date,t3.batch_no,t3.jz_id,t3.`name`,t3.phone,t2.id visitorId,t3.id_card,t3.remark,t4.jz_link_name,t4.jz_address,t4.jz_link_phone from trade_detail t1 inner join trade_visitor t2 on t1.id = t2.detail_id
  2868. inner join trade_order_jz_detail t3 on t2.id = t3.visitor_id
  2869. inner join trade_order_jz t4 on t3.jz_id = t4.id
  2870. where t1.deleted=0 and t2.deleted=0 and t3.deleted =0
  2871. and t3.extend_order_no is null and DATE_FORMAT(t1.travel_date, '%Y-%m-%d') = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL (1) DAY), '%Y-%m-%d')
  2872. </select>
  2873. <select id="getCanContractOrder" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  2874. SELECT * FROM trade_order WHERE is_contract is null and travel_date BETWEEN CONCAT(DATE_ADD(CURDATE(),INTERVAL 1 DAY),' 00:00:00') and CONCAT(DATE_ADD(CURDATE(),INTERVAL 2 DAY), ' 23:59:59')
  2875. </select>
  2876. </mapper>