PayOrderMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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.mapper.PayOrderMapper">
  6. <select id="getPayOnLineSwitch" resultType="java.lang.Integer">
  7. select status from cm_pay_online_switch where id=1
  8. </select>
  9. <select id="getDiscernReceipt" resultType="com.caimei.model.vo.DiscernReceiptVo">
  10. SELECT
  11. cdr.*,
  12. cror.associateAmount
  13. FROM
  14. cm_receipt_order_relation cror
  15. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  16. WHERE
  17. (
  18. cror.orderID = #{orderId}
  19. AND cror.relationType = '2'
  20. OR
  21. cror.orderID = #{shopOrderIds}
  22. AND cror.relationType = '1'
  23. )
  24. AND cror.delFlag = '0'
  25. AND cdr.delFlag = '0'
  26. AND cdr.payType != '16'
  27. AND cdr.receiptStatus IN(2,3)
  28. ORDER BY
  29. cdr.receiptDate DESC
  30. </select>
  31. <update id="updateSelective">
  32. update cm_order
  33. <set>
  34. <if test="status != null">
  35. `status` = #{status},
  36. </if>
  37. <if test="receiptStatus != null">
  38. receiptStatus = #{receiptStatus},
  39. </if>
  40. <if test="payStatus != null">
  41. payStatus = #{payStatus},
  42. </if>
  43. <if test="sendOutStatus != null">
  44. sendOutStatus = #{sendOutStatus},
  45. </if>
  46. <if test="refundType != null">
  47. refundType = #{refundType},
  48. </if>
  49. <if test="paySuccessCounter != null">
  50. paySuccessCounter = #{paySuccessCounter},
  51. </if>
  52. <if test="payFlag != null">
  53. payFlag = #{payFlag,jdbcType=CHAR},
  54. </if>
  55. <if test="onlinePayFlag != null">
  56. onlinePayFlag = #{onlinePayFlag},
  57. </if>
  58. </set>
  59. where orderID = #{orderID,jdbcType=BIGINT}
  60. </update>
  61. <insert id="insertDiscernReceipt" keyColumn="id" keyProperty="id" useGeneratedKeys="true" parameterType="com.caimei.model.po.CmDiscernReceiptPo">
  62. INSERT INTO `cm_discern_receipt` (
  63. `payWay`, `payType`, `receiptType`,
  64. `receiptStatus`, `smsContent`, `smsMd5Code`,
  65. `orderFlag`, `receiptAmount`, `handlingFee`,
  66. `confirmType`, `confirmUserPermissionID`,
  67. `reviewUserPermissionID`, `cancelUserPermissionID`,
  68. `transactionNum`, `bankID`, `bankCode`,
  69. `kuaiQianPayTypeID`, `kuaiQianPayerID`,
  70. `rePayFlag`, `actualAmount`, `formData`,
  71. `problem`, `noOrderReason`, `reviewReason`,
  72. `cancelReason`, `receiptDate`, `confirmDate`,
  73. `reviewDate`, `cancelDate`, `updateDate`,
  74. `delFlag`
  75. )
  76. VALUES
  77. (
  78. #{payWay}, #{payType}, #{receiptType},
  79. #{receiptStatus}, #{smsContent}, #{smsMd5Code},
  80. #{orderFlag}, #{receiptAmount}, #{handlingFee},
  81. #{confirmType}, #{confirmUserPermissionID},
  82. #{reviewUserPermissionID}, #{cancelUserPermissionID},
  83. #{transactionNum}, #{bankID}, #{bankCode},
  84. #{kuaiQianPayTypeID}, #{kuaiQianPayerID},
  85. #{rePayFlag}, #{actualAmount}, #{formData},
  86. #{problem}, #{noOrderReason}, #{reviewReason},
  87. #{cancelReason}, #{receiptDate}, #{confirmDate},
  88. #{reviewDate}, #{cancelDate}, #{updateDate},
  89. #{delFlag}
  90. )
  91. </insert>
  92. <insert id="insertOrderRelation" keyColumn="id" keyProperty="id" useGeneratedKeys="true" parameterType="com.caimei.model.po.CmReceiptOrderRelationPo">
  93. INSERT INTO `cm_receipt_order_relation` (
  94. `relationType`, `receiptID`, `associateAmount`,
  95. `orderID`, `delFlag`, mbOrderId, orderRequestNo,
  96. splitStatus
  97. )
  98. VALUES
  99. (
  100. #{relationType}, #{receiptID}, #{associateAmount},
  101. #{orderID}, #{delFlag},#{mbOrderId},#{orderRequestNo},
  102. #{splitStatus}
  103. )
  104. </insert>
  105. <select id="findAllOrderProduct" resultType="com.caimei.model.vo.OrderProductVo">
  106. SELECT
  107. orderProductID AS orderProductId,
  108. orderID AS orderId,
  109. shopOrderID AS shopOrderId,
  110. shopID AS shopId,
  111. productID AS productId,
  112. organizeProductID AS organizeProductId,
  113. organizeID AS organizeId,
  114. num,
  115. presentNum,
  116. outStoreType,
  117. productNo,
  118. price,
  119. normalPrice,
  120. costPrice,
  121. price1,
  122. totalAmount,
  123. totalFee,
  124. shouldPayFee,
  125. discount,
  126. discountPrice,
  127. includedTax,
  128. invoiceType,
  129. taxRate,
  130. totalAddedValueTax,
  131. notOutStore,
  132. name,
  133. productUnit,
  134. productImage,
  135. productType,
  136. orderPromotionsId
  137. FROM
  138. cm_order_product
  139. WHERE
  140. orderID = #{orderId}
  141. ORDER BY
  142. shopID ASC,
  143. productID ASC
  144. </select>
  145. <select id="findUnallocatedAccount" resultType="com.caimei.model.po.CmReceiptOrderRelationPo">
  146. SELECT
  147. cror.id,
  148. cror.relationType,
  149. cror.receiptID,
  150. cror.orderID,
  151. cror.mbOrderId,
  152. cror.orderRequestNo,
  153. cror.splitStatus,
  154. cror.associateAmount
  155. FROM
  156. cm_receipt_order_relation cror
  157. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  158. LEFT JOIN cm_order co ON cror.orderID = co.orderID
  159. WHERE
  160. cror.relationType = 2
  161. AND cdr.payWay = 1
  162. AND cror.delFlag = 0
  163. AND cror.mbOrderId IS NOT NULL
  164. AND cror.splitStatus = 0
  165. AND cdr.receiptDate <![CDATA[ <= ]]> #{currentTime}
  166. AND co.orderType = 2
  167. </select>
  168. <insert id="insertSplitAccount" keyColumn="id" keyProperty="id" parameterType="com.caimei.model.vo.SplitAccountVo" useGeneratedKeys="true">
  169. INSERT INTO `cm_split_account` (
  170. `orderId`, `productId`, `orderProductId`,
  171. `shopId`, `type`, `subUserNo`, `splitAccount`,
  172. `mbOrderId`, `orderRequestNo`,
  173. `payStatus`, `productType`, splitTime
  174. )
  175. VALUES
  176. (
  177. #{orderId}, #{productId}, #{orderProductId},
  178. #{shopId}, #{type}, #{subUserNo}, #{splitAccount},
  179. #{mbOrderId}, #{orderRequestNo},
  180. #{payStatus}, #{productType}, NOW()
  181. )
  182. </insert>
  183. <select id="findPaidAmount" resultType="java.math.BigDecimal">
  184. SELECT
  185. SUM(splitAccount)
  186. FROM
  187. cm_split_account
  188. WHERE
  189. orderProductId = #{orderProductId}
  190. AND payStatus = 1
  191. AND productType = 1
  192. </select>
  193. <select id="findCommercialCode" resultType="string">
  194. SELECT commercialCode FROM shop WHERE shopID = #{shopId}
  195. </select>
  196. <select id="findShipping" resultType="java.math.BigDecimal">
  197. SELECT
  198. SUM(splitAccount)
  199. FROM
  200. cm_split_account
  201. WHERE
  202. orderId = #{orderId}
  203. AND shopId = #{shopId}
  204. AND productType = 2
  205. AND payStatus = 1
  206. </select>
  207. <update id="updateBySplitStatus">
  208. UPDATE cm_receipt_order_relation SET splitStatus = 1 WHERE mbOrderId = #{mbOrderId}
  209. </update>
  210. <select id="findByMbOrderId" resultType="com.caimei.model.vo.SplitAccountVo">
  211. SELECT
  212. orderId,
  213. productId,
  214. orderProductId,
  215. shopId,
  216. type,
  217. subUserNo,
  218. SUM(splitAccount) AS "splitAccount",
  219. mbOrderId,
  220. orderRequestNo,
  221. payStatus,
  222. productType
  223. FROM
  224. cm_split_account
  225. WHERE
  226. TYPE = 4
  227. AND payStatus = 1
  228. AND splitAccount > 0
  229. AND mbOrderId = #{mbOrderId}
  230. GROUP BY
  231. shopID
  232. </select>
  233. <select id="findPaidShop" resultType="java.math.BigDecimal">
  234. SELECT
  235. SUM(payAmount)
  236. FROM
  237. cm_pay_shop_record
  238. WHERE
  239. STATUS = 1
  240. AND delFlag = 0
  241. AND shopOrderID = #{shopOrderId}
  242. </select>
  243. <update id="updateShopOrderByPayStatus">
  244. UPDATE
  245. cm_shop_order
  246. SET
  247. payStatus = #{payStatus},
  248. payedShopAmount = #{paidShop}
  249. WHERE
  250. shopOrderID = #{shopOrderId}
  251. </update>
  252. <insert id="insertPayShop" useGeneratedKeys="true" keyProperty="id" keyColumn="id" parameterType="com.caimei.model.po.CmPayShopPo">
  253. INSERT INTO `cm_pay_shop` (
  254. `shopID`, `name`, `bankAccountName`,
  255. `bankAccount`, `bankName`, `type`,
  256. `totalAmount`, `balancePayFee`,
  257. `transferPayFee`, `payType`, `wipePayment`,
  258. `wipeRemarks`, `wipeRemarkImages`,
  259. `wipeTime`, `applicant`, `applyTime`,
  260. `reviewer`, `reviewTime`, `payTime`,
  261. `status`, `reason`, `delFlag`
  262. )
  263. VALUES
  264. (
  265. #{shopID}, #{name}, #{bankAccountName},
  266. #{bankAccount}, #{bankName}, #{type},
  267. #{totalAmount}, #{balancePayFee},
  268. #{transferPayFee}, #{payType}, #{wipePayment},
  269. #{wipeRemarks}, #{wipeRemarkImages},
  270. #{wipeTime}, #{applicant}, #{applyTime},
  271. #{reviewer}, #{reviewTime}, #{payTime},
  272. #{status}, #{reason}, #{delFlag}
  273. )
  274. </insert>
  275. <insert id="insertPayShopRecord">
  276. INSERT INTO `cm_pay_shop_record` (
  277. `shopID`, `shopOrderID`, `shopOrderNo`,
  278. `payAmount`, `wipePayment`, `payType`,
  279. `payTime`, `payShopID`,
  280. `status`, `delFlag`
  281. )
  282. VALUES
  283. (
  284. #{shopID}, #{shopOrderID}, #{shopOrderNo},
  285. #{payAmount}, #{wipePayment}, #{payType},
  286. #{payTime}, #{payShopID},
  287. #{status}, #{delFlag}
  288. )
  289. </insert>
  290. <update id="updateOrderByPayStatus">
  291. UPDATE
  292. cm_order
  293. SET
  294. payStatus = #{payStatus}
  295. WHERE
  296. orderID = #{orderId}
  297. </update>
  298. </mapper>