TradeOrderMapper.xml 138 KB

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