SELECT
oi.*,
s.NAME stationName,
si.contact_tel registerTel,
si.contact_tel customerTel,
si.id supplierId,
si.name supplierName,
o.id orderId,
o.order_no,
o.payment_time,
c.parent_name flowerCategoryName,
CONCAT(o.customer_province, ' ', o.customer_city, ' ', o.customer_region, ' ', o.customer_address) AS address,
COALESCE((SELECT oic.num FROM t_order_item_check oic WHERE oic.order_item_id = oi.id AND oic.type = 'replace'),
0) replaceNum,
COALESCE((SELECT oic.num FROM t_order_item_check oic WHERE oic.order_item_id = oi.id AND oic.type = 'reduce'),
0) reduceNum,
COALESCE((SELECT oic.num FROM t_order_item_check oic WHERE oic.order_item_id = oi.id AND oic.type = 'lack'), 0)
lackNum
FROM
t_order_item oi
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 o ON oi.order_id = o.id
LEFT JOIN t_flower f on oi.flower_id = f.id
LEFT JOIN t_flower_category c on c.id = f.category
WHERE oi.deleted = 0
and o.payment_time is not null
and o.status_backend not in ('PENDING','CANCEL','REFUND')
and si.id = #{dto.supplierId}
AND si.name LIKE concat('%', #{dto.supplierName},'%')
AND si.contact_tel LIKE CONCAT('%',#{dto.registerTel}, '%')
AND si.contact_tel LIKE CONCAT('%',#{dto.contactTel}, '%')
AND oi.station_id = #{dto.stationId}
AND ( f.category = #{dto.flowerCategory} or f.category in (
select id from t_flower_category where parent_id = #{dto.flowerCategory}
))
AND oi.flower_level = #{dto.flowerLevel}
AND o.customer_province like CONCAT('%',#{dto.customerProvince}, '%')
AND o.customer_city like CONCAT('%',#{dto.customerCity}, '%')
AND o.customer_region like CONCAT('%',#{dto.customerRegion}, '%')
AND o.order_no LIKE concat('%', #{dto.orderNo},'%')
AND o.payment_time >= #{dto.createStartDate}
AND o.payment_time < #{dto.createEndDate}
order by ${dto.orderField} ${dto.orderType}