select
t3.payment_date as orderDate ,t3.partner_id,t3.partner_name,
IFNULL(sum(order_total),0) as order_total,
IFNULL(sum(order_supplier_price_amount)+sum(order_markup_one_amount)+sum(order_markup_two_amount),0) as order_partner_price_amount,
IFNULL(sum(order_supplier_price_amount),0) as order_supplier_price_amount,
IFNULL(sum(order_markup_one_amount),0) as order_markup_one_amount,
IFNULL(sum(order_markup_two_amount),0) as order_markup_two_amount,
IFNULL(sum(order_markup_partner_amount),0) as order_markup_partner_amount,
IFNULL(sum(order_price_discount_amount),0) as order_price_discount_amount,
IFNULL(sum(order_coupon_amount_total),0) as order_coupon_amount_total,
IFNULL(sum(order_check_fee),0) as order_check_fee,
IFNULL(sum(order_lack_fee_supplier),0) as order_lack_fee_supplier,
IFNULL(sum(order_replace_fee),0) as order_replace_fee,
IFNULL(sum(order_fee_supplier),0) as order_fee_supplier,
IFNULL(sum(order_fee_partner),0) as order_fee_partner,
IFNULL(sum(order_fee_platform),0) as order_fee_platform,
IFNULL(sum(order_fee_platform_pack),0) as order_fee_platform_pack,
IFNULL(sum(order_fee_platform_check),0) as order_fee_platform_check,
IFNULL(sum(order_fee_platform_transport),0) as order_fee_platform_transport,
IFNULL(sum(order_total_fee),0) as order_total_fee,
IFNULL(sum(order_fee_packing_transport),0) as order_fee_packing_transport,
IFNULL(sum(order_num),0) as order_num,
IFNULL(sum(order_replace_num),0) as order_replace_num,
IFNULL(sum(order_reduce_num),0) as order_reduce_num,
IFNULL(sum(order_lack_num),0) as order_lack_num,
IFNULL(sum(order_num)-sum(order_lack_num),0) as real_sale_num
from (
select t2.payment_date,t2.id,t2.order_no,t2.create_by,t2.partner_id,p.name as partner_name,r2.* from (
SELECT t.*,
CASE
WHEN t.payment_time > DATE(t.payment_time) + INTERVAL 17 HOUR THEN DATE(t.payment_time) + INTERVAL 1 DAY
ELSE DATE(t.payment_time)
END AS payment_date,
t.payment_time as payment_time2
FROM t_order t
WHERE t.deleted = 0
and t.status_backend not in ('PENDING','CANCEL','REFUND')
)t2
left join ( ) r2
on t2.id = r2.order_id
left join t_partner_info p
on t2.partner_id=p.id
)t3
where t3.partner_id is not null
and t3.payment_date >= #{dto.paymentDateStart}
and t3.payment_date <= #{dto.paymentDateEnd}
and t3.partner_id = #{dto.partnerId}
group by t3.payment_date,t3.partner_id,t3.partner_name
order by t3.payment_date desc,t3.partner_id
select t2.*,
IFNULL(t3.fee_supplier,0) as order_fee_supplier,
IFNULL(t3.fee_partner,0) as order_fee_partner,
IFNULL(t3.fee_platform,0) + IFNULL(t3.fee_packing_transport,0) as order_fee_platform,
IFNULL(t3.fee_platform_pack,0) as order_fee_platform_pack,
IFNULL(t3.fee_platform_check,0) as order_fee_platform_check,
IFNULL(t3.fee_platform_transport,0) as order_fee_platform_transport,
IFNULL(t3.total_fee,0) as order_total_fee,
IFNULL(t3.fee_packing_transport,0) as order_fee_packing_transport
from (
select
t1.order_id, t1.total_amount ,sum(t1.num) as order_num ,
( sum( t1.supplier_price_amount )+sum( t1.markup_one_amount )+sum( t1.markup_two_amount )+sum( t1.markup_partner_amount ) + t1.packing_fee + t1.transport_fee ) AS order_total,
sum(t1.supplier_price_amount) as order_supplier_price_amount, sum(t1.markup_one_amount) as order_markup_one_amount,sum(t1.markup_two_amount) as order_markup_two_amount, sum(t1.markup_partner_amount) as order_markup_partner_amount,sum(t1.price_amount) as order_price_amount,sum(t1.original_price_amount) as order_original_price_amount,sum(t1.price_discount_amount) as order_price_discount_amount,sum(t1.coupon_amount_total) as order_coupon_amount_total,sum(t1.check_fee) as order_check_fee,sum(t1.lack_fee_supplier) as order_lack_fee_supplier,sum(t1.replace_fee) as order_replace_fee,
sum(replace_num) as order_replace_num,sum(reduce_num) as order_reduce_num,sum(lack_num) as order_lack_num
from (
SELECT
o.total_amount, o.flower_amount, o.packing_fee, o.transport_fee,
oi.order_id,
oi.id,
IFNULL(oi.num,0) as num,
IFNULL(oi.total,0) as total,
IFNULL(oi.supplier_price,0) as supplier_price,
IFNULL(oi.supplier_price,0) * IFNULL(oi.num,0) as supplier_price_amount,
IFNULL(oi.markup_one,0) as markup_one,
IFNULL(oi.markup_one,0)* IFNULL(oi.num,0) as markup_one_amount,
IFNULL(oi.markup_two,0) as markup_two,
IFNULL(oi.markup_two,0)* IFNULL(oi.num,0) as markup_two_amount,
IFNULL(oi.markup_partner,0) as markup_partner,
IFNULL(oi.markup_partner,0)* IFNULL(oi.num,0) as markup_partner_amount,
IFNULL(oi.price,0) as price,
IFNULL(oi.price,0)* IFNULL(oi.num,0) as price_amount,
IFNULL(oi.original_price,0) as original_price,
IFNULL(oi.original_price,0)*IFNULL(oi.num,0) as original_price_amount,
IFNULL(oi.original_price,0)*IFNULL(oi.num,0) - IFNULL(oi.price,0)* IFNULL(oi.num,0) as price_discount_amount,
IFNULL(oi.real_price,0) as real_price,
IFNULL(oi.real_total,0) as real_total,
IFNULL(oi.coupon_amount_total,0) as coupon_amount_total,
IFNULL(ois.check_fee,0) as check_fee,
IFNULL(ois.lack_fee_supplier,0) as lack_fee_supplier,
IFNULL(ois.replace_fee,0) as replace_fee
,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'replace' and oic.audit_status='AGREED'),0) as replace_num
,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'reduce' and oic.audit_status='AGREED'),0) as reduce_num
,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num
FROM t_order o
left join t_order_item oi
on oi.order_id=o.id
left join t_station s on s.id = oi.station_id
left join t_supplier_info si on si.id = oi.supplier_id
left join t_order_item_settlement ois on ois.order_item_id = oi.id
WHERE oi.deleted = 0
and o.payment_time > #{dto.startDate}
and o.payment_time <= #{dto.endDate}
)t1
group by order_id
) t2
left join (
select
ois.order_id,
IFNULL(sum(ois.fee_supplier),0) as fee_supplier,
IFNULL(sum(ois.fee_partner),0) as fee_partner,
IFNULL(sum(ois.fee_platform),0) as fee_platform,
IFNULL(sum(ois.fee_platform_pack),0) as fee_platform_pack,
IFNULL(sum(ois.fee_platform_check),0) as fee_platform_check,
IFNULL(sum(ois.fee_platform_transport),0) as fee_platform_transport,
IFNULL(sum(ois.total_fee),0) as total_fee,
IFNULL(sum(ois.fee_packing_transport),0) as fee_packing_transport
from t_order_item_sales ois
group by order_id
)t3
on t2.order_id =t3.order_id
select t2.*,
IFNULL(t3.fee_supplier,0) as order_fee_supplier,
IFNULL(t3.fee_partner,0) as order_fee_partner,
IFNULL(t3.fee_platform,0) as order_fee_platform,
IFNULL(t3.fee_platform_pack,0) as order_fee_platform_pack,
IFNULL(t3.fee_platform_check,0) as order_fee_platform_check,
IFNULL(t3.fee_platform_transport,0) as order_fee_platform_transport,
IFNULL(t3.total_fee,0) as order_total_fee,
IFNULL(t3.fee_packing_transport,0) as order_fee_packing_transport
from (
select
t1.order_id,sum(t1.num) as order_num , sum(t1.total) as order_total, sum(t1.supplier_price_amount) as order_supplier_price_amount, sum(t1.markup_one_amount) as order_markup_one_amount,sum(t1.markup_two_amount) as order_markup_two_amount, sum(t1.markup_partner_amount) as order_markup_partner_amount,sum(t1.price_amount) as order_price_amount,sum(t1.original_price_amount) as order_original_price_amount,sum(t1.price_discount_amount) as order_price_discount_amount,sum(t1.coupon_amount_total) as order_coupon_amount_total,sum(t1.check_fee) as order_check_fee,sum(t1.lack_fee_supplier) as order_lack_fee_supplier,sum(t1.replace_fee) as order_replace_fee,
sum(replace_num) as order_replace_num,sum(reduce_num) as order_reduce_num,sum(lack_num) as order_lack_num
from (
SELECT
CASE
WHEN o.payment_time > DATE(o.payment_time) + INTERVAL 17 HOUR THEN DATE(o.payment_time) + INTERVAL 1 DAY
ELSE DATE(o.payment_time)
END AS payment_date,
oi.order_id,
oi.id,
IFNULL(oi.num,0) as num,
IFNULL(oi.total,0) as total,
IFNULL(oi.supplier_price,0) as supplier_price,
IFNULL(oi.supplier_price,0) * IFNULL(oi.num,0) as supplier_price_amount,
IFNULL(oi.markup_one,0) as markup_one,
IFNULL(oi.markup_one,0)* IFNULL(oi.num,0) as markup_one_amount,
IFNULL(oi.markup_two,0) as markup_two,
IFNULL(oi.markup_two,0)* IFNULL(oi.num,0) as markup_two_amount,
IFNULL(oi.markup_partner,0) as markup_partner,
IFNULL(oi.markup_partner,0)* IFNULL(oi.num,0) as markup_partner_amount,
IFNULL(oi.price,0) as price,
IFNULL(oi.price,0)* IFNULL(oi.num,0) as price_amount,
IFNULL(oi.original_price,0) as original_price,
IFNULL(oi.original_price,0)*IFNULL(oi.num,0) as original_price_amount,
IFNULL(oi.original_price,0)*IFNULL(oi.num,0) - IFNULL(oi.price,0)* IFNULL(oi.num,0) as price_discount_amount,
IFNULL(oi.real_price,0) as real_price,
IFNULL(oi.real_total,0) as real_total,
IFNULL(oi.coupon_amount_total,0) as coupon_amount_total,
IFNULL(ois.check_fee,0) as check_fee,
IFNULL(ois.lack_fee_supplier,0) as lack_fee_supplier,
IFNULL(ois.replace_fee,0) as replace_fee
,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'replace' and oic.audit_status='AGREED'),0) as replace_num
,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'reduce' and oic.audit_status='AGREED'),0) as reduce_num
,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num
FROM t_order o
left join t_order_item oi
on oi.order_id=o.id
left join t_station s on s.id = oi.station_id
left join t_supplier_info si on si.id = oi.supplier_id
left join t_order_item_settlement ois on ois.order_item_id = oi.id
WHERE oi.deleted = 0
and o.payment_time > #{dto.startDate}
and o.payment_time <= #{dto.endDate}
)t1
where 1=1
and t1.payment_date >= #{dto.paymentDateStart}
and t1.payment_date <= #{dto.paymentDateEnd}
group by order_id
) t2
left join (
select
ois.order_id,
IFNULL(sum(ois.fee_supplier),0) as fee_supplier,
IFNULL(sum(ois.fee_partner),0) as fee_partner,
IFNULL(sum(ois.fee_platform),0) as fee_platform,
IFNULL(sum(ois.fee_platform_pack),0) as fee_platform_pack,
IFNULL(sum(ois.fee_platform_check),0) as fee_platform_check,
IFNULL(sum(ois.fee_platform_transport),0) as fee_platform_transport,
IFNULL(sum(ois.total_fee),0) as total_fee,
IFNULL(sum(ois.fee_packing_transport),0) as fee_packing_transport
from t_order_item_sales ois
group by order_id
)t3
on t2.order_id =t3.order_id
SELECT
t2.*,
IFNULL( t3.sales_fee_supplier, 0 ) AS sales_fee_supplier
FROM
(
SELECT
t1.order_item_id,
t1.supplier_id,
t1.dateinfo,
t1.order_id,
sum( t1.supplier_price_amount ) AS order_supplier_price_amount,
sum( t1.check_fee ) AS order_check_fee,
sum( t1.replace_fee ) AS order_replace_fee,
sum( t1.lack_fee_supplier ) AS order_lack_fee_supplier,
sum( t1.num ) AS order_num,
sum( t1.lack_num ) AS order_lack_num
FROM
(
SELECT
oi.id AS order_item_id,
o.id order_id,
oi.supplier_id supplier_id,
CASE
WHEN HOUR ( o.payment_time ) >= 17 THEN
DATE_FORMAT( DATE_ADD( o.payment_time, INTERVAL 1 DAY ), '%Y-%m-%d' ) ELSE DATE_FORMAT( o.payment_time, '%Y-%m-%d' )
END AS dateinfo,
IFNULL( oi.num, 0 ) AS num,
IFNULL( oi.total, 0 ) AS total,
IFNULL( oi.supplier_price, 0 ) * IFNULL( oi.num, 0 ) AS supplier_price_amount,
IFNULL( ois.check_fee, 0 ) AS check_fee,
IFNULL( ois.replace_fee, 0 ) AS replace_fee,
IFNULL( ois.lack_fee_supplier, 0 ) AS lack_fee_supplier,
IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num
FROM
t_order o
LEFT JOIN t_order_item oi ON oi.order_id = o.id
LEFT JOIN t_station s ON s.id = oi.station_id
LEFT JOIN t_supplier_info si ON si.id = oi.supplier_id
LEFT JOIN t_order_item_settlement ois ON ois.order_item_id = oi.id
WHERE
oi.deleted = 0
and o.payment_time is not null
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and o.payment_time >= #{dto.startDate}
and o.payment_time <= #{dto.endDate}
and oi.supplier_id = #{dto.supplierId}
) t1
GROUP BY
t1.order_item_id
) t2
LEFT JOIN ( SELECT ois.order_item_id, IFNULL( sum( ois.sales_fee_supplier ), 0 ) AS sales_fee_supplier FROM t_order_item_settlement ois GROUP BY order_item_id ) t3 ON t2.order_item_id = t3.order_item_id
select IFNULL(sum(oi.supplier_price*oi.num),0) as supplier_amount
from t_order_item oi
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
select IFNULL(sum(oi.supplier_price*oi.num),0) as cur_mon_supplier_amount
from t_order_item oi
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
select IFNULL(sum(oi.supplier_price*oi.num),0) as last_mon_supplier_amount
from t_order_item oi
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')
select IFNULL(sum(oi.supplier_price*oi.num),0) as today_supplier_amount
from t_order_item oi
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and o.payment_time > #{dto.startDateTime}
and o.payment_time <= #{dto.endDateTime}
select IFNULL(sum(oic.num),0) as cur_mon_lack_num
from t_order_item_check oic
left join t_order_item oi
on oic.order_item_id=oi.ID
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and oic.type = 'lack' and oic.audit_status='AGREED'
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
select IFNULL(sum(oic.num),0) as last_mon_lack_num
from t_order_item_check oic
left join t_order_item oi
on oic.order_item_id=oi.ID
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and oic.type = 'lack' and oic.audit_status='AGREED'
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')
select IFNULL(sum(oic.num),0) as cur_mon_reduce_num
from t_order_item_check oic
left join t_order_item oi
on oic.order_item_id=oi.ID
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and oic.type = 'reduce' and oic.audit_status='AGREED'
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
select IFNULL(sum(oic.num),0) as last_mon_reduce_num
from t_order_item_check oic
left join t_order_item oi
on oic.order_item_id=oi.ID
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and oic.type = 'reduce' and oic.audit_status='AGREED'
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')
select IFNULL(sum(oic.num),0) as cur_mon_replace_num
from t_order_item_check oic
left join t_order_item oi
on oic.order_item_id=oi.ID
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and oic.type = 'replace' and oic.audit_status='AGREED'
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
select IFNULL(sum(oic.num),0) as last_mon_replace_num
from t_order_item_check oic
left join t_order_item oi
on oic.order_item_id=oi.ID
left join t_order o
on oi.order_id = o.id
where o.deleted=0
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and oi.supplier_id = #{dto.supplierId}
and oic.type = 'replace' and oic.audit_status='AGREED'
and o.payment_time > DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
and o.payment_time <= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')