jiangqs
2023-05-10 7a49bcc5e561df7a9b65266a57a9c0896c0fd3d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?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.ruoyi.order.mapper.order.ShoppingCartMapper">
 
    <resultMap type="ShoppingCart" id="ShoppingCartResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="userId"    column="user_id"    />
        <result property="shopId"    column="shop_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="buyNum"    column="buy_num"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
 
    <sql id="selectShoppingCartVo">
        select id, del_flag, user_id, shop_id, goods_id, buy_num, create_time, update_time from t_shopping_cart
    </sql>
 
    <select id="selectShoppingCartList" parameterType="ShoppingCart" resultMap="ShoppingCartResult">
        <include refid="selectShoppingCartVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="shopId != null "> and shop_id = #{shopId}</if>
            <if test="goodsId != null  and goodsId != ''"> and goods_id = #{goodsId}</if>
            <if test="buyNum != null "> and buy_num = #{buyNum}</if>
        </where>
    </select>
 
    <select id="selectShoppingCartById" parameterType="Long" resultMap="ShoppingCartResult">
        <include refid="selectShoppingCartVo"/>
        where id = #{id}
    </select>
 
    <insert id="insertShoppingCart" parameterType="ShoppingCart" useGeneratedKeys="true" keyProperty="id">
        insert into t_shopping_cart
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="delFlag != null">del_flag,</if>
            <if test="userId != null">user_id,</if>
            <if test="shopId != null">shop_id,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="buyNum != null">buy_num,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="delFlag != null">#{delFlag},</if>
            <if test="userId != null">#{userId},</if>
            <if test="shopId != null">#{shopId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="buyNum != null">#{buyNum},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
 
    <update id="updateShoppingCart" parameterType="ShoppingCart">
        update t_shopping_cart
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="shopId != null">shop_id = #{shopId},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="buyNum != null">buy_num = #{buyNum},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteShoppingCartById" parameterType="Long">
        update t_shopping_cart set del_flag = 1 where id = #{id}
    </delete>
 
    <delete id="deleteShoppingCartByIds" parameterType="String">
        update t_shopping_cart set del_flag = 1 where id in
        <foreach item="ids" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <select id="listShoppingCartVo" resultType="com.ruoyi.order.domain.vo.AppShoppingCartVo">
        SELECT
        tsc.id shoppingCartId,
        tg.goods_id goodsId,
        tg.goods_name goodsName,
        tg.goods_introduction goodsIntroduction,
        tg.goods_type goodsType,
        CASE tg.goods_type
        WHEN 1 THEN "周期"
        WHEN 2 THEN "服务"
        WHEN 3 THEN "体验"
        WHEN 4 THEN "单品"
        END goodsTag,
        IFNULL(tsg.sales_price,tg.sales_price) salesPrice,
        tgf.file_url goodsPicture,
        tg.goods_nurses goodsNurses,
        buy_num buyNum
        FROM t_shopping_cart tsc
        INNER JOIN t_goods tg ON tsc.goods_id = tg.goods_id
        LEFT JOIN t_goods_file tgf ON tg.goods_id = tgf.goods_id AND tgf.del_flag = 0 AND tgf.file_type = 1
        LEFT JOIN t_shop_goods tsg ON tg.goods_id = tsg.goods_id AND tsg.shop_id = #{shopId}
        WHERE tg.del_flag = 0 AND tsc.shop_id = #{shopId} AND tsc.user_id = #{userId} AND tg.del_flag = 0 AND tg.goods_status = 1 AND tg.recommend_flag = 1
        ORDER BY tg.create_time DESC
    </select>
</mapper>