统计
This commit is contained in:
@@ -3,125 +3,4 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.ShopOrderStatisticMapper">
|
||||
<select id="getTradeData" resultType="com.czg.order.entity.ShopOrderStatistic">
|
||||
select
|
||||
sum(sale_amount) as sale_amount,
|
||||
sum(sale_count) as sale_count,
|
||||
sum(discount_amount) as discount_amount,
|
||||
sum(discount_count) as discount_count,
|
||||
sum(refund_amount) as refund_amount,
|
||||
sum(refund_count) as refund_count,
|
||||
sum(wechat_pay_count) as wechat_pay_count,
|
||||
sum(wechat_pay_amount) as wechat_pay_amount,
|
||||
sum(ali_pay_count) as ali_pay_count,
|
||||
sum(ali_pay_amount) as ali_pay_amount,
|
||||
sum(credit_pay_count) as credit_pay_count,
|
||||
sum(credit_pay_amount) as credit_pay_amount,
|
||||
sum(member_pay_count) as member_pay_count,
|
||||
sum(member_pay_amount) as member_pay_amount,
|
||||
sum(scan_pay_count) as scan_pay_count,
|
||||
sum(scan_pay_amount) as scan_pay_amount,
|
||||
sum(cash_pay_count) as cash_pay_count,
|
||||
sum(cash_pay_amount) as cash_pay_amount,
|
||||
sum(recharge_amount) as recharge_amount,
|
||||
avg(customer_unit_price) as customer_unit_price,
|
||||
avg(table_turnover_rate) as table_turnover_rate,
|
||||
sum(new_member_count) as new_member_count,
|
||||
max(update_time) as update_time
|
||||
from tb_shop_order_statistic
|
||||
where shop_id = #{shopId}
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
|
||||
]]>
|
||||
</if>
|
||||
group by shop_id
|
||||
</select>
|
||||
<select id="getNewMemberCount" resultType="java.lang.Long">
|
||||
select count(1) from tb_shop_user where main_shop_id = #{mainShopId} and is_vip = 1
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and join_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and join_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
</if>
|
||||
</select>
|
||||
<select id="getPayTypeAmountCount" resultType="java.util.Map">
|
||||
SELECT
|
||||
t1.pay_type as payType,
|
||||
sum(t1.pay_amount) as amount,
|
||||
sum(t1.refund_amount) as refund,
|
||||
count(case when t1.refund_amount>0 then 1 end) as refundCount,
|
||||
sum(t1.discount_amount) as discount,
|
||||
count(case when t1.discount_amount>0 then 1 end) as discountCount,
|
||||
count(*) as count
|
||||
FROM
|
||||
tb_order_info t1
|
||||
WHERE t1.shop_id = #{shopId}
|
||||
and t1.paid_time is not null
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
</if>
|
||||
group by t1.pay_type
|
||||
</select>
|
||||
<select id="getVipRechargeAmountCount" resultType="java.util.Map">
|
||||
select
|
||||
t1.biz_code as bizCode,sum(t1.amount) as amount,count(*) as count
|
||||
from tb_shop_user_flow t1
|
||||
where t1.shop_id = #{shopId}
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
</if>
|
||||
group by t1.biz_code
|
||||
</select>
|
||||
<select id="getCustomerUnitPrice" resultType="java.math.BigDecimal">
|
||||
SELECT
|
||||
ifnull((sum(t1.pay_amount)-sum(t1.refund_amount))/count(ifnull(case t1.seat_num when 0 then 1 end,1)),0.00) as customerUnitPrice
|
||||
FROM
|
||||
tb_order_info t1
|
||||
WHERE t1.shop_id = #{shopId}
|
||||
and t1.paid_time is not null
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
</if>
|
||||
</select>
|
||||
<select id="getTableTurnoverRate" resultType="java.math.BigDecimal">
|
||||
SELECT
|
||||
ifnull((count(*)-count(DISTINCT t1.table_code))/count(DISTINCT t1.table_code)*100,0.00)
|
||||
FROM
|
||||
tb_order_info t1
|
||||
WHERE t1.shop_id = #{shopId}
|
||||
and t1.paid_time is not null
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
</if>
|
||||
</select>
|
||||
<select id="getShopIdList" resultType="java.lang.Long">
|
||||
select id from tb_shop_info order by id
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -4,164 +4,120 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.ShopProdStatisticMapper">
|
||||
|
||||
<select id="findProdRandingSummaryPage" resultType="com.czg.order.vo.DataSummaryProductSaleRankingVo">
|
||||
select
|
||||
t1.prod_id,
|
||||
t2.name as product_name,
|
||||
sum(t1.sale_count) as number,
|
||||
sum(t1.sale_amount) as amount
|
||||
from tb_shop_prod_statistic t1
|
||||
left join tb_product t2 on t1.prod_id = t2.id
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.create_day in
|
||||
<foreach item="day" collection="days" open="(" separator="," close=")">
|
||||
#{day}
|
||||
</foreach>
|
||||
group by t1.prod_id,t2.name
|
||||
order by sum(t1.sale_count) desc
|
||||
</select>
|
||||
<select id="getSaleSummaryCount" resultType="com.czg.order.vo.SaleSummaryCountVo">
|
||||
select
|
||||
sum(t1.sale_count) as sale_count,
|
||||
sum(t1.sale_amount) as total_amount,
|
||||
sum(t1.refund_count) as refund_count,
|
||||
sum(t1.refund_amount) as refund_amount
|
||||
from tb_shop_prod_statistic t1
|
||||
left join tb_product t2 on t1.prod_id = t2.id
|
||||
where t1.shop_id = #{shopId}
|
||||
<if test="productName != null and productName != ''">
|
||||
and t2.name like concat('%', #{productName}, '%')
|
||||
</if>
|
||||
<if test="prodCategoryId != null">
|
||||
and t2.category_id = #{prodCategoryId}
|
||||
</if>
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
|
||||
]]>
|
||||
</if>
|
||||
</select>
|
||||
<select id="findSaleSummaryList" resultType="com.czg.order.vo.SaleSummaryInfoVo">
|
||||
select
|
||||
t1.prod_id,
|
||||
max(t1.id) as id,
|
||||
t2.NAME AS product_name,
|
||||
t3.name as category_name,
|
||||
sum(t1.sale_count) as sale_count,
|
||||
sum(t1.sale_amount) as sale_amount,
|
||||
sum(t1.refund_count) as refund_count,
|
||||
sum(t1.refund_amount) as refund_amount
|
||||
from tb_shop_prod_statistic t1
|
||||
left join tb_product t2 on t1.prod_id = t2.id
|
||||
left join tb_shop_prod_category t3 on t2.category_id = t3.id
|
||||
where t1.shop_id = #{shopId}
|
||||
<if test="productName != null and productName != ''">
|
||||
and t2.name like concat('%', #{productName}, '%')
|
||||
</if>
|
||||
<if test="prodCategoryId != null">
|
||||
and t2.category_id = #{prodCategoryId}
|
||||
</if>
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
|
||||
]]>
|
||||
</if>
|
||||
group by t1.prod_id
|
||||
ORDER BY sum( t1.sale_count ) DESC,max(t1.id) DESC
|
||||
</select>
|
||||
<select id="getSaleSummaryCount2" resultType="com.czg.order.vo.SaleSummaryCountVo">
|
||||
<select id="selectProStatByDay" resultType="com.czg.order.entity.ShopProdStatistic">
|
||||
SELECT
|
||||
sum(t1.pay_amount) as totalAmount,
|
||||
sum(t1.refund_amount) as refundAmount,
|
||||
count(*) as saleCount,
|
||||
count(case when t1.refund_amount > 0 then 1 end) as refundCount
|
||||
CASE WHEN detail.is_temporary = 1 THEN -1 ELSE detail.product_id END AS prodId,
|
||||
CASE WHEN detail.is_temporary = 1 THEN '临时菜' ELSE prod.name END AS productName,
|
||||
sum(detail.num-detail.return_num) as saleCount,
|
||||
sum(detail.pay_amount) as saleAmount,
|
||||
sum(detail.refund_num) refundCount,
|
||||
sum(detail.return_amount) refundAmount
|
||||
FROM
|
||||
tb_order_info t1
|
||||
left join (
|
||||
SELECT
|
||||
x1.order_id,
|
||||
concat( ',', GROUP_CONCAT( x2.category_id ), ',' ) AS category_id,
|
||||
GROUP_CONCAT( x1.product_name ) AS product_name
|
||||
FROM
|
||||
tb_order_detail x1
|
||||
LEFT JOIN tb_product x2 ON x1.product_id = x2.id
|
||||
GROUP BY x1.order_id
|
||||
) t2 on t1.id = t2.order_id
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.status in ('part-refund','refund','done')
|
||||
tb_order_info `order`
|
||||
INNER JOIN tb_order_detail detail ON `order`.id = detail.order_id
|
||||
LEFT JOIN tb_product prod ON detail.product_id = prod.id
|
||||
WHERE
|
||||
`order`.shop_id = #{shopId}
|
||||
AND `order`.trade_day = #{tradeDay}
|
||||
AND `order`.paid_time IS NOT NULL
|
||||
<if test="productName != null and productName != ''">
|
||||
and t2.product_name like concat('%', #{productName}, '%')
|
||||
</if>
|
||||
<if test="prodCategoryId != null">
|
||||
and t2.category_id like concat('%,', #{prodCategoryId}, ',%')
|
||||
</if>
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
AND detail.name LIKE CONCAT('%',#{productName},'%')
|
||||
</if>
|
||||
GROUP BY prodId
|
||||
</select>
|
||||
<select id="findSaleSummaryList2" resultType="com.czg.order.vo.SaleSummaryInfoVo">
|
||||
|
||||
<select id="getProdStatSingleDate" resultType="com.czg.order.entity.ShopProdStatistic">
|
||||
SELECT
|
||||
t1.product_id,
|
||||
t1.product_name as productName,
|
||||
t3.name as category_name,
|
||||
sum( t1.num ) AS saleCount,
|
||||
sum( t1.pay_amount ) AS saleAmount,
|
||||
sum( t1.return_num ) AS refundCount,
|
||||
sum( t1.return_amount ) AS refundAmount
|
||||
tb_shop_prod_statistic.*,
|
||||
CASE WHEN tb_shop_prod_statistic.prod_id = -1 THEN '临时菜' ELSE prod.name END AS productName
|
||||
FROM
|
||||
tb_order_detail t1
|
||||
left join tb_product t2 on t1.product_id = t2.id
|
||||
left join tb_shop_prod_category t3 on t2.category_id = t3.id
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.status in ('part-refund','refund','done')
|
||||
tb_shop_prod_statistic
|
||||
LEFT JOIN tb_product prod ON tb_shop_prod_statistic.prod_id = prod.id
|
||||
WHERE
|
||||
tb_shop_prod_statistic.shop_id = #{shopId}
|
||||
AND tb_shop_prod_statistic.create_day = #{day}
|
||||
<if test="productName != null and productName != ''">
|
||||
and t1.product_name like concat('%', #{productName}, '%')
|
||||
AND prod.name LIKE CONCAT('%',#{productName},'%')
|
||||
</if>
|
||||
<if test="prodCategoryId != null">
|
||||
and t2.category_id = #{prodCategoryId}
|
||||
</if>
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
</if>
|
||||
GROUP BY t1.product_id,t1.product_name
|
||||
ORDER BY sum( t1.num ) DESC,max(t1.product_id) DESC
|
||||
ORDER BY
|
||||
tb_shop_prod_statistic.sale_count DESC, tb_shop_prod_statistic.prod_id
|
||||
</select>
|
||||
<select id="findProdRandingSummaryPage2" resultType="com.czg.order.vo.DataSummaryProductSaleRankingVo">
|
||||
select
|
||||
t1.product_id,
|
||||
t1.product_name,
|
||||
sum(t1.num) as number,
|
||||
sum(t1.pay_amount) as amount,
|
||||
sum(t1.return_num) AS refundCount,
|
||||
sum(t1.return_amount) AS refundAmount
|
||||
from tb_order_detail t1
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.status in ('part-refund','refund','done')
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
<select id="getProdStatDateRange" resultType="com.czg.order.entity.ShopProdStatistic">
|
||||
SELECT
|
||||
tb_shop_prod_statistic.prod_id as prodId,
|
||||
CASE WHEN prod_id = -1 THEN '临时菜' ELSE prod.name END AS productName,
|
||||
tb_shop_prod_statistic.shop_id as shopId,
|
||||
SUM(tb_shop_prod_statistic.sale_count) AS saleCount,
|
||||
SUM(tb_shop_prod_statistic.sale_amount) AS saleAmount,
|
||||
SUM(tb_shop_prod_statistic.refund_count) AS refundCount,
|
||||
SUM(tb_shop_prod_statistic.refund_amount) AS refundAmount
|
||||
FROM
|
||||
tb_shop_prod_statistic
|
||||
LEFT JOIN tb_product prod ON tb_shop_prod_statistic.prod_id = prod.id
|
||||
WHERE
|
||||
tb_shop_prod_statistic.shop_id = #{shopId}
|
||||
AND tb_shop_prod_statistic.create_day >= #{start}
|
||||
AND tb_shop_prod_statistic.create_day <= #{end}
|
||||
<if test="productName != null and productName != ''">
|
||||
AND prod.name LIKE CONCAT('%',#{productName},'%')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
<![CDATA[
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
]]>
|
||||
</if>
|
||||
GROUP BY t1.product_id,t1.product_name
|
||||
order by sum(t1.num) desc
|
||||
GROUP BY
|
||||
tb_shop_prod_statistic.prod_id
|
||||
ORDER BY
|
||||
tb_shop_prod_statistic.sale_count DESC, tb_shop_prod_statistic.prod_id
|
||||
</select>
|
||||
|
||||
|
||||
<select id="summaryCountByDay" resultType="com.czg.order.vo.SaleSummaryCountVo">
|
||||
SELECT
|
||||
sum(detail.num-detail.return_num) as saleCount,
|
||||
sum(detail.pay_amount) as saleAmount,
|
||||
sum(detail.refund_num) refundCount,
|
||||
sum(detail.return_amount) refundAmount
|
||||
FROM
|
||||
tb_order_info `order`
|
||||
INNER JOIN tb_order_detail detail ON `order`.id = detail.order_id
|
||||
LEFT JOIN tb_product prod ON detail.product_id = prod.id
|
||||
WHERE
|
||||
`order`.shop_id = #{shopId}
|
||||
AND `order`.trade_day = #{day}
|
||||
AND `order`.paid_time IS NOT NULL
|
||||
<if test="productName != null and productName != ''">
|
||||
AND detail.name LIKE CONCAT('%',#{productName},'%')
|
||||
</if>
|
||||
</select>
|
||||
<select id="summaryCountSingleDate" resultType="com.czg.order.vo.SaleSummaryCountVo">
|
||||
SELECT
|
||||
sum(tb_shop_prod_statistic.sale_count) AS saleCount,
|
||||
sum(tb_shop_prod_statistic.sale_amount) AS saleAmount,
|
||||
sum(tb_shop_prod_statistic.refund_count) AS refundCount,
|
||||
sum(tb_shop_prod_statistic.refund_amount) AS refundAmount
|
||||
FROM
|
||||
tb_shop_prod_statistic
|
||||
WHERE
|
||||
tb_shop_prod_statistic.shop_id = #{shopId}
|
||||
AND tb_shop_prod_statistic.create_day = #{day}
|
||||
<if test="productName != null and productName != ''">
|
||||
AND prod.name LIKE CONCAT('%',#{productName},'%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="summaryCountDateRange" resultType="com.czg.order.vo.SaleSummaryCountVo">
|
||||
SELECT
|
||||
sum(tb_shop_prod_statistic.sale_count) AS saleCount,
|
||||
sum(tb_shop_prod_statistic.sale_amount) AS saleAmount,
|
||||
sum(tb_shop_prod_statistic.refund_count) AS refundCount,
|
||||
sum(tb_shop_prod_statistic.refund_amount) AS refundAmount
|
||||
FROM
|
||||
tb_shop_prod_statistic
|
||||
WHERE
|
||||
tb_shop_prod_statistic.shop_id = #{shopId}
|
||||
AND tb_shop_prod_statistic.create_day >= #{start}
|
||||
AND tb_shop_prod_statistic.create_day <= #{end}
|
||||
<if test="productName != null and productName != ''">
|
||||
AND prod.name LIKE CONCAT('%',#{productName},'%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -3,124 +3,50 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.ShopTableOrderStatisticMapper">
|
||||
<update id="incrInfo">
|
||||
update tb_shop_table_order_statistic set order_count=order_count + #{count}, order_amount=order_amount + #{count}
|
||||
where shop_id = #{shopId} and table_id = #{tableId} and create_day=#{date}
|
||||
</update>
|
||||
|
||||
<select id="selectSummary" resultType="com.czg.order.entity.ShopTableOrderStatistic">
|
||||
<select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo">
|
||||
SELECT
|
||||
a.table_id as tableId, b.name as name, sum(a.order_count) as orderCount, sum(a.order_amount) as orderAmount
|
||||
t.product_name,
|
||||
date_format(t.create_time, '%Y-%m-%d') as create_date,
|
||||
if(t.table_name = 'NONE','银收客',t.table_name) as table_name,
|
||||
concat(if(t.table_name = 'NONE','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate,
|
||||
t.category_name,
|
||||
t.unit_name,
|
||||
group_concat(distinct t.sku_name SEPARATOR ';') as sku_name,
|
||||
sum(t.num) as num,
|
||||
avg(t.unit_price) as unit_price,
|
||||
sum(t.num*t.unit_price) as amount,
|
||||
sum(-t.refund_num) as refund_num,
|
||||
sum(-t.refund_num*t.unit_price) as refund_amount
|
||||
FROM
|
||||
tb_shop_table_order_statistic as a
|
||||
left join tb_shop_table as b on a.table_id = b.id
|
||||
WHERE
|
||||
a.shop_id = #{shopId}
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND a.create_day >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
and a.create_day <= #{endTime}
|
||||
</if>
|
||||
GROUP BY
|
||||
a.table_id
|
||||
order by a.id desc
|
||||
</select>
|
||||
<select id="findSummaryList" resultType="com.czg.order.vo.TableSummaryInfoVo">
|
||||
select
|
||||
t1.table_code,
|
||||
t1.table_id,
|
||||
t1.table_name as table_name,
|
||||
t1.area_name as area_name,
|
||||
sum(t1.order_count) as order_count,
|
||||
sum(t1.order_amount) as order_amount,
|
||||
ifnull(sum(t1.refund_count),0) as refund_count,
|
||||
ifnull(sum(t1.refund_amount),0) as refund_amount
|
||||
from tb_shop_table_order_statistic t1
|
||||
left join tb_shop_table t2 on t1.table_id = t2.id
|
||||
left join tb_shop_table_area t3 on t2.area_id = t3.id
|
||||
where t1.shop_id = #{shopId}
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
AND t1.create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
and t1.create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
|
||||
</if>
|
||||
group by t1.table_code
|
||||
order by sum(t1.order_count) desc,sum(t1.order_amount) desc
|
||||
</select>
|
||||
<select id="findSummaryList2" resultType="com.czg.order.vo.TableSummaryInfoVo">
|
||||
(
|
||||
SELECT
|
||||
t1.table_code,
|
||||
t2.id as table_id,
|
||||
ifnull(t2.NAME,t1.table_code) AS table_name,
|
||||
ifnull(t3.NAME,'未知') AS area_name,
|
||||
count( t1.id ) AS order_count,
|
||||
sum( t1.pay_amount ) as order_amount,
|
||||
ifnull(count( case when t1.refund_amount > 0 then 1 end),0) AS refund_count,
|
||||
ifnull( sum( t1.refund_amount ), 0 ) AS refund_amount
|
||||
t1.product_id,
|
||||
t2.table_code,
|
||||
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, 'NONE', t6.NAME) AS table_name,
|
||||
t1.create_time,
|
||||
t4.NAME AS category_name,
|
||||
t3.name as product_name,
|
||||
t5.NAME AS unit_name,
|
||||
t1.sku_name,
|
||||
t1.num,
|
||||
t1.unit_price,
|
||||
t1.refund_num as refund_num
|
||||
FROM
|
||||
tb_order_info t1
|
||||
LEFT JOIN tb_shop_table t2 ON t1.table_code = t2.table_code and t1.shop_id = t2.shop_id
|
||||
LEFT JOIN tb_shop_table_area t3 ON t2.area_id = t3.id
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.table_code is not null
|
||||
and t2.table_code is not null
|
||||
and t2.table_code != ''
|
||||
and t2.name is not null
|
||||
and t1.paid_time is not null
|
||||
tb_order_detail t1
|
||||
LEFT JOIN tb_order_info t2 ON t1.order_id = t2.id
|
||||
LEFT JOIN tb_product t3 ON t1.product_id = t3.id
|
||||
LEFT JOIN tb_shop_prod_category t4 ON t3.category_id = t4.id
|
||||
LEFT JOIN tb_shop_prod_unit t5 ON t3.unit_id = t5.id
|
||||
LEFT JOIN tb_shop_table t6 ON t2.table_code = t6.table_code AND t1.shop_id = t6.shop_id and t6.table_code != '' and t6.table_code is not null
|
||||
WHERE t1.shop_id = #{shopId}
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
AND t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
GROUP BY t1.table_code
|
||||
order by count( t1.id ) desc,sum( t1.pay_amount ) desc
|
||||
</select>
|
||||
<select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo">
|
||||
SELECT
|
||||
t.product_name,
|
||||
date_format(t.create_time, '%Y-%m-%d') as create_date,
|
||||
if(t.table_name = 'NONE','银收客',t.table_name) as table_name,
|
||||
concat(if(t.table_name = 'NONE','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate,
|
||||
t.category_name,
|
||||
t.unit_name,
|
||||
group_concat(distinct t.sku_name SEPARATOR ';') as sku_name,
|
||||
sum(t.num) as num,
|
||||
avg(t.unit_price) as unit_price,
|
||||
sum(t.num*t.unit_price) as amount,
|
||||
sum(-t.refund_num) as refund_num,
|
||||
sum(-t.refund_num*t.unit_price) as refund_amount
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
t1.product_id,
|
||||
t2.table_code,
|
||||
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, 'NONE', t6.NAME) AS table_name,
|
||||
t1.create_time,
|
||||
t4.NAME AS category_name,
|
||||
t3.name as product_name,
|
||||
t5.NAME AS unit_name,
|
||||
t1.sku_name,
|
||||
t1.num,
|
||||
t1.unit_price,
|
||||
t1.refund_num as refund_num
|
||||
FROM
|
||||
tb_order_detail t1
|
||||
LEFT JOIN tb_order_info t2 ON t1.order_id = t2.id
|
||||
LEFT JOIN tb_product t3 ON t1.product_id = t3.id
|
||||
LEFT JOIN tb_shop_prod_category t4 ON t3.category_id = t4.id
|
||||
LEFT JOIN tb_shop_prod_unit t5 ON t3.unit_id = t5.id
|
||||
LEFT JOIN tb_shop_table t6 ON t2.table_code = t6.table_code AND t1.shop_id = t6.shop_id and t6.table_code != '' and t6.table_code is not null
|
||||
WHERE t1.shop_id = #{shopId}
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
AND t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
<if test="endDate != null and endDate != ''">
|
||||
and t1.create_time <= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
) t
|
||||
) t
|
||||
group by t.product_id,date_format(t.create_time, '%Y-%m-%d'),t.table_name
|
||||
order by t.table_name,t.table_code,date_format(t.create_time, '%Y-%m-%d'),t.category_name,t.product_id
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user