<?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>
|