TradeOrderMapper.xml 119 KB

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