1
0

ApiCartMapper.xml 21 KB

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