ApiCartMapper.xml 19 KB

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