TradeOrderMapper.xml 126 KB

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