TradeOrderMapper.xml 122 KB

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