(SELECT IF(0 = 0, ew_start_adjust.title_zh, ew_start_adjust.title_en) FROM ecw_warehouse ew_start_adjust WHERE
ew_start_adjust.id = o.adjust_to_start_warehouse_id) AS adjust_to_start_warehouse_name,
o.adjust_to_dest_warehouse_id,
(SELECT IF(0 = 0, ew_dest_adjust.title_zh, ew_dest_adjust.title_en) FROM ecw_warehouse ew_dest_adjust WHERE
ew_dest_adjust.id = o.adjust_to_dest_warehouse_id) AS adjust_to_dest_warehouse_name,
o.dest_adjust_to_start_warehouse_id,
(SELECT IF(0 = 0, ew_start_adjust.title_zh, ew_start_adjust.title_en) FROM ecw_warehouse ew_start_adjust WHERE
ew_start_adjust.id = o.dest_adjust_to_start_warehouse_id) AS dest_adjust_to_start_warehouse_name,
o.dest_adjust_to_dest_warehouse_id,
(SELECT IF(0 = 0, ew_dest_adjust.title_zh, ew_dest_adjust.title_en) FROM ecw_warehouse ew_dest_adjust WHERE
ew_dest_adjust.id = o.dest_adjust_to_dest_warehouse_id) AS dest_adjust_to_dest_warehouse_name,
w.start_warehouse_name,
w.dst_warehouse_name,
w.start_warehouse_id,
w.dst_warehouse_id,
o.marks,
o.salesman_id,
o.status,
o.abnormal_state,
o.in_warehouse_state,
o.shipment_state,
o.pick_state,
o.audit_type,
o.audit_result,
o.guan_lian_order_status,
o.transport_id,
o.is_cargo_control,
o.cargo_control_status,
o.cost ->> '$.totalNum' as total_num,
o.pick_state,
o.sum_num,
o.sum_volume,
o.sum_weight,
o.check_num,
o.check_volume,
o.check_weight,
o.sum_weight_finished_warehouse_in,
o.sum_volume_finished_warehouse_in,
o.packing_list_url,
o.is_external_warehouse,
o.exception_reason,
o.is_exception,
o.create_time,
o.load_time,
o.unload_time,
o.customer_id,
(select su.nickname from system_user su where su.deleted = 0 and su.id = o.salesman_id) as salesman_name,
if(#{query.userType} = 1, 1, 2) as user_type,
nor.customer_id as consignor_customer_id,
if(nor.customer_id is not null and nor.customer_id > 0,
(SELECT u1.nickname FROM system_user u1 JOIN system_user u2 on u1.id = u2.customer_service_id JOIN ecw_customer u ON u.customer_service = u2.id WHERE u.id = nor.customer_id),
"") as consignor_follow_customerService,
nor.customer_number as consignor_customer_number,
nor.name as consignor_name,
nor.name_en as consignor_name_en,
nor.phone as consignor_phone,
nor.country_code as consignor_country_code,
nee.customer_id as consignee_customer_id,
if(nee.customer_id is not null and nee.customer_id > 0,
(SELECT u1.nickname FROM system_user u1 JOIN system_user u2 on u1.id = u2.customer_service_id JOIN ecw_customer u ON u.customer_service = u2.id WHERE u.id = nee.customer_id),
"") as consignee_follow_customerService,
nee.customer_number as consignee_customer_number,
nee.name as consignee_name,
nee.name_en as consignee_name_en,
nee.phone as consignee_phone,
nee.country_code as consignee_country_code,
if(#{query.lang} = 0, channel.name_zh, channel.name_en) as channel_name,
o.update_time,
c.name as customer_name,
c.customer_service,
su.nickname as customer_service_name,
oi.*,
oi.create_time as oi_create_time,
oi.update_time as oi_update_time,
(select min(wi.`in_time`) from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.order_id = oi.order_item_id ) as
first_in_time,
(select max(wi.`in_time`) from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.order_id = oi.order_item_id ) as
IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, IFNULL(oi.warehouse_in_info ->> '$.volume', oi.volume), oi.w_volume ) as we_volume,
IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, IFNULL(oi.warehouse_in_info ->> '$.weight', oi.weight), oi.v_weight ) as vo_weight,
CASE #{query.lang}
WHEN 0 THEN pd.title_zh
WHEN 1 THEN pd.title_en
WHEN 2 THEN pd.title_fr
ELSE pd.title_zh
END as brand_name ,
CASE #{query.lang}
WHEN 0 THEN pdc.title_zh
WHEN 1 THEN pdc.title_en
WHEN 2 THEN pdc.title_fr
ELSE pdc.title_zh
END as check_brand ,
#{query.lang} as lang
from ecw_order o
left join ecw_order_item oi on oi.order_id = o.order_id
left join ecw_product_brank pd on pd.id = oi.brand
left join ecw_product_brank pdc on pdc.id = oi.check_brand
left join ecw_customer c on o.customer_id = c.id
left join system_user su on su.id = c.customer_service
left join (
SELECT
ewl.id AS line_id,
ew_start.id AS start_warehouse_id,
ew_dest.id AS dst_warehouse_id,
ew_start.title_zh AS start_title_zh,
IF( #{query.lang} = 0, ew_dest.title_zh, ew_dest.title_en ) AS dst_warehouse_name,
IF( #{query.lang} = 0, ew_start.title_zh, ew_start.title_en ) AS start_warehouse_name
FROM
ecw_warehouse_line ewl
LEFT JOIN ecw_warehouse ew_start ON ewl.start_warehouse_id = ew_start.id
LEFT JOIN ecw_warehouse ew_dest ON ewl.dest_warehouse_id = ew_dest.id
) w ON w.line_id = o.line_id
left join ecw_order_departure de on de.order_id = o.order_id
left join ecw_order_objective ob on ob.order_id = o.order_id
left join ecw_order_consignor nor on nor.order_id = o.order_id and nor.deleted = 0
left join ecw_order_consignee nee on nee.order_id = o.order_id and nee.deleted = 0
left join ecw_channel channel on channel.channel_id = o.channel_id
where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10