TradeOrderMapper.xml 124 KB

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