|
|
|
@ -0,0 +1,83 @@
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
|
|
<mapper namespace="com.yami.shop.dao.BasketMapper">
|
|
|
|
|
<!-- 定义了一个名为 BaseResultMap 的 resultMap,它描述了数据库列和 Basket 类属性之间的映射 -->
|
|
|
|
|
<resultMap id="BaseResultMap" type="com.yami.shop.bean.model.Basket">
|
|
|
|
|
<!--
|
|
|
|
|
WARNING - @mbg.generated
|
|
|
|
|
此注释通常由 MyBatis Generator 自动生成代码时添加,表示此段代码是由工具生成的。
|
|
|
|
|
-->
|
|
|
|
|
<id column="basket_id" jdbcType="BIGINT" property="basketId"/> <!-- 主键映射 -->
|
|
|
|
|
<result column="shop_id" jdbcType="BIGINT" property="shopId"/>
|
|
|
|
|
<result column="prod_id" jdbcType="BIGINT" property="prodId"/>
|
|
|
|
|
<result column="sku_id" jdbcType="BIGINT" property="skuId"/>
|
|
|
|
|
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
|
|
|
|
|
<result column="basket_count" jdbcType="INTEGER" property="basketCount"/>
|
|
|
|
|
<result column="basket_date" jdbcType="TIMESTAMP" property="basketDate"/>
|
|
|
|
|
<result column="discount_id" jdbcType="BIGINT" property="discountId"/>
|
|
|
|
|
<result column="distribution_card_no" jdbcType="VARCHAR" property="distributionCardNo"/>
|
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
<!-- 查询用户的购物车商品项,并返回 ShopCartItemDto 对象列表 -->
|
|
|
|
|
<select id="getShopCartItems" resultType="com.yami.shop.bean.app.dto.ShopCartItemDto">
|
|
|
|
|
SELECT tb.*,tb.basket_count as prod_count,tsd.shop_name,IFNULL(ts.pic,tp.pic)AS pic,ts.price,ts.ori_price,tp.brief,ts.properties,ts.prod_name,ts.sku_name
|
|
|
|
|
FROM tz_basket tb
|
|
|
|
|
LEFT JOIN tz_shop_detail tsd ON tb.shop_id = tsd.shop_id
|
|
|
|
|
LEFT JOIN tz_prod tp ON tb.prod_id = tp.prod_id
|
|
|
|
|
LEFT JOIN tz_sku ts ON tb.sku_id = ts.sku_id
|
|
|
|
|
WHERE tp.status = 1 AND ts.status =1 AND tb.user_id = #{userId}
|
|
|
|
|
ORDER BY tb.`basket_id` DESC
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 根据用户ID和购物车项ID列表删除购物车中的项目 -->
|
|
|
|
|
<delete id="deleteShopCartItemsByBasketIds">
|
|
|
|
|
delete from tz_basket where user_id = #{userId} and basket_id in
|
|
|
|
|
<foreach collection="basketIds" item="basketId" open="(" separator="," close=")">
|
|
|
|
|
#{basketId}
|
|
|
|
|
</foreach>
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<!-- 删除指定用户的所有购物车项 -->
|
|
|
|
|
<delete id="deleteAllShopCartItems">
|
|
|
|
|
delete from tz_basket where user_id = #{userId}
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<!-- 获取已过期的商品项 -->
|
|
|
|
|
<select id="getShopCartExpiryItems" resultType="com.yami.shop.bean.app.dto.ShopCartItemDto">
|
|
|
|
|
SELECT tb.*,tb.basket_count AS prod_count,tsd.shop_name,tp.pic,tp.price,tp.ori_price,tp.brief,ts.properties,ts.prod_name,ts.sku_name
|
|
|
|
|
FROM tz_basket tb
|
|
|
|
|
LEFT JOIN tz_shop_detail tsd ON tb.shop_id = tsd.shop_id
|
|
|
|
|
LEFT JOIN tz_prod tp ON tb.prod_id = tp.prod_id
|
|
|
|
|
LEFT JOIN tz_sku ts ON tb.sku_id = ts.sku_id
|
|
|
|
|
WHERE (tp.status = 0 OR ts.status =0) AND tb.user_id = #{userId}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 清理所有状态为非激活的产品条目 -->
|
|
|
|
|
<delete id="cleanExpiryProdList">
|
|
|
|
|
DELETE FROM tz_basket
|
|
|
|
|
WHERE basket_id IN(
|
|
|
|
|
SELECT basket_id FROM (
|
|
|
|
|
SELECT tb.basket_id basket_id
|
|
|
|
|
FROM tz_basket tb
|
|
|
|
|
LEFT JOIN tz_shop_detail tsd
|
|
|
|
|
ON tb.shop_id = tsd.shop_id
|
|
|
|
|
LEFT JOIN tz_prod tp
|
|
|
|
|
ON tb.prod_id = tp.prod_id
|
|
|
|
|
LEFT JOIN tz_sku ts
|
|
|
|
|
ON tb.sku_id = ts.sku_id
|
|
|
|
|
WHERE (tp.status = 0 OR ts.status = 0) AND tb.user_id = #{userId}) AS temp)
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<!-- 更新购物车项的折扣项ID -->
|
|
|
|
|
<update id="updateDiscountItemId">
|
|
|
|
|
<foreach collection="basketIdShopCartParamMap" index="key" item="shopCartParam" separator=";">
|
|
|
|
|
UPDATE tz_basket SET discount_id = #{shopCartParam.discountId} where basket_id = #{key} and user_id = #{userId}
|
|
|
|
|
</foreach>
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<!-- 根据产品ID列出拥有该产品的用户ID -->
|
|
|
|
|
<select id="listUserIdByProdId" resultType="java.lang.String">
|
|
|
|
|
select user_id from tz_basket where prod_id = #{prodId}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
</mapper>
|