WxPayMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.supplier.mapper.WxPayMapper">
  5. <!-- 支付 -->
  6. <insert id="pay" parameterType="WxPay">
  7. insert into bus_pay(uuid,release_uuid,fee_type,mch_id,nonce_str,out_trade_no,total_fee,trade_type,prepay_id,open_id,time_end,jdrq,code_url,body)
  8. values(#{uuid},#{releaseUuid},#{feeType},#{mchId},#{nonceStr},#{outTradeNo},#{totalFee},#{tradeType},#{prepayId},#{openId},#{timeEnd},CONVERT(VARCHAR(100), SYSDATETIME(), 20),#{codeUrl},#{body})
  9. </insert>
  10. <!-- 删除支付信息 -->
  11. <delete id="deletePay" parameterType="WxPay">
  12. delete from bus_pay where release_uuid = #{releaseUuid}
  13. </delete>
  14. <!-- 修改支付信息 -->
  15. <update id="payUpdate" parameterType="WxPay">
  16. update bus_pay
  17. <set>
  18. <trim suffixOverrides=",">
  19. <if test="feeType != null and feeType != ''">
  20. fee_type = #{feeType},
  21. </if>
  22. <if test="mchId != null and mchId != ''">
  23. mch_id = #{mchId},
  24. </if>
  25. <if test="nonceStr != null and nonceStr != ''">
  26. nonce_str = #{nonceStr},
  27. </if>
  28. <if test="outTradeNo != null and outTradeNo != ''">
  29. out_trade_no = #{outTradeNo},
  30. </if>
  31. <if test="totalFee != null and totalFee != ''">
  32. total_fee = #{totalFee},
  33. </if>
  34. <if test="tradeType != null and tradeType != ''">
  35. trade_type = #{tradeType},
  36. </if>
  37. <if test="prepayId != null and prepayId != ''">
  38. prepay_id = #{prepayId},
  39. </if>
  40. <if test="openId != null and openId != ''">
  41. open_id = #{openId},
  42. </if>
  43. <if test="timeEnd != null and timeEnd != ''">
  44. time_end = #{timeEnd},
  45. </if>
  46. <if test="payType != null and payType != ''">
  47. pay_type = #{payType},
  48. </if>
  49. </trim>
  50. where release_uuid = #{releaseUuid}
  51. </set>
  52. </update>
  53. <!-- 查询是否支付 -->
  54. <select id="getPolling" parameterType="String" resultType="int">
  55. select count(*) from bus_pay where release_uuid = #{releUuid} and prepay_id is not null
  56. </select>
  57. <!-- 存入提现记录 -->
  58. <insert id="wxCash" parameterType="WxWithdrawal">
  59. insert into bus_withdrawal(uuid,jdrq,amount,out_trade_no,code)
  60. values(#{uuid},#{jdrq},#{amount},#{outTradeNo},#{code})
  61. </insert>
  62. <!-- 查询指定报价单的支付信息 -->
  63. <select id="getRefundVal" resultType="WxPay" parameterType="String">
  64. SELECT
  65. a.*,
  66. c.balance_of,
  67. c.code
  68. FROM
  69. bus_pay a
  70. LEFT JOIN bus_supplier_release b ON a.release_uuid = b.uuid
  71. LEFT JOIN sys_supplier c ON b.code = c.code
  72. WHERE
  73. a.release_uuid = #{releUuid}
  74. </select>
  75. <!-- 查询退款信息 -->
  76. <select id="getUserRefund" resultType="WxRefund">
  77. SELECT
  78. TOP ${limit} a.*,b.offer_name,b.order_no,b.title_img,c.id as offerCode,d.pay_type as payType,c.name,c.headpir
  79. FROM
  80. bus_refund a
  81. JOIN (select uuid,code,offer_name,jdrq,order_no,title_img from bus_supplier_release where code = #{code} GROUP BY uuid,code,offer_name,jdrq,order_no,title_img) b on a.release_uuid = b.uuid
  82. LEFT JOIN sys_users c on a.code = c.code
  83. LEFT JOIN bus_pay d on a.release_uuid = d.release_uuid
  84. WHERE
  85. a.id NOT IN
  86. (
  87. select
  88. TOP ${page} a.id
  89. FROM
  90. bus_refund a
  91. JOIN (select uuid,code,offer_name,jdrq,order_no from bus_supplier_release where code = #{code} GROUP BY uuid,code,offer_name,jdrq,order_no) b on a.release_uuid = b.uuid
  92. <where>
  93. <if test="startTime != null and startTime != ''">
  94. CONVERT (datetime, b.jdrq) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, b.jdrq) <![CDATA[ <= ]]> #{endTime}
  95. </if>
  96. <if test="offerName != null and offerName != ''">
  97. and b.offer_name like concat('%', #{offerName}, '%')
  98. </if>
  99. </where>
  100. )
  101. <if test="startTime != null and startTime != ''">
  102. and CONVERT (datetime, b.jdrq) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, b.jdrq) <![CDATA[ <= ]]> #{endTime}
  103. </if>
  104. <if test="offerName != null and offerName != ''">
  105. and b.offer_name like concat('%', #{offerName}, '%')
  106. </if>
  107. and a.refund_state = #{refundState}
  108. order by a.id
  109. </select>
  110. <!-- 查询退款信息 -->
  111. <select id="getAuditRefund" resultType="WxRefund">
  112. SELECT
  113. TOP ${limit} a.*,b.offer_name,b.order_no,b.title_img,c.id as offerCode,d.pay_type as payType,c.name,c.headpir
  114. FROM
  115. bus_refund a
  116. JOIN (select uuid,code,offer_name,jdrq,order_no,title_img from bus_supplier_release where code = #{code} GROUP BY uuid,code,offer_name,jdrq,order_no,title_img) b on a.release_uuid = b.uuid
  117. LEFT JOIN sys_users c on a.code = c.code
  118. LEFT JOIN bus_pay d on a.release_uuid = d.release_uuid
  119. WHERE
  120. a.id NOT IN
  121. (
  122. select
  123. TOP ${page} a.id
  124. FROM
  125. bus_refund a
  126. JOIN (select uuid,code,offer_name,jdrq,order_no from bus_supplier_release where code = #{code} GROUP BY uuid,code,offer_name,jdrq,order_no) b on a.release_uuid = b.uuid
  127. <where>
  128. <if test="startTime != null and startTime != ''">
  129. CONVERT (datetime, b.jdrq) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, b.jdrq) <![CDATA[ <= ]]> #{endTime}
  130. </if>
  131. <if test="offerName != null and offerName != ''">
  132. and b.offer_name like concat('%', #{offerName}, '%')
  133. </if>
  134. </where>
  135. )
  136. <if test="startTime != null and startTime != ''">
  137. and CONVERT (datetime, b.jdrq) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, b.jdrq) <![CDATA[ <= ]]> #{endTime}
  138. </if>
  139. <if test="offerName != null and offerName != ''">
  140. and b.offer_name like concat('%', #{offerName}, '%')
  141. </if>
  142. and (a.refund_state = '1' or a.refund_state = '2')
  143. order by a.id
  144. </select>
  145. <!-- 查询退款信息条数 -->
  146. <select id="getUserRefundCount" resultType="int">
  147. SELECT
  148. count(*)
  149. FROM
  150. bus_refund a
  151. JOIN (select uuid,code,offer_name,jdrq,order_no from bus_supplier_release where code = #{code} GROUP BY uuid,code,offer_name,jdrq,order_no) b on a.release_uuid = b.uuid
  152. <trim prefix="WHERE" prefixOverrides="and | or">
  153. <if test="startTime != null and startTime != ''">
  154. and CONVERT (datetime, b.jdrq) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, b.jdrq) <![CDATA[ <= ]]> #{endTime}
  155. </if>
  156. <if test="offerName != null and offerName != ''">
  157. and b.offer_name like concat('%', #{offerName}, '%')
  158. </if>
  159. and a.refund_state = #{refundState}
  160. </trim>
  161. </select>
  162. <!-- 查询退款信息条数 -->
  163. <select id="getAuditRefundCount" resultType="int">
  164. SELECT
  165. count(*)
  166. FROM
  167. bus_refund a
  168. JOIN (select uuid,code,offer_name,jdrq,order_no from bus_supplier_release where code = #{code} GROUP BY uuid,code,offer_name,jdrq,order_no) b on a.release_uuid = b.uuid
  169. <trim prefix="WHERE" prefixOverrides="and | or">
  170. <if test="startTime != null and startTime != ''">
  171. and CONVERT (datetime, b.jdrq) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, b.jdrq) <![CDATA[ <= ]]> #{endTime}
  172. </if>
  173. <if test="offerName != null and offerName != ''">
  174. and b.offer_name like concat('%', #{offerName}, '%')
  175. </if>
  176. and (a.refund_state = '1' or a.refund_state = '2')
  177. </trim>
  178. </select>
  179. <!-- 修改退款状态 -->
  180. <update id="updateRefundType" parameterType="String">
  181. update bus_refund set refund_state = #{refundState} where release_uuid = #{releUuid}
  182. </update>
  183. <!-- 查询指定参数的退款信息 -->
  184. <select id="getRefund" resultType="WxRefund">
  185. select * from bus_refund
  186. <trim prefix="WHERE" prefixOverrides="and | or">
  187. <if test="code != null and code !=''">
  188. and code = #{code}
  189. </if>
  190. <if test="releaseUuid != null and releaseUuid !=''">
  191. and release_uuid = #{releaseUuid}
  192. </if>
  193. </trim>
  194. </select>
  195. <!-- 供应商余额充值记录 -->
  196. <insert id="buySupplierBalance" parameterType="WxPay">
  197. insert into bus_top_up_record(uuid,code,jdrq,total_fee,pay_type)
  198. values(#{uuid},#{code},CONVERT(VARCHAR(100), SYSDATETIME(), 20),#{totalFee},#{payType})
  199. </insert>
  200. <!-- 供应商余额充值 -->
  201. <update id="updateBalance" parameterType="double">
  202. UPDATE sys_supplier
  203. SET balance_of = (SELECT balance_of + ${totalFee} FROM sys_supplier WHERE code = #{code})
  204. WHERE
  205. code = #{code}
  206. </update>
  207. <!-- 子账户余额同步 -->
  208. <update id="updateBalanceChild">
  209. UPDATE sys_supplier
  210. SET balance_of = (SELECT balance_of FROM sys_supplier WHERE code = #{code})
  211. WHERE
  212. account_associated = #{code}
  213. </update>
  214. <!-- 完善充值记录 -->
  215. <update id="updateBuySupplier" parameterType="WxPay">
  216. update bus_top_up_record set jdrq = CONVERT(VARCHAR(100), SYSDATETIME(), 20),total_fee=#{totalFee},pay_type=#{payType} where code = #{code} and uuid = #{uuid}
  217. </update>
  218. <!-- 查询用户是否充值成功 -->
  219. <select id="getTopUp" resultType="int" parameterType="WxPay">
  220. select count(*) from bus_top_up_record where uuid = #{uuid} and code = #{code} and total_fee is not null
  221. </select>
  222. <!-- 查询超时充值记录 -->
  223. <select id="getTopUpTimeOut" resultType="WxPay">
  224. SELECT
  225. *
  226. FROM
  227. bus_top_up_record
  228. where
  229. total_fee is null and CONVERT(DATE, jdrq, 20) <![CDATA[ < ]]> CONVERT(DATE, DATEADD(DAY, -1, SYSDATETIME()))
  230. </select>
  231. <!-- 删除超时充值记录 -->
  232. <delete id="delTopOut">
  233. delete from bus_top_up_record where uuid = #{uuid}
  234. </delete>
  235. <!-- 购买记录添加金额 -->
  236. <update id="updateBuyOfferNum" parameterType="BuyOfferNum">
  237. update bus_buy_offer_num set pay_amount = #{payAmount},pay_type=#{payType} where code = #{code} and uuid = #{uuid}
  238. </update>
  239. <!-- 查询用户是否购买次数成功 -->
  240. <select id="getOfferNum" resultType="int" parameterType="BuyOfferNum">
  241. select count(*) from bus_buy_offer_num where uuid = #{uuid} and code = #{code} and pay_amount is not null
  242. </select>
  243. <!-- 查询超时购买次数记录 -->
  244. <select id="getOfferNumTimeOut" resultType="BuyOfferNum">
  245. SELECT
  246. *
  247. FROM
  248. bus_buy_offer_num
  249. where
  250. pay_amount is null and CONVERT(DATE, jdrq, 20) <![CDATA[ < ]]> CONVERT(DATE, DATEADD(DAY, -1, SYSDATETIME()))
  251. </select>
  252. <!-- 删除超时购买次数记录 -->
  253. <delete id="delOfferNum">
  254. delete from bus_buy_offer_num where uuid = #{uuid}
  255. </delete>
  256. <!-- 用户购买报价单后将资金转入供应商余额 -->
  257. <update id="addSupplierBalanceOf" parameterType="Supplier">
  258. UPDATE sys_supplier
  259. SET balance_of = ( SELECT balance_of + ${balanceOf} FROM sys_supplier WHERE code = #{code} )
  260. WHERE
  261. code = #{code}
  262. </update>
  263. <!-- 用户购买报价单后将资金转入供应商余额子账号同步 -->
  264. <update id="addSupplierBalanceOfChild" parameterType="Supplier">
  265. UPDATE sys_supplier
  266. SET balance_of = ( SELECT balance_of FROM sys_supplier WHERE code = #{code} )
  267. WHERE
  268. account_associated = #{code}
  269. </update>
  270. <!-- 供应商退款后账户余额变更 -->
  271. <update id="subtractBalance" parameterType="Supplier">
  272. UPDATE sys_supplier
  273. SET balance_of = #{bigDecimal2}
  274. WHERE
  275. code = #{code}
  276. </update>
  277. <!-- 查询充值记录 -->
  278. <select id="getTopUpRecord" resultType="TopUpRecord">
  279. select
  280. *
  281. from
  282. bus_top_up_record
  283. <trim prefix="WHERE" prefixOverrides="and | or">
  284. <if test="code != null and code !=''">
  285. and code = #{code}
  286. </if>
  287. </trim>
  288. </select>
  289. </mapper>