You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
15 KiB

2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
1 week ago
2 weeks ago
2 weeks ago
2 weeks ago
2 months ago
  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.example.demo.mapper.cash.CashCollectionMapper">
  4. <insert id="add" parameterType="com.example.demo.domain.entity.CashRecord"
  5. useGeneratedKeys="true" keyProperty="id">
  6. insert into
  7. cash_record_collection(order_type,jwcode,name,market,activity,
  8. order_code,goods_name,good_num,num_unit,permanent_gold,free_gold,
  9. payment_currency,payment_amount,received_market,
  10. pay_type,pay_time,status,submitter_id,submitter_market,
  11. voucher,remark)
  12. values(#{orderType},#{jwcode},#{name},#{market},#{activity},
  13. #{orderCode},#{goodsName},#{goodNum},#{numUnit},#{permanentGold},#{freeGold},#{paymentCurrency},
  14. #{paymentAmount},#{receivedMarket},#{payType},#{payTime},
  15. #{status},#{submitterId},#{submitterMarket},#{voucher},#{remark})
  16. </insert>
  17. <!-- <insert id="syncToCashRecord">
  18. insert into cash_record(order_type,jwcode,name,market,activity,
  19. order_code,goods_name,good_num,permanent_gold,free_gold,
  20. payment_currency,payment_amount,received_market,
  21. pay_type,pay_time,status,submitter_id,
  22. voucher,remark)
  23. values(1,#{jwcode},#{name},#{market},#{activity},
  24. #{order_code},#{goods_name},#{good_num},#{permanent}
  25. )
  26. </insert>-->
  27. <!--更新订单状态-->
  28. <update id="updateStatus">
  29. update cash_record_collection
  30. set status=#{status}
  31. where order_code=#{orderCode}
  32. </update>
  33. <!--更新订单-->
  34. <update id="updateByOrderCode">
  35. UPDATE cash_record_collection
  36. <set>
  37. jwcode = #{cashRecordCollection.jwcode},
  38. name = #{cashRecordCollection.name},
  39. market = #{cashRecordCollection.market},
  40. activity = #{cashRecordCollection.activity},
  41. goods_name = #{cashRecordCollection.goodsName},
  42. good_num = #{cashRecordCollection.goodNum},
  43. num_unit = #{cashRecordCollection.numUnit},
  44. permanent_gold = #{cashRecordCollection.permanentGold},
  45. free_gold = #{cashRecordCollection.freeGold},
  46. payment_currency = #{cashRecordCollection.paymentCurrency},
  47. payment_amount = #{cashRecordCollection.paymentAmount},
  48. received_market = #{cashRecordCollection.receivedMarket},
  49. pay_type = #{cashRecordCollection.payType},
  50. pay_time = #{cashRecordCollection.payTime},
  51. voucher = #{cashRecordCollection.voucher},
  52. remark = #{cashRecordCollection.remark},
  53. status = 0,
  54. </set>
  55. WHERE order_code = #{cashRecordCollection.orderCode}
  56. AND status = 5
  57. </update>
  58. <!--补全手续费等字段-->
  59. <update id="complete">
  60. UPDATE cash_record_collection
  61. <set>
  62. handling_charge = #{cashRecordCollection.handlingCharge},
  63. received_currency = #{cashRecordCollection.receivedCurrency},
  64. <if test="cashRecordCollection.receivedAmount != 0">
  65. received_amount = #{cashRecordCollection.receivedAmount},
  66. </if>
  67. received_time = #{cashRecordCollection.receivedTime},
  68. payment_currency = #{cashRecordCollection.paymentCurrency},
  69. <if test="cashRecordCollection.paymentAmount != 0">
  70. payment_amount = #{cashRecordCollection.paymentAmount},
  71. </if>
  72. <!-- 只有 这些字段全部非空才更新状态 -->
  73. status = CASE
  74. WHEN
  75. handling_charge IS NOT NULL
  76. AND received_currency IS NOT NULL AND received_currency != ''
  77. AND received_amount IS NOT NULL
  78. AND received_time IS NOT NULL
  79. AND payment_currency IS NOT NULL AND payment_currency != ''
  80. AND payment_amount IS NOT NULL
  81. THEN 4
  82. ELSE status
  83. END
  84. </set>
  85. WHERE order_code = #{cashRecordCollection.orderCode}
  86. AND status IN (1, 3)
  87. </update>
  88. <!--设置gOrder订单为已同步-->
  89. <update id="markSynced">
  90. update g_order
  91. set is_synced = 1
  92. where id = #{orderId}
  93. </update>
  94. <!--根据jwcode获取所属地区-->
  95. <select id="getMarketByJwcode" resultType="java.lang.String">
  96. select market from user where jwcode=#{jwcode}
  97. </select>
  98. <!--根据订单号获取订单id与状态-->
  99. <select id="selectByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  100. select id ,status
  101. from cash_record_collection
  102. where order_code=#{orderCode}
  103. </select>
  104. <!--多条件查询收款订单列表-->
  105. <select id="selectCollection1" resultType="com.example.demo.domain.vo.cash.CashCollection">
  106. select cr.order_type, cr.id,cr.jwcode,cr.name,cr.market,
  107. m1.name as marketName, ra.id as activityId,
  108. ra.activity_name as activity,cr.order_code,cr.bank_code,
  109. cr.goods_name,cr.good_num,
  110. cr.num_unit,
  111. cr.permanent_gold/100 as permanentGold,cr.free_gold/100 as freeGold,cr.payment_amount/100 as paymentAmount,
  112. r1.rate_name as paymentCurrency,
  113. r2.rate_name as receivedCurrency,
  114. m2.name as receivedMarket,
  115. cr.received_amount/100 as receivedAmount,cr.handling_charge/100 as handlingCharge,
  116. cr.pay_type,cr.pay_time,cr.received_time,
  117. cr.status,cr.submitter_id,cr.submitter_market,cr.voucher,cr.remark,cr.reject_reason,
  118. cr.audit_id,cr.create_time,cr.update_time,cr.audit_time,
  119. a1.admin_name as submitterName,
  120. a2.admin_name as auditName
  121. from cash_record_collection cr
  122. left join admin a1 on cr.submitter_id = a1.id
  123. left join admin a2 on cr.audit_id = a2.id
  124. left join market m1 on m1.id = cr.market
  125. left join market m2 on m2.id = cr.received_market
  126. left join rate r1 on r1.id = cr.payment_currency
  127. left join rate r2 on r2.id = cr.received_currency
  128. left join recharge_activity ra on ra.id = cr.activity
  129. <where>
  130. 1 = 1
  131. <if test="cashCollection.market != null and cashCollection.market != ''">
  132. AND cr.market = #{cashCollection.market}
  133. </if>
  134. <if test="cashCollection.jwcode != null and cashCollection.jwcode!=''">
  135. AND cr.jwcode = #{cashCollection.jwcode}
  136. </if>
  137. <if test="cashCollection.name!=null and cashCollection.name !=''">
  138. AND cr.name like concat('%',#{cashCollection.name},'%')
  139. </if>
  140. <if test="cashCollection.submitterId!=null and cashCollection.submitterId !=''">
  141. AND cr.submitter_id = #{cashCollection.submitterId}
  142. </if>
  143. <!-- 其他原有条件不变 -->
  144. <choose>
  145. <when test="cashCollection.status != null and (cashCollection.status == 46||cashCollection.status == 13)">
  146. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  147. AND (cr.received_market = #{cashCollection.receivedMarket}
  148. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  149. OR cr.submitter_market = #{cashCollection.submitterMarket}
  150. </if>
  151. )
  152. </if>
  153. <if test="(cashCollection.receivedMarket == null or cashCollection.receivedMarket == '')
  154. and cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  155. AND cr.submitter_market = #{cashCollection.submitterMarket}
  156. </if>
  157. </when>
  158. <!-- 非 status=46 保持原逻辑:同时满足 -->
  159. <otherwise>
  160. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  161. AND cr.received_market = #{cashCollection.receivedMarket}
  162. </if>
  163. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  164. AND cr.submitter_market = #{cashCollection.submitterMarket}
  165. </if>
  166. </otherwise>
  167. </choose>
  168. <if test="cashCollection.activity!=null and cashCollection.activity!=''">
  169. AND cr.activity =#{cashCollection.activity}
  170. </if>
  171. <if test="cashCollection.paymentCurrency!=null and cashCollection.paymentCurrency!=''">
  172. AND cr.payment_currency like concat('%',#{cashCollection.paymentCurrency},'%')
  173. </if>
  174. <if test="cashCollection.goodsName!=null and cashCollection.goodsName!=''">
  175. AND cr.goods_name like concat('%',#{cashCollection.goodsName},'%')
  176. </if>
  177. <if test="cashCollection.payType!=null and cashCollection.payType!=''">
  178. AND cr.pay_type = #{cashCollection.payType}
  179. </if>
  180. <if test="cashCollection.status != null">
  181. AND cr.status IN
  182. <foreach collection="cashCollection.status.toString().toCharArray()" item="digit" open="(" separator="," close=")">
  183. #{digit}
  184. </foreach>
  185. </if>
  186. <if test="cashCollection.startTime!=null and cashCollection.endTime!=null">
  187. AND cr.pay_time between #{cashCollection.startTime} and #{cashCollection.endTime}
  188. </if>
  189. and cr.order_type=1
  190. </where>
  191. <choose>
  192. <when test="cashCollection.sortField != null and cashCollection.sortField.length > 0 or cashCollection.sortOrder != null and cashCollection.sortOrder.length > 0">
  193. ORDER BY ${cashCollection.sortField} ${cashCollection.sortOrder}
  194. </when>
  195. <otherwise>
  196. ORDER BY create_time DESC
  197. </otherwise>
  198. </choose>
  199. </select>
  200. <select id="selectAuditByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  201. select crc.id,jwcode,name,market,ra.activity_name as activity,
  202. order_code,bank_code,goods_name,good_num,num_unit,permanent_gold,free_gold,
  203. payment_currency,payment_amount,pay_type,pay_time,crc.status,submitter_id,
  204. voucher,remark
  205. from cash_record_collection crc
  206. left join recharge_activity ra on ra.id = crc.activity
  207. where order_code=#{orderCode}
  208. </select>
  209. <!--根据精网号获取姓名-->
  210. <select id="getNameByJwcode" resultType="java.lang.String">
  211. select name from user where jwcode=#{jwcode}
  212. </select>
  213. <select id="getMarketNameByJwcode" resultType="java.lang.String">
  214. select m.name from user u left join market m on u.market=m.id
  215. where u.jwcode=#{jwcode}</select>
  216. <select id="getActivityList" resultType="com.example.demo.domain.entity.RechargeActivity">
  217. select ra.id,ra.activity_name,ra.business_belong,m.name as area,ra.status
  218. from recharge_activity ra
  219. left join market m on m.id=ra.area
  220. where ra.flag=1
  221. </select>
  222. <!--查找未同步的订单-->
  223. <select id="getUnSync" resultType="com.example.demo.domain.entity.GOrder">
  224. select id,jwcode,order_no,type,price,count,pay_style,state,
  225. success_time,ios_environment,ios_transaction_id,ios_receipt_data,
  226. add_time,is_synced
  227. from g_order
  228. where is_synced=0 and state=1 and type='gold_coin' and pay_style in(3,5,6,7,9)
  229. limit #{size}
  230. </select>
  231. <select id="selectById" resultType="com.example.demo.domain.vo.cash.CashCollection">
  232. select cr.id,cr.jwcode,cr.name,cr.market,
  233. cr.order_code,cr.bank_code,cr.goods_name,cr.good_num,cr.num_unit,cr.permanent_gold,cr.free_gold,
  234. cr.payment_currency,cr.payment_amount,cr.received_currency,cr.received_amount,cr.handling_charge,
  235. cr.pay_type,cr.received_market,cr.pay_time,cr.received_time,cr.audit_id,cr.status,cr.submitter_id,
  236. cr.submitter_market,cr.voucher,cr.remark,cr.audit_time,a1.admin_name as submitterName,
  237. a2.admin_name as auditName,ra.activity_name as activity
  238. from cash_record_collection cr
  239. left join admin a1 on cr.submitter_id = a1.id
  240. left join admin a2 on cr.audit_id = a2.id
  241. left join recharge_activity ra on ra.id = cr.activity
  242. where cr.id=#{id}
  243. </select>
  244. <!--根据id查询收款订单-->
  245. <select id="selectBatchIds" resultType="com.example.demo.domain.vo.cash.CashCollection">
  246. select
  247. cr.id, cr.jwcode, cr.name, cr.market,
  248. cr.order_code, cr.bank_code, cr.goods_name, cr.good_num, cr.num_unit, cr.permanent_gold, cr.free_gold,
  249. cr.payment_amount, cr.received_amount, cr.handling_charge,
  250. cr.pay_type, cr.received_market, cr.pay_time, cr.received_time, cr.audit_id, cr.status, cr.submitter_id,
  251. cr.submitter_market, cr.voucher, cr.remark, cr.audit_time,
  252. a1.admin_name as submitterName,
  253. a2.admin_name as auditName,
  254. ra.activity_name as activity,
  255. r1.rate_name as paymentCurrency,
  256. r2.rate_name as receivedCurrency
  257. from cash_record_collection cr
  258. left join admin a1 on cr.submitter_id = a1.id
  259. left join admin a2 on cr.audit_id = a2.id
  260. left join recharge_activity ra on ra.id = cr.activity
  261. left join rate r1 on r1.id = cr.payment_currency
  262. left join rate r2 on r2.id = cr.received_currency
  263. where 1 = 0
  264. <if test="relatedIds != null and relatedIds.size() > 0">
  265. OR cr.id IN
  266. <foreach collection="relatedIds" item="id" open="(" separator="," close=")">
  267. #{id}
  268. </foreach>
  269. </if>
  270. </select>
  271. <select id="selectByGoldCoinOrderCode" resultType="com.example.demo.domain.vo.cash.CashCollection">
  272. select * from cash_record_collection where order_no=#{orderNo}
  273. </select>
  274. <!--根据glodcoin订单号更新收款订单-->
  275. <update id="updateByGoldCoinOrderCode">
  276. update cash_record_collection
  277. <set>
  278. received_time=#{time},
  279. payment_currency=#{currency},
  280. received_currency=#{currency},
  281. payment_amount=#{order_amount},
  282. received_amount=#{net_amount},
  283. handling_charge=#{charge},
  284. order_no_status=0
  285. </set>
  286. where order_code=#{merchant_reference}
  287. </update>
  288. </mapper>