TradeOrderMapper.xml 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093
  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.route_plan_id,
  1002. o.seller_id,
  1003. o.sell_method,
  1004. o.share_name,
  1005. o.source_id,
  1006. o.source_name,
  1007. o.store_id,
  1008. o.store_name,
  1009. o.visitor_type,
  1010. ps.cost_price,
  1011. tou.contact_name,
  1012. tou.credential_no,
  1013. tou.mobile,
  1014. td.product_name,
  1015. count(
  1016. DISTINCT
  1017. CASE
  1018. WHEN (
  1019. td.voucher_status in (3,6,7,8)
  1020. OR ( td.voucher_status = 9 AND td.check_status = 1 )
  1021. ) THEN
  1022. td.id ELSE null
  1023. END
  1024. ) AS num,
  1025. o.pay_amount - SUM( ifnull(trd.refund_amount,0) ) - SUM(
  1026. CASE
  1027. WHEN ( td.voucher_status in (1,2) )
  1028. AND DATE_FORMAT( td.validity_end_date, '%Y-%c-%d' ) >= DATE_FORMAT( NOW( ), '%Y-%c-%d' ) THEN
  1029. td.actual_price ELSE 0
  1030. END
  1031. ) AS pay_amount
  1032. FROM
  1033. trade_order o
  1034. INNER JOIN trade_detail td ON td.order_id = o.id
  1035. LEFT JOIN trade_refund_detail trd ON trd.trade_detail_id = td.id
  1036. AND trd.refund_status = 6
  1037. INNER JOIN trade_order_user tou ON o.id = tou.order_id
  1038. INNER JOIN product_spu ps ON ps.id = td.product_id
  1039. LEFT JOIN trade_invoice_detail i ON i.order_no = o.order_no
  1040. LEFT JOIN trade_invoice ii ON i.invoice_id = ii.id AND ii.invoice_status IN (1,3)
  1041. 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
  1042. LEFT JOIN ota_bill_order obo ON obo.order_id = o.id
  1043. LEFT JOIN ota_bill_store obs ON obs.id = obo.bill_store_id AND obs.bill_status=1
  1044. where td.validity_end_date >= DATE_SUB(NOW(), INTERVAL #{canInvoicedDay} DAY)
  1045. and o.is_invoice in (0,2)
  1046. and o.order_status in (7,8,9,11,12)
  1047. <if test="vo.orderNo != null and vo.orderNo != ''">
  1048. AND o.order_no = #{vo.orderNo}
  1049. </if>
  1050. <if test="vo.sourceId != null and vo.sourceId != ''">
  1051. AND o.source_id = #{vo.sourceId}
  1052. </if>
  1053. <if test="vo.storeId != null and vo.storeId != ''">
  1054. AND o.store_id = #{vo.storeId}
  1055. </if>
  1056. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1057. AND tou.credential_no = #{vo.credentialNo}
  1058. </if>
  1059. <if test="vo.mobile != null and vo.mobile != ''">
  1060. AND tou.mobile = #{vo.mobile}
  1061. </if>
  1062. <if test="vo.contactName != null and vo.contactName != ''">
  1063. AND tou.contact_name = #{vo.contactName}
  1064. </if>
  1065. <if test="vo.travelDate != null and vo.travelDate != ''">
  1066. AND o.travel_date = #{vo.travelDate}
  1067. </if>
  1068. <if test="vo.sellerId != null and vo.sellerId != ''">
  1069. AND o.seller_id = #{vo.sellerId}
  1070. </if>
  1071. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1072. AND td.voucher_code = #{vo.voucherCode}
  1073. </if>
  1074. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  1075. AND o.sell_method = #{vo.sellMethod}
  1076. </if>
  1077. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1078. AND td.use_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1079. </if>
  1080. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1081. AND td.use_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1082. </if>
  1083. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  1084. AND o.payment_date <![CDATA[ >= ]]> #{vo.orderDateStart}
  1085. </if>
  1086. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  1087. AND o.payment_date <![CDATA[ <= ]]> #{vo.orderDateEnd}
  1088. </if>
  1089. <if test="vo.productName != null and vo.productName != ''">
  1090. AND td.product_name like concat('%',#{vo.productName}, '%')
  1091. </if>
  1092. AND ii.id IS NULL
  1093. AND (op.payment_type != 6 OR (o.is_bill=2 AND obs.id IS NOT NULL))
  1094. AND date_format(NOW(), '%Y-%m-%d') > date_format(o.travel_date, '%Y-%m-%d')
  1095. GROUP BY
  1096. o.order_no
  1097. HAVING
  1098. SUM(CASE WHEN td.voucher_status IN (1,2) AND td.validity_end_date >= CURDATE() THEN 1 ELSE 0 END) = 0
  1099. AND pay_amount > 0
  1100. ORDER BY
  1101. o.travel_date DESC
  1102. </select>
  1103. <select id="getOrderByVoucherCode"
  1104. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1105. SELECT o.* FROM trade_order o
  1106. inner join trade_detail d on d.order_id = o.id
  1107. where (o.order_status = 6 or o.order_status = 7) and d.voucher_code = #{voucherCode} limit 1
  1108. </select>
  1109. <select id="getOrderByExternalOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1110. 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
  1111. </select>
  1112. <select id="getOtcOrderByExternalOrderNo" resultType="java.util.Map">
  1113. 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
  1114. </select>
  1115. <select id="getTradeOrderByVoucherCode" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1116. SELECT o.* FROM trade_order o inner join trade_detail d on d.order_id = o.id where d.voucher_code = #{voucherCode} limit 1
  1117. </select>
  1118. <select id="getOrderByCardNo"
  1119. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1120. SELECT
  1121. o.*
  1122. FROM
  1123. trade_order o
  1124. INNER JOIN trade_detail d ON d.order_id = o.id
  1125. INNER JOIN trade_visitor v ON v.detail_id = d.id
  1126. WHERE
  1127. o.travel_date >= CURDATE()
  1128. and d.voucher_status in (1,2,3,4,8,9)
  1129. and v.credential_no = #{cardNo}
  1130. </select>
  1131. <select id="getOrderByDetailBase"
  1132. resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1133. SELECT o.* FROM trade_order o
  1134. inner join trade_detail d on d.order_id = o.id
  1135. inner join trade_detail_base tdb on tdb.detail_id = d.id
  1136. where (o.order_status = 6 or o.order_status = 7) and tdb.id = #{baseId} limit 1
  1137. </select>
  1138. <select id="getAccountOrderPage"
  1139. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1140. SELECT td.*,tou.contact_name,tou.credential_no,tou.mobile,COUNT(tdl.id) num,tdl.product_name,tdl.spec_type
  1141. FROM trade_order td
  1142. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1143. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  1144. where 1= 1 AND td.order_status NOT IN (-2, -1, 0, 1, 2, 12) AND td.is_account = 0
  1145. <if test="vo.orderNo != null and vo.orderNo != ''">
  1146. AND td.order_no = #{vo.orderNo}
  1147. </if>
  1148. <if test="vo.contactName != null and vo.contactName != ''">
  1149. AND tou.contact_name = #{vo.contactName}
  1150. </if>
  1151. <if test="vo.travelDate != null and vo.travelDate != ''">
  1152. AND td.travel_date = #{vo.travelDate}
  1153. </if>
  1154. GROUP BY td.id
  1155. ORDER BY td.create_time DESC
  1156. </select>
  1157. <update id="updateOrderStatus">
  1158. UPDATE trade_order SET order_status = #{orderStatus} WHERE id = #{orderId} and order_status != #{orderStatus}
  1159. </update>
  1160. <update id="updateOrderIsAccount">
  1161. UPDATE trade_order SET is_account = #{isAccount} WHERE id = #{orderId}
  1162. </update>
  1163. <update id="updateOrderDeleted">
  1164. UPDATE trade_order SET deleted = #{deleted},update_time = now() WHERE id = #{orderId}
  1165. </update>
  1166. <resultMap id="OrderAndDetailResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderPdaRespVO">
  1167. <id property="id" column="id"/>
  1168. <result property="orderNo" column="order_no"/>
  1169. <result property="sourceName" column="source_name"/>
  1170. <result property="externalOrderNo" column="external_order_no"/>
  1171. <result property="routePlanId" column="route_plan_id"/>
  1172. <result property="visitorType" column="visitor_type"/>
  1173. <result property="travelDate" column="travel_date"/>
  1174. <result property="sellMethod" column="sell_method"/>
  1175. <result property="sourceName" column="source_name"/>
  1176. <result property="sellerId" column="seller_id"/>
  1177. <result property="memberId" column="member_id"/>
  1178. <result property="amount" column="amount"/>
  1179. <result property="payAmount" column="pay_amount"/>
  1180. <result property="orderStatus" column="order_status"/>
  1181. <result property="paymentDate" column="payment_date"/>
  1182. <result property="contactName" column="contact_name"/>
  1183. <result property="credentialNo" column="credential_no"/>
  1184. <result property="mobile" column="mobile"/>
  1185. <result property="remark" column="remark"/>
  1186. <collection property="tradeDetailList" resultMap="tradeDetailMap"/>
  1187. </resultMap>
  1188. <resultMap id="tradeDetailMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  1189. <result property="id" column="detailId"/>
  1190. <result property="orderId" column="order_id"/>
  1191. <result property="voucherCode" column="voucher_code"/>
  1192. <result property="voucherStatus" column="voucher_status"/>
  1193. <result property="useDate" column="use_date"/>
  1194. <result property="validityStartDate" column="validity_start_date"/>
  1195. <result property="validityEndDate" column="validity_end_date"/>
  1196. <result property="usageDays" column="usage_days"/>
  1197. <result property="checkStatus" column="check_status"/>
  1198. <result property="takeStatus" column="take_status"/>
  1199. <result property="refundStatus" column="refund_status"/>
  1200. <result property="verifyTime" column="verify_time"/>
  1201. <result property="activateStatus" column="activate_status"/>
  1202. <result property="activateDays" column="activate_days"/>
  1203. <result property="activateTime" column="activate_time"/>
  1204. <result property="productId" column="product_id"/>
  1205. <result property="productName" column="product_name"/>
  1206. <result property="specType" column="spec_type"/>
  1207. <collection property="detailBaseList" resultMap="tradeDetailBaseResMap"/>
  1208. </resultMap>
  1209. <resultMap id="tradeDetailBaseResMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.DetailBaseRespVO">
  1210. <result property="id" column="detail_base_id"/>
  1211. <result property="detailId" column="detailId"/>
  1212. <result property="productBaseId" column="product_base_id"/>
  1213. <result property="productBaseName" column="product_base_name"/>
  1214. <result property="productBaseType" column="product_base_type"/>
  1215. <result property="productResourceId" column="product_resource_id"/>
  1216. <result property="productResourceName" column="product_resource_name"/>
  1217. <result property="supplierProductId" column="supplier_product_id"/>
  1218. <result property="supplierId" column="supplier_id"/>
  1219. <result property="supplierName" column="supplier_name"/>
  1220. <result property="isSystemDirect" column="is_system_direct"/>
  1221. <result property="useStatus" column="use_status"/>
  1222. <result property="checkStatus" column="base_check_status"/>
  1223. <result property="verifyTime" column="base_verify_time"/>
  1224. <result property="price" column="base_price"/>
  1225. <result property="usageCount" column="usage_count"/>
  1226. <result property="productResourcePrice" column="product_resource_price"/>
  1227. <result property="projectId" column="project_id"/>
  1228. <result property="projectName" column="project_name"/>
  1229. <result property="specificationId" column="specification_id"/>
  1230. <result property="specificationName" column="specification_name"/>
  1231. <result property="specType" column="base_spec_type"/>
  1232. <result property="supplierVoucherCode" column="supplier_voucher_code"/>
  1233. <result property="platSupplierOrderId" column="plat_supplier_order_id"/>
  1234. </resultMap>
  1235. <select id="getOrderAndDetailInfo" resultMap="OrderAndDetailResultMap">
  1236. 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,
  1237. tou.contact_name,tou.credential_no,tou.mobile,
  1238. tdl.id detailId,tdl.voucher_code,tdl.voucher_status,tdl.product_name,tdl.spec_type,tdl.validity_start_date,tdl.validity_end_date,
  1239. 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,
  1240. 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,
  1241. tdb.specification_id,tdb.specification_name,tdb.spec_type base_spec_type,tdb.supplier_voucher_code,tdb.plat_supplier_order_id
  1242. FROM trade_order td
  1243. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1244. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1245. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1246. inner join trade_detail_base tdb on tdl.id = tdb.detail_id
  1247. where 1= 1 and td.order_status >= 6 and td.order_status <![CDATA[ <= ]]> 9
  1248. and td.sell_method != 3 and td.sell_method != 4
  1249. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1250. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1251. <if test="channelId != null and channelId != ''">
  1252. and tdb.product_base_id in (select product_id from product_check_channel where channel_id=#{channelId} and deleted = 0)
  1253. </if>
  1254. <if test="orderNo != null and orderNo != ''">
  1255. AND td.order_no = #{orderNo}
  1256. </if>
  1257. <choose>
  1258. <when test="phone != null and phone.length() == 4">
  1259. AND tou.mobile like concat('%',#{phone})
  1260. </when>
  1261. <when test="phone != null and phone != ''">
  1262. AND tou.mobile = #{phone}
  1263. </when>
  1264. <otherwise>
  1265. </otherwise>
  1266. </choose>
  1267. <choose>
  1268. <when test="cardNo != null and cardNo.length() == 4">
  1269. AND tv.credential_no like concat('%',#{cardNo})
  1270. </when>
  1271. <when test="cardNo != null and cardNo != ''">
  1272. AND tv.credential_no = #{cardNo}
  1273. </when>
  1274. <otherwise>
  1275. </otherwise>
  1276. </choose>
  1277. ORDER BY td.travel_date DESC
  1278. </select>
  1279. <select id="getPlatOrderNo" resultType="java.lang.String">
  1280. select t3.order_no from trade_order t1
  1281. inner join trade_supplier_order t2 on t1.id = t2.order_id
  1282. inner join trade_order t3 on t2.trade_no = t3.external_order_no
  1283. where t1.order_no = #{orderNo}
  1284. </select>
  1285. <select id="getTotalPayByOrderNo" resultType="java.math.BigDecimal">
  1286. select sum(t2.pay_amount) from trade_order t1 inner join trade_order_pay t2 on t1.id = t2.order_id
  1287. where t1.order_no = #{orderNo} and t2.pay_status = 1
  1288. </select>
  1289. <select id="getCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1290. 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,
  1291. td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,
  1292. td.payment_date,td.remark, tou.contact_name,tou.credential_no,tou.mobile,td.is_add_order
  1293. FROM trade_order td
  1294. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1295. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1296. left join product_route_plan plan on td.route_plan_id = plan.id
  1297. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
  1298. left join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
  1299. </if>
  1300. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
  1301. left join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
  1302. </if>
  1303. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1304. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1305. </if>
  1306. where 1=1
  1307. <choose>
  1308. <when test="vo.orderStatus != null">
  1309. AND td.order_status = #{vo.orderStatus}
  1310. </when>
  1311. <otherwise>
  1312. and td.order_status in (6,7,8,9,10,13)
  1313. </otherwise>
  1314. </choose>
  1315. <choose>
  1316. <when test="vo.travelDate != null and vo.travelDate != ''">
  1317. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  1318. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  1319. </when>
  1320. <otherwise>
  1321. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1322. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1323. </otherwise>
  1324. </choose>
  1325. <choose>
  1326. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1327. AND td.order_no like concat('%',#{vo.orderNo})
  1328. </when>
  1329. <when test="vo.orderNo != null and vo.orderNo != ''">
  1330. AND td.order_no = #{vo.orderNo}
  1331. </when>
  1332. <otherwise>
  1333. </otherwise>
  1334. </choose>
  1335. <choose>
  1336. <when test="vo.phone != null and vo.phone.length() == 4">
  1337. AND tou.mobile like concat('%',#{vo.phone})
  1338. </when>
  1339. <when test="vo.phone != null and vo.phone != ''">
  1340. AND tou.mobile = #{vo.phone}
  1341. </when>
  1342. <otherwise>
  1343. </otherwise>
  1344. </choose>
  1345. <choose>
  1346. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  1347. AND tv.credential_no like concat('%',#{vo.credentialNo})
  1348. </when>
  1349. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  1350. AND tv.credential_no = #{vo.credentialNo}
  1351. </when>
  1352. <otherwise>
  1353. </otherwise>
  1354. </choose>
  1355. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  1356. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  1357. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  1358. </if>
  1359. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  1360. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  1361. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  1362. </if>
  1363. <if test="vo.travelStatus != null">
  1364. AND td.travel_status = #{vo.travelStatus}
  1365. </if>
  1366. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1367. AND tdl.voucher_code = #{vo.voucherCode}
  1368. </if>
  1369. <if test="vo.productName != null and vo.productName != ''">
  1370. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1371. </if>
  1372. <if test="vo.sellMethod != null">
  1373. AND td.sell_method = #{vo.sellMethod}
  1374. </if>
  1375. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  1376. AND (td.route_plan_id in
  1377. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1378. #{item}
  1379. </foreach>
  1380. or tdl.product_id in
  1381. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1382. #{item}
  1383. </foreach>
  1384. )
  1385. </if>
  1386. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  1387. AND tdl.product_id in
  1388. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1389. #{item}
  1390. </foreach>
  1391. </if>
  1392. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1393. and td.route_plan_id in
  1394. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1395. #{item}
  1396. </foreach>
  1397. </if>
  1398. group by td.id
  1399. ORDER BY td.create_time DESC
  1400. </select>
  1401. <select id="countCheckOrder" resultType="java.lang.Integer">
  1402. SELECT count(DISTINCT td.id) num FROM trade_order td
  1403. INNER JOIN trade_detail tdl ON td.id = tdl.order_id
  1404. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  1405. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1406. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1407. </if>
  1408. where 1=1
  1409. <choose>
  1410. <when test="vo.orderStatus != null">
  1411. AND td.order_status = #{vo.orderStatus}
  1412. </when>
  1413. <otherwise>
  1414. and td.order_status in (6,7,8,9,10,13)
  1415. </otherwise>
  1416. </choose>
  1417. <choose>
  1418. <when test="vo.travelDate != null and vo.travelDate != ''">
  1419. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  1420. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  1421. </when>
  1422. <otherwise>
  1423. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1424. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1425. </otherwise>
  1426. </choose>
  1427. <choose>
  1428. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1429. AND td.order_no like concat('%',#{vo.orderNo})
  1430. </when>
  1431. <when test="vo.orderNo != null and vo.orderNo != ''">
  1432. AND td.order_no = #{vo.orderNo}
  1433. </when>
  1434. <otherwise>
  1435. </otherwise>
  1436. </choose>
  1437. <choose>
  1438. <when test="vo.phone != null and vo.phone.length() == 4">
  1439. AND tou.mobile like concat('%',#{vo.phone})
  1440. </when>
  1441. <when test="vo.phone != null and vo.phone != ''">
  1442. AND tou.mobile = #{vo.phone}
  1443. </when>
  1444. <otherwise>
  1445. </otherwise>
  1446. </choose>
  1447. <choose>
  1448. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  1449. AND tv.credential_no like concat('%',#{vo.credentialNo})
  1450. </when>
  1451. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  1452. AND tv.credential_no = #{vo.credentialNo}
  1453. </when>
  1454. <otherwise>
  1455. </otherwise>
  1456. </choose>
  1457. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  1458. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  1459. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  1460. </if>
  1461. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  1462. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  1463. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  1464. </if>
  1465. <if test="vo.travelStatus != null">
  1466. AND td.travel_status = #{vo.travelStatus}
  1467. </if>
  1468. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1469. AND tdl.voucher_code = #{vo.voucherCode}
  1470. </if>
  1471. <if test="vo.productName != null and vo.productName != ''">
  1472. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1473. </if>
  1474. <if test="vo.sellMethod != null">
  1475. AND td.sell_method = #{vo.sellMethod}
  1476. </if>
  1477. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  1478. AND (td.route_plan_id in
  1479. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1480. #{item}
  1481. </foreach>
  1482. or tdl.product_id in
  1483. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1484. #{item}
  1485. </foreach>
  1486. )
  1487. </if>
  1488. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  1489. AND tdl.product_id in
  1490. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1491. #{item}
  1492. </foreach>
  1493. </if>
  1494. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1495. and td.route_plan_id in
  1496. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1497. #{item}
  1498. </foreach>
  1499. </if>
  1500. </select>
  1501. <select id="selectStoreMachineProductList"
  1502. resultType="java.lang.Long">
  1503. SELECT t1.product_id FROM otc_agency_store_machine_product t1
  1504. where 1=1
  1505. <if test="vo.storeId != null and vo.storeId != ''">
  1506. AND t1.store_id = #{vo.storeId}
  1507. </if>
  1508. <if test="vo.machineId != null and vo.machineId != ''">
  1509. AND t1.machine_id = #{vo.machineId}
  1510. </if>
  1511. </select>
  1512. <select id="orderListByOta" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1513. SELECT
  1514. t1.*
  1515. FROM
  1516. trade_order t1
  1517. inner join trade_detail t3 on t1.id = t3.order_id
  1518. inner join trade_visitor t4 on t3.id = t4.detail_id
  1519. INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
  1520. WHERE
  1521. t1.sell_method = 0
  1522. AND t1.order_status in (6,7,8,9,10,13)
  1523. AND t1.tenant_id = #{tenantId}
  1524. AND t1.travel_date = #{travelDate}
  1525. <if test="credentialNo != null and credentialNo != ''">
  1526. AND t4.credential_no = #{credentialNo}
  1527. </if>
  1528. <if test="mobile != null and mobile != ''">
  1529. AND t2.mobile = #{mobile}
  1530. </if>
  1531. ORDER BY
  1532. t1.payment_date DESC
  1533. </select>
  1534. <select id="orderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1535. SELECT
  1536. t1.*
  1537. FROM
  1538. trade_order t1
  1539. INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
  1540. INNER JOIN trade_detail td on t1.id = td.order_id
  1541. INNER JOIN trade_visitor v on v.detail_id = td.id
  1542. WHERE
  1543. 1 = 1
  1544. <if test="orderStatus!=null and orderStatus.size()>0">
  1545. AND t1.order_status in
  1546. <foreach collection="orderStatus" item="item" separator="," open="(" close=")">
  1547. #{item}
  1548. </foreach>
  1549. </if>
  1550. AND t1.tenant_id = #{tenantId}
  1551. AND t1.travel_date = #{travelDate}
  1552. <if test="credentialNo != null and credentialNo != ''">
  1553. AND v.credential_no = #{credentialNo}
  1554. </if>
  1555. <if test="mobile != null and mobile != ''">
  1556. AND t2.mobile = #{mobile}
  1557. </if>
  1558. group by t1.id
  1559. ORDER BY
  1560. t1.payment_date DESC
  1561. </select>
  1562. <select id="queryOneByOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1563. SELECT DISTINCT o2.*
  1564. FROM trade_order o
  1565. INNER JOIN trade_detail d on d.order_id = o.id
  1566. INNER JOIN trade_detail_base db ON db.detail_id = d.id
  1567. INNER JOIN trade_detail d2 ON db.supplier_voucher_code = d2.voucher_code
  1568. INNER JOIN trade_order o2 ON d2.order_id = o2.id
  1569. WHERE o.order_no = #{orderNo}
  1570. union all
  1571. SELECT o.* FROM trade_order o WHERE o.sell_method in (0,1,4,6,7) and o.order_no = #{orderNo}
  1572. </select>
  1573. <select id="updateAppletProductSellNum">
  1574. update applet_product t1 inner JOIN applet_product_group t2 ON t1.id = t2.applet_product_id
  1575. and t2.deleted =0
  1576. set t1.sell_num = t1.sell_num+#{sellNum} where t2.product_id = #{productId}
  1577. </select>
  1578. <select id="selectCanBindOrderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1579. SELECT o.id,o.is_bind
  1580. FROM trade_order o
  1581. INNER JOIN trade_detail d ON d.order_id = o.id
  1582. INNER JOIN trade_order_user u on o.id = u.order_id
  1583. WHERE
  1584. o.order_status > 5 AND o.deleted = 0
  1585. AND (o.is_bind IS NULL or o.is_bind = 0 ) and o.id != #{vo.orderId}
  1586. AND o.travel_date = #{vo.travelDate}
  1587. AND d.product_id = #{vo.productId}
  1588. <if test="vo.routePlanId !=null">
  1589. And o.route_plan_id = #{vo.routePlanId}
  1590. </if>
  1591. AND u.mobile = #{vo.mobile}
  1592. GROUP BY o.id
  1593. </select>
  1594. <update id="deleteOrderById">
  1595. delete from trade_order where id = #{orderId}
  1596. </update>
  1597. <update id="deleteOrderByOrderNo">
  1598. update from trade_order where order_no = #{orderNo}
  1599. </update>
  1600. <select id="getInvoiceOrderCount" resultType="java.lang.Integer">
  1601. select count(1) num from trade_invoice t1 inner join trade_invoice_detail t2 on t1.id = t2.invoice_id
  1602. and t1.invoice_status in (1,3)
  1603. where t2.order_no = #{orderNo} and t1.deleted = 0
  1604. </select>
  1605. <select id="selectPlatPayAmountByOriginOrderNo" resultType="java.util.Map">
  1606. select sum(tod.pay_amount) totalPayAmount
  1607. from trade_order tod
  1608. where tod.external_origin_order_no =#{originOrderNo} and tod.order_status>=6
  1609. </select>
  1610. <select id="selectChangeCountByOrderId" resultType="java.lang.Integer">
  1611. select count(*) totalCount
  1612. from trade_order tod
  1613. inner join trade_order_bind tb on tod.id = tb.order_id and tb.type = 2 and tb.deleted =0
  1614. inner join trade_order tod1 on tod1.id = tb.bind_id
  1615. where tod.id = #{orderId} and tod1.order_status>=6
  1616. </select>
  1617. <update id="updateOrderFinishStatus">
  1618. update trade_order tod,
  1619. (select tod.id
  1620. from trade_order tod
  1621. inner join trade_detail td on tod.id = td.order_id
  1622. where tod.sell_method in
  1623. <foreach collection="sellMethodList" item="item" separator="," open="(" close=")">
  1624. #{item}
  1625. </foreach>
  1626. and tod.order_status >=6
  1627. and td.validity_end_date = #{endDate}
  1628. and not EXISTS (
  1629. select 1
  1630. from trade_detail td1
  1631. where td1.validity_end_date > #{endDate} and td1.order_id = tod.id and td1.refund_status != 1
  1632. )
  1633. ) t
  1634. set tod.finish_status = 1
  1635. where tod.id = t.id
  1636. </update>
  1637. <select id="getSupplierCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
  1638. 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,
  1639. td.sell_method,td.source_name,td.seller_id,td.member_id,td.amount,td.pay_amount,td.order_status,
  1640. td.payment_date,td.remark, tou.contact_name,tou.credential_no,tou.mobile
  1641. FROM trade_order td
  1642. INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
  1643. INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1644. INNER JOIN trade_detail_base tdb on tdb.detail_id = tdl.id
  1645. left join product_route_plan plan on td.route_plan_id = plan.id
  1646. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
  1647. inner join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
  1648. </if>
  1649. <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
  1650. inner join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
  1651. </if>
  1652. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1653. INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
  1654. </if>
  1655. where supplier_id in (
  1656. select t2.id from product_supplier_user t1 inner join product_supplier t2 on t1.supplier_id = t2.id
  1657. where t1.user_id=#{vo.userId} and t1.deleted =0
  1658. )
  1659. <choose>
  1660. <when test="vo.orderStatus != null">
  1661. AND td.order_status = #{vo.orderStatus}
  1662. </when>
  1663. <otherwise>
  1664. and td.order_status in (6,7,8,9,10,13)
  1665. </otherwise>
  1666. </choose>
  1667. <choose>
  1668. <when test="vo.travelDate != null and vo.travelDate != ''">
  1669. AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
  1670. AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
  1671. </when>
  1672. <otherwise>
  1673. and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
  1674. and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
  1675. </otherwise>
  1676. </choose>
  1677. <choose>
  1678. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1679. AND td.order_no like concat('%',#{vo.orderNo})
  1680. </when>
  1681. <when test="vo.orderNo != null and vo.orderNo != ''">
  1682. AND td.order_no = #{vo.orderNo}
  1683. </when>
  1684. <otherwise>
  1685. </otherwise>
  1686. </choose>
  1687. <choose>
  1688. <when test="vo.phone != null and vo.phone.length() == 4">
  1689. AND tou.mobile like concat('%',#{vo.phone})
  1690. </when>
  1691. <when test="vo.phone != null and vo.phone != ''">
  1692. AND tou.mobile = #{vo.phone}
  1693. </when>
  1694. <otherwise>
  1695. </otherwise>
  1696. </choose>
  1697. <choose>
  1698. <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
  1699. AND tv.credential_no like concat('%',#{vo.credentialNo})
  1700. </when>
  1701. <when test="vo.credentialNo != null and vo.credentialNo != ''">
  1702. AND tv.credential_no = #{vo.credentialNo}
  1703. </when>
  1704. <otherwise>
  1705. </otherwise>
  1706. </choose>
  1707. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
  1708. AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
  1709. WHERE plan_id = #{vo.dispatchId} and deleted = 0)
  1710. </if>
  1711. <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
  1712. AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
  1713. WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
  1714. </if>
  1715. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1716. AND tdl.voucher_code = #{vo.voucherCode}
  1717. </if>
  1718. <if test="vo.checkType != null and vo.checkType == 1">
  1719. AND tdb.use_status in (1,2)
  1720. </if>
  1721. <if test="vo.checkType != null and vo.checkType == 2">
  1722. AND tdb.use_status in (3,6,8)
  1723. </if>
  1724. <if test="vo.productName != null and vo.productName != ''">
  1725. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1726. </if>
  1727. <if test="vo.sellMethod != null">
  1728. AND td.sell_method = #{vo.sellMethod}
  1729. </if>
  1730. <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
  1731. AND (td.route_plan_id in
  1732. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1733. #{item}
  1734. </foreach>
  1735. or tdl.product_id in
  1736. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1737. #{item}
  1738. </foreach>
  1739. )
  1740. </if>
  1741. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
  1742. AND tdl.product_id in
  1743. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1744. #{item}
  1745. </foreach>
  1746. </if>
  1747. <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
  1748. and td.route_plan_id in
  1749. <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
  1750. #{item}
  1751. </foreach>
  1752. </if>
  1753. group by td.id
  1754. ORDER BY td.create_time DESC
  1755. </select>
  1756. <select id="getOtaTradeOrderPage"
  1757. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  1758. SELECT td.*,tor.order_no,pbr.check_start_date,pbr.check_end_date
  1759. FROM trade_detail td
  1760. LEFT JOIN product_basic_rule pbr on td.product_id = pbr.id
  1761. LEFT JOIN trade_order tor on tor.id = td.order_id
  1762. where 1= 1 AND
  1763. EXISTS (select * from product_sale_channel sc where sc.product_id = td.product_id and sc.channel_id = 0)
  1764. <if test="vo.productName != null and vo.productName != ''">
  1765. AND td.product_name = #{vo.productName}
  1766. </if>
  1767. <if test="vo.orderNo != null and vo.orderNo != ''">
  1768. AND tor.order_no = #{vo.orderNo}
  1769. </if>
  1770. <if test="vo.orderStatus != null and vo.orderStatus != ''">
  1771. AND tor.order_status = #{vo.orderStatus}
  1772. </if>
  1773. <if test="vo.paymentDateStart != null">
  1774. AND tor.payment_date <![CDATA[ >= ]]> #{vo.paymentDateStart}
  1775. </if>
  1776. <if test="vo.paymentDateEnd != null">
  1777. AND tor.payment_date <![CDATA[ <= ]]> #{vo.paymentDateEnd}
  1778. </if>
  1779. <if test="vo.type == 1">
  1780. AND tor.source_id = #{distributorId}
  1781. </if>
  1782. GROUP BY td.voucher_code
  1783. ORDER BY td.create_time DESC
  1784. </select>
  1785. <select id="regionStatic" resultType="java.util.Map">
  1786. 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
  1787. inner join trade_visitor t3 on t2.id = t3.detail_id
  1788. inner join ota_distributor t4 on t1.source_id = t4.id
  1789. inner join ota_distributor_region t5 on t4.id = t5.distributor_id
  1790. and (left(t3.credential_no,2) = t5.distributor_region_id or left(t3.credential_no,4) = t5.distributor_region_id)
  1791. inner join ota_region t6 on ((t5.distributor_region_id = province_code and LEVEL=1) or t5.distributor_region_id = left(t6.id,4) )
  1792. where t2.voucher_status in (1,2,3,4,6,8,9)
  1793. <if test="vo.startDate != null and vo.startDate!=''">
  1794. AND t2.use_date <![CDATA[ >= ]]> #{vo.startDate}
  1795. </if>
  1796. <if test="vo.endDate != null and vo.endDate!=''">
  1797. AND t2.use_date <![CDATA[ <= ]]> #{vo.endDate}
  1798. </if>
  1799. GROUP BY t4.id
  1800. order by num desc
  1801. </select>
  1802. <select id="queryOrderByLast" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1803. SELECT * FROM trade_order WHERE order_no = #{orderNo} and deleted = 1 ORDER BY update_time DESC limit 1
  1804. </select>
  1805. <select id="queryOrderById" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
  1806. SELECT * FROM trade_order WHERE id = #{orderId} ORDER BY update_time DESC limit 1
  1807. </select>
  1808. <select id="selectConfirmationCountry"
  1809. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderConfirmationCountryRespVO">
  1810. SELECT
  1811. t1.real_money actual_price,
  1812. t1.room_model_id,
  1813. t2.short_name room_model_short_name,
  1814. t2.NAME room_model_name,
  1815. t3.type,
  1816. ifnull( t3.nationality, 1 ) nationality,
  1817. t3.floor,
  1818. IFNULL( t4.`name`, '中国' ) nationality_name,
  1819. count( t3.id ) num
  1820. FROM
  1821. trade_order_room_model t1
  1822. LEFT JOIN resource_room_model t2 ON t1.room_model_id = t2.id
  1823. LEFT JOIN trade_visitor t3 ON t1.room_index_id = t3.room_index_id
  1824. LEFT JOIN area t4 ON t3.nationality = t4.id
  1825. WHERE
  1826. t1.order_id = 2031362252762136577
  1827. AND t1.deleted = 0
  1828. GROUP BY
  1829. t1.room_model_id,
  1830. t1.floor,
  1831. t3.type
  1832. ORDER BY
  1833. floor DESC
  1834. </select>
  1835. <select id="getOrderCount" resultType="java.util.Map">
  1836. select GROUP_CONCAT(num,'*',name) name,sum(num1) num1,sum(num2) num2,sum(num3) num3,sum(num4) num4 from (
  1837. SELECT sum(CASE WHEN tv.type='adultPlus' or tv.type='adultTake' THEN 1 ELSE 0 END) num1,
  1838. 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,
  1839. sum(CASE WHEN tv.type='with' THEN 1 ELSE 0 END) num3,
  1840. sum(CASE WHEN tv.type='leader' THEN 1 ELSE 0 END) num4,
  1841. CONCAT(rrm.short_name,'(',tv.floor,'F)') name ,count(1) num
  1842. FROM trade_order td
  1843. INNER JOIN trade_order_user tou on td.id = tou.order_id
  1844. left JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
  1845. left join trade_visitor tv on tdl.id = tv.detail_id
  1846. left JOIN product_spu ps on ps.id = tdl.product_id
  1847. LEFT JOIN ota_distributor od on od.id = td.source_id
  1848. left join trade_order_room_model tm on tv.room_index_id = tm.room_index_id and tm.deleted =0
  1849. left join resource_room_model rrm on tm.room_model_id = rrm.id
  1850. 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
  1851. where td.deleted = 0 and tou.deleted = 0 and td.order_status >0 and tv.type is not null
  1852. <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
  1853. and td.order_status in
  1854. <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
  1855. #{item}
  1856. </foreach>
  1857. </if>
  1858. <if test="vo.tenantId!=null">
  1859. AND td.tenant_id = #{vo.tenantId}
  1860. </if>
  1861. <choose>
  1862. <when test="vo.orderNo != null and vo.orderNo.length() == 4">
  1863. AND td.order_no like concat('%',#{vo.orderNo})
  1864. </when>
  1865. <when test="vo.orderNo != null and vo.orderNo != ''">
  1866. AND td.order_no = #{vo.orderNo}
  1867. </when>
  1868. <otherwise>
  1869. </otherwise>
  1870. </choose>
  1871. <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
  1872. AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
  1873. </if>
  1874. <if test="vo.memberId != null and vo.memberId != ''">
  1875. AND td.member_id = #{vo.memberId}
  1876. </if>
  1877. <if test="vo.voyageId != null and vo.voyageId != ''">
  1878. AND td.voyage_id = #{vo.voyageId}
  1879. </if>
  1880. <if test="vo.shipId != null and vo.shipId != ''">
  1881. AND td.ship_id = #{vo.shipId}
  1882. </if>
  1883. <if test="vo.routeId != null and vo.routeId != ''">
  1884. AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
  1885. </if>
  1886. <if test="vo.dispatchStatus != null">
  1887. AND td.dispatch_status = #{vo.dispatchStatus}
  1888. </if>
  1889. <if test="vo.payType != null">
  1890. AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
  1891. </if>
  1892. <if test="vo.otaCateId != null and vo.otaCateId != ''">
  1893. AND od.ota_category_id = #{vo.otaCateId}
  1894. </if>
  1895. <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
  1896. and od.ota_category_id in
  1897. <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
  1898. #{item}
  1899. </foreach>
  1900. </if>
  1901. <if test="vo.otaId != null and vo.otaId != ''">
  1902. AND td.source_id = #{vo.otaId}
  1903. </if>
  1904. <if test="vo.storeId != null and vo.storeId != ''">
  1905. AND td.store_id = #{vo.storeId}
  1906. </if>
  1907. <if test="vo.productTag != null and vo.productTag != ''">
  1908. AND ps.product_tag = #{vo.productTag}
  1909. </if>
  1910. <if test="vo.productTag2 != null and vo.productTag2 != ''">
  1911. AND ps.product_tag2 = #{vo.productTag2}
  1912. </if>
  1913. <if test="vo.productTag3 != null and vo.productTag3 != ''">
  1914. AND ps.product_tag3 = #{vo.productTag3}
  1915. </if>
  1916. <if test="vo.productTag4 != null and vo.productTag4 != ''">
  1917. AND ps.product_tag4 = #{vo.productTag4}
  1918. </if>
  1919. <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
  1920. AND tdl.product_id in
  1921. <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
  1922. #{item}
  1923. </foreach>
  1924. </if>
  1925. <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
  1926. AND td.external_order_no = #{vo.externalOrderNo}
  1927. </if>
  1928. <if test="vo.credentialNo != null and vo.credentialNo != ''">
  1929. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
  1930. </if>
  1931. <if test="vo.userName != null and vo.userName != ''">
  1932. AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
  1933. </if>
  1934. <choose>
  1935. <when test="vo.mobile != null and vo.mobile.length() == 4">
  1936. AND tou.mobile like concat('%',#{vo.mobile})
  1937. </when>
  1938. <when test="vo.mobile != null and vo.mobile != ''">
  1939. AND tou.mobile = #{vo.mobile}
  1940. </when>
  1941. <otherwise>
  1942. </otherwise>
  1943. </choose>
  1944. <if test="vo.contactName != null and vo.contactName != ''">
  1945. AND tou.contact_name = #{vo.contactName}
  1946. </if>
  1947. <if test="vo.travelDate != null and vo.travelDate != ''">
  1948. AND td.travel_date = #{vo.travelDate}
  1949. </if>
  1950. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  1951. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  1952. </if>
  1953. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  1954. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  1955. </if>
  1956. <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
  1957. AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
  1958. </if>
  1959. <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
  1960. AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
  1961. </if>
  1962. <if test="vo.orderDate != null and vo.orderDate != ''">
  1963. AND td.create_time = #{vo.orderDate}
  1964. </if>
  1965. <if test="vo.sellerId != null and vo.sellerId != ''">
  1966. AND td.seller_id = #{vo.sellerId}
  1967. </if>
  1968. <if test="vo.shareName != null and vo.shareName != ''">
  1969. AND td.share_name like concat('%',#{vo.shareName},'%')
  1970. </if>
  1971. <if test="vo.voucherCode != null and vo.voucherCode != ''">
  1972. AND tdl.voucher_code = #{vo.voucherCode}
  1973. </if>
  1974. <if test="vo.sellMethod != null and vo.sellMethod != ''">
  1975. AND td.sell_method = #{vo.sellMethod}
  1976. </if>
  1977. <if test="vo.productName != null and vo.productName != ''">
  1978. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  1979. </if>
  1980. <if test="vo.isFullPay == 0">
  1981. AND td.is_full_pay = #{vo.isFullPay}
  1982. </if>
  1983. <if test="vo.isComment != null">
  1984. AND td.is_comment = #{vo.isComment}
  1985. </if>
  1986. <if test="vo.sourceId != null and vo.sourceId != ''">
  1987. AND td.source_id = #{vo.sourceId}
  1988. </if>
  1989. <if test="vo.distributorId != null and vo.distributorId != ''">
  1990. AND td.source_id = #{vo.distributorId}
  1991. </if>
  1992. <if test="vo.sourceName != null and vo.sourceName != ''">
  1993. AND td.source_name like concat('%',#{vo.sourceName}, '%')
  1994. </if>
  1995. <if test="vo.travelStatus != null">
  1996. AND td.travel_status = #{vo.travelStatus}
  1997. </if>
  1998. <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
  1999. 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} )
  2000. </if>
  2001. GROUP BY rrm.short_name,tv.floor
  2002. ) p
  2003. </select>
  2004. </mapper>