CmPayShopMapper.xml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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.caimei.modules.order.dao.CmPayShopDao">
  4. <sql id="cmPayShopColumns">
  5. a.id AS "id",
  6. a.shopID AS "shopID",
  7. a.name AS "name",
  8. a.bankAccountName AS "bankAccountName",
  9. a.bankAccount AS "bankAccount",
  10. a.bankName AS "bankName",
  11. a.type AS "type",
  12. a.totalAmount AS "totalAmount",
  13. a.balancePayFee AS "balancePayFee",
  14. a.transferPayFee AS "transferPayFee",
  15. a.payType AS "payType",
  16. a.wipePayment AS "wipePayment",
  17. a.wipeRemarks AS "wipeRemarks",
  18. a.wipeRemarkImages AS "wipeRemarkImages",
  19. a.applicant AS "applicant",
  20. a.applyTime AS "applyTime",
  21. a.wipeTime AS "wipeTime",
  22. a.reviewer AS "reviewer",
  23. a.reviewTime AS "reviewTime",
  24. a.payTime AS "payTime",
  25. a.status AS "status",
  26. a.reason AS "reason",
  27. a.delFlag AS "delFlag"
  28. </sql>
  29. <sql id="cmPayShopJoins">
  30. </sql>
  31. <select id="get" resultType="CmPayShop">
  32. SELECT
  33. <include refid="cmPayShopColumns"/>,
  34. u1.name AS applicantName,
  35. u2.name AS reviewerName,
  36. s.name AS shopName,
  37. s.ableRebateAmount AS ableRebateAmount,
  38. s.rebateAmount AS rebateAmount,
  39. (SELECT paymentType FROM cm_pay_shop_record WHERE payShopID = a.id LIMIT 1) AS paymentType
  40. FROM cm_pay_shop a
  41. <include refid="cmPayShopJoins"/>
  42. left join shop s on s.shopID = a.shopID
  43. left join sys_user u1 on u1.id = a.applicant
  44. left join sys_user u2 on u2.id = a.reviewer
  45. WHERE a.id = #{id}
  46. </select>
  47. <select id="getPayShopByShopOrderId" resultType="com.caimei.modules.order.entity.CmPayShop">
  48. SELECT
  49. <include refid="cmPayShopColumns"/>
  50. FROM cm_pay_shop a
  51. left join cm_pay_shop_record cpsr on a.id = cpsr.payShopID
  52. <include refid="cmPayShopJoins"/>
  53. left join shop s on s.shopID = a.shopID
  54. left join sys_user u1 on u1.id = a.applicant
  55. left join sys_user u2 on u2.id = a.reviewer
  56. where cpsr.shopOrderID=#{shopOrderID}
  57. and a.delFlag = '0'
  58. order by a.id desc
  59. limit 1
  60. </select>
  61. <select id="findList" resultType="CmPayShop">
  62. SELECT
  63. <include refid="cmPayShopColumns"/>,
  64. u1.name AS applicantName,
  65. u2.name AS reviewerName,
  66. s.name AS shopName,
  67. (SELECT paymentType FROM cm_pay_shop_record WHERE payShopID = a.id LIMIT 1) AS paymentType
  68. FROM cm_pay_shop a
  69. left join sys_user u1 on u1.id = a.applicant
  70. left join sys_user u2 on u2.id = a.reviewer
  71. left join shop s on s.shopID = a.shopID
  72. LEFT JOIN cm_pay_shop_record psr ON psr.payShopID = a.id
  73. LEFT JOIN cm_shop_order so ON so.shopOrderID = psr.shopOrderID
  74. <where>
  75. <if test="id != null and id != ''">
  76. and a.id = #{id}
  77. </if>
  78. <if test="shopName != null and shopName != ''">
  79. and s.name like concat('%', #{shopName}, '%')
  80. </if>
  81. <if test="name != null and name != ''">
  82. AND a.name LIKE
  83. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  84. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  85. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  86. </if>
  87. <if test="startTime != null and startTime != ''">
  88. AND a.applyTime <![CDATA[ >= ]]> #{startTime}
  89. </if>
  90. <if test="endTime != null and endTime != ''">
  91. AND a.applyTime <![CDATA[ <= ]]> #{endTime}
  92. </if>
  93. <if test="startTime2 != null and startTime2 != ''">
  94. AND a.payTime <![CDATA[ >= ]]> #{startTime2}
  95. </if>
  96. <if test="endTime2 != null and endTime2 != ''">
  97. AND a.payTime <![CDATA[ <= ]]> #{endTime2}
  98. </if>
  99. <if test="status != null and status != ''">
  100. AND a.status = #{status}
  101. </if>
  102. <if test="shopOrderNo != null and shopOrderNo != ''">
  103. AND a.id in (select cpsr.payShopID from cm_pay_shop_record cpsr where cpsr.shopOrderNo like concat('%',#{shopOrderNo},'%'))
  104. </if>
  105. <if test="shopOrderID != null and shopOrderID != ''">
  106. AND a.id in (SELECT cpsr.payShopID FROM cm_pay_shop_record cpsr WHERE cpsr.shopOrderID=#{shopOrderID})
  107. </if>
  108. <if test="orderID != null and orderID != ''">
  109. AND a.id in (SELECT cpsr.payShopID FROM cm_pay_shop_record cpsr LEFT JOIN cm_shop_order so ON so.shopOrderID=cpsr.shopOrderID WHERE so.orderID=#{orderID})
  110. </if>
  111. <if test='organizeID != null and organizeID != "" and organizeID != "9999"'>
  112. AND a.id in (SELECT cpsr.payShopID FROM cm_pay_shop_record cpsr LEFT JOIN cm_shop_order so ON so.shopOrderID=cpsr.shopOrderID WHERE so.organizeID = #{organizeID})
  113. </if>
  114. <if test='organizeID == "9999"'>
  115. AND a.id IN (SELECT cpsr.payShopID FROM cm_pay_shop_record cpsr LEFT JOIN cm_shop_order so ON so.shopOrderID=cpsr.shopOrderID WHERE so.orderType = 2)
  116. </if>
  117. <if test="orderNo != null and orderNo != ''">
  118. AND a.id in (SELECT cpsr.payShopID FROM cm_pay_shop_record cpsr LEFT JOIN cm_shop_order so ON so.shopOrderID=cpsr.shopOrderID WHERE so.orderNo LIKE CONCAT('%',#{orderNo},'%'))
  119. </if>
  120. <if test="paymentType != null">
  121. AND a.id IN(SELECT payShopID FROM cm_pay_shop_record WHERE paymentType = #{paymentType} AND delFlag = 0)
  122. </if>
  123. and a.delFlag = '0'
  124. and (so.organizeID!=4 or so.organizeID is null)
  125. and a.shopID != 998
  126. </where>
  127. GROUP BY a.id
  128. <choose>
  129. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  130. ORDER BY ${page.orderBy}
  131. </when>
  132. <otherwise>
  133. ORDER BY a.id desc
  134. </otherwise>
  135. </choose>
  136. </select>
  137. <select id="findAllList" resultType="CmPayShop">
  138. SELECT
  139. <include refid="cmPayShopColumns"/>
  140. FROM cm_pay_shop a
  141. <include refid="cmPayShopJoins"/>
  142. <where>
  143. </where>
  144. <choose>
  145. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  146. ORDER BY ${page.orderBy}
  147. </when>
  148. <otherwise>
  149. </otherwise>
  150. </choose>
  151. </select>
  152. <select id="priceNum" resultType="com.caimei.modules.product.entity.Product">
  153. SELECT cso.shopOrderID,cop.orderProductID,cop.taxRate,cop.discountPrice as price,cop.costPrice as costPrice FROM cm_order co
  154. LEFT JOIN cm_order_product cop ON co.orderID = cop.orderID
  155. LEFT JOIN cm_shop_order cso ON cop.shopOrderNo = cso.shopOrderNo
  156. LEFT JOIN product p ON cop.productID = p.productID WHERE co.orderNo = #{orderNo}
  157. </select>
  158. <insert id="insert" parameterType="CmPayShop" keyProperty="id" useGeneratedKeys="true">
  159. INSERT INTO cm_pay_shop(
  160. shopID,
  161. name,
  162. bankAccountName,
  163. bankAccount,
  164. bankName,
  165. type,
  166. totalAmount,
  167. balancePayFee,
  168. transferPayFee,
  169. payType,
  170. wipePayment,
  171. wipeRemarks,
  172. wipeRemarkImages,
  173. wipeTime,
  174. applicant,
  175. applyTime,
  176. reviewer,
  177. reviewTime,
  178. payTime,
  179. status,
  180. reason,
  181. delFlag
  182. ) VALUES (
  183. #{shopID},
  184. #{name},
  185. #{bankAccountName},
  186. #{bankAccount},
  187. #{bankName},
  188. #{type},
  189. #{totalAmount},
  190. #{balancePayFee},
  191. #{transferPayFee},
  192. #{payType},
  193. #{wipePayment},
  194. #{wipeRemarks},
  195. #{wipeRemarkImages},
  196. #{wipeTime},
  197. #{applicant},
  198. #{applyTime},
  199. #{reviewer},
  200. #{reviewTime},
  201. #{payTime},
  202. #{status},
  203. #{reason},
  204. #{delFlag}
  205. )
  206. </insert>
  207. <update id="update">
  208. UPDATE cm_pay_shop SET
  209. shopID = #{shopID},
  210. name = #{name},
  211. bankAccountName = #{bankAccountName},
  212. bankAccount = #{bankAccount},
  213. bankName = #{bankName},
  214. type = #{type},
  215. totalAmount = #{totalAmount},
  216. balancePayFee = #{balancePayFee},
  217. transferPayFee = #{transferPayFee},
  218. payType = #{payType},
  219. wipePayment = #{wipePayment},
  220. wipeRemarks = #{wipeRemarks},
  221. wipeRemarkImages = #{wipeRemarkImages},
  222. wipeTime = #{wipeTime},
  223. applicant = #{applicant},
  224. applyTime = #{applyTime},
  225. reviewer = #{reviewer},
  226. reviewTime = #{reviewTime},
  227. payTime = #{payTime},
  228. status = #{status},
  229. reason = #{reason},
  230. delFlag = #{delFlag}
  231. WHERE id = #{id}
  232. </update>
  233. <delete id="delete">
  234. DELETE FROM cm_pay_shop
  235. WHERE id = #{id}
  236. </delete>
  237. <select id="orderList" parameterType="string" resultType="com.caimei.modules.order.entity.NewShopOrder">
  238. SELECT DISTINCT so.shopOrderID, so.shopOrderNo, so.orderNo, so.orderID, bou.name AS buyer ,so.organizeID,c.name AS clubName
  239. FROM `cm_pay_shop_record` psr
  240. LEFT JOIN cm_shop_order so ON so.shopOrderID = psr.shopOrderID
  241. LEFT JOIN bp_order_userinfo bou ON so.orderId = bou.orderId
  242. LEFT JOIN club c ON c.userID = so.userID
  243. WHERE psr.payShopID = #{id}
  244. AND psr.delFlag = '0'
  245. </select>
  246. <select id="hasReapply" resultType="integer">
  247. select id from cm_pay_shop_record where shopOrderID in
  248. <foreach collection="shopOrderIds" open="(" close=")" item="shopOrderId" separator=",">
  249. #{shopOrderId}
  250. </foreach>
  251. and payShopID > #{id}
  252. </select>
  253. <select id="findPayOnlineStatus" resultType="java.lang.Integer">
  254. select status from cm_pay_online_switch where id=1
  255. </select>
  256. <select id="getShopOrderIdsList" resultType="java.lang.Integer">
  257. SELECT DISTINCT shopOrderID FROM cm_pay_shop_record WHERE payShopID = #{payShopID} AND delFlag = '0'
  258. </select>
  259. <update id="savePayOnlineStatus">
  260. update cm_pay_online_switch set
  261. status=#{status},
  262. sysUserId=#{userId},
  263. updateTime=NOW()
  264. where id=1
  265. </update>
  266. <select id="getDiscernReceipts" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  267. SELECT
  268. cdr.id,
  269. cdr.payType,
  270. cdr.receiptType,
  271. cdr.receiptAmount,
  272. cdr.receiptDate,
  273. f.bankAccount as bankNameType
  274. FROM
  275. cm_discern_receipt cdr
  276. LEFT JOIN cm_receipt_order_relation cror ON cdr.id = cror.receiptID
  277. LEFT JOIN cm_offline_collection f ON cdr.payType = f.type
  278. WHERE
  279. cror.relationType = 1
  280. AND cror.delFlag = 0
  281. AND cror.orderID = #{shopOrderId}
  282. AND cdr.receiptType = 5
  283. AND cdr.receiptStatus = 2
  284. ORDER BY
  285. receiptDate DESC
  286. </select>
  287. </mapper>