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.

232 lines
11 KiB

2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months 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(order_type,jwcode,name,market,activity,
  8. order_code,goods_name,good_num,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},#{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
  30. set status=#{status}
  31. where order_code=#{orderCode}
  32. </update>
  33. <!--更新订单-->
  34. <update id="updateByOrderCode">
  35. UPDATE cash_record
  36. <set>
  37. jwcode = #{cashRecord.jwcode},
  38. name = #{cashRecord.name},
  39. market = #{cashRecord.market},
  40. activity = #{cashRecord.activity},
  41. goods_name = #{cashRecord.goodsName},
  42. good_num = #{cashRecord.goodNum},
  43. payment_currency = #{cashRecord.paymentCurrency},
  44. payment_amount = #{cashRecord.paymentAmount},
  45. received_market = #{cashRecord.receivedMarket},
  46. pay_type = #{cashRecord.payType},
  47. pay_time = #{cashRecord.payTime},
  48. voucher = #{cashRecord.voucher},
  49. remark = #{cashRecord.remark},
  50. status = 0,
  51. </set>
  52. WHERE order_code = #{cashRecord.orderCode}
  53. AND status = 5
  54. </update>
  55. <!--补全手续费等字段-->
  56. <update id="complete">
  57. UPDATE cash_record
  58. <set>
  59. <if test="cashRecord.handlingCharge != null and cashRecord.handlingCharge!=''">
  60. handling_charge = #{cashRecord.handlingCharge},
  61. </if>
  62. <if test="cashRecord.receivedCurrency != null and cashRecord.receivedCurrency != ''">
  63. received_currency = #{cashRecord.receivedCurrency},
  64. </if>
  65. <if test="cashRecord.receivedAmount != null">
  66. received_amount = #{cashRecord.receivedAmount},
  67. </if>
  68. <if test="cashRecord.receivedTime != null">
  69. received_time = #{cashRecord.receivedTime},
  70. </if>
  71. <if test="cashRecord.paymentCurrency != null and cashRecord.paymentCurrency != ''">
  72. payment_currency = #{cashRecord.paymentCurrency},
  73. </if>
  74. <!-- 关键:null 就不拼这一列 -->
  75. <if test="cashRecord.paymentAmount != null">
  76. payment_amount = #{cashRecord.paymentAmount},
  77. </if>
  78. <!-- 只有 这些字段全部非空才更新状态 -->
  79. status = CASE
  80. WHEN
  81. handling_charge IS NOT NULL
  82. AND received_currency IS NOT NULL AND received_currency != ''
  83. AND received_amount IS NOT NULL
  84. AND received_time IS NOT NULL
  85. AND payment_currency IS NOT NULL AND payment_currency != ''
  86. AND payment_amount IS NOT NULL
  87. THEN 4
  88. ELSE status
  89. END
  90. </set>
  91. WHERE order_code = #{cashRecord.orderCode}
  92. AND status IN (1, 3)
  93. </update>
  94. <!--设置gOrder订单为已同步-->
  95. <update id="markSynced">
  96. update g_order
  97. set is_synced = 1
  98. where id = #{orderId}
  99. </update>
  100. <!--根据jwcode获取所属地区-->
  101. <select id="getMarketByJwcode" resultType="java.lang.String">
  102. select market from user where jwcode=#{jwcode}
  103. </select>
  104. <!--根据订单号获取订单id与状态-->
  105. <select id="selectByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  106. select id ,status
  107. from cash_record
  108. where order_code=#{orderCode}
  109. </select>
  110. <!--多条件查询收款订单列表-->
  111. <select id="selectCollection1" resultType="com.example.demo.domain.vo.cash.CashCollection">
  112. select cr.id,cr.jwcode,cr.name,cr.market,
  113. m1.name as marketName,
  114. cr.activity,cr.order_code,cr.bank_code,
  115. cr.goods_name,cr.good_num,cr.permanent_gold/100,cr.free_gold/100,cr.payment_amount/100 as paymentAmount,
  116. r1.rate_name as paymentCurrency,
  117. r2.rate_name as receivedCurrency,
  118. m2.name as receivedMarket,
  119. cr.received_amount/100 as receivedAmount,cr.handling_charge/100 as handlingCharge,
  120. cr.pay_type,cr.pay_time,cr.received_time,
  121. cr.status,cr.submitter_id,cr.submitter_market,cr.voucher,cr.remark,cr.reject_reason,
  122. cr.audit_id,cr.create_time,cr.update_time,cr.audit_time,
  123. a1.admin_name as submitterName,
  124. a2.admin_name as auditName
  125. from cash_record cr
  126. left join admin a1 on cr.submitter_id = a1.id
  127. left join admin a2 on cr.audit_id = a2.id
  128. left join market m1 on m1.id = cr.market
  129. left join market m2 on m2.id = cr.received_market
  130. left join rate r1 on r1.id = cr.payment_currency
  131. left join rate r2 on r2.id = cr.received_currency
  132. <where>
  133. 1 = 1
  134. <if test="cashCollection.market != null and cashCollection.market != ''">
  135. AND cr.market = #{cashCollection.market}
  136. </if>
  137. <if test="cashCollection.jwcode != null and cashCollection.jwcode!=''">
  138. AND cr.jwcode = #{cashCollection.jwcode}
  139. </if>
  140. <if test="cashCollection.name!=null and cashCollection.name !=''">
  141. AND cr.name like concat('%',#{cashCollection.name},'%')
  142. </if>
  143. <if test="cashCollection.submitterId!=null and cashCollection.submitterId !=''">
  144. AND cr.submitter_id = #{cashCollection.submitterId}
  145. </if>
  146. <!-- 其他原有条件不变 -->
  147. <choose>
  148. <when test="cashCollection.status != null and cashCollection.status == 46">
  149. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  150. AND (cr.received_market = #{cashCollection.receivedMarket}
  151. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  152. OR cr.submitter_market = #{cashCollection.submitterMarket}
  153. </if>
  154. )
  155. </if>
  156. <if test="(cashCollection.receivedMarket == null or cashCollection.receivedMarket == '')
  157. and cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  158. AND cr.submitter_market = #{cashCollection.submitterMarket}
  159. </if>
  160. </when>
  161. <!-- 非 status=46 保持原逻辑:同时满足 -->
  162. <otherwise>
  163. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  164. AND cr.received_market = #{cashCollection.receivedMarket}
  165. </if>
  166. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  167. AND cr.submitter_market = #{cashCollection.submitterMarket}
  168. </if>
  169. </otherwise>
  170. </choose>
  171. <if test="cashCollection.activity!=null and cashCollection.activity!=''">
  172. AND cr.activity like concat('%',#{cashCollection.activity},'%')
  173. </if>
  174. <if test="cashCollection.paymentCurrency!=null and cashCollection.paymentCurrency!=''">
  175. AND cr.payment_currency like concat('%',#{cashCollection.paymentCurrency},'%')
  176. </if>
  177. <if test="cashCollection.goodsName!=null and cashCollection.goodsName!=''">
  178. AND cr.goods_name like concat('%',#{cashCollection.goodsName},'%')
  179. </if>
  180. <if test="cashCollection.payType!=null and cashCollection.payType!=''">
  181. AND cr.pay_type = #{cashCollection.payType}
  182. </if>
  183. <if test="cashCollection.status != null">
  184. AND cr.status IN
  185. <foreach collection="cashCollection.status.toString().toCharArray()" item="digit" open="(" separator="," close=")">
  186. #{digit}
  187. </foreach>
  188. </if>
  189. <if test="cashCollection.startTime!=null and cashCollection.endTime!=null">
  190. AND cr.pay_time between #{cashCollection.startTime} and #{cashCollection.endTime}
  191. </if>
  192. and cr.order_type=1
  193. </where>
  194. <choose>
  195. <when test="cashCollection.sortField != null and cashCollection.sortField.length > 0 or cashCollection.sortOrder != null and cashCollection.sortOrder.length > 0">
  196. ORDER BY ${cashCollection.sortField} ${cashCollection.sortOrder}
  197. </when>
  198. <otherwise>
  199. ORDER BY update_time DESC
  200. </otherwise>
  201. </choose>
  202. </select>
  203. <select id="selectAuditByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  204. select id, status,jwcode,name,market,activity,
  205. order_code,bank_code,goods_name,good_num,permanent_gold,free_gold,
  206. payment_currency,payment_amount,pay_type,pay_time,status,submitter_id,
  207. voucher,remark from cash_record 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="java.lang.String">
  217. select distinct activity from cash_record
  218. </select>
  219. <!--查找未同步的订单-->
  220. <select id="getUnSync" resultType="com.example.demo.domain.entity.GOrder">
  221. select id,jwcode,order_no,type,price,count,pay_style,state,
  222. success_time,ios_environment,ios_transaction_id,ios_receipt_data,
  223. add_time,is_synced
  224. from g_order
  225. where is_synced=0 and state=1 and type='gold_coin' and pay_style in(3,5,6,7,9)
  226. limit #{size}
  227. </select>
  228. </mapper>