250 lines
11 KiB
XML
250 lines
11 KiB
XML
<?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.chaozhanggui.system.cashierservice.dao.TbProductMapper">
|
|
|
|
<resultMap type="com.chaozhanggui.system.cashierservice.entity.TbProduct" id="BaseResultMap">
|
|
<result property="id" column="id" jdbcType="INTEGER"/>
|
|
<result property="categoryId" column="category_id" jdbcType="VARCHAR"/>
|
|
<result property="specId" column="spec_id" jdbcType="INTEGER"/>
|
|
<result property="shopId" column="shop_id" jdbcType="VARCHAR"/>
|
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
|
<result property="shortTitle" column="short_title" jdbcType="VARCHAR"/>
|
|
<result property="type" column="type" jdbcType="VARCHAR"/>
|
|
<result property="packFee" column="pack_fee" jdbcType="NUMERIC"/>
|
|
<result property="lowPrice" column="low_price" jdbcType="NUMERIC"/>
|
|
<result property="unitId" column="unit_id" jdbcType="INTEGER"/>
|
|
<result property="coverImg" column="cover_img" jdbcType="VARCHAR"/>
|
|
<result property="images" column="images" jdbcType="VARCHAR"/>
|
|
<result property="sort" column="sort" jdbcType="INTEGER"/>
|
|
<result property="status" column="status" jdbcType="INTEGER"/>
|
|
<result property="isHot" column="is_hot" jdbcType="INTEGER"/>
|
|
<result property="typeEnum" column="type_enum" jdbcType="VARCHAR"/>
|
|
<result property="isDel" column="is_del" jdbcType="INTEGER"/>
|
|
<result property="isStock" column="is_stock" jdbcType="INTEGER"/>
|
|
<result property="isPauseSale" column="is_pause_sale" jdbcType="INTEGER"/>
|
|
<result property="createdAt" column="created_at" jdbcType="INTEGER"/>
|
|
<result property="updatedAt" column="updated_at" jdbcType="INTEGER"/>
|
|
<result property="groupType" column="group_type" jdbcType="INTEGER"/>
|
|
<result property="groupSnap" column="group_snap" jdbcType="VARCHAR"/>
|
|
<result property="specInfo" column="spec_info" jdbcType="VARCHAR"/>
|
|
<result property="selectSpec" column="select_spec" jdbcType="VARCHAR"/>
|
|
<result property="specTableHeaders" column="spec_table_headers" jdbcType="VARCHAR"/>
|
|
<result property="groupCategoryId" column="group_category_id" jdbcType="VARCHAR"/>
|
|
<result property="realSalesNumber" column="real_sales_number" jdbcType="INTEGER"/>
|
|
<result property="stockNumber" column="stock_number" jdbcType="INTEGER"/>
|
|
<result property="isGrounding" column="is_grounding" jdbcType="INTEGER"/>
|
|
<result property="isRefundStock" column="is_refund_stock" jdbcType="INTEGER"/>
|
|
<result property="warnLine" column="warn_line" jdbcType="INTEGER"/>
|
|
<result property="showType" column="show_type" jdbcType="VARCHAR"/>
|
|
<result property="weight" column="weight" jdbcType="NUMERIC"/>
|
|
<result property="isTempPrice" column="is_temp_price" jdbcType="INTEGER"/>
|
|
<result property="dayLimit" column="day_limit" jdbcType="INTEGER"/>
|
|
<result property="singleOrderLimit" column="single_order_limit" jdbcType="INTEGER"/>
|
|
<result property="singlePeopleLimit" column="single_people_limit" jdbcType="INTEGER"/>
|
|
<result property="days" column="days" jdbcType="VARCHAR"/>
|
|
<result property="startTime" column="start_time" jdbcType="VARCHAR"/>
|
|
<result property="endTime" column="end_time" jdbcType="VARCHAR"/>
|
|
</resultMap>
|
|
|
|
<sql id="Base_Column_List">
|
|
id
|
|
, category_id, spec_id, shop_id, name, short_title, type, pack_fee,
|
|
low_price, unit_id, cover_img, images, sort, status, fail_msg, is_hot, type_enum,
|
|
is_del, is_stock, is_pause_sale, created_at, updated_at, group_type, group_snap,
|
|
spec_info, select_spec, spec_table_headers, group_category_id, real_sales_number,
|
|
stock_number, is_grounding, is_refund_stock, warn_line, show_type, weight, is_temp_price,
|
|
day_limit, single_order_limit, single_people_limit, days, start_time, end_time </sql>
|
|
|
|
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
|
select
|
|
<include refid="Base_Column_List"/>
|
|
from tb_product
|
|
where id = #{id,jdbcType=INTEGER}
|
|
</select>
|
|
|
|
|
|
<select id="selectByIdInAndCheck" resultMap="BaseResultMap">
|
|
select min(sku.suit) as suit, tb.*, sum(sku.real_sales_number) as stockNumber
|
|
from tb_product tb
|
|
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id and sku.is_del = 0
|
|
where tb.id in (${ids})
|
|
and tb.is_grounding = 1 and tb.type!='coupon' and tb.type != 'weigh' and tb.status = 1 and tb.is_del = 0
|
|
and tb.days LIKE concat('%',DAYNAME(CURRENT_DATE),'%') and tb.start_time <= CURRENT_TIMESTAMP and tb.end_time >= CURRENT_TIMESTAMP
|
|
group by tb.id
|
|
order by tb.sort asc
|
|
</select>
|
|
|
|
<select id="selectHot" resultMap="BaseResultMap">
|
|
select min(sku.suit) as suit, tb.* ,top_products.realSalesNumber as stockNumber
|
|
from tb_product tb
|
|
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id
|
|
JOIN (SELECT product_id ,SUM(real_sales_number) as realSalesNumber
|
|
FROM tb_product_sku
|
|
WHERE
|
|
shop_id = #{shopId} and is_del = 0 AND product_id IN
|
|
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
|
|
#{item}
|
|
</foreach>
|
|
GROUP BY product_id
|
|
ORDER BY realSalesNumber DESC LIMIT 3) AS top_products ON tb.id = top_products.product_id
|
|
where
|
|
tb.status = 1
|
|
and tb.type != 'coupon' and tb.is_del = 0
|
|
and tb.days LIKE concat('%',DAYNAME(CURRENT_DATE),'%') and tb.start_time <= CURRENT_TIMESTAMP and tb.end_time >= CURRENT_TIMESTAMP
|
|
and tb.is_grounding = 1
|
|
group by tb.id
|
|
order by stockNumber desc
|
|
</select>
|
|
|
|
|
|
<select id="selectIsSpecialty" resultMap="BaseResultMap">
|
|
select min(sku.suit) as suit, tb.*
|
|
from tb_product tb
|
|
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id and sku.is_del = 0
|
|
where is_hot = 1
|
|
and tb.shop_id = #{shopId}
|
|
and tb.status = 1
|
|
and tb.is_grounding = 1
|
|
and tb.type != 'coupon' and tb.type != 'weigh' and tb.is_del = 0
|
|
and tb.days LIKE concat('%',DAYNAME(CURRENT_DATE),'%') and tb.start_time <= CURRENT_TIMESTAMP and tb.end_time >= CURRENT_TIMESTAMP
|
|
group by tb.id
|
|
order by tb.sort asc
|
|
</select>
|
|
|
|
<select id="selectById" resultType="com.chaozhanggui.system.cashierservice.entity.TbProduct">
|
|
select
|
|
<include refid="Base_Column_List"/>
|
|
from tb_product
|
|
where id = #{id,jdbcType=INTEGER}
|
|
</select>
|
|
|
|
<select id="selectByQcode" resultType="java.lang.Integer">
|
|
SELECT IFNULL(sum(t.number), 0)
|
|
FROM tb_cashier_cart t
|
|
WHERE t.shop_id = #{shopId}
|
|
AND t.product_id = #{productId}
|
|
AND t.`status` = 'create'
|
|
AND t.table_id = #{code}
|
|
GROUP BY t.shop_id,
|
|
t.product_id
|
|
</select>
|
|
<select id="selectByCodeAndSkuId" resultType="java.lang.Integer">
|
|
SELECT SUM(IFNULL(t.number, 0))
|
|
FROM tb_cashier_cart t
|
|
WHERE t.shop_id = #{shopId}
|
|
AND t.sku_id = #{skuId}
|
|
AND t.`status` = 'create'
|
|
AND t.table_id = #{code}
|
|
</select>
|
|
<select id="selectByNewQcode" resultType="java.lang.Integer">
|
|
SELECT
|
|
IFNULL( sum( t.number ), 0 )
|
|
FROM
|
|
tb_cashier_cart t
|
|
WHERE
|
|
t.shop_id = #{shopId}
|
|
AND t.product_id = #{productId}
|
|
AND t.`status` = 'create'
|
|
AND t.table_id = #{code}
|
|
AND user_id IN
|
|
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
|
|
#{item}
|
|
</foreach>
|
|
GROUP BY
|
|
t.shop_id,
|
|
t.product_id
|
|
</select>
|
|
<select id="selectByIds" resultType="com.chaozhanggui.system.cashierservice.entity.TbProduct">
|
|
select *
|
|
from tb_product
|
|
where id IN
|
|
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
|
|
#{item}
|
|
</foreach>
|
|
</select>
|
|
|
|
|
|
<select id="selGroups" resultType="com.chaozhanggui.system.cashierservice.entity.vo.ShopGroupInfoVo">
|
|
SELECT
|
|
info.id AS shopId,
|
|
info.shop_name AS shopName,
|
|
info.logo AS shopImg,
|
|
info.tag AS shopTag,
|
|
info.lat AS lat,
|
|
info.lng AS lng,
|
|
info.districts as districts,
|
|
pro.id AS proId,
|
|
pro.`name` AS proName,
|
|
pro.cover_img AS proImg,
|
|
pro.real_sales_number AS number
|
|
FROM
|
|
tb_product pro
|
|
LEFT JOIN tb_shop_info AS info ON info.id = pro.shop_id
|
|
<where>
|
|
info.`status`='1'
|
|
AND pro.type = 'coupon'
|
|
AND (info.cities = #{cities} or info.districts = #{cities})
|
|
<if test="proName != null and proName != ''">
|
|
AND pro.`name` LIKE concat('%',#{proName,jdbcType=VARCHAR},'%')
|
|
</if>
|
|
<if test="type != null and type != ''">
|
|
AND group_category_id LIKE concat('%',#{type,jdbcType=VARCHAR},'%')
|
|
</if>
|
|
<if test="rightTopLng != null and rightTopLng != '' and leftBottomLng != null and leftBottomLng != ''">
|
|
AND info.lng BETWEEN #{leftBottomLng} AND #{rightTopLng}
|
|
AND info.lat BETWEEN #{leftBottomLat} AND #{rightTopLat}
|
|
</if>
|
|
</where>
|
|
<choose>
|
|
<when test="orderBy == 1">
|
|
ORDER BY (ABS(info.lat - #{lat}) + ABS(info.lng - #{lng})) ASC
|
|
</when>
|
|
<when test="orderBy == 2">
|
|
ORDER BY pro.real_sales_number desc
|
|
</when>
|
|
<when test="orderBy == 3">
|
|
ORDER BY pro.low_price ASC
|
|
</when>
|
|
<otherwise>
|
|
ORDER BY pro.real_sales_number DESC
|
|
</otherwise>
|
|
</choose>
|
|
</select>
|
|
|
|
<select id="selHotGroups" resultType="com.chaozhanggui.system.cashierservice.entity.vo.ShopGroupInfoVo">
|
|
SELECT
|
|
info.id AS shopId,
|
|
info.shop_name AS shopName,
|
|
info.logo AS shopImg,
|
|
info.tag AS shopTag,
|
|
info.lat AS lat,
|
|
info.lng AS lng,
|
|
info.districts as districts,
|
|
pro.id AS proId,
|
|
pro.`name` AS proName,
|
|
pro.cover_img AS proImg,
|
|
sum(`order`.number) AS number
|
|
FROM
|
|
tb_group_order_info AS `order`
|
|
LEFT JOIN tb_product AS pro ON `order`.pro_id = pro.id
|
|
LEFT JOIN tb_shop_info AS info ON info.id = `order`.shop_id
|
|
<where>
|
|
info.`status`='1'
|
|
AND pro.type = 'coupon'
|
|
AND (info.cities = #{cities} or info.districts = #{cities})
|
|
<if test="proName != null and proName != ''">
|
|
AND pro.`name` LIKE concat('%',#{proName,jdbcType=VARCHAR},'%')
|
|
</if>
|
|
<if test="type != null and type != ''">
|
|
AND pro.group_category_id LIKE concat('%',#{type,jdbcType=VARCHAR},'%')
|
|
</if>
|
|
<if test="startTime != null and startTime != ''">
|
|
AND `order`.create_time BETWEEN #{startTime} AND #{endTime}
|
|
</if>
|
|
</where>
|
|
group by `order`.pro_id
|
|
ORDER BY number desc
|
|
</select>
|
|
</mapper>
|
|
|