📄 settle.ec.0704
字号:
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 将当前交易流水已清算的记录转入历史交易流水表中 */
$insert into his_tran_ls
select * from cur_tran_ls
where acq_bank_id = $sys.bank_id
and snd_settle_flag = 'Y'
and snd_settle_date <= $l_date
and saf_flag in ('0') /* 冲正标志:正常 */
and edc_err_flag in ('0') /* 正常 */
and tran_flag in ('0','4') /* 交易标志:正常,已退货 */
and resp_code = '00'
and tran_type <> 4 /* 预授权 */
and terminal_id not like 'TRM%'
and merchant_id = $tmp_merch;
/*
where snd_settle_flag = 'Y'
and snd_settle_date <= $l_date
and tran_type <> 4
and merchant_id = $tmp_merch;
*/
if (SQLCODE) {
daylog(ERROR, "Unable insert from cur_tran_ls into his_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 删除当前交易流水已清算的记录 */
$delete from cur_tran_ls
where acq_bank_id = $sys.bank_id
and snd_settle_flag = 'Y'
and snd_settle_date <= $l_date
and saf_flag in ('0') /* 冲正标志:正常 */
and edc_err_flag in ('0') /* 正常 */
and tran_flag in ('0','4') /* 交易标志:正常,已退货 */
and resp_code = '00'
and tran_type <> 4 /* 预授权 */
and terminal_id not like 'TRM%'
and merchant_id = $tmp_merch;
/*
where snd_settle_flag = 'Y'
and snd_settle_date <= $l_date
and tran_type <> 4
and merchant_id = $tmp_merch;
*/
if (SQLCODE) {
daylog(ERROR, "Unable delete from cur_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
}/*END*/
else {/*按交易时系统的逻辑日进清算*/
if (G_settle_level == 0) { /*只有借记卡使用*/
$insert into cur_settle_ls
select * from cur_tran_ls
where acq_bank_id = $sys.bank_id
and ((snd_settle_flag = 'Y'
and snd_settle_date <= $l_date)
or (card_type = '02'
and local_logic_date <= $l_date))
and saf_flag in ('0') /* 冲正标志:正常 */
and edc_err_flag in ('0') /* 正常 */
and tran_flag in ('0','4') /* 交易标志:正常,已退货 */
and resp_code = '00'
and tran_type not in (4,12) /* 预授权,撤消 */
and tran_amt >= 0.01 /* 交易金额为0*/
and terminal_id not like 'TRM%'
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable insert cur_tran_ls to cur_settle_ls![%ld]", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 将当前交易流水已清算的记录转入历史交易流水表中 */
$insert into his_tran_ls
select * from cur_tran_ls
where ((snd_settle_flag = 'Y'
and snd_settle_date <= $l_date)
or (card_type = '02'
and local_logic_date <= $l_date))
and tran_type <> 4
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable insert from cur_tran_ls into his_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 删除当前交易流水已清算的记录 */
$delete from cur_tran_ls
where ((snd_settle_flag = 'Y'
and snd_settle_date <= $l_date)
or (card_type = '02'
and local_logic_date <= $l_date))
and tran_type <> 4
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable delete from cur_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
}
else if (G_settle_level == 1) { /*人民币卡使用*/
$insert into cur_settle_ls
select * from cur_tran_ls
where acq_bank_id = $sys.bank_id
and ((snd_settle_flag = 'Y'
and snd_settle_date <= $l_date)
or (card_type < '50'
and local_logic_date <= $l_date))
and saf_flag in ('0') /* 冲正标志:正常 */
and edc_err_flag in ('0') /* 正常 */
and tran_flag in ('0','4') /* 交易标志:正常,已退货 */
and resp_code = '00'
and tran_type not in (4,12) /* 预授权,撤消 */
and tran_amt >= 0.01 /* 交易金额为0*/
and terminal_id not like 'TRM%'
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable insert cur_tran_ls to cur_settle_ls![%ld]", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 将当前交易流水已清算的记录转入历史交易流水表中 */
$insert into his_tran_ls
select * from cur_tran_ls
where ((snd_settle_flag = 'Y'
and snd_settle_date <= $l_date)
or (card_type < '50'
and local_logic_date <= $l_date))
and tran_type <> 4
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable insert from cur_tran_ls into his_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 删除当前交易流水已清算的记录 */
$delete from cur_tran_ls
where ((snd_settle_flag = 'Y'
and snd_settle_date <= $l_date)
or (card_type < '50'
and local_logic_date <= $l_date))
and tran_type <> 4
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable delete from cur_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
}
else if (G_settle_level == 2) { /*所有的卡均使用*/
$insert into cur_settle_ls
select * from cur_tran_ls
where acq_bank_id = $sys.bank_id
and local_logic_date = $l_date
and saf_flag = '0' /* 冲正标志:正常 */
and edc_err_flag = '0' /* 正常 */
and tran_flag in ('0','4') /* 交易标志:正常,已退货 */
and resp_code = '00'
and tran_type not in (4,12) /* 预授权,撤消 */
and tran_amt >= 0.01 /* 交易金额为0*/
and terminal_id not like 'TRM%'
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable insert cur_tran_ls to cur_settle_ls![%ld]", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 将当前交易流水已清算的记录转入历史交易流水表中 */
$insert into his_tran_ls
select * from cur_tran_ls
where local_logic_date <= $l_date
and tran_type <> 4
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable insert from cur_tran_ls into his_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
/* 删除当前交易流水已清算的记录 */
$delete from cur_tran_ls
where local_logic_date <= $l_date
and tran_type <> 4
and merchant_id = $tmp_merch;
if (SQLCODE) {
daylog(ERROR, "Unable delete from cur_tran_ls!(%d)", SQLCODE);
$rollback work;
free(G_merchant_id_array);
return -1;
}
}
}
$commit work;
i ++;
}
free(G_merchant_id_array);
/*
更新cur_settle_ls中snd_settle_date为当前日期
*/
$begin work;
/*由于CUR_SETTLE_LS中只有刚转入的流水可以直接更新数据库*/
$update cur_settle_ls
set snd_settle_date = $e_date,
snd_settle_flag='Y',
update_date = $e_date,
update_time = $e_time;
if (SQLCODE) {
daylog(ERROR, "Unable update settle_date to local_sys_date[%ld]!", SQLCODE);
$rollback work;
return -1;
}
$commit work;
return 0;
}
/*
* 转当前已结帐完毕的交易流水记录到历史交易流水表中
*/
int posls_to_history()
{
$char e_date[20];
$char e_date1[20];
$char tmp_date[9];
$char tmp_time[7];
$char tmp_merch[16];
$char sqlstr[512];
return 0;
$ifdef wyz_del_020327;
daylog(ERROR, "posls_to_history() begin.");
getdatef(tmp_date, "");
gettimef(tmp_time, "");
dateadd(tmp_date, -2, e_date1);
dateadd(tmp_date, -30, e_date);
$ifdef wyz_del_020108;
/* 修改还使用前面的条件为使用刚才更新的update_date
和update_time
标识出转入his_tran_ls的日期和时间
*/
$update cur_tran_ls
set update_date=$tmp_date,
update_time = $tmp_time
where ((snd_settle_flag = 'Y'
and snd_settle_date < $sys.logic_date
and acq_bank_id = $sys.bank_id
and acq_host_id = $sys.host_id
and tran_type not in ( 4 )
/* 收单行为自己且不是预授权的所有已结帐交易 */
)
or (( not (acq_bank_id = $sys.bank_id /* 非自己收单 */
and acq_host_id = $sys.host_id ) )
and tran_type not in ( 4 )
and local_sys_date <= $e_date1
/* 非自己收单的超过一定时间的所有非PRE_AUTH交易*/
)
or (tran_type = 4
and ( tran_flag <> '0'
or ( tran_flag = '0' and saf_flag = '1') )
/* PRE_AUTH 已确认,已冲正或超过一定时间*/
)
or resp_code not like '00%'
or local_sys_date <= $e_date
);
$endif;
/*为解决流水太大转流水不成功而采用分隔处理*/
$ifdef wyz_mod_020110;
/* 将当前交易流水已清算的记录转入历史交易流水表中 */
$insert into his_tran_ls
select * from cur_tran_ls
where snd_settle_flag = 'Y'
and snd_settle_date < $sys.logic_date
and tran_type not in ( 4 );
if (SQLCODE) {
daylog(ERROR, "Unable insert from cur_tran_ls into his_tran_ls!(%d)", SQLCODE);
return -1;
}
/* 删除当前交易流水已清算的记录 */
$delete from cur_tran_ls
where snd_settle_flag = 'Y'
and snd_settle_date < $sys.logic_date
and tran_type not in ( 4 );
if (SQLCODE) {
daylog(ERROR, "Unable delete from cur_tran_ls!(%d)", SQLCODE);
return -1;
}
$else;
sprintf(sqlstr, "SELECT DISTINCT merchant_id from merchant_base");
EXEC SQL PREPARE sel_merch_id FROM :sqlstr;
EXEC SQL DECLARE sel_merch_id_cur CURSOR FOR sel_merch_id;
EXEC SQL OPEN sel_merch_id_cur;
if( SQLCODE < 0 ) {
daylog(ERROR, "OPEN Cursor Failed[%ld]", SQLCODE);
return(-1);
}
while(1) {
//循环查找流水记录
EXEC SQL FETCH sel_merch_id_cur INTO :tmp_merch;
if( SQLCODE < 0 ) {
daylog(ERROR, "取商户号失败!![%ld]", SQLCODE);
EXEC SQL CLOSE sel_merch_id_cur;
return(-1);
}
if( SQLCODE == SQLNOTFOUND ) {
EXEC SQL CLOSE sel_merch_id_cur;
break;
}
DelSpace(tmp_merch);
daylog(ERROR, "商户号[%s]", tmp_merch);
/* 将当前交易流水已清算的记录转入历史交易流水表中 */
$insert into his_tran_ls
select * from cur_tran_ls
where merchant_id = $tmp_merch
and snd_settle_flag = 'Y'
and snd_settle_date < $sys.logic_date
and tran_type <> 4;
if (SQLCODE) {
daylog(ERROR, "Unable insert from cur_tran_ls into his_tran_ls!(%d)", SQLCODE);
EXEC SQL CLOSE sel_merch_id_cur;
return -1;
}
/* 删除当前交易流水已清算的记录 */
$delete from cur_tran_ls
where merchant_id = $tmp_merch
and snd_settle_flag = 'Y'
and snd_settle_date < $sys.logic_date
and tran_type <> 4;
if (SQLCODE) {
daylog(ERROR, "Unable delete from cur_tran_ls!(%d)", SQLCODE);
EXEC SQL CLOSE sel_merch_id_cur;
return -1;
}
}
$endif;
return 0;
$endif;
}
/*
* 将cur_tran_ls中非成功交易流水记录和其它不需要进行清算的交易流水
* 转到历史交易流水表中
*/
int pre_posls_to_history()
{
$char tmp_date[9];
$char tmp_date1[9];
$char tmp_date2[9];
$char logic_date[9];
$char tmp_merch[16];
$char sqlstr[512];
$char tmp_sttl_mode[2];
int i=0;
FILE *fp;
SETTLE_RESULT s_r;
char filename[128];
daylog(ERROR, "pre_posls_to_history() begin.");
getdatef(tmp_date, "");
dateadd(tmp_date, -2, tmp_date1);
dateadd(tmp_date, -60, tmp_date2);
#ifdef wyz020704_mod
#else
sprintf(filename, "%s/etc/settle_result", getenv("WORKDIR"));
if ((fp = fopen(filename, "r")) == NULL) {
daylog(ERROR, "pre_posls_to_history fopen failed");
fclose(fp);
return -1;
}
if (fread(&s_r, sizeof(SETTLE_RESULT), 1, fp) != 1){
daylog(ERROR, "pre_posls_to_history fread failed");
fclose(fp);
return -1;
}
if (s_r.result == 0 || s_r.result == -1) {
strcpy(logic_date, sys.logic_date);
else
strcpy(logic_date, s_r.logic_date);
fclose(fp);
#endif
/*
$set isolation to dirty read;
*/
/*首先将当前清算流水中的清算数据,导入历史清算流水中*/
/*即当前清算流水中只保留最近一次的清算流水*/
if (G_settle_mode == 0) {
daylog(DEBUG, "insert into his_settle_ls begin");
EXEC SQL insert into his_settle_ls
select * from cur_settle_ls;
if (SQLCODE) {
daylog(ERROR, "Unable insert cur_settle_ls to his_settle_ls(%d)!", SQLCODE);
return -1;
}
daylog(DEBUG, "delete from cur_settle_ls begin");
EXEC SQL delete from cur_settle_ls;
if (SQLCODE) {
daylog(ERROR, "Unable delete cur_settle_ls(%d)!", SQLCODE);
return -1;
}
}
else {
daylog(DEBUG, "insert into his_settle_ls begin");
EXEC SQL insert into his_settle_ls
select * from cur_settle_ls;
if (SQLCODE) {
daylog(ERROR, "Unable insert cur_settle_ls to his_settle_ls(%d)!", SQLCODE);
return -1;
}
daylog(DEBUG, "delete from cur_settle_ls begin");
EXEC SQL delete from cur_settle_ls;
if (SQLCODE) {
daylog(ERROR, "Unable delete cur_settle_ls!");
return -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -