select info.*,
(select apply_date from ps_contract_info pci where pci.custom_id = info.custom_id and pci.is_cancel != '03' and pci.contract_status != '10' order by pci.apply_date limit 0,1)
as first_apply_date,
com.id com_id,
com.company_name com_company_name,
com.company_adress com_company_adress,
com.company_account_bank com_company_account_bank,
com.legal_person_name com_legal_person_name,
com.legal_person_idcard com_legal_person_idcard,
com.legal_person_phone com_legal_person_phone,
cus.id cus_id,
cus.custom_name cus_custom_name ,
cus.custom_mobile cus_custom_mobile,
cus.custom_status cus_custom_status,
us.nick_name custom_manager_name,
(select ptm.invoice from ps_task_main ptm where ptm.task_type = '3' and ptm.contract_code = info.contract_code and ptm.task_status = 30 limit 0,1)
as invoice_ossid
from ps_contract_info info
left join ps_company_info com on info.company_id = com.id
left join ps_custom_info cus on info.custom_id = cus.id
left join sys_user us on info.custom_manager = us.user_id
select
cus.custom_source channel,
info.contract_code,
info.contract_amount,
pay.business_type,
pay.money
from ps_contract_info info
left join ps_custom_info cus on info.custom_id = cus.id
left join ps_contract_pay pay on info.contract_code = pay.contract_code