| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.yc.ship.module.trade.dal.mysql.order.TradeOrderMapper">
- <resultMap id="MiddleWareDtoResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- <id property="id" column="id"/>
- <result property="orderNo" column="order_no"/>
- <result property="voyageId" column="voyage_id"/>
- <result property="bindId" column="bindId"/>
- <result property="isRead" column="isRead"/>
- <result property="sourceName" column="source_name"/>
- <result property="externalOrderNo" column="external_order_no"/>
- <result property="externalOriginOrderNo" column="external_origin_order_no"/>
- <result property="routePlanId" column="route_plan_id"/>
- <result property="routePlanName" column="route_plan_name"/>
- <result property="visitorType" column="visitor_type"/>
- <result property="travelDate" column="travel_date"/>
- <result property="sellMethod" column="sell_method"/>
- <result property="sourceName" column="source_name"/>
- <result property="sellerId" column="seller_id"/>
- <result property="memberId" column="member_id"/>
- <result property="amount" column="amount"/>
- <result property="payAmount" column="pay_amount"/>
- <result property="paymentStatus" column="pay_status"/>
- <result property="paymentType" column="payment_type"/>
- <result property="orderStatus" column="order_status"/>
- <result property="paymentDate" column="payment_date"/>
- <result property="areaManagerId" column="area_manager_id"/>
- <result property="storeName" column="store_name"/>
- <result property="contactName" column="contactName"/>
- <result property="shareName" column="share_name"/>
- <result property="isBind" column="is_bind"/>
- <result property="credentialNo" column="credentialNo"/>
- <result property="city" column="city"/>
- <result property="province" column="province"/>
- <result property="county" column="county"/>
- <result property="createTime" column="create_time"/>
- <result property="mobile" column="mobile"/>
- <result property="auditState" column="audit_state"/>
- <result property="storeId" column="store_id"/>
- <result property="sourceId" column="source_id"/>
- <result property="isMarketing" column="is_marketing"/>
- <result property="isMarketingUse" column="is_marketing_use"/>
- <result property="remark" column="remark"/>
- <result property="dispatchStatus" column="dispatch_status"/>
- <result property="isInvoice" column="is_invoice"/>
- <result property="isChangeOrder" column="is_change_order"/>
- <result property="refundAmount" column="refund_amount"/>
- <result property="confirmType" column="confirm_type"/>
- <result property="travelStatus" column="travel_status"/>
- <result property="finishStatus" column="finish_status"/>
- <result property="agencyGroupId" column="agency_group_id"/>
- <collection property="orderPayList" resultMap="orderPayList"/>
- <collection property="insuranceList" resultMap="insuranceResultMap"/>
- <collection property="contractList" resultMap="contractResultMap"/>
- </resultMap>
- <resultMap id="MiddleWareDtoResultMap2" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderPdaRespVO">
- <id property="id" column="id"/>
- <result property="orderNo" column="order_no"/>
- <result property="bindId" column="bindId"/>
- <result property="isRead" column="isRead"/>
- <result property="sourceName" column="source_name"/>
- <result property="externalOrderNo" column="external_order_no"/>
- <result property="externalOriginOrderNo" column="external_origin_order_no"/>
- <result property="routePlanId" column="route_plan_id"/>
- <result property="routePlanName" column="route_plan_name"/>
- <result property="visitorType" column="visitor_type"/>
- <result property="travelDate" column="travel_date"/>
- <result property="sellMethod" column="sell_method"/>
- <result property="sourceName" column="source_name"/>
- <result property="sellerId" column="seller_id"/>
- <result property="memberId" column="member_id"/>
- <result property="amount" column="amount"/>
- <result property="payAmount" column="pay_amount"/>
- <result property="paymentStatus" column="pay_status"/>
- <result property="paymentType" column="payment_type"/>
- <result property="orderStatus" column="order_status"/>
- <result property="paymentDate" column="payment_date"/>
- <result property="areaManagerId" column="area_manager_id"/>
- <result property="storeName" column="store_name"/>
- <result property="contactName" column="contactName"/>
- <result property="shareName" column="share_name"/>
- <result property="isBind" column="is_bind"/>
- <result property="credentialNo" column="credentialNo"/>
- <result property="city" column="city"/>
- <result property="province" column="province"/>
- <result property="county" column="county"/>
- <result property="createTime" column="create_time"/>
- <result property="mobile" column="mobile"/>
- <result property="auditState" column="audit_state"/>
- <result property="storeId" column="store_id"/>
- <result property="sourceId" column="source_id"/>
- <result property="isMarketing" column="is_marketing"/>
- <result property="isMarketingUse" column="is_marketing_use"/>
- <result property="remark" column="remark"/>
- <result property="dispatchStatus" column="dispatch_status"/>
- <result property="isInvoice" column="is_invoice"/>
- <result property="isChangeOrder" column="is_change_order"/>
- <result property="refundAmount" column="refund_amount"/>
- <result property="confirmType" column="confirm_type"/>
- <result property="travelStatus" column="travel_status"/>
- <result property="finishStatus" column="finish_status"/>
- <result property="agencyGroupId" column="agency_group_id"/>
- <collection property="orderPayList" resultMap="orderPayList"/>
- <collection property="insuranceList" resultMap="insuranceResultMap"/>
- <collection property="contractList" resultMap="contractResultMap"/>
- </resultMap>
- <resultMap id="orderPayList" type="com.yc.ship.module.trade.api.dto.TradeOrderPayDTO">
- <id property="id" column="payId"/>
- <result property="orderId" column="id"/>
- <result property="payAmount" column="payAmount"/>
- <result property="paymentNo" column="payment_no"/>
- <result property="payStatus" column="pay_status"/>
- <result property="paymentType" column="payment_type"/>
- <result property="paymentDate" column="payment_date"/>
- </resultMap>
- <resultMap id="insuranceResultMap" type="com.yc.ship.module.trade.dal.dataobject.insurance.InsuranceDO">
- <id property="id" column="insuranceId"/>
- <result property="orderId" column="id"/>
- <result property="policyNo" column="policy_no"/>
- <result property="proposalNo" column="proposal_no"/>
- <result property="insuranceNo" column="insurance_no"/>
- <result property="insuranceStatus" column="insurance_status"/>
- <result property="insuredNum" column="insured_num"/>
- <result property="insuranceEffectDate" column="insurance_effect_date"/>
- <result property="electronicPolicy" column="electronic_policy"/>
- </resultMap>
- <resultMap id="contractResultMap" type="com.yc.ship.module.trade.dal.dataobject.contract.ContractDO">
- <id property="id" column="contractId"/>
- <result property="orderId" column="id"/>
- <result property="contractNo" column="contract_no"/>
- <result property="status" column="status"/>
- <result property="touristsCount" column="tourists_count"/>
- <result property="contractUrl" column="contract_url"/>
- <result property="operateName" column="operate_name"/>
- <result property="signerName" column="signer_name"/>
- <result property="signerMobile" column="signer_mobile"/>
- <result property="signingTime" column="signing_time"/>
- <result property="signingUrl" column="signing_url"/>
- <result property="viewUrl" column="view_url"/>
- </resultMap>
- <resultMap id="RefundResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- <id property="id" column="id"/>
- <result property="orderNo" column="order_no"/>
- <result property="sourceName" column="source_name"/>
- <result property="externalOrderNo" column="external_order_no"/>
- <result property="routePlanId" column="route_plan_id"/>
- <result property="visitorType" column="visitor_type"/>
- <result property="travelDate" column="travel_date"/>
- <result property="sellMethod" column="sell_method"/>
- <result property="sourceName" column="source_name"/>
- <result property="sellerId" column="seller_id"/>
- <result property="memberId" column="member_id"/>
- <result property="amount" column="amount"/>
- <result property="payAmount" column="pay_amount"/>
- <result property="orderStatus" column="order_status"/>
- <result property="paymentDate" column="payment_date"/>
- <result property="contactName" column="contact_name"/>
- <result property="credentialNo" column="credential_no"/>
- <result property="mobile" column="mobile"/>
- <result property="remark" column="remark"/>
- <collection property="tradeDetailList" resultMap="tradeDetailResultMap"/>
- </resultMap>
- <resultMap id="tradeDetailResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
- <id property="orderId" column="id"/>
- <result property="id" column="detailId"/>
- <result property="voucherCode" column="voucher_code"/>
- <result property="voucherStatus" column="voucher_status"/>
- <result property="productName" column="product_name"/>
- <result property="specType" column="spec_type"/>
- <collection property="visitors" resultMap="visitorResultMap"/>
- </resultMap>
- <resultMap id="visitorResultMap" type="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
- <id property="detailId" column="detailId"/>
- <result property="id" column="visitorId"/>
- <result property="credentialNo" column="credential_no"/>
- <result property="credentialType" column="credential_type"/>
- <result property="name" column="name"/>
- </resultMap>
- <select id="getCategoryTreeList" resultType="com.yc.ship.module.product.api.dto.CategoryRespDTO">
- 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
- </select>
- <select id="getCategoryOTATreeList" resultType="com.yc.ship.module.product.api.dto.CategoryRespDTO">
- SELECT id,parent_id parentId,cate_name cateName,sort_num sortNum from product_category WHERE type = 1 AND use_status = 1 AND deleted = 0
- </select>
- <select id="getTradeOrderUserPage"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- 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
- ,tr.refund_amount refundAmount,
- ps.product_tag productTag,ps.product_tag2 productTag2,ps.product_tag3 productTag3,ps.product_tag4 productTag4
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id
- left JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
- left JOIN product_spu ps on ps.id = tdl.product_id
- LEFT JOIN ota_distributor od on od.id = td.source_id
- LEFT JOIN trade_order_audit toa on toa.order_id = td.id and toa.audit_status = 1
- 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
- where td.deleted = 0 and tou.deleted = 0
- <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
- and td.order_status in
- <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.tenantId!=null">
- AND td.tenant_id = #{vo.tenantId}
- </if>
- <choose>
- <when test="vo.orderNo != null and vo.orderNo.length() == 4">
- AND td.order_no like concat('%',#{vo.orderNo})
- </when>
- <when test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
- AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
- </if>
- <if test="vo.memberId != null and vo.memberId != ''">
- AND td.member_id = #{vo.memberId}
- </if>
- <if test="vo.voyageId != null and vo.voyageId != ''">
- AND td.voyage_id = #{vo.voyageId}
- </if>
- <if test="vo.shipId != null and vo.shipId != ''">
- AND td.ship_id = #{vo.shipId}
- </if>
- <if test="vo.routeId != null and vo.routeId != ''">
- AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
- </if>
- <if test="vo.dispatchStatus != null">
- AND td.dispatch_status = #{vo.dispatchStatus}
- </if>
- <if test="vo.payType != null">
- AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
- </if>
- <if test="vo.otaCateId != null and vo.otaCateId != ''">
- AND od.ota_category_id = #{vo.otaCateId}
- </if>
- <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
- and od.ota_category_id in
- <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.otaId != null and vo.otaId != ''">
- AND td.source_id = #{vo.otaId}
- </if>
- <if test="vo.storeId != null and vo.storeId != ''">
- AND td.store_id = #{vo.storeId}
- </if>
- <if test="vo.productTag != null and vo.productTag != ''">
- AND ps.product_tag = #{vo.productTag}
- </if>
- <if test="vo.productTag2 != null and vo.productTag2 != ''">
- AND ps.product_tag2 = #{vo.productTag2}
- </if>
- <if test="vo.productTag3 != null and vo.productTag3 != ''">
- AND ps.product_tag3 = #{vo.productTag3}
- </if>
- <if test="vo.productTag4 != null and vo.productTag4 != ''">
- AND ps.product_tag4 = #{vo.productTag4}
- </if>
- <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
- AND tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
- AND td.external_order_no = #{vo.externalOrderNo}
- </if>
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
- </if>
- <if test="vo.userName != null and vo.userName != ''">
- AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
- </if>
- <choose>
- <when test="vo.mobile != null and vo.mobile.length() == 4">
- AND tou.mobile like concat('%',#{vo.mobile})
- </when>
- <when test="vo.mobile != null and vo.mobile != ''">
- AND tou.mobile = #{vo.mobile}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.contactName != null and vo.contactName != ''">
- AND tou.contact_name = #{vo.contactName}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
- AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
- </if>
- <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
- AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
- </if>
- <if test="vo.orderDate != null and vo.orderDate != ''">
- AND td.create_time = #{vo.orderDate}
- </if>
- <if test="vo.sellerId != null and vo.sellerId != ''">
- AND td.seller_id = #{vo.sellerId}
- </if>
- <if test="vo.shareName != null and vo.shareName != ''">
- AND td.share_name like concat('%',#{vo.shareName},'%')
- </if>
- <if test="vo.voucherCode != null and vo.voucherCode != ''">
- AND tdl.voucher_code = #{vo.voucherCode}
- </if>
- <if test="vo.sellMethod != null and vo.sellMethod != ''">
- AND td.sell_method = #{vo.sellMethod}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.isFullPay == 0">
- AND td.is_full_pay = #{vo.isFullPay}
- </if>
- <if test="vo.isComment != null">
- AND td.is_comment = #{vo.isComment}
- </if>
- <if test="vo.sourceId != null and vo.sourceId != ''">
- AND td.source_id = #{vo.sourceId}
- </if>
- <if test="vo.distributorId != null and vo.distributorId != ''">
- AND td.source_id = #{vo.distributorId}
- </if>
- <if test="vo.sourceName != null and vo.sourceName != ''">
- AND td.source_name like concat('%',#{vo.sourceName}, '%')
- </if>
- <if test="vo.travelStatus != null">
- AND td.travel_status = #{vo.travelStatus}
- </if>
- <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
- 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} )
- </if>
- GROUP BY td.id
- ORDER BY td.create_time DESC
- </select>
- <select id="getTradeOrderUserCount" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderCountRespVO">
- SELECT count(DISTINCT td.id) orderNum,sum(if(tdl.voucher_status in (1,2,3,4,6,8,9), quantity_of_one,0)) totalNum,
- sum(if(tdl.spec_type='full' and tdl.voucher_status in (1,2,3,4,6,8,9), quantity_of_one,0)) fullNum,
- sum(if(tdl.spec_type='half' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) halfNum,
- sum(if(tdl.spec_type='free' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) freeNum,
- sum(if(tdl.spec_type='common' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) commonNum,
- sum(if(tdl.spec_type='car_seat' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carSeatNum,
- sum(if(tdl.spec_type='car_yd' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carYdNum,
- sum(if(tdl.spec_type='other' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) otherNum,
- sum(if(tdl.spec_type='carrying_children' and tdl.voucher_status in (1,2,3,4,6,8,9),quantity_of_one,0)) carryingChildrenNum,
- sum(tdl.actual_price) totalPayAmount
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id
- INNER JOIN trade_detail tdl on td.id = tdl.order_id
- INNER JOIN product_spu ps on ps.id = tdl.product_id
- LEFT JOIN ota_distributor od on od.id = td.source_id
- where 1= 1
- <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
- and td.order_status in
- <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.tenantId!=null">
- AND td.tenant_id = #{vo.tenantId}
- </if>
- <choose>
- <when test="vo.orderNo != null and vo.orderNo.length() == 4">
- AND td.order_no like concat('%',#{vo.orderNo})
- </when>
- <when test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
- AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
- </if>
- <if test="vo.memberId != null and vo.memberId != ''">
- AND td.member_id = #{vo.memberId}
- </if>
- <if test="vo.productTag != null and vo.productTag != ''">
- AND ps.product_tag = #{vo.productTag}
- </if>
- <if test="vo.productTag2 != null and vo.productTag2 != ''">
- AND ps.product_tag2 = #{vo.productTag2}
- </if>
- <if test="vo.productTag3 != null and vo.productTag3 != ''">
- AND ps.product_tag3 = #{vo.productTag3}
- </if>
- <if test="vo.productTag4 != null and vo.productTag4 != ''">
- AND ps.product_tag4 = #{vo.productTag4}
- </if>
- <if test="vo.dispatchStatus != null">
- AND td.dispatch_status = #{vo.dispatchStatus}
- </if>
- <if test="vo.payType != null">
- AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
- </if>
- <if test="vo.otaCateId != null and vo.otaCateId != ''">
- AND od.ota_category_id = #{vo.otaCateId}
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
- AND (td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- or tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- )
- </if>
- <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
- AND tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
- and td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.otaId != null and vo.otaId != ''">
- AND td.source_id = #{vo.otaId}
- </if>
- <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
- and od.ota_category_id in
- <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.storeId != null and vo.storeId != ''">
- AND td.store_id = #{vo.storeId}
- </if>
- <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
- AND td.external_order_no = #{vo.externalOrderNo}
- </if>
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
- </if>
- <if test="vo.userName != null and vo.userName != ''">
- AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
- </if>
- <choose>
- <when test="vo.mobile != null and vo.mobile.length() == 4">
- AND tou.mobile like concat('%',#{vo.mobile})
- </when>
- <when test="vo.mobile != null and vo.mobile != ''">
- AND tou.mobile = #{vo.mobile}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.contactName != null and vo.contactName != ''">
- AND tou.contact_name = #{vo.contactName}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
- AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
- </if>
- <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
- AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
- </if>
- <if test="vo.orderDate != null and vo.orderDate != ''">
- AND td.create_time = #{vo.orderDate}
- </if>
- <if test="vo.sellerId != null and vo.sellerId != ''">
- AND td.seller_id = #{vo.sellerId}
- </if>
- <if test="vo.shareName != null and vo.shareName != ''">
- AND td.share_name like concat('%',#{vo.shareName},'%')
- </if>
- <if test="vo.voucherCode != null and vo.voucherCode != ''">
- AND tdl.voucher_code = #{vo.voucherCode}
- </if>
- <if test="vo.sellMethod != null and vo.sellMethod != ''">
- AND td.sell_method = #{vo.sellMethod}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.isFullPay == 0">
- AND td.is_full_pay = #{vo.isFullPay}
- </if>
- <if test="vo.isComment != null">
- AND td.is_comment = #{vo.isComment}
- </if>
- <if test="vo.sourceId != null and vo.sourceId != ''">
- AND td.source_id = #{vo.sourceId}
- </if>
- <if test="vo.sourceName != null and vo.sourceName != ''">
- AND td.source_name like concat('%',#{vo.sourceName}, '%')
- </if>
- <if test="vo.travelStatus != null">
- AND td.travel_status = #{vo.travelStatus}
- </if>
- <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
- 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} )
- </if>
- </select>
- <select id="getPaidOrderPage"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- SELECT td.*, op.pay_amount payAmount, op.refund_amount refundAmount, op.pay_status paymentStatus, op.payment_type paymentType, op.payment_date paymentDate
- FROM trade_order td
- INNER JOIN trade_order_pay op on op.order_id = td.id
- where td.order_status <![CDATA[ >= ]]> 6 and td.order_status <![CDATA[ <= ]]> 11
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </if>
- <if test="vo.payType != null">
- AND op.payment_type = #{vo.payType}
- </if>
- <if test="vo.storeId != null and vo.storeId != ''">
- AND td.store_id = #{vo.storeId}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
- AND op.payment_date <![CDATA[ >= ]]> #{vo.orderDateStart}
- </if>
- <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
- AND op.payment_date <![CDATA[ <= ]]> #{vo.orderDateEnd}
- </if>
- <if test="vo.orderDate != null and vo.orderDate != ''">
- AND td.create_time = #{vo.orderDate}
- </if>
- <if test="vo.sellerId != null and vo.sellerId != ''">
- AND td.seller_id = #{vo.sellerId}
- </if>
- <if test="vo.sellMethod != null and vo.sellMethod != ''">
- AND td.sell_method = #{vo.sellMethod}
- </if>
- ORDER BY td.create_time DESC
- </select>
- <select id="getRefundDetailPage"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
- SELECT td.*,tv.credential_no,tv.`name`,tv.mobile,tor.order_no
- FROM trade_detail td
- INNER JOIN trade_visitor tv on tv.detail_id = td.id
- LEFT JOIN trade_order tor on tor.id = td.order_id
- where 1= 1
- <if test="vo.name != null and vo.name != ''">
- AND tv.name = #{vo.name}
- </if>
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND tor.order_no = #{vo.orderNo}
- </if>
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- AND tv.credential_no = #{vo.credentialNo}
- </if>
- <if test="vo.mobile != null and vo.mobile != ''">
- AND tv.mobile = #{vo.mobile}
- </if>
- <if test="vo.orderStatus != null and vo.orderStatus != ''">
- AND tor.order_status = #{vo.orderStatus}
- </if>
- </select>
- <select id="getRefundRecordPage"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundRespVO">
- SELECT tr.*,td.order_no, ou.mobile,td.travel_date, ou.contact_name ,tdl.product_name
- FROM trade_refund tr
- INNER JOIN trade_order td on tr.order_id = td.id
- inner join product_voyage pv on td.voyage_id = pv.id
- inner join trade_order_user ou on ou.order_id = td.id
- INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
- LEFT JOIN ota_distributor od on od.id = td.source_id
- where 1= 1
- <if test="vo.shipId != null and vo.shipId != ''">
- AND td.ship_id = #{vo.shipId}
- </if>
- <if test="vo.voyageId != null and vo.voyageId != ''">
- AND td.voyage_id = #{vo.voyageId}
- </if>
- <if test="vo.routeId != null and vo.routeId != ''">
- AND pv.route_id = #{vo.routeId}
- </if>
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </if>
- <if test="vo.refundStatus!=null and vo.refundStatus.size()>0">
- and tr.refund_status in
- <foreach collection="vo.refundStatus" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.refundMethod != null and vo.refundMethod != ''">
- AND tr.refund_method = #{vo.refundMethod}
- </if>
- <if test="vo.refundUserId!=null and vo.refundUserId.size()>0">
- and tr.refund_user in
- <foreach collection="vo.refundUserId" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.refundChannel != null">
- AND tr.refund_channel = #{vo.refundChannel}
- </if>
- <if test="vo.mobile != null and vo.mobile != ''">
- AND ou.mobile = #{vo.mobile}
- </if>
- <if test="vo.sourceId != null and vo.sourceId != ''">
- AND td.source_id = #{vo.sourceId}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.refundTime != null and vo.refundTime != ''">
- AND tr.refund_time = #{vo.refundTime}
- </if>
- <if test="vo.refundTimeStart != null and vo.refundTimeStart != ''">
- AND tr.refund_time <![CDATA[ >= ]]> #{vo.refundTimeStart}
- </if>
- <if test="vo.refundTimeEnd != null and vo.refundTimeEnd != ''">
- AND tr.refund_time <![CDATA[ <= ]]> #{vo.refundTimeEnd}
- </if>
- <if test="vo.otaId != null and vo.otaId != ''">
- AND td.source_id = #{vo.otaId}
- </if>
- <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
- and od.ota_category_id in
- <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
- AND tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
- and td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- group by tr.id
- ORDER BY tr.create_time DESC
- </select>
- <select id="getOrderInfo" resultMap="MiddleWareDtoResultMap">
- 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,
- tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,tou.county,tou.province,tou.city,td.agency_group_id,
- top.id payId,top.pay_amount payAmount,top.pay_status,top.payment_type,top.payment_date,top.payment_no,
- td.store_name,td.is_invoice, td.confirm_type, td.travel_status, tr.refund_amount,td.finish_status,
- 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,
- 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
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id
- left JOIN trade_order_pay top on td.id = top.order_id AND top.pay_status = 1 and top.deleted = 0
- left JOIN trade_insurance ti on td.id = ti.order_id
- left JOIN trade_contract tc on td.id = tc.order_id
- LEFT JOIN (select m2.order_id,sum(m1.refund_amount) refund_amount from trade_refund_detail m1
- 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
- where 1= 1
- AND td.id = #{id}
- </select>
- <select id="getPdaOrderInfo" resultMap="MiddleWareDtoResultMap2">
- 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,
- tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,tou.county,tou.province,tou.city,td.is_change_order,td.agency_group_id,
- top.id payId,top.pay_amount payAmount,top.pay_status,top.payment_type,top.payment_date,top.payment_no,
- td.store_name,td.dispatch_status,td.is_invoice, td.confirm_type, td.travel_status, tr.refund_amount,td.finish_status,
- 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,
- 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
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id
- left JOIN trade_order_pay top on td.id = top.order_id AND top.pay_status = 1 and top.deleted = 0
- left JOIN trade_insurance ti on td.id = ti.order_id
- left JOIN trade_contract tc on td.id = tc.order_id
- left JOIN product_route_plan rt on rt.id = td.route_plan_id
- LEFT JOIN (select m2.order_id,sum(m1.refund_amount) refund_amount from trade_refund_detail m1
- 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
- where 1= 1
- AND td.id = #{id}
- </select>
- <select id="getMarketingApplyOrderPage" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- 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,
- tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
- 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
- FROM
- product_marketing_audit pma
- INNER JOIN trade_order td on pma.order_id = td.id
- inner join trade_detail ttd on td.id = ttd.order_id
- INNER JOIN trade_order_user tou ON td.id = tou.order_id
- LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
- WHERE 1 = 1 AND td.order_status != 11 and
- pma.travel_id in (SELECT DISTINCT travel_id FROM product_marketing_pm WHERE user_id = #{vo.userId} and deleted = 0)
- <if test="vo.ids.size()>0">
- and pma.travel_id in
- <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </if>
- <if test="vo.policyType != null and vo.policyType != ''">
- AND pmk.policy_type = #{vo.policyType}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND ttd.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.marketingName != null and vo.marketingName != ''">
- AND pmk.name like concat('%',#{vo.marketingName}, '%')
- </if>
- <if test="vo.isExecute != null and vo.isExecute != ''">
- AND pma.is_execute = #{vo.isExecute}
- </if>
- <if test="vo.distributorId != null and vo.distributorId != ''">
- AND pma.agency_id = #{vo.distributorId}
- </if>
- <if test="vo.storeId != null and vo.storeId != ''">
- AND pma.store_id = #{vo.storeId}
- </if>
- <if test="vo.orderStartTime != null and vo.orderStartTime != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.orderStartTime}
- </if>
- <if test="vo.orderEndTime != null and vo.orderEndTime != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.orderEndTime}
- </if>
- <if test="vo.auditState != null ">
- AND pma.audit_state = #{vo.auditState}
- </if>
- GROUP BY pma.id,td.id
- order by pma.create_time desc
- </select>
- <select id="getStoresMarketingOrderPage" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeMarketOrderRespVO">
- 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,
- tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
- 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
- FROM
- product_marketing_audit pma
- INNER JOIN trade_order td on pma.order_id = td.id
- INNER JOIN trade_detail tdl on td.id = tdl.order_id
- INNER JOIN trade_order_user tou ON td.id = tou.order_id
- LEFT JOIN product_marketing_pool_spu pms on td.id = pms.order_id
- LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
- WHERE 1 = 1
- <if test="vo.storeId != null">
- and pma.store_id = #{vo.storeId}
- </if>
- <if test="vo.distributorId != null">
- and td.source_id = #{vo.distributorId}
- </if>
- <if test="vo.ids.size()>0">
- and pma.travel_id in
- <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.isExecute != null">
- and pma.is_execute = #{vo.isExecute}
- </if>
- <if test="vo.policyType != null and vo.policyType != ''">
- AND pmk.policy_type = #{vo.policyType}
- </if>
- <if test="vo.marketingName != null and vo.marketingName != ''">
- AND pmk.name like concat('%',#{vo.marketingName}, '%')
- </if>
- <if test="vo.auditState != null">
- and pma.audit_state = #{vo.auditState}
- </if>
- <if test="vo.useAuditState != null">
- and pma.use_audit_state = #{vo.useAuditState}
- </if>
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- GROUP BY pma.id
- order by pma.create_time desc
- </select>
- <select id="getStoresMarketingOrderDesc" resultType="java.util.Map">
- 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,
- tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
- 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
- FROM
- product_marketing_audit pma
- INNER JOIN trade_order td on pma.order_id = td.id
- INNER JOIN trade_detail tdl on td.id = tdl.order_id
- INNER JOIN trade_order_user tou ON td.id = tou.order_id
- LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
- WHERE 1 = 1
- <if test="vo.storeId != null">
- and pma.store_id = #{vo.storeId}
- </if>
- <if test="vo.ids.size()>0">
- and pma.travel_id in
- <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.isExecute != null">
- and pma.is_execute = #{vo.isExecute}
- </if>
- <if test="vo.policyType != null and vo.policyType != ''">
- AND pmk.policy_type = #{vo.policyType}
- </if>
- <if test="vo.marketingName != null and vo.marketingName != ''">
- AND pmk.name like concat('%',#{vo.marketingName}, '%')
- </if>
- <if test="vo.auditState != null">
- and pma.audit_state = #{vo.auditState}
- </if>
- <if test="vo.useAuditState != null">
- and pma.use_audit_state = #{vo.useAuditState}
- </if>
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- GROUP BY pma.id
- order by pma.create_time desc
- </select>
- <select id="selectBindMarketing" resultType="java.lang.Long">
- SELECT tob.bind_id
- FROM
- trade_order_bind tob
- WHERE
- tob.type = 7 AND tob.deleted = 0 AND tob.order_id = #{orderId}
- </select>
- <select id="selectBindUseMarketing" resultType="java.lang.Long">
- SELECT tob.bind_id
- FROM
- trade_order_bind tob
- WHERE
- tob.type = 8 AND tob.deleted = 0 AND tob.order_id = #{orderId}
- </select>
- <select id="selectOrderIdByOrderNo" resultType="java.lang.Long">
- SELECT id FROM trade_order WHERE order_no = #{orderNo}
- </select>
- <select id="getRefundOrderInfo" resultMap="RefundResultMap">
- 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,
- tou.contact_name contactName,tou.credential_no credentialNo,tou.mobile,
- tdl.id detailId,tdl.voucher_code,tdl.voucher_status,tdl.product_name,tdl.spec_type,
- tv.id visitorId,tv.credential_no,tv.credential_type,tv.`name`
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id
- INNER JOIN trade_detail tdl on td.id = tdl.order_id
- INNER JOIN trade_visitor tv on tdl.id = tv.detail_id
- where 1= 1
- <if test="id != null and id != ''">
- AND td.id = #{id}
- </if>
- </select>
- <select id="getTradeOrderByExpire" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- select * from trade_order where order_status =14 and travel_date <![CDATA[ <= ]]> #{expiretime}
- </select>
- <select id="getPageRefundRecord"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundRecordRespVO">
- SELECT trr.*,td.order_no, td.id orderId, td.travel_date
- FROM trade_refund_record trr
- left join trade_order_pay top on trr.order_pay_id = top.id
- left join trade_refund tr on trr.refund_id = tr.id
- left join trade_order td on td.id = top.order_id
- left join product_voyage pv on td.voyage_id = pv.id
- LEFT JOIN ota_distributor od on od.id = td.source_id
- where 1= 1
- <if test="vo.shipId != null and vo.shipId != ''">
- AND td.ship_id = #{vo.shipId}
- </if>
- <if test="vo.voyageId != null and vo.voyageId != ''">
- AND td.voyage_id = #{vo.voyageId}
- </if>
- <if test="vo.routeId != null and vo.routeId != ''">
- AND pv.route_id = #{vo.routeId}
- </if>
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </if>
- <if test="vo.refundNo != null and vo.refundNo != ''">
- AND trr.refund_no = #{vo.refundNo}
- </if>
- <if test="vo.paymentNo != null and vo.paymentNo != ''">
- AND trr.payment_no = #{vo.paymentNo}
- </if>
- <if test="vo.refundStatus != null and vo.refundStatus != ''">
- AND trr.refund_status = #{vo.refundStatus}
- </if>
- <if test="vo.refundId != null and vo.refundId != ''">
- AND trr.refund_id = #{vo.refundId}
- </if>
- <if test="vo.openId != null and vo.openId != ''">
- AND trr.openId = #{vo.openId}
- </if>
- <if test="vo.otaId != null and vo.otaId != ''">
- AND td.source_id = #{vo.otaId}
- </if>
- <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
- and od.ota_category_id in
- <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.sourceId != null and vo.sourceId != ''">
- AND td.source_id = #{vo.sourceId}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.refundTime != null and vo.refundTime != ''">
- AND trr.refund_time = #{vo.refundTime}
- </if>
- <if test="vo.refundTimeStart != null and vo.refundTimeStart != ''">
- AND trr.refund_time <![CDATA[ >= ]]> #{vo.refundTimeStart}
- </if>
- <if test="vo.refundTimeEnd != null and vo.refundTimeEnd != ''">
- AND trr.refund_time <![CDATA[ <= ]]> #{vo.refundTimeEnd}
- </if>
- ORDER BY trr.create_time DESC
- </select>
- <select id="getPrintTemp"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.otc.PrintRespVO">
- SELECT pt.* FROM print_temp pt where pt.template_code = #{printTemp}
- </select>
- <select id="queryCanInvoicedOrderPage"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- SELECT
- o.order_no,
- o.travel_date,
- o.order_status,
- o.amount,
- o.create_time,
- o.external_order_no,
- o.id,
- o.is_invoice,
- o.item_id,
- o.payment_date,
- o.remark,
- o.route_plan_id,
- o.seller_id,
- o.sell_method,
- o.share_name,
- o.source_id,
- o.source_name,
- o.store_id,
- o.store_name,
- o.visitor_type,
- ps.cost_price,
- tou.contact_name,
- tou.credential_no,
- tou.mobile,
- td.product_name,
- count(
- DISTINCT
- CASE
- WHEN (
- td.voucher_status in (3,6,7,8)
- OR ( td.voucher_status = 9 AND td.check_status = 1 )
- ) THEN
- td.id ELSE null
- END
- ) AS num,
- o.pay_amount - SUM( ifnull(trd.refund_amount,0) ) - SUM(
- CASE
- WHEN ( td.voucher_status in (1,2) )
- AND DATE_FORMAT( td.validity_end_date, '%Y-%c-%d' ) >= DATE_FORMAT( NOW( ), '%Y-%c-%d' ) THEN
- td.actual_price ELSE 0
- END
- ) AS pay_amount
- FROM
- trade_order o
- INNER JOIN trade_detail td ON td.order_id = o.id
- LEFT JOIN trade_refund_detail trd ON trd.trade_detail_id = td.id
- AND trd.refund_status = 6
- INNER JOIN trade_order_user tou ON o.id = tou.order_id
- INNER JOIN product_spu ps ON ps.id = td.product_id
- LEFT JOIN trade_invoice_detail i ON i.order_no = o.order_no
- LEFT JOIN trade_invoice ii ON i.invoice_id = ii.id AND ii.invoice_status IN (1,3)
- 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
- LEFT JOIN ota_bill_order obo ON obo.order_id = o.id
- LEFT JOIN ota_bill_store obs ON obs.id = obo.bill_store_id AND obs.bill_status=1
- where td.validity_end_date >= DATE_SUB(NOW(), INTERVAL #{canInvoicedDay} DAY)
- and o.is_invoice in (0,2)
- and o.order_status in (7,8,9,11,12)
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND o.order_no = #{vo.orderNo}
- </if>
- <if test="vo.sourceId != null and vo.sourceId != ''">
- AND o.source_id = #{vo.sourceId}
- </if>
- <if test="vo.storeId != null and vo.storeId != ''">
- AND o.store_id = #{vo.storeId}
- </if>
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- AND tou.credential_no = #{vo.credentialNo}
- </if>
- <if test="vo.mobile != null and vo.mobile != ''">
- AND tou.mobile = #{vo.mobile}
- </if>
- <if test="vo.contactName != null and vo.contactName != ''">
- AND tou.contact_name = #{vo.contactName}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND o.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.sellerId != null and vo.sellerId != ''">
- AND o.seller_id = #{vo.sellerId}
- </if>
- <if test="vo.voucherCode != null and vo.voucherCode != ''">
- AND td.voucher_code = #{vo.voucherCode}
- </if>
- <if test="vo.sellMethod != null and vo.sellMethod != ''">
- AND o.sell_method = #{vo.sellMethod}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.use_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.use_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
- AND o.payment_date <![CDATA[ >= ]]> #{vo.orderDateStart}
- </if>
- <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
- AND o.payment_date <![CDATA[ <= ]]> #{vo.orderDateEnd}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND td.product_name like concat('%',#{vo.productName}, '%')
- </if>
- AND ii.id IS NULL
- AND (op.payment_type != 6 OR (o.is_bill=2 AND obs.id IS NOT NULL))
- AND date_format(NOW(), '%Y-%m-%d') > date_format(o.travel_date, '%Y-%m-%d')
- GROUP BY
- o.order_no
- HAVING
- SUM(CASE WHEN td.voucher_status IN (1,2) AND td.validity_end_date >= CURDATE() THEN 1 ELSE 0 END) = 0
- AND pay_amount > 0
- ORDER BY
- o.travel_date DESC
- </select>
- <select id="getOrderByVoucherCode"
- resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT o.* FROM trade_order o
- inner join trade_detail d on d.order_id = o.id
- where (o.order_status = 6 or o.order_status = 7) and d.voucher_code = #{voucherCode} limit 1
- </select>
- <select id="getOrderByExternalOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- 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
- </select>
- <select id="getOtcOrderByExternalOrderNo" resultType="java.util.Map">
- 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
- </select>
- <select id="getTradeOrderByVoucherCode" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT o.* FROM trade_order o inner join trade_detail d on d.order_id = o.id where d.voucher_code = #{voucherCode} limit 1
- </select>
- <select id="getOrderByCardNo"
- resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT
- o.*
- FROM
- trade_order o
- INNER JOIN trade_detail d ON d.order_id = o.id
- INNER JOIN trade_visitor v ON v.detail_id = d.id
- WHERE
- o.travel_date >= CURDATE()
- and d.voucher_status in (1,2,3,4,8,9)
- and v.credential_no = #{cardNo}
- </select>
- <select id="getOrderByDetailBase"
- resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT o.* FROM trade_order o
- inner join trade_detail d on d.order_id = o.id
- inner join trade_detail_base tdb on tdb.detail_id = d.id
- where (o.order_status = 6 or o.order_status = 7) and tdb.id = #{baseId} limit 1
- </select>
- <select id="getAccountOrderPage"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- SELECT td.*,tou.contact_name,tou.credential_no,tou.mobile,COUNT(tdl.id) num,tdl.product_name,tdl.spec_type
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id
- INNER JOIN trade_detail tdl on td.id = tdl.order_id
- where 1= 1 AND td.order_status NOT IN (-2, -1, 0, 1, 2, 12) AND td.is_account = 0
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </if>
- <if test="vo.contactName != null and vo.contactName != ''">
- AND tou.contact_name = #{vo.contactName}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- GROUP BY td.id
- ORDER BY td.create_time DESC
- </select>
- <update id="updateOrderStatus">
- UPDATE trade_order SET order_status = #{orderStatus} WHERE id = #{orderId} and order_status != #{orderStatus}
- </update>
- <update id="updateOrderIsAccount">
- UPDATE trade_order SET is_account = #{isAccount} WHERE id = #{orderId}
- </update>
- <update id="updateOrderDeleted">
- UPDATE trade_order SET deleted = #{deleted},update_time = now() WHERE id = #{orderId}
- </update>
- <resultMap id="OrderAndDetailResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderPdaRespVO">
- <id property="id" column="id"/>
- <result property="orderNo" column="order_no"/>
- <result property="sourceName" column="source_name"/>
- <result property="externalOrderNo" column="external_order_no"/>
- <result property="routePlanId" column="route_plan_id"/>
- <result property="visitorType" column="visitor_type"/>
- <result property="travelDate" column="travel_date"/>
- <result property="sellMethod" column="sell_method"/>
- <result property="sourceName" column="source_name"/>
- <result property="sellerId" column="seller_id"/>
- <result property="memberId" column="member_id"/>
- <result property="amount" column="amount"/>
- <result property="payAmount" column="pay_amount"/>
- <result property="orderStatus" column="order_status"/>
- <result property="paymentDate" column="payment_date"/>
- <result property="contactName" column="contact_name"/>
- <result property="credentialNo" column="credential_no"/>
- <result property="mobile" column="mobile"/>
- <result property="remark" column="remark"/>
- <collection property="tradeDetailList" resultMap="tradeDetailMap"/>
- </resultMap>
- <resultMap id="tradeDetailMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
- <result property="id" column="detailId"/>
- <result property="orderId" column="order_id"/>
- <result property="voucherCode" column="voucher_code"/>
- <result property="voucherStatus" column="voucher_status"/>
- <result property="useDate" column="use_date"/>
- <result property="validityStartDate" column="validity_start_date"/>
- <result property="validityEndDate" column="validity_end_date"/>
- <result property="usageDays" column="usage_days"/>
- <result property="checkStatus" column="check_status"/>
- <result property="takeStatus" column="take_status"/>
- <result property="refundStatus" column="refund_status"/>
- <result property="verifyTime" column="verify_time"/>
- <result property="activateStatus" column="activate_status"/>
- <result property="activateDays" column="activate_days"/>
- <result property="activateTime" column="activate_time"/>
- <result property="productId" column="product_id"/>
- <result property="productName" column="product_name"/>
- <result property="specType" column="spec_type"/>
- <collection property="detailBaseList" resultMap="tradeDetailBaseResMap"/>
- </resultMap>
- <resultMap id="tradeDetailBaseResMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.DetailBaseRespVO">
- <result property="id" column="detail_base_id"/>
- <result property="detailId" column="detailId"/>
- <result property="productBaseId" column="product_base_id"/>
- <result property="productBaseName" column="product_base_name"/>
- <result property="productBaseType" column="product_base_type"/>
- <result property="productResourceId" column="product_resource_id"/>
- <result property="productResourceName" column="product_resource_name"/>
- <result property="supplierProductId" column="supplier_product_id"/>
- <result property="supplierId" column="supplier_id"/>
- <result property="supplierName" column="supplier_name"/>
- <result property="isSystemDirect" column="is_system_direct"/>
- <result property="useStatus" column="use_status"/>
- <result property="checkStatus" column="base_check_status"/>
- <result property="verifyTime" column="base_verify_time"/>
- <result property="price" column="base_price"/>
- <result property="usageCount" column="usage_count"/>
- <result property="productResourcePrice" column="product_resource_price"/>
- <result property="projectId" column="project_id"/>
- <result property="projectName" column="project_name"/>
- <result property="specificationId" column="specification_id"/>
- <result property="specificationName" column="specification_name"/>
- <result property="specType" column="base_spec_type"/>
- <result property="supplierVoucherCode" column="supplier_voucher_code"/>
- <result property="platSupplierOrderId" column="plat_supplier_order_id"/>
- </resultMap>
- <select id="getOrderAndDetailInfo" resultMap="OrderAndDetailResultMap">
- 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,
- tou.contact_name,tou.credential_no,tou.mobile,
- tdl.id detailId,tdl.voucher_code,tdl.voucher_status,tdl.product_name,tdl.spec_type,tdl.validity_start_date,tdl.validity_end_date,
- 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,
- 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,
- tdb.specification_id,tdb.specification_name,tdb.spec_type base_spec_type,tdb.supplier_voucher_code,tdb.plat_supplier_order_id
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
- INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
- INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
- inner join trade_detail_base tdb on tdl.id = tdb.detail_id
- where 1= 1 and td.order_status >= 6 and td.order_status <![CDATA[ <= ]]> 9
- and td.sell_method != 3 and td.sell_method != 4
- and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
- and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
- <if test="channelId != null and channelId != ''">
- and tdb.product_base_id in (select product_id from product_check_channel where channel_id=#{channelId} and deleted = 0)
- </if>
- <if test="orderNo != null and orderNo != ''">
- AND td.order_no = #{orderNo}
- </if>
- <choose>
- <when test="phone != null and phone.length() == 4">
- AND tou.mobile like concat('%',#{phone})
- </when>
- <when test="phone != null and phone != ''">
- AND tou.mobile = #{phone}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <choose>
- <when test="cardNo != null and cardNo.length() == 4">
- AND tv.credential_no like concat('%',#{cardNo})
- </when>
- <when test="cardNo != null and cardNo != ''">
- AND tv.credential_no = #{cardNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- ORDER BY td.travel_date DESC
- </select>
- <select id="getPlatOrderNo" resultType="java.lang.String">
- select t3.order_no from trade_order t1
- inner join trade_supplier_order t2 on t1.id = t2.order_id
- inner join trade_order t3 on t2.trade_no = t3.external_order_no
- where t1.order_no = #{orderNo}
- </select>
- <select id="getCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- 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,
- 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, tou.contact_name,tou.credential_no,tou.mobile,td.is_add_order
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
- INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
- left join product_route_plan plan on td.route_plan_id = plan.id
- <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
- left join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
- </if>
- <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
- left join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
- </if>
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
- </if>
- where 1=1
- <choose>
- <when test="vo.orderStatus != null">
- AND td.order_status = #{vo.orderStatus}
- </when>
- <otherwise>
- and td.order_status in (6,7,8,9,10,13)
- </otherwise>
- </choose>
- <choose>
- <when test="vo.travelDate != null and vo.travelDate != ''">
- AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
- AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
- </when>
- <otherwise>
- and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
- and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
- </otherwise>
- </choose>
- <choose>
- <when test="vo.orderNo != null and vo.orderNo.length() == 4">
- AND td.order_no like concat('%',#{vo.orderNo})
- </when>
- <when test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <choose>
- <when test="vo.phone != null and vo.phone.length() == 4">
- AND tou.mobile like concat('%',#{vo.phone})
- </when>
- <when test="vo.phone != null and vo.phone != ''">
- AND tou.mobile = #{vo.phone}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <choose>
- <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
- AND tv.credential_no like concat('%',#{vo.credentialNo})
- </when>
- <when test="vo.credentialNo != null and vo.credentialNo != ''">
- AND tv.credential_no = #{vo.credentialNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
- AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
- WHERE plan_id = #{vo.dispatchId} and deleted = 0)
- </if>
- <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
- AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
- WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
- </if>
- <if test="vo.travelStatus != null">
- AND td.travel_status = #{vo.travelStatus}
- </if>
- <if test="vo.voucherCode != null and vo.voucherCode != ''">
- AND tdl.voucher_code = #{vo.voucherCode}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.sellMethod != null">
- AND td.sell_method = #{vo.sellMethod}
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
- AND (td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- or tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- )
- </if>
- <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
- AND tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
- and td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- group by td.id
- ORDER BY td.create_time DESC
- </select>
- <select id="countCheckOrder" resultType="java.lang.Integer">
- SELECT count(DISTINCT td.id) num FROM trade_order td
- INNER JOIN trade_detail tdl ON td.id = tdl.order_id
- INNER JOIN trade_order_user tou ON td.id = tou.order_id
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
- </if>
- where 1=1
- <choose>
- <when test="vo.orderStatus != null">
- AND td.order_status = #{vo.orderStatus}
- </when>
- <otherwise>
- and td.order_status in (6,7,8,9,10,13)
- </otherwise>
- </choose>
- <choose>
- <when test="vo.travelDate != null and vo.travelDate != ''">
- AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
- AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
- </when>
- <otherwise>
- and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
- and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
- </otherwise>
- </choose>
- <choose>
- <when test="vo.orderNo != null and vo.orderNo.length() == 4">
- AND td.order_no like concat('%',#{vo.orderNo})
- </when>
- <when test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <choose>
- <when test="vo.phone != null and vo.phone.length() == 4">
- AND tou.mobile like concat('%',#{vo.phone})
- </when>
- <when test="vo.phone != null and vo.phone != ''">
- AND tou.mobile = #{vo.phone}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <choose>
- <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
- AND tv.credential_no like concat('%',#{vo.credentialNo})
- </when>
- <when test="vo.credentialNo != null and vo.credentialNo != ''">
- AND tv.credential_no = #{vo.credentialNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
- AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
- WHERE plan_id = #{vo.dispatchId} and deleted = 0)
- </if>
- <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
- AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
- WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
- </if>
- <if test="vo.travelStatus != null">
- AND td.travel_status = #{vo.travelStatus}
- </if>
- <if test="vo.voucherCode != null and vo.voucherCode != ''">
- AND tdl.voucher_code = #{vo.voucherCode}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.sellMethod != null">
- AND td.sell_method = #{vo.sellMethod}
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
- AND (td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- or tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- )
- </if>
- <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
- AND tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
- and td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- </select>
- <select id="selectStoreMachineProductList"
- resultType="java.lang.Long">
- SELECT t1.product_id FROM otc_agency_store_machine_product t1
- where 1=1
- <if test="vo.storeId != null and vo.storeId != ''">
- AND t1.store_id = #{vo.storeId}
- </if>
- <if test="vo.machineId != null and vo.machineId != ''">
- AND t1.machine_id = #{vo.machineId}
- </if>
- </select>
- <select id="orderListByOta" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT
- t1.*
- FROM
- trade_order t1
- inner join trade_detail t3 on t1.id = t3.order_id
- inner join trade_visitor t4 on t3.id = t4.detail_id
- INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
- WHERE
- t1.sell_method = 0
- AND t1.order_status in (6,7,8,9,10,13)
- AND t1.tenant_id = #{tenantId}
- AND t1.travel_date = #{travelDate}
- <if test="credentialNo != null and credentialNo != ''">
- AND t4.credential_no = #{credentialNo}
- </if>
- <if test="mobile != null and mobile != ''">
- AND t2.mobile = #{mobile}
- </if>
- ORDER BY
- t1.payment_date DESC
- </select>
- <select id="orderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT
- t1.*
- FROM
- trade_order t1
- INNER JOIN trade_order_user t2 ON t2.order_id = t1.id
- INNER JOIN trade_detail td on t1.id = td.order_id
- INNER JOIN trade_visitor v on v.detail_id = td.id
- WHERE
- 1 = 1
- <if test="orderStatus!=null and orderStatus.size()>0">
- AND t1.order_status in
- <foreach collection="orderStatus" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- AND t1.tenant_id = #{tenantId}
- AND t1.travel_date = #{travelDate}
- <if test="credentialNo != null and credentialNo != ''">
- AND v.credential_no = #{credentialNo}
- </if>
- <if test="mobile != null and mobile != ''">
- AND t2.mobile = #{mobile}
- </if>
- group by t1.id
- ORDER BY
- t1.payment_date DESC
- </select>
- <select id="queryOneByOrderNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT DISTINCT o2.*
- FROM trade_order o
- INNER JOIN trade_detail d on d.order_id = o.id
- INNER JOIN trade_detail_base db ON db.detail_id = d.id
- INNER JOIN trade_detail d2 ON db.supplier_voucher_code = d2.voucher_code
- INNER JOIN trade_order o2 ON d2.order_id = o2.id
- WHERE o.order_no = #{orderNo}
- union all
- SELECT o.* FROM trade_order o WHERE o.sell_method in (0,1,4,6,7) and o.order_no = #{orderNo}
- </select>
- <select id="updateAppletProductSellNum">
- update applet_product t1 inner JOIN applet_product_group t2 ON t1.id = t2.applet_product_id
- and t2.deleted =0
- set t1.sell_num = t1.sell_num+#{sellNum} where t2.product_id = #{productId}
- </select>
- <select id="selectCanBindOrderList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT o.id,o.is_bind
- FROM trade_order o
- INNER JOIN trade_detail d ON d.order_id = o.id
- INNER JOIN trade_order_user u on o.id = u.order_id
- WHERE
- o.order_status > 5 AND o.deleted = 0
- AND (o.is_bind IS NULL or o.is_bind = 0 ) and o.id != #{vo.orderId}
- AND o.travel_date = #{vo.travelDate}
- AND d.product_id = #{vo.productId}
- <if test="vo.routePlanId !=null">
- And o.route_plan_id = #{vo.routePlanId}
- </if>
- AND u.mobile = #{vo.mobile}
- GROUP BY o.id
- </select>
- <update id="deleteOrderById">
- delete from trade_order where id = #{orderId}
- </update>
- <update id="deleteOrderByOrderNo">
- update from trade_order where order_no = #{orderNo}
- </update>
- <select id="getInvoiceOrderCount" resultType="java.lang.Integer">
- select count(1) num from trade_invoice t1 inner join trade_invoice_detail t2 on t1.id = t2.invoice_id
- and t1.invoice_status in (1,3)
- where t2.order_no = #{orderNo} and t1.deleted = 0
- </select>
- <select id="selectPlatPayAmountByOriginOrderNo" resultType="java.util.Map">
- select sum(tod.pay_amount) totalPayAmount
- from trade_order tod
- where tod.external_origin_order_no =#{originOrderNo} and tod.order_status>=6
- </select>
- <select id="selectChangeCountByOrderId" resultType="java.lang.Integer">
- select count(*) totalCount
- from trade_order tod
- inner join trade_order_bind tb on tod.id = tb.order_id and tb.type = 2 and tb.deleted =0
- inner join trade_order tod1 on tod1.id = tb.bind_id
- where tod.id = #{orderId} and tod1.order_status>=6
- </select>
- <update id="updateOrderFinishStatus">
- update trade_order tod,
- (select tod.id
- from trade_order tod
- inner join trade_detail td on tod.id = td.order_id
- where tod.sell_method in
- <foreach collection="sellMethodList" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- and tod.order_status >=6
- and td.validity_end_date = #{endDate}
- and not EXISTS (
- select 1
- from trade_detail td1
- where td1.validity_end_date > #{endDate} and td1.order_id = tod.id and td1.refund_status != 1
- )
- ) t
- set tod.finish_status = 1
- where tod.id = t.id
- </update>
- <select id="getSupplierCheckOrder" resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderRespVO">
- 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,
- 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, tou.contact_name,tou.credential_no,tou.mobile
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id and td.deleted = 0
- INNER JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
- INNER JOIN trade_detail_base tdb on tdb.detail_id = tdl.id
- left join product_route_plan plan on td.route_plan_id = plan.id
- <if test="vo.type != null and vo.dispatchId == null and vo.type == 'boat'">
- inner join dispatch_operate_plan_boat_order_detail_base dopbodb on td.id = dopbodb.order_id and dopbodb.deleted = 0
- </if>
- <if test="vo.type != null and vo.dispatchId == null and vo.type == 'car'">
- inner join dispatch_car_dispatch_order_detail_base dcdodb on td.id = dcdodb.order_id and dcdodb.deleted = 0
- </if>
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- INNER JOIN trade_visitor tv on tv.detail_id = tdl.id and tv.deleted = 0
- </if>
- where supplier_id in (
- select t2.id from product_supplier_user t1 inner join product_supplier t2 on t1.supplier_id = t2.id
- where t1.user_id=#{vo.userId} and t1.deleted =0
- )
- <choose>
- <when test="vo.orderStatus != null">
- AND td.order_status = #{vo.orderStatus}
- </when>
- <otherwise>
- and td.order_status in (6,7,8,9,10,13)
- </otherwise>
- </choose>
- <choose>
- <when test="vo.travelDate != null and vo.travelDate != ''">
- AND DATE_FORMAT(tdl.validity_start_date, '%Y-%m-%d') <![CDATA[ <= ]]> #{vo.travelDate}
- AND DATE_FORMAT(tdl.validity_end_date, '%Y-%m-%d') <![CDATA[ >= ]]> #{vo.travelDate}
- </when>
- <otherwise>
- and tdl.validity_start_date <![CDATA[ <= ]]> NOW()
- and tdl.validity_end_date <![CDATA[ >= ]]> NOW()
- </otherwise>
- </choose>
- <choose>
- <when test="vo.orderNo != null and vo.orderNo.length() == 4">
- AND td.order_no like concat('%',#{vo.orderNo})
- </when>
- <when test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <choose>
- <when test="vo.phone != null and vo.phone.length() == 4">
- AND tou.mobile like concat('%',#{vo.phone})
- </when>
- <when test="vo.phone != null and vo.phone != ''">
- AND tou.mobile = #{vo.phone}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <choose>
- <when test="vo.credentialNo != null and vo.credentialNo.length() == 4">
- AND tv.credential_no like concat('%',#{vo.credentialNo})
- </when>
- <when test="vo.credentialNo != null and vo.credentialNo != ''">
- AND tv.credential_no = #{vo.credentialNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.type != null and vo.dispatchId != null and vo.type == 'boat'">
- AND td.id in (SELECT DISTINCT order_id FROM dispatch_operate_plan_boat_order_detail_base
- WHERE plan_id = #{vo.dispatchId} and deleted = 0)
- </if>
- <if test="vo.type != null and vo.dispatchId != null and vo.type == 'car'">
- AND td.id in (SELECT DISTINCT order_id FROM dispatch_car_dispatch_order_detail_base
- WHERE car_dispatch_id = #{vo.dispatchId} and deleted = 0)
- </if>
- <if test="vo.voucherCode != null and vo.voucherCode != ''">
- AND tdl.voucher_code = #{vo.voucherCode}
- </if>
- <if test="vo.checkType != null and vo.checkType == 1">
- AND tdb.use_status in (1,2)
- </if>
- <if test="vo.checkType != null and vo.checkType == 2">
- AND tdb.use_status in (3,6,8)
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.sellMethod != null">
- AND td.sell_method = #{vo.sellMethod}
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and vo.cateIds!=null and vo.cateIds.size()>0">
- AND (td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- or tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- )
- </if>
- <if test="vo.cateIds!=null and vo.cateIds.size()>0 and vo.planIds==null">
- AND tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.planIds!=null and vo.planIds.size()>0 and (vo.cateIds==null or vo.cateIds.size()==0)">
- and td.route_plan_id in
- <foreach collection="vo.planIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- group by td.id
- ORDER BY td.create_time DESC
- </select>
- <select id="getOtaTradeOrderPage"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
- SELECT td.*,tor.order_no,pbr.check_start_date,pbr.check_end_date
- FROM trade_detail td
- LEFT JOIN product_basic_rule pbr on td.product_id = pbr.id
- LEFT JOIN trade_order tor on tor.id = td.order_id
- where 1= 1 AND
- EXISTS (select * from product_sale_channel sc where sc.product_id = td.product_id and sc.channel_id = 0)
- <if test="vo.productName != null and vo.productName != ''">
- AND td.product_name = #{vo.productName}
- </if>
- <if test="vo.orderNo != null and vo.orderNo != ''">
- AND tor.order_no = #{vo.orderNo}
- </if>
- <if test="vo.orderStatus != null and vo.orderStatus != ''">
- AND tor.order_status = #{vo.orderStatus}
- </if>
- <if test="vo.paymentDateStart != null">
- AND tor.payment_date <![CDATA[ >= ]]> #{vo.paymentDateStart}
- </if>
- <if test="vo.paymentDateEnd != null">
- AND tor.payment_date <![CDATA[ <= ]]> #{vo.paymentDateEnd}
- </if>
- <if test="vo.type == 1">
- AND tor.source_id = #{distributorId}
- </if>
- GROUP BY td.voucher_code
- ORDER BY td.create_time DESC
- </select>
- <select id="regionStatic" resultType="java.util.Map">
- 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
- inner join trade_visitor t3 on t2.id = t3.detail_id
- inner join ota_distributor t4 on t1.source_id = t4.id
- inner join ota_distributor_region t5 on t4.id = t5.distributor_id
- and (left(t3.credential_no,2) = t5.distributor_region_id or left(t3.credential_no,4) = t5.distributor_region_id)
- inner join ota_region t6 on ((t5.distributor_region_id = province_code and LEVEL=1) or t5.distributor_region_id = left(t6.id,4) )
- where t2.voucher_status in (1,2,3,4,6,8,9)
- <if test="vo.startDate != null and vo.startDate!=''">
- AND t2.use_date <![CDATA[ >= ]]> #{vo.startDate}
- </if>
- <if test="vo.endDate != null and vo.endDate!=''">
- AND t2.use_date <![CDATA[ <= ]]> #{vo.endDate}
- </if>
- GROUP BY t4.id
- order by num desc
- </select>
- <select id="queryOrderByLast" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT * FROM trade_order WHERE order_no = #{orderNo} and deleted = 1 ORDER BY update_time DESC limit 1
- </select>
- <select id="queryOrderById" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO">
- SELECT * FROM trade_order WHERE id = #{orderId} ORDER BY update_time DESC limit 1
- </select>
- <select id="selectConfirmationCountry"
- resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderConfirmationCountryRespVO">
- select t1.actual_price,
- t2.room_model_id,
- t3.short_name room_model_short_name,
- t3.name room_model_name,t2.type,
- ifnull(t2.nationality,1) nationality,
- t2.floor,ifnull(t4.name, '中国') nationality_name,
- count(t1.id) num
- from trade_detail t1
- LEFT JOIN trade_visitor t2 on t1.visitor_id = t2.id
- LEFT JOIN resource_room_model t3 on t2.room_model_id = t3.id
- LEFT JOIN area t4 on t2.nationality = t4.id
- where t1.order_id = #{orderId} and t1.product_type = 0 and t1.deleted = 0 and t2.deleted = 0 and t3.deleted = 0
- GROUP BY t2.room_model_id, t2.floor, t2.type
- ORDER BY floor desc
- </select>
- <select id="getOrderCount" resultType="java.util.Map">
- select GROUP_CONCAT(num,'*',name) name,sum(num1) num1,sum(num2) num2,sum(num3) num3,sum(num4) num4 from (
- SELECT sum(CASE WHEN tv.type='adultPlus' or tv.type='adultTake' THEN 1 ELSE 0 END) num1,
- 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,
- sum(CASE WHEN tv.type='with' THEN 1 ELSE 0 END) num3,
- sum(CASE WHEN tv.type='leader' THEN 1 ELSE 0 END) num4,
- CONCAT(rrm.short_name,'(',tv.floor,'F)') name ,count(1) num
- FROM trade_order td
- INNER JOIN trade_order_user tou on td.id = tou.order_id
- left JOIN trade_detail tdl on td.id = tdl.order_id and tdl.deleted = 0
- left join trade_visitor tv on tdl.id = tv.detail_id
- left JOIN product_spu ps on ps.id = tdl.product_id
- LEFT JOIN ota_distributor od on od.id = td.source_id
- left join trade_order_room_model tm on tv.room_index_id = tm.room_index_id and tm.deleted =0
- left join resource_room_model rrm on tm.room_model_id = rrm.id
- 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
- where td.deleted = 0 and tou.deleted = 0 and td.order_status >0 and tv.type is not null
- <if test="vo.orderStatus!=null and vo.orderStatus.size()>0">
- and td.order_status in
- <foreach collection="vo.orderStatus" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.tenantId!=null">
- AND td.tenant_id = #{vo.tenantId}
- </if>
- <choose>
- <when test="vo.orderNo != null and vo.orderNo.length() == 4">
- AND td.order_no like concat('%',#{vo.orderNo})
- </when>
- <when test="vo.orderNo != null and vo.orderNo != ''">
- AND td.order_no = #{vo.orderNo}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.externalOriginOrderNo != null and vo.externalOriginOrderNo != ''">
- AND td.external_origin_order_no = #{vo.externalOriginOrderNo}
- </if>
- <if test="vo.memberId != null and vo.memberId != ''">
- AND td.member_id = #{vo.memberId}
- </if>
- <if test="vo.voyageId != null and vo.voyageId != ''">
- AND td.voyage_id = #{vo.voyageId}
- </if>
- <if test="vo.shipId != null and vo.shipId != ''">
- AND td.ship_id = #{vo.shipId}
- </if>
- <if test="vo.routeId != null and vo.routeId != ''">
- AND exists (select 1 from product_voyage top where top.id = td.voyage_id and top.route_id = #{vo.routeId})
- </if>
- <if test="vo.dispatchStatus != null">
- AND td.dispatch_status = #{vo.dispatchStatus}
- </if>
- <if test="vo.payType != null">
- AND exists (select 1 from trade_order_pay top where top.order_id = td.id and top.payment_type = #{vo.payType})
- </if>
- <if test="vo.otaCateId != null and vo.otaCateId != ''">
- AND od.ota_category_id = #{vo.otaCateId}
- </if>
- <if test="vo.otaCateIds!=null and vo.otaCateIds.size()>0">
- and od.ota_category_id in
- <foreach collection="vo.otaCateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.otaId != null and vo.otaId != ''">
- AND td.source_id = #{vo.otaId}
- </if>
- <if test="vo.storeId != null and vo.storeId != ''">
- AND td.store_id = #{vo.storeId}
- </if>
- <if test="vo.productTag != null and vo.productTag != ''">
- AND ps.product_tag = #{vo.productTag}
- </if>
- <if test="vo.productTag2 != null and vo.productTag2 != ''">
- AND ps.product_tag2 = #{vo.productTag2}
- </if>
- <if test="vo.productTag3 != null and vo.productTag3 != ''">
- AND ps.product_tag3 = #{vo.productTag3}
- </if>
- <if test="vo.productTag4 != null and vo.productTag4 != ''">
- AND ps.product_tag4 = #{vo.productTag4}
- </if>
- <if test="vo.cateIds!=null and vo.cateIds.size()>0 and (vo.planIds==null or vo.planIds.size()==0)">
- AND tdl.product_id in
- <foreach collection="vo.cateIds" item="item" separator="," open="(" close=")">
- #{item}
- </foreach>
- </if>
- <if test="vo.externalOrderNo != null and vo.externalOrderNo != ''">
- AND td.external_order_no = #{vo.externalOrderNo}
- </if>
- <if test="vo.credentialNo != null and vo.credentialNo != ''">
- AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.credential_no = #{vo.credentialNo})
- </if>
- <if test="vo.userName != null and vo.userName != ''">
- AND exists (select tv.id from trade_visitor tv where tv.detail_id = tdl.id and tv.name = #{vo.userName})
- </if>
- <choose>
- <when test="vo.mobile != null and vo.mobile.length() == 4">
- AND tou.mobile like concat('%',#{vo.mobile})
- </when>
- <when test="vo.mobile != null and vo.mobile != ''">
- AND tou.mobile = #{vo.mobile}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- <if test="vo.contactName != null and vo.contactName != ''">
- AND tou.contact_name = #{vo.contactName}
- </if>
- <if test="vo.travelDate != null and vo.travelDate != ''">
- AND td.travel_date = #{vo.travelDate}
- </if>
- <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
- AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
- </if>
- <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
- AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
- </if>
- <if test="vo.orderDateStart != null and vo.orderDateStart != ''">
- AND td.create_time <![CDATA[ >= ]]> #{vo.orderDateStart}
- </if>
- <if test="vo.orderDateEnd != null and vo.orderDateEnd != ''">
- AND td.create_time <![CDATA[ <= ]]> #{vo.orderDateEnd}
- </if>
- <if test="vo.orderDate != null and vo.orderDate != ''">
- AND td.create_time = #{vo.orderDate}
- </if>
- <if test="vo.sellerId != null and vo.sellerId != ''">
- AND td.seller_id = #{vo.sellerId}
- </if>
- <if test="vo.shareName != null and vo.shareName != ''">
- AND td.share_name like concat('%',#{vo.shareName},'%')
- </if>
- <if test="vo.voucherCode != null and vo.voucherCode != ''">
- AND tdl.voucher_code = #{vo.voucherCode}
- </if>
- <if test="vo.sellMethod != null and vo.sellMethod != ''">
- AND td.sell_method = #{vo.sellMethod}
- </if>
- <if test="vo.productName != null and vo.productName != ''">
- AND tdl.product_name like concat('%',#{vo.productName}, '%')
- </if>
- <if test="vo.isFullPay == 0">
- AND td.is_full_pay = #{vo.isFullPay}
- </if>
- <if test="vo.isComment != null">
- AND td.is_comment = #{vo.isComment}
- </if>
- <if test="vo.sourceId != null and vo.sourceId != ''">
- AND td.source_id = #{vo.sourceId}
- </if>
- <if test="vo.distributorId != null and vo.distributorId != ''">
- AND td.source_id = #{vo.distributorId}
- </if>
- <if test="vo.sourceName != null and vo.sourceName != ''">
- AND td.source_name like concat('%',#{vo.sourceName}, '%')
- </if>
- <if test="vo.travelStatus != null">
- AND td.travel_status = #{vo.travelStatus}
- </if>
- <if test="vo.orderRefundDateStart != null and vo.orderRefundDateEnd != ''">
- 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} )
- </if>
- GROUP BY rrm.short_name,tv.floor
- ) p
- </select>
- </mapper>
|