TradeOrderMapper.xml 122 KB

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