perf: 每月20号, 发送退款调账记录给财务; 修复PayPal重复

webht/payment
Lei OT 9 months ago
parent f226619289
commit 991d8d2e96

@ -429,36 +429,67 @@ class Online_payment_account_model extends CI_Model {
{ {
$ret = array(); $ret = array();
$send_flag = "send-to-finance"; $send_flag = "send-to-finance";
$paypal_sql = "SELECT 'paypal' as payment_type, $paypal_sql = "WITH pn
pn_sn note_sn,pn_txn_id transaction_id, AS (
(select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN SELECT pn_txn_id,pn_invoice,pn_mc_gross,pn_mc_currency,pn_payer_email,pn_payer,pn_payment_date,pn_datetime,pn_sn
where OPI_SN=ISNULL(table_t.COLI_OPI_ID, isnull(table_b.COLI_OPI_ID,table_app.COLI_OPI_ID)) ,ROW_NUMBER() OVER (
) as department, PARTITION BY pn_txn_id ORDER BY pn_payer_email DESC
case when ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) is null ) AS rn
then isnull(table_app.COLI_GroupCode,table_app.COLI_ID) FROM paypal_note p1
else (select GRI_Name from GRoupInfo WHERE p1.pn_send = '$send_flag'
where gri_sn=ISNULL(table_t.COLI_GRI_SN,table_b.COLI_GRI_SN) )
) end as gri_name, SELECT 'paypal' AS payment_type,pn_sn note_sn,pn_txn_id transaction_id
pn.pn_payment_date payment_date, ,(
pn.pn_mc_gross amount,pn_mc_currency currency, SELECT DEI_DepartmentName
isnull(table_t.GAI_SSJE,isnull(table_b.GAI_SSJE,table_app.GAI_SSJE)) amount_CNY, FROM OperatorInfo
pn_payer payer,pn_payer_email payer_email INNER JOIN DepartmentInfo ON OPI_DEI_SN = DEI_SN
from paypal_note pn WHERE OPI_SN = ISNULL(table_t.COLI_OPI_ID, table_b.COLI_OPI_ID)
left join ( ) AS department
select gai.GAI_SSJE,gai.GAI_AccreditNo ,coli.COLI_GRI_SN,coli.COLI_OPI_ID,coli.COLI_SN ,CASE
from GroupAccountInfo gai inner join ConfirmLineInfo coli on coli.COLI_SN=gai.GAI_COLI_SN WHEN ISNULL(table_t.COLI_GRI_SN, table_b.COLI_GRI_SN) IS NULL
) as table_t on table_t.GAI_AccreditNo=pn.pn_txn_id THEN ''
left join ( ELSE (
select bgai.GAI_AccreditNo,bgai.GAI_SSJE ,bcoli.COLI_GRI_SN,bcoli.COLI_OPI_ID,bcoli.COLI_SN SELECT GRI_Name
from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN FROM GRoupInfo
) as table_b on table_b.GAI_AccreditNo=pn.pn_txn_id WHERE gri_sn = ISNULL(table_t.COLI_GRI_SN, table_b.COLI_GRI_SN)
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 END AS gri_name
from BIZ_GroupAccountInfo bgai inner join BIZ_ConfirmLineInfo bcoli on bcoli.COLI_SN=bgai.GAI_COLI_SN ,pn.pn_payment_date payment_date
) as table_app on table_app.COLI_ID=REPLACE ( pn_invoice , '_B' , '' ) ,pn.pn_mc_gross amount
and pn.pn_mc_gross=table_app.GAI_SQJE and pn.pn_mc_currency=table_app.GAI_SQJECurrency ,pn_mc_currency currency
where pn_send='$send_flag' ,isnull(table_t.GAI_SSJE, table_b.GAI_SSJE) amount_CNY
order by department "; ,pn_payer payer
,pn_payer_email payer_email
FROM pn
LEFT JOIN (
SELECT SUM( gai.GAI_SSJE) 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
GROUP BY gai.GAI_AccreditNo
,coli.COLI_GRI_SN
,coli.COLI_OPI_ID
,coli.COLI_SN
) AS table_t ON table_t.GAI_AccreditNo = pn.pn_txn_id
LEFT JOIN (
SELECT bgai.GAI_AccreditNo
,sum(bgai.GAI_SSJE) 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
GROUP BY bgai.GAI_AccreditNo
,bcoli.COLI_GRI_SN
,bcoli.COLI_OPI_ID
,bcoli.COLI_SN
) AS table_b ON table_b.GAI_AccreditNo = pn.pn_txn_id
WHERE pn.rn = 1
ORDER BY department ASC
,pn.payment_date DESC";
$ret = $paypal_list = $this->HT->query($paypal_sql)->result_array(); $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, $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 (select DEI_DepartmentName from OperatorInfo inner join DepartmentInfo on OPI_DEI_SN=DEI_SN

Loading…
Cancel
Save