OrderRefundMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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.yami.shop.dao.OrderRefundMapper">
  4. <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.OrderRefund">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="refund_id" property="refundId"/>
  9. <result column="refund_sn" property="refundSn"/>
  10. <result column="shop_id" property="shopId"/>
  11. <result column="user_id" property="userId"/>
  12. <result column="order_id" property="orderId"/>
  13. <result column="refund_type" property="orderId"/>
  14. <result column="order_item_id" property="orderItemId"/>
  15. <result column="goods_num" property="goodsNum"/>
  16. <result column="refund_amount" property="refundAmount"/>
  17. <result column="apply_type" property="applyType"/>
  18. <result column="is_receiver" property="isReceiver"/>
  19. <result column="buyer_reason" property="buyerReason"/>
  20. <result column="buyer_desc" property="buyerDesc"/>
  21. <result column="buyer_mobile" property="buyerMobile"/>
  22. <result column="photo_files" property="photoFiles"/>
  23. <result column="return_money_sts" property="returnMoneySts"/>
  24. <result column="reject_message" property="rejectMessage"/>
  25. <result column="seller_msg" property="sellerMsg"/>
  26. <result column="apply_time" property="applyTime"/>
  27. <result column="handel_time" property="handelTime"/>
  28. <result column="ship_time" property="shipTime"/>
  29. <result column="receive_time" property="receiveTime"/>
  30. <result column="cancel_time" property="cancelTime"/>
  31. <result column="refund_time" property="refundTime"/>
  32. <result column="decision_time" property="decisionTime"/>
  33. <result column="update_time" property="updateTime"/>
  34. <result column="reject_time" property="rejectTime"/>
  35. </resultMap>
  36. <resultMap id="tagResultMap" type="com.yami.shop.bean.dto.OrderRefundDto">
  37. <id column="refund_id" property="refundId"/>
  38. <result column="refund_sn" property="refundSn"/>
  39. <result column="shop_id" property="shopId"/>
  40. <result column="user_id" property="userId"/>
  41. <result column="order_id" property="orderId"/>
  42. <result column="refund_type" property="refundType"/>
  43. <result column="order_item_id" property="orderItemId"/>
  44. <result column="r_goods_num" property="goodsNum"/>
  45. <result column="refund_amount" property="refundAmount"/>
  46. <result column="apply_type" property="applyType"/>
  47. <result column="is_receiver" property="isReceiver"/>
  48. <result column="buyer_reason" property="buyerReason"/>
  49. <result column="buyer_mobile" property="buyerMobile"/>
  50. <result column="photo_files" property="photoFiles"/>
  51. <result column="return_money_sts" property="returnMoneySts"/>
  52. <result column="reject_message" property="rejectMessage"/>
  53. <result column="seller_msg" property="sellerMsg"/>
  54. <result column="apply_time" property="applyTime"/>
  55. <result column="handel_time" property="handelTime"/>
  56. <result column="ship_time" property="shipTime"/>
  57. <result column="receive_time" property="receiveTime"/>
  58. <result column="cancel_time" property="cancelTime"/>
  59. <result column="refund_time" property="refundTime"/>
  60. <result column="decision_time" property="decisionTime"/>
  61. <result column="update_time" property="updateTime"/>
  62. <result column="reject_time" property="rejectTime"/>
  63. <result column="shop_name" property="shopName"/>
  64. <!-- 扩展字段 -->
  65. <result column="o_order_number" property="orderNumber"/>
  66. <result column="o_actual_total" property="orderAmount"/>
  67. <result column="s_order_pay_no" property="orderPayNo"/>
  68. <result column="s_settlement_id" property="settlementId"/>
  69. <result column="o_pay_time" property="orderPayTime"/>
  70. <result column="o_status" property="status"/>
  71. <result column="o_refund_status" property="refundStatus"/>
  72. <result column="freight_amount" property="freightAmount"/>
  73. <result column="offset_points" property="offsetPoints"/>
  74. <!-- 退货地址信息 -->
  75. <association property="refundDelivery" javaType="com.yami.shop.bean.model.RefundDelivery">
  76. <id column="refund_delivery_id" property="refundDeliveryId"/>
  77. <result column="shop_id" property="shopId"/>
  78. <result column="refund_sn" property="refundSn"/>
  79. <result column="user_id" property="userId"/>
  80. <result column="payer" property="payer"/>
  81. <result column="price" property="price"/>
  82. <result column="dey_id" property="deyId"/>
  83. <result column="dey_name" property="deyName"/>
  84. <result column="dey_nu" property="deyNu"/>
  85. <result column="receiver_name" property="receiverName"/>
  86. <result column="receiver_mobile" property="receiverMobile"/>
  87. <result column="receiver_telephone" property="receiverTelephone"/>
  88. <result column="receiver_post_code" property="receiverPostCode"/>
  89. <result column="receiver_addr" property="receiverAddr"/>
  90. <result column="sender_mobile" property="senderMobile"/>
  91. <result column="sender_remarks" property="senderRemarks"/>
  92. <result column="imgs" property="imgs"/>
  93. <result column="create_time" property="createTime"/>
  94. </association>
  95. </resultMap>
  96. <resultMap id="InfoResultMap" type="com.yami.shop.bean.dto.OrderRefundDto">
  97. <id column="refund_id" property="refundId"/>
  98. <result column="refund_sn" property="refundSn"/>
  99. <result column="shop_id" property="shopId"/>
  100. <result column="user_id" property="userId"/>
  101. <result column="order_id" property="orderId"/>
  102. <result column="refund_type" property="refundType"/>
  103. <result column="order_item_id" property="orderItemId"/>
  104. <result column="goods_num" property="goodsNum"/>
  105. <result column="refund_amount" property="refundAmount"/>
  106. <result column="apply_type" property="applyType"/>
  107. <result column="is_receiver" property="isReceiver"/>
  108. <result column="is_return_logistics" property="isReturnLogistics"/>
  109. <result column="buyer_desc" property="buyerDesc"/>
  110. <result column="platform_refund_amount" property="platformRefundAmount"/>
  111. <result column="buyer_reason" property="buyerReason"/>
  112. <result column="buyer_mobile" property="buyerMobile"/>
  113. <result column="photo_files" property="photoFiles"/>
  114. <result column="return_money_sts" property="returnMoneySts"/>
  115. <result column="reject_message" property="rejectMessage"/>
  116. <result column="seller_msg" property="sellerMsg"/>
  117. <result column="apply_time" property="applyTime"/>
  118. <result column="handel_time" property="handelTime"/>
  119. <result column="ship_time" property="shipTime"/>
  120. <result column="receive_time" property="receiveTime"/>
  121. <result column="cancel_time" property="cancelTime"/>
  122. <result column="refund_time" property="refundTime"/>
  123. <result column="decision_time" property="decisionTime"/>
  124. <result column="update_time" property="updateTime"/>
  125. <result column="reject_time" property="rejectTime"/>
  126. <result column="shop_name" property="shopName"/>
  127. <result column="distribution_total_amount" property="distributionTotalAmount"/>
  128. <!-- 扩展字段 -->
  129. <result column="o_order_number" property="orderNumber"/>
  130. <result column="o_actual_total" property="orderAmount"/>
  131. <result column="o_status" property="status"/>
  132. <result column="s_order_pay_no" property="orderPayNo"/>
  133. <result column="s_settlement_id" property="settlementId"/>
  134. <result column="o_pay_time" property="orderPayTime"/>
  135. <result column="o_dvy_type" property="dvyType"/>
  136. <result column="freight_amount" property="freightAmount"/>
  137. <result column="offset_points" property="offsetPoints"/>
  138. <!-- 退货地址信息 -->
  139. <association property="refundDelivery" javaType="com.yami.shop.bean.model.RefundDelivery">
  140. <id column="refund_delivery_id" property="refundDeliveryId"/>
  141. <result column="shop_id" property="shopId"/>
  142. <result column="refund_sn" property="refundSn"/>
  143. <result column="user_id" property="userId"/>
  144. <result column="dey_id" property="deyId"/>
  145. <result column="dey_name" property="deyName"/>
  146. <result column="dey_nu" property="deyNu"/>
  147. <result column="receiver_name" property="receiverName"/>
  148. <result column="receiver_mobile" property="receiverMobile"/>
  149. <result column="receiver_telephone" property="receiverTelephone"/>
  150. <result column="receiver_post_code" property="receiverPostCode"/>
  151. <result column="receiver_addr" property="receiverAddr"/>
  152. <result column="sender_mobile" property="senderMobile"/>
  153. <result column="sender_remarks" property="senderRemarks"/>
  154. <result column="imgs" property="imgs"/>
  155. <result column="create_time" property="createTime"/>
  156. <result column="pay" property="pay"/>
  157. <result column="payer" property="payer"/>
  158. <result column="price" property="price"/>
  159. <result column="touch_time" property="touchTime"/>
  160. <result column="delivery_time" property="deliveryTime"/>
  161. </association>
  162. </resultMap>
  163. <sql id="selectJoinAll">
  164. SELECT r.*,
  165. o.dvy_type as o_dvy_type,
  166. o.pay_time as o_pay_time,
  167. o.order_number AS o_order_number,
  168. o.actual_total AS o_actual_total,
  169. o.hb_order_status AS o_status,
  170. s.pay_no AS s_order_pay_no,
  171. sp.shop_name AS shop_name,
  172. s.settlement_id AS s_settlement_id,
  173. d.*
  174. FROM tz_order_refund r
  175. LEFT JOIN tz_order o ON r.order_id = o.order_id
  176. LEFT JOIN tz_shop_detail sp ON sp.shop_id = o.shop_id
  177. LEFT JOIN tz_refund_delivery d ON r.refund_sn = d.refund_sn
  178. LEFT JOIN tz_order_settlement s ON o.order_number = s.order_number
  179. </sql>
  180. <!-- 分页查询列表 -->
  181. <select id="getPage" parameterType="com.yami.shop.bean.dto.OrderRefundDto" resultMap="tagResultMap">
  182. SELECT
  183. r.*,
  184. rd.payer,
  185. rd.price,
  186. IF(r.goods_num = 0,o.product_nums,r.goods_num) AS r_goods_num,
  187. o.order_number AS o_order_number,
  188. o.pay_time as o_pay_time,
  189. o.actual_total AS o_actual_total,
  190. o.product_nums AS product_nums,
  191. o.hb_order_status AS o_status,
  192. o.refund_status AS o_refund_status,
  193. sd.shop_name AS shop_name
  194. FROM tz_order_refund r
  195. LEFT JOIN tz_order o on r.order_id = o.order_id
  196. LEFT JOIN tz_shop_detail sd on sd.shop_id = r.shop_id
  197. LEFT JOIN tz_refund_delivery rd on rd.refund_sn=r.refund_sn
  198. <where>
  199. <if test="orderRefundDto.shopId != null and orderRefundDto.shopId != ''">
  200. AND r.shop_id = #{orderRefundDto.shopId}
  201. </if>
  202. <if test="orderRefundDto.userId != null and orderRefundDto.userId != ''">
  203. AND r.user_id = #{orderRefundDto.userId}
  204. </if>
  205. <if test="orderRefundDto.refundSn != null and orderRefundDto.refundSn != ''">
  206. AND r.refund_sn = #{orderRefundDto.refundSn}
  207. </if>
  208. <if test="orderRefundDto.orderNumber != null and orderRefundDto.orderNumber != ''">
  209. AND o.order_number = #{orderRefundDto.orderNumber}
  210. </if>
  211. <if test="orderRefundDto.applyType != null and orderRefundDto.applyType != ''">
  212. AND r.apply_type = #{orderRefundDto.applyType}
  213. </if>
  214. <if test="beginTime != null and beginTime != ''">
  215. AND r.apply_time &gt;= #{beginTime}
  216. </if>
  217. <if test="endTime != null and endTime != ''">
  218. AND r.apply_time &lt;= #{endTime}
  219. </if>
  220. <if test="orderRefundDto.returnMoneySts != null and orderRefundDto.returnMoneySts != ''">
  221. AND r.return_money_sts = #{orderRefundDto.returnMoneySts}
  222. </if>
  223. <if test="orderRefundDto.shopName != null">
  224. AND sd.shop_name LIKE concat("%",#{orderRefundDto.shopName},"%")
  225. </if>
  226. <if test="orderRefundDto.orderType != null and orderRefundDto.orderType != ''">
  227. AND o.order_type = #{orderRefundDto.orderType}
  228. </if>
  229. <if test="orderRefundDto.refundType != null and orderRefundDto.refundType != ''">
  230. AND r.refund_type = #{orderRefundDto.refundType}
  231. </if>
  232. </where>
  233. ORDER BY apply_time DESC
  234. </select>
  235. <!-- 查询详情信息 -->
  236. <select id="getById" resultMap="InfoResultMap">
  237. <include refid="selectJoinAll"/>
  238. WHERE r.refund_id = #{id}
  239. <if test="shopId != null">
  240. and r.shop_id = #{shopId}
  241. </if>
  242. </select>
  243. <!-- 获取退款单数量 -->
  244. <select id="getRefundCount" resultType="int">
  245. SELECT count(*)
  246. FROM tz_order_refund r
  247. LEFT JOIN tz_order o on r.order_id = o.order_id
  248. LEFT JOIN tz_shop_detail sd on sd.shop_id = r.shop_id
  249. where r.user_id = #{userId}
  250. </select>
  251. <select id="getOrderRefundByRefundSn" resultMap="InfoResultMap">
  252. <include refid="selectJoinAll"/>
  253. WHERE r.refund_sn = #{refundSn}
  254. </select>
  255. <select id="getRefundByShopId" resultType="com.yami.shop.bean.param.StatisticsRefundParam">
  256. SELECT SUM(refund_amount) as payActualTotal,count(*) as refundCount FROM tz_order_refund
  257. <where>
  258. <if test="shopId != null">
  259. and shop_id = #{shopId}
  260. </if>
  261. <if test="startTime != null">
  262. and refund_time >= #{startTime}
  263. </if>
  264. <if test="endTime != null">
  265. and refund_time &lt;= #{endTime}
  266. </if>
  267. AND return_money_sts =5
  268. </where>
  269. </select>
  270. <select id="getRefundRankingByProd" resultType="com.yami.shop.bean.param.StatisticsRefundParam">
  271. SELECT MAX(buyer_reason) as buyerReason,prod_name as refundPordName,COUNT(buyer_reason) as
  272. refundCount,SUM(refund_amount) as payActualTotal
  273. FROM `tz_order_refund` a LEFT JOIN tz_order b
  274. ON a.order_id = b.order_id
  275. <where>
  276. <if test="shopId != null">
  277. and a.shop_id = #{shopId}
  278. </if>
  279. <if test="startTime != null">
  280. and refund_time >= #{startTime}
  281. </if>
  282. <if test="endTime != null">
  283. and refund_time &lt;= #{endTime}
  284. </if>
  285. AND return_money_sts =5
  286. </where>
  287. GROUP BY prod_name ORDER BY SUM(refund_amount) DESC LIMIT 0,5
  288. </select>
  289. <select id="getRefundRankingByReason" resultType="com.yami.shop.bean.param.StatisticsRefundParam">
  290. SELECT buyer_reason as buyerReason,MAX(prod_name) as refundPordName,COUNT(buyer_reason) as
  291. refundCount,SUM(refund_amount) as payActualTotal
  292. FROM `tz_order_refund` a LEFT JOIN tz_order b
  293. ON a.order_id = b.order_id
  294. <where>
  295. <if test="shopId != null">
  296. and a.shop_id = #{shopId}
  297. </if>
  298. <if test="startTime != null">
  299. and refund_time >= #{startTime}
  300. </if>
  301. <if test="endTime != null">
  302. and refund_time &lt;= #{endTime}
  303. </if>
  304. AND return_money_sts =5
  305. </where>
  306. GROUP BY buyer_reason ORDER BY SUM(refund_amount) DESC LIMIT 0,5
  307. </select>
  308. <select id="getRefundByShopIdAndDay" resultType="com.yami.shop.bean.param.StatisticsRefundParam">
  309. SELECT dates as refundDate,MAX(payActualTotal) as payActualTotal,MAX(refundCount) as refundCount FROM(
  310. SELECT @cdate := DATE_ADD(@cdate,INTERVAL - 1 DAY) dates ,0 AS payActualTotal,0 AS 'refundCount'
  311. FROM (SELECT @cdate :=DATE_ADD(CURDATE(),INTERVAL + 1 DAY) FROM tz_user) t1
  312. <where>
  313. <if test="startTime != null">
  314. and @cdate >= #{startTime}
  315. </if>
  316. </where>
  317. UNION ALL
  318. SELECT DATE_FORMAT(refund_time, '%Y-%m-%d') AS dates,SUM(refund_amount) AS payActualTotal,COUNT(refund_id)
  319. refundCount FROM tz_order_refund
  320. <where>
  321. <if test="shopId != null">
  322. and shop_id = #{shopId}
  323. </if>
  324. <if test="startTime != null">
  325. and refund_time >= #{startTime}
  326. </if>
  327. <if test="endTime != null">
  328. and refund_time &lt;= #{endTime}
  329. </if>
  330. AND return_money_sts =5
  331. </where>
  332. GROUP BY dates)_tmpAllTable GROUP BY dates
  333. ORDER BY dates
  334. </select>
  335. <update id="updateReturnMoneySts">
  336. UPDATE tz_order_refund
  337. <set>
  338. return_money_sts = #{status},update_time = now(),
  339. <if test="status == 2">
  340. handel_time = now()
  341. </if>
  342. </set>
  343. WHERE refund_id IN (
  344. <foreach collection="refundList" separator="," item="item">
  345. #{item.refundId}
  346. </foreach>
  347. )
  348. </update>
  349. <select id="sumRefundSuccessAmountByOrderId" resultType="double">
  350. select ifnull(sum(refund_amount), 0)
  351. from tz_order_refund
  352. where order_id = #{orderId}
  353. and return_money_sts = 5
  354. </select>
  355. <select id="getProcessingOrderRefundByOrderId" resultType="com.yami.shop.bean.model.OrderRefund">
  356. SELECT r.*
  357. FROM tz_order_refund r
  358. WHERE r.`order_id` = #{orderId}
  359. -- 买家撤回申请
  360. AND r.`return_money_sts` != 6
  361. -- 商家拒绝
  362. AND r.`return_money_sts` != 7
  363. -- 退款关闭
  364. AND r.`return_money_sts` != - 1
  365. </select>
  366. <select id="sumRefundSuccessPlatformAmountByOrderId" resultType="double">
  367. select ifnull(sum(platform_refund_amount), 0)
  368. from tz_order_refund
  369. where order_id = #{orderId}
  370. and return_money_sts = 5
  371. </select>
  372. <select id="getOrderRefundCountByRefundSn" resultType="java.lang.Integer">
  373. SELECT COUNT(*)
  374. FROM tz_order_refund
  375. WHERE order_id = (SELECT order_id
  376. FROM tz_order_refund
  377. WHERE refund_sn = #{refundSn } AND return_money_sts IN (1, 2, 3, 4, 5))
  378. </select>
  379. <select id="countRefundByOrderItem" resultType="java.lang.Integer">
  380. SELECT COUNT(refund_id)
  381. FROM `tz_order_refund`
  382. WHERE order_item_id = #{orderItemId}
  383. AND (return_money_sts &gt;= #{returnMoneySts0} AND return_money_sts &lt;= #{returnMoneySts1})
  384. </select>
  385. </mapper>