TradeOrderMapper.xml 100 KB

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