TradeDetailMapper.xml 62 KB

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