TradeDetailMapper.xml 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.yc.ship.module.trade.dal.mysql.order.TradeDetailMapper">
  4. <resultMap id="tradeDetailMap" type="com.yc.ship.module.trade.service.order.bo.TradeDetailBO">
  5. <result property="id" column="id"/>
  6. <result property="orderId" column="order_id"/>
  7. <result property="hotelOrderId" column="hotel_order_id"/>
  8. <result property="routePlanId" column="route_plan_id"/>
  9. <result property="faceimg" column="faceimg"/>
  10. <result property="voucherCode" column="voucher_code"/>
  11. <result property="voucherStatus" column="voucher_status"/>
  12. <result property="useDate" column="use_date"/>
  13. <result property="validityStartDate" column="validity_start_date"/>
  14. <result property="validityEndDate" column="validity_end_date"/>
  15. <result property="usageDays" column="usage_days"/>
  16. <result property="checkStatus" column="check_status"/>
  17. <result property="takeStatus" column="take_status"/>
  18. <result property="refundStatus" column="refund_status"/>
  19. <result property="verifyTime" column="verify_time"/>
  20. <result property="activateStatus" column="activate_status"/>
  21. <result property="activateDays" column="activate_days"/>
  22. <result property="activateTime" column="activate_time"/>
  23. <result property="productId" column="product_id"/>
  24. <result property="productName" column="product_name"/>
  25. <result property="specType" column="spec_type"/>
  26. <result property="price" column="price"/>
  27. <result property="actualPrice" column="actual_price"/>
  28. <result property="quantityOfOne" column="quantity_of_one"/>
  29. <result property="useRealName" column="use_real_name"/>
  30. <result property="productType" column="product_type"/>
  31. <result property="cateType" column="cate_type"/>
  32. <collection property="tradeDetailBaseList" ofType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailBaseDO" javaType="java.util.List">
  33. <result property="id" column="detail_base_id"/>
  34. <result property="detailId" column="detail_id"/>
  35. <result property="productBaseId" column="product_base_id"/>
  36. <result property="productBaseName" column="product_base_name"/>
  37. <result property="productBaseType" column="product_base_type"/>
  38. <result property="productResourceId" column="product_resource_id"/>
  39. <result property="productResourceName" column="product_resource_name"/>
  40. <result property="supplierProductId" column="supplier_product_id"/>
  41. <result property="supplierId" column="supplier_id"/>
  42. <result property="supplierName" column="supplier_name"/>
  43. <result property="isSystemDirect" column="is_system_direct"/>
  44. <result property="useStatus" column="use_status"/>
  45. <result property="checkStatus" column="base_check_status"/>
  46. <result property="verifyTime" column="base_verify_time"/>
  47. <result property="price" column="base_price"/>
  48. <result property="usageCount" column="usage_count"/>
  49. <result property="productResourcePrice" column="product_resource_price"/>
  50. <result property="projectId" column="project_id"/>
  51. <result property="projectName" column="project_name"/>
  52. <result property="projectCode" column="project_code"/>
  53. <result property="specificationId" column="specification_id"/>
  54. <result property="specificationName" column="specification_name"/>
  55. <result property="specType" column="base_spec_type"/>
  56. <result property="supplierVoucherCode" column="supplier_voucher_code"/>
  57. <result property="platSupplierOrderId" column="plat_supplier_order_id"/>
  58. </collection>
  59. </resultMap>
  60. <select id="selectTradeDetailWithBase" resultMap="tradeDetailMap">
  61. select td.*,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,
  62. 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,
  63. tdb.specification_id,tdb.specification_name,tdb.spec_type base_spec_type,tdb.supplier_voucher_code,tdb.plat_supplier_order_id,tdb.project_code
  64. from trade_detail td
  65. left join trade_detail_base tdb on td.id = tdb.detail_id
  66. <where>
  67. td.order_id = #{orderId}
  68. <if test="tradeDetailId!=null">
  69. and td.id = #{tradeDetailId}
  70. </if>
  71. <if test="voucherList!=null">
  72. and td.voucher_code in
  73. <foreach collection="voucherList" item="item" separator="," open="(" close=")">
  74. #{item}
  75. </foreach>
  76. </if>
  77. <if test="detailIdList!=null">
  78. and td.id in
  79. <foreach collection="detailIdList" item="item" separator="," open="(" close=")">
  80. #{item}
  81. </foreach>
  82. </if>
  83. </where>
  84. </select>
  85. <update id="updateRefundingBatch">
  86. <foreach collection="tradeDetailList" item="item" separator=";" close=";">
  87. UPDATE trade_detail SET voucher_status = #{refundStatus}
  88. WHERE id = #{item.id} AND voucher_status = #{item.voucherStatus}
  89. </foreach>
  90. </update>
  91. <update id="updateStatusAfterAllCheck">
  92. UPDATE trade_detail d LEFT JOIN ( SELECT detail_id FROM trade_detail_base WHERE use_status != 3 and order_id = #{orderId} GROUP BY detail_id ) b ON d.id = b.detail_id
  93. SET d.voucher_status = 3 WHERE d.order_id = #{orderId} and d.voucher_status in (1,2,8) and b.detail_id is null and d.voucher_status != 3
  94. </update>
  95. <update id="updateVoucherStatus">
  96. UPDATE trade_detail SET voucher_status = #{voucherStatus} WHERE id = #{tradeDetailId}
  97. </update>
  98. <select id="queryDetailCountByOrderId" resultType="java.util.Map">
  99. select count(*) as allCount,
  100. SUM(t.price) as allAmount,
  101. SUM(CASE WHEN t.voucher_status = '3' THEN 1 ELSE 0 END) AS checkCount,
  102. SUM(CASE WHEN t.voucher_status = '8' THEN 1 ELSE 0 END) AS partCount,
  103. SUM(CASE WHEN t.voucher_status = '1' THEN 1 ELSE 0 END) AS payCount,
  104. SUM(CASE WHEN t.voucher_status = '2' THEN 1 ELSE 0 END) AS takeCount,
  105. SUM(CASE WHEN t.voucher_status in ('4','5') THEN 1 ELSE 0 END) AS refundCount,
  106. SUM(CASE WHEN t.voucher_status in ('4','5') THEN t.price ELSE 0 END) as refundAmount,
  107. SUM(CASE WHEN t.voucher_status <![CDATA[ <> '5' ]]> AND t.voucher_status <![CDATA[ <> '4' ]]> AND t.voucher_status > 0 THEN 1 ELSE 0 END) AS realityNum,
  108. SUM(CASE WHEN t.voucher_status <![CDATA[ <> '5' ]]> AND t.voucher_status <![CDATA[ <> '4' ]]> AND t.voucher_status > 0 THEN t.price ELSE 0 END) as realityAmount,
  109. SUM(CASE WHEN t.voucher_status in ('6','7') THEN 1 ELSE 0 END) AS outTimeCount
  110. from trade_detail t
  111. where t.order_id = #{orderId}
  112. </select>
  113. <resultMap id="MiddleWareDtoResultMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  114. <id property="id" column="id"/>
  115. <result property="orderId" column="order_id"/>
  116. <result property="orderNo" column="order_no"/>
  117. <result property="voucherCode" column="voucher_code"/>
  118. <result property="voucherStatus" column="voucher_status"/>
  119. <result property="useDate" column="use_date"/>
  120. <result property="validityStartDate" column="validity_start_date"/>
  121. <result property="validityEndDate" column="validity_end_date"/>
  122. <result property="usageDays" column="usage_days"/>
  123. <result property="checkStatus" column="check_status"/>
  124. <result property="takeStatus" column="take_status"/>
  125. <result property="refundStatus" column="refund_status"/>
  126. <result property="verifyTime" column="verify_time"/>
  127. <result property="activateStatus" column="activate_status"/>
  128. <result property="activateDays" column="activate_days"/>
  129. <result property="activateTime" column="activate_time"/>
  130. <result property="productId" column="product_id"/>
  131. <result property="productType" column="product_type"/>
  132. <result property="productTag" column="product_tag"/>
  133. <result property="productTag2" column="product_tag2"/>
  134. <result property="suppSpecType" column="supp_spec_type"/>
  135. <result property="productName" column="product_name"/>
  136. <result property="productCategoryName" column="full_path_name"/>
  137. <result property="specType" column="spec_type"/>
  138. <result property="price" column="price"/>
  139. <result property="visitorId" column="visitorId"/>
  140. <result property="actualPrice" column="actual_price"/>
  141. <result property="quantityOfOne" column="quantity_of_one"/>
  142. <result property="useRealName" column="use_real_name"/>
  143. <result property="cateType" column="cate_type"/>
  144. <result property="hotelOrderId" column="hotel_order_id"/>
  145. <result property="routePlanId" column="route_plan_id"/>
  146. <result property="packProductId" column="pack_product_id"/>
  147. <result property="packProductName" column="pack_product_name"/>
  148. <result property="routePlanId" column="route_plan_id"/>
  149. <result property="routePlanGroupType" column="route_plan_group_type"/>
  150. <result property="createTime" column="create_time"/>
  151. <collection property="visitors" resultMap="visitorResultMap"/>
  152. </resultMap>
  153. <resultMap id="MiddleWareDtoResultMap2" type="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  154. <id property="id" column="id"/>
  155. <result property="orderId" column="order_id"/>
  156. <result property="orderNo" column="order_no"/>
  157. <result property="voucherCode" column="voucher_code"/>
  158. <result property="voucherStatus" column="voucher_status"/>
  159. <result property="useDate" column="use_date"/>
  160. <result property="validityStartDate" column="validity_start_date"/>
  161. <result property="validityEndDate" column="validity_end_date"/>
  162. <result property="usageDays" column="usage_days"/>
  163. <result property="checkStatus" column="check_status"/>
  164. <result property="takeStatus" column="take_status"/>
  165. <result property="refundStatus" column="refund_status"/>
  166. <result property="verifyTime" column="verify_time"/>
  167. <result property="activateStatus" column="activate_status"/>
  168. <result property="activateDays" column="activate_days"/>
  169. <result property="activateTime" column="activate_time"/>
  170. <result property="productId" column="product_id"/>
  171. <result property="productType" column="product_type"/>
  172. <result property="productTag" column="product_tag"/>
  173. <result property="productTag2" column="product_tag2"/>
  174. <result property="suppSpecType" column="supp_spec_type"/>
  175. <result property="productName" column="product_name"/>
  176. <result property="productCategoryName" column="full_path_name"/>
  177. <result property="specType" column="spec_type"/>
  178. <result property="price" column="price"/>
  179. <result property="visitorId" column="visitorId"/>
  180. <result property="actualPrice" column="actual_price"/>
  181. <result property="quantityOfOne" column="quantity_of_one"/>
  182. <result property="useRealName" column="use_real_name"/>
  183. <result property="cateType" column="cate_type"/>
  184. <result property="hotelOrderId" column="hotel_order_id"/>
  185. <result property="routePlanId" column="route_plan_id"/>
  186. <result property="packProductId" column="pack_product_id"/>
  187. <result property="packProductName" column="pack_product_name"/>
  188. <result property="routePlanId" column="route_plan_id"/>
  189. <result property="routePlanGroupType" column="route_plan_group_type"/>
  190. <collection property="visitors" resultMap="visitorResultMap"/>
  191. </resultMap>
  192. <resultMap id="visitorResultMap" type="com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO">
  193. <id property="id" column="visitorId"/>
  194. <result property="detailId" column="detail_id"/>
  195. <result property="name" column="name"/>
  196. <result property="gender" column="gender"/>
  197. <result property="credentialNo" column="credential_no"/>
  198. <result property="credentialType" column="credential_type"/>
  199. <result property="mobile" column="mobile"/>
  200. <result property="otaDetailId" column="ota_detail_id"/>
  201. <result property="isInsure" column="is_insure"/>
  202. <result property="age" column="age"/>
  203. <result property="birthday" column="birthday"/>
  204. <result property="cohabitation" column="cohabitation"/>
  205. <result property="type" column="type"/>
  206. <result property="roomId" column="room_id"/>
  207. <result property="remark" column="remark"/>
  208. <result property="initRoomId" column="init_room_id"/>
  209. <result property="finalRoomId" column="final_room_id"/>
  210. <result property="inDate" column="in_date"/>
  211. <result property="outDate" column="out_date"/>
  212. <result property="nationality" column="nationality"/>
  213. </resultMap>
  214. <resultMap id="tradeDetailBaseResMap" type="com.yc.ship.module.trade.controller.admin.order.vo.order.DetailBaseRespVO">
  215. <result property="id" column="id"/>
  216. <result property="detailId" column="detail_id"/>
  217. <result property="productBaseId" column="product_base_id"/>
  218. <result property="productBaseName" column="product_base_name"/>
  219. <result property="productBaseType" column="product_base_type"/>
  220. <result property="productResourceId" column="product_resource_id"/>
  221. <result property="productResourceName" column="product_resource_name"/>
  222. <result property="supplierProductId" column="supplier_product_id"/>
  223. <result property="supplierId" column="supplier_id"/>
  224. <result property="supplierName" column="supplier_name"/>
  225. <result property="isSystemDirect" column="is_system_direct"/>
  226. <result property="useStatus" column="use_status"/>
  227. <result property="checkStatus" column="check_status"/>
  228. <result property="verifyTime" column="verify_time"/>
  229. <result property="price" column="price"/>
  230. <result property="usageCount" column="usage_count"/>
  231. <result property="productResourcePrice" column="product_resource_price"/>
  232. <result property="projectId" column="project_id"/>
  233. <result property="projectCode" column="project_code"/>
  234. <result property="projectName" column="project_name"/>
  235. <result property="specificationId" column="specification_id"/>
  236. <result property="specificationName" column="specification_name"/>
  237. <result property="specType" column="spec_type"/>
  238. <result property="supplierVoucherCode" column="supplier_voucher_code"/>
  239. <result property="platSupplierOrderId" column="plat_supplier_order_id"/>
  240. <result property="platSupplierOrderNo" column="plat_supplier_order_no"/>
  241. <result property="useDate" column="use_date"/>
  242. <result property="planStartTime" column="plan_start_time"/>
  243. </resultMap>
  244. <select id="getOrderIdDetail" resultMap="MiddleWareDtoResultMap">
  245. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,tv.age,tv.birthday,tv.nationality,tv.cohabitation,tv.room_id,tv.in_date,tv.out_date,tv.remark,tv.init_room_id,tv.final_room_id,tv.type,
  246. tv.credential_type, tv.mobile,tv.ota_detail_id,tv.is_insure,pc.full_path_name,p.product_tag,p.product_tag2
  247. FROM trade_detail td
  248. left join product_spu p on p.id = td.product_id
  249. left join product_category pc on pc.id = p.category_id
  250. inner JOIN trade_visitor tv on td.id = tv.detail_id
  251. where 1= 1 and td.deleted = 0 and tv.deleted=0
  252. <if test="orderId != null and orderId != ''">
  253. AND td.order_id = #{orderId}
  254. </if>
  255. </select>
  256. <select id="getOrderIdDetailList2" resultMap="MiddleWareDtoResultMap2">
  257. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,
  258. tv.credential_type, tv.mobile,tv.ota_detail_id,tv.is_insure,pc.full_path_name,p.product_tag,p.product_tag2,tstd.supp_spec_type
  259. FROM trade_detail td
  260. inner join product_spu p on p.id = td.product_id
  261. inner join product_category pc on pc.id = p.category_id
  262. inner JOIN trade_visitor tv on td.id = tv.detail_id
  263. left join trade_supp_ticket_detail tstd on td.id = tstd.trade_detail_id
  264. where 1= 1
  265. <if test="orderIds!=null">
  266. and td.order_id in
  267. <foreach collection="orderIds" item="item" separator="," open="(" close=")">
  268. #{item}
  269. </foreach>
  270. </if>
  271. </select>
  272. <select id="getOrderIdDetailList" resultMap="MiddleWareDtoResultMap">
  273. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,
  274. tv.credential_type, tv.mobile,tv.ota_detail_id,tv.is_insure,pc.full_path_name,p.product_tag,p.product_tag2,tstd.supp_spec_type
  275. FROM trade_detail td
  276. inner join product_spu p on p.id = td.product_id
  277. inner join product_category pc on pc.id = p.category_id
  278. inner JOIN trade_visitor tv on td.id = tv.detail_id
  279. left join trade_supp_ticket_detail tstd on td.id = tstd.trade_detail_id
  280. where 1= 1
  281. and td.order_id in
  282. ( SELECT td.id FROM
  283. product_marketing_audit pma
  284. INNER JOIN trade_order td on pma.order_id = td.id
  285. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  286. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  287. LEFT JOIN product_marketing_pool_spu pms on td.id = pms.order_id
  288. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  289. WHERE 1 = 1
  290. <if test="vo.storeId != null">
  291. and pma.store_id = #{vo.storeId}
  292. </if>
  293. <if test="vo.distributorId != null">
  294. and td.source_id = #{vo.distributorId}
  295. </if>
  296. <if test="vo.ids.size()>0">
  297. and pma.travel_id in
  298. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  299. #{item}
  300. </foreach>
  301. </if>
  302. <if test="vo.isExecute != null">
  303. and pma.is_execute = #{vo.isExecute}
  304. </if>
  305. <if test="vo.policyType != null and vo.policyType != ''">
  306. AND pmk.policy_type = #{vo.policyType}
  307. </if>
  308. <if test="vo.marketingName != null and vo.marketingName != ''">
  309. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  310. </if>
  311. <if test="vo.auditState != null">
  312. and pma.audit_state = #{vo.auditState}
  313. </if>
  314. <if test="vo.useAuditState != null">
  315. and pma.use_audit_state = #{vo.useAuditState}
  316. </if>
  317. <if test="vo.orderNo != null and vo.orderNo != ''">
  318. AND td.order_no = #{vo.orderNo}
  319. </if>
  320. <if test="vo.travelDate != null and vo.travelDate != ''">
  321. AND td.travel_date = #{vo.travelDate}
  322. </if>
  323. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  324. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  325. </if>
  326. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  327. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  328. </if>
  329. <if test="vo.productName != null and vo.productName != ''">
  330. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  331. </if>
  332. )
  333. </select>
  334. <select id="getOrderIdDetailList1" resultMap="MiddleWareDtoResultMap2">
  335. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,
  336. tv.credential_type, tv.mobile,tv.ota_detail_id,tv.is_insure,pc.full_path_name,p.product_tag,p.product_tag2,tstd.supp_spec_type
  337. FROM trade_detail td
  338. inner join product_spu p on p.id = td.product_id
  339. inner join product_category pc on pc.id = p.category_id
  340. inner JOIN trade_visitor tv on td.id = tv.detail_id
  341. left join trade_supp_ticket_detail tstd on td.id = tstd.trade_detail_id
  342. where 1= 1
  343. and td.order_id in
  344. ( SELECT td.id FROM
  345. product_marketing_audit pma
  346. INNER JOIN trade_order td on pma.order_id = td.id
  347. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  348. INNER JOIN trade_order_user tou ON td.id = tou.order_id
  349. LEFT JOIN product_marketing_pool_spu pms on td.id = pms.order_id
  350. LEFT JOIN product_marketing pmk ON pmk.id = pma.marketing_id
  351. WHERE 1 = 1
  352. <if test="vo.storeId != null">
  353. and pma.store_id = #{vo.storeId}
  354. </if>
  355. <if test="vo.distributorId != null">
  356. and td.source_id = #{vo.distributorId}
  357. </if>
  358. <if test="vo.ids.size()>0">
  359. and pma.travel_id in
  360. <foreach collection="vo.ids" item="item" separator="," open="(" close=")">
  361. #{item}
  362. </foreach>
  363. </if>
  364. <if test="vo.isExecute != null">
  365. and pma.is_execute = #{vo.isExecute}
  366. </if>
  367. <if test="vo.policyType != null and vo.policyType != ''">
  368. AND pmk.policy_type = #{vo.policyType}
  369. </if>
  370. <if test="vo.marketingName != null and vo.marketingName != ''">
  371. AND pmk.name like concat('%',#{vo.marketingName}, '%')
  372. </if>
  373. <if test="vo.auditState != null">
  374. and pma.audit_state = #{vo.auditState}
  375. </if>
  376. <if test="vo.useAuditState != null">
  377. and pma.use_audit_state = #{vo.useAuditState}
  378. </if>
  379. <if test="vo.orderNo != null and vo.orderNo != ''">
  380. AND td.order_no = #{vo.orderNo}
  381. </if>
  382. <if test="vo.travelDate != null and vo.travelDate != ''">
  383. AND td.travel_date = #{vo.travelDate}
  384. </if>
  385. <if test="vo.travelDateStart != null and vo.travelDateStart != ''">
  386. AND td.travel_date <![CDATA[ >= ]]> #{vo.travelDateStart}
  387. </if>
  388. <if test="vo.travelDateEnd != null and vo.travelDateEnd != ''">
  389. AND td.travel_date <![CDATA[ <= ]]> #{vo.travelDateEnd}
  390. </if>
  391. <if test="vo.productName != null and vo.productName != ''">
  392. AND tdl.product_name like concat('%',#{vo.productName}, '%')
  393. </if>
  394. )
  395. </select>
  396. <select id="getOrderIdDetailV2" resultMap="MiddleWareDtoResultMap">
  397. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,
  398. tv.credential_type, tv.mobile,tv.ota_detail_id,tv.is_insure
  399. FROM trade_detail td
  400. left JOIN trade_visitor tv on td.id = tv.detail_id
  401. where 1= 1
  402. <if test="orderId != null and orderId != ''">
  403. AND td.order_id = #{orderId}
  404. </if>
  405. </select>
  406. <select id="getOtcOrderIdDetail" resultMap="MiddleWareDtoResultMap">
  407. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,
  408. tv.credential_type, tv.mobile,tv.ota_detail_id,tv.is_insure,pc.full_path_name
  409. FROM trade_detail td
  410. inner join ota_distributor_product d on d.id = td.product_id
  411. inner join product_spu p on p.id = d.product_id
  412. inner join product_category pc on pc.id = p.category_id
  413. left JOIN trade_visitor tv on td.id = tv.detail_id
  414. where 1= 1
  415. <if test="orderId != null and orderId != ''">
  416. AND td.order_id = #{orderId}
  417. </if>
  418. </select>
  419. <select id="selectRefundCount" resultType="java.util.Map">
  420. select count(*) totalCount,count(if(td.voucher_status=5,1,null)) refundCount
  421. from trade_detail td
  422. where td.order_id=#{orderId}
  423. </select>
  424. <resultMap id="RefundDetailMap" type="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundDetailRespVO">
  425. <id property="id" column="id"/>
  426. <result property="refundId" column="refund_id"/>
  427. <result property="tradeDetailId" column="trade_detail_id"/>
  428. <result property="refundAmount" column="refundDetailAmount"/>
  429. <result property="voucherStatus" column="voucher_status"/>
  430. <result property="refundStatus" column="refundDetailStatus"/>
  431. <result property="refundTime" column="refund_time"/>
  432. <result property="refundBaseId" column="refundBaseId"/>
  433. <result property="voucherCode" column="voucher_code"/>
  434. <result property="productName" column="product_name"/>
  435. <result property="tradeDetailPrice" column="tradeDetailPrice"/>
  436. <result property="actualPrice" column="actual_price"/>
  437. <result property="fee" column="fee"/>
  438. <!-- <collection property="refundDetailBaseRespList" resultMap="RefundBaseMap"/>-->
  439. </resultMap>
  440. <resultMap id="RefundBaseMap" type="com.yc.ship.module.trade.controller.admin.order.vo.refund.RefundDetailBaseRespVO">
  441. <id property="id" column="refundBaseId"/>
  442. <result property="refundDetailId" column="id"/>
  443. <result property="tradeBaseId" column="tradeBaseId"/>
  444. <result property="refundAmount" column="refundBaseAmount"/>
  445. <result property="refundStatus" column="refundBaseStatus"/>
  446. <result property="useStatus" column="use_status"/>
  447. <result property="platSupplierRefundId" column="plat_supplier_refund_id"/>
  448. <result property="platSupplierOrderId" column="plat_supplier_order_id"/>
  449. <result property="supplierVoucherCode" column="supplier_voucher_code"/>
  450. <result property="productBaseId" column="product_base_id"/>
  451. <result property="productBaseName" column="product_base_name"/>
  452. <result property="productResourceId" column="product_resource_id"/>
  453. <result property="productResourceName" column="product_resource_name"/>
  454. <result property="supplierProductId" column="supplier_product_id"/>
  455. <result property="projectName" column="project_name"/>
  456. <result property="productResourcePrice" column="product_resource_price"/>
  457. <result property="supplierId" column="supplier_id"/>
  458. <result property="supplierName" column="supplier_name"/>
  459. <result property="tradeBasePrice" column="tradeBasePrice"/>
  460. </resultMap>
  461. <!-- 1、OTA推送查询,1、根据门票ID查询 -->
  462. <select id="getDetailInfoByDetailId" resultType="java.util.Map">
  463. SELECT
  464. tor.id orderId,
  465. tor.external_order_no,
  466. td.id detailId,
  467. td.id check_id,
  468. tor.source_id,
  469. tor.sell_method,
  470. td.voucher_code voucherCode,
  471. tor.item_id,
  472. tor.order_no orderNo,
  473. ps.product_code ticketCode,
  474. ps.id productId,
  475. td.validity_start_date ticketStartDate,
  476. td.validity_end_date ticketEndDate,
  477. td.voucher_status voucherStatus
  478. FROM
  479. trade_detail td
  480. INNER JOIN product_spu ps ON td.product_id = ps.id
  481. <if test="voucherId != null and voucherId != ''">
  482. AND td.id = #{voucherId}
  483. </if>
  484. INNER JOIN trade_order tor ON td.order_id = tor.id
  485. <if test="orderId != null and orderId != ''">
  486. AND tor.id = #{orderId}
  487. </if>
  488. </select>
  489. <select id="getOneByCardNo" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  490. select d.* from trade_detail d inner join trade_visitor v on d.id = v.detail_id
  491. INNER JOIN trade_order o on o.id = d.order_id
  492. where d.order_id = #{orderId} and v.credential_no = #{cardNo} and o.sell_method in (0,1,6,7) limit 1
  493. </select>
  494. <select id="getOneByCardNoAndChannelId" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  495. SELECT
  496. DISTINCT d.*
  497. FROM
  498. trade_order o
  499. INNER JOIN trade_detail d ON d.order_id = o.id
  500. INNER JOIN trade_visitor v ON v.detail_id = d.id
  501. inner join trade_detail_base tdb on d.id = tdb.detail_id
  502. inner join product_check_channel pcc on tdb.product_base_id = pcc.product_id and pcc.deleted=0
  503. WHERE
  504. d.validity_start_date <![CDATA[ <= ]]> CURDATE() and d.validity_end_date <![CDATA[ >= ]]> CURDATE()
  505. and d.voucher_status in (1,2,3,8,9)
  506. and tdb.use_status in (1,2,8,9)
  507. and o.sell_method in (0,1,6,7)
  508. and v.credential_no = #{cardNo}
  509. <if test="channelId != null">
  510. and pcc.channel_id = #{channelId}
  511. </if>
  512. and v.credential_type in (0,2)
  513. limit 1
  514. </select>
  515. <select id="getOneByVoucherCode" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  516. SELECT
  517. DISTINCT t1.*
  518. FROM
  519. trade_detail t1
  520. WHERE
  521. t1.voucher_code = #{voucherCode}
  522. </select>
  523. <update id="updateImgByVoucherCode">
  524. update trade_detail set faceimg=#{url} WHERE voucher_code = #{voucherCode}
  525. </update>
  526. <select id="getOneCheckGateQuery" resultType="com.yc.ship.module.trade.controller.admin.order.vo.rule.GateCheckDetailRespVO">
  527. SELECT
  528. t2.credential_no cardNo,t3.payment_date orderCreateTime,t1.use_date travelDate,t3.order_no orderNo,t3.pay_amount orderAmount,t1.faceimg imageUrl
  529. FROM
  530. trade_detail t1
  531. INNER JOIN trade_visitor t2 ON t1.id = t2.detail_id
  532. inner join trade_order t3 on t1.order_id = t3.id
  533. WHERE t1.voucher_code = #{voucherCode}
  534. </select>
  535. <select id="getProductTag4" resultType="java.lang.String">
  536. SELECT product_tag4 FROM product_spu WHERE id = #{productId}
  537. </select>
  538. <select id="getOneByVoucherCodePlat" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  539. SELECT *
  540. FROM
  541. trade_detail
  542. WHERE
  543. voucher_code = #{voucherCode}
  544. </select>
  545. <select id="getListByVoucherCodePlat" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  546. SELECT
  547. DISTINCT t3.*
  548. FROM
  549. trade_detail t1
  550. INNER JOIN trade_detail_base t2 ON t1.id = t2.detail_id
  551. inner JOIN trade_detail t3 ON t2.supplier_voucher_code = t3.voucher_code
  552. WHERE
  553. t1.voucher_code in
  554. <foreach collection="voucherCodes" item="item" separator="," open="(" close=")">
  555. #{item}
  556. </foreach>
  557. </select>
  558. <select id="getListByVoucherCodeOtc" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  559. SELECT
  560. DISTINCT t3.*
  561. FROM
  562. trade_detail t1
  563. INNER JOIN trade_detail_base t2 ON t1.id = t2.detail_id
  564. inner JOIN trade_detail t3 ON t2.supplier_voucher_code = t3.voucher_code
  565. WHERE
  566. t3.voucher_code in
  567. <foreach collection="voucherCodes" item="item" separator="," open="(" close=")">
  568. #{item}
  569. </foreach>
  570. </select>
  571. <!-- 产品相关信息 -->
  572. <select id="getProductSupInfo"
  573. resultType="com.yc.ship.module.product.api.dto.ProductGroupRespDTO">
  574. SELECT
  575. pg.id,
  576. pg.product_id productId,
  577. pg.product_base_id productBaseId,
  578. pg.product_base_type productBaseType,
  579. pg.sku_id skuId,
  580. pg.project_id projectId,
  581. pg.specification_id specificationId,
  582. pg.first_resource_id firstResourceId,
  583. pg.cost_price costPrice,
  584. pg.sale_price salePrice,
  585. pg.spec_type specType,
  586. pg.need_choose needChoose,
  587. pg.max_num maxNum,
  588. p.product_name productName,
  589. pb.can_repeat_buy canRepeatBuy,
  590. pb.`name` productBaseName,
  591. pp.`name` projectName,
  592. pp1.`name` specificationName,
  593. pp1.sort specSort
  594. FROM
  595. product_group pg
  596. INNER JOIN product_spu p ON p.id = pg.product_id
  597. INNER JOIN product_base pb ON pb.id = pg.product_base_id
  598. INNER JOIN product_project pp ON pp.id = pg.project_id
  599. INNER JOIN product_project pp1 ON pp1.id = pg.specification_id
  600. WHERE
  601. pg.deleted = 0
  602. and pg.product_base_type = 0
  603. <if test="productId != null and productId != ''">
  604. AND pg.product_id = #{productId}
  605. </if>
  606. ORDER BY pg.id,pg.update_time
  607. </select>
  608. <select id="getProductSupInfoByPlanId"
  609. resultType="com.yc.ship.module.product.api.dto.ProductGroupRespDTO">
  610. SELECT
  611. pg.id,
  612. pg.product_id productId,
  613. pg.product_base_id productBaseId,
  614. pg.product_base_type productBaseType,
  615. pg.sku_id skuId,
  616. pg.project_id projectId,
  617. pg.specification_id specificationId,
  618. pg.first_resource_id firstResourceId,
  619. pg.cost_price costPrice,
  620. pg.sale_price salePrice,
  621. pg.spec_type specType,
  622. pg.need_choose needChoose,
  623. pg.max_num maxNum,
  624. p.product_name productName,
  625. pb.can_repeat_buy canRepeatBuy,
  626. pb.`name` productBaseName,
  627. pp.`name` projectName,
  628. pp1.`name` specificationName,
  629. pp1.sort specSort,
  630. pdetail.sort
  631. FROM
  632. product_group pg
  633. INNER JOIN product_spu p ON p.id = pg.product_id
  634. INNER JOIN product_base pb ON pb.id = pg.product_base_id
  635. INNER JOIN product_project pp ON pp.id = pg.project_id
  636. INNER JOIN product_project pp1 ON pp1.id = pg.specification_id
  637. left join product_route_plan plan on p.id = plan.product_id
  638. <if test="planId != null and planId != ''">
  639. AND plan.id = #{planId}
  640. </if>
  641. left join product_route_plan_detail pdetail on plan.id = pdetail.plan_id and pdetail.product_base_id = pb.id
  642. AND ( pdetail.is_use IS NULL OR pdetail.is_use = 1) and pdetail.deleted=0
  643. WHERE
  644. pg.deleted = 0
  645. and pg.product_base_type = 0
  646. <if test="productId != null and productId != ''">
  647. AND pg.product_id = #{productId}
  648. </if>
  649. <if test="planId != null and planId != ''">
  650. AND if(pb.tenant_id = plan.tenant_id,plan.id = #{planId} and pdetail.id is not null,1=1)
  651. </if>
  652. ORDER BY pp.sort,pdetail.sort
  653. </select>
  654. <!-- 产品相关和规格信息 -->
  655. <select id="getProductSkuInfo"
  656. resultType="com.yc.ship.module.product.api.dto.ProductGroupRespDTO">
  657. SELECT
  658. odp.id,
  659. odp.product_id productId,
  660. odp.product_base_id productBaseId,
  661. odp.specification_id specificationId,
  662. odp.cost_price costPrice,
  663. odp.sale_price salePrice,
  664. odp.spec_type specType,
  665. pdp.product_sku_id skuId,
  666. pdp.sale_price allSalePrice,
  667. p.product_name productName,
  668. pp.id projectId,
  669. pb.`name` productBaseName,
  670. pb.can_repeat_buy canRepeatBuy,
  671. pp.`name` specificationName,
  672. pp.parent_id
  673. FROM
  674. ota_distributor_project odp
  675. INNER JOIN ota_distributor_product pdp ON pdp.id = odp.distributor_product_id
  676. INNER JOIN product_spu p ON p.id = odp.product_id
  677. INNER JOIN product_base pb ON pb.id = odp.product_base_id
  678. INNER JOIN product_project pp ON pp.id = odp.specification_id
  679. WHERE
  680. odp.deleted = 0 AND (odp.is_use = 1 or odp.is_use is null)
  681. <if test="productId != null and productId != ''">
  682. AND odp.product_id = #{productId}
  683. </if>
  684. <if test="distributorId != null and distributorId != ''">
  685. AND odp.distributor_id = #{distributorId}
  686. </if>
  687. <if test="skuId != null and skuId != ''">
  688. AND pdp.product_sku_id = #{skuId}
  689. </if>
  690. ORDER BY odp.id
  691. </select>
  692. <select id="selectSpuListByTenantId"
  693. resultType="com.yc.ship.module.product.api.dto.ProductSpuRespDTO">
  694. SELECT distinct
  695. p.id,
  696. p.product_name productName,
  697. p.product_code productCode,
  698. p.product_type productType,
  699. p.category_id categoryId,
  700. p.sort_num sortNum,
  701. p.sale_price salePrice,
  702. p.cost_price costPrice,
  703. p.is_validated isValidated,
  704. odp.is_use isUse,
  705. odp.is_use_otc isUseOtc,
  706. pc.full_path_name categoryName
  707. FROM
  708. product_spu p
  709. INNER JOIN ota_distributor_product odp ON odp.product_id = p.id
  710. INNER JOIN ota_distributor od ON od.id = odp.distributor_id
  711. INNER JOIN product_category pc ON pc.id = p.category_id
  712. WHERE
  713. od.deleted = 0
  714. AND od.is_use = 1
  715. AND odp.is_use = 1
  716. and if(od.self_support = 1, odp.is_use_otc=1, true)
  717. AND p.is_use = 1
  718. <if test="categoryId != null and categoryId != ''">
  719. AND pc.id = #{categoryId}
  720. </if>
  721. <if test="useDate != null and useDate != ''">
  722. and EXISTS (
  723. select 1 from (
  724. SELECT product_id as id FROM stock_day_product WHERE is_use = 1 and deleted = 0 and use_date = #{useDate}
  725. union ALL
  726. SELECT business_id as id FROM stock_day_config WHERE type = 0 and deleted = 0 and is_use = 1
  727. and start_date <![CDATA[ <= ]]> #{useDate} AND end_date <![CDATA[ >= ]]> #{useDate}
  728. ) m where m.id = p.id
  729. )
  730. </if>
  731. <if test='type != null and type != "" and type == "3"'>
  732. AND p.product_type = 7
  733. </if>
  734. AND odp.deleted = 0
  735. AND p.deleted = 0
  736. AND od.account_tenant_id = #{tenantId}
  737. order by if (p.sort_num is null, 9999,p.sort_num), p.create_time desc
  738. </select>
  739. <select id="platProductAll"
  740. resultType="com.yc.ship.module.product.api.dto.ProductSpuRespDTO">
  741. SELECT distinct
  742. p.id,
  743. p.product_name productName,
  744. p.product_code productCode,
  745. p.product_type productType,
  746. p.category_id categoryId,
  747. p.sort_num sortNum,
  748. p.sale_price salePrice,
  749. p.cost_price costPrice,
  750. p.is_validated isValidated,
  751. 1 isUse,
  752. 1 isUseOtc,
  753. pc.full_path_name categoryName
  754. FROM
  755. product_spu p INNER JOIN product_category pc ON pc.id = p.category_id
  756. WHERE 1=1
  757. <if test="productIds!=null">
  758. and p.id in
  759. <foreach collection="productIds" item="item" separator="," open="(" close=")">
  760. #{item}
  761. </foreach>
  762. </if>
  763. AND p.deleted = 0
  764. order by p.create_time desc
  765. </select>
  766. <select id="selectSpuOTAListByTenantId"
  767. resultType="com.yc.ship.module.product.api.dto.ProductSpuRespDTO">
  768. SELECT * from product_spu WHERE is_use = 1 AND deleted = 0
  769. <if test="categoryId != null and categoryId != ''">
  770. AND category_id = #{categoryId}
  771. </if>
  772. <if test='type != null and type != "" and type == "3"'>
  773. AND product_type = 7
  774. </if>
  775. order by if (sort_num is null, 9999,sort_num),create_time desc
  776. </select>
  777. <select id="getProductSpuPlat"
  778. resultType="com.yc.ship.module.product.api.dto.ProductSpuRespDTO">
  779. SELECT
  780. ps.*,
  781. odp.id productBaseId,
  782. od.id distributorId
  783. FROM
  784. product_spu ps
  785. INNER JOIN ota_distributor_product odp ON ps.id = odp.product_id
  786. INNER JOIN ota_distributor od ON odp.distributor_id = od.id
  787. WHERE ps.id = #{productId} AND od.account_tenant_id = #{tenantId}
  788. LIMIT 1
  789. </select>
  790. <select id="getProductSpu" resultType="com.yc.ship.module.product.api.dto.ProductSpuRespDTO">
  791. SELECT ps.* FROM product_spu ps WHERE ps.id = #{productId}
  792. </select>
  793. <select id="getProductBasicRule" resultType="com.yc.ship.module.product.api.dto.ProductBasicRuleRespDTO">
  794. SELECT * from product_basic_rule WHERE id = #{productId}
  795. </select>
  796. <select id="getProductSaleRule" resultType="com.yc.ship.module.product.api.dto.ProductSaleRuleRespDTO">
  797. SELECT * from product_sale_rule WHERE id = #{productId}
  798. </select>
  799. <select id="getProductRefundRule" resultType="com.yc.ship.module.product.api.dto.ProductRefundRuleRespDTO">
  800. SELECT * from product_refund_rule WHERE id = #{productId}
  801. </select>
  802. <select id="getProductTakeRule" resultType="com.yc.ship.module.product.api.dto.ProductTakeRuleRespDTO">
  803. SELECT * from product_take_rule WHERE id = #{productId}
  804. </select>
  805. <select id="getProductOtherRule" resultType="com.yc.ship.module.product.api.dto.ProductOtherRuleRespDTO">
  806. SELECT * from product_other_rule WHERE id = #{productId}
  807. </select>
  808. <select id="getProductSukList" resultType="com.yc.ship.module.product.api.dto.ProductSkuRespDTO">
  809. SELECT * from product_sku WHERE product_id = #{productId} AND deleted = 0
  810. </select>
  811. <select id="getProductSkuPriceList" resultType="com.yc.ship.module.product.api.dto.ProductSkuRespDTO">
  812. SELECT product_sku_id id,distributor_product_id,product_id,spec_type,cost_price,sale_price,stock
  813. from ota_distributor_agency_price WHERE deleted = 0 and product_id = #{productId} AND distributor_id = #{distributorId}
  814. </select>
  815. <select id="getProductCheckRule" resultType="com.yc.ship.module.product.api.dto.ProductCheckRuleRespDTO">
  816. SELECT * from product_check_rule WHERE id = #{productId}
  817. </select>
  818. <select id="getProductTakeRules"
  819. resultType="com.yc.ship.module.product.api.dto.ProductTakeRuleRespDTO">
  820. SELECT ptr.*
  821. FROM trade_order td
  822. INNER JOIN trade_detail tdl on td.id = tdl.order_id
  823. INNER JOIN product_spu ps on tdl.product_id = ps.id
  824. INNER JOIN product_take_rule ptr on ps.id = ptr.id
  825. where 1= 1
  826. <if test="orderId != null and orderId != ''">
  827. AND td.id = #{orderId}
  828. </if>
  829. GROUP BY ps.id
  830. </select>
  831. <select id="selectInsuranceProductFromOrder"
  832. resultType="java.util.Map">
  833. select td.product_id,por.insurance_code,por.insurance_amount,count(1) num
  834. from trade_detail td
  835. inner join product_other_rule por on td.product_id = por.id
  836. <where>
  837. por.need_insurance = 1 and td.order_id=#{orderId}
  838. </where>
  839. GROUP BY
  840. td.product_id
  841. </select>
  842. <select id="selectContractProductFromOrder"
  843. resultType="java.util.Map">
  844. select td.product_id,por.contract_id
  845. from trade_detail td
  846. inner join product_other_rule por on td.product_id = por.id
  847. <where>
  848. por.contract_id != '' and td.order_id=#{orderId}
  849. </where>
  850. GROUP BY
  851. td.product_id
  852. </select>
  853. <select id="selectDetailAndVisitor"
  854. resultMap="MiddleWareDtoResultMap">
  855. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,tv.credential_type,tv.mobile,tv.ota_detail_id
  856. FROM trade_detail td
  857. LEFT JOIN trade_visitor tv on td.id = tv.detail_id
  858. <where>
  859. td.order_id = #{orderId}
  860. <if test="detailVoucherList!=null">
  861. and td.voucher_code in
  862. <foreach collection="detailVoucherList" item="item" separator="," open="(" close=")">
  863. #{item}
  864. </foreach>
  865. </if>
  866. </where>
  867. </select>
  868. <!--获取核销通知失败门票重新推送-->
  869. <select id="queryNotifyFailedVoucherInfo" resultType="java.util.Map">
  870. SELECT border.id orderId,
  871. border.external_order_no,
  872. border.source_id,
  873. border.sell_method,
  874. border.item_id,
  875. border.order_no orderNo,
  876. ticket.id ticketId,
  877. ticket.validity_start_date ticketStartDate,
  878. ticket.validity_end_date ticketEndDate,
  879. ticket.voucher_status voucherStatus,
  880. ticket.product_id productId,
  881. ticket.voucher_code voucherCode,
  882. notify0.check_id,
  883. notify0.create_time
  884. FROM trade_notify_log notify0
  885. INNER JOIN trade_detail ticket on ticket.voucher_code = notify0.voucher_code
  886. INNER JOIN trade_order border on border.id = ticket.order_id
  887. INNER JOIN trade_check tc ON tc.detail_id = ticket.id
  888. LEFT JOIN trade_notify_log notify1 ON notify1.voucher_code = notify0.voucher_code
  889. AND notify1.notity_status = 1
  890. WHERE notify0.notity_status = 0
  891. AND notify0.create_time >= CONCAT(DATE_FORMAT(DATE_ADD(NOW(), INTERVAL - 1 DAY ), '%Y-%m-%d'), ' 00:00:00')
  892. AND notify1.notity_status IS NULL
  893. <if test="voucherCode != null and voucherCode != ''">
  894. AND ticket.voucher_code = #{voucherCode}
  895. </if>
  896. UNION ALL
  897. SELECT border.id orderId,
  898. border.external_order_no,
  899. border.source_id,
  900. border.sell_method,
  901. border.item_id,
  902. border.order_no orderNo,
  903. ticket.id ticketId,
  904. ticket.validity_start_date ticketStartDate,
  905. ticket.validity_end_date ticketEndDate,
  906. ticket.voucher_status voucherStatus,
  907. ticket.product_id productId,
  908. ticket.voucher_code voucherCode,
  909. tc.id check_id,
  910. tc.create_time create_time
  911. FROM trade_detail ticket
  912. INNER JOIN trade_order border ON border.id = ticket.order_id
  913. INNER JOIN trade_check tc ON tc.detail_id = ticket.id
  914. LEFT JOIN trade_notify_log notify ON notify.voucher_code = ticket.voucher_code
  915. WHERE border.sell_method = 1
  916. AND ticket.check_status = 1
  917. AND notify.voucher_code is null
  918. AND tc.create_time &gt;= CONCAT(DATE_FORMAT(NOW(), '%Y-%m-%d'), ' 00:00:00')
  919. AND tc.create_time &lt;= CONCAT(DATE_FORMAT(NOW(), '%Y-%m-%d'), ' 23:59:59')
  920. <if test="voucherCode != null and voucherCode != ''">
  921. AND ticket.voucher_code = #{voucherCode}
  922. </if>
  923. GROUP BY ticket.id
  924. ORDER BY create_time DESC
  925. </select>
  926. <select id="getTradeDetailWithBaseByCodeAndIdcard" resultMap="MiddleWareDtoResultMap">
  927. select <include refid="selectColumnId"/>
  928. from trade_detail td
  929. inner join trade_detail_base tdb on td.id = tdb.detail_id and td.voucher_status > 0 and td.deleted = 0
  930. INNER JOIN trade_order tdo on tdo.id = td.order_id and tdo.deleted = 0
  931. left JOIN trade_visitor tv on tv.detail_id = td.id
  932. <where>
  933. 1=1 and td.validity_start_date <![CDATA[ <= ]]> NOW()
  934. and td.validity_end_date <![CDATA[ >= ]]> NOW()
  935. and td.voucher_status in (1,2,3,8,9)
  936. and tdo.sell_method != 3 and tdo.sell_method != 4
  937. <if test="idCard!=null and idCard != ''">
  938. and tv.credential_no = #{idCard}
  939. </if>
  940. <if test="voucherCode!=null and voucherCode != ''">
  941. and td.voucher_code = #{voucherCode}
  942. </if>
  943. <if test="channelId != null and channelId != ''">
  944. and EXISTS (select product_id from product_check_channel p1 where p1.product_id=tdb.product_base_id and channel_id=#{channelId} and deleted = 0)
  945. </if>
  946. </where>
  947. </select>
  948. <select id="getPlatByVoucherCode1" resultMap="MiddleWareDtoResultMap">
  949. select <include refid="selectColumnId"/>
  950. from trade_detail td
  951. inner join trade_detail_base tdb on td.id = tdb.detail_id and td.voucher_status > 0 and td.deleted = 0
  952. INNER JOIN trade_order tdo on tdo.id = td.order_id and tdo.deleted = 0
  953. left JOIN trade_visitor tv on tv.detail_id = td.id
  954. WHERE td.validity_start_date <![CDATA[ <= ]]> NOW()
  955. and td.validity_end_date <![CDATA[ >= ]]> NOW()
  956. and td.voucher_status in (1,2,3,8,9)
  957. and td.voucher_code = #{voucherCode}
  958. </select>
  959. <select id="getPlatByVoucherCode2" resultMap="MiddleWareDtoResultMap">
  960. select <include refid="selectColumnId"/>
  961. from trade_detail td
  962. inner join trade_detail_base tdb on td.id = tdb.detail_id and td.voucher_status > 0 and td.deleted = 0
  963. INNER JOIN trade_order tdo on tdo.id = td.order_id and tdo.deleted = 0
  964. left JOIN trade_visitor tv on tv.detail_id = td.id
  965. WHERE td.validity_start_date <![CDATA[ <= ]]> NOW()
  966. and td.validity_end_date <![CDATA[ >= ]]> NOW()
  967. and td.voucher_status in (1,2,3,8,9)
  968. and td.id IN (
  969. SELECT t3.id
  970. FROM trade_detail t1
  971. INNER JOIN trade_detail_base t2 ON t1.id = t2.detail_id
  972. LEFT JOIN trade_detail t3 ON t2.supplier_voucher_code = t3.voucher_code
  973. WHERE t1.voucher_code = #{voucherCode}
  974. )
  975. </select>
  976. <select id="getTradeDetailByCheckId" resultMap="MiddleWareDtoResultMap">
  977. select <include refid="selectColumnId"/>
  978. from trade_detail td
  979. inner join trade_detail_base tdb on td.id = tdb.detail_id
  980. INNER JOIN trade_order tdo on tdo.id = td.order_id
  981. INNER JOIN trade_check_detail tcd on tcd.detail_base_id =tdb.id and tcd.check_id = #{checkId}
  982. LEFT JOIN trade_visitor tv on tv.detail_id = td.id
  983. </select>
  984. <sql id="selectColumnId">
  985. td.*,tdo.order_no,tdb.id detail_base_id,tdb.detail_id,tdb.product_base_id,tdb.product_base_name,tdb.product_base_type,
  986. tdb.product_resource_id,tdb.product_resource_name,tdb.supplier_product_id,tdb.supplier_id,
  987. tdb.supplier_name,tdb.is_system_direct,tdb.use_status,tdb.check_status base_check_status,tdb.verify_time base_verify_time,
  988. tdb.price base_price,tdb.usage_count,tdb.product_resource_price,tdb.project_id,tdb.project_name,
  989. tdb.specification_id,tdb.specification_name,tdb.spec_type base_spec_type,tdb.supplier_voucher_code,tdb.plat_supplier_order_id,
  990. tv.id visitorId,tv.credential_no,tv.credential_type,tv.gender,tv.`name`,tv.mobile,tv.gender
  991. </sql>
  992. <select id="selectOrderProduct" resultType="java.util.Map">
  993. select td.product_id,td.route_plan_id,td.route_plan_group_type,td.product_name,td.actual_price,td.use_date,td.quantity_of_one,count(*) buyCount
  994. from trade_detail td
  995. where td.order_id =#{orderId}
  996. group by td.product_id
  997. </select>
  998. <select id="selectOrderProductV2" resultType="java.util.Map">
  999. select td.product_id,td.route_plan_id,td.route_plan_group_type,td.product_name,td.actual_price,td.use_date,td.quantity_of_one,
  1000. count(if(FIND_IN_SET(td.spec_type,
  1001. <foreach collection="noContainSpecList" item="item" separator="," open="" close="">
  1002. #{item}
  1003. </foreach> )<![CDATA[<= ]]> 0,1,null)) buyCount
  1004. from trade_detail td
  1005. where td.order_id =#{orderId}
  1006. group by td.product_id
  1007. </select>
  1008. <select id="selectNoCheckCount" resultType="java.lang.Integer">
  1009. select count(1) from trade_detail where order_id = #{orderId} and voucher_status in (1,2,8)
  1010. </select>
  1011. <select id="getMaxOrderNo" resultType="java.lang.Integer">
  1012. select count(1) from trade_order where voyage_id = #{voyageId}
  1013. </select>
  1014. <select id="getOrderDetail"
  1015. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeDetailRespVO">
  1016. SELECT td.*,tv.detail_id,tv.name,tv.id visitorId,tv.gender,tv.credential_no,tv.credential_type,tv.mobile,tv.ota_detail_id,tv.is_insure
  1017. FROM trade_detail td
  1018. INNER JOIN trade_visitor tv on td.id = tv.detail_id
  1019. where 1= 1
  1020. <if test="orderId != null and orderId != ''">
  1021. AND td.order_id = #{orderId}
  1022. </if>
  1023. </select>
  1024. <select id="getProductProject" resultType="java.util.Map">
  1025. select pp.id,pp.name
  1026. from product_project pp
  1027. where pp.id =#{projectId}
  1028. </select>
  1029. <select id="selectVisitorOrderProductCount" resultType="java.util.Map">
  1030. select tv.credential_no,count(td.id) total
  1031. from trade_detail td
  1032. INNER JOIN trade_visitor tv on td.id = tv.detail_id
  1033. where td.product_id =#{productId} and td.voucher_status in (0,1,2) and td.use_date = #{useDate}
  1034. <if test="excludeOrderId!=null">
  1035. and td.order_id != #{excludeOrderId}
  1036. </if>
  1037. and tv.credential_no in
  1038. <foreach collection="credentialNoList" item="item" separator="," open="(" close=")">
  1039. #{item}
  1040. </foreach>
  1041. group by tv.credential_no
  1042. HAVING total>0
  1043. </select>
  1044. <select id="selectPlatDetailByDetailIds" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1045. select td.*
  1046. from trade_detail_base tdb
  1047. inner join trade_detail td on td.voucher_code = tdb.supplier_voucher_code
  1048. where td.order_id = #{orderId}
  1049. <if test="detailIdList!=null and detailIdList.size()>0">
  1050. and tdb.detail_id in
  1051. <foreach collection="detailIdList" item="id" separator="," open="(" close=")">
  1052. #{id}
  1053. </foreach>
  1054. </if>
  1055. group by td.id
  1056. </select>
  1057. <select id="getPlatDetailByOrderId" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1058. select * from trade_detail where order_id = #{orderId} and voucher_status in (1,2,3,4,6,8,9)
  1059. </select>
  1060. <select id="selectChangeDetailList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1061. select td.*
  1062. from trade_order_change_detail cd
  1063. inner join trade_detail td on cd.origin_detail_id = td.id
  1064. where cd.order_id = #{orderId} and cd.origin_order_id =#{originOrderId}
  1065. </select>
  1066. <select id="selectToCheckList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1067. select td.*
  1068. from trade_detail td inner join trade_order o on o.id = td.order_id and o.sell_method in (0,1,6,7)
  1069. INNER JOIN product_refund_rule rr on rr.id = td.product_id and rr.deleted = 0
  1070. where td.validity_start_date <![CDATA[ <= ]]> #{useDate}
  1071. AND td.validity_end_date <![CDATA[ >= ]]> #{useDate}
  1072. and rr.expire_operate_type = 2 AND td.voucher_status in (1,2,4,8,9)
  1073. </select>
  1074. <select id="selectToAllCheckList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1075. SELECT td.* FROM trade_detail td
  1076. INNER JOIN trade_order o ON o.id = td.order_id
  1077. AND o.sell_method IN (0, 1, 6, 7 )
  1078. INNER JOIN trade_detail_base tdb ON td.id = tdb.detail_id
  1079. INNER JOIN product_refund_rule rr ON rr.id = td.product_id
  1080. AND rr.deleted = 0
  1081. WHERE td.validity_end_date <![CDATA[ < ]]> #{useDate}
  1082. AND rr.expire_operate_type = 2
  1083. AND td.voucher_status IN ( 1, 2, 4, 8, 9 )
  1084. AND tdb.use_status IN ( 1, 2, 4, 8, 9 )
  1085. </select>
  1086. <select id="selectToTravlCheckList" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1087. SELECT td.* FROM trade_detail td
  1088. INNER JOIN trade_order o ON o.id = td.order_id
  1089. AND o.sell_method IN (3,4 )
  1090. INNER JOIN trade_detail_base tdb ON td.id = tdb.detail_id
  1091. INNER JOIN product_refund_rule rr ON rr.id = td.product_id
  1092. AND rr.deleted = 0
  1093. WHERE td.validity_end_date <![CDATA[ < ]]> #{useDate}
  1094. AND rr.expire_operate_type = 2
  1095. AND td.voucher_status IN ( 1, 2, 4, 8, 9 )
  1096. AND tdb.use_status IN ( 1, 2, 4, 8, 9 )
  1097. </select>
  1098. <select id="selectTravelTradeDetail" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1099. select td.* from trade_detail td
  1100. inner join trade_detail_base db on db.detail_id = td.id
  1101. where db.supplier_voucher_code = #{voucherCode} limit 1
  1102. </select>
  1103. <select id="selectTradeDetailByVistorId" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1104. select td.* from trade_detail td
  1105. inner join trade_visitor db on db.detail_id = td.id
  1106. where db.id = #{visitorId} limit 1
  1107. </select>
  1108. <select id="selectPlatTradeBaseDetail" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailBaseDO">
  1109. select tdd.* from trade_detail td inner join trade_detail_base tdd on td.id = tdd.detail_id
  1110. where td.voucher_code = #{voucherCode} and tdd.supplier_product_id is not null and tdd.deleted = 0
  1111. limit 1
  1112. </select>
  1113. <select id="selectDispatchRecord" resultType="java.util.Map">
  1114. select odb.id from dispatch_car_dispatch_order_detail_base odb
  1115. where odb.car_dispatch_id = #{dispatchId} and odb.detail_id = #{detailId} and odb.deleted = 0
  1116. union all
  1117. select dodb.id from dispatch_operate_plan_boat_order_detail_base dodb
  1118. where dodb.plan_id = #{dispatchId} and dodb.detail_id = #{detailId} and dodb.deleted = 0
  1119. </select>
  1120. <select id="getAllUpCategoryById" resultType="com.yc.ship.module.trade.dal.dataobject.order.CategoryRespVO">
  1121. WITH recursive temp AS (
  1122. SELECT c.* FROM product_category c WHERE c.deleted = 0 AND c.use_status = 1
  1123. <choose>
  1124. <when test="type != null">
  1125. AND c.type = #{type}
  1126. </when>
  1127. <otherwise>
  1128. AND c.type = 0
  1129. </otherwise>
  1130. </choose>
  1131. AND c.id = #{id}
  1132. UNION ALL
  1133. SELECT c.* FROM product_category c
  1134. INNER JOIN temp t2 ON t2.parent_id = c.id WHERE c.deleted = 0 AND c.use_status = 1
  1135. <choose>
  1136. <when test="type != null">
  1137. AND c.type = #{type}
  1138. </when>
  1139. <otherwise>
  1140. AND c.type = 0
  1141. </otherwise>
  1142. </choose>
  1143. ) SELECT
  1144. pc.id, pc.type,
  1145. pc.parent_id parentId,
  1146. pc.cate_name cateName,
  1147. pc.use_status useStatus,
  1148. pc.sort_num sortNum,
  1149. pc.cate_code cateCode,
  1150. pc.full_path_name fullPathName,
  1151. pc.parent_path parentPath,
  1152. pc.create_time createTime
  1153. FROM temp pc group by pc.id
  1154. ORDER BY create_time
  1155. </select>
  1156. <insert id="insertSmsLog">
  1157. INSERT INTO system_sms_send_log (
  1158. `id`,
  1159. `order_no`,
  1160. `sms_config_id`,
  1161. `sms_content`,
  1162. `mobile`,
  1163. `creator`,
  1164. `create_time`,
  1165. `updater`,
  1166. `update_time`,
  1167. `deleted`,
  1168. `result`,
  1169. `status`
  1170. )
  1171. VALUES
  1172. (
  1173. #{smsSendLogDTO.id},
  1174. #{smsSendLogDTO.orderNo},
  1175. #{smsSendLogDTO.smsConfigId},
  1176. #{smsSendLogDTO.smsContent},
  1177. #{smsSendLogDTO.mobile},
  1178. 1,
  1179. now(),
  1180. 1,
  1181. now(),
  1182. 0,
  1183. #{smsSendLogDTO.result},
  1184. #{smsSendLogDTO.status}
  1185. );
  1186. </insert>
  1187. <select id="selectOverdueOrderDetailForRefund" resultType="com.yc.ship.module.trade.dal.dataobject.order.TradeDetailDO">
  1188. select td.*
  1189. from trade_detail td
  1190. inner join product_refund_rule ru on td.product_id = ru.id
  1191. where td.voucher_status in (1,2) and td.validity_end_date <![CDATA[ < ]]> #{overdueDay} and ru.expire_operate_type = 3
  1192. </select>
  1193. <select id="selectCheckAmount" resultType="java.math.BigDecimal">
  1194. select sum(td.actual_price) checkAmount
  1195. from trade_detail td
  1196. where td.check_status =1 and td.order_id =#{orderId}
  1197. </select>
  1198. <select id="selectOrderPackProduct" resultType="java.util.Map">
  1199. select td.pack_product_id,sum(td.quantity_of_one) totalQuantity,count(*) buyCount
  1200. from trade_detail td
  1201. where td.order_id =#{orderId}
  1202. group by td.pack_product_id
  1203. </select>
  1204. <select id="selectContractByOrderId" resultType="java.util.Map">
  1205. select order_id,res_code,res_msg,status,contract_no,signing_url,view_url,t1.payment_date paymentDate
  1206. from trade_order t1 left join trade_contract t2 on t1.id = t2.order_id
  1207. where t1.id =#{orderId} and t1.order_status = 6
  1208. </select>
  1209. <select id="queryRoutePlanDetailTimeByPlanId" resultType="java.util.Map">
  1210. SELECT
  1211. TIME_FORMAT(MIN(STR_TO_DATE(start_time, '%H:%i')), '%H:%i') AS startTime,
  1212. TIME_FORMAT(MAX(STR_TO_DATE(start_time, '%H:%i')), '%H:%i') AS endTime
  1213. FROM
  1214. product_route_plan_detail where plan_id = #{planId};
  1215. </select>
  1216. <select id="selectOrderSmsInfo" resultType="com.yc.ship.module.trade.controller.admin.smsSendconfig.vo.SmsSendconfigQueryRespVO">
  1217. select t7.*,t1.group_no groupNo,t2.product_id,t2.product_name,t66.name voyageName,t77.name shipName,t1.order_no,t1.seller_id,t2.use_date,count(distinct t2.id)
  1218. num,t1.source_name,t3.contact_name,t3.mobile,t6.params templateParams,t6.api_template_id,t8.api_key,t8.api_secret,t8.api_url,t8.signature,t8.code channelCode from
  1219. trade_order t1
  1220. inner join trade_detail t2 on t1.id = t2.order_id
  1221. inner join trade_order_user t3 on t3.order_id = t1.id
  1222. inner join product_voyage t66 on t66.id = t1.voyage_id
  1223. inner join resource_route t67 on t66.route_id = t67.id
  1224. inner join resource_ship t77 on t77.id = t1.ship_id
  1225. left join system_sms_product t5 on (t67.id=t5.product_id )
  1226. left join system_sms_sendconfig t7 on t7.id = t5.sms_template_id
  1227. left join system_sms_template t6 on t7.sms_template_id = t6.id
  1228. left join system_sms_channel t8 on t8.id = t6.channel_id
  1229. where t2.voucher_status in (1,2)
  1230. and t2.deleted = 0
  1231. and t7.deleted = 0
  1232. and t8.deleted = 0
  1233. and t7.is_use = 1
  1234. and t7.send_type=#{type}
  1235. and t1.id=#{orderId}
  1236. GROUP BY t1.id
  1237. </select>
  1238. <select id="getRoutePlanByProductId" resultType="com.yc.ship.module.product.api.dto.RoutePlanRespDTO">
  1239. select p.*
  1240. from product_route_plan p
  1241. where p.product_id = #{productId} and p.deleted =0 and use_start_time <![CDATA[<= ]]> now()
  1242. and use_end_time <![CDATA[>= ]]> now()
  1243. <if test="useStatus != null">
  1244. AND p.use_status = #{useStatus}
  1245. </if>
  1246. </select>
  1247. <select id="getRefundBatchDetails"
  1248. resultMap="RefundDetailMap">
  1249. SELECT
  1250. tf.id,tf.refund_id,tf.trade_detail_id,tf.refund_amount refundDetailAmount,tf.voucher_status,tf.refund_status refundDetailStatus,tf.refund_time,
  1251. tf.fee, td.voucher_code,td.product_id,td.product_name,td.price tradeDetailPrice,td.actual_price,
  1252. tfb.id refundBaseId,tfb.trade_detail_base_id tradeBaseId,tfb.refund_amount refundBaseAmount,tfb.refund_status refundBaseStatus,tfb.use_status,
  1253. tdb.product_base_id,tdb.product_base_name,tdb.product_resource_id,tdb.product_resource_name,tdb.supplier_product_id,tdb.project_name,tdb.product_resource_price,tdb.supplier_id,tdb.supplier_name,tdb.price tradeBasePrice
  1254. FROM
  1255. trade_refund_detail tf
  1256. INNER JOIN trade_detail td ON tf.trade_detail_id = td.id
  1257. left JOIN trade_refund_detail_base tfb ON tfb.refund_detail_id = tf.id
  1258. left JOIN trade_detail_base tdb ON tfb.trade_detail_base_id = tdb.id
  1259. where 1= 1
  1260. <if test="refundId != null and refundId != ''">
  1261. AND tf.refund_id = #{refundId}
  1262. </if>
  1263. </select>
  1264. <select id="getOrderIdDetailCount"
  1265. resultType="com.yc.ship.module.trade.controller.admin.order.vo.order.TradeOrderDetailCountRespVO">
  1266. select product_id, product_name, price, count(1) quantity, product_type
  1267. from trade_detail
  1268. WHERE deleted = 0 and (product_type = 2 or product_type = 1) and order_id = #{orderId}
  1269. GROUP BY product_type, product_id
  1270. order by product_type asc
  1271. </select>
  1272. </mapper>