mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?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.sinata.rest.modular.mall.dao.MallGoodsMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.sinata.rest.modular.mall.model.MallGoods">
        <id column="id" property="id" />
        <result column="classify_id_one" property="classifyIdOne" />
        <result column="classify_id_two" property="classifyIdTwo" />
        <result column="goods_no" property="goodsNo" />
        <result column="goods_name" property="goodsName" />
        <result column="goods_title" property="goodsTitle" />
        <result column="goods_image" property="goodsImage" />
        <result column="price" property="price" />
        <result column="price_sale" property="priceSale" />
        <result column="price_member" property="priceMember" />
        <result column="stock" property="stock" />
        <result column="buy_count" property="buyCount" />
        <result column="is_delete" property="isDelete" />
        <result column="state" property="state" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="is_recommend" property="isRecommend" />
        <result column="look_count" property="lookCount" />
        <result column="collect_count" property="collectCount" />
        <result column="audit_remark" property="auditRemark" />
        <result column="sort" property="sort" />
        <result column="tag_ids" property="tagIds" />
        <result column="group_type" property="groupType" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
    </resultMap>
 
    <sql id="Base_Column_List">
        o.id, o.classify_id_one, o.classify_id_two, o.goods_name, o.goods_image, o.price, o.freight,
        o.is_recommend,o.is_delete,o.create_time,o.update_time,o.buy_count,o.look_count,o.collect_count,o.stock,
        o.state,o.audit_remark,o.commission_rate
    </sql>
 
    <!--  增加商品销售量  -->
    <update id="addGoodsBuyCount">
        UPDATE mall_goods SET
        buy_count = buy_count +
        CASE id
        <foreach collection="list" item="data">
            WHEN #{data.goodsId} THEN #{data.stock}
        </foreach>
        END
        WHERE id IN
        <foreach collection="list" open="(" separator="," close=")" item="data">
            #{data.goodsId}
        </foreach>
    </update>
 
    <select id="getGoodsBySkuIdArray" resultType="com.sinata.rest.modular.mall.controller.vo.VoGoodsSku">
        SELECT
            goods.id goods_id, goods.goods_name,goods.goods_image, goods.state, mall_group_spec.start_time, mall_group_spec.end_time, goods.group_type,
            sku.id, sku.sku_id, sku.grep_name, sku.spec_grep, sku.spec_ids, sku.img_url, sku.price, sku.price_sale, sku.price_member, sku.price_merchant, sku.stock, sku.merchant_id,
            city.province_code, city.city_code, city.county_code
        FROM mall_goods_sku sku
        LEFT JOIN mall_group_spec ON mall_group_spec.id = sku.spec_ids
        LEFT JOIN mall_goods goods ON sku.goods_id = goods.id
        LEFT JOIN mem_merchant mer ON mer.id = sku.merchant_id
        LEFT JOIN sys_area_city city ON city.id = mer.city_id
        <where>
            ( sku.id IN
            <foreach collection="skuIdArray" open="(" separator="," close=")" item="ids">
                #{ids}
            </foreach>
            OR sku.sku_id IN
            <foreach collection="skuIdArray" open="(" separator="," close=")" item="ids">
                #{ids}
            </foreach> )
        </where>
    </select>
 
    <select id="getGoodsBySkuIdMerchant" resultType="com.sinata.rest.modular.mall.controller.vo.VoGoodsSku">
        SELECT
            goods.id goods_id, goods.goods_name, goods.state, goods.start_time, goods.end_time, goods.group_type,
            sku.id, sku.sku_id, sku.grep_name, sku.spec_grep, sku.spec_ids, sku.img_url, sku.price, sku.price_sale, sku.price_member, sku.price_merchant, sku.stock, sku.merchant_id,
            city.province_code, city.city_code, city.county_code
        FROM mall_goods_sku sku
        LEFT JOIN mall_goods goods ON sku.goods_id = goods.id
        LEFT JOIN mem_merchant mer ON mer.id = sku.merchant_id
        LEFT JOIN sys_area_city city ON city.id = mer.city_id
        <where>
            ( sku.id IN
            <foreach collection="skuIdArray" open="(" separator="," close=")" item="ids">
                #{ids}
            </foreach>
            OR sku.sku_id IN
            <foreach collection="skuIdArray" open="(" separator="," close=")" item="ids">
                #{ids}
            </foreach> )
            <if test="merchantId != null">
                AND sku.merchant_id = #{merchantId}
            </if>
        </where>
    </select>
 
    <select id="listGoods" resultType="com.sinata.rest.modular.mall.controller.vo.VoGoods">
        SELECT * FROM mall_goods
        WHERE state = #{goodsState} AND is_delete = 0
        <if test="groupType != null and groupType != 12">
            AND group_type = #{groupType}
        </if>
        <if test="groupType != null and groupType == 12">
            AND (group_type = 1 OR group_type = 2)
        </if>
        <if test="merchantId != null">
            AND id IN ( SELECT goods_id FROM mall_goods_sku WHERE merchant_id = #{merchantId} )
        </if>
        <if test="goodsName != null and goodsName != ''">
            and goods_name LIKE CONCAT('%',#{goodsName},'%')
        </if>
        <if test="firstClassifyId != null">
            and classify_id_one = #{firstClassifyId}
        </if>
        <if test="secondClassifyId != null">
            and classify_id_two = #{secondClassifyId}
        </if>
        <if test="type == null or type == 0">
            ORDER BY (collect_count+look_count+buy_count) DESC
        </if>
        <if test="type != null and type == 1">
            ORDER BY create_time DESC
        </if>
        <if test="type != null and type == 2">
            ORDER BY buy_count DESC
        </if>
        <if test="type != null and type == 3">
            ORDER BY price_sale
            <choose>
                <when test="sortType != null and sortType == 2">
                    DESC
                </when>
                <otherwise>
                    ASC
                </otherwise>
            </choose>
        </if>
    </select>
 
    <select id="goodsDetail" parameterType="java.lang.Integer" resultType="com.sinata.rest.modular.mall.controller.vo.VoGoodsDetail">
        SELECT
            sku.price, sku.price_sale, sku.price_member, sku.price_merchant,
            g.*,
            gd.img_list,
            gd.intro_h5,
            gd.intro_image,
            gd.purchase_h5
        FROM
            mall_goods g
        LEFT JOIN mall_goods_sku sku ON g.id = sku.goods_id AND sku.merchant_id = 0
        LEFT JOIN mall_goods_detail gd ON g.id = gd.id
        <where>
            <if test="id != null">
                AND g.id = #{id}
            </if>
        </where>
    </select>
 
    <select id="getHotGoodsByBody" resultType="com.sinata.rest.modular.mall.controller.vo.VoGoods">
        SELECT
        goods.id,goods.buy_count,goods.classify_id_one,goods.goods_image,goods.goods_name,goods.goods_no,goods.state,goods.stock,goods.tag_ids,
        goods.goods_title,goods.group_type,sku.price, sku.price_sale, sku.price_member, IFNULL( orderCount, 0 ) orderCount
        FROM
            mall_goods goods
        LEFT JOIN mall_goods_sku sku ON goods.id = sku.goods_id AND sku.merchant_id = 0
        LEFT JOIN (
            SELECT
            count( 1 ) orderCount, o.goods_id, county_code
            FROM
            mall_order_detail od
            RIGHT JOIN mall_order o ON o.order_no = od.order_no
            <where>
                <if test="stateArray != null">
                    AND o.state IN
                    <foreach collection="stateArray" open="(" separator="," close=")" item="ids">
                        #{ids}
                    </foreach>
                </if>
                <if test="body != null and body.cityCode != null and body.cityCode != ''">
                    AND od.county_code = #{body.cityCode}
                </if>
            </where>
            GROUP BY o.goods_id
        ) goodsCount ON goods.id = goodsCount.goods_id
        WHERE
            goods.state = 1 AND goods.group_type = 0 AND goods.is_delete = 0
        ORDER BY goods.buy_count DESC
        <if test="body != null and body.current != null and body.size != null">
            LIMIT #{body.current}, #{body.size}
        </if>
    </select>
 
    <!--  增加商品的收藏数  -->
    <update id="addCollectCount">
        UPDATE mall_goods SET collect_count = collect_count+1 WHERE id=#{goodsId}
    </update>
 
    <!--  减少商品的收藏数  -->
    <update id="subCollectCount">
        UPDATE mall_goods SET collect_count = collect_count-1 WHERE id=#{goodsId}
    </update>
 
    <!--  增加商品的浏览量  -->
    <update id="addLookCount">
        UPDATE mall_goods SET look_count = look_count+1 WHERE id=#{goodsId}
    </update>
 
    <!--  增加商品的浏览量  -->
    <update id="subLookCount">
        UPDATE mall_goods SET look_count = look_count-1 WHERE id=#{goodsId}
    </update>
 
</mapper>