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.

468 lines
22 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
3 months ago
3 months ago
3 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
4 weeks ago
5 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,bank_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,payload,audit_time,
  11. voucher,remark)
  12. values(#{orderType},#{jwcode},#{name},#{market},#{activity},
  13. #{orderCode},#{bankCode},#{goodsName},#{goodNum},#{numUnit},#{permanentGold},#{freeGold},#{paymentCurrency},
  14. #{paymentAmount},#{receivedMarket},#{payType},#{payTime},
  15. #{status},#{submitterId},#{submitterMarket},#{payload},#{auditTime},#{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. payment_currency_orig = #{cashRecordCollection.paymentCurrencyOrig},
  73. <if test="cashRecordCollection.paymentAmountOrig != 0">
  74. payment_amount_orig = #{cashRecordCollection.paymentAmountOrig},
  75. </if>
  76. <!-- 只有 这些字段全部非空才更新状态 -->
  77. status = CASE
  78. WHEN
  79. handling_charge IS NOT NULL
  80. AND received_currency IS NOT NULL AND received_currency != ''
  81. AND received_amount IS NOT NULL
  82. AND received_time IS NOT NULL
  83. AND payment_currency IS NOT NULL AND payment_currency != ''
  84. AND payment_amount IS NOT NULL
  85. THEN 4
  86. ELSE status
  87. END
  88. </set>
  89. WHERE order_code = #{cashRecordCollection.orderCode}
  90. AND status IN (1, 3)
  91. </update>
  92. <!--提交手续费时修改金币订单-->
  93. <update id="updateGoldOrder">
  94. UPDATE user_gold_record
  95. <set>
  96. rate_id=#{cashRecordCollection.paymentCurrency},
  97. <if test="cashRecordCollection.paymentAmount != 0">
  98. money = #{cashRecordCollection.paymentAmount}
  99. </if>
  100. </set>
  101. WHERE order_code = #{cashRecordCollection.orderCode}
  102. </update>
  103. <!--设置gOrder订单为已同步-->
  104. <update id="markSynced">
  105. update g_order
  106. set is_synced = 1
  107. where id = #{orderId}
  108. </update>
  109. <!-- 检查用户是否存在 -->
  110. <select id="checkUserExists" resultType="int">
  111. SELECT COUNT(*)
  112. FROM user
  113. WHERE jwcode = #{jwcode}
  114. </select>
  115. <!--根据jwcode获取所属地区-->
  116. <select id="getMarketByJwcode" resultType="java.lang.String">
  117. select market from user where jwcode=#{jwcode}
  118. </select>
  119. <!--根据订单号获取订单id与状态-->
  120. <select id="selectByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  121. select id ,status
  122. from cash_record_collection
  123. where order_code=#{orderCode}
  124. </select>
  125. <!--多条件查询收款订单列表-->
  126. <select id="selectCollection1" resultType="com.example.demo.domain.vo.cash.CashCollection">
  127. select cr.order_type, cr.id,cr.jwcode,cr.name,cr.market,
  128. m1.name as marketName, ra.id as activityId,
  129. ra.activity_name as activity,cr.order_code,cr.bank_code,
  130. cr.goods_name,cr.good_num,
  131. cr.num_unit,
  132. cr.permanent_gold/100 as permanentGold,cr.free_gold/100 as freeGold,cr.payment_amount/100 as paymentAmount,
  133. r1.rate_name as paymentCurrency,
  134. r2.rate_name as receivedCurrency,
  135. m2.name as receivedMarket,
  136. cr.received_amount/100 as receivedAmount,cr.handling_charge/100 as handlingCharge,
  137. cr.pay_type,cr.pay_time,cr.received_time,
  138. cr.status,cr.submitter_id,cr.submitter_market,cr.voucher,cr.remark,cr.reject_reason,
  139. cr.audit_id,cr.create_time,cr.update_time,cr.audit_time,
  140. a1.admin_name as submitterName,
  141. a2.admin_name as auditName
  142. from cash_record_collection cr
  143. left join admin a1 on cr.submitter_id = a1.id
  144. left join admin a2 on cr.audit_id = a2.id
  145. left join market m1 on m1.id = cr.market
  146. left join market m2 on m2.id = cr.received_market
  147. left join rate r1 on r1.id = cr.payment_currency
  148. left join rate r2 on r2.id = cr.received_currency
  149. left join recharge_activity ra on ra.id = cr.activity
  150. <where>
  151. 1 = 1
  152. <if test="cashCollection.market != null and cashCollection.market != ''">
  153. AND cr.market = #{cashCollection.market}
  154. </if>
  155. <if test="cashCollection.jwcode != null and cashCollection.jwcode!=''">
  156. AND cr.jwcode = #{cashCollection.jwcode}
  157. </if>
  158. <if test="cashCollection.name!=null and cashCollection.name !=''">
  159. AND cr.name like concat('%',#{cashCollection.name},'%')
  160. </if>
  161. <if test="cashCollection.submitterId!=null and cashCollection.submitterId !=''">
  162. AND cr.submitter_id = #{cashCollection.submitterId}
  163. </if>
  164. <!-- 其他原有条件不变 -->
  165. <choose>
  166. <when test="cashCollection.status != null and (cashCollection.status == 46||cashCollection.status == 13)">
  167. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  168. AND (cr.received_market = #{cashCollection.receivedMarket}
  169. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  170. OR cr.submitter_market = #{cashCollection.submitterMarket}
  171. </if>
  172. )
  173. </if>
  174. <if test="(cashCollection.receivedMarket == null or cashCollection.receivedMarket == '')
  175. and cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  176. AND cr.submitter_market = #{cashCollection.submitterMarket}
  177. </if>
  178. </when>
  179. <!-- 非 status=46 保持原逻辑:同时满足 -->
  180. <otherwise>
  181. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  182. AND cr.received_market = #{cashCollection.receivedMarket}
  183. </if>
  184. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  185. AND cr.submitter_market = #{cashCollection.submitterMarket}
  186. </if>
  187. </otherwise>
  188. </choose>
  189. <if test="cashCollection.activity!=null and cashCollection.activity!=''">
  190. AND cr.activity =#{cashCollection.activity}
  191. </if>
  192. <if test="cashCollection.paymentCurrency!=null and cashCollection.paymentCurrency!=''">
  193. AND cr.payment_currency like concat('%',#{cashCollection.paymentCurrency},'%')
  194. </if>
  195. <if test="cashCollection.goodsName!=null and cashCollection.goodsName!=''">
  196. AND cr.goods_name like concat('%',#{cashCollection.goodsName},'%')
  197. </if>
  198. <if test="cashCollection.payType!=null and cashCollection.payType!=''">
  199. AND cr.pay_type = #{cashCollection.payType}
  200. </if>
  201. <if test="cashCollection.status != null">
  202. AND cr.status IN
  203. <foreach collection="cashCollection.status.toString().toCharArray()" item="digit" open="(" separator="," close=")">
  204. #{digit}
  205. </foreach>
  206. </if>
  207. <if test="cashCollection.startTime!=null and cashCollection.endTime!=null">
  208. AND cr.pay_time between #{cashCollection.startTime} and #{cashCollection.endTime}
  209. </if>
  210. and cr.order_type=1
  211. </where>
  212. <choose>
  213. <when test="cashCollection.sortField != null and cashCollection.sortField.length > 0 or cashCollection.sortOrder != null and cashCollection.sortOrder.length > 0">
  214. ORDER BY ${cashCollection.sortField} ${cashCollection.sortOrder}
  215. </when>
  216. <otherwise>
  217. ORDER BY pay_time DESC
  218. </otherwise>
  219. </choose>
  220. </select>
  221. <select id="selectAuditByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  222. select crc.id,jwcode,name,market,ra.activity_name as activity,
  223. order_code,bank_code,goods_name,good_num,num_unit,permanent_gold,free_gold,
  224. payment_currency,payment_amount,pay_type,pay_time,crc.status,submitter_id,
  225. voucher,remark,version,received_market
  226. from cash_record_collection crc
  227. left join recharge_activity ra on ra.id = crc.activity
  228. where order_code=#{orderCode}
  229. </select>
  230. <!--根据精网号获取姓名-->
  231. <select id="getNameByJwcode" resultType="java.lang.String">
  232. select name from user where jwcode=#{jwcode}
  233. </select>
  234. <select id="getMarketNameByJwcode" resultType="java.lang.String">
  235. select m.name from user u left join market m on u.market=m.id
  236. where u.jwcode=#{jwcode}</select>
  237. <select id="getActivityList" resultType="com.example.demo.domain.entity.RechargeActivity">
  238. select ra.id,ra.activity_name,ra.business_belong,m.name as area,ra.status
  239. from recharge_activity ra
  240. left join market m on m.id=ra.area
  241. where ra.flag=1 and ra.status=1 and #{now} between start_time and end_time
  242. <if test="activity != null and activity != ''">
  243. AND ra.activity_name like concat('%',#{activity},'%')
  244. </if>
  245. </select>
  246. <!--查找未同步的订单-->
  247. <select id="getUnSync" resultType="com.example.demo.domain.entity.GOrder">
  248. select id,jwcode,order_no,type,price,count,pay_style,state,
  249. success_time,ios_environment,ios_transaction_id,ios_receipt_data,firstdata_ipgTransactionId,
  250. add_time,is_synced
  251. from g_order
  252. where is_synced=0 and state=1 and pay_style in(3,5,6,7,9,10,15)
  253. and success_time>=1767196800
  254. limit #{size}
  255. </select>
  256. <select id="selectById" resultType="com.example.demo.domain.vo.cash.CashCollection">
  257. select cr.id,cr.jwcode,cr.name,cr.market,
  258. cr.order_code,cr.bank_code,cr.goods_name,cr.good_num,cr.num_unit,cr.permanent_gold,cr.free_gold,
  259. cr.payment_currency,cr.payment_amount,cr.received_currency,cr.received_amount,cr.handling_charge,
  260. cr.pay_type,cr.received_market,cr.pay_time,cr.received_time,cr.audit_id,cr.status,cr.submitter_id,
  261. cr.submitter_market,cr.voucher,cr.remark,cr.audit_time,a1.admin_name as submitterName,
  262. a2.admin_name as auditName,ra.activity_name as activity
  263. from cash_record_collection cr
  264. left join admin a1 on cr.submitter_id = a1.id
  265. left join admin a2 on cr.audit_id = a2.id
  266. left join recharge_activity ra on ra.id = cr.activity
  267. where cr.id=#{id}
  268. </select>
  269. <!--根据id查询收款订单-->
  270. <select id="selectBatchIds" resultType="com.example.demo.domain.vo.cash.CashCollection">
  271. select
  272. cr.id, cr.jwcode, cr.name, cr.market,
  273. cr.order_code, cr.bank_code, cr.goods_name, cr.good_num, cr.num_unit, cr.permanent_gold, cr.free_gold,
  274. cr.payment_amount, cr.received_amount, cr.handling_charge,
  275. cr.pay_type, cr.received_market, cr.pay_time, cr.received_time, cr.audit_id, cr.status, cr.submitter_id,
  276. cr.submitter_market, cr.voucher, cr.remark, cr.audit_time,
  277. a1.admin_name as submitterName,
  278. a2.admin_name as auditName,
  279. ra.activity_name as activity,
  280. r1.rate_name as paymentCurrency,
  281. r2.rate_name as receivedCurrency
  282. from cash_record_collection cr
  283. left join admin a1 on cr.submitter_id = a1.id
  284. left join admin a2 on cr.audit_id = a2.id
  285. left join recharge_activity ra on ra.id = cr.activity
  286. left join rate r1 on r1.id = cr.payment_currency
  287. left join rate r2 on r2.id = cr.received_currency
  288. where 1 = 0
  289. <if test="relatedIds != null and relatedIds.size() > 0">
  290. OR cr.id IN
  291. <foreach collection="relatedIds" item="id" open="(" separator="," close=")">
  292. #{id}
  293. </foreach>
  294. </if>
  295. </select>
  296. <select id="selectByGoldCoinOrderCode" resultType="com.example.demo.domain.vo.cash.CashCollection">
  297. select * from cash_record_collection where order_no=#{orderNo}
  298. </select>
  299. <!--根据glodcoin订单号更新收款订单-->
  300. <update id="updateByGoldCoinOrderCode">
  301. update cash_record_collection
  302. <set>
  303. received_time=#{time},
  304. payment_currency=#{currency},
  305. received_currency=#{currency},
  306. payment_amount=#{order_amount},
  307. received_amount=#{net_amount},
  308. handling_charge=#{charge},
  309. order_no_status=0
  310. </set>
  311. where order_code=#{merchant_reference}
  312. </update>
  313. <update id="updateOrderWithVersion">
  314. UPDATE cash_record_collection
  315. SET status = #{status},
  316. audit_id = #{auditId},
  317. version = version + 1
  318. WHERE order_code = #{orderCode}
  319. AND status = 0
  320. AND version = #{version}
  321. </update>
  322. <select id="performanceSelect" resultType="com.example.demo.domain.vo.cash.PerformanceVO" parameterType="com.example.demo.domain.DTO.PerformanceDTO">
  323. select cr.jwcode,cr.name,cr.market,m.name as marketName,cr.order_code,r1.rate_name as paymentCurrency,cr.payment_amount,r2.rate_name as receivedCurrency,cr.received_amount,cr.handling_charge
  324. from cash_record_collection cr
  325. left join market m on m.id = cr.market
  326. left join rate r1 on r1.id = cr.payment_currency
  327. left join rate r2 on r2.id = cr.received_currency
  328. where order_type = 1 and status = 4
  329. <!-- adminMarket筛选:如果adminMarket列表不为空且不包含研发部或总部,则筛选market表中的name等于adminMarket列表中的内容 -->
  330. <if test="adminMarket != null and adminMarket.size() > 0">
  331. <choose>
  332. <when test="adminMarket.contains('研发部'.toString()) or adminMarket.contains('总部'.toString())">
  333. <!-- 如果包含研发部或总部,则不筛选 -->
  334. </when>
  335. <otherwise>
  336. AND m.name IN
  337. <foreach collection="adminMarket" item="item" open="(" separator="," close=")">
  338. #{item}
  339. </foreach>
  340. </otherwise>
  341. </choose>
  342. </if>
  343. <!-- customerMarket筛选:如果customerMarket列表不为空,则筛选cash_record_collection表中的market等于customerMarket列表中的内容 -->
  344. <if test="customerMarket != null and customerMarket.size() > 0">
  345. AND cr.market IN
  346. <foreach collection="customerMarket" item="item" open="(" separator="," close=")">
  347. #{item}
  348. </foreach>
  349. </if>
  350. <!-- jwcode筛选:如果jwcode不为空,则筛选cash_record_collection表中的jwcode等于jwcode -->
  351. <if test="jwcode != null and jwcode != ''">
  352. AND cr.jwcode = #{jwcode}
  353. </if>
  354. <!-- 时间范围筛选:如果startTime和endTime不为空,则筛选cash_record_collection表中的pay_time在startTime和endTime之间 -->
  355. <if test="startTime != null and endTime != null">
  356. AND cr.pay_time BETWEEN #{startTime} AND #{endTime}
  357. </if>
  358. </select>
  359. <select id="selectByBankCode" resultType="com.example.demo.domain.vo.cash.CashCollection">
  360. select * from cash_record_collection where bank_code=#{bankCode}
  361. </select>
  362. <select id="selectFirstdataList" resultType="java.lang.String">
  363. select bank_code from cash_record_collection where bank_code is not null and payload='FirstData' and order_no_status=1
  364. </select>
  365. <select id="selectStripeList" resultType="java.lang.String">
  366. select order_code from cash_record_collection where payload='Stripe' and order_no_status=1
  367. </select>
  368. <select id="selectStripe2List" resultType="java.lang.String">
  369. select order_code from cash_record_collection where payload='Stripe2' and order_no_status=1
  370. </select>
  371. <select id="selectPaymentList" resultType="java.lang.String">
  372. select order_code from cash_record_collection where payload='PaymentAsia' and order_no_status=1
  373. </select>
  374. <select id="selectIpayList" resultType="com.example.demo.domain.vo.cash.CashCollection">
  375. select order_code,permanent_gold from cash_record_collection where payload='Ipay88' and order_no_status=1
  376. </select>
  377. <!--根据订单号获取商品名称-->
  378. <select id="selectGoodsNameByCode" resultType="java.lang.String">
  379. select goods_name from cash_record_collection where order_code=#{orderCode}
  380. </select>
  381. <!--根据OrderCode订单号更新收款订单-->
  382. <update id="updateByGoldCoinOrderCodeByPayment">
  383. update cash_record_collection
  384. SET
  385. received_time=#{time},
  386. payment_currency='2',
  387. received_currency='2',
  388. payment_amount=#{order_amount},
  389. received_amount=#{net_amount},
  390. handling_charge=#{charge},
  391. status=4,
  392. order_no_status=0
  393. where order_code=#{merchant_reference}
  394. </update>
  395. <!--根据OrderCode订单号更新收款订单-->
  396. <update id="updateByGoldCoinOrderCodeByStripe">
  397. update cash_record_collection
  398. SET
  399. received_time=#{availableOn},
  400. payment_currency='2',
  401. received_currency='2',
  402. payment_amount=#{amount},
  403. received_amount=#{net},
  404. handling_charge=#{fee},
  405. status=4,
  406. order_no_status=0
  407. where order_code=#{orderNo}
  408. </update>
  409. <!--根据OrderCode订单号更新收款订单-->
  410. <update id="updateByGoldCoinOrderCodeByStripe2">
  411. update cash_record_collection
  412. SET
  413. received_time=#{availableOn},
  414. payment_currency='3',
  415. received_currency='3',
  416. payment_amount=#{amount},
  417. received_amount=#{net},
  418. handling_charge=#{fee},
  419. status=4,
  420. order_no_status=0
  421. where order_code=#{orderNo}
  422. </update>
  423. <update id="updateByGoldCoinOrderCodeByFirstdata">
  424. update cash_record_collection
  425. SET
  426. payment_currency='3',
  427. received_currency='3',
  428. payment_amount=#{amount},
  429. received_amount=#{net},
  430. handling_charge=#{fee},
  431. status=4,
  432. order_no_status=0
  433. where order_code=#{orderId}
  434. </update>
  435. <update id="updateByGoldCoinOrderCodeByIpay88">
  436. update cash_record_collection
  437. SET
  438. payment_currency='4',
  439. received_currency='4',
  440. payment_amount=#{amount},
  441. received_amount=#{net},
  442. handling_charge=#{fee},
  443. status=4,
  444. order_no_status=0
  445. where order_code=#{orderNo}
  446. </update>
  447. <update id="updateMessageFlagByTypeIdAndType">
  448. UPDATE message
  449. SET flag = #{flag}
  450. WHERE type_id = #{typeId} AND type = #{type}
  451. </update>
  452. </mapper>