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.

464 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
  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. </select>
  243. <!--查找未同步的订单-->
  244. <select id="getUnSync" resultType="com.example.demo.domain.entity.GOrder">
  245. select id,jwcode,order_no,type,price,count,pay_style,state,
  246. success_time,ios_environment,ios_transaction_id,ios_receipt_data,firstdata_ipgTransactionId,
  247. add_time,is_synced
  248. from g_order
  249. where is_synced=0 and state=1 and pay_style in(3,5,6,7,9,10,15)
  250. and success_time>=1767196800
  251. limit #{size}
  252. </select>
  253. <select id="selectById" resultType="com.example.demo.domain.vo.cash.CashCollection">
  254. select cr.id,cr.jwcode,cr.name,cr.market,
  255. cr.order_code,cr.bank_code,cr.goods_name,cr.good_num,cr.num_unit,cr.permanent_gold,cr.free_gold,
  256. cr.payment_currency,cr.payment_amount,cr.received_currency,cr.received_amount,cr.handling_charge,
  257. cr.pay_type,cr.received_market,cr.pay_time,cr.received_time,cr.audit_id,cr.status,cr.submitter_id,
  258. cr.submitter_market,cr.voucher,cr.remark,cr.audit_time,a1.admin_name as submitterName,
  259. a2.admin_name as auditName,ra.activity_name as activity
  260. from cash_record_collection cr
  261. left join admin a1 on cr.submitter_id = a1.id
  262. left join admin a2 on cr.audit_id = a2.id
  263. left join recharge_activity ra on ra.id = cr.activity
  264. where cr.id=#{id}
  265. </select>
  266. <!--根据id查询收款订单-->
  267. <select id="selectBatchIds" resultType="com.example.demo.domain.vo.cash.CashCollection">
  268. select
  269. cr.id, cr.jwcode, cr.name, cr.market,
  270. cr.order_code, cr.bank_code, cr.goods_name, cr.good_num, cr.num_unit, cr.permanent_gold, cr.free_gold,
  271. cr.payment_amount, cr.received_amount, cr.handling_charge,
  272. cr.pay_type, cr.received_market, cr.pay_time, cr.received_time, cr.audit_id, cr.status, cr.submitter_id,
  273. cr.submitter_market, cr.voucher, cr.remark, cr.audit_time,
  274. a1.admin_name as submitterName,
  275. a2.admin_name as auditName,
  276. ra.activity_name as activity,
  277. r1.rate_name as paymentCurrency,
  278. r2.rate_name as receivedCurrency
  279. from cash_record_collection cr
  280. left join admin a1 on cr.submitter_id = a1.id
  281. left join admin a2 on cr.audit_id = a2.id
  282. left join recharge_activity ra on ra.id = cr.activity
  283. left join rate r1 on r1.id = cr.payment_currency
  284. left join rate r2 on r2.id = cr.received_currency
  285. where 1 = 0
  286. <if test="relatedIds != null and relatedIds.size() > 0">
  287. OR cr.id IN
  288. <foreach collection="relatedIds" item="id" open="(" separator="," close=")">
  289. #{id}
  290. </foreach>
  291. </if>
  292. </select>
  293. <select id="selectByGoldCoinOrderCode" resultType="com.example.demo.domain.vo.cash.CashCollection">
  294. select * from cash_record_collection where order_no=#{orderNo}
  295. </select>
  296. <!--根据glodcoin订单号更新收款订单-->
  297. <update id="updateByGoldCoinOrderCode">
  298. update cash_record_collection
  299. <set>
  300. received_time=#{time},
  301. payment_currency=#{currency},
  302. received_currency=#{currency},
  303. payment_amount=#{order_amount},
  304. received_amount=#{net_amount},
  305. handling_charge=#{charge},
  306. order_no_status=0
  307. </set>
  308. where order_code=#{merchant_reference}
  309. </update>
  310. <update id="updateOrderWithVersion">
  311. UPDATE cash_record_collection
  312. SET status = #{status},
  313. audit_id = #{auditId},
  314. version = version + 1
  315. WHERE order_code = #{orderCode}
  316. AND status = 0
  317. AND version = #{version}
  318. </update>
  319. <select id="performanceSelect" resultType="com.example.demo.domain.vo.cash.PerformanceVO" parameterType="com.example.demo.domain.DTO.PerformanceDTO">
  320. 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
  321. from cash_record_collection cr
  322. left join market m on m.id = cr.market
  323. left join rate r1 on r1.id = cr.payment_currency
  324. left join rate r2 on r2.id = cr.received_currency
  325. where order_type = 1 and status = 4
  326. <!-- adminMarket筛选:如果adminMarket列表不为空且不包含研发部或总部,则筛选market表中的name等于adminMarket列表中的内容 -->
  327. <if test="adminMarket != null and adminMarket.size() > 0">
  328. <choose>
  329. <when test="adminMarket.contains('研发部'.toString()) or adminMarket.contains('总部'.toString())">
  330. <!-- 如果包含研发部或总部,则不筛选 -->
  331. </when>
  332. <otherwise>
  333. AND m.name IN
  334. <foreach collection="adminMarket" item="item" open="(" separator="," close=")">
  335. #{item}
  336. </foreach>
  337. </otherwise>
  338. </choose>
  339. </if>
  340. <!-- customerMarket筛选:如果customerMarket列表不为空,则筛选cash_record_collection表中的market等于customerMarket列表中的内容 -->
  341. <if test="customerMarket != null and customerMarket.size() > 0">
  342. AND cr.market IN
  343. <foreach collection="customerMarket" item="item" open="(" separator="," close=")">
  344. #{item}
  345. </foreach>
  346. </if>
  347. <!-- jwcode筛选:如果jwcode不为空,则筛选cash_record_collection表中的jwcode等于jwcode -->
  348. <if test="jwcode != null and jwcode != ''">
  349. AND cr.jwcode = #{jwcode}
  350. </if>
  351. <!-- 时间范围筛选:如果startTime和endTime不为空,则筛选cash_record_collection表中的pay_time在startTime和endTime之间 -->
  352. <if test="startTime != null and endTime != null">
  353. AND cr.pay_time BETWEEN #{startTime} AND #{endTime}
  354. </if>
  355. </select>
  356. <select id="selectByBankCode" resultType="com.example.demo.domain.vo.cash.CashCollection">
  357. select * from cash_record_collection where bank_code=#{bankCode}
  358. </select>
  359. <select id="selectFirstdataList" resultType="java.lang.String">
  360. select bank_code from cash_record_collection where bank_code is not null and payload='FirstData' and order_no_status=1
  361. </select>
  362. <select id="selectStripeList" resultType="java.lang.String">
  363. select order_code from cash_record_collection where payload='Stripe' and order_no_status=1
  364. </select>
  365. <select id="selectStripe2List" resultType="java.lang.String">
  366. select order_code from cash_record_collection where payload='Stripe2' and order_no_status=1
  367. </select>
  368. <select id="selectPaymentList" resultType="java.lang.String">
  369. select order_code from cash_record_collection where payload='PaymentAsia' and order_no_status=1
  370. </select>
  371. <select id="selectIpayList" resultType="com.example.demo.domain.vo.cash.CashCollection">
  372. select order_code,permanent_gold from cash_record_collection where payload='Ipay88' and order_no_status=1
  373. </select>
  374. <!--根据订单号获取商品名称-->
  375. <select id="selectGoodsNameByCode" resultType="java.lang.String">
  376. select goods_name from cash_record_collection where order_code=#{orderCode}
  377. </select>
  378. <!--根据OrderCode订单号更新收款订单-->
  379. <update id="updateByGoldCoinOrderCodeByPayment">
  380. update cash_record_collection
  381. SET
  382. received_time=#{time},
  383. payment_currency='2',
  384. received_currency='2',
  385. payment_amount=#{order_amount},
  386. received_amount=#{net_amount},
  387. handling_charge=#{charge},
  388. status=4,
  389. order_no_status=0
  390. where order_code=#{merchant_reference}
  391. </update>
  392. <!--根据OrderCode订单号更新收款订单-->
  393. <update id="updateByGoldCoinOrderCodeByStripe">
  394. update cash_record_collection
  395. SET
  396. received_time=#{availableOn},
  397. payment_currency='2',
  398. received_currency='2',
  399. payment_amount=#{amount},
  400. received_amount=#{net},
  401. handling_charge=#{fee},
  402. status=4,
  403. order_no_status=0
  404. where order_code=#{orderNo}
  405. </update>
  406. <!--根据OrderCode订单号更新收款订单-->
  407. <update id="updateByGoldCoinOrderCodeByStripe2">
  408. update cash_record_collection
  409. SET
  410. received_time=#{availableOn},
  411. payment_currency='3',
  412. received_currency='3',
  413. payment_amount=#{amount},
  414. received_amount=#{net},
  415. handling_charge=#{fee},
  416. status=4,
  417. order_no_status=0
  418. where order_code=#{orderNo}
  419. </update>
  420. <update id="updateByGoldCoinOrderCodeByFirstdata">
  421. update cash_record_collection
  422. SET
  423. payment_currency='3',
  424. received_currency='3',
  425. payment_amount=#{amount},
  426. received_amount=#{net},
  427. handling_charge=#{fee},
  428. status=4,
  429. order_no_status=0
  430. where order_code=#{orderId}
  431. </update>
  432. <update id="updateByGoldCoinOrderCodeByIpay88">
  433. update cash_record_collection
  434. SET
  435. payment_currency='4',
  436. received_currency='4',
  437. payment_amount=#{amount},
  438. received_amount=#{net},
  439. handling_charge=#{fee},
  440. status=4,
  441. order_no_status=0
  442. where order_code=#{orderNo}
  443. </update>
  444. <update id="updateMessageFlagByTypeIdAndType">
  445. UPDATE message
  446. SET flag = #{flag}
  447. WHERE type_id = #{typeId} AND type = #{type}
  448. </update>
  449. </mapper>