CmReceiptOrderRelationMapper.xml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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.caimei.modules.order.dao.CmReceiptOrderRelationDao">
  4. <sql id="cmReceiptOrderRelationColumns">
  5. a.id AS "id",
  6. a.relationType AS "relationType",
  7. a.receiptID AS "receiptID",
  8. a.associateAmount AS "associateAmount",
  9. a.orderID AS "orderID",
  10. a.shopOrderId as "shopOrderId",
  11. a.delFlag AS "delFlag"
  12. </sql>
  13. <select id="get" resultType="CmReceiptOrderRelation">
  14. SELECT
  15. <include refid="cmReceiptOrderRelationColumns"/>
  16. FROM cm_receipt_order_relation a
  17. WHERE a.id = #{id}
  18. </select>
  19. <select id="findList" resultType="CmReceiptOrderRelation">
  20. SELECT
  21. <include refid="cmReceiptOrderRelationColumns"/>
  22. FROM cm_receipt_order_relation a
  23. <where>
  24. </where>
  25. <choose>
  26. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  27. ORDER BY ${page.orderBy}
  28. </when>
  29. <otherwise>
  30. </otherwise>
  31. </choose>
  32. </select>
  33. <select id="findAllList" resultType="CmReceiptOrderRelation">
  34. SELECT
  35. <include refid="cmReceiptOrderRelationColumns"/>
  36. FROM cm_receipt_order_relation a
  37. <where>
  38. </where>
  39. <choose>
  40. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  41. ORDER BY ${page.orderBy}
  42. </when>
  43. <otherwise>
  44. </otherwise>
  45. </choose>
  46. </select>
  47. <insert id="insert" parameterType="CmReceiptOrderRelation" keyProperty="id" useGeneratedKeys="true">
  48. INSERT INTO cm_receipt_order_relation(relationType,
  49. receiptID,
  50. associateAmount,
  51. orderID,
  52. shopOrderId,
  53. delFlag)
  54. VALUES (#{relationType},
  55. #{receiptID},
  56. #{associateAmount},
  57. #{orderID},
  58. #{shopOrderId},
  59. #{delFlag})
  60. </insert>
  61. <update id="update">
  62. UPDATE cm_receipt_order_relation
  63. SET relationType = #{relationType},
  64. receiptID = #{receiptID},
  65. associateAmount = #{associateAmount},
  66. orderID = #{orderID},
  67. delFlag = #{delFlag}
  68. WHERE id = #{id}
  69. </update>
  70. <delete id="delete">
  71. DELETE
  72. FROM cm_receipt_order_relation
  73. WHERE id = #{id}
  74. </delete>
  75. <select id="findByReceiptID" resultType="CmReceiptOrderRelation">
  76. select
  77. <include refid="cmReceiptOrderRelationColumns"/>,
  78. b.receiptDate,
  79. b.newReceiptType
  80. from cm_receipt_order_relation a
  81. left join cm_discern_receipt b on a.receiptID = b.id
  82. where a.receiptID = #{receiptID}
  83. and a.delFlag = 0
  84. </select>
  85. <select id="findByOrderID" resultType="CmReceiptOrderRelation">
  86. select a.*,
  87. b.payType as "payType",
  88. b.receiptDate as "receiptDate",
  89. b.confirmType as "confirmType",
  90. b.balanceAccountsRemark as "balanceAccountsRemark",
  91. b.payWay as "payWay"
  92. from cm_receipt_order_relation a
  93. left join cm_discern_receipt b on a.receiptID = b.id
  94. where a.orderID = #{orderID}
  95. AND b.receiptType = '1'
  96. AND b.receiptStatus = '3'
  97. AND a.delFlag = '0'
  98. AND b.delFlag = '0'
  99. order by b.receiptDate desc
  100. </select>
  101. <select id="findByOrderIDGroupBy" resultType="CmReceiptOrderRelation">
  102. select a.relationType,
  103. a.orderID AS "orderID",
  104. a.receiptID AS "receiptID",
  105. SUM(b.receiptAmount) AS "associateAmount",
  106. b.payType as "payType",
  107. DATE_FORMAT(b.receiptDate, "%Y年%m月%d日") as "receiptDate",
  108. b.confirmType as "confirmType"
  109. from cm_receipt_order_relation a
  110. left join cm_discern_receipt b on a.receiptID = b.id
  111. where a.orderID = #{orderID}
  112. AND b.receiptType = '1'
  113. AND b.receiptStatus = '3'
  114. AND a.delFlag = '0'
  115. AND b.delFlag = '0'
  116. GROUP BY b.payType, DATE_FORMAT(b.receiptDate, "%Y年%m月%d日")
  117. </select>
  118. <select id="findByOrderIDGroup" resultType="CmReceiptOrderRelation">
  119. SELECT a.relationType,
  120. a.orderID AS "orderID",
  121. a.receiptID AS "receiptID",
  122. b.receiptAmount AS "associateAmount",
  123. b.payType AS "payType",
  124. DATE_FORMAT(b.receiptDate, "%Y年%m月%d日") AS "receiptDate",
  125. b.confirmType AS "confirmType"
  126. FROM cm_receipt_order_relation a
  127. LEFT JOIN cm_shop_order so ON a.orderID = so.shopOrderID
  128. LEFT JOIN cm_discern_receipt b ON a.receiptID = b.id
  129. WHERE so.orderID = #{orderID}
  130. AND b.receiptType = '3'
  131. AND b.receiptStatus = '2'
  132. AND a.delFlag = '0'
  133. AND b.delFlag = '0'
  134. GROUP BY b.payType, DATE_FORMAT(b.receiptDate, "%Y年%m月%d日")
  135. </select>
  136. <select id="findPayFeeByOrderID" resultType="java.lang.Double">
  137. select IFNULL(sum(associateAmount), 0)
  138. from cm_receipt_order_relation a
  139. left join cm_discern_receipt b on a.receiptID = b.id
  140. where a.orderID = #{orderID}
  141. AND b.receiptStatus = '3'
  142. AND a.delFlag = '0'
  143. AND b.delFlag = '0'
  144. </select>
  145. <select id="findReceiptByShopOrderId" resultType="java.lang.Double">
  146. select IFNULL(sum(associateAmount), 0)
  147. from cm_receipt_order_relation a
  148. left join cm_discern_receipt b on a.receiptID = b.id
  149. where a.shopOrderId = #{shopOrderId}
  150. AND b.receiptStatus = '3'
  151. AND a.delFlag = '0'
  152. AND b.delFlag = '0'
  153. </select>
  154. <select id="toAudit" resultType="java.lang.Integer">
  155. SELECT cdr.id
  156. FROM `cm_receipt_order_relation` cror
  157. LEFT JOIN `cm_discern_receipt` cdr ON cror.receiptID = cdr.id
  158. WHERE cdr.receiptStatus = '2'
  159. AND cror.relationType = '2'
  160. AND cror.delFlag = '0'
  161. AND cror.orderID = #{orderID}
  162. </select>
  163. <select id="findOrderRelation" resultType="CmReceiptOrderRelation">
  164. SELECT *
  165. FROM cm_receipt_order_relation
  166. WHERE (orderID = #{orderId} or shopOrderId = #{shopOrderId})
  167. AND delFlag = '0'
  168. GROUP BY orderID
  169. </select>
  170. <select id="getDiscernPayWay" resultType="java.lang.Integer">
  171. SELECT cdr.payWay
  172. FROM cm_receipt_order_relation cror
  173. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  174. WHERE cror.orderID = #{orderID} and cror.delFlag = 0
  175. ORDER BY cdr.payWay
  176. LIMIT 1
  177. </select>
  178. <select id="findOnlinePayment" resultType="date">
  179. SELECT cdr.receiptDate
  180. FROM cm_receipt_order_relation cror
  181. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  182. WHERE cror.relationType = 2
  183. AND cror.delFlag = 0
  184. AND cdr.payWay = 1
  185. AND cror.orderID = #{orderID}
  186. ORDER BY cdr.receiptDate
  187. LIMIT 1
  188. </select>
  189. <select id="findPayType" resultType="java.lang.String">
  190. SELECT payType
  191. FROM cm_discern_receipt cdr
  192. LEFT JOIN cm_receipt_order_relation cror ON cdr.id = cror.receiptID
  193. WHERE cror.shopOrderId = #{orderId}
  194. </select>
  195. <select id="findUserId" resultType="java.lang.String">
  196. select userId
  197. from cm_order
  198. where orderId = #{orderId}
  199. </select>
  200. <select id="findByShopOrderIds" resultType="com.caimei.modules.order.entity.CmReceiptOrderRelation">
  201. SELECT
  202. a.relationType,
  203. a.receiptID,
  204. a.shopOrderId,
  205. a.orderID,
  206. a.mbOrderId,
  207. a.orderRequestNo,
  208. a.splitStatus,
  209. a.associateAmount-IFNULL((SELECT SUM(refundAmount) FROM cm_refundmoney_record WHERE
  210. orderRequestNo=a.orderRequestNo),0) AS associateAmount,
  211. b.payType AS "payType",
  212. b.receiptDate AS "receiptDate",
  213. b.confirmType AS "confirmType",
  214. b.balanceAccountsRemark AS "balanceAccountsRemark",
  215. b.payWay AS "payWay"
  216. FROM cm_receipt_order_relation a
  217. LEFT JOIN cm_discern_receipt b ON a.receiptID = b.id
  218. WHERE a.shopOrderId IN
  219. <foreach collection="shopOrderIds" separator="," item="shopOrderID" open="(" close=")">
  220. #{shopOrderID}
  221. </foreach>
  222. AND b.receiptType = '1'
  223. AND b.receiptStatus = '3'
  224. AND a.delFlag = '0'
  225. AND b.delFlag = '0'
  226. ORDER BY a.associateAmount DESC
  227. </select>
  228. </mapper>