TradeOrderMapper.xml 127 KB

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