ApiCartMapper.xml 17 KB

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