CmDiscernReceiptMapper.xml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.caimei.modules.order.dao.CmDiscernReceiptDao">
  6. <insert id="insertOrderReceipt" keyColumn="id" keyProperty="id"
  7. parameterType="com.caimei.modules.order.entity.ReceiptVo" useGeneratedKeys="true">
  8. insert into cm_discern_receipt(payWay, payType, receiptType, receiptStatus, receiptAmount, confirmType,
  9. receiptDate, confirmDate, reviewDate, delFlag, receStatct)
  10. values (#{payWay}, #{payType}, #{receiptType}, #{receiptStatus}, #{receiptAmount}, 4, now(), now(), now(), 0, 0)
  11. </insert>
  12. <insert id="insertOrderRelation">
  13. INSERT INTO cm_receipt_order_relation(relationType,
  14. receiptID,
  15. associateAmount,
  16. orderID,
  17. delFlag)
  18. VALUES (#{relationType},
  19. #{receiptId},
  20. #{receiptAmount},
  21. #{orderId},
  22. 0)
  23. </insert>
  24. <select id="findRebateOrderId" resultType="integer">
  25. select cso.orderId AS orderId
  26. from cm_receipt_order_relation cror left join cm_shop_order cso
  27. on cror.orderId = cso.shopOrderId
  28. where cror.relationType = '1' and cror.delFlag = '0'
  29. and cso.orderId in
  30. <foreach collection="orderIds" item="id" open="(" close=")" separator=",">
  31. #{id}
  32. </foreach>
  33. </select>
  34. <select id="findOrderReceipt" resultType="double">
  35. select ifnull(sum(associateAmount),0)
  36. from cm_receipt_order_relation cror
  37. left join cm_discern_receipt cdr on cror.receiptId = cdr.id
  38. where cror.orderId = #{orderId}
  39. and cror.delFlag = '0'
  40. and cror.relationType = '2'
  41. and cdr.delFlag = '0'
  42. and cdr.receiptStatus = '3'
  43. </select>
  44. <select id="findReceiptList" resultType="com.caimei.modules.order.entity.ReceiptVo">
  45. SELECT
  46. a.id AS "receiptId",
  47. a.payWay AS "payWay",
  48. a.payType AS "payType",
  49. a.receiptStatus AS "receiptStatus",
  50. a.receiptAmount AS "receiptAmount",
  51. a.receiptDate AS "receiptTime",
  52. a.newReceiptType,
  53. cso.orderId AS orderId,
  54. cso.shopOrderNo as shopOrderNos,
  55. cso.shopOrderId as shopOrderId,
  56. cof.bankAccount AS bankNameType,
  57. cr.organizeId AS organizeId,
  58. cr.orderNo,
  59. cr.orderType,
  60. (CASE WHEN cr.orderType = '0' THEN
  61. ( CASE sp.status WHEN 91 THEN '默认采购员(官方账号)' ELSE sp.linkMan END )
  62. ELSE ''
  63. END) AS spName,
  64. c.name as clubName
  65. FROM cm_discern_receipt a
  66. left join cm_receipt_order_relation crr on crr.receiptId = a.id and crr.delFlag = '0'
  67. left join cm_order cr on cr.orderId = crr.orderId
  68. left join serviceprovider sp ON cr.spID = sp.serviceProviderID
  69. left join club c on cr.userId = c.userId
  70. left join cm_shop_order cso on cso.orderId = crr.orderId
  71. LEFT JOIN cm_offline_collection cof ON a.payType = cof.type
  72. <where>
  73. <if test="organizeId != null">
  74. AND cr.organizeId = #{organizeId}
  75. </if>
  76. <if test="receiptId != null">
  77. AND a.id = #{receiptId}
  78. </if>
  79. <if test="startTime != null and startTime != ''">
  80. AND (a.receiptDate &gt; #{startTime} OR a.receiptDate = #{startTime})
  81. </if>
  82. <if test="endTime != null and endTime != ''">
  83. AND (a.receiptDate &lt; #{endTime} OR a.receiptDate = #{endTime})
  84. </if>
  85. <if test="payWay != null and payWay != ''">
  86. AND a.payWay = #{payWay}
  87. </if>
  88. <if test="payType != null and payType != ''">
  89. AND a.payType = #{payType}
  90. </if>
  91. <if test="receiptStatus != null and receiptStatus != ''">
  92. AND a.receiptStatus = #{receiptStatus}
  93. </if>
  94. <if test="orderNo != null and orderNo != ''">
  95. AND ((cr.orderNo like concat('%',#{orderNo},'%')) OR (cso.shopOrderNo like concat('%',#{orderNo},'%')))
  96. </if>
  97. <if test="orderId != null and orderId != ''">
  98. AND cr.orderId = #{orderId}
  99. </if>
  100. <if test="clubName != null and clubName != ''">
  101. AND (c.name LIKE concat('%',#{clubName},'%'))
  102. </if>
  103. <if test="receiptProgress != null">
  104. AND cr.receiptStatus = #{receiptProgress}
  105. </if>
  106. <if test="orderType != null">
  107. AND cr.orderType = #{orderType}
  108. </if>
  109. <if test="associationNum != null and associationNum != ''">
  110. <if test="associationNum == 1">
  111. and (select count(1) from cm_receipt_order_relation where receiptId = a.id and delFlag = '0') = 1
  112. </if>
  113. <if test="associationNum == 2">
  114. and (select count(1) from cm_receipt_order_relation where receiptId = a.id and delFlag = '0')
  115. <![CDATA[ > ]]> 1
  116. </if>
  117. </if>
  118. and a.delFlag = 0
  119. </where>
  120. group by a.id
  121. order by a.id desc
  122. </select>
  123. <select id="findReceiptDetail" resultType="com.caimei.modules.order.entity.ReceiptDetail">
  124. select cdr.id AS receiptId,
  125. cof.bankAccount AS bankNameType,
  126. cdr.receiptAmount AS receiptAmount,
  127. cdr.receiptDate AS receiptDate,
  128. cdr.receiptStatus AS receiptStatus,
  129. cdr.smsContent AS smsContent,
  130. cdr.payWay AS payWay,
  131. cror.orderId
  132. from cm_discern_receipt cdr
  133. left join cm_receipt_order_relation cror on cdr.id = cror.receiptID
  134. LEFT JOIN cm_offline_collection cof ON cdr.payType = cof.type
  135. where cdr.id = #{id}
  136. </select>
  137. <select id="findReceiptOrder" resultType="com.caimei.modules.order.entity.ReceiptOrderInfo">
  138. select co.orderNo,
  139. co.orderId,
  140. co.payTotalFee as orderAmount,
  141. co.payableAmount,
  142. co.orderType,
  143. (select ifnull(sum(cror.associateAmount),0)
  144. from cm_receipt_order_relation cror
  145. left join cm_order o on o.orderId = cror.orderId
  146. left join cm_discern_receipt cdr on cdr.id = cror.receiptId
  147. where o.orderId = co.orderId
  148. and cror.delFlag = '0'
  149. and cdr.delFlag = '0'
  150. and cdr.receiptStatus = '3'
  151. ) AS receiptAmount,
  152. c.name AS clubName,
  153. co.receiptStatus,
  154. co.orderTime,
  155. (CASE WHEN co.orderType = '0' THEN
  156. ( CASE sp.status WHEN 91 THEN '默认采购员(官方账号)' ELSE sp.linkMan END )
  157. ELSE ''
  158. END) AS spName
  159. from cm_order co
  160. left join club c on co.userId = c.userId
  161. left join serviceprovider sp ON co.spID = sp.serviceProviderID
  162. where co.orderId = #{orderId}
  163. </select>
  164. <select id="findOrderRelation" resultType="com.caimei.modules.order.entity.OrderRelationRecord">
  165. SELECT receiptDate as receiptTime,
  166. cof.bankAccount as bankNameType,
  167. receiptAmount,
  168. cror.mbOrderId,
  169. cdr.payWay
  170. FROM cm_discern_receipt cdr
  171. left join cm_offline_collection cof on cdr.payType = cof.type
  172. left join cm_receipt_order_relation cror on cdr.id = cror.receiptId
  173. where cdr.id = #{receiptId}
  174. </select>
  175. <select id="findReceiptShopOrder" resultType="com.caimei.modules.order.entity.NewShopOrder">
  176. select cso.shopOrderNo,
  177. shopOrderId,
  178. cso.realPay,
  179. cso.receiptAmount,
  180. cso.receiptStatus as shopReceiptStatus
  181. from cm_order co
  182. left join cm_shop_order cso on co.orderId = cso.orderId
  183. where co.orderId = #{orderId}
  184. </select>
  185. <select id="findReceiptType" resultType="com.caimei.modules.order.entity.ReceiptPayType">
  186. select type as id, bankAccount as name
  187. from cm_offline_collection
  188. where type in (12,17,13,14,15,29,30,31)
  189. </select>
  190. <select id="findOrderIds" resultType="java.lang.String">
  191. select cror.orderID
  192. from cm_receipt_order_relation cror
  193. where cror.receiptID = #{id}
  194. and cror.delFlag = '0'
  195. and cror.relationType = '1'
  196. </select>
  197. <select id="hasReceiptRecordOrder" resultType="java.lang.String">
  198. select cror.receiptId
  199. from cm_receipt_order_relation cror
  200. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  201. where cror.orderID = #{orderID}
  202. and cror.receiptID != #{receiptID}
  203. and cror.relationType = '2'
  204. and cror.delFlag = '0'
  205. and cdr.receiptStatus = '3'
  206. and cdr.delFlag = '0'
  207. </select>
  208. <select id="findPayType" resultType="com.caimei.modules.order.entity.ReceiptPayType">
  209. select type as id, bankAccount as name
  210. from cm_offline_collection
  211. where organizeId = 4
  212. </select>
  213. </mapper>