PayMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.caimei.module.pay.dao.PayDao">
  6. <select id="findOrder" resultType="com.caimei.module.base.entity.vo.OrderVo">
  7. SELECT
  8. *
  9. FROM
  10. cm_order
  11. WHERE
  12. orderID = #{orderID}
  13. AND delFlag = '0'
  14. </select>
  15. <select id="getDiscernReceipt" resultType="com.caimei.module.base.entity.vo.DiscernReceiptVo">
  16. SELECT
  17. cdr.*,
  18. cror.associateAmount
  19. FROM
  20. cm_receipt_order_relation cror
  21. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  22. WHERE
  23. (
  24. cror.orderID = #{orderID}
  25. AND cror.relationType = '2'
  26. OR
  27. cror.orderID = #{shopOrderIDs}
  28. AND cror.relationType = '1'
  29. )
  30. AND cror.delFlag = '0'
  31. AND cdr.delFlag = '0'
  32. AND cdr.payType != '16'
  33. AND cdr.receiptStatus IN(2,3)
  34. ORDER BY
  35. cdr.receiptDate DESC
  36. </select>
  37. <update id="updateSelective" parameterType="com.caimei.module.base.entity.po.CmOrder">
  38. update cm_order
  39. <set>
  40. <if test="orderNo != null">
  41. orderNo = #{orderNo,jdbcType=VARCHAR},
  42. </if>
  43. <if test="userID != null">
  44. userID = #{userID,jdbcType=BIGINT},
  45. </if>
  46. <if test="buyUserID != null">
  47. buyUserID = #{buyUserID,jdbcType=INTEGER},
  48. </if>
  49. <if test="shopOrderIDs != null">
  50. shopOrderIDs = #{shopOrderIDs,jdbcType=VARCHAR},
  51. </if>
  52. <if test="orderSubmitType != null">
  53. orderSubmitType = #{orderSubmitType,jdbcType=INTEGER},
  54. </if>
  55. <if test="orderType != null">
  56. orderType = #{orderType,jdbcType=INTEGER},
  57. </if>
  58. <if test="hasActProduct != null">
  59. hasActProduct = #{hasActProduct,jdbcType=CHAR},
  60. </if>
  61. <if test="autoCloseTimeMills != null">
  62. autoCloseTimeMills = #{autoCloseTimeMills,jdbcType=DECIMAL},
  63. </if>
  64. <if test="status != null">
  65. `status` = #{status,jdbcType=CHAR},
  66. </if>
  67. <if test="receiptStatus != null">
  68. receiptStatus = #{receiptStatus,jdbcType=CHAR},
  69. </if>
  70. <if test="payStatus != null">
  71. payStatus = #{payStatus,jdbcType=CHAR},
  72. </if>
  73. <if test="sendOutStatus != null">
  74. sendOutStatus = #{sendOutStatus,jdbcType=CHAR},
  75. </if>
  76. <if test="refundType != null">
  77. refundType = #{refundType,jdbcType=CHAR},
  78. </if>
  79. <if test="paySuccessCounter != null">
  80. paySuccessCounter = #{paySuccessCounter},
  81. </if>
  82. <if test="payFlag != null">
  83. payFlag = #{payFlag,jdbcType=CHAR},
  84. </if>
  85. <if test="onlinePayFlag != null">
  86. onlinePayFlag = #{onlinePayFlag,jdbcType=CHAR},
  87. </if>
  88. <if test="productTotalFee != null">
  89. productTotalFee = #{productTotalFee,jdbcType=DECIMAL},
  90. </if>
  91. <if test="orderTotalFee != null">
  92. orderTotalFee = #{orderTotalFee,jdbcType=DECIMAL},
  93. </if>
  94. <if test="payTotalFee != null">
  95. payTotalFee = #{payTotalFee,jdbcType=DECIMAL},
  96. </if>
  97. <if test="payableAmount != null">
  98. payableAmount = #{payableAmount,jdbcType=DECIMAL},
  99. </if>
  100. <if test="balancePayFee != null">
  101. balancePayFee = #{balancePayFee,jdbcType=DECIMAL},
  102. </if>
  103. <if test="preferential != null">
  104. preferential = #{preferential,jdbcType=DECIMAL},
  105. </if>
  106. <if test="discountFee != null">
  107. discountFee = #{discountFee,jdbcType=DECIMAL},
  108. </if>
  109. <if test="spID != null">
  110. spID = #{spID,jdbcType=BIGINT},
  111. </if>
  112. <if test="mainSpID != null">
  113. mainSpID = #{mainSpID,jdbcType=BIGINT},
  114. </if>
  115. <if test="note != null">
  116. note = #{note,jdbcType=VARCHAR},
  117. </if>
  118. <if test="clubID != null">
  119. clubID = #{clubID,jdbcType=BIGINT},
  120. </if>
  121. <if test="clubScanTime != null">
  122. clubScanTime = #{clubScanTime,jdbcType=VARCHAR},
  123. </if>
  124. <if test="payWay != null">
  125. payWay = #{payWay,jdbcType=VARCHAR},
  126. </if>
  127. <if test="orderSource != null">
  128. orderSource = #{orderSource,jdbcType=CHAR},
  129. </if>
  130. <if test="closeTime != null">
  131. closeTime = #{closeTime,jdbcType=VARCHAR},
  132. </if>
  133. <if test="confirmTime != null">
  134. confirmTime = #{confirmTime,jdbcType=VARCHAR},
  135. </if>
  136. <if test="payTime != null">
  137. payTime = #{payTime,jdbcType=VARCHAR},
  138. </if>
  139. <if test="orderTime != null">
  140. orderTime = #{orderTime,jdbcType=VARCHAR},
  141. </if>
  142. <if test="productCount != null">
  143. productCount = #{productCount,jdbcType=INTEGER},
  144. </if>
  145. <if test="presentCount != null">
  146. presentCount = #{presentCount,jdbcType=INTEGER},
  147. </if>
  148. <if test="cooFreeFlag != null">
  149. cooFreeFlag = #{cooFreeFlag,jdbcType=CHAR},
  150. </if>
  151. <if test="cooFreeRate != null">
  152. cooFreeRate = #{cooFreeRate,jdbcType=INTEGER},
  153. </if>
  154. <if test="cooFreeAmount != null">
  155. cooFreeAmount = #{cooFreeAmount,jdbcType=DECIMAL},
  156. </if>
  157. <if test="invoiceFlag != null">
  158. invoiceFlag = #{invoiceFlag,jdbcType=CHAR},
  159. </if>
  160. <if test="confirmFlag != null">
  161. confirmFlag = #{confirmFlag,jdbcType=CHAR},
  162. </if>
  163. <if test="clauseID != null">
  164. clauseID = #{clauseID,jdbcType=BIGINT},
  165. </if>
  166. <if test="clauseContent != null">
  167. clauseContent = #{clauseContent,jdbcType=VARCHAR},
  168. </if>
  169. <if test="clauseName != null">
  170. clauseName = #{clauseName,jdbcType=VARCHAR},
  171. </if>
  172. <if test="updateDate != null">
  173. updateDate = #{updateDate,jdbcType=VARCHAR},
  174. </if>
  175. <if test="freePostFlag != null">
  176. freePostFlag = #{freePostFlag,jdbcType=CHAR},
  177. </if>
  178. <if test="freight != null">
  179. freight = #{freight,jdbcType=DECIMAL},
  180. </if>
  181. <if test="delFlag != null">
  182. delFlag = #{delFlag,jdbcType=CHAR},
  183. </if>
  184. <if test="freePostageTicketID != null">
  185. freePostageTicketID = #{freePostageTicketID,jdbcType=INTEGER},
  186. </if>
  187. <if test="splitFlag != null">
  188. splitFlag = #{splitFlag,jdbcType=CHAR},
  189. </if>
  190. <if test="closeReason != null">
  191. closeReason = #{closeReason,jdbcType=VARCHAR},
  192. </if>
  193. <if test="postageOrderFlag != null">
  194. postageOrderFlag = #{postageOrderFlag,jdbcType=CHAR},
  195. </if>
  196. </set>
  197. where orderID = #{orderID,jdbcType=BIGINT}
  198. </update>
  199. <insert id="insertDiscernReceipt" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  200. parameterType="com.caimei.module.base.entity.vo.DiscernReceiptVo">
  201. INSERT INTO `cm_discern_receipt` (
  202. `payWay`, `payType`, `receiptType`,
  203. `receiptStatus`, `smsContent`, `smsMd5Code`,
  204. `orderFlag`, `receiptAmount`, `handlingFee`,
  205. `confirmType`, `confirmUserPermissionID`,
  206. `reviewUserPermissionID`, `cancelUserPermissionID`,
  207. `transactionNum`, `bankID`, `bankCode`,
  208. `kuaiQianPayTypeID`, `kuaiQianPayerID`,
  209. `rePayFlag`, `actualAmount`, `formData`,
  210. `problem`, `noOrderReason`, `reviewReason`,
  211. `cancelReason`, `receiptDate`, `confirmDate`,
  212. `reviewDate`, `cancelDate`, `updateDate`,
  213. `delFlag`
  214. )
  215. VALUES
  216. (
  217. #{payWay}, #{payType}, #{receiptType},
  218. #{receiptStatus}, #{smsContent}, #{smsMd5Code},
  219. #{orderFlag}, #{receiptAmount}, #{handlingFee},
  220. #{confirmType}, #{confirmUserPermissionID},
  221. #{reviewUserPermissionID}, #{cancelUserPermissionID},
  222. #{transactionNum}, #{bankID}, #{bankCode},
  223. #{kuaiQianPayTypeID}, #{kuaiQianPayerID},
  224. #{rePayFlag}, #{actualAmount}, #{formData},
  225. #{problem}, #{noOrderReason}, #{reviewReason},
  226. #{cancelReason}, #{receiptDate}, #{confirmDate},
  227. #{reviewDate}, #{cancelDate}, #{updateDate},
  228. #{delFlag}
  229. )
  230. </insert>
  231. <insert id="insertOrderRelation" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  232. parameterType="com.caimei.module.base.entity.vo.OrderRelationVo">
  233. INSERT INTO `cm_receipt_order_relation` (
  234. `relationType`, `receiptID`, `associateAmount`,
  235. `orderID`, `delFlag`, mbOrderId, orderRequestNo,
  236. splitStatus
  237. )
  238. VALUES
  239. (
  240. #{relationType}, #{receiptID}, #{associateAmount},
  241. #{orderID}, #{delFlag},#{mbOrderId},#{orderRequestNo},
  242. #{splitStatus}
  243. )
  244. </insert>
  245. <select id="findOrderPayLink" resultType="com.caimei.module.base.entity.vo.OrderPayLinkVo">
  246. SELECT
  247. *
  248. FROM
  249. cm_order_pay_link
  250. WHERE
  251. orderId = #{orderId}
  252. <if test="amount != null">
  253. AND unpaidAmount = #{amount}
  254. </if>
  255. AND delFlag = '0'
  256. AND payStatus = '0'
  257. ORDER BY id DESC LIMIT 1
  258. </select>
  259. <insert id="insertOrderPayLink">
  260. insert into cm_order_pay_link
  261. <trim prefix="(" suffix=")" suffixOverrides=",">
  262. <if test="orderId != null">
  263. orderId,
  264. </if>
  265. <if test="linkLogo != null">
  266. linkLogo,
  267. </if>
  268. <if test="unpaidAmount != null">
  269. unpaidAmount,
  270. </if>
  271. <if test="generateTime != null">
  272. generateTime,
  273. </if>
  274. <if test="effectiveTime != null">
  275. effectiveTime,
  276. </if>
  277. <if test="payStatus != null">
  278. payStatus,
  279. </if>
  280. <if test="payType != null">
  281. payType,
  282. </if>
  283. <if test="delFlag != null">
  284. delFlag,
  285. </if>
  286. </trim>
  287. <trim prefix="values (" suffix=")" suffixOverrides=",">
  288. <if test="orderId != null">
  289. #{orderId,jdbcType=BIGINT},
  290. </if>
  291. <if test="linkLogo != null">
  292. #{linkLogo,jdbcType=VARCHAR},
  293. </if>
  294. <if test="unpaidAmount != null">
  295. #{unpaidAmount,jdbcType=DECIMAL},
  296. </if>
  297. <if test="generateTime != null">
  298. #{generateTime,jdbcType=TIMESTAMP},
  299. </if>
  300. <if test="effectiveTime != null">
  301. #{effectiveTime,jdbcType=TIMESTAMP},
  302. </if>
  303. <if test="payStatus != null">
  304. #{payStatus,jdbcType=CHAR},
  305. </if>
  306. <if test="payType != null">
  307. #{payType},
  308. </if>
  309. <if test="delFlag != null">
  310. #{delFlag,jdbcType=CHAR},
  311. </if>
  312. </trim>
  313. </insert>
  314. <update id="updateOrderPayLink">
  315. update cm_order_pay_link
  316. <set>
  317. <if test="orderId != null">
  318. orderId = #{orderId,jdbcType=BIGINT},
  319. </if>
  320. <if test="linkLogo != null">
  321. linkLogo = #{linkLogo,jdbcType=VARCHAR},
  322. </if>
  323. <if test="unpaidAmount != null">
  324. unpaidAmount = #{unpaidAmount,jdbcType=DECIMAL},
  325. </if>
  326. <if test="generateTime != null">
  327. generateTime = #{generateTime,jdbcType=TIMESTAMP},
  328. </if>
  329. <if test="effectiveTime != null">
  330. effectiveTime = #{effectiveTime,jdbcType=TIMESTAMP},
  331. </if>
  332. <if test="payStatus != null">
  333. payStatus = #{payStatus,jdbcType=CHAR},
  334. </if>
  335. <if test="payType != null">
  336. payType = #{payType},
  337. </if>
  338. <if test="delFlag != null">
  339. delFlag = #{delFlag,jdbcType=CHAR},
  340. </if>
  341. </set>
  342. where id = #{id,jdbcType=INTEGER}
  343. </update>
  344. <select id="getOrderPayLink" resultType="com.caimei.module.base.entity.vo.OrderPayLinkVo">
  345. SELECT
  346. *
  347. FROM
  348. cm_order_pay_link
  349. WHERE
  350. linkLogo = #{linkLogo}
  351. AND delFlag = '0'
  352. </select>
  353. <select id="fandAllOrderProduct" resultType="com.caimei.module.base.entity.vo.OrderProductVo">
  354. SELECT * FROM cm_order_product WHERE orderID = #{orderId} ORDER BY shopID ASC, productID ASC
  355. </select>
  356. <select id="findUser" resultType="com.caimei.module.base.entity.vo.UserVo">
  357. SELECT
  358. *
  359. FROM
  360. USER
  361. WHERE
  362. userID = #{userID}
  363. </select>
  364. <select id="getPayOnLineSwitch" resultType="java.lang.Integer">
  365. select status from cm_pay_online_switch where id=1
  366. </select>
  367. <update id="updateSeconHand">
  368. UPDATE
  369. cm_second_hand_detail
  370. SET
  371. payStatus = '2',
  372. payAmount = #{payAmount},
  373. payFormData = #{payFormData},
  374. payType = #{payType},
  375. payDate = NOW()
  376. WHERE
  377. productID = #{productID}
  378. </update>
  379. <insert id="insertSplitAccount" keyColumn="id" keyProperty="id" parameterType="com.caimei.module.base.entity.po.CmSplitAccount" useGeneratedKeys="true">
  380. INSERT INTO `cm_split_account` (
  381. `orderId`, `productId`, `orderProductId`,
  382. `shopId`, `type`, `subUserNo`, `splitAccount`,
  383. `mbOrderId`, `orderRequestNo`,
  384. `payStatus`, `productType`, splitTime
  385. )
  386. VALUES
  387. (
  388. #{orderId}, #{productId}, #{orderProductId},
  389. #{shopId}, #{type}, #{subUserNo}, #{splitAccount},
  390. #{mbOrderId}, #{orderRequestNo},
  391. #{payStatus}, #{productType}, NOW()
  392. );
  393. </insert>
  394. <update id="updateSplitAccountByPay">
  395. UPDATE cm_split_account SET payStatus = '1' WHERE mbOrderId = #{mbOrderId}
  396. </update>
  397. <update id="updateUserMoney">
  398. update user
  399. <set>
  400. <if test="userMoney != null">
  401. userMoney = #{userMoney},
  402. </if>
  403. <if test="ableUserMoney != null">
  404. ableUserMoney = #{ableUserMoney},
  405. </if>
  406. </set>
  407. where userID = #{userId}
  408. </update>
  409. <insert id="insertBalanceRecord">
  410. INSERT INTO `cm_user_balance_record` (
  411. `userId`, `type`, `balanceType`, `addDate`,
  412. `amount`, `orderId`, `receiptId`,
  413. `returnedId`, `withdrawalsId`, `remark`,
  414. `delFlag`
  415. )
  416. VALUES
  417. (
  418. #{userId}, #{type}, #{balanceType}, #{addDate},
  419. #{amount}, #{orderId}, #{receiptId},
  420. #{returnedId}, #{withdrawalsId}, #{remark},
  421. #{delFlag}
  422. )
  423. </insert>
  424. <select id="findCommercialCode" resultType="string">
  425. SELECT commercialCode FROM shop WHERE shopID = #{shopId}
  426. </select>
  427. <select id="findPaidAmount" resultType="java.math.BigDecimal">
  428. SELECT
  429. SUM(splitAccount)
  430. FROM
  431. cm_split_account
  432. WHERE
  433. orderProductId = #{orderProductId}
  434. AND payStatus = 1
  435. AND productType = 1
  436. </select>
  437. <select id="findShopOrder" resultType="com.caimei.module.base.entity.vo.ShopOrderVo">
  438. SELECT * FROM cm_shop_order WHERE orderID = #{orderId}
  439. </select>
  440. <select id="findShipping" resultType="java.math.BigDecimal">
  441. SELECT
  442. SUM(splitAccount)
  443. FROM
  444. cm_split_account
  445. WHERE
  446. orderId = #{orderId}
  447. AND shopId = #{shopId}
  448. AND productType = 2
  449. AND payStatus = 1
  450. </select>
  451. <select id="findUnallocatedAccount" resultType="com.caimei.module.base.entity.vo.OrderRelationVo">
  452. SELECT
  453. cror.*, cdr.payType
  454. FROM
  455. cm_receipt_order_relation cror
  456. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  457. LEFT JOIN cm_order co ON cror.orderID = co.orderID
  458. WHERE
  459. cror.relationType = 2
  460. AND cdr.payWay = 1
  461. AND cror.delFlag = 0
  462. AND cror.mbOrderId IS NOT NULL
  463. AND cror.splitStatus = 0
  464. AND cdr.receiptDate <![CDATA[ <= ]]> #{currentTime}
  465. AND co.organizeID = 0
  466. AND co.orderType != 2
  467. </select>
  468. <select id="findByMbOrderId" resultType="com.caimei.module.base.entity.vo.SplitAccountVo">
  469. SELECT
  470. orderId,
  471. productId,
  472. orderProductId,
  473. shopId,
  474. type,
  475. subUserNo,
  476. SUM(splitAccount) AS "splitAccount",
  477. mbOrderId,
  478. orderRequestNo,
  479. payStatus,
  480. productType
  481. FROM
  482. cm_split_account
  483. WHERE
  484. TYPE = 4
  485. AND payStatus = 1
  486. AND splitAccount > 0
  487. AND mbOrderId = #{mbOrderId}
  488. GROUP BY
  489. shopID
  490. </select>
  491. <select id="findPaidShop" resultType="java.math.BigDecimal">
  492. SELECT
  493. SUM(payAmount)
  494. FROM
  495. cm_pay_shop_record
  496. WHERE
  497. STATUS = 1
  498. AND delFlag = 0
  499. AND shopOrderID = #{shopOrderId}
  500. </select>
  501. <insert id="insertPayShop" useGeneratedKeys="true" keyProperty="id" keyColumn="id" parameterType="com.caimei.module.base.entity.vo.PayShopVo">
  502. INSERT INTO `cm_pay_shop` (
  503. `shopID`, `name`, `bankAccountName`,
  504. `bankAccount`, `bankName`, `type`,
  505. `totalAmount`, `balancePayFee`,
  506. `transferPayFee`, `payType`, `wipePayment`,
  507. `wipeRemarks`, `wipeRemarkImages`,
  508. `wipeTime`, `applicant`, `applyTime`,
  509. `reviewer`, `reviewTime`, `payTime`,
  510. `status`, `reason`, `delFlag`
  511. )
  512. VALUES
  513. (
  514. #{shopID}, #{name}, #{bankAccountName},
  515. #{bankAccount}, #{bankName}, #{type},
  516. #{totalAmount}, #{balancePayFee},
  517. #{transferPayFee}, #{payType}, #{wipePayment},
  518. #{wipeRemarks}, #{wipeRemarkImages},
  519. #{wipeTime}, #{applicant}, #{applyTime},
  520. #{reviewer}, #{reviewTime}, #{payTime},
  521. #{status}, #{reason}, #{delFlag}
  522. )
  523. </insert>
  524. <insert id="insertPayShopRecord">
  525. INSERT INTO `cm_pay_shop_record` (
  526. `shopID`, `shopOrderID`, `shopOrderNo`,
  527. `payAmount`, `wipePayment`, `payType`,
  528. `payTime`, `payShopID`,
  529. `status`, `delFlag`
  530. )
  531. VALUES
  532. (
  533. #{shopID}, #{shopOrderID}, #{shopOrderNo},
  534. #{payAmount}, #{wipePayment}, #{payType},
  535. #{payTime}, #{payShopID},
  536. #{status}, #{delFlag}
  537. )
  538. </insert>
  539. <update id="updateBySplitStatus">
  540. UPDATE cm_receipt_order_relation SET splitStatus = 1 WHERE mbOrderId = #{mbOrderId}
  541. </update>
  542. <update id="updateShopOrderByPayStatus">
  543. UPDATE
  544. cm_shop_order
  545. SET
  546. payStatus = #{payStatus},
  547. payedShopAmount = #{paidShop}
  548. WHERE
  549. shopOrderID = #{shopOrderId}
  550. </update>
  551. <update id="updateOrderByPayStatus">
  552. UPDATE
  553. cm_order
  554. SET
  555. payStatus = #{payStatus}
  556. WHERE
  557. orderID = #{orderId}
  558. </update>
  559. </mapper>