BaseMapper.xml 17 KB

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