TradeOrderMapper.xml 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183
  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="getTradeOrderUserPage"
  186. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  187. 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
  188. ,tr.refund_amount refundAmount,
  189. ps.product_tag productTag,ps.product_tag2 productTag2,ps.product_tag3 productTag3,ps.product_tag4 productTag4
  190. FROM trade_order td
  191. INNER JOIN trade_order_user tou on td.id = tou.order_id
  192. left JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  193. left JOIN product_spu ps on ps.id = tdl.product_id
  194. LEFT JOIN ota_distributor od on od.id = td.source_id
  195. LEFT JOIN trade_order_audit toa on toa.order_id = td.id and toa.audit_status = 1
  196. 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
  197. LEFT JOIN trade_order_room_model torm on torm.order_id = td.id
  198. where td.deleted = 0 and tou.deleted = 0
  199. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  200. and td.order_status in
  201. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  202. #{item}
  203. </foreach>
  204. </if>
  205. <if test="vo.tenantId!=null">
  206. AND td.tenant_id = #{vo.tenantId}
  207. </if>
  208. <choose>
  209. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  210. AND td.order_no like concat('%',#{vo.orderNo})
  211. </when>
  212. <when test="vo.orderNo != null and vo.orderNo != ''">
  213. AND td.order_no = #{vo.orderNo}
  214. </when>
  215. <otherwise>
  216. </otherwise>
  217. </choose>
  218. <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
  219. AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
  220. </if>
  221. <if test="vo.memberId != null and vo.memberId != ''">
  222. AND td.member_id = #{vo.memberId}
  223. </if>
  224. <if test="vo.voyageId != null and vo.voyageId != ''">
  225. AND td.voyage_id = #{vo.voyageId}
  226. </if>
  227. <if test="vo.shipId != null and vo.shipId != ''">
  228. AND td.ship_id = #{vo.shipId}
  229. </if>
  230. <if test="vo.routeId != null and vo.routeId != ''">
  231. AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
  232. </if>
  233. <if test="vo.dispatchStatus != null">
  234. AND td.dispatch_status = #{vo.dispatchStatus}
  235. </if>
  236. <if test="vo.payType != null">
  237. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  238. </if>
  239. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  240. AND od.ota_category_id = #{vo.otaCateId}
  241. </if>
  242. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  243. and od.ota_category_id in
  244. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  245. #{item}
  246. </foreach>
  247. </if>
  248. <if test="vo.otaId != null and vo.otaId != ''">
  249. AND td.source_id = #{vo.otaId}
  250. </if>
  251. <if test="vo.storeId != null and vo.storeId != ''">
  252. AND td.store_id = #{vo.storeId}
  253. </if>
  254. <if test="vo.productTag != null and vo.productTag != ''">
  255. AND ps.product_tag = #{vo.productTag}
  256. </if>
  257. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  258. AND ps.product_tag2 = #{vo.productTag2}
  259. </if>
  260. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  261. AND ps.product_tag3 = #{vo.productTag3}
  262. </if>
  263. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  264. AND ps.product_tag4 = #{vo.productTag4}
  265. </if>
  266. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  267. AND tdl.product_id in
  268. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  269. #{item}
  270. </foreach>
  271. </if>
  272. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  273. AND td.external_order_no = #{vo.externalOrderNo}
  274. </if>
  275. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  276. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  277. </if>
  278. <if test="vo.userName != null and vo.userName != ''">
  279. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  280. </if>
  281. <choose>
  282. <when test="vo.mobile != null and vo.mobile.length() == 4">
  283. AND tou.mobile like concat('%',#{vo.mobile})
  284. </when>
  285. <when test="vo.mobile != null and vo.mobile != ''">
  286. AND tou.mobile = #{vo.mobile}
  287. </when>
  288. <otherwise>
  289. </otherwise>
  290. </choose>
  291. <if test="vo.contactName != null and vo.contactName != ''">
  292. AND tou.contact_name = #{vo.contactName}
  293. </if>
  294. <if test="vo.travelDate != null and vo.travelDate != ''">
  295. AND td.travel_date = #{vo.travelDate}
  296. </if>
  297. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  298. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  299. </if>
  300. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  301. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  302. </if>
  303. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  304. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  305. </if>
  306. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  307. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  308. </if>
  309. <if test="vo.orderDate != null and vo.orderDate != ''">
  310. AND td.create_time = #{vo.orderDate}
  311. </if>
  312. <if test="vo.sellerId != null and vo.sellerId != ''">
  313. AND td.seller_id = #{vo.sellerId}
  314. </if>
  315. <if test="vo.shareName != null and vo.shareName != ''">
  316. AND td.share_name like concat('%',#{vo.shareName},'%')
  317. </if>
  318. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  319. AND tdl.voucher_code = #{vo.voucherCode}
  320. </if>
  321. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  322. AND td.sell_method = #{vo.sellMethod}
  323. </if>
  324. <if test="vo.productName != null and vo.productName != ''">
  325. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  326. </if>
  327. <if test="vo.isFullPay == 0">
  328. AND td.is_full_pay = #{vo.isFullPay}
  329. </if>
  330. <if test="vo.isComment != null">
  331. AND td.is_comment = #{vo.isComment}
  332. </if>
  333. <if test="vo.sourceId != null and vo.sourceId != ''">
  334. AND td.source_id = #{vo.sourceId}
  335. </if>
  336. <if test="vo.distributorId != null and vo.distributorId != ''">
  337. AND td.source_id = #{vo.distributorId}
  338. </if>
  339. <if test="vo.sourceName != null and vo.sourceName != ''">
  340. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  341. </if>
  342. <if test="vo.travelStatus != null">
  343. AND td.travel_status = #{vo.travelStatus}
  344. </if>
  345. <if test="vo.roomModelId != null and vo.roomModelId != ''">
  346. AND torm.room_model_id = #{vo.roomModelId}
  347. </if>
  348. <if test="vo.floor != null and vo.floor != ''">
  349. AND torm.floor = #{vo.floor}
  350. </if>
  351. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  352. 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} )
  353. </if>
  354. GROUP BY td.id
  355. ORDER BY td.create_time DESC
  356. </select>
  357. <select id="getTradeOrderUserCount" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderCountRespVO">
  358. SELECT count(DISTINCT td.id) orderNum,sum(if(tdl.voucher_status in (1,2,3,4,6,8,9), quantity_of_one,0)) totalNum,
  359. sum(if(tdl.spec_type='full' and tdl.voucher_status in (1,2,3,4,6,8,9), quantity_of_one,0)) fullNum,
  360. sum(if(tdl.spec_type='half' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) halfNum,
  361. sum(if(tdl.spec_type='free' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) freeNum,
  362. sum(if(tdl.spec_type='common' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) commonNum,
  363. sum(if(tdl.spec_type='car_seat' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carSeatNum,
  364. sum(if(tdl.spec_type='car_yd' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carYdNum,
  365. sum(if(tdl.spec_type='other' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) otherNum,
  366. sum(if(tdl.spec_type='carrying_children' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carryingChildrenNum,
  367. sum(tdl.actual_price) totalPayAmount
  368. FROM trade_order td
  369. INNER JOIN trade_order_user tou on td.id = tou.order_id
  370. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  371. INNER JOIN product_spu ps on ps.id = tdl.product_id
  372. LEFT JOIN ota_distributor od on od.id = td.source_id
  373. where 1= 1
  374. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  375. and td.order_status in
  376. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  377. #{item}
  378. </foreach>
  379. </if>
  380. <if test="vo.tenantId!=null">
  381. AND td.tenant_id = #{vo.tenantId}
  382. </if>
  383. <choose>
  384. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  385. AND td.order_no like concat('%',#{vo.orderNo})
  386. </when>
  387. <when test="vo.orderNo != null and vo.orderNo != ''">
  388. AND td.order_no = #{vo.orderNo}
  389. </when>
  390. <otherwise>
  391. </otherwise>
  392. </choose>
  393. <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
  394. AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
  395. </if>
  396. <if test="vo.memberId != null and vo.memberId != ''">
  397. AND td.member_id = #{vo.memberId}
  398. </if>
  399. <if test="vo.productTag != null and vo.productTag != ''">
  400. AND ps.product_tag = #{vo.productTag}
  401. </if>
  402. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  403. AND ps.product_tag2 = #{vo.productTag2}
  404. </if>
  405. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  406. AND ps.product_tag3 = #{vo.productTag3}
  407. </if>
  408. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  409. AND ps.product_tag4 = #{vo.productTag4}
  410. </if>
  411. <if test="vo.dispatchStatus != null">
  412. AND td.dispatch_status = #{vo.dispatchStatus}
  413. </if>
  414. <if test="vo.payType != null">
  415. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  416. </if>
  417. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  418. AND od.ota_category_id = #{vo.otaCateId}
  419. </if>
  420. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  421. AND (td.route_plan_id in
  422. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  423. #{item}
  424. </foreach>
  425. or tdl.product_id in
  426. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  427. #{item}
  428. </foreach>
  429. )
  430. </if>
  431. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  432. AND tdl.product_id in
  433. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  434. #{item}
  435. </foreach>
  436. </if>
  437. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  438. and td.route_plan_id in
  439. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  440. #{item}
  441. </foreach>
  442. </if>
  443. <if test="vo.otaId != null and vo.otaId != ''">
  444. AND td.source_id = #{vo.otaId}
  445. </if>
  446. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  447. and od.ota_category_id in
  448. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  449. #{item}
  450. </foreach>
  451. </if>
  452. <if test="vo.storeId != null and vo.storeId != ''">
  453. AND td.store_id = #{vo.storeId}
  454. </if>
  455. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  456. AND td.external_order_no = #{vo.externalOrderNo}
  457. </if>
  458. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  459. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  460. </if>
  461. <if test="vo.userName != null and vo.userName != ''">
  462. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  463. </if>
  464. <choose>
  465. <when test="vo.mobile != null and vo.mobile.length() == 4">
  466. AND tou.mobile like concat('%',#{vo.mobile})
  467. </when>
  468. <when test="vo.mobile != null and vo.mobile != ''">
  469. AND tou.mobile = #{vo.mobile}
  470. </when>
  471. <otherwise>
  472. </otherwise>
  473. </choose>
  474. <if test="vo.contactName != null and vo.contactName != ''">
  475. AND tou.contact_name = #{vo.contactName}
  476. </if>
  477. <if test="vo.travelDate != null and vo.travelDate != ''">
  478. AND td.travel_date = #{vo.travelDate}
  479. </if>
  480. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  481. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  482. </if>
  483. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  484. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  485. </if>
  486. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  487. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  488. </if>
  489. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  490. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  491. </if>
  492. <if test="vo.orderDate != null and vo.orderDate != ''">
  493. AND td.create_time = #{vo.orderDate}
  494. </if>
  495. <if test="vo.sellerId != null and vo.sellerId != ''">
  496. AND td.seller_id = #{vo.sellerId}
  497. </if>
  498. <if test="vo.shareName != null and vo.shareName != ''">
  499. AND td.share_name like concat('%',#{vo.shareName},'%')
  500. </if>
  501. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  502. AND tdl.voucher_code = #{vo.voucherCode}
  503. </if>
  504. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  505. AND td.sell_method = #{vo.sellMethod}
  506. </if>
  507. <if test="vo.productName != null and vo.productName != ''">
  508. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  509. </if>
  510. <if test="vo.isFullPay == 0">
  511. AND td.is_full_pay = #{vo.isFullPay}
  512. </if>
  513. <if test="vo.isComment != null">
  514. AND td.is_comment = #{vo.isComment}
  515. </if>
  516. <if test="vo.sourceId != null and vo.sourceId != ''">
  517. AND td.source_id = #{vo.sourceId}
  518. </if>
  519. <if test="vo.sourceName != null and vo.sourceName != ''">
  520. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  521. </if>
  522. <if test="vo.travelStatus != null">
  523. AND td.travel_status = #{vo.travelStatus}
  524. </if>
  525. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  526. 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} )
  527. </if>
  528. </select>
  529. <select id="getPaidOrderPage"
  530. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  531. SELECT td.*, op.pay_amount payAmount, op.refund_amount refundAmount, op.pay_status paymentStatus, op.payment_type paymentType, op.payment_date paymentDate
  532. FROM trade_order td
  533. INNER JOIN trade_order_pay op on op.order_id = td.id
  534. where td.order_status <![CDATA[ >= ]]> 6 and td.order_status <![CDATA[ <= ]]> 11
  535. <if test="vo.orderNo != null and vo.orderNo != ''">
  536. AND td.order_no = #{vo.orderNo}
  537. </if>
  538. <if test="vo.payType != null">
  539. AND op.payment_type = #{vo.payType}
  540. </if>
  541. <if test="vo.storeId != null and vo.storeId != ''">
  542. AND td.store_id = #{vo.storeId}
  543. </if>
  544. <if test="vo.travelDate != null and vo.travelDate != ''">
  545. AND td.travel_date = #{vo.travelDate}
  546. </if>
  547. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  548. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  549. </if>
  550. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  551. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  552. </if>
  553. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  554. AND op.payment_date <![CDATA[ >= ]]> #{vo.orderDateStart}
  555. </if>
  556. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  557. AND op.payment_date <![CDATA[ <= ]]> #{vo.orderDateEnd}
  558. </if>
  559. <if test="vo.orderDate != null and vo.orderDate != ''">
  560. AND td.create_time = #{vo.orderDate}
  561. </if>
  562. <if test="vo.sellerId != null and vo.sellerId != ''">
  563. AND td.seller_id = #{vo.sellerId}
  564. </if>
  565. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  566. AND td.sell_method = #{vo.sellMethod}
  567. </if>
  568. ORDER BY td.create_time DESC
  569. </select>
  570. <select id="getRefundDetailPage"
  571. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  572. SELECT td.*,tv.credential_no,tv.`name`,tv.mobile,tor.order_no
  573. FROM trade_detail td
  574. INNER JOIN trade_visitor tv on tv.detail_id = td.id
  575. LEFT JOIN trade_order tor on tor.id = td.order_id
  576. where 1= 1
  577. <if test="vo.name != null and vo.name != ''">
  578. AND tv.name = #{vo.name}
  579. </if>
  580. <if test="vo.orderNo != null and vo.orderNo != ''">
  581. AND tor.order_no = #{vo.orderNo}
  582. </if>
  583. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  584. AND tv.credential_no = #{vo.credentialNo}
  585. </if>
  586. <if test="vo.mobile != null and vo.mobile != ''">
  587. AND tv.mobile = #{vo.mobile}
  588. </if>
  589. <if test="vo.orderStatus != null and vo.orderStatus != ''">
  590. AND tor.order_status = #{vo.orderStatus}
  591. </if>
  592. </select>
  593. <select id="getRefundRecordPage"
  594. resultType="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundRespVO">
  595. SELECT tr.*,td.order_no, ou.mobile,td.travel_date, ou.contact_name ,tdl.product_name
  596. FROM trade_refund tr
  597. INNER JOIN trade_order td on tr.order_id = td.id
  598. inner join product_voyage pv on td.voyage_id = pv.id
  599. inner join trade_order_user ou on ou.order_id = td.id
  600. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  601. LEFT JOIN ota_distributor od on od.id = td.source_id
  602. where 1= 1
  603. <if test="vo.shipId != null and vo.shipId != ''">
  604. AND td.ship_id = #{vo.shipId}
  605. </if>
  606. <if test="vo.voyageId != null and vo.voyageId != ''">
  607. AND td.voyage_id = #{vo.voyageId}
  608. </if>
  609. <if test="vo.routeId != null and vo.routeId != ''">
  610. AND pv.route_id = #{vo.routeId}
  611. </if>
  612. <if test="vo.orderNo != null and vo.orderNo != ''">
  613. AND td.order_no = #{vo.orderNo}
  614. </if>
  615. <if test="vo.refundStatus!=null and vo.refundStatus.size()>0">
  616. and tr.refund_status in
  617. <foreach collection="vo.refundStatus" item="item" separator="," open="(" close=")">
  618. #{item}
  619. </foreach>
  620. </if>
  621. <if test="vo.refundMethod != null and vo.refundMethod != ''">
  622. AND tr.refund_method = #{vo.refundMethod}
  623. </if>
  624. <if test="vo.refundUserId!=null and vo.refundUserId.size()>0">
  625. and tr.refund_user in
  626. <foreach collection="vo.refundUserId" item="item" separator="," open="(" close=")">
  627. #{item}
  628. </foreach>
  629. </if>
  630. <if test="vo.refundChannel != null">
  631. AND tr.refund_channel = #{vo.refundChannel}
  632. </if>
  633. <if test="vo.mobile != null and vo.mobile != ''">
  634. AND ou.mobile = #{vo.mobile}
  635. </if>
  636. <if test="vo.sourceId != null and vo.sourceId != ''">
  637. AND td.source_id = #{vo.sourceId}
  638. </if>
  639. <if test="vo.travelDate != null and vo.travelDate != ''">
  640. AND td.travel_date = #{vo.travelDate}
  641. </if>
  642. <if test="vo.productName != null and vo.productName != ''">
  643. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  644. </if>
  645. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  646. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  647. </if>
  648. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  649. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  650. </if>
  651. <if test="vo.refundTime != null and vo.refundTime != ''">
  652. AND tr.refund_time = #{vo.refundTime}
  653. </if>
  654. <if test="vo.refundTimeStart != null and vo.refundTimeStart != ''">
  655. AND tr.refund_time <![CDATA[ >= ]]> #{vo.refundTimeStart}
  656. </if>
  657. <if test="vo.refundTimeEnd != null and vo.refundTimeEnd != ''">
  658. AND tr.refund_time <![CDATA[ <= ]]> #{vo.refundTimeEnd}
  659. </if>
  660. <if test="vo.otaId != null and vo.otaId != ''">
  661. AND td.source_id = #{vo.otaId}
  662. </if>
  663. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  664. and od.ota_category_id in
  665. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  666. #{item}
  667. </foreach>
  668. </if>
  669. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  670. AND tdl.product_id in
  671. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  672. #{item}
  673. </foreach>
  674. </if>
  675. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  676. and td.route_plan_id in
  677. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  678. #{item}
  679. </foreach>
  680. </if>
  681. group by tr.id
  682. ORDER BY tr.create_time DESC
  683. </select>
  684. <select id="getOrderInfo" resultMap="MiddleWareDtoResultMap">
  685. 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,
  686. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,tou.county,tou.province,tou.city,td.agency_group_id,
  687. top.id payId,top.pay_amount payAmount,top.pay_status,top.payment_type,top.payment_date,top.payment_no,
  688. td.store_name,td.is_invoice, td.confirm_type, td.travel_status, tr.refund_amount,td.finish_status,
  689. 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,
  690. 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
  691. FROM trade_order td
  692. INNER JOIN trade_order_user tou on td.id = tou.order_id
  693. left JOIN trade_order_pay top on td.id = top.order_id AND top.pay_status = 1 and top.deleted = 0
  694. left JOIN trade_insurance ti on td.id = ti.order_id
  695. left JOIN trade_contract tc on td.id = tc.order_id
  696. LEFT JOIN (select m2.order_id,sum(m1.refund_amount) refund_amount from trade_refund_detail m1
  697. 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
  698. where 1= 1
  699. AND td.id = #{id}
  700. </select>
  701. <select id="getPdaOrderInfo" resultMap="MiddleWareDtoResultMap2">
  702. 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,
  703. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,tou.county,tou.province,tou.city,td.is_change_order,td.agency_group_id,
  704. top.id payId,top.pay_amount payAmount,top.pay_status,top.payment_type,top.payment_date,top.payment_no,
  705. td.store_name,td.dispatch_status,td.is_invoice, td.confirm_type, td.travel_status, tr.refund_amount,td.finish_status,
  706. 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,
  707. 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
  708. FROM trade_order td
  709. INNER JOIN trade_order_user tou on td.id = tou.order_id
  710. left JOIN trade_order_pay top on td.id = top.order_id AND top.pay_status = 1 and top.deleted = 0
  711. left JOIN trade_insurance ti on td.id = ti.order_id
  712. left JOIN trade_contract tc on td.id = tc.order_id
  713. left JOIN product_route_plan rt on rt.id = td.route_plan_id
  714. LEFT JOIN (select m2.order_id,sum(m1.refund_amount) refund_amount from trade_refund_detail m1
  715. 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
  716. where 1= 1
  717. AND td.id = #{id}
  718. </select>
  719. <select id="getMarketingApplyOrderPage" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  720. 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,
  721. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  722. 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
  723. FROM
  724. product_marketing_audit pma
  725. INNER JOIN trade_order td on pma.order_id = td.id
  726. inner join trade_detail ttd on td.id = ttd.order_id
  727. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  728. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  729. WHERE 1 = 1 AND td.order_status != 11 and
  730. pma.travel_id in (SELECT DISTINCT travel_id FROM product_marketing_pm WHERE user_id = #{vo.userId} and deleted = 0)
  731. <if test="vo.ids.size()>0">
  732. and pma.travel_id in
  733. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  734. #{item}
  735. </foreach>
  736. </if>
  737. <if test="vo.orderNo != null and vo.orderNo != ''">
  738. AND td.order_no = #{vo.orderNo}
  739. </if>
  740. <if test="vo.policyType != null and vo.policyType != ''">
  741. AND pmk.policy_type = #{vo.policyType}
  742. </if>
  743. <if test="vo.productName != null and vo.productName != ''">
  744. AND ttd.product_name like concat('%',#{vo.productName}, '%')
  745. </if>
  746. <if test="vo.marketingName != null and vo.marketingName != ''">
  747. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  748. </if>
  749. <if test="vo.isExecute != null and vo.isExecute != ''">
  750. AND pma.is_execute = #{vo.isExecute}
  751. </if>
  752. <if test="vo.distributorId != null and vo.distributorId != ''">
  753. AND pma.agency_id = #{vo.distributorId}
  754. </if>
  755. <if test="vo.storeId != null and vo.storeId != ''">
  756. AND pma.store_id = #{vo.storeId}
  757. </if>
  758. <if test="vo.orderStartTime != null and vo.orderStartTime != ''">
  759. AND td.travel_date <![CDATA[ >= ]]> #{vo.orderStartTime}
  760. </if>
  761. <if test="vo.orderEndTime != null and vo.orderEndTime != ''">
  762. AND td.travel_date <![CDATA[ <= ]]> #{vo.orderEndTime}
  763. </if>
  764. <if test="vo.auditState != null ">
  765. AND pma.audit_state = #{vo.auditState}
  766. </if>
  767. GROUP BY pma.id,td.id
  768. order by pma.create_time desc
  769. </select>
  770. <select id="getStoresMarketingOrderPage" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeMarketOrderRespVO">
  771. 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,
  772. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  773. 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
  774. FROM
  775. product_marketing_audit pma
  776. INNER JOIN trade_order td on pma.order_id = td.id
  777. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  778. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  779. LEFT JOIN product_marketing_pool_spu pms on td.id = pms.order_id
  780. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  781. WHERE 1 = 1
  782. <if test="vo.storeId != null">
  783. and pma.store_id = #{vo.storeId}
  784. </if>
  785. <if test="vo.distributorId != null">
  786. and td.source_id = #{vo.distributorId}
  787. </if>
  788. <if test="vo.ids.size()>0">
  789. and pma.travel_id in
  790. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  791. #{item}
  792. </foreach>
  793. </if>
  794. <if test="vo.isExecute != null">
  795. and pma.is_execute = #{vo.isExecute}
  796. </if>
  797. <if test="vo.policyType != null and vo.policyType != ''">
  798. AND pmk.policy_type = #{vo.policyType}
  799. </if>
  800. <if test="vo.marketingName != null and vo.marketingName != ''">
  801. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  802. </if>
  803. <if test="vo.auditState != null">
  804. and pma.audit_state = #{vo.auditState}
  805. </if>
  806. <if test="vo.useAuditState != null">
  807. and pma.use_audit_state = #{vo.useAuditState}
  808. </if>
  809. <if test="vo.orderNo != null and vo.orderNo != ''">
  810. AND td.order_no = #{vo.orderNo}
  811. </if>
  812. <if test="vo.travelDate != null and vo.travelDate != ''">
  813. AND td.travel_date = #{vo.travelDate}
  814. </if>
  815. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  816. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  817. </if>
  818. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  819. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  820. </if>
  821. <if test="vo.productName != null and vo.productName != ''">
  822. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  823. </if>
  824. GROUP BY pma.id
  825. order by pma.create_time desc
  826. </select>
  827. <select id="getStoresMarketingOrderDesc" resultType="java.util.Map">
  828. 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,
  829. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  830. 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
  831. FROM
  832. product_marketing_audit pma
  833. INNER JOIN trade_order td on pma.order_id = td.id
  834. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  835. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  836. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  837. WHERE 1 = 1
  838. <if test="vo.storeId != null">
  839. and pma.store_id = #{vo.storeId}
  840. </if>
  841. <if test="vo.ids.size()>0">
  842. and pma.travel_id in
  843. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  844. #{item}
  845. </foreach>
  846. </if>
  847. <if test="vo.isExecute != null">
  848. and pma.is_execute = #{vo.isExecute}
  849. </if>
  850. <if test="vo.policyType != null and vo.policyType != ''">
  851. AND pmk.policy_type = #{vo.policyType}
  852. </if>
  853. <if test="vo.marketingName != null and vo.marketingName != ''">
  854. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  855. </if>
  856. <if test="vo.auditState != null">
  857. and pma.audit_state = #{vo.auditState}
  858. </if>
  859. <if test="vo.useAuditState != null">
  860. and pma.use_audit_state = #{vo.useAuditState}
  861. </if>
  862. <if test="vo.orderNo != null and vo.orderNo != ''">
  863. AND td.order_no = #{vo.orderNo}
  864. </if>
  865. <if test="vo.travelDate != null and vo.travelDate != ''">
  866. AND td.travel_date = #{vo.travelDate}
  867. </if>
  868. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  869. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  870. </if>
  871. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  872. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  873. </if>
  874. <if test="vo.productName != null and vo.productName != ''">
  875. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  876. </if>
  877. GROUP BY pma.id
  878. order by pma.create_time desc
  879. </select>
  880. <select id="selectBindMarketing" resultType="java.lang.Long">
  881. SELECT tob.bind_id
  882. FROM
  883. trade_order_bind tob
  884. WHERE
  885. tob.type = 7 AND tob.deleted = 0 AND tob.order_id = #{orderId}
  886. </select>
  887. <select id="selectBindUseMarketing" resultType="java.lang.Long">
  888. SELECT tob.bind_id
  889. FROM
  890. trade_order_bind tob
  891. WHERE
  892. tob.type = 8 AND tob.deleted = 0 AND tob.order_id = #{orderId}
  893. </select>
  894. <select id="selectOrderIdByOrderNo" resultType="java.lang.Long">
  895. SELECT id FROM trade_order WHERE order_no = #{orderNo}
  896. </select>
  897. <select id="getRefundOrderInfo" resultMap="RefundResultMap">
  898. 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,
  899. tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
  900. tdl.id detailId,tdl.voucher_code,tdl.voucher_status,tdl.product_name,tdl.spec_type,
  901. tv.id visitorId,tv.credential_no,tv.credential_type,tv.`name`
  902. FROM trade_order td
  903. INNER JOIN trade_order_user tou on td.id = tou.order_id
  904. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  905. INNER JOIN trade_visitor tv on tdl.id = tv.detail_id
  906. where 1= 1
  907. <if test="id != null and id != ''">
  908. AND td.id = #{id}
  909. </if>
  910. </select>
  911. <select id="getTradeOrderByExpire" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  912. select * from trade_order where order_status =14 and travel_date <![CDATA[ <= ]]> #{expiretime}
  913. </select>
  914. <select id="getPageRefundRecord"
  915. resultType="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundRecordRespVO">
  916. SELECT trr.*,td.order_no, td.id orderId, td.travel_date
  917. FROM trade_refund_record trr
  918. left join trade_order_pay top on trr.order_pay_id = top.id
  919. left join trade_refund tr on trr.refund_id = tr.id
  920. left join trade_order td on td.id = top.order_id
  921. left join product_voyage pv on td.voyage_id = pv.id
  922. LEFT JOIN ota_distributor od on od.id = td.source_id
  923. where 1= 1
  924. <if test="vo.shipId != null and vo.shipId != ''">
  925. AND td.ship_id = #{vo.shipId}
  926. </if>
  927. <if test="vo.voyageId != null and vo.voyageId != ''">
  928. AND td.voyage_id = #{vo.voyageId}
  929. </if>
  930. <if test="vo.routeId != null and vo.routeId != ''">
  931. AND pv.route_id = #{vo.routeId}
  932. </if>
  933. <if test="vo.orderNo != null and vo.orderNo != ''">
  934. AND td.order_no = #{vo.orderNo}
  935. </if>
  936. <if test="vo.refundNo != null and vo.refundNo != ''">
  937. AND trr.refund_no = #{vo.refundNo}
  938. </if>
  939. <if test="vo.paymentNo != null and vo.paymentNo != ''">
  940. AND trr.payment_no = #{vo.paymentNo}
  941. </if>
  942. <if test="vo.refundStatus != null and vo.refundStatus != ''">
  943. AND trr.refund_status = #{vo.refundStatus}
  944. </if>
  945. <if test="vo.refundId != null and vo.refundId != ''">
  946. AND trr.refund_id = #{vo.refundId}
  947. </if>
  948. <if test="vo.openId != null and vo.openId != ''">
  949. AND trr.openId = #{vo.openId}
  950. </if>
  951. <if test="vo.otaId != null and vo.otaId != ''">
  952. AND td.source_id = #{vo.otaId}
  953. </if>
  954. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  955. and od.ota_category_id in
  956. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  957. #{item}
  958. </foreach>
  959. </if>
  960. <if test="vo.sourceId != null and vo.sourceId != ''">
  961. AND td.source_id = #{vo.sourceId}
  962. </if>
  963. <if test="vo.travelDate != null and vo.travelDate != ''">
  964. AND td.travel_date = #{vo.travelDate}
  965. </if>
  966. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  967. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  968. </if>
  969. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  970. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  971. </if>
  972. <if test="vo.refundTime != null and vo.refundTime != ''">
  973. AND trr.refund_time = #{vo.refundTime}
  974. </if>
  975. <if test="vo.refundTimeStart != null and vo.refundTimeStart != ''">
  976. AND trr.refund_time <![CDATA[ >= ]]> #{vo.refundTimeStart}
  977. </if>
  978. <if test="vo.refundTimeEnd != null and vo.refundTimeEnd != ''">
  979. AND trr.refund_time <![CDATA[ <= ]]> #{vo.refundTimeEnd}
  980. </if>
  981. ORDER BY trr.create_time DESC
  982. </select>
  983. <select id="getPrintTemp"
  984. resultType="com.yc.ship.module.trade.controller.admin.order.vo.otc.PrintRespVO">
  985. SELECT pt.* FROM print_temp pt where pt.template_code = #{printTemp}
  986. </select>
  987. <select id="queryCanInvoicedOrderPage"
  988. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  989. SELECT
  990. o.order_no,
  991. o.travel_date,
  992. o.order_status,
  993. o.amount,
  994. o.create_time,
  995. o.external_order_no,
  996. o.id,
  997. o.is_invoice,
  998. o.item_id,
  999. o.payment_date,
  1000. o.remark,
  1001. o.seller_id,
  1002. o.sell_method,
  1003. o.share_name,
  1004. o.source_id,
  1005. o.source_name,
  1006. o.store_id,
  1007. o.store_name,
  1008. o.visitor_type,
  1009. tou.contact_name,
  1010. tou.credential_no,
  1011. tou.mobile,
  1012. td.product_name,
  1013. count(
  1014. DISTINCT
  1015. CASE
  1016. WHEN (
  1017. td.voucher_status in (3,6,7,8)
  1018. OR ( td.voucher_status = 9 AND td.check_status = 1 )
  1019. ) THEN
  1020. td.id ELSE null
  1021. END
  1022. ) AS num,
  1023. o.pay_amount - SUM( ifnull(trd.refund_amount,0) ) - SUM(
  1024. CASE
  1025. WHEN ( td.voucher_status in (1,2) )
  1026. AND DATE_FORMAT( td.validity_end_date, '%Y-%c-%d' ) >= DATE_FORMAT( NOW( ), '%Y-%c-%d' ) THEN
  1027. td.actual_price ELSE 0
  1028. END
  1029. ) AS pay_amount
  1030. FROM
  1031. trade_order o
  1032. INNER JOIN trade_detail td ON td.order_id = o.id
  1033. LEFT JOIN trade_refund_detail trd ON trd.trade_detail_id = td.id
  1034. AND trd.refund_status = 6
  1035. INNER JOIN trade_order_user tou ON o.id = tou.order_id
  1036. LEFT JOIN trade_invoice_detail i ON i.order_no = o.order_no
  1037. LEFT JOIN trade_invoice ii ON i.invoice_id = ii.id AND ii.invoice_status IN (1,3)
  1038. 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
  1039. LEFT JOIN ota_bill_order obo ON obo.order_id = o.id
  1040. LEFT JOIN ota_bill_store obs ON obs.id = obo.bill_store_id AND obs.bill_status=1
  1041. where td.use_date >= DATE_SUB(NOW(), INTERVAL #{canInvoicedDay} DAY)
  1042. and o.is_invoice in (0,2)
  1043. and o.order_status in (6,7,8,9,11,12)
  1044. <if test="vo.orderNo != null and vo.orderNo != ''">
  1045. AND o.order_no = #{vo.orderNo}
  1046. </if>
  1047. <if test="vo.sourceId != null and vo.sourceId != ''">
  1048. AND o.source_id = #{vo.sourceId}
  1049. </if>
  1050. <if test="vo.storeId != null and vo.storeId != ''">
  1051. AND o.store_id = #{vo.storeId}
  1052. </if>
  1053. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1054. AND tou.credential_no = #{vo.credentialNo}
  1055. </if>
  1056. <if test="vo.mobile != null and vo.mobile != ''">
  1057. AND tou.mobile = #{vo.mobile}
  1058. </if>
  1059. <if test="vo.contactName != null and vo.contactName != ''">
  1060. AND tou.contact_name = #{vo.contactName}
  1061. </if>
  1062. <if test="vo.travelDate != null and vo.travelDate != ''">
  1063. AND o.travel_date = #{vo.travelDate}
  1064. </if>
  1065. <if test="vo.sellerId != null and vo.sellerId != ''">
  1066. AND o.seller_id = #{vo.sellerId}
  1067. </if>
  1068. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1069. AND td.voucher_code = #{vo.voucherCode}
  1070. </if>
  1071. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  1072. AND o.sell_method = #{vo.sellMethod}
  1073. </if>
  1074. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1075. AND td.use_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1076. </if>
  1077. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1078. AND td.use_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1079. </if>
  1080. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  1081. AND o.payment_date <![CDATA[ >= ]]> #{vo.orderDateStart}
  1082. </if>
  1083. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  1084. AND o.payment_date <![CDATA[ <= ]]> #{vo.orderDateEnd}
  1085. </if>
  1086. <if test="vo.productName != null and vo.productName != ''">
  1087. AND td.product_name like concat('%',#{vo.productName}, '%')
  1088. </if>
  1089. AND ii.id IS NULL
  1090. AND (op.payment_type != 6 OR (o.is_bill=2 AND obs.id IS NOT NULL))
  1091. AND date_format(NOW(), '%Y-%m-%d') > date_format(o.travel_date, '%Y-%m-%d')
  1092. GROUP BY
  1093. o.order_no
  1094. HAVING
  1095. SUM(CASE WHEN td.voucher_status IN (1,2) AND td.validity_end_date >= CURDATE() THEN 1 ELSE 0 END) = 0
  1096. AND pay_amount > 0
  1097. ORDER BY
  1098. o.travel_date DESC
  1099. </select>
  1100. <select id="getOrderByVoucherCode"
  1101. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1102. SELECT o.* FROM trade_order o
  1103. inner join trade_detail d on d.order_id = o.id
  1104. where (o.order_status = 6 or o.order_status = 7) and d.voucher_code = #{voucherCode} limit 1
  1105. </select>
  1106. <select id="getOrderByExternalOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1107. 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
  1108. </select>
  1109. <select id="getOtcOrderByExternalOrderNo" resultType="java.util.Map">
  1110. 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
  1111. </select>
  1112. <select id="getTradeOrderByVoucherCode" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1113. SELECT o.* FROM trade_order o inner join trade_detail d on d.order_id = o.id where d.voucher_code = #{voucherCode} limit 1
  1114. </select>
  1115. <select id="getOrderByCardNo"
  1116. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1117. SELECT
  1118. o.*
  1119. FROM
  1120. trade_order o
  1121. INNER JOIN trade_detail d ON d.order_id = o.id
  1122. INNER JOIN trade_visitor v ON v.detail_id = d.id
  1123. WHERE
  1124. o.travel_date >= CURDATE()
  1125. and d.voucher_status in (1,2,3,4,8,9)
  1126. and v.credential_no = #{cardNo}
  1127. </select>
  1128. <select id="getOrderByDetailBase"
  1129. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1130. SELECT o.* FROM trade_order o
  1131. inner join trade_detail d on d.order_id = o.id
  1132. inner join trade_detail_base tdb on tdb.detail_id = d.id
  1133. where (o.order_status = 6 or o.order_status = 7) and tdb.id = #{baseId} limit 1
  1134. </select>
  1135. <select id="getAccountOrderPage"
  1136. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1137. SELECT td.*,tou.contact_name,tou.credential_no,tou.mobile,COUNT(tdl.id) num,tdl.product_name,tdl.spec_type
  1138. FROM trade_order td
  1139. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1140. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  1141. where 1= 1 AND td.order_status NOT IN (-2, -1, 0, 1, 2, 12) AND td.is_account = 0
  1142. <if test="vo.orderNo != null and vo.orderNo != ''">
  1143. AND td.order_no = #{vo.orderNo}
  1144. </if>
  1145. <if test="vo.contactName != null and vo.contactName != ''">
  1146. AND tou.contact_name = #{vo.contactName}
  1147. </if>
  1148. <if test="vo.travelDate != null and vo.travelDate != ''">
  1149. AND td.travel_date = #{vo.travelDate}
  1150. </if>
  1151. GROUP BY td.id
  1152. ORDER BY td.create_time DESC
  1153. </select>
  1154. <update id="updateOrderStatus">
  1155. UPDATE trade_order SET order_status = #{orderStatus} WHERE id = #{orderId} and order_status != #{orderStatus}
  1156. </update>
  1157. <update id="updateOrderIsAccount">
  1158. UPDATE trade_order SET is_account = #{isAccount} WHERE id = #{orderId}
  1159. </update>
  1160. <update id="updateOrderDeleted">
  1161. UPDATE trade_order SET deleted = #{deleted},update_time = now() WHERE id = #{orderId}
  1162. </update>
  1163. <resultMap id="OrderAndDetailResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderPdaRespVO">
  1164. <id property="id" column="id"/>
  1165. <result property="orderNo" column="order_no"/>
  1166. <result property="sourceName" column="source_name"/>
  1167. <result property="externalOrderNo" column="external_order_no"/>
  1168. <result property="routePlanId" column="route_plan_id"/>
  1169. <result property="visitorType" column="visitor_type"/>
  1170. <result property="travelDate" column="travel_date"/>
  1171. <result property="sellMethod" column="sell_method"/>
  1172. <result property="sourceName" column="source_name"/>
  1173. <result property="sellerId" column="seller_id"/>
  1174. <result property="memberId" column="member_id"/>
  1175. <result property="amount" column="amount"/>
  1176. <result property="payAmount" column="pay_amount"/>
  1177. <result property="orderStatus" column="order_status"/>
  1178. <result property="paymentDate" column="payment_date"/>
  1179. <result property="contactName" column="contact_name"/>
  1180. <result property="credentialNo" column="credential_no"/>
  1181. <result property="mobile" column="mobile"/>
  1182. <result property="remark" column="remark"/>
  1183. <collection property="tradeDetailList" resultMap="tradeDetailMap"/>
  1184. </resultMap>
  1185. <resultMap id="tradeDetailMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  1186. <result property="id" column="detailId"/>
  1187. <result property="orderId" column="order_id"/>
  1188. <result property="voucherCode" column="voucher_code"/>
  1189. <result property="voucherStatus" column="voucher_status"/>
  1190. <result property="useDate" column="use_date"/>
  1191. <result property="validityStartDate" column="validity_start_date"/>
  1192. <result property="validityEndDate" column="validity_end_date"/>
  1193. <result property="usageDays" column="usage_days"/>
  1194. <result property="checkStatus" column="check_status"/>
  1195. <result property="takeStatus" column="take_status"/>
  1196. <result property="refundStatus" column="refund_status"/>
  1197. <result property="verifyTime" column="verify_time"/>
  1198. <result property="activateStatus" column="activate_status"/>
  1199. <result property="activateDays" column="activate_days"/>
  1200. <result property="activateTime" column="activate_time"/>
  1201. <result property="productId" column="product_id"/>
  1202. <result property="productName" column="product_name"/>
  1203. <result property="specType" column="spec_type"/>
  1204. <collection property="detailBaseList" resultMap="tradeDetailBaseResMap"/>
  1205. </resultMap>
  1206. <resultMap id="tradeDetailBaseResMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.DetailBaseRespVO">
  1207. <result property="id" column="detail_base_id"/>
  1208. <result property="detailId" column="detailId"/>
  1209. <result property="productBaseId" column="product_base_id"/>
  1210. <result property="productBaseName" column="product_base_name"/>
  1211. <result property="productBaseType" column="product_base_type"/>
  1212. <result property="productResourceId" column="product_resource_id"/>
  1213. <result property="productResourceName" column="product_resource_name"/>
  1214. <result property="supplierProductId" column="supplier_product_id"/>
  1215. <result property="supplierId" column="supplier_id"/>
  1216. <result property="supplierName" column="supplier_name"/>
  1217. <result property="isSystemDirect" column="is_system_direct"/>
  1218. <result property="useStatus" column="use_status"/>
  1219. <result property="checkStatus" column="base_check_status"/>
  1220. <result property="verifyTime" column="base_verify_time"/>
  1221. <result property="price" column="base_price"/>
  1222. <result property="usageCount" column="usage_count"/>
  1223. <result property="productResourcePrice" column="product_resource_price"/>
  1224. <result property="projectId" column="project_id"/>
  1225. <result property="projectName" column="project_name"/>
  1226. <result property="specificationId" column="specification_id"/>
  1227. <result property="specificationName" column="specification_name"/>
  1228. <result property="specType" column="base_spec_type"/>
  1229. <result property="supplierVoucherCode" column="supplier_voucher_code"/>
  1230. <result property="platSupplierOrderId" column="plat_supplier_order_id"/>
  1231. </resultMap>
  1232. <select id="getOrderAndDetailInfo" resultMap="OrderAndDetailResultMap">
  1233. 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,
  1234. tou.contact_name,tou.credential_no,tou.mobile,
  1235. tdl.id detailId,tdl.voucher_code,tdl.voucher_status,tdl.product_name,tdl.spec_type,tdl.validity_start_date,tdl.validity_end_date,
  1236. 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,
  1237. 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,
  1238. tdb.specification_id,tdb.specification_name,tdb.spec_type base_spec_type,tdb.supplier_voucher_code,tdb.plat_supplier_order_id
  1239. FROM trade_order td
  1240. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1241. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1242. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1243. inner join trade_detail_base tdb on tdl.id = tdb.detail_id
  1244. where 1= 1 and td.order_status >= 6 and td.order_status <![CDATA[ <= ]]> 9
  1245. and td.sell_method != 3 and td.sell_method != 4
  1246. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1247. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1248. <if test="channelId != null and channelId != ''">
  1249. and tdb.product_base_id in (select product_id from product_check_channel where channel_id=#{channelId} and deleted = 0)
  1250. </if>
  1251. <if test="orderNo != null and orderNo != ''">
  1252. AND td.order_no = #{orderNo}
  1253. </if>
  1254. <choose>
  1255. <when test="phone != null and phone.length() == 4">
  1256. AND tou.mobile like concat('%',#{phone})
  1257. </when>
  1258. <when test="phone != null and phone != ''">
  1259. AND tou.mobile = #{phone}
  1260. </when>
  1261. <otherwise>
  1262. </otherwise>
  1263. </choose>
  1264. <choose>
  1265. <when test="cardNo != null and cardNo.length() == 4">
  1266. AND tv.credential_no like concat('%',#{cardNo})
  1267. </when>
  1268. <when test="cardNo != null and cardNo != ''">
  1269. AND tv.credential_no = #{cardNo}
  1270. </when>
  1271. <otherwise>
  1272. </otherwise>
  1273. </choose>
  1274. ORDER BY td.travel_date DESC
  1275. </select>
  1276. <select id="getPlatOrderNo" resultType="java.lang.String">
  1277. select t3.order_no from trade_order t1
  1278. inner join trade_supplier_order t2 on t1.id = t2.order_id
  1279. inner join trade_order t3 on t2.trade_no = t3.external_order_no
  1280. where t1.order_no = #{orderNo}
  1281. </select>
  1282. <select id="getTotalPayByOrderNo" resultType="java.math.BigDecimal">
  1283. select sum(t2.pay_amount) from trade_order t1 inner join trade_order_pay t2 on t1.id = t2.order_id
  1284. where t1.order_no = #{orderNo} and t2.pay_status = 1
  1285. </select>
  1286. <select id="getCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1287. 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,
  1288. td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,
  1289. td.payment_date,td.remark, tou.contact_name,tou.credential_no,tou.mobile,td.is_add_order
  1290. FROM trade_order td
  1291. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1292. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1293. left join product_route_plan plan on td.route_plan_id = plan.id
  1294. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
  1295. left join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
  1296. </if>
  1297. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
  1298. left join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
  1299. </if>
  1300. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1301. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1302. </if>
  1303. where 1=1
  1304. <choose>
  1305. <when test="vo.orderStatus != null">
  1306. AND td.order_status = #{vo.orderStatus}
  1307. </when>
  1308. <otherwise>
  1309. and td.order_status in (6,7,8,9,10,13)
  1310. </otherwise>
  1311. </choose>
  1312. <choose>
  1313. <when test="vo.travelDate != null and vo.travelDate != ''">
  1314. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  1315. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  1316. </when>
  1317. <otherwise>
  1318. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1319. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1320. </otherwise>
  1321. </choose>
  1322. <choose>
  1323. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1324. AND td.order_no like concat('%',#{vo.orderNo})
  1325. </when>
  1326. <when test="vo.orderNo != null and vo.orderNo != ''">
  1327. AND td.order_no = #{vo.orderNo}
  1328. </when>
  1329. <otherwise>
  1330. </otherwise>
  1331. </choose>
  1332. <choose>
  1333. <when test="vo.phone != null and vo.phone.length() == 4">
  1334. AND tou.mobile like concat('%',#{vo.phone})
  1335. </when>
  1336. <when test="vo.phone != null and vo.phone != ''">
  1337. AND tou.mobile = #{vo.phone}
  1338. </when>
  1339. <otherwise>
  1340. </otherwise>
  1341. </choose>
  1342. <choose>
  1343. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  1344. AND tv.credential_no like concat('%',#{vo.credentialNo})
  1345. </when>
  1346. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  1347. AND tv.credential_no = #{vo.credentialNo}
  1348. </when>
  1349. <otherwise>
  1350. </otherwise>
  1351. </choose>
  1352. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  1353. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  1354. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  1355. </if>
  1356. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  1357. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  1358. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  1359. </if>
  1360. <if test="vo.travelStatus != null">
  1361. AND td.travel_status = #{vo.travelStatus}
  1362. </if>
  1363. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1364. AND tdl.voucher_code = #{vo.voucherCode}
  1365. </if>
  1366. <if test="vo.productName != null and vo.productName != ''">
  1367. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1368. </if>
  1369. <if test="vo.sellMethod != null">
  1370. AND td.sell_method = #{vo.sellMethod}
  1371. </if>
  1372. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  1373. AND (td.route_plan_id in
  1374. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1375. #{item}
  1376. </foreach>
  1377. or tdl.product_id in
  1378. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1379. #{item}
  1380. </foreach>
  1381. )
  1382. </if>
  1383. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  1384. AND tdl.product_id in
  1385. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1386. #{item}
  1387. </foreach>
  1388. </if>
  1389. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1390. and td.route_plan_id in
  1391. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1392. #{item}
  1393. </foreach>
  1394. </if>
  1395. group by td.id
  1396. ORDER BY td.create_time DESC
  1397. </select>
  1398. <select id="countCheckOrder" resultType="java.lang.Integer">
  1399. SELECT count(DISTINCT td.id) num FROM trade_order td
  1400. INNER JOIN trade_detail tdl ON td.id = tdl.order_id
  1401. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  1402. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1403. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1404. </if>
  1405. where 1=1
  1406. <choose>
  1407. <when test="vo.orderStatus != null">
  1408. AND td.order_status = #{vo.orderStatus}
  1409. </when>
  1410. <otherwise>
  1411. and td.order_status in (6,7,8,9,10,13)
  1412. </otherwise>
  1413. </choose>
  1414. <choose>
  1415. <when test="vo.travelDate != null and vo.travelDate != ''">
  1416. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  1417. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  1418. </when>
  1419. <otherwise>
  1420. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1421. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1422. </otherwise>
  1423. </choose>
  1424. <choose>
  1425. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1426. AND td.order_no like concat('%',#{vo.orderNo})
  1427. </when>
  1428. <when test="vo.orderNo != null and vo.orderNo != ''">
  1429. AND td.order_no = #{vo.orderNo}
  1430. </when>
  1431. <otherwise>
  1432. </otherwise>
  1433. </choose>
  1434. <choose>
  1435. <when test="vo.phone != null and vo.phone.length() == 4">
  1436. AND tou.mobile like concat('%',#{vo.phone})
  1437. </when>
  1438. <when test="vo.phone != null and vo.phone != ''">
  1439. AND tou.mobile = #{vo.phone}
  1440. </when>
  1441. <otherwise>
  1442. </otherwise>
  1443. </choose>
  1444. <choose>
  1445. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  1446. AND tv.credential_no like concat('%',#{vo.credentialNo})
  1447. </when>
  1448. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  1449. AND tv.credential_no = #{vo.credentialNo}
  1450. </when>
  1451. <otherwise>
  1452. </otherwise>
  1453. </choose>
  1454. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  1455. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  1456. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  1457. </if>
  1458. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  1459. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  1460. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  1461. </if>
  1462. <if test="vo.travelStatus != null">
  1463. AND td.travel_status = #{vo.travelStatus}
  1464. </if>
  1465. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1466. AND tdl.voucher_code = #{vo.voucherCode}
  1467. </if>
  1468. <if test="vo.productName != null and vo.productName != ''">
  1469. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1470. </if>
  1471. <if test="vo.sellMethod != null">
  1472. AND td.sell_method = #{vo.sellMethod}
  1473. </if>
  1474. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  1475. AND (td.route_plan_id in
  1476. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1477. #{item}
  1478. </foreach>
  1479. or tdl.product_id in
  1480. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1481. #{item}
  1482. </foreach>
  1483. )
  1484. </if>
  1485. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  1486. AND tdl.product_id in
  1487. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1488. #{item}
  1489. </foreach>
  1490. </if>
  1491. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1492. and td.route_plan_id in
  1493. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1494. #{item}
  1495. </foreach>
  1496. </if>
  1497. </select>
  1498. <select id="selectStoreMachineProductList"
  1499. resultType="java.lang.Long">
  1500. SELECT t1.product_id FROM otc_agency_store_machine_product t1
  1501. where 1=1
  1502. <if test="vo.storeId != null and vo.storeId != ''">
  1503. AND t1.store_id = #{vo.storeId}
  1504. </if>
  1505. <if test="vo.machineId != null and vo.machineId != ''">
  1506. AND t1.machine_id = #{vo.machineId}
  1507. </if>
  1508. </select>
  1509. <select id="orderListByOta" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1510. SELECT
  1511. t1.*
  1512. FROM
  1513. trade_order t1
  1514. inner join trade_detail t3 on t1.id = t3.order_id
  1515. inner join trade_visitor t4 on t3.id = t4.detail_id
  1516. INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
  1517. WHERE
  1518. t1.sell_method = 0
  1519. AND t1.order_status in (6,7,8,9,10,13)
  1520. AND t1.tenant_id = #{tenantId}
  1521. AND t1.travel_date = #{travelDate}
  1522. <if test="credentialNo != null and credentialNo != ''">
  1523. AND t4.credential_no = #{credentialNo}
  1524. </if>
  1525. <if test="mobile != null and mobile != ''">
  1526. AND t2.mobile = #{mobile}
  1527. </if>
  1528. ORDER BY
  1529. t1.payment_date DESC
  1530. </select>
  1531. <select id="orderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1532. SELECT
  1533. t1.*
  1534. FROM
  1535. trade_order t1
  1536. INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
  1537. INNER JOIN trade_detail td on t1.id = td.order_id
  1538. INNER JOIN trade_visitor v on v.detail_id = td.id
  1539. WHERE
  1540. 1 = 1
  1541. <if test="orderStatus!=null and orderStatus.size()>0">
  1542. AND t1.order_status in
  1543. <foreach collection="orderStatus" item="item" separator="," open="(" close=")">
  1544. #{item}
  1545. </foreach>
  1546. </if>
  1547. AND t1.tenant_id = #{tenantId}
  1548. AND t1.travel_date = #{travelDate}
  1549. <if test="credentialNo != null and credentialNo != ''">
  1550. AND v.credential_no = #{credentialNo}
  1551. </if>
  1552. <if test="mobile != null and mobile != ''">
  1553. AND t2.mobile = #{mobile}
  1554. </if>
  1555. group by t1.id
  1556. ORDER BY
  1557. t1.payment_date DESC
  1558. </select>
  1559. <select id="queryOneByOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1560. SELECT DISTINCT o2.*
  1561. FROM trade_order o
  1562. INNER JOIN trade_detail d on d.order_id = o.id
  1563. INNER JOIN trade_detail_base db ON db.detail_id = d.id
  1564. INNER JOIN trade_detail d2 ON db.supplier_voucher_code = d2.voucher_code
  1565. INNER JOIN trade_order o2 ON d2.order_id = o2.id
  1566. WHERE o.order_no = #{orderNo}
  1567. union all
  1568. SELECT o.* FROM trade_order o WHERE o.sell_method in (0,1,4,6,7) and o.order_no = #{orderNo}
  1569. </select>
  1570. <select id="updateAppletProductSellNum">
  1571. update applet_product t1 inner JOIN applet_product_group t2 ON t1.id = t2.applet_product_id
  1572. and t2.deleted =0
  1573. set t1.sell_num = t1.sell_num+#{sellNum} where t2.product_id = #{productId}
  1574. </select>
  1575. <select id="selectCanBindOrderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1576. SELECT o.id,o.is_bind
  1577. FROM trade_order o
  1578. INNER JOIN trade_detail d ON d.order_id = o.id
  1579. INNER JOIN trade_order_user u on o.id = u.order_id
  1580. WHERE
  1581. o.order_status > 5 AND o.deleted = 0
  1582. AND (o.is_bind IS NULL or o.is_bind = 0 ) and o.id != #{vo.orderId}
  1583. AND o.travel_date = #{vo.travelDate}
  1584. AND d.product_id = #{vo.productId}
  1585. <if test="vo.routePlanId !=null">
  1586. And o.route_plan_id = #{vo.routePlanId}
  1587. </if>
  1588. AND u.mobile = #{vo.mobile}
  1589. GROUP BY o.id
  1590. </select>
  1591. <update id="deleteOrderById">
  1592. delete from trade_order where id = #{orderId}
  1593. </update>
  1594. <update id="deleteOrderByOrderNo">
  1595. update from trade_order where order_no = #{orderNo}
  1596. </update>
  1597. <select id="getInvoiceOrderCount" resultType="java.lang.Integer">
  1598. select count(1) num from trade_invoice t1 inner join trade_invoice_detail t2 on t1.id = t2.invoice_id
  1599. and t1.invoice_status in (1,3)
  1600. where t2.order_no = #{orderNo} and t1.deleted = 0
  1601. </select>
  1602. <select id="selectPlatPayAmountByOriginOrderNo" resultType="java.util.Map">
  1603. select sum(tod.pay_amount) totalPayAmount
  1604. from trade_order tod
  1605. where tod.external_origin_order_no =#{originOrderNo} and tod.order_status>=6
  1606. </select>
  1607. <select id="selectChangeCountByOrderId" resultType="java.lang.Integer">
  1608. select count(*) totalCount
  1609. from trade_order tod
  1610. inner join trade_order_bind tb on tod.id = tb.order_id and tb.type = 2 and tb.deleted =0
  1611. inner join trade_order tod1 on tod1.id = tb.bind_id
  1612. where tod.id = #{orderId} and tod1.order_status>=6
  1613. </select>
  1614. <update id="updateOrderFinishStatus">
  1615. update trade_order tod,
  1616. (select tod.id
  1617. from trade_order tod
  1618. inner join trade_detail td on tod.id = td.order_id
  1619. where tod.sell_method in
  1620. <foreach collection="sellMethodList" item="item" separator="," open="(" close=")">
  1621. #{item}
  1622. </foreach>
  1623. and tod.order_status >=6
  1624. and td.validity_end_date = #{endDate}
  1625. and not EXISTS (
  1626. select 1
  1627. from trade_detail td1
  1628. where td1.validity_end_date > #{endDate} and td1.order_id = tod.id and td1.refund_status != 1
  1629. )
  1630. ) t
  1631. set tod.finish_status = 1
  1632. where tod.id = t.id
  1633. </update>
  1634. <select id="getSupplierCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1635. 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,
  1636. td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,
  1637. td.payment_date,td.remark, tou.contact_name,tou.credential_no,tou.mobile
  1638. FROM trade_order td
  1639. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1640. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1641. INNER JOIN trade_detail_base tdb on tdb.detail_id = tdl.id
  1642. left join product_route_plan plan on td.route_plan_id = plan.id
  1643. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
  1644. inner join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
  1645. </if>
  1646. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
  1647. inner join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
  1648. </if>
  1649. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1650. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1651. </if>
  1652. where supplier_id in (
  1653. select t2.id from product_supplier_user t1 inner join product_supplier t2 on t1.supplier_id = t2.id
  1654. where t1.user_id=#{vo.userId} and t1.deleted =0
  1655. )
  1656. <choose>
  1657. <when test="vo.orderStatus != null">
  1658. AND td.order_status = #{vo.orderStatus}
  1659. </when>
  1660. <otherwise>
  1661. and td.order_status in (6,7,8,9,10,13)
  1662. </otherwise>
  1663. </choose>
  1664. <choose>
  1665. <when test="vo.travelDate != null and vo.travelDate != ''">
  1666. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  1667. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  1668. </when>
  1669. <otherwise>
  1670. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1671. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1672. </otherwise>
  1673. </choose>
  1674. <choose>
  1675. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1676. AND td.order_no like concat('%',#{vo.orderNo})
  1677. </when>
  1678. <when test="vo.orderNo != null and vo.orderNo != ''">
  1679. AND td.order_no = #{vo.orderNo}
  1680. </when>
  1681. <otherwise>
  1682. </otherwise>
  1683. </choose>
  1684. <choose>
  1685. <when test="vo.phone != null and vo.phone.length() == 4">
  1686. AND tou.mobile like concat('%',#{vo.phone})
  1687. </when>
  1688. <when test="vo.phone != null and vo.phone != ''">
  1689. AND tou.mobile = #{vo.phone}
  1690. </when>
  1691. <otherwise>
  1692. </otherwise>
  1693. </choose>
  1694. <choose>
  1695. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  1696. AND tv.credential_no like concat('%',#{vo.credentialNo})
  1697. </when>
  1698. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  1699. AND tv.credential_no = #{vo.credentialNo}
  1700. </when>
  1701. <otherwise>
  1702. </otherwise>
  1703. </choose>
  1704. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  1705. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  1706. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  1707. </if>
  1708. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  1709. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  1710. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  1711. </if>
  1712. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1713. AND tdl.voucher_code = #{vo.voucherCode}
  1714. </if>
  1715. <if test="vo.checkType != null and vo.checkType == 1">
  1716. AND tdb.use_status in (1,2)
  1717. </if>
  1718. <if test="vo.checkType != null and vo.checkType == 2">
  1719. AND tdb.use_status in (3,6,8)
  1720. </if>
  1721. <if test="vo.productName != null and vo.productName != ''">
  1722. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1723. </if>
  1724. <if test="vo.sellMethod != null">
  1725. AND td.sell_method = #{vo.sellMethod}
  1726. </if>
  1727. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  1728. AND (td.route_plan_id in
  1729. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1730. #{item}
  1731. </foreach>
  1732. or tdl.product_id in
  1733. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1734. #{item}
  1735. </foreach>
  1736. )
  1737. </if>
  1738. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  1739. AND tdl.product_id in
  1740. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1741. #{item}
  1742. </foreach>
  1743. </if>
  1744. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1745. and td.route_plan_id in
  1746. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1747. #{item}
  1748. </foreach>
  1749. </if>
  1750. group by td.id
  1751. ORDER BY td.create_time DESC
  1752. </select>
  1753. <select id="getOtaTradeOrderPage"
  1754. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  1755. SELECT td.*,tor.order_no,pbr.check_start_date,pbr.check_end_date
  1756. FROM trade_detail td
  1757. LEFT JOIN product_basic_rule pbr on td.product_id = pbr.id
  1758. LEFT JOIN trade_order tor on tor.id = td.order_id
  1759. where 1= 1 AND
  1760. EXISTS (select * from product_sale_channel sc where sc.product_id = td.product_id and sc.channel_id = 0)
  1761. <if test="vo.productName != null and vo.productName != ''">
  1762. AND td.product_name = #{vo.productName}
  1763. </if>
  1764. <if test="vo.orderNo != null and vo.orderNo != ''">
  1765. AND tor.order_no = #{vo.orderNo}
  1766. </if>
  1767. <if test="vo.orderStatus != null and vo.orderStatus != ''">
  1768. AND tor.order_status = #{vo.orderStatus}
  1769. </if>
  1770. <if test="vo.paymentDateStart != null">
  1771. AND tor.payment_date <![CDATA[ >= ]]> #{vo.paymentDateStart}
  1772. </if>
  1773. <if test="vo.paymentDateEnd != null">
  1774. AND tor.payment_date <![CDATA[ <= ]]> #{vo.paymentDateEnd}
  1775. </if>
  1776. <if test="vo.type == 1">
  1777. AND tor.source_id = #{distributorId}
  1778. </if>
  1779. GROUP BY td.voucher_code
  1780. ORDER BY td.create_time DESC
  1781. </select>
  1782. <select id="regionStatic" resultType="java.util.Map">
  1783. 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
  1784. inner join trade_visitor t3 on t2.id = t3.detail_id
  1785. inner join ota_distributor t4 on t1.source_id = t4.id
  1786. inner join ota_distributor_region t5 on t4.id = t5.distributor_id
  1787. and (left(t3.credential_no,2) = t5.distributor_region_id or left(t3.credential_no,4) = t5.distributor_region_id)
  1788. inner join ota_region t6 on ((t5.distributor_region_id = province_code and LEVEL=1) or t5.distributor_region_id = left(t6.id,4) )
  1789. where t2.voucher_status in (1,2,3,4,6,8,9)
  1790. <if test="vo.startDate != null and vo.startDate!=''">
  1791. AND t2.use_date <![CDATA[ >= ]]> #{vo.startDate}
  1792. </if>
  1793. <if test="vo.endDate != null and vo.endDate!=''">
  1794. AND t2.use_date <![CDATA[ <= ]]> #{vo.endDate}
  1795. </if>
  1796. GROUP BY t4.id
  1797. order by num desc
  1798. </select>
  1799. <select id="queryOrderByLast" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1800. SELECT * FROM trade_order WHERE order_no = #{orderNo} and deleted = 1 ORDER BY update_time DESC limit 1
  1801. </select>
  1802. <select id="queryOrderById" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1803. SELECT * FROM trade_order WHERE id = #{orderId} ORDER BY update_time DESC limit 1
  1804. </select>
  1805. <select id="selectConfirmationCountry"
  1806. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderConfirmationCountryRespVO">
  1807. SELECT
  1808. t1.real_money actual_price,
  1809. t1.room_model_id,
  1810. t2.short_name room_model_short_name,
  1811. t2.NAME room_model_name,
  1812. t3.type,
  1813. ifnull( t3.nationality, 1 ) nationality,
  1814. t3.floor,
  1815. IFNULL( t4.`name`, '中国' ) nationality_name,
  1816. count( t3.id ) num
  1817. FROM
  1818. trade_order_room_model t1
  1819. LEFT JOIN resource_room_model t2 ON t1.room_model_id = t2.id
  1820. LEFT JOIN trade_visitor t3 ON t1.room_index_id = t3.room_index_id
  1821. LEFT JOIN area t4 ON t3.nationality = t4.id
  1822. WHERE
  1823. t1.order_id = #{orderId}
  1824. AND t1.deleted = 0
  1825. GROUP BY
  1826. t1.room_model_id,
  1827. t1.floor,
  1828. t3.type
  1829. ORDER BY
  1830. floor DESC
  1831. </select>
  1832. <select id="getOrderCount" resultType="java.util.Map">
  1833. select GROUP_CONCAT(num,'*',name) name,sum(num1) num1,sum(num2) num2,sum(num3) num3,sum(num4) num4 from (
  1834. SELECT sum(CASE WHEN tv.type='adultPlus' or tv.type='adultTake' THEN 1 ELSE 0 END) num1,
  1835. 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,
  1836. sum(CASE WHEN tv.type='with' THEN 1 ELSE 0 END) num3,
  1837. sum(CASE WHEN tv.type='leader' THEN 1 ELSE 0 END) num4,
  1838. CONCAT(rrm.short_name,'(',tv.floor,'F)') name ,count(1) num
  1839. FROM trade_order td
  1840. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1841. left JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1842. left join trade_visitor tv on tdl.id = tv.detail_id
  1843. left JOIN product_spu ps on ps.id = tdl.product_id
  1844. LEFT JOIN ota_distributor od on od.id = td.source_id
  1845. left join trade_order_room_model tm on tv.room_index_id = tm.room_index_id and tm.deleted =0
  1846. left join resource_room_model rrm on tm.room_model_id = rrm.id
  1847. 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
  1848. where td.deleted = 0 and tou.deleted = 0 and td.order_status >0 and tv.type is not null
  1849. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  1850. and td.order_status in
  1851. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  1852. #{item}
  1853. </foreach>
  1854. </if>
  1855. <if test="vo.tenantId!=null">
  1856. AND td.tenant_id = #{vo.tenantId}
  1857. </if>
  1858. <choose>
  1859. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1860. AND td.order_no like concat('%',#{vo.orderNo})
  1861. </when>
  1862. <when test="vo.orderNo != null and vo.orderNo != ''">
  1863. AND td.order_no = #{vo.orderNo}
  1864. </when>
  1865. <otherwise>
  1866. </otherwise>
  1867. </choose>
  1868. <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
  1869. AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
  1870. </if>
  1871. <if test="vo.memberId != null and vo.memberId != ''">
  1872. AND td.member_id = #{vo.memberId}
  1873. </if>
  1874. <if test="vo.voyageId != null and vo.voyageId != ''">
  1875. AND td.voyage_id = #{vo.voyageId}
  1876. </if>
  1877. <if test="vo.shipId != null and vo.shipId != ''">
  1878. AND td.ship_id = #{vo.shipId}
  1879. </if>
  1880. <if test="vo.routeId != null and vo.routeId != ''">
  1881. AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
  1882. </if>
  1883. <if test="vo.dispatchStatus != null">
  1884. AND td.dispatch_status = #{vo.dispatchStatus}
  1885. </if>
  1886. <if test="vo.payType != null">
  1887. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  1888. </if>
  1889. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  1890. AND od.ota_category_id = #{vo.otaCateId}
  1891. </if>
  1892. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  1893. and od.ota_category_id in
  1894. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  1895. #{item}
  1896. </foreach>
  1897. </if>
  1898. <if test="vo.otaId != null and vo.otaId != ''">
  1899. AND td.source_id = #{vo.otaId}
  1900. </if>
  1901. <if test="vo.storeId != null and vo.storeId != ''">
  1902. AND td.store_id = #{vo.storeId}
  1903. </if>
  1904. <if test="vo.productTag != null and vo.productTag != ''">
  1905. AND ps.product_tag = #{vo.productTag}
  1906. </if>
  1907. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  1908. AND ps.product_tag2 = #{vo.productTag2}
  1909. </if>
  1910. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  1911. AND ps.product_tag3 = #{vo.productTag3}
  1912. </if>
  1913. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  1914. AND ps.product_tag4 = #{vo.productTag4}
  1915. </if>
  1916. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  1917. AND tdl.product_id in
  1918. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1919. #{item}
  1920. </foreach>
  1921. </if>
  1922. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  1923. AND td.external_order_no = #{vo.externalOrderNo}
  1924. </if>
  1925. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1926. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  1927. </if>
  1928. <if test="vo.userName != null and vo.userName != ''">
  1929. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  1930. </if>
  1931. <choose>
  1932. <when test="vo.mobile != null and vo.mobile.length() == 4">
  1933. AND tou.mobile like concat('%',#{vo.mobile})
  1934. </when>
  1935. <when test="vo.mobile != null and vo.mobile != ''">
  1936. AND tou.mobile = #{vo.mobile}
  1937. </when>
  1938. <otherwise>
  1939. </otherwise>
  1940. </choose>
  1941. <if test="vo.contactName != null and vo.contactName != ''">
  1942. AND tou.contact_name = #{vo.contactName}
  1943. </if>
  1944. <if test="vo.travelDate != null and vo.travelDate != ''">
  1945. AND td.travel_date = #{vo.travelDate}
  1946. </if>
  1947. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1948. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1949. </if>
  1950. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1951. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1952. </if>
  1953. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  1954. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  1955. </if>
  1956. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  1957. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  1958. </if>
  1959. <if test="vo.orderDate != null and vo.orderDate != ''">
  1960. AND td.create_time = #{vo.orderDate}
  1961. </if>
  1962. <if test="vo.sellerId != null and vo.sellerId != ''">
  1963. AND td.seller_id = #{vo.sellerId}
  1964. </if>
  1965. <if test="vo.shareName != null and vo.shareName != ''">
  1966. AND td.share_name like concat('%',#{vo.shareName},'%')
  1967. </if>
  1968. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1969. AND tdl.voucher_code = #{vo.voucherCode}
  1970. </if>
  1971. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  1972. AND td.sell_method = #{vo.sellMethod}
  1973. </if>
  1974. <if test="vo.productName != null and vo.productName != ''">
  1975. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1976. </if>
  1977. <if test="vo.isFullPay == 0">
  1978. AND td.is_full_pay = #{vo.isFullPay}
  1979. </if>
  1980. <if test="vo.isComment != null">
  1981. AND td.is_comment = #{vo.isComment}
  1982. </if>
  1983. <if test="vo.sourceId != null and vo.sourceId != ''">
  1984. AND td.source_id = #{vo.sourceId}
  1985. </if>
  1986. <if test="vo.distributorId != null and vo.distributorId != ''">
  1987. AND td.source_id = #{vo.distributorId}
  1988. </if>
  1989. <if test="vo.sourceName != null and vo.sourceName != ''">
  1990. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  1991. </if>
  1992. <if test="vo.travelStatus != null">
  1993. AND td.travel_status = #{vo.travelStatus}
  1994. </if>
  1995. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  1996. 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} )
  1997. </if>
  1998. GROUP BY rrm.short_name,tv.floor
  1999. ) p
  2000. </select>
  2001. <select id="selectTotalByOrderIds" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.OrderTotalRespVO">
  2002. select sum(adult_total_num) adultTotalNum, sum(child_total_num) childTotalNum, sum(baby_total_num) babyTotalNum,
  2003. sum(with_total_num) withTotalNum, sum(leader_total_num) leaderTotalNum, sum(free_num) freeNum,
  2004. sum(order_money) orderMoney, sum(real_money) realMoney, sum(other_money) otherMoney,
  2005. sum(adjust_total_money) adjustTotalMoney, sum(with_amount) withTotalNumMoney,
  2006. sum(leader_amount) leaderTotalMoney, sum(free_amount) freeAmount, sum(service_money) serviceMoney,
  2007. sum(up_floor_total_num) upFloorTotalNum, sum(up_floor_total_money) upFloorTotalMoney,
  2008. sum(plus_total_num) plusTotalNum, sum(collection_service_money) collectionServiceMoney,
  2009. sum(use_room_total_num) totalRoomNum,sum(free_amount) freeAmount from trade_order_total
  2010. where 1=1
  2011. AND old_order_id in
  2012. <foreach collection="orderIds" item="item" separator="," open="(" close=")">
  2013. #{item}
  2014. </foreach>
  2015. </select>
  2016. <!-- 查询游客名单导出基础信息(船名、航期、航向) -->
  2017. <select id="selectTouristExportBase" resultType="java.util.Map">
  2018. SELECT
  2019. rs.name as shipName,
  2020. pv.start_time as travelDate,
  2021. rr.direction as direction
  2022. FROM trade_order tor
  2023. LEFT JOIN product_voyage pv ON tor.voyage_id = pv.id
  2024. LEFT JOIN resource_ship rs ON pv.ship_id = rs.id
  2025. LEFT JOIN resource_route rr ON pv.route_id = rr.id
  2026. LEFT JOIN ota_distributor od on od.id = tor.source_id
  2027. WHERE tor.deleted = 0
  2028. <if test="vo.orderNo != null and vo.orderNo != ''">
  2029. AND tor.order_no = #{vo.orderNo}
  2030. </if>
  2031. <if test="vo.voyageId != null and vo.voyageId != ''">
  2032. AND tor.voyage_id = #{vo.voyageId}
  2033. </if>
  2034. <if test="vo.shipId != null and vo.shipId != ''">
  2035. AND pv.ship_id = #{vo.shipId}
  2036. </if>
  2037. <if test="vo.routeId != null and vo.routeId != ''">
  2038. AND pv.route_id = #{vo.routeId}
  2039. </if>
  2040. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  2041. AND pv.start_time &gt;= #{vo.travelDateStart}
  2042. </if>
  2043. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  2044. AND pv.start_time &lt;= #{vo.travelDateEnd}
  2045. </if>
  2046. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  2047. AND tor.create_time &gt;= #{vo.orderDateStart}
  2048. </if>
  2049. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  2050. AND tor.create_time &lt;= #{vo.orderDateEnd}
  2051. </if>
  2052. <if test="vo.orderStatus != null and vo.orderStatus.size() > 0">
  2053. AND tor.order_status IN
  2054. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  2055. #{item}
  2056. </foreach>
  2057. </if>
  2058. <if test="vo.otaId != null and vo.otaId != ''">
  2059. AND tor.source_id = #{vo.otaId}
  2060. </if>
  2061. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  2062. AND od.ota_category_id = #{vo.otaCateId}
  2063. </if>
  2064. <if test="vo.otaCateIds != null and vo.otaCateIds.size() > 0">
  2065. AND od.ota_category_id IN
  2066. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  2067. #{item}
  2068. </foreach>
  2069. </if>
  2070. <if test="vo.contactName != null and vo.contactName != ''">
  2071. AND tor.contact_name LIKE CONCAT('%', #{vo.contactName}, '%')
  2072. </if>
  2073. <if test="vo.mobile != null and vo.mobile != ''">
  2074. AND tor.mobile = #{vo.mobile}
  2075. </if>
  2076. LIMIT 1
  2077. </select>
  2078. <select id="selectAppPage" resultType="com.yc.ship.module.trade.controller.app.otc.vo.AppTradeOrderRespNewVO">
  2079. 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
  2080. LEFT JOIN resource_ship t3 on t1.ship_id = t3.id
  2081. LEFT JOIN resource_route t4 on t2.route_id = t4.id
  2082. where t1.deleted = 0
  2083. and member_id = #{pageReqVO.memberId}
  2084. <if test="pageReqVO.orderStatus != null and pageReqVO.orderStatus != ''">
  2085. and order_status = #{pageReqVO.orderStatus}
  2086. </if>
  2087. </select>
  2088. </mapper>