📄 lan_ip_month.ec
字号:
/* 试用固定IP费用每月数据库结算程序
读ip-net表的费率
按IP地址计算费用,插入费用表*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include <signal.h>
$include sqlca;
/* david */
#define K 1024
#define M 1048576
$long sqlreturn;
$float rn_in,rn_out,rw_in,rw_out;
checksql(str)
char *str;
{
if (sqlca.sqlcode < 0 )
{ printf("%s failure , sqlcode=%d, isam=%d\n",str,sqlca.sqlcode,sqlca.sqlerrd[1]); exit(-1); }
}
cacu_ip()
{
int i;
$char ip[20], group_id[20],login_name[20];
$int account_id;
$double n_in,n_out,w_in,w_out;
$double fn_in,fn_out,fw_in,fw_out,fn_sum,fw_sum,f_total;
$declare cur cursor for
select login_id,sum(n_in),sum(n_out),sum(w_in),sum(w_out)
from lan_ip_day
where fee_id=-1
group by login_id;
$open cur;
while(1)
{
$fetch cur into $ip,$n_in,$n_out,$w_in,$w_out;
checksql("fetch cur error");
if (sqlca.sqlcode==100) break;
fn_in = n_in/M * rn_in;
fn_out = n_out/M * rn_out;
fw_in = w_in/M * rw_in;
fw_out = w_out/M * rw_out;
fn_sum = fn_in + fw_in;
fw_sum = fn_out+ fw_out;
f_total = fn_sum + fw_sum;
/*printf("ip=%s,n_in=%f fn_sum=%f\n",ip,n_in,fn_sum);*/
/* for david's own ip_fee */
$insert into lan_ip_fee(login_id,fee_id,f_date,fee_in,fee_out,fee_total)
values($ip,0,today,$fn_sum,$fw_sum,$f_total);
checksql("insert ip_fee");
/* sqlreturn=sqlca.sqlerrd[1];
$update lan_ip_day set fee_id = $sqlreturn
where login_id=$ip and fee_id=-1;*/
/* for insert z_fee_user_table */
$select account_id,name,group_id
into $account_id,$login_name,$group_id
from g_user_table
where login_id=$ip and services_type="E";
checksql("select account from g_user_table");
if (sqlca.sqlcode ==100)
continue;
$insert into z_fee_user_table
(account_id,group_id,services_type,login_id,login_name,fee_id,fee_date,in_fee,out_fee,total_fee,fee_g_id)
values($account_id,$group_id,"E",$ip,$login_name,0,today,$fn_sum,$fw_sum,$f_total,-1);
checksql("insert z_fee_user_table");
sqlreturn=sqlca.sqlerrd[1];
$update lan_ip_day set fee_id = $sqlreturn
where login_id=$ip and fee_id=-1;
}
$close cur;
printf("insert fee ok!\n");
}
get_rate()
{
$declare cur_n scroll cursor for
select rate_in,rate_out from ip_net where name="n";
$declare cur_w scroll cursor for
select rate_in,rate_out from ip_net where name="w";
$open cur_n;
$fetch first cur_n into $rn_in,$rn_out;
if (sqlca.sqlcode==100)
{
printf("read n_rate error!\n");
$close cur_n;
exit(-1);
}
$close cur_n;
$open cur_w;
$fetch first cur_w into $rw_in,$rw_out;
if (sqlca.sqlcode==100)
{
printf("read w_rate error!\n");
$close cur_w;
exit(-1);
}
$close cur_w;
printf(" get rate ok! \n<n_in=%5.1f n_out=%5.1f w_in=%5.1f w_out%5.1f>\n",rn_in,rn_out,rw_in,rw_out);
}
main(int argc, char *argv[])
{
char command[150];
long i1,i2,j;
if (argc > 1)
{
printf("get arg <%s>\n",argv[1]);
if (strcmp(argv[1],"m")==0)
{
}
}
$database scs_internet@ONLINE;
checksql("database connect error!");
get_rate(); /*读ip-net表的费率*/
cacu_ip(); /*按IP地址计算费用,插入费用表*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -