ApiCartMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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.kmall.api.dao.ApiCartMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.api.entity.CartVo" id="cartMap">
  6. <result property="id" column="id"/>
  7. <result property="user_id" column="user_id"/>
  8. <result property="store_id" column="store_id"/>
  9. <result property="goods_id" column="goods_id"/>
  10. <result property="goods_sn" column="goods_sn"/>
  11. <result property="product_id" column="product_id"/>
  12. <result property="goods_name" column="goods_name"/>
  13. <result property="market_price" column="market_price"/>
  14. <result property="retail_price" column="retail_price"/>
  15. <result property="number" column="number"/>
  16. <result property="goods_specification_name_value" column="goods_specification_name_value"/>
  17. <result property="goods_specification_ids" column="goods_specification_ids"/>
  18. <result property="checked" column="checked"/>
  19. <result property="list_pic_url" column="list_pic_url"/>
  20. <result column="sku" property="sku" jdbcType="VARCHAR" />
  21. <result column="goods_biz_type" property="goodsBizType" jdbcType="CHAR" />
  22. <result column="creater_sn" property="createrSn" jdbcType="VARCHAR" />
  23. <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  24. <result column="moder_sn" property="moderSn" jdbcType="VARCHAR" />
  25. <result column="mod_time" property="modTime" jdbcType="TIMESTAMP" />
  26. <result column="tstm" property="tstm" jdbcType="TIMESTAMP" />
  27. <result property="stockNum" column="productStockNum"/>
  28. <result property="merchSn" column="merch_sn"/>
  29. <result property="goodsNumber" column="goods_number"/>
  30. </resultMap>
  31. <sql id="Base_Column_List" >
  32. id, user_id, goods_id, sku, goods_sn, product_id, goods_name, market_price, retail_price,
  33. number, goods_specification_ids, checked, list_pic_url, store_id, goods_biz_type,
  34. creater_sn, create_time, moder_sn, mod_time, tstm,goods_specification_name_value,stock_num,merch_sn
  35. </sql>
  36. <select id="queryObject" resultMap="cartMap">
  37. select
  38. <include refid="Base_Column_List" /> from mall_cart where id = #{value}
  39. </select>
  40. <select id="queryCartByGoodsBizType" resultMap="cartMap">
  41. select
  42. <include refid="Base_Column_List" /> from mall_cart where goods_biz_type = #{goodsBizType}
  43. </select>
  44. <select id="queryObjectByGoodsIdAndUserId" resultMap="cartMap">
  45. SELECT * FROM `mall_cart` where goods_id =#{goods_id} and user_id =#{user_id} and store_id = #{storeId}
  46. </select>
  47. <select id="queryList" resultMap="cartMap">
  48. select a.*,
  49. b.list_pic_url as list_pic_url,
  50. psr.retail_price as retail_product_price,psr.stock_num 'productStockNum',
  51. b.goods_number,mb.is_stock_share isStockShare
  52. from mall_cart a
  53. left join mall_goods b on a.goods_id = b.id
  54. left join third_merchant_biz mb on b.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=b.merch_sn
  55. left join mall_product c on c.goods_id = a.goods_id and c.id = a.product_id
  56. left join mall_product_store_rela psr on psr.product_id = c.id and psr.store_id = #{store_id}
  57. where 1 = 1 and b.is_delete = 0 and b.is_on_sale = 1
  58. <if test="checkCart == null">
  59. <if test="isStockShare == 1">
  60. and b.goods_number > 0
  61. </if>
  62. <if test="isStockShare == 0">
  63. and psr.stock_num > 0
  64. </if>
  65. </if>
  66. <if test="isStockShare == 1 and (checkCart != null and checkCart == '00')">
  67. and b.goods_number > 0
  68. </if>
  69. <if test="isStockShare == 0 and (checkCart != null and checkCart == '00')">
  70. and psr.stock_num > 0
  71. </if>
  72. <if test="checkCart != null and checkCart == '11'">
  73. and psr.stock_num > 0 and b.goods_biz_type = '11'
  74. </if>
  75. <if test="checkCart != null and checkCart == '00'">
  76. and b.goods_biz_type != '11'
  77. </if>
  78. <if test="user_id != null">
  79. AND a.user_id = #{user_id}
  80. </if>
  81. <if test="goods_id != null">
  82. AND a.goods_id = #{goods_id}
  83. </if>
  84. <if test="product_id != null">
  85. AND a.product_id = #{product_id}
  86. </if>
  87. <if test="store_id != null">
  88. AND a.store_id = #{store_id}
  89. </if>
  90. <if test="checked != null">
  91. AND a.checked = #{checked}
  92. </if>
  93. <choose>
  94. <when test="sidx != null and sidx.trim() != ''">
  95. order by ${sidx} ${order}
  96. </when>
  97. <otherwise>
  98. order by a.id desc
  99. </otherwise>
  100. </choose>
  101. <if test="offset != null and limit != null">
  102. limit #{offset}, #{limit}
  103. </if>
  104. </select>
  105. <select id="queryValidCartList" resultMap="cartMap">
  106. select a.*,
  107. b.list_pic_url as list_pic_url,
  108. psr.retail_price as retail_product_price,psr.stock_num 'productStockNum'
  109. from mall_cart a
  110. left join mall_goods b on a.goods_id = b.id
  111. left join mall_product c on c.goods_id = a.goods_id and c.id = a.product_id
  112. left join mall_product_store_rela psr on psr.product_id = c.id and psr.store_id = #{store_id}
  113. where 1 = 1
  114. <if test="isStockShare == 1 and checkCart != null and checkCart == '00'">
  115. and (b.goods_number = 0 or b.is_on_sale = 0)
  116. </if>
  117. <if test="isStockShare == 0 and checkCart != null and checkCart == '00'">
  118. and (psr.stock_num = 0 or b.is_on_sale = 0)
  119. </if>
  120. <if test="checkCart != null and checkCart == '11'">
  121. and (psr.stock_num = 0 or b.is_on_sale = 0)
  122. </if>
  123. <if test="checkCart != null and checkCart == '00'">
  124. and b.goods_biz_type != '11'
  125. </if>
  126. <if test="checkCart != null and checkCart == '11'">
  127. and b.goods_biz_type = '11'
  128. </if>
  129. <if test="merchSn != null">
  130. and a.merch_sn = #{merchSn}
  131. </if>
  132. <if test="user_id != null">
  133. AND a.user_id = #{user_id}
  134. </if>
  135. <if test="goods_id != null">
  136. AND a.goods_id = #{goods_id}
  137. </if>
  138. <if test="product_id != null">
  139. AND a.product_id = #{product_id}
  140. </if>
  141. <if test="store_id != null">
  142. AND psr.store_id = #{store_id}
  143. </if>
  144. <if test="checked != null">
  145. AND a.checked = #{checked}
  146. </if>
  147. <choose>
  148. <when test="sidx != null and sidx.trim() != ''">
  149. order by ${sidx} ${order}
  150. </when>
  151. <otherwise>
  152. order by a.id desc
  153. </otherwise>
  154. </choose>
  155. <if test="offset != null and limit != null">
  156. limit #{offset}, #{limit}
  157. </if>
  158. </select>
  159. <select id="queryTotal" resultType="int">
  160. select count(*)
  161. from mall_cart a
  162. left join mall_goods b on a.goods_id = b.id
  163. left join mall_product c on c.goods_id = a.goods_id and c.id = a.product_id
  164. left join mall_product_store_rela psr on psr.product_id = c.id and psr.store_id = #{store_id}
  165. where 1 = 1 and b.is_delete = 0 and b.is_on_sale = 1
  166. <if test="isStockShare == 1 and checkCart != null and checkCart == '00'">
  167. and b.goods_number > 0
  168. </if>
  169. <if test="isStockShare == 0 and checkCart != null and checkCart == '00'">
  170. and psr.stock_num > 0
  171. </if>
  172. <if test="checkCart != null and checkCart == '11'">
  173. and psr.stock_num > 0
  174. </if>
  175. <if test="checkCart != null and checkCart == '00'">
  176. and b.goods_biz_type != '11'
  177. </if>
  178. <if test="checkCart != null and checkCart == '11'">
  179. and b.goods_biz_type = '11'
  180. </if>
  181. <if test="user_id != null">
  182. AND a.user_id = #{user_id}
  183. </if>
  184. <if test="goods_id != null">
  185. AND a.goods_id = #{goods_id}
  186. </if>
  187. <if test="product_id != null">
  188. AND a.product_id = #{product_id}
  189. </if>
  190. <if test="store_id != null">
  191. AND a.store_id = #{store_id}
  192. </if>
  193. <if test="checked != null">
  194. AND a.checked = #{checked}
  195. </if>
  196. </select>
  197. <insert id="save" parameterType="com.kmall.api.entity.CartVo" useGeneratedKeys="true" keyProperty="id">
  198. INSERT INTO mall_cart
  199. <trim prefix="(" suffix=")" suffixOverrides="," >
  200. <if test="user_id != null" >
  201. user_id,
  202. </if>
  203. <if test="stockNum != null" >
  204. stock_num,
  205. </if>
  206. <if test="goods_id != null" >
  207. goods_id,
  208. </if>
  209. <if test="sku != null" >
  210. sku,
  211. </if>
  212. <if test="goods_sn != null" >
  213. goods_sn,
  214. </if>
  215. <if test="product_id != null" >
  216. product_id,
  217. </if>
  218. <if test="goods_name != null" >
  219. goods_name,
  220. </if>
  221. <if test="market_price != null" >
  222. market_price,
  223. </if>
  224. <if test="retail_price != null" >
  225. retail_price,
  226. </if>
  227. <if test="number != null" >
  228. number,
  229. </if>
  230. <if test="goods_specification_ids != null" >
  231. goods_specification_ids,
  232. </if>
  233. <if test="checked != null" >
  234. checked,
  235. </if>
  236. <if test="list_pic_url != null" >
  237. list_pic_url,
  238. </if>
  239. <if test="store_id != null" >
  240. store_id,
  241. </if>
  242. <if test="goodsBizType != null" >
  243. goods_biz_type,
  244. </if>
  245. <if test="createrSn != null" >
  246. creater_sn,
  247. </if>
  248. <if test="createTime != null" >
  249. create_time,
  250. </if>
  251. <if test="moderSn != null" >
  252. moder_sn,
  253. </if>
  254. <if test="modTime != null" >
  255. mod_time,
  256. </if>
  257. <if test="tstm != null" >
  258. tstm,
  259. </if>
  260. <if test="goods_specification_name_value != null" >
  261. goods_specification_name_value,
  262. </if>
  263. <if test="merchSn != null" >
  264. merch_sn,
  265. </if>
  266. </trim>
  267. <trim prefix="values (" suffix=")" suffixOverrides="," >
  268. <if test="user_id != null" >
  269. #{user_id},
  270. </if>
  271. <if test="stockNum != null" >
  272. #{stockNum},
  273. </if>
  274. <if test="goods_id != null" >
  275. #{goods_id,jdbcType=INTEGER},
  276. </if>
  277. <if test="sku != null" >
  278. #{sku,jdbcType=VARCHAR},
  279. </if>
  280. <if test="goods_sn != null" >
  281. #{goods_sn,jdbcType=VARCHAR},
  282. </if>
  283. <if test="product_id != null" >
  284. #{product_id,jdbcType=INTEGER},
  285. </if>
  286. <if test="goods_name != null" >
  287. #{goods_name,jdbcType=VARCHAR},
  288. </if>
  289. <if test="market_price != null" >
  290. #{market_price,jdbcType=DECIMAL},
  291. </if>
  292. <if test="retail_price != null" >
  293. #{retail_price,jdbcType=DECIMAL},
  294. </if>
  295. <if test="number != null" >
  296. #{number,jdbcType=SMALLINT},
  297. </if>
  298. <if test="goods_specification_ids != null" >
  299. #{goods_specification_ids,jdbcType=VARCHAR},
  300. </if>
  301. <if test="checked != null" >
  302. #{checked,jdbcType=BIT},
  303. </if>
  304. <if test="list_pic_url != null" >
  305. #{list_pic_url,jdbcType=VARCHAR},
  306. </if>
  307. <if test="store_id != null" >
  308. #{store_id,jdbcType=INTEGER},
  309. </if>
  310. <if test="goodsBizType != null" >
  311. #{goodsBizType,jdbcType=CHAR},
  312. </if>
  313. <if test="createrSn != null" >
  314. #{createrSn,jdbcType=VARCHAR},
  315. </if>
  316. <if test="createTime != null" >
  317. #{createTime,jdbcType=TIMESTAMP},
  318. </if>
  319. <if test="moderSn != null" >
  320. #{moderSn,jdbcType=VARCHAR},
  321. </if>
  322. <if test="modTime != null" >
  323. #{modTime,jdbcType=TIMESTAMP},
  324. </if>
  325. <if test="tstm != null" >
  326. #{tstm,jdbcType=TIMESTAMP},
  327. </if>
  328. <if test="goods_specification_name_value != null" >
  329. #{goods_specification_name_value,jdbcType=LONGVARCHAR},
  330. </if>
  331. <if test="merchSn != null" >
  332. #{merchSn,jdbcType=LONGVARCHAR},
  333. </if>
  334. </trim>
  335. </insert>
  336. <update id="update" parameterType="com.kmall.api.entity.CartVo">
  337. update mall_cart
  338. <set >
  339. <if test="user_id != null" >
  340. user_id = #{user_id},
  341. </if>
  342. <if test="stockNum != null" >
  343. stock_num = #{stockNum},
  344. </if>
  345. <if test="goods_id != null" >
  346. goods_id = #{goods_id,jdbcType=INTEGER},
  347. </if>
  348. <if test="sku != null" >
  349. sku = #{sku,jdbcType=VARCHAR},
  350. </if>
  351. <if test="goods_sn != null" >
  352. goods_sn = #{goods_sn,jdbcType=VARCHAR},
  353. </if>
  354. <if test="product_id != null" >
  355. product_id = #{product_id,jdbcType=INTEGER},
  356. </if>
  357. <if test="goods_name != null" >
  358. goods_name = #{goods_name,jdbcType=VARCHAR},
  359. </if>
  360. <if test="market_price != null" >
  361. market_price = #{market_price,jdbcType=DECIMAL},
  362. </if>
  363. <if test="retail_price != null" >
  364. retail_price = #{retail_price,jdbcType=DECIMAL},
  365. </if>
  366. <if test="number != null" >
  367. number = #{number,jdbcType=SMALLINT},
  368. </if>
  369. <if test="goods_specification_ids != null" >
  370. goods_specification_ids = #{goods_specification_ids,jdbcType=VARCHAR},
  371. </if>
  372. <if test="checked != null" >
  373. checked = #{checked,jdbcType=BIT},
  374. </if>
  375. <if test="list_pic_url != null" >
  376. list_pic_url = #{list_pic_url,jdbcType=VARCHAR},
  377. </if>
  378. <if test="store_id != null" >
  379. store_id = #{store_id,jdbcType=INTEGER},
  380. </if>
  381. <if test="goodsBizType != null" >
  382. goods_biz_type = #{goodsBizType,jdbcType=CHAR},
  383. </if>
  384. <if test="createrSn != null" >
  385. creater_sn = #{createrSn,jdbcType=VARCHAR},
  386. </if>
  387. <if test="createTime != null" >
  388. create_time = #{createTime,jdbcType=TIMESTAMP},
  389. </if>
  390. <if test="moderSn != null" >
  391. moder_sn = #{moderSn,jdbcType=VARCHAR},
  392. </if>
  393. <if test="modTime != null" >
  394. mod_time = #{modTime,jdbcType=TIMESTAMP},
  395. </if>
  396. <if test="tstm != null" >
  397. tstm = #{tstm,jdbcType=TIMESTAMP},
  398. </if>
  399. <if test="goods_specification_name_value != null" >
  400. goods_specification_name_value = #{goods_specification_name_value,jdbcType=LONGVARCHAR},
  401. </if>
  402. <if test="merchSn != null" >
  403. merch_sn = #{merchSn},
  404. </if>
  405. </set>
  406. where id = #{id}
  407. </update>
  408. <update id="updateCheck">
  409. update mall_cart
  410. set `checked` = #{isChecked}
  411. where goods_id in
  412. <foreach item="goods_id" collection="goodsIds" open="(" separator="," close=")">
  413. #{goods_id}
  414. </foreach>
  415. and user_id = #{user_id} and store_id = #{store_id}
  416. </update>
  417. <delete id="delete">
  418. delete from mall_cart where id = #{value}
  419. </delete>
  420. <delete id="deleteBatch">
  421. delete from mall_cart where id in
  422. <foreach item="id" collection="array" open="(" separator="," close=")">
  423. #{id}
  424. </foreach>
  425. </delete>
  426. <delete id="deleteByProductIds">
  427. delete from mall_cart where product_id in
  428. <foreach item="id" collection="productIds" open="(" separator="," close=")">
  429. #{id}
  430. </foreach>
  431. and store_id = #{store_id}
  432. </delete>
  433. <delete id="deleteByCart">
  434. delete from mall_cart
  435. where user_id = #{user_id} and store_id = #{store_id} and checked = #{checked}
  436. <if test="checkCart != null and checkCart == '00'">
  437. and goods_biz_type != '11'
  438. </if>
  439. <if test="checkCart != null and checkCart == '11'">
  440. and goods_biz_type = '11'
  441. </if>
  442. </delete>
  443. </mapper>