BaseMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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.caimei365.order.mapper.BaseMapper">
  4. <select id="getShopNameById" resultType="java.lang.String">
  5. SELECT `name`
  6. FROM shop
  7. WHERE shopID = #{shopId}
  8. LIMIT 1
  9. </select>
  10. <select id="getClubNameById" resultType="java.lang.String">
  11. SELECT `name`
  12. FROM club
  13. WHERE clubID = #{clubId}
  14. LIMIT 1
  15. </select>
  16. <insert id="insertUserInvoiceByUserId" parameterType="com.caimei365.order.model.vo.InvoiceVo">
  17. INSERT INTO cm_user_invoiceinfo (userId, invoiceTitle, corporationTaxNum, registeredAddress, registeredPhone,
  18. bankAccountNo, openBank)
  19. VALUES (#{userId}, #{invoiceTitle}, #{corporationTaxNum}, #{registeredAddress}, #{registeredPhone},
  20. #{bankAccountNo}, #{openBank})
  21. </insert>
  22. <insert id="insertPurchasePrice" keyColumn="id" keyProperty="id"
  23. parameterType="com.caimei365.order.model.po.PurchasePricePo" useGeneratedKeys="true">
  24. INSERT INTO repeat_purchase_price (userId, clubId, orderId, productId, shopId, shopName,
  25. taxRate, currentPrice, createTime, updateTime, delFlag)
  26. VALUES (#{userId}, #{clubId}, #{orderId}, #{productId}, #{shopId}, #{shopName},
  27. #{taxRate}, #{currentPrice}, #{createTime}, #{updateTime}, #{delFlag})
  28. </insert>
  29. <insert id="insertPurchaseHistory" keyColumn="id" keyProperty="id"
  30. parameterType="com.caimei365.order.model.po.PurchaseHistoryPo" useGeneratedKeys="true">
  31. INSERT INTO repeat_purchase_price_history (userId, clubId, orderId, productId, price, currentCostPrice,
  32. createTime, delFlag)
  33. VALUES (#{userId}, #{clubId}, #{orderId}, #{productId}, #{price}, #{currentCostPrice}, #{createTime},
  34. #{delFlag})
  35. </insert>
  36. <update id="updateUserInvoiceByUserId" parameterType="com.caimei365.order.model.vo.InvoiceVo">
  37. UPDATE cm_user_invoiceinfo
  38. SET invoiceTitle = #{invoiceTitle},
  39. corporationTaxNum = #{corporationTaxNum},
  40. registeredAddress = #{registeredAddress},
  41. registeredPhone = #{registeredPhone},
  42. bankAccountNo = #{bankAccountNo},
  43. openBank = #{openBank}
  44. WHERE userId = #{userId}
  45. </update>
  46. <update id="updatePurchasePrice">
  47. UPDATE repeat_purchase_price
  48. SET currentPrice = #{currentPrice},
  49. taxRate = #{taxRate},
  50. updateTime = #{updateTime}
  51. WHERE id = #{id}
  52. </update>
  53. <select id="getUserIdByClubId" resultType="java.lang.Integer">
  54. select userID
  55. from user
  56. where clubID = #{clubId}
  57. LIMIT 1
  58. </select>
  59. <select id="getIdentityByUserId" resultType="java.lang.Integer">
  60. select ifnull(userIdentity,0)
  61. from user
  62. where userID = #{userId}
  63. LIMIT 1
  64. </select>
  65. <select id="getUserNameByUserId" resultType="java.lang.String">
  66. select userName
  67. from user
  68. where userID = #{userId}
  69. LIMIT 1
  70. </select>
  71. <select id="getLadderPriceList" resultType="com.caimei365.order.model.vo.LadderPriceVo">
  72. select id,
  73. productId,
  74. ladderNum,
  75. buyNum,
  76. buyPrice
  77. from product_ladder_price
  78. where productId = #{productId}
  79. and userType = 3
  80. and delFlag = 0
  81. order by ladderNum asc
  82. </select>
  83. <select id="getRepurchasePrice" resultType="java.lang.Double">
  84. select r.currentPrice
  85. from repeat_purchase_price r
  86. left join product p on p.productID = r.productId
  87. where r.productId = #{productId}
  88. and r.userId = #{userId}
  89. and ((p.costCheckFlag = 1 and r.currentPrice <![CDATA[ >= ]]> p.costPrice) or p.costCheckFlag = 2)
  90. and p.price <![CDATA[ >= ]]> r.currentPrice
  91. and r.delFlag = 0
  92. </select>
  93. <select id="getPromotionByShopId" resultType="com.caimei365.order.model.vo.PromotionsVo">
  94. SELECT pr.id,
  95. pr.name,
  96. pr.description,
  97. pr.type,
  98. pr.mode,
  99. pr.touchPrice,
  100. pr.reducedPrice,
  101. pr.beginTime,
  102. pr.endTime,
  103. pr.status,
  104. prp.productId,
  105. prp.supplierId AS shopId,
  106. pr.seen,
  107. pr.discount
  108. FROM cm_promotions pr
  109. LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
  110. WHERE prp.supplierId = #{shopId}
  111. and pr.delFlag = 0
  112. and pr.type = 3
  113. AND (pr.status = 1 OR (pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
  114. ORDER BY pr.type DESC
  115. LIMIT 1
  116. </select>
  117. <select id="getPromotionByProductId" resultType="com.caimei365.order.model.vo.PromotionsVo">
  118. SELECT pr.id,
  119. pr.name,
  120. pr.description,
  121. pr.type,
  122. pr.mode,
  123. pr.touchPrice,
  124. pr.reducedPrice,
  125. pr.beginTime,
  126. pr.endTime,
  127. pr.status,
  128. prp.productId,
  129. prp.supplierId AS shopId,
  130. pr.discount,
  131. pr.seen
  132. FROM cm_promotions pr
  133. LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
  134. WHERE prp.productId = #{productId}
  135. and pr.delFlag = 0
  136. and pr.type in (1, 2)
  137. AND (pr.status = 1 OR (pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
  138. ORDER BY pr.type DESC
  139. LIMIT 1
  140. </select>
  141. <select id="getPromotionGifts" resultType="com.caimei365.order.model.vo.CartItemVo">
  142. SELECT cpg.id AS id,
  143. p.productID AS productId,
  144. p.shopID AS shopId,
  145. p.`name` AS `name`,
  146. p.mainImage AS image,
  147. cpg.number AS number,
  148. 0 AS price,
  149. 2 as productType,
  150. p.price AS originalPrice,
  151. p.unit AS unit,
  152. p.stock AS stock,
  153. p.validFlag AS validFlag
  154. FROM cm_promotions_gift cpg
  155. LEFT JOIN product p ON cpg.productId = p.productID
  156. WHERE cpg.promotionsId = #{promotionsId}
  157. ORDER BY cpg.id DESC
  158. </select>
  159. <select id="getShopByProductId" resultType="com.caimei365.order.model.vo.CartShopVo">
  160. SELECT s.shopID AS shopId,
  161. s.name AS shopName,
  162. s.logo AS shopLogo
  163. FROM shop s
  164. LEFT JOIN product p ON p.shopID = s.shopID
  165. WHERE p.productId = #{productId}
  166. LIMIT 1
  167. </select>
  168. <select id="getUserInvoice" resultType="com.caimei365.order.model.vo.InvoiceVo">
  169. SELECT id,
  170. userId,
  171. invoiceTitle,
  172. corporationTaxNum,
  173. registeredAddress,
  174. registeredPhone,
  175. bankAccountNo,
  176. openBank
  177. FROM cm_user_invoiceinfo
  178. WHERE userId = #{userId}
  179. LIMIT 1
  180. </select>
  181. <select id="getUserMoney" resultType="java.lang.Double">
  182. SELECT userMoney
  183. FROM user
  184. WHERE userID = #{userId}
  185. </select>
  186. <select id="getAbleUserMoney" resultType="java.lang.Double">
  187. SELECT ableUserMoney
  188. FROM user
  189. WHERE userID = #{userId}
  190. </select>
  191. <select id="getUserBeans" resultType="java.lang.Integer">
  192. SELECT userBeans
  193. FROM user
  194. WHERE userID = #{userId}
  195. </select>
  196. <select id="getPostageFlagList" resultType="com.caimei365.order.model.vo.ProductPostageVo">
  197. SELECT
  198. productID AS productId,
  199. freePostFlag AS postageFlag,
  200. commodityType
  201. FROM product
  202. WHERE validFlag='2' AND productID in
  203. <foreach collection="productIds" open="(" separator="," close=")" item="productId">
  204. #{productId}
  205. </foreach>
  206. </select>
  207. <select id="countUserOrder" resultType="java.lang.Integer">
  208. SELECT COUNT(*)
  209. FROM cm_order
  210. WHERE userID = #{userId}
  211. AND delFlag = 0
  212. AND STATUS != 6
  213. </select>
  214. <select id="getProvinceIdAndCityId" resultType="com.caimei365.order.model.vo.AddressVo">
  215. SELECT provinceID AS provinceId, cityID AS cityId
  216. FROM city
  217. WHERE cityID = (SELECT cityID from town where townID = #{townId})
  218. </select>
  219. <select id="getTownIdByAddressId" resultType="java.lang.Integer">
  220. SELECT townID
  221. FROM address
  222. WHERE addressID = #{addressId}
  223. </select>
  224. <select id="getPurchasePricePo" resultType="com.caimei365.order.model.po.PurchasePricePo">
  225. SELECT id,
  226. userId,
  227. clubId,
  228. orderId,
  229. productId,
  230. shopId,
  231. shopName,
  232. taxRate,
  233. currentPrice,
  234. createTime
  235. FROM repeat_purchase_price
  236. WHERE userId = #{userId}
  237. AND productId = #{productId}
  238. AND delFlag = '0'
  239. </select>
  240. <select id="getBindMobileByUserId" resultType="java.lang.String">
  241. SELECT bindMobile
  242. FROM user
  243. WHERE userID = #{userId}
  244. </select>
  245. <select id="getShopIdByproductId" resultType="java.lang.Integer">
  246. SELECT shopID
  247. FROM product
  248. WHERE productID = #{productId}
  249. </select>
  250. <select id="getClauseList" resultType="com.caimei365.order.model.vo.ClauseVo">
  251. SELECT id,
  252. name,
  253. content,
  254. clauseType,
  255. enabledStatus
  256. FROM bp_clause
  257. </select>
  258. <insert id="insertDiscernReceipt" keyColumn="id" keyProperty="id"
  259. parameterType="com.caimei365.order.model.po.DiscernReceiptPo" useGeneratedKeys="true">
  260. INSERT INTO cm_discern_receipt (payWay, payType, receiptType, receiptStatus, receiptAmount, confirmType,
  261. receiptDate, confirmDate, reviewDate, updateDate, delFlag, rePayFlag, formData)
  262. VALUES (#{payWay}, #{payType}, #{receiptType}, #{receiptStatus}, #{receiptAmount}, #{confirmType},
  263. #{receiptDate}, #{confirmDate}, #{reviewDate}, #{updateDate}, #{delFlag}, #{rePayFlag}, #{formData})
  264. </insert>
  265. <insert id="insertOrderReceiptRelation" keyColumn="id" keyProperty="id"
  266. parameterType="com.caimei365.order.model.po.OrderReceiptRelationPo" useGeneratedKeys="true">
  267. INSERT INTO cm_receipt_order_relation (relationType, receiptId, associateAmount, orderId, couponRecordId, vipRecordId,authVipRecordId, delFlag,
  268. mbOrderId, orderRequestNo, splitStatus, productId)
  269. VALUES (#{relationType}, #{receiptId}, #{associateAmount}, #{orderId},#{couponRecordId}, #{vipRecordId}, #{authVipRecordId}, #{delFlag}, #{mbOrderId},
  270. #{orderRequestNo}, #{splitStatus}, #{productId})
  271. </insert>
  272. <insert id="insertBeansHistory" parameterType="com.caimei365.order.model.po.UserBeansHistoryPo">
  273. INSERT INTO user_beans_history (userId, type, beansType, orderId, num, pushStatus, addTime, delFlag)
  274. VALUES (#{userId}, #{type}, #{beansType}, #{orderId}, #{num}, #{pushStatus}, #{addTime}, #{delFlag})
  275. </insert>
  276. <update id="updateUserBeans">
  277. UPDATE USER
  278. SET userBeans = #{userBeans}
  279. WHERE userID = #{userId}
  280. </update>
  281. <update id="updateUserClubStatus">
  282. UPDATE user
  283. SET clubStatus = #{clubStatus}
  284. WHERE userID = #{userId}
  285. </update>
  286. <update id="updateClubStatus">
  287. UPDATE club
  288. SET status = #{clubStatus}
  289. WHERE userID = #{userId}
  290. </update>
  291. <insert id="insertBalanceRecord" parameterType="com.caimei365.order.model.po.BalanceRecordPo">
  292. INSERT INTO cm_user_balance_record (userId, type, balanceType, addDate, amount, orderId, remark, delFlag)
  293. VALUES (#{userId}, #{type}, #{balanceType}, #{addDate}, #{amount}, #{orderId}, #{remark}, #{delFlag})
  294. </insert>
  295. <select id="getSvipUserIdByUserId" resultType="java.lang.Integer">
  296. select userId
  297. from cm_svip_user
  298. where userId = #{userId}
  299. and delFlag = '0'
  300. and now() <![CDATA[ < ]]> endTime
  301. </select>
  302. <select id="getSvipUserIdByClubId" resultType="java.lang.Integer">
  303. select svu.userId
  304. from cm_svip_user svu
  305. left join club c on svu.userId = c.userID
  306. where c.clubID = #{clubId}
  307. and delFlag = '0'
  308. and now() <![CDATA[ < ]]> endTime;
  309. </select>
  310. <select id="getClubStatus" resultType="java.lang.Integer">
  311. select clubStatus
  312. from user
  313. where userID = #{userId}
  314. </select>
  315. <select id="getClubConfirmTime" resultType="java.util.Date">
  316. SELECT confirmTime
  317. FROM club_confirm_record
  318. WHERE userId = #{userId}
  319. ORDER BY confirmTime DESC
  320. LIMIT 1
  321. </select>
  322. <select id="findLowOrder" resultType="com.caimei365.order.model.po.UserBeansHistoryPo">
  323. select id, userId, type, beansType, orderId, num, addTime
  324. from user_beans_history
  325. where orderId = #{orderId}
  326. and delFlag = 0
  327. and type = 2
  328. and num = 500
  329. </select>
  330. <select id="findBeans" resultType="java.lang.Integer">
  331. select userBeans from user where userID=#{userId}
  332. </select>
  333. <select id="getonlineMoney" resultType="java.lang.Double">
  334. select onlineMoney FROM USER WHERE userId = #{userId}
  335. </select>
  336. <select id="getAuthUser" resultType="com.caimei365.order.model.vo.AuthUserVo">
  337. select authUserId,name,mobile
  338. from cm_brand_auth_user
  339. where authUserId = #{userId}
  340. LIMIT 1
  341. </select>
  342. </mapper>