TradeOrderMapper.xml 114 KB

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