1
0

ApiCartMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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="checkCart == null">
  167. <if test="isStockShare == 1">
  168. and b.goods_number > 0
  169. </if>
  170. <if test="isStockShare == 0">
  171. and psr.stock_num > 0
  172. </if>
  173. </if>
  174. <if test="isStockShare == 1 and checkCart != null and checkCart == '00'">
  175. and b.goods_number > 0
  176. </if>
  177. <if test="isStockShare == 0 and checkCart != null and checkCart == '00'">
  178. and psr.stock_num > 0
  179. </if>
  180. <if test="checkCart != null and checkCart == '11'">
  181. and psr.stock_num > 0
  182. </if>
  183. <if test="checkCart != null and checkCart == '00'">
  184. and b.goods_biz_type != '11'
  185. </if>
  186. <if test="checkCart != null and checkCart == '11'">
  187. and b.goods_biz_type = '11'
  188. </if>
  189. <if test="user_id != null">
  190. AND a.user_id = #{user_id}
  191. </if>
  192. <if test="goods_id != null">
  193. AND a.goods_id = #{goods_id}
  194. </if>
  195. <if test="product_id != null">
  196. AND a.product_id = #{product_id}
  197. </if>
  198. <if test="store_id != null">
  199. AND a.store_id = #{store_id}
  200. </if>
  201. <if test="checked != null">
  202. AND a.checked = #{checked}
  203. </if>
  204. </select>
  205. <insert id="save" parameterType="com.kmall.api.entity.CartVo" useGeneratedKeys="true" keyProperty="id">
  206. INSERT INTO mall_cart
  207. <trim prefix="(" suffix=")" suffixOverrides="," >
  208. <if test="user_id != null" >
  209. user_id,
  210. </if>
  211. <if test="stockNum != null" >
  212. stock_num,
  213. </if>
  214. <if test="goods_id != null" >
  215. goods_id,
  216. </if>
  217. <if test="sku != null" >
  218. sku,
  219. </if>
  220. <if test="goods_sn != null" >
  221. goods_sn,
  222. </if>
  223. <if test="product_id != null" >
  224. product_id,
  225. </if>
  226. <if test="goods_name != null" >
  227. goods_name,
  228. </if>
  229. <if test="market_price != null" >
  230. market_price,
  231. </if>
  232. <if test="retail_price != null" >
  233. retail_price,
  234. </if>
  235. <if test="number != null" >
  236. number,
  237. </if>
  238. <if test="goods_specification_ids != null" >
  239. goods_specification_ids,
  240. </if>
  241. <if test="checked != null" >
  242. checked,
  243. </if>
  244. <if test="list_pic_url != null" >
  245. list_pic_url,
  246. </if>
  247. <if test="store_id != null" >
  248. store_id,
  249. </if>
  250. <if test="goodsBizType != null" >
  251. goods_biz_type,
  252. </if>
  253. <if test="createrSn != null" >
  254. creater_sn,
  255. </if>
  256. <if test="createTime != null" >
  257. create_time,
  258. </if>
  259. <if test="moderSn != null" >
  260. moder_sn,
  261. </if>
  262. <if test="modTime != null" >
  263. mod_time,
  264. </if>
  265. <if test="tstm != null" >
  266. tstm,
  267. </if>
  268. <if test="goods_specification_name_value != null" >
  269. goods_specification_name_value,
  270. </if>
  271. <if test="merchSn != null" >
  272. merch_sn,
  273. </if>
  274. </trim>
  275. <trim prefix="values (" suffix=")" suffixOverrides="," >
  276. <if test="user_id != null" >
  277. #{user_id},
  278. </if>
  279. <if test="stockNum != null" >
  280. #{stockNum},
  281. </if>
  282. <if test="goods_id != null" >
  283. #{goods_id,jdbcType=INTEGER},
  284. </if>
  285. <if test="sku != null" >
  286. #{sku,jdbcType=VARCHAR},
  287. </if>
  288. <if test="goods_sn != null" >
  289. #{goods_sn,jdbcType=VARCHAR},
  290. </if>
  291. <if test="product_id != null" >
  292. #{product_id,jdbcType=INTEGER},
  293. </if>
  294. <if test="goods_name != null" >
  295. #{goods_name,jdbcType=VARCHAR},
  296. </if>
  297. <if test="market_price != null" >
  298. #{market_price,jdbcType=DECIMAL},
  299. </if>
  300. <if test="retail_price != null" >
  301. #{retail_price,jdbcType=DECIMAL},
  302. </if>
  303. <if test="number != null" >
  304. #{number,jdbcType=SMALLINT},
  305. </if>
  306. <if test="goods_specification_ids != null" >
  307. #{goods_specification_ids,jdbcType=VARCHAR},
  308. </if>
  309. <if test="checked != null" >
  310. #{checked,jdbcType=BIT},
  311. </if>
  312. <if test="list_pic_url != null" >
  313. #{list_pic_url,jdbcType=VARCHAR},
  314. </if>
  315. <if test="store_id != null" >
  316. #{store_id,jdbcType=INTEGER},
  317. </if>
  318. <if test="goodsBizType != null" >
  319. #{goodsBizType,jdbcType=CHAR},
  320. </if>
  321. <if test="createrSn != null" >
  322. #{createrSn,jdbcType=VARCHAR},
  323. </if>
  324. <if test="createTime != null" >
  325. #{createTime,jdbcType=TIMESTAMP},
  326. </if>
  327. <if test="moderSn != null" >
  328. #{moderSn,jdbcType=VARCHAR},
  329. </if>
  330. <if test="modTime != null" >
  331. #{modTime,jdbcType=TIMESTAMP},
  332. </if>
  333. <if test="tstm != null" >
  334. #{tstm,jdbcType=TIMESTAMP},
  335. </if>
  336. <if test="goods_specification_name_value != null" >
  337. #{goods_specification_name_value,jdbcType=LONGVARCHAR},
  338. </if>
  339. <if test="merchSn != null" >
  340. #{merchSn,jdbcType=LONGVARCHAR},
  341. </if>
  342. </trim>
  343. </insert>
  344. <update id="update" parameterType="com.kmall.api.entity.CartVo">
  345. update mall_cart
  346. <set >
  347. <if test="user_id != null" >
  348. user_id = #{user_id},
  349. </if>
  350. <if test="stockNum != null" >
  351. stock_num = #{stockNum},
  352. </if>
  353. <if test="goods_id != null" >
  354. goods_id = #{goods_id,jdbcType=INTEGER},
  355. </if>
  356. <if test="sku != null" >
  357. sku = #{sku,jdbcType=VARCHAR},
  358. </if>
  359. <if test="goods_sn != null" >
  360. goods_sn = #{goods_sn,jdbcType=VARCHAR},
  361. </if>
  362. <if test="product_id != null" >
  363. product_id = #{product_id,jdbcType=INTEGER},
  364. </if>
  365. <if test="goods_name != null" >
  366. goods_name = #{goods_name,jdbcType=VARCHAR},
  367. </if>
  368. <if test="market_price != null" >
  369. market_price = #{market_price,jdbcType=DECIMAL},
  370. </if>
  371. <if test="retail_price != null" >
  372. retail_price = #{retail_price,jdbcType=DECIMAL},
  373. </if>
  374. <if test="number != null" >
  375. number = #{number,jdbcType=SMALLINT},
  376. </if>
  377. <if test="goods_specification_ids != null" >
  378. goods_specification_ids = #{goods_specification_ids,jdbcType=VARCHAR},
  379. </if>
  380. <if test="checked != null" >
  381. checked = #{checked,jdbcType=BIT},
  382. </if>
  383. <if test="list_pic_url != null" >
  384. list_pic_url = #{list_pic_url,jdbcType=VARCHAR},
  385. </if>
  386. <if test="store_id != null" >
  387. store_id = #{store_id,jdbcType=INTEGER},
  388. </if>
  389. <if test="goodsBizType != null" >
  390. goods_biz_type = #{goodsBizType,jdbcType=CHAR},
  391. </if>
  392. <if test="createrSn != null" >
  393. creater_sn = #{createrSn,jdbcType=VARCHAR},
  394. </if>
  395. <if test="createTime != null" >
  396. create_time = #{createTime,jdbcType=TIMESTAMP},
  397. </if>
  398. <if test="moderSn != null" >
  399. moder_sn = #{moderSn,jdbcType=VARCHAR},
  400. </if>
  401. <if test="modTime != null" >
  402. mod_time = #{modTime,jdbcType=TIMESTAMP},
  403. </if>
  404. <if test="tstm != null" >
  405. tstm = #{tstm,jdbcType=TIMESTAMP},
  406. </if>
  407. <if test="goods_specification_name_value != null" >
  408. goods_specification_name_value = #{goods_specification_name_value,jdbcType=LONGVARCHAR},
  409. </if>
  410. <if test="merchSn != null" >
  411. merch_sn = #{merchSn},
  412. </if>
  413. </set>
  414. where id = #{id}
  415. </update>
  416. <update id="updateCheck">
  417. update mall_cart
  418. set `checked` = #{isChecked}
  419. where goods_id in
  420. <foreach item="goods_id" collection="goodsIds" open="(" separator="," close=")">
  421. #{goods_id}
  422. </foreach>
  423. and user_id = #{user_id} and store_id = #{store_id}
  424. </update>
  425. <delete id="delete">
  426. delete from mall_cart where id = #{value}
  427. </delete>
  428. <delete id="deleteBatch">
  429. delete from mall_cart where id in
  430. <foreach item="id" collection="array" open="(" separator="," close=")">
  431. #{id}
  432. </foreach>
  433. </delete>
  434. <delete id="deleteByProductIds">
  435. delete from mall_cart where product_id in
  436. <foreach item="id" collection="productIds" open="(" separator="," close=")">
  437. #{id}
  438. </foreach>
  439. and store_id = #{store_id}
  440. </delete>
  441. <delete id="deleteByCart">
  442. delete from mall_cart
  443. where user_id = #{user_id} and store_id = #{store_id} and checked = #{checked}
  444. <if test="checkCart != null and checkCart == '00'">
  445. and goods_biz_type != '11'
  446. </if>
  447. <if test="checkCart != null and checkCart == '11'">
  448. and goods_biz_type = '11'
  449. </if>
  450. </delete>
  451. </mapper>