diff --git a/webht/third_party/pay/models/Online_payment_account_model.php b/webht/third_party/pay/models/Online_payment_account_model.php index d1c33493..c2118335 100644 --- a/webht/third_party/pay/models/Online_payment_account_model.php +++ b/webht/third_party/pay/models/Online_payment_account_model.php @@ -375,55 +375,102 @@ class Online_payment_account_model extends CI_Model { public function get_refund_imported() { $ret = array(); - $paypal_sql = "SELECT 'paypal' as 'payment_type', pn_sn note_sn, pn_txn_id transaction_id, - (select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN - where OPI_SN=ISNULL(coli.COLI_OPI_ID, bcoli.COLI_OPI_ID)) as department, - (select GRI_Name from GRoupInfo where gri_sn=ISNULL(coli.COLI_GRI_SN,bcoli.COLI_GRI_SN)) as gri_name, + $send_flag = "send-to-finance"; + $paypal_sql = "SELECT 'paypal' as payment_type, + pn_sn note_sn,pn_txn_id transaction_id, + (select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN + where OPI_SN=ISNULL(table_t.COLI_OPI_ID, isnull(table_b.COLI_OPI_ID,table_app.COLI_OPI_ID)) + ) as department, + case when ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) is null + then isnull(table_app.COLI_GroupCode,table_app.COLI_ID) + else (select GRI_Name from GRoupInfo + where gri_sn=ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) + ) end as gri_name, pn.pn_payment_date payment_date, pn.pn_mc_gross amount,pn_mc_currency currency, - isnull(gai.GAI_SSJE,bgai.GAI_SSJE) amount_CNY, + isnull(table_t.GAI_SSJE,isnull(table_b.GAI_SSJE,table_app.GAI_SSJE)) amount_CNY, pn_payer payer,pn_payer_email payer_email from paypal_note pn - left join GroupAccountInfo gai on gai.GAI_AccreditNo=pn.pn_txn_id - left join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN - left join BIZ_GroupAccountInfo bgai on bgai.GAI_AccreditNo=pn.pn_txn_id - left join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN - where pn_send='send-to-finance' "; + left join ( + select gai.GAI_SSJE,gai.GAI_AccreditNo ,coli.COLI_GRI_SN,coli.COLI_OPI_ID,coli.COLI_SN + from GroupAccountInfo gai inner join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN + ) as table_t on table_t.GAI_AccreditNo=pn.pn_txn_id + left join ( + select bgai.GAI_AccreditNo,bgai.GAI_SSJE ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN + from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN + ) as table_b on table_b.GAI_AccreditNo=pn.pn_txn_id + left join ( + select bgai.GAI_AccreditNo,bgai.GAI_SSJE,bgai.GAI_SQJE,bgai.GAI_SQJECurrency ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN ,bcoli.COLI_id ,bcoli.COLI_GroupCode + from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN + ) as table_app on table_app.COLI_ID=REPLACE ( pn_invoice , '_B' , '' ) + and pn.pn_mc_gross=table_app.GAI_SQJE and pn.pn_mc_currency=table_app.GAI_SQJECurrency + where pn_send='$send_flag' + order by department "; $ret = $paypal_list = $this->HT->query($paypal_sql)->result_array(); $ipaylinks_sql = "SELECT 'ipaylinks' as 'payment_type', IPL_sn note_sn,IPL_dealId transaction_id, - (select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN - where OPI_SN=ISNULL(coli.COLI_OPI_ID, bcoli.COLI_OPI_ID)) as department, - (select GRI_Name from GRoupInfo where gri_sn=ISNULL(coli.COLI_GRI_SN,bcoli.COLI_GRI_SN)) as gri_name, + (select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN + where OPI_SN=ISNULL(table_t.COLI_OPI_ID, isnull(table_b.COLI_OPI_ID,table_app.COLI_OPI_ID)) + ) as department, + case when ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) is null + then isnull(table_app.COLI_GroupCode,table_app.COLI_ID) + else (select GRI_Name from GRoupInfo + where gri_sn=ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) + ) end as gri_name, pn.IPL_completeTime payment_date, pn.IPL_orderAmount amount, - isnull(IPL_currencyCode,isnull(gai.GAI_SQJECurrency,bgai.GAI_SQJECurrency)) currency, - isnull(gai.GAI_SSJE,bgai.GAI_SSJE) amount_CNY, - isnull(IPL_payerName,isnull(gai.GAI_CusName,bgai.GAI_CusName)) payer, - isnull(IPL_payerEmail,ISNULL(gai.gai_cusEmail,bgai.gai_cusemail)) payer_email + isnull(IPL_currencyCode,isnull(table_t.GAI_SQJECurrency,isnull(table_b.GAI_SQJECurrency,table_app.GAI_SQJECurrency))) currency, + isnull(table_t.GAI_SSJE,isnull(table_b.GAI_SSJE,table_app.GAI_SSJE)) amount_CNY, + isnull(IPL_payerName,isnull(table_t.GAI_CusName,isnull(table_b.GAI_CusName,table_app.GAI_CusName))) payer, + isnull(IPL_payerEmail,ISNULL(table_t.gai_cusEmail,isnull(table_b.gai_cusemail,table_app.gai_cusemail))) payer_email from InfoManager.dbo.IPayLinksLog pn - left join GroupAccountInfo gai on gai.GAI_AccreditNo=pn.IPL_dealId - left join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN - left join BIZ_GroupAccountInfo bgai on bgai.GAI_AccreditNo=pn.IPL_dealId - left join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN - where IPL_sent='send-to-finance' "; + left join ( + select gai.GAI_SQJECurrency,gai.GAI_CusName,gai.gai_cusEmail, gai.GAI_SSJE,gai.GAI_AccreditNo ,coli.COLI_GRI_SN,coli.COLI_OPI_ID,coli.COLI_SN + from GroupAccountInfo gai inner join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN + ) as table_t on table_t.GAI_AccreditNo=pn.IPL_dealId + left join ( + select bgai.GAI_AccreditNo,bgai.GAI_CusName,bgai.gai_cusEmail,bgai.GAI_SQJECurrency,bgai.GAI_SSJE ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN + from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN + ) as table_b on table_b.GAI_AccreditNo=pn.IPL_dealId + left join ( + select bgai.GAI_AccreditNo,bgai.GAI_CusName,bgai.gai_cusEmail,bgai.GAI_SSJE,bgai.GAI_SQJE,bgai.GAI_SQJECurrency ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN ,bcoli.COLI_id ,bcoli.COLI_GroupCode + from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN + ) as table_app on table_app.COLI_ID=REPLACE ( IPL_orderId , '_B' , '' ) + and pn.IPL_orderAmount=table_app.GAI_SQJE and pn.IPL_currencyCode=table_app.GAI_SQJECurrency + where IPL_sent='$send_flag' + order by department "; $ipaylinks_list = $this->HT->query($ipaylinks_sql)->result_array(); empty($ipaylinks_list) ? $ipaylinks_list=array() : false; $alipay_sql = "SELECT 'alipay' as 'payment_type', ALI_sn note_sn,ALI_dealId transaction_id, (select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN - where OPI_SN=ISNULL(coli.COLI_OPI_ID, bcoli.COLI_OPI_ID)) as department, - (select GRI_Name from GRoupInfo where gri_sn=ISNULL(coli.COLI_GRI_SN,bcoli.COLI_GRI_SN)) as gri_name, - pn.ALI_completeTime payment_date, - pn.ALI_orderAmount amount, - isnull(ALI_currencyCode,isnull(gai.GAI_SQJECurrency,bgai.GAI_SQJECurrency)) currency, - isnull(gai.GAI_SSJE,bgai.GAI_SSJE) amount_CNY, - isnull(ALI_payerName,isnull(gai.GAI_CusName,bgai.GAI_CusName)) payer, - isnull(ALI_payerEmail,ISNULL(gai.gai_cusEmail,bgai.gai_cusemail)) payer_email - from InfoManager.dbo.AlipayLog pn - left join GroupAccountInfo gai on gai.GAI_AccreditNo=SUBSTRING(pn.ALI_dealId,0,31) - left join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN - left join BIZ_GroupAccountInfo bgai on bgai.GAI_AccreditNo=SUBSTRING(pn.ALI_dealId,0,31) - left join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN - where ALI_sent='send-to-finance' "; + where OPI_SN=ISNULL(table_t.COLI_OPI_ID, isnull(table_b.COLI_OPI_ID,table_app.COLI_OPI_ID)) + ) as department, + case when ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) is null + then isnull(table_app.COLI_GroupCode,table_app.COLI_ID) + else (select GRI_Name from GRoupInfo + where gri_sn=ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) + ) end as gri_name, + pn.ALI_completeTime payment_date, + pn.ALI_orderAmount amount, + isnull(ALI_currencyCode,isnull(table_t.GAI_SQJECurrency,isnull(table_b.GAI_SQJECurrency,table_app.GAI_SQJECurrency))) currency, + isnull(table_t.GAI_SSJE,isnull(table_b.GAI_SSJE,table_app.GAI_SSJE)) amount_CNY, + isnull(ALI_payerName,isnull(table_t.GAI_CusName,isnull(table_b.GAI_CusName,table_app.GAI_CusName))) payer, + isnull(ALI_payerEmail,ISNULL(table_t.gai_cusEmail,isnull(table_b.gai_cusemail,table_app.gai_cusemail))) payer_email + from InfoManager.dbo.AlipayLog pn + left join ( + select gai.GAI_SQJECurrency,gai.GAI_CusName,gai.gai_cusEmail, gai.GAI_SSJE,gai.GAI_AccreditNo ,coli.COLI_GRI_SN,coli.COLI_OPI_ID,coli.COLI_SN + from GroupAccountInfo gai inner join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN + ) as table_t on table_t.GAI_AccreditNo=SUBSTRING( pn.ALI_dealId,0,31) + left join ( + select bgai.GAI_AccreditNo,bgai.GAI_CusName,bgai.gai_cusEmail,bgai.GAI_SQJECurrency,bgai.GAI_SSJE ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN + from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN + ) as table_b on table_b.GAI_AccreditNo=SUBSTRING( pn.ALI_dealId,0,31) + left join ( + select bgai.GAI_AccreditNo,bgai.GAI_CusName,bgai.gai_cusEmail,bgai.GAI_SSJE,bgai.GAI_SQJE,bgai.GAI_SQJECurrency ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN ,bcoli.COLI_id ,bcoli.COLI_GroupCode + from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN + ) as table_app on table_app.COLI_ID=REPLACE ( REPLACE ( ALI_orderId , '_A' , '' ) , '_B' , '' ) + and pn.ALI_orderAmount=table_app.GAI_SQJE --and pn.ALI_currencyCode=table_app.GAI_SQJECurrency + where ALI_sent ='$send_flag' + order by department "; $alipay_list = $this->HT->query($alipay_sql)->result_array(); empty($alipay_list) ? $alipay_list=array() : false; $ret = array_merge($paypal_list, $ipaylinks_list, $alipay_list);