TradeOrderMapper.xml 142 KB

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