Beispiel #1
0
static int SaveCancelLossSerial(T_t_tif_tradeserial  *pTradeserial)
{
	int ret;
	
	//	插入卡操作流水表
	ret = DB_t_tif_tradeserial_add(pTradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret [%d]",ret);
		if(DB_REPEAT==ret)
			return E_DB_TRADESERIAL_E;
		else
			return E_DB_TRADESERIAL_I;
	}
	return ret;
}
Beispiel #2
0
 int record_serial(ST_PACK *in_pack,T_t_tif_tradeserial *tradeserial,ST_PACK *out_pack){
	int ret =0;
	double dUniqno = 0;
	char sMsg[256]="";

	//	准备数据插入交易流水表
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqno);  					//获得最大流水号
	if(ret)
	{
		writelog(LOG_ERR,"getNewUniqNo error,errcode=[%d]",ret);
		return ret;
	}						
	tradeserial->serial_no = D2I(dUniqno);			//流水号
	out_pack->damt1=tradeserial->trade_fee;		//充值金额
	out_pack->damt0=tradeserial->out_balance;	//出卡值
	out_pack->lvol0=tradeserial->serial_no;//流水号
	
	sprintf(sMsg,"交易前卡余额:%.2lf元 卡当前余额:%.2lf元",tradeserial->in_balance,tradeserial->out_balance);
	strcat(out_pack->vsmess,sMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);

	ret = DB_t_tif_tradeserial_add(tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			ret = E_DB_TRADESERIAL_E;
		else
			ret = E_DB_TRADESERIAL_I;
		return ret;
	}
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit error,errcode=[%d]",ret);
		return E_DB_COMMIT;
	}
	return 0;
	

}	
Beispiel #3
0
static int record_small_serial(ST_PACK *in_pack,T_t_tif_tradeserial *tradeserial,ST_PACK *out_pack){
	int ret =0;
	double dUniqno = 0;
	 T_t_tif_tradeserial  tPacketSerial;

	//保存充值流水
	memset(&tPacketSerial, 0, sizeof tPacketSerial);
	memcpy(&tPacketSerial, tradeserial, sizeof tPacketSerial);
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqno);  						//获得最大流水号
	if(ret)
	{
		writelog(LOG_ERR,"ret [%d]",ret);
		return ret;
	}
	tPacketSerial.serial_no = D2I(dUniqno);
	tPacketSerial.serial_state = SERISTAT_NONEEDDEBT;
	tPacketSerial.serial_type = TXCODE_SAVING_SMALL_PACKET;
	tPacketSerial.purse_id = 33;//33扇区钱包
	tPacketSerial.in_balance = in_pack->damt2;
	tPacketSerial.trade_fee = in_pack->damt1;
	tPacketSerial.out_balance = tPacketSerial.in_balance + tPacketSerial.trade_fee;

	ret = DB_t_tif_tradeserial_add(&tPacketSerial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			ret = E_DB_TRADESERIAL_E;
		else
			ret = E_DB_TRADESERIAL_I;
		return ret;
	}

	out_pack->damt2=tPacketSerial.out_balance;
	out_pack->lvol1= D2I(dUniqno);			//流水号

	return 0;
	

}	
Beispiel #4
0
int F846336(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	int transflag=0;
	char logicdate[9]="";
	char sysdate[9]="";
	char systime[7]="";

	int cardno=0;

	InAcc	IA;
	char sMaxBalance[20]="";
	double dMaxCardBalance = 0;
	double dMaxEACCBalance = 0;
	T_t_tif_tradeserial  tradeserial;
	T_t_cif_customer tCustomer;
	T_t_pif_card tCard;
	T_t_aif_account tCardAccount;
	T_t_aif_account tEAcc;

	memset(&IA,0,sizeof(IA));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tCard,0,sizeof(tCard));
	memset(&tCardAccount,0,sizeof(tCardAccount));
	memset(&tEAcc,0,sizeof(tEAcc));
	
	char cardphyid[9]="";
	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	
	transflag=rPack->lvol3;		
//	char key[17]="";
//	char pwd_plain[33]="";
//	char pwd_crypt[65]="";
//	strcpy(key,STATIC_SEED_KEY);
//	des2src(pwd_crypt,rPack->snote2);
//	EncodePwd(key,pwd_plain,pwd_crypt, 0);

	getsysdate(sysdate);
	getsystime(systime);
	
	cardno=rPack->lvol0;		//卡号

	//检查卡号
	ret=DB_t_pif_card_read_by_card_id(cardno,&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",cardno);
		if(DB_NOTFOUND==ret)
			return E_CARDNO_NOT_EXIST;
		else 
			return E_DB_CARD_R;
	}

	if(strncmp(tCard.state_id,CARDSTAT_REG,4)!=0)
	{
		if('2'==tCard.state_id[CARDSTAT_TYPE_REG])
			ret= E_CARDNO_LOGOUT;
		else if('3'==tCard.state_id[CARDSTAT_TYPE_REG])
			ret = E_CARD_CHANGE;
		else if(tCard.state_id[CARDSTAT_TYPE_LOST]==STATE_TRUE)
			ret=E_CARDNO_LOST;
		else if(tCard.state_id[CARDSTAT_TYPE_FREEZE]==STATE_TRUE)
			ret=E_CARDNO_FREEZE;
		else if(tCard.state_id[CARDSTAT_TYPE_WFAIL]==STATE_TRUE)
			ret=E_CARDNO_WFAIL;
		return ret;
	}
	
	//比较卡物理ID是否相同
	if(strcmp(tCard.physical_no,rPack->sstation0)!=0)
	{
		writelog(LOG_ERR,"db cardphyid[%s],input cardphyid[%s]",tCard.physical_no,rPack->sstation0);
		return E_CARD_PHYNO_DIFFER;
	}
	//检查卡的有效期
	if(strncmp(tCard.end_time,sysdate,6)<=0)
		return E_CARD_EXPIRE;
	//检查卡对应的账户
	ret = DB_t_aif_account_read_by_card_id_and_purse_id(cardno, PURSE_NO_ONE,&tCardAccount);
	if (ret)
	{
		if(DB_NOTFOUND==ret)
			return E_ACTNO_NOT_EXIST;
		else
			return  E_DB_ACCOUNT_R;
	}
	if(tCardAccount.current_state!=1)
		return E_ACTNO_LOGOUT;

	//检查客户表,电子钱包是否开通
	ret = DB_t_cif_customer_read_by_cut_id(tCardAccount.customer_id, &tCustomer);
	if(ret)
	{		
		if(DB_NOTFOUND==ret)
			return E_CUSTOMER_NOT_EXIST;
		else
			return E_DB_CUSTOMER_R;
	}
	if(tCustomer.cut_state==CUSTSTAT_LOGOUT)
		return E_CUSTOMER_LOGOUT;
	
	if(tCustomer.eaccflag[0]=='0')
		return E_EACCNO_LOGOUT;

	//检查电子账户
	ret=DB_t_aif_account_read_by_customer_id_and_act_type(tCustomer.cut_id, ACCTYPE_PEREACC, &tEAcc);
	if (ret)
	{
		if(DB_NOTFOUND==ret)
			return E_ACTNO_NOT_EXIST;
		else
			return  E_DB_ACCOUNT_R;
	}
	if(tEAcc.current_state!=1)
		return E_ACTNO_LOGOUT;

	tradeserial.trade_fee = rPack->damt0;					//充值金额
	char inpwd_crypt[65]="";
	char seedkey[33]="";
	char inpwd_plain[65]="";
	char dbpwd_plain[65]="";
	if(transflag)		//电子钱包到卡转帐
	{
		tradeserial.serial_type = TXCODE_EACC2CARD;
		ret=GetParameter(2006,seedkey);
		if(ret)
			return ret;
		des2src(inpwd_crypt,rPack->snote2);
		if(!strlen(inpwd_crypt))
			return E_INPUTNULL_PWD;
		
		ret=decrypt_elec_card_pwd(0,seedkey,inpwd_crypt,inpwd_plain);
		if(ret)
			return E_EACCPWD;
		ret=decrypt_elec_card_pwd(0,seedkey,tEAcc.password,dbpwd_plain);
		if(ret)
			return E_PWD_DECRYPT;
		if(strcmp(inpwd_plain,dbpwd_plain)!=0)
			return E_EACCPWD;
		if(tEAcc.stoppayflag[0] == '1')
			return E_EACC_STOPPAY;
		if(amtcmp(tEAcc.cur_freebala , rPack->damt0) <0)   //金额不足
			return E_EACC_BALANCE_SHORTAGE;
		ret=GetParameter(GLOBE_MAXCARDBALANCE,sMaxBalance);
		if(ret)
			return ret;
		dMaxCardBalance=atof(sMaxBalance);
		if(amtcmp(tCardAccount.cur_bala+tradeserial.trade_fee,dMaxCardBalance)>0)
			return E_AMT_EXCEED_MAX;

//		tradeserial.in_balance=rPack->damt1;			//卡上余额
//		tradeserial.trade_count=rPack->lvol6+1;		//交易次数
		
	}
	else
	{
		tradeserial.serial_type = TXCODE_CARD2EACC;

		strcpy(seedkey,STATIC_SEED_KEY);
		des2src(inpwd_plain,rPack->scust_limit2);
		EncodePwd(seedkey,inpwd_plain,inpwd_crypt,0);
		if(strcmp(tCardAccount.password,inpwd_crypt)!=0)
			return E_CARD_PWD_DIFFER;
		if(amtcmp(tCardAccount.cur_freebala , rPack->damt0) <0)   //金额不足
			return E_EACC_BALANCE_SHORTAGE;
			
		ret=GetParameter(GLOBE_MAXEACCBALANCE,sMaxBalance);
		if(ret)
			return ret;
		dMaxEACCBalance=atof(sMaxBalance);
		if(amtcmp(tEAcc.cur_bala+tradeserial.trade_fee,dMaxEACCBalance)>0)
			return E_AMT_EXCEED_MAX;
		
//		tradeserial.in_balance=tEAcc.cur_freebala;
//		tradeserial.trade_count=tEAcc.consume_count+1;		//交易次数

	}

	ret=GetLogicDate(logicdate);							//业务日期
	if(ret)
		return ret;
	
	double dSerialNo = 0;
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialNo);  					//获得最大流水号
	if(ret)
	{
		writelog(LOG_ERR," getNewUniqNo ERRCODE = [%d]",ret);
		return ret;
	}
	tradeserial.serial_no = D2I(dSerialNo);											//流水号
	tradeserial.other_seri_no = 0;															//上传端流水号
	tradeserial.serial_state = SERISTAT_DEBT;												//流水状态
	des2src(tradeserial.operate_date,sysdate);											//发生日期
	des2src(tradeserial.operate_time,systime);											//发生时间
	des2src(tradeserial.collect_date,sysdate);												//采集日期
	des2src(tradeserial.collect_time,systime);												//采集时间
	des2src(tradeserial.enteract_date,logicdate);											//处理日期
	des2src(tradeserial.enteract_time,systime);											//处理时间
	des2src(tradeserial.oper_code, rPack->sname);
	tradeserial.customer_id = tCustomer.cut_id;
	tradeserial.sys_id = 0;																//外部系统标识
	tradeserial.in_balance=rPack->lvol7/100.0;
	tradeserial.trade_count=rPack->lvol6+1;		//交易次数
	des2src(IA.sArrInActno[0],tCardAccount.account_id);						//卡帐户
	des2src(IA.sArrInActno[5],tEAcc.account_id);						//电子钱包帐户
	IA.iCardNo=tEAcc.card_id;

	IA.dArrInAmt[0]=tradeserial.trade_fee;

	ret=process(&IA,&tradeserial);
	if(ret)
	{
		writelog(LOG_ERR,"process ret[%d]",ret);
		return ret;
	}	
	if(TXCODE_CARD2EACC==tradeserial.serial_type)
		sprintf(outPack->vsmess,"卡转电子钱包:转帐前卡余额%.2lf元,转账金额%.2lf,当前卡余额%.2lf元",tradeserial.in_balance,tradeserial.trade_fee,tradeserial.out_balance);
	else
		sprintf(outPack->vsmess,"电子钱包转卡:转帐前卡余额%.2lf元,转账金额%.2lf,当前卡余额%.2lf元",tradeserial.in_balance,tradeserial.trade_fee,tradeserial.out_balance);
	writelog(LOG_DEBUG,outPack->vsmess);
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			return E_DB_TRADESERIAL_E;
		else
			return E_DB_TRADESERIAL_I;
	}
	if(amtcmp(tradeserial.out_balance,0)<0)
		return E_ENTER_ACCOUNT;

	SetCol(handle,F_DAMT2,F_LSERIAL1,F_VSMESS,0);		

	outPack->damt2=tradeserial.out_balance;		//出卡值
	outPack->lserial1=tradeserial.serial_no;			//流水号
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
int F847301(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
    T_t_tif_tradeserial tSerial, tPacketSerial;
    T_t_aif_account tAccount;
    T_t_card tCard;
    T_t_customer tCustomer;
    T_t_tif_writefailed tWriteFailed;
    InAcc IA;

    ST_CPACK aPack;
    ST_PACK *out_pack = &(aPack.pack);

    int ret = 0;
    int TxTypeCount = 0;
    int hi_cardid = 0;             //交易卡号
    char buf[100 + 1] = "";
    char sysdate[11] = "";
    char systime[7] = "";
    char logicdate[11] = "";
    char sMsg[128] = "";
//    char temp_account_id[16 + 1] = "2081";             //个人临时帐户
    double dUniqNo = 0;                              //最大流水号
    double cardbefbal = 0;
    double small_packet_balance = 0;                    //小钱包中的余额
    double max_balance = 0;                           //小钱包余额上限  
    double transfer_price = 0;                          //转入金额

    memset(&tAccount, 0, sizeof tAccount);
    memset(&tCard, 0, sizeof tCard);
    memset(&tCustomer, 0, sizeof tCustomer);
    memset(&IA, 0, sizeof IA);
    memset(&tPacketSerial, 0, sizeof tPacketSerial);
    memset(&tWriteFailed, 0, sizeof tWriteFailed);

    memset(&aPack,0,sizeof aPack);
    ResetNormalCPack(&aPack, 0, 1);
    SetCol(handle,0);
    SetCol(handle,F_LVOL0,F_LVOL1,F_DAMT0,F_DAMT2,F_VSMESS,F_LVOL9,F_LVOL5,0);

    hi_cardid = rPack->lvol0;
    if (hi_cardid <= 0)
    {
        *pRetCode = E_INPUT_CARDNO;
        goto L_RETU;
    }

    //判断小钱包中的余额
    small_packet_balance = rPack->damt3;

    //读取小钱包余额上限
    ret = GetSysParaVal(GLB_PACKET_LIMITS,buf);
    if (ret)
    {
        *pRetCode = ret;
        goto L_RETU;
    }
    max_balance = atof(buf);
    if (amtcmp(max_balance,0) <= 0)
    {
        *pRetCode = E_GLOBAL_PARAM_ERROR;
        goto L_RETU;
    }

    //判断充值到小钱包的金额
    transfer_price = rPack->damt4;               //钱包转入金额

    writelog(LOG_DEBUG,"tranfser_price=[%d]",transfer_price);
    writelog(LOG_DEBUG,"small_packet_balance=[%d]",small_packet_balance);
    if (amtcmp(transfer_price, 0) <= 0 || amtcmp(small_packet_balance, 0) < 0)
    {
        *pRetCode = E_INPUT_DATA_INVAILD;
        goto L_RETU;
    }

    if (amtcmp(small_packet_balance + transfer_price,max_balance) > 0)
    {
        sprintf(sMsg, "钱包余额上限是%f吨", max_balance);
        *pRetCode = E_PACKET_LIMIT_EXCEED;
        goto L_RETU;
    }

    cardbefbal = rPack->damt1;
    if (amtcmp(cardbefbal,0.0) < 0)
    {
        *pRetCode = E_BALANCE_SHORTAGE;
        goto L_RETU;
    }
    
    ret = DB_t_card_read_by_cardno(hi_cardid,&tCard);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
		{
		    *pRetCode = E_DB_CARD_N;
		}
		else
		{
		    *pRetCode = E_DB_CARD_R;
	    }
	    goto L_RETU;
	}
	
    //判断卡密码是否正确
    /*
    if (CheckUserPswd(rPack->semp_pwd,tCard.password))
    {
        writelog(LOG_ERR,"Card password error");
        *pRetCode = E_TRANS_SCHCARD_PWDERR;
        goto L_RETU;
    }
    */
    
    if (strncmp(tCard.cardstatus, TYPE_YES, 1) != 0)
    {
        writelog(LOG_ERR,"card_state=[%s]",tCard.cardstatus);
        *pRetCode = E_TRANS_SCHACC_DESTORY;
        goto L_RETU;
    }

    if (STATE_TRUE == tCard.cardstatus[CARDSTAT_TYPE_LOST])
    {
        writelog(LOG_ERR,"card_state=[%s]",tCard.cardstatus);
        *pRetCode = E_TRANS_SCHCARD_LOSTING;
        goto L_RETU;
    }

    if (STATE_TRUE == tCard.cardstatus[CARDSTAT_TYPE_FREEZE])
    {
        writelog(LOG_ERR,"card_state=[%s]",tCard.cardstatus);
        *pRetCode = E_TRANS_SCHCARD_FREEZE;
        goto L_RETU;
    }

    if (STATE_TRUE == tCard.cardstatus[CARDSTAT_TYPE_WFAIL])
    {
        *pRetCode = E_CARDNO_WFAIL;
        goto L_RETU;
    }

    ret = DB_t_customer_read_by_custid(tCard.custid,&tCustomer);
    if (ret)
    {
        if (DB_NOTFOUND == ret)
        {
            *pRetCode = E_DB_CUSTOMER_N;
        }
        else
        {
            *pRetCode = E_DB_CUSTOMER_R;
        }
        goto L_RETU;
    }

    //读取个人帐户
    ret = DB_t_aif_account_read_by_cardno_and_purseno(tCard.cardno,PURSE_NO_ONE,&tAccount);
    if (ret)
    {
        if (DB_NOTFOUND == ret)
        {
            *pRetCode = E_DB_ACCOUNT_N;
        }
        else
        {
            *pRetCode = E_DB_ACCOUNT_R;
        }
        goto L_RETU;
    }
    //个人临时帐户填死掉了, 不需要查询
    ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqNo);              // 获得最大流水号
    if (ret)
    {
        writelog(LOG_ERR,"ret[%d]",ret);
        *pRetCode = ret;
		goto L_RETU;
    }

    getsysdate(sysdate);
    getsystime(systime);
    GetLogicDate(logicdate);
    memset(&tSerial, 0, sizeof tSerial);
    tSerial.serial_no = D2I(dUniqNo);
    tSerial.other_seri_no = 0;
    tSerial.serial_state = SERISTAT_DEBT;                           //流水状态
    tSerial.serial_type = TXCODE_CONSUME;                           //交易类型
    des2src(tSerial.operate_date,sysdate);                           //发生日期
    des2src(tSerial.operate_time,systime);                           //发生时间
    des2src(tSerial.collect_date,sysdate);                           //采集日期
    des2src(tSerial.collect_time,systime);                           //采集时间
    des2src(tSerial.enteract_date,logicdate);                        //处理日期
    des2src(tSerial.enteract_time,systime);                          //处理时间

//    tSerial.maindeviceid = rPack->lvol3;                            //上传工作站标识
    tSerial.deviceid = 0;                                          //采集设备标识 
    tSerial.cardno = hi_cardid;                                    //交易卡号
    des2src(tSerial.showid,tCard.showid);                           //显示卡号
    tSerial.purseno = PURSE_NO_ONE;                                //钱包号
    tSerial.custid = tCard.custid;                         //客户号
    des2src(tSerial.opercode, rPack->scust_no);                      //操作员代码
    tSerial.sysid = 0;
    tSerial.trade_count = rPack->lvol4 + 1;                          //卡交易次数
    tSerial.trade_fee = transfer_price;                             //转钱金额
    tSerial.cardbefbal = cardbefbal;                                //入卡值
    writelog(LOG_DEBUG,"水控转账入卡值[%.2lf]",cardbefbal);
    des2src(IA.sArrInActno[0],tAccount.account_id);                 //个人帐户
//  des2src(IA.sArrInActno[1],temp_account_id);                  //个人临时帐户
    IA.dArrInAmt[0] = tSerial.trade_fee;                            //交易金额
    IA.iCardNo = tCard.cardno;                                     //交易卡号
    IA.iFeeType = tCustomer.feetype;                               //客户收费类型

    //调用入帐子模块
    ret = process(&IA,&tSerial);
    if (ret)
    {
        writelog(LOG_ERR,"process ret[%d]",ret);
        *pRetCode = ret;
        goto L_RETU;
    }
    sprintf(out_pack->vsmess,"流水号:%d 卡号:%d ",IA.iSerialNo,IA.iCardNo);
	for(TxTypeCount = 1; TxTypeCount <= IA.iOutTxTypeCnt; TxTypeCount++)
	{
		switch(IA.iArrOutTxType[TxTypeCount])
		{
			case TXTYPE_TOLL_DEPOSIT:
			case TXTYPE_TOLL_DEPOSIT_BILL:
			case TXTYPE_TOLL_DEPOSIT_FUNDBOOK:
			case TXTYPE_DEDUCT_DEPOSIT:
			case TXTYPE_RETURN_DEPOSIT:
				tSerial.depositfee = IA.dArrOutAmt[TxTypeCount];
				break;
			case TXTYPE_PRE_TOLL_BOARD:
			case TXTYPE_PRE_TOLL_BOARD_BILL:
			case TXTYPE_PRE_TOLL_BOARD_FUNDBOOK:
			case TXTYPE_TOLL_BOARD:
			case TXTYPE_DEDUCT_BOARD:
			case TXTYPE_RETURN_BOARD:
			case TXTYPE_RETURN_BOARD_BILL:
			case TXTYPE_RETURN_BOARD_FUNDBOOK:
				tSerial.managefee = IA.dArrOutAmt[TxTypeCount];
				break;
			case TXTYPE_TOLL_CHARGE:
			case TXTYPE_TOLL_CHARGE_BILL:
			case TXTYPE_TOLL_CHARGE_FUNDBOOK:
				tSerial.in_fee = IA.dArrOutAmt[TxTypeCount];
				break;
			case TXTYPE_TOLL_CARDCOST:
			case TXTYPE_TOLL_CARDCOST_BILL:
			case TXTYPE_TOLL_CARDCOST_FUNDBOOK:
				tSerial.cost_fee = IA.dArrOutAmt[TxTypeCount];
				break;
			default:
				break;
		}
		if (amtcmp(IA.dArrOutAmt[TxTypeCount], 0) != 0)
		{
		    sprintf(sMsg,"%s:%.2lf元 ", IA.sArrOutTxName[TxTypeCount], IA.dArrOutAmt[TxTypeCount]);
			strcat(out_pack->vsmess, sMsg);
		}
	}
	sprintf(sMsg, "卡当前余额:%.2lf元", tSerial.cardaftbal);
	strcat(out_pack->vsmess, sMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);

	//插入交易流水表
	ret = DB_t_tif_tradeserial_add(&tSerial);
	if (ret)
	{
	    writelog(LOG_ERR,"ret[%d]",ret);
		if (DB_REPEAT == ret)
		{
		    *pRetCode = E_DB_TRADESERIAL_E;
		}
		else
		{
		    *pRetCode = E_DB_TRADESERIAL_I;
		}
		goto L_RETU;
	}
	//保存充值流水
	memcpy(&tPacketSerial, &tSerial, sizeof tPacketSerial);
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqNo);  						//获得最大流水号
	if(ret)
	{
		writelog(LOG_ERR,"ret [%d]",ret);
		*pRetCode = ret;
		goto L_RETU;
	}
	tPacketSerial.serial_no = D2I(dUniqNo);
	tPacketSerial.serial_state = SERISTAT_NONEEDDEBT;
	tPacketSerial.serial_type = TXCODE_SAVING_SMALL_PACKET;
	tPacketSerial.purseno = PURSE_NO_TWO;
	tPacketSerial.trade_count = rPack->lvol5 + 1;
    des2src(tPacketSerial.opercode, rPack->scust_no);
	tPacketSerial.cardbefbal = small_packet_balance;
	tPacketSerial.trade_fee = transfer_price;
	tPacketSerial.cardaftbal = small_packet_balance + tPacketSerial.trade_fee;
	
	ret = DB_t_tif_tradeserial_add(&tPacketSerial);
	if(ret)
	{
		if(DB_REPEAT == ret)
		{
	        *pRetCode = E_DB_TRADESERIAL_E;	
		}
		else
		{
		    *pRetCode = E_DB_TRADESERIAL_I;
		}
		goto L_RETU;
	}
	out_pack->lvol0 = tSerial.serial_no;
	out_pack->lvol1 = tPacketSerial.serial_no;
	out_pack->damt2 = tPacketSerial.cardaftbal;
	out_pack->damt0 = tSerial.cardaftbal;
	out_pack->lvol9 = tSerial.trade_count;
	out_pack->lvol5 = tPacketSerial.trade_count;
	writelog(LOG_DEBUG,"水控钱包金额[%.2lf], 出卡值[%.2lf]",out_pack->damt2,out_pack->damt0);
	
	PutRow(handle,out_pack,pRetCode,szMsg);
    return 0;
L_RETU:
	return -1;	
}
Beispiel #6
0
int F847104(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret =0;
	int len = 0;
	int i=0;
	int hi_cutid=0;
	char h_showcardid[11] = "";						//显示卡号
	char h_password[7] = "";							//卡密码
	double h_temp_Card_id = 0;						//卡号
	double dSerialNo=0;
	char seed_key[17] = "";							//种子密钥
	char card_endtime[8 + 1] = "";						//卡的有效截至日期
	char logicdate[11]="";								//业务日期
	char sysdate[11]="";
	char systime[9]="";
	char sEndDate[9]="";
	char sMsg[256]="";
	char sMaxCardBalance[20]="";
	char lost_date[11]="";
	char buf[64] = "";
	int write_failed = 0;
	double dMaxCardBalance=0;
	int lost_card_id=0;
	T_t_pif_card		tCard;
	T_t_pif_card		tOldCard;
	T_t_cif_customer 	tCustomer;
	T_t_pif_spefee 	tSpeFee;
    //	T_t_pif_cardlossinfo tCardLossInfo;
	T_t_tif_tradeserial  tradeserial;
	T_t_aif_account tAccount;
	InAcc  IA;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL5,
           F_SCUST_NO,	F_SCUST_NO2,F_SCUST_AUTH,F_SCUST_AUTH2,
           F_SDATE0,F_SNAME,F_SNAME2,
           F_SOPEN_EMP,F_SSTATUS0,
           F_DAMT2,F_LSERIAL1,F_VSMESS,0);

	memset(&tCard,0,sizeof(tCard));
	memset(&tOldCard,0,sizeof(tOldCard));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tSpeFee,0,sizeof(tSpeFee));
    //	memset(&tCardLossInfo,0,sizeof(tCardLossInfo));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&IA,0,sizeof(IA));

	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);										//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	//检查客户信息,判断是否可以发行卡
	hi_cutid=rPack->lvol0;									//客户号
	des2src(tCard.physical_no, rPack->sbank_acc);				//物理卡号
	trim(h_showcardid);
	ret=IsExistFreezeCardByCustomId(hi_cutid);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	ret=IsExistNoLostCardByCustomId(hi_cutid);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	if(strlen(h_showcardid))
	{
		ret=IsExistShowCardNo(h_showcardid);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
	}
	ret=IsExistCardByPhyCardNo(tCard.physical_no);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	ret=GetLostCardIdByCustomId_TypeId(hi_cutid,CT_NORMAL,&lost_card_id);
	if(ret)
	{
		writelog(LOG_ERR,"customer[%d]tCard type_id[%d]",hi_cutid,CT_NORMAL);
		*pRetCode = ret;
		goto L_RETU;
	}

    /*
      ret=DB_t_pif_cardlossinfo_read_by_card_id_and_state_id(lost_card_id, STATE_VALID, &tCardLossInfo);
      if(ret)
      {
      writelog(LOG_ERR,"lost_card_id[%d]",lost_card_id);
      if(DB_NOTFOUND==ret)
      *pRetCode =  E_CARDNO_NOT_EXIST;
      else
      *pRetCode =  E_DB_CARD_R;
      goto L_RETU;
      }
    */
	ret=get_latest_lost_date_by_card_no(lost_card_id,lost_date);
	if(ret)
	{
		writelog(LOG_ERR,"lost_card_id[%d]",lost_card_id);
		*pRetCode =ret;
		goto L_RETU;
	}
	//先检查客户的挂失的正式卡是否到了补办日期
	ret=GetLostCardValiddate(lost_date,sEndDate);
	if(ret)
	{
		*pRetCode =ret;
		goto L_RETU;
	}

	if(strncmp(sEndDate,sysdate,8)>0)
	{
		writelog(LOG_ERR,"lost_normal_card_id[%d]lost_date[%s]end_date[%s]",lost_card_id,lost_date,sEndDate);
		*pRetCode =  E_NORMALCARD_NOT_REACH_ENDDATE;
		goto L_RETU;
	}
    /*
	//更新卡挂失日期表中该卡状态为无效
	ret=UpdateCardLossInfoState(lost_card_id,STATE_VALID,STATE_INVALID);
	if(ret)
	{
    *pRetCode = ret;
    goto L_RETU;
	}
    */
	//注销原卡
	ret=DB_t_pif_card_read_lock_by_cur_and_card_id(lost_card_id,&tOldCard);
	if(ret)
	{
		writelog(LOG_ERR,"lost_card_id[%d]",lost_card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode = E_CARDNO_NOT_EXIST;
		else
			*pRetCode =  E_DB_CARD_R;
		goto L_RETU;
	}
	if(tOldCard.state_id[CARDSTAT_TYPE_WFAIL] == STATE_TRUE
		&& tOldCard.is_managefee[0] == CARDWFAIL_WATER )
	{
		// 转账的时候写卡失败
		write_failed = 1;
	}
	else
	{
		des2src(tCard.state_id,CARDSTAT_REG);			//卡状态
	}
	des2src(tOldCard.state_id,CARDSTAT_LOGOUT);		//注销
	des2src(tOldCard.end_time,sysdate);					//注销日期
	ret=DB_t_pif_card_update_lock_by_cur(&tOldCard);
	if(ret)
	{
		writelog(LOG_ERR,"lost_card_id[%d]",lost_card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode =   E_CARDNO_NOT_EXIST;
		else
			*pRetCode =  E_DB_CARD_R;
		goto L_RETU;
	}
	DB_t_pif_card_free_lock_by_cur();

	if(write_failed)
	{
		ret = GetXmlValue(tOldCard.comments,sizeof buf,XML_KEY_SERIALNO2,buf);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		AddXmlItemStr(tCard.comments,XML_KEY_SERIALNO2,buf);
		ret = GetXmlValue(tOldCard.comments,sizeof buf,XML_KEY_OPERATEDATE2,buf);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		AddXmlItemStr(tCard.comments,XML_KEY_OPERATEDATE2,buf);
		ret = GetXmlValue(tOldCard.comments,sizeof buf,XML_KEY_TRADECODE2,buf);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		AddXmlItemStr(tCard.comments,XML_KEY_TRADECODE2,buf);
		tCard.is_managefee[0] = CARDWFAIL_WATER;
	}

	ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(hi_cutid, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",hi_cutid);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode= E_DB_CUSTOMER_R;
		goto L_RETU;
	}
	//得到收费类别
	if(tCustomer.fee_type<1)
	{
		ret=DB_t_pif_spefee_read_by_dept_code_and_cut_type(tCustomer.classdept_no, tCustomer.cut_type,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.fee_type=tCustomer.cut_type;
			}
			else
			{
				DB_t_cif_customer_free_lock_cur();
				*pRetCode=E_DB_SPEFEE_R;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.fee_type=tSpeFee.fee_type;
		}
		//更新客户表的收费类别字段
		ret=DB_t_cif_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode= E_CUSTOMER_NOT_EXIST;
			else
				*pRetCode= E_DB_CUSTOMER_U;
			goto L_RETU;
		}
	}
	DB_t_cif_customer_free_lock_cur();

	tradeserial.trade_fee =D4U5(rPack->damt0,2);
	//	准备数据插入卡信息表
	memcpy(seed_key,STATIC_SEED_KEY,16);			//读种子密钥
	if(strlen(tCustomer.can_time)==8)
	{
		ret=IsInvalidDateTime(tCustomer.can_time,"YYYYMMDD");
		if(ret)
		{
			*pRetCode=E_TB_CUSTOMER_ENDTIME;
			goto L_RETU;
		}
		if(strncmp(tCustomer.can_time,sysdate,8)<=0)
		{
			*pRetCode=E_TB_CUSTOMER_ENDTIME;
			goto L_RETU;
		}
		des2src(card_endtime,tCustomer.can_time);
	}
	else if(strlen(rPack->sdate0)==0)
	{
		*pRetCode=E_TB_CUSTOMER_NO_ENDTIME;
		goto L_RETU;
	}
	else
	{
		ret=IsInvalidDateTime(rPack->sdate0,"YYYYMMDD");
		if(ret)
		{
			*pRetCode = E_INPUT_DATE;
			goto L_RETU;
		}
		if(strncmp(rPack->sdate0,sysdate,8)<=0)
		{
			*pRetCode=E_INPUT_DATE;
			goto L_RETU;
		}
		des2src(card_endtime,rPack->sdate0);
	}

	tradeserial.trade_fee = rPack->damt0;								//金额
	tradeserial.other_seri_no = 0;										//上传端流水号
	tradeserial.serial_state = SERISTAT_DEBT;								//流水状态
	des2src(tradeserial.operate_date,sysdate);							//发生日期
	des2src(tradeserial.operate_time,systime);							//发生时间
	des2src(tradeserial.collect_date,sysdate);								//采集日期
	des2src(tradeserial.collect_time,systime);								//采集时间
	des2src(tradeserial.enteract_date,logicdate);							//处理日期
	des2src(tradeserial.enteract_time,systime);							//处理时间
	tradeserial.maindevice_id = rPack->lvol6;								//上传工作站标识
	tradeserial.device_id = rPack->lvol7;									//采集设备标识
	tradeserial.purse_id = PURSE_NO_ONE;								//钱包号
	tradeserial.customer_id = tCustomer.cut_id;							//客户标识
	tradeserial.sys_id = 0;												//外部系统标识
	des2src(tradeserial.oper_code, rPack->scust_limit);					//操作员号

	len=strlen(tCustomer.man_id) ;
	if (len >= 6)
	{
		strncpy(h_password,&(tCustomer.man_id[len-6]),6);
		if(h_password[5]>'9'||h_password[5]<'0')
			h_password[5]='0';
	}
	else
	{
		strcpy(h_password,"666666");
	}
	ret = getNewUniqNo(KEYTYPE_CARD_ID,&h_temp_Card_id);						//获取最大卡号
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	tCard.card_id = (int)h_temp_Card_id;											//卡号
	des2src(tCard.showid,h_showcardid);										//显示卡号
	des2src(tCard.is_main,TYPE_YES);  											//是否为主卡
	tCard.type_id = CT_NORMAL;													//卡类别
	EncodePwd(seed_key,h_password,tCard.password,0);							//卡密码
	tCard.cosumer_id = hi_cutid;													//客户标识
	tCard.account_count = ACCOUNT_COUNT_ONE;									//卡对应帐户个数
	des2src(tCard.begin_time,sysdate);											//注册时间
	des2src(tCard.end_time, card_endtime);										//截至时间

	tCard.phytype = PHYTYPE_NO_ONE;											//设备物理型号;默认为1
	//	插入卡信息
	ret = DB_t_pif_card_add(&tCard);
	if (ret)
	{
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_CARD_E;
		else
			*pRetCode = E_DB_CARD_I;
		goto L_RETU;
	}
	//修改帐户表中对应的卡号,类型,状态
	ret=DB_t_aif_account_read_lock_by_c0_and_card_id_and_purse_id(lost_card_id,PURSE_NO_ONE,&tAccount);
	if (ret)
	{
		writelog(LOG_ERR,"normalcard_account_id[%s]",lost_card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode =  E_ACTNO_NOT_EXIST;
		else
			*pRetCode =  E_DB_ACCOUNT_R;
	}
	if(tAccount.current_state!=1)
	{
		*pRetCode=E_ACTNO_LOGOUT;
		goto L_RETU;
	}
	tAccount.card_id=tCard.card_id;
	tAccount.card_balance=tAccount.cur_freebala;			//更新卡余额与库余额一致
	tAccount.consume_count=0;
	ret=DB_t_aif_account_update_lock_by_c0(&tAccount);
	if (ret)
	{
		writelog(LOG_ERR,"DB_t_aif_account_update_lock_by_cur4 ret[%d]account_id[%s]",ret,tAccount.account_id);
		if(DB_NOTFOUND==ret)
			*pRetCode =   E_ACTNO_EXIST;
		else
			*pRetCode =  E_DB_ACCOUNT_U;
	}
	DB_t_aif_account_free_lock_c0();

	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialNo);  						//获得最大流水号
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	tradeserial.serial_no=(int)dSerialNo;
	tradeserial.serial_type=TXCODE_CHANGE_CARD;
	tradeserial.card_id=tCard.card_id;				//新卡号
	des2src(tradeserial.showid,tCard.showid);			//显示卡号

	strcpy(IA.sArrInActno[0],tAccount.account_id);		//账号
	IA.dArrInAmt[0]=tradeserial.trade_fee;			//交易金额
	IA.iUseCardFlag=USE_CARD_TYPE_ONLINE;		//联机交易
	IA.dInCardBala=tAccount.cur_freebala;			//入卡值
	IA.iTxCnt=1;
	IA.iCardNo=tCard.card_id;
	IA.iFeeType=tCustomer.fee_type;
	IA.iArrInFeeSwitch[0]=rPack->lvol0;
	IA.iArrInFeeSwitch[1]=rPack->lvol1;
	IA.iArrInFeeSwitch[2]=rPack->lvol2;
	IA.iArrInFeeSwitch[3]=rPack->lvol3;
	IA.iArrInFeeSwitch[4]=rPack->lvol4;
	IA.iArrInFeeSwitch[5]=rPack->lvol5;
	IA.iArrInFeeSwitch[6]=rPack->lvol6;
	IA.iArrInFeeSwitch[7]=rPack->lvol7;
	IA.iArrInFeeSwitch[8]=rPack->lvol8;
	IA.iArrInFeeSwitch[9]=rPack->lvol9;
	IA.iArrInFeeSwitch[10]=rPack->lvol10;
	ret=process(&IA,&tradeserial);
	if(ret)
	{
		writelog(LOG_ERR,"process ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d 卡号:%d ",IA.iSerialNo,IA.iCardNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		switch(IA.iArrOutTxType[i])
		{
	        case TXTYPE_TOLL_DEPOSIT:
	        case TXTYPE_DEDUCT_DEPOSIT:
	        case TXTYPE_RETURN_DEPOSIT:
	            tradeserial.deposit_fee=IA.dArrOutAmt[i];
	            break;
	        case TXTYPE_PRE_TOLL_BOARD:
	        case TXTYPE_TOLL_BOARD:
	        case TXTYPE_DEDUCT_BOARD:
	        case TXTYPE_RETURN_BOARD:
	            tradeserial.boardfee=IA.dArrOutAmt[i];
	            break;
	        case TXTYPE_TOLL_CHARGE:
	            tradeserial.in_fee=IA.dArrOutAmt[i];
	            break;
	        case TXTYPE_TOLL_CARDCOST:
	            tradeserial.cost_fee=IA.dArrOutAmt[i];
	            break;
	        default:
	            break;
		}
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	sprintf(sMsg,"卡当前余额:%.2lf元",tradeserial.out_balance);
	strcat(out_pack->vsmess,sMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	if(amtcmp(tradeserial.out_balance,0)<0)
	{
		*pRetCode=E_ENTER_ACCOUNT;
		goto L_RETU;
	}
	//检查金额是否超过最大额度
	ret=GetParameter(GLOBE_MAXCARDBALANCE,sMaxCardBalance);
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	dMaxCardBalance=atof(sMaxCardBalance);
	if(amtcmp(tradeserial.out_balance,dMaxCardBalance)>0)
	{
		writelog(LOG_ERR,"tradeserial.out_balance[%lf]",tradeserial.out_balance);
		*pRetCode=E_AMT_EXCEED_MAX;
		goto L_RETU;
	}
	// 增加发行新卡时的门禁名单表检查
	ret = CheckNewCardHook(&tCustomer, tCard.card_id);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	//返回卡号\密码\显示卡号\客户类型\图书证号\有效截至日期
	out_pack->lvol0 = (int)h_temp_Card_id;						//交易卡号
	out_pack->lvol1 = tCustomer.cut_type;						//客户类别
	out_pack->lvol5 = tCustomer.fee_type;						//收费类别
	des2src(out_pack->scust_no,h_showcardid);					//显示卡号
	des2src(out_pack->scust_no2,tCustomer.classdept_no);			//部门号
	des2src(out_pack->scust_auth,tCustomer.stuemp_no);			//学号
	des2src(out_pack->scust_auth2,tCustomer.man_id);			//身份证号
	des2src(out_pack->sname,tCustomer.cut_name);				//客户姓名
	des2src(out_pack->sname2,tCustomer.lib_cardid);				//图书证号
	des2src(out_pack->sstatus0,tCustomer.sex);					//性别
	des2src(out_pack->sopen_emp,h_password);					//卡密码
	des2src(out_pack->sdate0,card_endtime);					//有效截至日期

	out_pack->damt2=tradeserial.out_balance;					//出卡值
	out_pack->lserial1=tradeserial.serial_no;						//流水号
	// add by 汤成 2005-8-8
	// 增加向名单表写入记录
	ret = InsertToBlkList((int)h_temp_Card_id,CHCARD_BLACKLIST);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
  L_RETU:
	return -1;
}
Beispiel #7
0
int F847230(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret;
	char sysdate[9] = "";
	char systime[7] = "";
	char db_date[9] = "";
	char db_time[7] = "";
	char volume[13] = "";
	int auth_card_id = 0;
	T_t_pif_oper_authcard tAuthCard;
	T_t_tif_tradeserial tSerial;
	T_t_pif_operator tOper;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	double uni_no = 0.0;


	memset(&tAuthCard,0,sizeof tAuthCard);
	memset(&tSerial,0,sizeof tSerial);
	memset(&aPack,0,sizeof aPack);

	ResetNormalCPack(&aPack,0,1);

	auth_card_id = rPack->lvol0;
	if(auth_card_id <= 0)
	{
		*pRetCode = E_INPUT_CARDNO;
		goto L_RETU;
	}

	
	if(strlen(rPack->scust_limit) == 0)
	{
		*pRetCode = E_INPUT_OPER_NULL;
		goto L_RETU;
	}

	
	ret = DB_t_pif_oper_authcard_read_by_card_id(auth_card_id,&tAuthCard);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_AUTHCARD_NOT_EXISTS;
		else
			*pRetCode = E_DB_OPER_AUTHCARD_R;
		goto L_RETU;
	}

	if(tAuthCard.status == AUTHCARD_STATUS_CANCEL)
	{
		writelog(LOG_ERR,"auth card has been cancel ,card id[%d]",tAuthCard.card_id);
		*pRetCode = E_AUTHCARD_HAS_CANCEL;
		goto L_RETU;
	}
	
	memset(&tOper,0,sizeof tOper);
	ret = DB_t_pif_operator_read_by_oper_code(tAuthCard.oper_code,&tOper);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
		{
			writelog(LOG_ERR,"operator does not exists, oper [%s]",tAuthCard.oper_code);
			*pRetCode = E_DB_OPERATOR_N;
		}
		else
			*pRetCode = E_DB_OPERATOR_R;
		goto L_RETU;
	}
	if(strcmp(tOper.status,OPERATOR_LOGOUT) == 0)
	{
		writelog(LOG_ERR,"operator [%s] has been logout ",tAuthCard.oper_code);
		*pRetCode = E_OPERLOGON_UNREG;
		goto L_RETU;
	}

	ret=chk_oper_pwd(tAuthCard.oper_code,rPack->semp_pwd);
	if(ret)
	{
		writelog(LOG_ERR,"operator password error, operator [%s]",tAuthCard.oper_code);
		if(E_OPER_NOT_EXIST==ret)
			*pRetCode=E_AUTH_OPER_NOT_EXIST;
		else if(E_PASSWORD_WRONG==ret)
			*pRetCode=E_AUTH_OPER_PWD;
		else
			*pRetCode=ret;
		goto L_RETU;
	}
	

	tAuthCard.status = AUTHCARD_STATUS_NORMAL;

	ret = DB_t_pif_oper_authcard_update_by_card_id(tAuthCard.card_id,&tAuthCard);
	if(ret)
	{
		writelog(LOG_ERR,"update operator auth card information error, card id[%d]",tAuthCard.card_id);
		*pRetCode = E_DB_OPER_AUTHCARD_U;
		goto L_RETU;
	}
	// 插入黑名单表
	ret = InsertToBlkList(auth_card_id,DELETE_BLACKLIST);
	if(ret)
	{
		writelog(LOG_ERR,"insert into black list error, card id[%d]",auth_card_id);
		*pRetCode = ret;
		goto L_RETU;
	}
	
	// 生成流水
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&uni_no);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	tSerial.serial_no = D2I(uni_no);

	getsysdate(sysdate);
	getsystime(systime);

	tSerial.card_id = tAuthCard.card_id;
	tSerial.serial_state = SERISTAT_NONEEDDEBT;
	tSerial.serial_type = TXCODE_UNLOSS_AUTHCARD;
	des2src(tSerial.operate_date,sysdate);
	des2src(tSerial.operate_time,systime);
	des2src(tSerial.enteract_date,sysdate);
	des2src(tSerial.enteract_time,systime);
	des2src(tSerial.collect_date,sysdate);
	des2src(tSerial.collect_time,systime);
	des2src(tSerial.oper_code,rPack->scust_limit);
	
	ret = DB_t_tif_tradeserial_add(&tSerial);
	if(ret)
	{
		if(DB_REPEAT == ret)
		{
			writelog(LOG_ERR,"记录流水表失败!");
			*pRetCode = E_DB_TRADESERIAL_E;
		}
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	writelog(LOG_DEBUG,"解挂授权卡成功,操作员[%s]交易卡号[%d]流水号[%d]"
		,tAuthCard.oper_code,tAuthCard.card_id,tSerial.serial_no);

	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_SSERIAL0,0);
	get_datetime_from_db(db_date,db_time);
	out_pack->lvol0 = auth_card_id;
	memcpy(volume,db_date+2,6);
	memcpy(volume+6,db_time,6);
	des2src(out_pack->sserial0,volume);
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;		
}
Beispiel #8
0
int F240002(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	double unique=0;
	int temp_serial_no=0;
	char logicdate[11]="";
	char buffer[16]="";
	int i=0;

	double trans_amt=0.0;
	char sMsg[255]="";
	char sDebugMsg[255]="";

	char sMaxCardBalance[20]="";
	double dMaxCardBalance=0;
	T_t_aif_account	tAccount;		//帐户表
	T_t_cif_customer	tCustomer;
	T_t_pif_spefee 	tSpeFee;
	T_t_tif_tradeserial  tradeserial;		//卡操作流水表
	T_t_pif_card		card;
	InAcc	IA;

	memset(&tSpeFee,0,sizeof(tSpeFee));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&IA,0,sizeof(IA));

	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&card,0,sizeof(card));


	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);


	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_DAMT0,F_DAMT1,F_DAMT2,F_LVOL1,F_LVOL2,F_SBANK_CODE,F_SEMP_NO,0);


	//memset(&tradeserial_bak,0,sizeof(tradeserial_bak));

	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=E_TRANS_UNKNOW_ERROR;
		writelog(LOG_ERR,"GetLogicDate error,errcode=[%d]",ret);
		goto L_RETU;
	}

	//判断设备是否登陆
	if(0!=device_login_yes_or_no(atoi(rPack->sorder2)))
	{
		*pRetCode=E_TRANS_TERM_NOLOGIN;
		writelog(LOG_ERR,"Device don't login");
		goto L_RETU;
	}
	//判断是否处于日终结算状态
 	ret=GetParameter(GLOBE_FLAG_BALANCE,buffer);
	if(ret)
	{
		*pRetCode=E_TRANS_UNKNOW_ERROR;
		writelog(LOG_ERR,"GetParameter error,errcode=[%d]",ret);
		goto L_RETU;
	}
	else if(strncmp(buffer,"0",1)!=0)
	{
		*pRetCode=E_TRANS_BANK_SERVICE_NOEXIT;
		writelog(LOG_ERR,"System is balance now!");
		goto L_RETU;
	}

	ret=DB_t_pif_card_read_by_card_id(atoi(rPack->sserial0),&card);
	if(ret)
	{
		*pRetCode=E_TRANS_SCHACC_NOEXIT;
		writelog(LOG_ERR,"Create serial_no error,error code=[%d]",ret);
		goto L_RETU;
	}

	if(strncmp(card.state_id,CARDSTAT_LOGOUT,4)==0)
	{
		*pRetCode=E_TRANS_SCHACC_DESTORY;
		writelog(LOG_ERR,"card.state_id=[%d]",card.card_id);
		goto L_RETU;
	}

	if(STATE_TRUE==card.state_id[CARDSTAT_TYPE_LOST])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_TRANS_SCHCARD_LOSTING;
		writelog(LOG_ERR,"card_state=[%s]",card.state_id);
		goto L_RETU;
	}

	if(STATE_TRUE==card.state_id[CARDSTAT_TYPE_FREEZE])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_TRANS_SCHCARD_FREEZE;
		writelog(LOG_ERR,"card_state=[%s]",card.state_id);
		goto L_RETU;
	}
	if(STATE_TRUE==card.state_id[CARDSTAT_TYPE_WFAIL])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_TRANS_SCHCARD_WFAIL;
		writelog(LOG_ERR,"card_state=[%s]",card.state_id);
		goto L_RETU;
	}

	//转账不允许转小数金额
	if((rPack->lvol5)%100>0)
	{
		*pRetCode=E_TRANS_TRANSMONEY_OUTRANGE;
		writelog(LOG_ERR,"Trans money is not a integer!,transmoney=[%f]",rPack->lvol5/100.0);
		goto L_RETU;
	}

	//开始填充流水数据
	//流水号

	ret=getNewUniqNo(KEYTYPE_TRADESERIAL, &unique);
	if(ret)
	{
		*pRetCode=E_TRANS_UNKNOW_ERROR;
		writelog(LOG_ERR,"Create serial_no error,error code=[%d]",ret);
		goto L_RETU;
	}


	tradeserial.serial_no=D2I(unique);
	//记录流水号,作为冲正使用
	temp_serial_no=tradeserial.serial_no;

	tradeserial.other_seri_no=rPack->lvol0;	//上传端流水号
	tradeserial.serial_type=TXCODE_BANK_SCHOOL;	//交易代码
	tradeserial.serial_state=SERISTAT_NODEBT;	//流水状态
	tradeserial.card_id=atoi(rPack->sserial0);
	tradeserial.purse_id=0;
	tradeserial.in_balance=double((rPack->lvol6)/100.00);	//入卡金额
	tradeserial.out_balance=tradeserial.in_balance;			//出卡金额
	tradeserial.trade_count=rPack->lvol1+1;				//当前卡中交易次数

	ret=get_datetime_from_db(tradeserial.operate_date,tradeserial.operate_time);
	if(ret)
	{
		writelog(LOG_ERR,"get_datetime_from_db error,error code=[%d]",ret);
		getsysdate(tradeserial.operate_date);
		getsystime(tradeserial.operate_time);
	}
	Strncpy_t(tradeserial.collect_date,tradeserial.operate_date,sizeof(tradeserial.collect_date));	//采集日期
	Strncpy_t(tradeserial.collect_time,tradeserial.operate_time,sizeof(tradeserial.collect_time));	//采集时间
	Strncpy_t(tradeserial.enteract_date,logicdate,sizeof(tradeserial.enteract_date));	//入帐日期
	Strncpy_t(tradeserial.enteract_time,tradeserial.operate_time,sizeof(tradeserial.enteract_time));	//入帐时间
	tradeserial.maindevice_id=GetTransferSystemId();		//子系统号码
	tradeserial.device_id=atoi(rPack->sorder2);			//终端ID
	tradeserial.trade_fee=(rPack->lvol5)/100.0;	//转帐金额
	Strncpy_t(tradeserial.b_act_id,rPack->scust_auth,sizeof(tradeserial.b_act_id));
	tradeserial.sys_id=rPack->lvol2;						//表示银行
	tradeserial.condition_id=SELF_TRANS;						//自动/自助转帐标识
	tradeserial.customer_id=card.cosumer_id;
	Strncpy_t(tradeserial.oper_code,OPER_SYSTEM_KEY,sizeof(tradeserial.oper_code));	//操作员代码

	//判断转帐金额是否超出钱包最大限额
	ret=DB_t_aif_account_read_by_card_id_and_purse_id(card.card_id, PURSE_NO_ONE,&tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_aif_account_read_by_card_id_and_purse_id ret[%d]card_id[%d]",ret,card.card_id);
		if(DB_NOTFOUND==ret)
		{
			*pRetCode=E_TRANS_SCHACC_NOEXIT;
			goto L_RETU;
		}
		else
		{
			*pRetCode=E_TRANS_UNKNOW_ERROR;
			goto L_RETU;
		}
	}

	ret=GetParameter(GLOBE_MAXCARDBALANCE,sMaxCardBalance);
	if(ret)
	{
		writelog(LOG_ERR,"GetParameter GLOBE_MAXCARDBALANCE error,errcode=[%d]",ret);
		*pRetCode=E_TRANS_UNKNOW_ERROR;
		goto L_RETU;
	}
	dMaxCardBalance=atof(sMaxCardBalance);

	if(amtcmp(tAccount.cur_bala+tradeserial.trade_fee,dMaxCardBalance)>0)
	{
		*pRetCode=E_TRANS_TRANSMONEY_OUTRANGE;
		goto L_RETU;
	}
	//读取客户收费类别字段
	ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(card.cosumer_id, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",card.cosumer_id);
		if(DB_NOTFOUND==ret)
		{
			*pRetCode=E_TRANS_UNKNOW_ERROR;
			goto L_RETU;
		}
		else
		{
			*pRetCode=E_TRANS_UNKNOW_ERROR;
			goto L_RETU;
		}
	}

	if(0==tCustomer.fee_type)
	{
		ret=DB_t_pif_spefee_read_by_dept_code_and_cut_type(tCustomer.classdept_no, tCustomer.cut_type,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.fee_type=tCustomer.cut_type;
			}
			else
			{
				DB_t_cif_customer_free_lock_cur();
				writelog(LOG_ERR,"DB_t_pif_spefee_read_by_dept_code_and_cut_type error,errcode=[%d]",ret);
				*pRetCode=E_TRANS_UNKNOW_ERROR;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.fee_type=tSpeFee.fee_type;
		}
	}
	DB_t_cif_customer_free_lock_cur();
	//记录流水数据,用于提供正确的流水号,以及银行业务不成功供查询
	ret=DB_t_tif_tradeserial_add(&tradeserial);
	if(ret)
	{
		*pRetCode=E_TRANS_UNKNOW_ERROR;
		writelog(LOG_ERR,"Insert t_tif_tradeserial table error,error code=[%d]",ret);
		goto L_RETU;
	}

	ret=db_commit();
	if(ret)
	{
		*pRetCode=E_DB_COMMIT;
		writelog(LOG_ERR,"db_commit error,error code=[%d]",ret);
		goto L_RETU;

	}
	//填写入账结构,问问闻剑
	memset(&IA,0,sizeof(IA));
	des2src(IA.sArrInActno[0],tAccount.account_id);			//贷方帐户,持卡人账户
	des2src(IA.sArrInActno[2],rPack->sstation0);				//借方帐号,由前置机上传

	switch (rPack->lvol3)
	{
		case 4:
			IA.iArrInFeeSwitch[1] = 1;
			break;
		case 5:
			IA.iArrInFeeSwitch[1] = 0;
			break;
		default:
			break;
	}
	
	IA.iCardNo=card.card_id;
	IA.iFeeType=tCustomer.fee_type;
	IA.dArrInAmt[0]=tradeserial.trade_fee;

	writelog(LOG_ERR,"借方帐号=[%d]",atoi(rPack->sstation0));
	
	ret=process(&IA,&tradeserial);
	if(ret)
	{
		writelog(LOG_ERR,"process err,errcode[%d]",ret);
		*pRetCode=E_TRANS_UNKNOW_ERROR;
		goto L_RETU;
	}

	sprintf(sDebugMsg,"流水号:%d ",IA.iSerialNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		switch(IA.iArrOutTxType[i])
		{
			case TXTYPE_TOLL_DEPOSIT:
			case TXTYPE_DEDUCT_DEPOSIT:
			case TXTYPE_RETURN_DEPOSIT:
				tradeserial.deposit_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_PRE_TOLL_BOARD:
			case TXTYPE_TOLL_BOARD:
			case TXTYPE_DEDUCT_BOARD:
			case TXTYPE_RETURN_BOARD:
			case TXTYPE_BANK_PRE_TOLL_BOARD:
				tradeserial.boardfee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CHARGE:
				tradeserial.in_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_BANK_TRANSFER:
				trans_amt=IA.dArrOutAmt[i];
				break;
			default:
				break;
		}
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(sDebugMsg,sMsg);
		}
	}


	sprintf(sMsg,"充值前卡余额:%.2lf 转帐后卡余额:%.2lf ",IA.dInCardBala,IA.dOutCardBala);
    	strcat(sDebugMsg,sMsg);
	writelog(LOG_DEBUG,sDebugMsg);

	out_pack->damt0=tradeserial.out_balance;
	out_pack->damt1=tradeserial.trade_fee;
	out_pack->damt2=tradeserial.boardfee;
	out_pack->lvol1=tradeserial.serial_no;
	out_pack->lvol2=D2I(tradeserial.out_balance*100.0);
	des2src(out_pack->semp_no, tradeserial.operate_date);
	des2src(out_pack->sbank_code, tradeserial.operate_time);
	PutRow(handle,out_pack,pRetCode,szMsg);

	//业务结束后,回滚事务
	ret=db_rollback();
	if(ret)
	{
		*pRetCode=E_DB_ROLLBACK;
		writelog(LOG_ERR,"db_rollback error,error code=[%d]",ret);
		goto L_RETU;
	}
	
	return 0;
	
L_RETU:
	return -1;
}
Beispiel #9
0
int F847226(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret;
	int card_id;
	char oper_code[11] = "";
	char sysdate[9] = "";
	char systime[7] = "";
	char work_key[51] = "";
	T_t_pif_operator tOper;
	T_t_pif_oper_authcard tAuthCard;
	T_t_tif_tradeserial tSerial;
	double uni_no = 0.0;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	memset(&tOper,0,sizeof tOper);
	memset(&tAuthCard,0,sizeof tAuthCard);
	memset(&tSerial,0,sizeof tSerial);
	memset(&aPack,0,sizeof aPack);

	ResetNormalCPack(&aPack,0,1);

	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_LVOL1,F_SCUST_LIMIT,F_SCUST_LIMIT2,F_SDATE2,F_SBANK_ACC,0);

	des2src(oper_code,rPack->sname2);
	if(strlen(oper_code) == 0)
	{
		*pRetCode = E_OPER_NOT_EXIST;
		goto L_RETU;
	}

	if(strlen(rPack->scust_limit) == 0)
	{
		*pRetCode = E_INPUT_OPER_NULL;
		goto L_RETU;
	}

	
	if((ret = IsInvalidDateTime(rPack->sdate2,"YYYYMMDD")))
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	
	ret = DB_t_pif_operator_read_by_oper_code(oper_code,&tOper);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_OPER_NOT_EXIST;
		else
			*pRetCode = E_DB_OPERATOR_R;
		goto L_RETU;
	}

	if(strcmp(OPERATOR_LOGOUT,tOper.status) == 0)
	{
		writelog(LOG_ERR,"操作员[%s]已注销",oper_code);
		*pRetCode = E_OPERLOGON_UNREG;
		goto L_RETU;
	}
	//todo:判断如果该操作员持有该卡已经发行过,那么系统允许重复发行,但是不计流水
	//todo:用于解决操作员发行卡失败后,必须回收卡才能继续处理的问题
	ret=is_already_publish_authcard(rPack->sname,oper_code,&card_id);
	if(!ret)
	{
		//writelog(LOG_ERR,"physical_no=[%s],oper_code=[%s],card_id=[%d]",rPack->sname,oper_code,card_id);
		ret = DB_t_pif_oper_authcard_read_by_card_id(card_id,&tAuthCard);
		if(ret)
		{
			if(DB_NOTFOUND == ret)
				*pRetCode = E_AUTHCARD_NOT_EXISTS;
			else
				*pRetCode = E_DB_OPER_AUTHCARD_R;
			goto L_RETU;
		}
		out_pack->lvol0 = tAuthCard.card_id;
		out_pack->lvol1 = tAuthCard.privilege;
		des2src(out_pack->sdate2,tAuthCard.expired_date);
		des2src(out_pack->scust_limit,tAuthCard.oper_code);
		des2src(out_pack->sbank_acc,work_key);
		des2src(out_pack->scust_limit2,tOper.oper_name);
		PutRow(handle,out_pack,pRetCode,szMsg);
		return 0;
	}

	if((ret = is_oper_has_authcard(oper_code)))
	{
		if(ret == 1)
			*pRetCode = E_OPER_ALREADY_HAS_AUTHCARD;
		else
			*pRetCode = ret;
		goto L_RETU;
	}
	ret=is_physical_no_in_use(rPack->sname);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	ret=GetParameter(GLOBE_999_DEVAUTHKEY,work_key);
	if( ret)
	{
		*pRetCode= ret;
		goto L_RETU;
	}

	ret = getNewUniqNo(KEYTYPE_CARD_ID,&uni_no);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	tAuthCard.card_id = D2I(uni_no);

	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&uni_no);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	tSerial.serial_no = D2I(uni_no);

	getsysdate(sysdate);
	getsystime(systime);

	des2src(tAuthCard.issue_date,sysdate);
	des2src(tAuthCard.issue_time,systime);
	des2src(tAuthCard.oper_code,oper_code);
	des2src(tAuthCard.card_phyid,rPack->sname);
	des2src(tAuthCard.expired_date,rPack->sdate2);
	tAuthCard.privilege = rPack->lvol0;
	tAuthCard.status = AUTHCARD_STATUS_NORMAL;
	// TODO : 检查物理卡号是否已经存在
	ret = DB_t_pif_oper_authcard_add(&tAuthCard);
	if(ret)
	{
		if(DB_REPEAT == ret)
		{
			writelog(LOG_ERR,"授权卡交易卡号已存在[%d]",tAuthCard.card_id);
			*pRetCode = E_DB_OPER_AUTHCARD_E;
		}
		else
			*pRetCode = E_DB_OPER_AUTHCARD_I;
		goto L_RETU;
	}

	tSerial.card_id = tAuthCard.card_id;
	tSerial.serial_state = SERISTAT_NONEEDDEBT;
	tSerial.serial_type = TXCODE_ISSUE_AUTHCARD;
	des2src(tSerial.operate_date,sysdate);
	des2src(tSerial.operate_time,systime);
	des2src(tSerial.enteract_date,sysdate);
	des2src(tSerial.enteract_time,systime);
	des2src(tSerial.collect_date,sysdate);
	des2src(tSerial.collect_time,systime);
	des2src(tSerial.oper_code,rPack->scust_limit);
	ret = DB_t_tif_tradeserial_add(&tSerial);
	if(ret)
	{
		if(DB_REPEAT == ret)
		{
			writelog(LOG_ERR,"记录流水表失败!");
			*pRetCode = E_DB_TRADESERIAL_E;
		}
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	writelog(LOG_DEBUG,"发行授权卡成功,操作员[%s]交易卡号[%d]流水号[%d]"
		,tAuthCard.oper_code,tAuthCard.card_id,tSerial.serial_no);


	out_pack->lvol0 = tAuthCard.card_id;
	out_pack->lvol1 = tAuthCard.privilege;
	des2src(out_pack->sdate2,tAuthCard.expired_date);
	des2src(out_pack->scust_limit,tAuthCard.oper_code);
	des2src(out_pack->sbank_acc,work_key);
	des2src(out_pack->scust_limit2,tOper.oper_name);
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;		
}
Beispiel #10
0
int F847127(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
    int i=0;
    int ret =0;
    char logicdate[11]="";										//业务日期
    char sysdate[11]="";
    char systime[9]="";
    InAcc	IA;
    char  ia_buf[1024]="";
    double dUniqno = 0;
    char sMsg[256]="";
    T_t_tif_tradeserial tradeserial;
    ST_CPACK aPack;
    ST_PACK *out_pack = &(aPack.pack);

    memset(&tradeserial,0,sizeof(tradeserial));
    memset(&IA,0,sizeof(IA));
    IA.pVoidPointer=ia_buf;
    ResetNormalCPack(&aPack,0,1);

    if(amtcmp(rPack->damt0,0)==0)
    {
        *pRetCode=E_INPUT_AMT_NULL;
        goto L_RETU;
    }
    trim(rPack->sbank_acc);
    trim(rPack->sbank_acc2);
    if(strcmp(rPack->sbank_acc,rPack->sbank_acc2)==0)
    {
        *pRetCode=E_INPUT_2ACTNO_EQ;
        goto L_RETU;
    }
    trim(rPack->scust_limit);
    trim(rPack->scust_limit2);
    trim(rPack->semp_pwd);
    if(strlen(rPack->scust_limit)==0)
    {
        *pRetCode=E_INPUT_OPER_NULL;
        goto L_RETU;
    }
    if(strlen(rPack->scust_limit2)==0)
    {
        *pRetCode=E_INPUT_OPER_NULL;
        goto L_RETU;
    }
    if(strcmp(rPack->scust_limit,rPack->scust_limit2)==0)
    {
        writelog(LOG_ERR,"oper1[%s]oper2[%s]",rPack->scust_limit,rPack->scust_limit2);
        *pRetCode=E_INPUT_2OPER_EQ;
        goto L_RETU;
    }
    ret=chk_oper_pwd(rPack->scust_limit2,rPack->semp_pwd);
    if(ret)
    {
        if(E_OPER_NOT_EXIST==ret)
            *pRetCode=E_INPUT_OPER_EXIST;
        else if(E_PASSWORD_WRONG==ret)
            *pRetCode=E_INPUT_OPER_PWD;
        else
            *pRetCode=ret;
        goto L_RETU;
    }
    getsysdate(sysdate);
    getsystime(systime);
    ret=GetLogicDate(logicdate);							//业务日期
    if(ret)
    {
        *pRetCode=ret;
        goto L_RETU;
    }
    tradeserial.trade_fee = rPack->damt0;						//发生金额
    ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqno);  		//获得最大流水号
    if(ret)
    {
        *pRetCode = ret;
        writelog(LOG_ERR," ERRCODE = [%d]",ret);
        goto L_RETU;
    }

    tradeserial.serial_no = D2I(dUniqno);							//流水号
    tradeserial.other_seri_no = 0;								//上传端流水号
    tradeserial.serial_type  = TXCODE_CARD_DBCR;				//交易码
    tradeserial.serial_state = SERISTAT_DEBT;						//流水状态
    des2src(tradeserial.operate_date,sysdate);					//发生日期
    des2src(tradeserial.operate_time,systime);					//发生时间
    des2src(tradeserial.collect_date,sysdate);						//采集日期
    des2src(tradeserial.collect_time,systime);						//采集时间
    des2src(tradeserial.enteract_date,logicdate);					//处理日期
    des2src(tradeserial.enteract_time,systime);					//处理时间
    tradeserial.maindevice_id = rPack->lvol6;						//上传工作站标识
    tradeserial.in_balance=rPack->damt0;						//入卡值
    tradeserial.trade_count=0;									//交易次数
    des2src(tradeserial.oper_code,rPack->scust_limit);			//操作员代码
    des2src(tradeserial.reserve_1,rPack->scust_limit2);			//错帐操作员代码
    tradeserial.sys_id = 0;										//外部系统标识

    IA.iCardNo=0;
    IA.iFeeType=1;
    IA.dArrInAmt[0]=tradeserial.trade_fee;
    des2src(IA.sArrInActno[0],rPack->sbank_acc);				//借方帐号
    des2src(IA.sArrInActno[1],rPack->sbank_acc2);				//贷方帐号
    IA.iArrInFeeSwitch[0]=rPack->lvol0;
    IA.iArrInFeeSwitch[1]=rPack->lvol1;
    IA.iArrInFeeSwitch[2]=rPack->lvol2;
    IA.iArrInFeeSwitch[3]=rPack->lvol3;
    IA.iArrInFeeSwitch[4]=rPack->lvol4;
    IA.iArrInFeeSwitch[5]=rPack->lvol5;
    ret=process(&IA,&tradeserial);
    if(ret)
    {
        writelog(LOG_ERR,"process ret[%d]",ret);
        *pRetCode=ret;
        goto L_RETU;
    }
    sprintf(out_pack->vsmess,"流水号:%d ",IA.iSerialNo);
    for(i=1; i<=IA.iOutTxTypeCnt; i++)
    {
        if(amtcmp(IA.dArrOutAmt[i],0)!=0)
        {
            sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
            strcat(out_pack->vsmess,sMsg);
        }
    }
    strcat(out_pack->vsmess,(char*)IA.pVoidPointer);
    writelog(LOG_DEBUG,out_pack->vsmess);
    SetCol(handle,0);
    SetCol(handle,F_LSERIAL1,F_DAMT2,F_DAMT3,F_DAMT4,F_VSMESS,0);
    out_pack->lserial1=tradeserial.serial_no;			//流水号
    ret = DB_t_tif_tradeserial_add(&tradeserial);
    if (ret)
    {
        writelog(LOG_ERR,"ret[%d]",ret);
        if(DB_REPEAT==ret)
            *pRetCode = E_DB_TRADESERIAL_E;
        else
            *pRetCode = E_DB_TRADESERIAL_I;
        goto L_RETU;
    }
    PutRow(handle,out_pack,pRetCode,szMsg);
    return 0;
L_RETU:
    return -1;
}
Beispiel #11
0
int F847102(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
  	int ret = 0;
//	char logicdate[11] = "";
//	char enddate[10 + 1] = "";
	int	card_id = 0;
	char	Operator[33+1] = "";
//	int	Cut_id  = 0;
	int	maindevice_id = 0;
	int	device_id = 0;
	char logicdate[11]="";
	char sysdate[11]="";
	char systime[9]="";
	double	dUniqno = 0;
	T_t_pif_cardlossinfo cardlossinfo;
	T_t_tif_black_sheet black_sheet;
	T_t_tif_tradeserial  tradeserial;
       T_t_tif_meslist tMesList;
	T_t_pif_card	tCard;

	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&cardlossinfo,0,sizeof(cardlossinfo));
	memset(&black_sheet,0,sizeof(black_sheet));
	memset(&tMesList,0,sizeof(tMesList));
	memset(&tCard,0,sizeof(tCard));

	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	card_id = rPack->lvol1;													//卡标识
//	Cut_id = rPack->lvol0;													//客户号
	des2src(Operator,rPack->scust_limit);									//操作员号
	maindevice_id = rPack->lvol6;											//上传工作站标识
	device_id = rPack->lvol7;												//采集设备标识

	//	检查客户信息,判断是否可以挂失
	//修改卡标志,置为正常状态
	ret=DB_t_pif_card_read_lock_by_cur_and_card_id(card_id, &tCard);
	if(ret)
	{
		writelog(LOG_ERR,"card_id[%d]",card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_R;
		goto L_RETU;
	}
	if(card_id!=tCard.card_id)
	{
		DB_t_pif_card_free_lock_by_cur();
		writelog(LOG_ERR,"card_id[%d] db card_id[%d]",card_id,tCard.card_id);
		*pRetCode=E_DB_CARD_R;
		goto L_RETU;
	}
	if('2'==tCard.state_id[CARDSTAT_TYPE_REG])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode = E_CARDNO_LOGOUT;
		goto L_RETU;
	}
	if('3'==tCard.state_id[CARDSTAT_TYPE_REG])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode = E_CARDNO_WFAIL;
		goto L_RETU;
	}	
	if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_LOST])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode = E_CARDNO_LOST;
		goto L_RETU;
	}
	tCard.state_id[CARDSTAT_TYPE_LOST]=STATE_TRUE;
	//	修改卡状态为挂失
	ret=DB_t_pif_card_update_lock_by_cur(&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"card_id[%d]",card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_U;
		goto L_RETU;
	}
	DB_t_pif_card_free_lock_by_cur();

	//	插入卡挂失有效期限表
/*
	ret=GetLostCardValiddate(sysdate,enddate);											//获得挂失有效期限
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	cardlossinfo.card_id = card_id;													//卡号
	des2src(cardlossinfo.begin_date,sysdate);											//起始日期
	des2src(cardlossinfo.end_date,enddate);											//截至日期
	des2src(cardlossinfo.operate_date,sysdate);										//操作日期
	des2src(cardlossinfo.operate_time,systime);										//操作时间
	cardlossinfo.state_id=STATE_VALID;												//有效
	ret = DB_t_pif_cardlossinfo_add(&cardlossinfo);
	if (ret)
	{
		*pRetCode = E_DB_CARDLOSSINFO_I;
		writelog(LOG_ERR,"errcode[%d] ",ret);
		goto L_RETU;
	}
*/
	//如果该卡号被冻结,则挂失时对黑名单不处理
	if(STATE_FALSE==tCard.state_id[CARDSTAT_TYPE_FREEZE])
	{
		//	插入黑名单表
		ret=DB_t_tif_black_sheet_del_by_card_id_and_is_ad(tCard.card_id,DELETE_BLACKLIST);
		if(ret)
		{
			if(ret!=DB_NOTFOUND)
			{
				*pRetCode=ret;
				goto L_RETU;
			}
		}
		ret=InsertToBlkList(tCard.card_id,ADD_BLACKLIST);
		if(ret)
		{
			*pRetCode=ret;
			writelog(LOG_ERR,"InsertToBlkList err[%d]",ret);
			goto L_RETU;
		}
		//广播黑名单
		AddXmlItemInt(tMesList.incontent, XML_KEY_CARDID,card_id);
		AddXmlItemInt(tMesList.incontent, XML_KEY_ADDDELSIGN,ADD_BLACKLIST);	//增删标志

		tMesList.funid = 930005;
		tMesList.pfunid = 930003;
		tMesList.max_send_cnt = 10;
		tMesList.level = MESLIST_PRIORITY_REALTIME;
		tMesList.msgtype = MESLIST_TYPE_ORDER;
		ret=AddMsgLst(&tMesList);
		if(ret)
		{
			*pRetCode=ret;
			writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
			goto L_RETU;
		}
	}
	//	准备数据插入交易流水表
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqno);  					//获得最大流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ERRCODE = [%d]",ret);
		goto L_RETU;
	}
	des2src(tradeserial.operate_date,sysdate);											//发生日期
	des2src(tradeserial.operate_time,systime);											//发生时间
	des2src(tradeserial.collect_date,sysdate);												//采集日期
	des2src(tradeserial.collect_time,systime);												//采集时间
	des2src(tradeserial.enteract_date,logicdate);											//处理日期
	des2src(tradeserial.enteract_time,systime);											//处理时间
	tradeserial.serial_no = D2I(dUniqno);										//流水号
	tradeserial.serial_type = TXCODE_CARD_LOSS;								//挂失
	tradeserial.serial_state = SERISTAT_NONEEDDEBT;							//流水状态
	tradeserial.maindevice_id = maindevice_id;									//上传工作站标识
	tradeserial.device_id = device_id;											//采集设备标识
	tradeserial.card_id = card_id;											//交易卡号
	tradeserial.customer_id=tCard.cosumer_id;									//客户号
	des2src(tradeserial.oper_code,Operator);

	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	return 0;
L_RETU:
	return -1;
}
int F847183(TRUSERID *handle, int iRequest, ST_PACK *rPack, int *pRetCode, char *szMsg)
{

	int ret = 0;
	char    	tx_date[8+1] = "";              	//发生日期
//		char    	tx_time[6+1]="";      		//发生时间
	int		cardno = 0;                    	//卡号
	char    	deviceid[8+1] = "";            	//终端机ID
	int		serial_no = 0;                  	//终端机流水号
	int 		flag = 0;
	double 	iSeqNo = 0;
	T_t_tif_tradeserial		tOldTradeserial;	//当日流水表
	T_t_tif_tradeserial		tTradeserial;	//当日流水表
	T_t_tif_tradeserial_his	tTradeserialhis;	//历史流水表
	T_t_tradecode tTradeCode;
	T_t_card tCard;
	char sysdate[11] = "";
	char systime[9] = "";
	char sYear[5] = "";
	char sMonDay[5] = "";
	char logic_date[9] = "";
	int days = 0;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	ST_PACK next_pack;

	ResetNormalCPack(&aPack, 0, 1);
	memset(&tTradeserial, 0, sizeof(tTradeserial));
	memset(&tOldTradeserial, 0, sizeof(tOldTradeserial));
	memset(&tTradeserialhis, 0, sizeof(tTradeserialhis));
	memset(&tTradeCode, 0, sizeof tTradeCode);
	memset(&tCard, 0, sizeof tCard);
	getsysdate(sysdate);
	getsystime(systime);
	des2src(tTradeserial.enteract_time, systime);

	des2src(tx_date, rPack->sbank_pwd);
//		des2src(tx_time,rPack->sbank_code);
	cardno = rPack->lvol0;
	des2src(deviceid, rPack->sbank_pwd2);
	serial_no = rPack->lvol1;
	trim(rPack->scust_limit);
	trim(rPack->scust_limit2);
	trim(rPack->semp_pwd);
	des2src(sYear, tx_date);
	des2src(sMonDay, tx_date + 4);

	if (strlen(rPack->scust_limit) == 0)
	{
		*pRetCode = E_OPER_NOT_EXIST;
		goto L_RETU;
	}
	if (strlen(rPack->scust_limit2) == 0)
	{
		*pRetCode = E_INPUT_AUTH_OPER_NULL;
		goto L_RETU;
	}
	if (strcmp(rPack->scust_limit, rPack->scust_limit2) == 0)
	{
		writelog(LOG_ERR, "oper[%s]auth_oper[%s]", rPack->scust_limit, rPack->scust_limit2);
		*pRetCode = E_OPER_AND_AUTH_OPER_EQ;
		goto L_RETU;
	}
	ret = chk_oper_pwd(rPack->scust_limit2, rPack->semp_pwd);
	if (ret)
	{
		if (E_OPER_NOT_EXIST == ret)
			*pRetCode = E_AUTH_OPER_NOT_EXIST;
		else if (E_PASSWORD_WRONG == ret)
			*pRetCode = E_AUTH_OPER_PWD;
		else
			*pRetCode = ret;
		goto L_RETU;
	}
	ret = DB_t_card_read_by_cardno(cardno, &tCard);
	if (ret)
	{
		if (DB_NOTFOUND == ret)
			*pRetCode = E_CARDNO_NOT_EXIST;
		else
			*pRetCode = E_DB_CARD_R;
		goto L_RETU;
	}
	if (tCard.cardattr[CARDSTAT_TYPE_REG] == '2')
	{
		writelog(LOG_ERR, "冲正交易卡号已注销cardid[%d]", tCard.cardno);
		*pRetCode = E_ACTNO_LOGOUT;
		goto L_RETU;
	}
	//查询当前流水表
	ret = DB_t_tif_tradeserial_read_lock_by_c4_and_operate_date_and_serial_no_and_cardno(tx_date, serial_no, cardno, &tOldTradeserial);
	if (ret)
	{
		writelog(LOG_ERR, "tx_date[%s]serial_no[%d]ret[%d]", tx_date, serial_no, ret);
		if (DB_NOTFOUND != ret)
		{
			*pRetCode = E_DB_TRADESERIAL_R;
			goto L_RETU;
		}
	}
	else
	{
		flag = 1;
		memcpy(&tTradeserial, &tOldTradeserial, sizeof(tTradeserial));
		tTradeserial.other_seri_no = tOldTradeserial.serial_no;					//上传端流水号
		tOldTradeserial.serial_state = SERISTAT_RUSH;				//冲正
		ret = DB_t_tif_tradeserial_update_lock_by_c4(&tOldTradeserial);
		if (ret)
		{
			*pRetCode = E_DB_TRADESERIAL_U;
			writelog(LOG_ERR, "DB_t_tif_tradeserial_update_lock_by_c4[%d]", ret);
			goto L_RETU;
		}
		DB_t_tif_tradeserial_free_lock_c4();
	}
	if (!flag)
	{
		//查询历史流水表
		ret = DB_t_tif_tradeserial_his_read_lock_by_c0_and_trans_year_and_trans_mon_day_and_serial_no_and_cardno(sYear, sMonDay, serial_no, cardno, &tTradeserialhis);
		if (ret)
		{
			writelog(LOG_ERR, "year[%s]date[%d]serialno[%d]ret[%d]", sYear, sMonDay, serial_no, ret);
			if (DB_NOTFOUND == ret)
			{
				*pRetCode = E_SERIALNO_NOT_EXIST;
				goto L_RETU;
			}
			else
			{
				*pRetCode = E_DB_TRADESERIAL_R;
				goto L_RETU;
			}
		}
		tTradeserial.other_seri_no = tTradeserialhis.serial_no;						//上传端流水号
		tTradeserial.serial_state = tTradeserialhis.serial_state;						//流水状态
		tTradeserial.tmark = tTradeserialhis.tmark;								//999交易标记
		tTradeserial.maindeviceid = tTradeserialhis.maindeviceid;							//上传工作站标识(前置机注册号)
		tTradeserial.sys_id = tTradeserialhis.sys_id;
		tTradeserial.comu_ver = tTradeserialhis.comu_ver;							//通信版本号
		// add by 汤成 2007-10-31
		tTradeserial.deviceid = tTradeserialhis.deviceid;
		des2src(tTradeserial.devphyid, tTradeserialhis.devphyid);				//物理设备ID
		des2src(tTradeserial.dev_auth, tTradeserialhis.dev_auth);					//终端设备授权号
		des2src(tTradeserial.crc, tTradeserialhis.crc);								//CRC校验
		tTradeserial.cardno = tTradeserialhis.cardno;								//交易卡号
		tTradeserial.purseno = tTradeserialhis.purseno;							//消费钱包号
		tTradeserial.in_balance = tTradeserialhis.in_balance;						//入卡金额
		tTradeserial.out_balance = tTradeserialhis.out_balance;					//出卡金额
		tTradeserial.trade_fee = tTradeserialhis.trade_fee;						//本次消费金额
		tTradeserial.trade_count = tTradeserialhis.trade_count;							//当前卡中帐户消费次数(累计使用次数)
		tTradeserial.serial_type = tTradeserialhis.serial_type;							//交易代码
		tTradeserial.managefee = tTradeserialhis.managefee	;						//搭伙费
		des2src(tTradeserial.operate_date, tTradeserialhis.operate_date);					//发生日期(格式化输入的日期)
		des2src(tTradeserial.operate_time, tTradeserialhis.operate_time);					//发生时间(格式化输入的时间)
		tTradeserial.condition_id = tTradeserialhis.condition_id;							// 收费科目
		tTradeserialhis.serial_state = SERISTAT_RUSH;				//冲正
		// 保存被冲正交易的操作员号
		des2src(tTradeserialhis.opercode, tTradeserialhis.opercode);
		ret = DB_t_tif_tradeserial_his_update_lock_by_c0(&tTradeserialhis);
		if (ret)
		{
			*pRetCode = E_DB_TRADESERIAL_U;
			writelog(LOG_ERR, "DB_t_tif_tradeserial_update_lock_by_c4[%d]", ret);
			goto L_RETU;
		}
		DB_t_tif_tradeserial_his_free_lock_by_c0();
	}
	if (tTradeserial.cardno != cardno)
	{
		writelog(LOG_ERR, "流水中卡号不符cardid[%d]serial[%d]", cardno, tTradeserial.cardno);
		*pRetCode = E_SERIALNO_NOT_EXIST;
		goto L_RETU;
	}
	if (tTradeserial.serial_state == SERISTAT_RUSH)
	{
		*pRetCode = E_TX_SERIAL_CZ;
		goto L_RETU;
	}
	if (tTradeserial.serial_state != SERISTAT_DEBT)
	{
		*pRetCode = E_TX_SERIAL_CANNOT_CZ;
		goto L_RETU;
	}
	if (amtcmp(tTradeserial.trade_fee, 0) == 0)
	{
		*pRetCode = E_TX_SERIAL_CANNOT_CZ;
		strcpy(szMsg,"交易金额有误!");
		goto L_RETU;
	}

	ret = DB_t_tradecode_read_by_tradecode(tTradeserial.serial_type, &tTradeCode);
	if (ret)
	{
		if (DB_NOTFOUND == ret)
			*pRetCode = E_DB_TRADECODE_N;
		else
			*pRetCode = E_DB_TRADECODE_R;
		goto L_RETU;
	}

	if (tTradeCode.rush_flag != IS_YES)
	{
		*pRetCode = E_TX_SERIAL_CANNOT_CZ;
		strcpy(szMsg,"该交易不能被冲正");
		goto L_RETU;
	}

	ret = GetLogicDate(logic_date);						//业务日期
	if (ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR, "GetLogicDate  err ret[%d]", ret);
		goto L_RETU;
	}
	// 小于 0 , 则不判断
	if (tTradeCode.rush_max_day >= 0)
	{
		ret = DiffDay(logic_date, tTradeserial.enteract_date, &days);
		if (ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		if (days > tTradeCode.rush_max_day)
		{
			writelog(LOG_ERR, "流水入账日期[%s],已超过期限[%d]天",
					 tTradeserial.enteract_date, days);
			*pRetCode = E_TX_SERIAL_CANNOT_CZ;
			strcpy(szMsg, "流水日期已超过可冲正期限!");
			goto L_RETU;
		}
	}

	if (tTradeCode.restrict_oper == IS_YES)
	{
		if (strcmp(rPack->scust_limit, tTradeserial.opercode) != 0)
		{
			strcpy(szMsg, "必须由作此次交易的操作员来冲正");
			*pRetCode = E_TX_SERIAL_CANNOT_CZ;
			goto L_RETU;
		}
	}

	// 保存上传的操作员号
	des2src(tTradeserial.operate_date, sysdate);
	des2src(tTradeserial.operate_time, systime);
	des2src(tTradeserial.collect_date, sysdate);
	des2src(tTradeserial.collect_time, systime);

	des2src(tTradeserial.enteract_date, logic_date);						//业务日期
	des2src(tTradeserial.enteract_time, systime);
	tTradeserial.in_balance = rPack->damt1;
	tTradeserial.trade_fee = -1 * tTradeserial.trade_fee;					//本次消费金额
	tTradeserial.managefee = -1 * tTradeserial.managefee;					//本次消费管理费
	tTradeserial.out_balance = tTradeserial.in_balance - tTradeserial.trade_fee;
	if (rPack->lvol10 > 0)
		tTradeserial.trade_count = rPack->lvol10 + 1;
	tTradeserial.maindeviceid = rPack->lvol6;
	// 上传的操作员号
	des2src(tTradeserial.opercode, rPack->scust_limit);
	tTradeserial.reviseserial_no = tTradeserial.other_seri_no;

	//取流水号,从帐处理
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL, &iSeqNo);
	if (ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR, "getNewUniqNo err[%d]", ret);
		goto L_RETU;
	}
	tTradeserial.serial_no = iSeqNo;
	//######################################################
	//入账处理
	switch (tTradeserial.serial_type)
	{
	case 930031:
		// 交易冲正
		if (amtcmp(tTradeserial.trade_fee, 0) == 0)
			break;
		tTradeserial.serial_type = TXCODE_TX_REVEAL;
		ret = process930031(&tTradeserial);
		if (ret)
		{
			//业务处理失败处理
			*pRetCode = ret;
			goto L_RETU;
		}
		break;
	case 930034:
		// 充值冲正
		if (amtcmp(tTradeserial.trade_fee, 0) == 0)
			break;
		tTradeserial.serial_type = TXCODE_TX_REVEAL;
		ret = process930034(&tTradeserial);
		if (ret)
		{
			//业务处理失败处理
			*pRetCode = ret;
			goto L_RETU;
		}
		break;
	case 930036:
		// 搭伙费冲正
		if (amtcmp(tTradeserial.trade_fee, 0) == 0)
			break;
		tTradeserial.serial_type = TXCODE_TX_REVEAL;
		ret = process930036(&tTradeserial);
		if (ret)
		{
			//业务处理失败处理
			*pRetCode = ret;
			goto L_RETU;
		}
		break;
	case 847106: // 现金充值冲正
		memset(&next_pack,0,sizeof next_pack);
		tTradeserial.serial_type = TXCODE_SAVING_CASH;
		ret = do_flush_847106(&tTradeserial,&tCard);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		break;
	default:
		*pRetCode = E_TXCODE_NOT_EXIST;	//交易码错误
		goto L_RETU;
	}
	//######################################################
	//添加交易流水
	tTradeserial.serial_state = SERISTAT_DEBT;
	ret = DB_t_tif_tradeserial_add(&tTradeserial);
	if (ret)
	{
		writelog(LOG_ERR, "DB_t_tif_tradeserial_add ret[%d]", ret);
		if (DB_REPEAT == ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	if (amtcmp(tTradeserial.out_balance, 0) < 0)
	{
		*pRetCode = E_ENTER_ACCOUNT;
		goto L_RETU;
	}
	SetCol(handle, 0);
	SetCol(handle, F_LSERIAL1, F_DAMT2, F_DAMT3, F_VSMESS, 0);
	out_pack->lserial1 = tTradeserial.serial_no;
	out_pack->damt2 = tTradeserial.out_balance;
	out_pack->damt3 = -tTradeserial.trade_fee;
	sprintf(out_pack->vsmess, "流水号:%d 冲正金额:%.2lf元 冲正前卡余额:%.2lf元 卡当前余额:%.2lf元", tTradeserial.serial_no, -tTradeserial.trade_fee, tTradeserial.in_balance, tTradeserial.out_balance);
	writelog(LOG_DEBUG, out_pack->vsmess);
	PutRow(handle, out_pack, pRetCode, szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #13
0
int F847123(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	int card_id=0;
	char sSeedKey[17] = "";							//种子密钥
	char sPwd[7] = "";							//卡密码
	char logicdate[11]="";
	char sysdate[11]="";
	char systime[9]="";
	double dSerialno=0;
	T_t_pif_card tCard;
	T_t_cif_customer tCustomer;
	T_t_pif_spefee 	tSpeFee;
	T_t_aif_account  tAccount;
	T_t_tif_tradeserial tTradeserial;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	memset(&tCard,0,sizeof(tCard));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tSpeFee,0,sizeof(tSpeFee));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&tTradeserial,0,sizeof(tTradeserial));
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL10,F_LVOL5,
				F_SCUST_NO,	F_SCUST_NO2,F_SCUST_AUTH,F_SCUST_AUTH2,
				F_SDATE0,F_SNAME,F_SNAME2,
				F_SOPEN_EMP,F_SSTATUS0,
				F_DAMT2,F_LSERIAL1,F_VSMESS,0);

	card_id=rPack->lvol0;
	if(card_id<1)
	{
		*pRetCode=E_INPUT_CARDNO;
		goto L_RETU;
	}
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	//判断卡状态是否为写卡未成功状态
	ret=DB_t_pif_card_read_lock_by_cur_and_card_id(card_id, &tCard);
	if(ret)
	{
		writelog(LOG_ERR,"card_id[%d]",card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_R;
		goto L_RETU;
	}
	if(card_id!=tCard.card_id)
	{
		writelog(LOG_ERR,"card_id[%d] db card_id[%d]",card_id,tCard.card_id);
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_DB_CARD_R;
		goto L_RETU;
	}
	if('3'!=tCard.state_id[CARDSTAT_TYPE_REG])
	{
		DB_t_pif_card_free_lock_by_cur();
		if('2'==tCard.state_id[CARDSTAT_TYPE_REG])
			*pRetCode=E_CARDNO_LOGOUT;
		else if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_LOST])
			*pRetCode=E_CARDNO_LOST;
		else if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_FREEZE])
			*pRetCode=E_CARDNO_FREEZE;
		else if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_WFAIL])
			*pRetCode=E_CARDNO_WFAIL;
		else if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_REG])
			*pRetCode=E_OLDCARDINFO_NOSAVE;
		goto L_RETU;
	}
	trim(rPack->sbank_acc);
	trim(rPack->scust_no);
	trim(rPack->sdate0);
	if(strlen(rPack->scust_no))
	{
		ret=IsExistShowCardNo(rPack->scust_no);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
	}
	if(strcmp(tCard.physical_no,rPack->sbank_acc)!=0)
	{
		ret=IsExistCardByPhyCardNo(rPack->sbank_acc);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
	}
	ret=IsInvalidDateTime(rPack->sdate0,"YYYYMMDD");
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}

	des2src(tCard.physical_no, rPack->sbank_acc);		//物理卡号
	des2src(tCard.showid,rPack->scust_no);				//显示卡号
	des2src(tCard.end_time,rPack->sdate0);				//到期日期

	ret=DB_t_pif_card_update_lock_by_cur(&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"card_id[%d]",card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_U;
		goto L_RETU;
	}
	DB_t_pif_card_free_lock_by_cur();

	memcpy(sSeedKey,STATIC_SEED_KEY,16);			//读种子密钥
	EncodePwd(sSeedKey,sPwd,tCard.password,1);		//卡密码

	//注销帐户
	ret=DB_t_aif_account_read_by_card_id_and_purse_id(card_id,PURSE_NO_ONE, &tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_aif_account_read_by_card_id_and_purse_id ret[%d]card_id[%d]",ret,card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_ACTNO_NOT_EXIST;
		else
			*pRetCode= E_DB_ACCOUNT_R;
		goto L_RETU;
	}
	if(tAccount.consume_count<1)
	{
		*pRetCode=E_CARD_TXCNT;
		goto L_RETU;
	}
	if(amtcmp(tAccount.card_balance,0)<0)
	{
		*pRetCode=E_CARD_BALA;
		goto L_RETU;
	}
	ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(tCard.cosumer_id, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",tCard.cosumer_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode= E_DB_CUSTOMER_R;
		goto L_RETU;
	}
	//得到收费类别
	if(tCustomer.fee_type<1)
	{
		ret=DB_t_pif_spefee_read_by_dept_code_and_cut_type(tCustomer.classdept_no, tCustomer.cut_type,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.fee_type=tCustomer.cut_type;
			}
			else
			{
				DB_t_cif_customer_free_lock_cur();
				*pRetCode=E_DB_SPEFEE_R;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.fee_type=tSpeFee.fee_type;
		}
		//更新客户表的收费类别字段
		ret=DB_t_cif_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode= E_CUSTOMER_NOT_EXIST;
			else
				*pRetCode= E_DB_CUSTOMER_U;
			goto L_RETU;
		}
	}
	DB_t_cif_customer_free_lock_cur();
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialno);  				//获得流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret [%d]",ret);
		goto L_RETU;
	}
	tTradeserial.serial_no = (int)dSerialno;					//流水号
	tTradeserial.other_seri_no = 0;							//上传端流水号
	tTradeserial.serial_type = 847123;						//交易代码;备注:发卡+充值 用一个交易码,即847101; 发卡(不充值)另用一个交易码,即新的发卡程序文件名,从而区分发卡充值与发卡不充值的卡操作信息。
	tTradeserial.serial_state = SERISTAT_DEBT;				//流水状态
	des2src(tTradeserial.operate_date,sysdate);				//发生日期
	des2src(tTradeserial.operate_time,systime);				//发生时间
	des2src(tTradeserial.collect_date,sysdate);				//采集日期
	des2src(tTradeserial.collect_time,systime);				//采集时间
	des2src(tTradeserial.enteract_date,logicdate);				//处理日期
	des2src(tTradeserial.enteract_time,systime);				//处理时间
	des2src(tTradeserial.oper_code , rPack->scust_limit);
	tTradeserial.maindevice_id = rPack->lvol6;				//上传工作站标识
	tTradeserial.device_id = rPack->lvol7;					//采集设备标识
	tTradeserial.card_id = tCard.card_id;						//卡号
	des2src(tTradeserial.showid,tCard.showid);				//显示卡号
	tTradeserial.purse_id = PURSE_NO_ONE;					//钱包号
	tTradeserial.customer_id = tCard.cosumer_id;				//客户标识

	//插入交易流水表
	ret = DB_t_tif_tradeserial_add(&tTradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	out_pack->lvol0 = card_id;									//交易卡号
	out_pack->lvol1 = tCustomer.cut_type;						//客户类别
	out_pack->lvol5 = tCustomer.fee_type;						//收费类别
	des2src(out_pack->scust_no,tCard.showid);					//显示卡号
	des2src(out_pack->scust_no2,tCustomer.classdept_no);			//部门号
	des2src(out_pack->scust_auth,tCustomer.stuemp_no);			//学号
	des2src(out_pack->scust_auth2,tCustomer.man_id);			//身份证号
	des2src(out_pack->sname,tCustomer.cut_name);				//客户姓名
	des2src(out_pack->sname2,tCustomer.lib_cardid);				//图书证号
	des2src(out_pack->sstatus0,tCustomer.sex);					//性别
	des2src(out_pack->sopen_emp,sPwd);						//卡密码
	des2src(out_pack->sdate0,tCard.end_time);					//有效截至日期

	out_pack->damt2=D4U5(tAccount.card_balance,2);			//卡余额
	out_pack->lvol10=tAccount.consume_count;					//消费次数
	out_pack->lserial1=tTradeserial.serial_no;						//流水号

	sprintf(out_pack->vsmess,"流水号:%d 卡号:%d 学工号:%s 姓名:%s 卡余额:%.2lf元",tTradeserial.serial_no,card_id,tCustomer.stuemp_no,tCustomer.cut_name,tAccount.card_balance);
	writelog(LOG_DEBUG,out_pack->vsmess);
	// add by 汤成 2005-8-8
	// 增加向名单表写入记录
	ret = InsertToBlkList(card_id,CHCARD_BLACKLIST);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
int F930032(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg) {
    int ret = 0;						//返回码
    int hi_sign = 0;					//挂失解挂标志
    double h_temp_Serial_no = 0;		//本地流水号
    char logicdate[11]="";
    char sysdate[11]="";
    char systime[9]="";
    int dev_id=0;
    T_t_tif_tradeserial  tradeserial;

    memset(&tradeserial,0,sizeof(tradeserial));
    hi_sign = in_pack->lvol6;												//挂失解挂标志

    ret=chk_dyn_key(in_pack->lcert_code,in_pack->scust_limit2);
    if(ret) {
        *pRetCode = ret;
        goto L_RETU;
    }
    getsysdate(sysdate);
    getsystime(systime);
    ret=GetLogicDate(logicdate);												//业务日期
    if(ret) {
        *pRetCode = ret;
        goto L_RETU;
    }
    switch (hi_sign) {
    case 0:
        tradeserial.serial_type = TXCODE_CARD_LOSS;					//挂失
        break;
    case 1:
        tradeserial.serial_type = TXCODE_CARD_COMEBACK_LOSS;			//解挂
        break;
    case 2:
        tradeserial.serial_type = TXCODE_MODIFICATIONPW;				//修改密码
        break;
    default:
        *pRetCode = -1;
        writelog(LOG_ERR,"挂失解挂修改密码标志出错。ERRCODE[%d] ",*pRetCode);
        goto L_RETU;
        break;
    }
    /*	读取设备ID	*/
    ret = GetDevIdByDevPhyId(&dev_id,in_pack->sdate1);
    if (ret) {
        *pRetCode = ret;
        writelog(LOG_ERR,"GetDevIdByDevPhyId err[%d] ",ret);
        goto L_RETU;
    }

    tradeserial.serial_state = SERISTAT_NODEBT;								//流水状态

    ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&h_temp_Serial_no);
    if(ret) {
        *pRetCode = ret;
        writelog(LOG_ERR,"获取最大流水号错误: ERRCODE = [%d]",ret);
        goto L_RETU;
    }
    tradeserial.serial_no = D2I(h_temp_Serial_no);													//流水号

    snprintf(tradeserial.operate_date,9,"20%s",in_pack->spost_code);		//发生日期(格式化输入的日期)
    des2src(tradeserial.operate_time,in_pack->spost_code2);			//发生时间(格式化输入的时间)
    des2src(tradeserial.collect_date,sysdate);												//采集日期
    des2src(tradeserial.collect_time,systime);												//采集时间
    des2src(tradeserial.enteract_date,logicdate);											//处理日期
    des2src(tradeserial.enteract_time,systime);											//处理时间
    tradeserial.other_seri_no = in_pack->lvol4;													//上传端流水号
    tradeserial.serial_state = SERISTAT_DEBT;													//流水状态
    tradeserial.maindeviceid = in_pack->lcert_code;												//上传工作站标识
    tradeserial.deviceid = dev_id;														//采集设备标识
    tradeserial.cardno = in_pack->lvol5;														//卡号
    Strncpy_t(tradeserial.showid,in_pack->sstation0,sizeof(tradeserial.showid));						//显示卡号
    Strncpy_t(tradeserial.oldpwd,in_pack->sstock_code,sizeof(tradeserial.oldpwd));					//原始密码
    Strncpy_t(tradeserial.newpwd,in_pack->sstock_code2,sizeof(tradeserial.newpwd));				//更新密码
    des2src(tradeserial.opercode,"system");

    ret = DB_t_tif_tradeserial_add(&tradeserial);
    if (ret) {
        writelog(LOG_ERR,"ret[%d]",ret);
        if(DB_REPEAT==ret)
            *pRetCode = E_DB_TRADESERIAL_E;
        else
            *pRetCode = E_DB_TRADESERIAL_I;
        goto L_RETU;
    }
    return 0;
L_RETU:
    return -1;
}
int F847221(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	double 	tx_money = 0.0;
	char  ia_buf[1024]="";
	char sMsg[256]="";
	double	dUniNo = 0;
	T_t_tif_tradeserial serial;
	T_t_tif_tradeserial old_serial;
	T_t_group_cash_report group_cash;
	T_t_groups groups;
	InAcc IA;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	int i;

	ResetNormalCPack(&aPack,0,1);

	if(strlen(rPack->scard0) <= 0)
	{
		*pRetCode = E_NOTEXIST_OPER;
		goto L_RETU;
	}
	ret = CheckOperatorPwd(rPack->scard0,rPack->semp_pwd);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	if(rPack->lvol1 <= 0)
	{
		*pRetCode = E_FAN_SERIAL_NOT_EXISTS;
		goto L_RETU;
	}

	// 更新被冲正流水的状态
	memset(&old_serial,0,sizeof old_serial);
	ret = DB_t_tif_tradeserial_read_lock_by_cur_and_serial_no(rPack->lvol1,&old_serial);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_FAN_SERIAL_NOT_EXISTS;
		else
			*pRetCode = E_DB_TRADESERIAL_R;
		goto L_RETU;
	}

	if(SERISTAT_RUSH == old_serial.serial_state)
	{
		writelog(LOG_ERR,"流水已被冲正,流水号[%d]",old_serial.serial_no);
		*pRetCode = E_FAN_ALREADY_RUSHED;
		DB_t_tif_tradeserial_free_lock_cur();
		goto L_RETU;
	}

	old_serial.serial_state = SERISTAT_RUSH;
	ret = DB_t_tif_tradeserial_update_lock_by_cur(&old_serial);
	if(ret)
	{
		writelog(LOG_ERR,"更新流水[%d]状态失败",old_serial.serial_no);
		*pRetCode = E_DB_TRADESERIAL_U;
		goto L_RETU;
	}
	DB_t_tif_tradeserial_free_lock_cur();

	tx_money = old_serial.trade_fee;
	// 生成新的冲正流水
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniNo);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	// 查询组可解款余额
	memset(&group_cash,0,sizeof group_cash);
	ret = DB_t_group_cash_report_read_lock_by_c1_and_groupid(old_serial.showid,&group_cash);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_FAN_ACC_NOT_EXISTS;
		else
			*pRetCode = E_DB_GRP_CASH_RPT_R;
		goto L_RETU;
	}
	
	/*
	if(amtcmp(tx_money,group_cash.cur_money)>0)
	{
		*pRetCode = E_FAN_ACC_INSUFFICIENT;
		DB_t_group_cash_report_free_lock_by_c1();
		goto L_RETU;
	}
	*/

	// 生成流水
	memset(&serial,0,sizeof serial);
	serial.serial_no = (int)dUniNo;
	serial.serial_state = SERISTAT_DEBT;
	serial.serial_type = TXCODE_FAN_RUSH_PAY;
	getsysdate(serial.operate_date);
	getsystime(serial.operate_time);
	des2src(serial.collect_date,serial.operate_date);
	des2src(serial.collect_time,serial.operate_time);
	GetLogicDate(serial.enteract_date);
	des2src(serial.enteract_time,serial.operate_time);

	des2src(serial.opercode,rPack->scard0);
	des2src(serial.reserve_1,rPack->scert_addr);
	serial.cardbefbal = tx_money;
	serial.trade_fee = tx_money * -1;
	// 商户号
	des2src(serial.showid,old_serial.showid);

	// 入账
	memset(&IA,0,sizeof IA);
	IA.dArrInAmt[0] = serial.trade_fee;
	IA.iCardNo = 0;
	//收费类别为 1
	IA.iFeeType = 1;
	IA.iTxFlag = ACC_TYPE_RUSH;
	IA.pVoidPointer = ia_buf;
	ret = process(&IA,&serial);
	if(ret)
	{
		writelog(LOG_ERR,"account process error [%d]",ret);
		*pRetCode  = ret;
		DB_t_group_cash_report_free_lock_by_c1();
		goto L_RETU;
	}
	SetCol(handle,0);
	SetCol(handle,F_VSMESS,F_LVOL1,F_DAMT1,F_DAMT2,F_SBANK_ACC,0);
	
	sprintf(out_pack->vsmess,"流水号:%d ",IA.iSerialNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	
	strcat(out_pack->vsmess,(char*)IA.pVoidPointer);
	writelog(LOG_DEBUG,out_pack->vsmess);

	des2src(group_cash.last_check_date,serial.operate_date);
	des2src(group_cash.last_check_time,serial.operate_time);
	group_cash.cur_money = group_cash.cur_money + tx_money;
	out_pack->lvol1 = serial.serial_no;
	out_pack->damt1 = serial.trade_fee;
	out_pack->damt2 = group_cash.cur_money;

	//更新组未解款金额
	ret = DB_t_group_cash_report_update_lock_by_c1(&group_cash);
	if(ret)
	{
		*pRetCode = E_DB_GRP_CASH_RPT_U;
		goto L_RETU;
	}
	// add
	DB_t_group_cash_report_free_lock_by_c1();
	ret = DB_t_groups_read_by_groupid(group_cash.groupid,&groups);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_DB_GROUP_N;
		else
			*pRetCode = E_DB_GROUP_R;
		goto L_RETU;
	}
	des2src(out_pack->sbank_acc,groups.group_acc);
	//保存流水
	ret = DB_t_tif_tradeserial_add(&serial);
	if(ret)
	{
		if(DB_REPEAT == ret)
			return E_DB_TRADESERIAL_E;
		else
			return E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
	
L_RETU:
	return -1;
}
Beispiel #16
0
int F847105(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret =0;
	int i=0;
	int origin_card_id = 0;
	int bill_type=0;
	char physical_no[40+1] = "";
	char logicdate[11] = "";												//业务日期
	char sysdate[11]="";
	char lost_date[11]="";
	char systime[9]="";
	char sEndDate[9]="";
	char sMsg[256]="";
	T_t_pif_card		tCard;
	T_t_pif_cardlossinfo cardlossinfo;
	T_t_tif_tradeserial  tradeserial;
//	T_t_tif_savdtl tSavdtl;
	InAcc  IA;

	memset(&tCard,0,sizeof(tCard));
	memset(&cardlossinfo,0,sizeof(cardlossinfo));
	memset(&tradeserial,0,sizeof(tradeserial));
//	memset(&tSavdtl,0,sizeof(tSavdtl));
	memset(&IA,0,sizeof(IA));

	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);											//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	origin_card_id = rPack->lvol1;   										//原卡号
	des2src(physical_no, rPack->sbank_acc);							//物理卡号
	if(rPack->lvol1<1)
	{
		*pRetCode=E_INPUT_CARDNO_CANNOT_NULL;
		goto L_RETU;
	}
	//查询支票经费本有无充值记录
	/*
	ret=ChkSavdtl(origin_card_id,&tSavdtl);
	if(ret)
	{
		writelog(LOG_ERR,"ChkSavdtl ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	//Added by hhd at 2006-06-29 begin
	//增加判断:如果入卡值大于100,检查经费本知否充值过
	//否则不加任何判断,退款到现金中
	if(amtcmp(rPack->damt2,100.00)<0)
	{
		tSavdtl.bill_type=TYPE_CASH;
	}
	*/
	//Added by hhd at 2006-06-29 end

	tradeserial.other_seri_no = 0;										//上传端流水号
	tradeserial.serial_type=TXCODE_CALLBACK_CARD;						//功能号
	tradeserial.serial_state = SERISTAT_DEBT;								//流水状态
	des2src(tradeserial.operate_date,sysdate);							//发生日期
	des2src(tradeserial.operate_time,systime);							//发生时间
	des2src(tradeserial.collect_date,sysdate);								//采集日期
	des2src(tradeserial.collect_time,systime);								//采集时间
	des2src(tradeserial.enteract_date,logicdate);							//处理日期
	des2src(tradeserial.enteract_time,systime);							//处理时间
	tradeserial.maindevice_id = rPack->lvol6;								//上传工作站标识
	tradeserial.device_id = rPack->lvol7;									//采集设备标识
	tradeserial.purse_id = PURSE_NO_ONE;								//钱包号
	tradeserial.sys_id = 0;												//外部系统标识
	des2src(tradeserial.oper_code, rPack->scust_limit);					//操作员号
	tradeserial.card_id=origin_card_id;
	ret=DB_t_pif_card_read_lock_by_cur_and_card_id(origin_card_id,&tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_R;
		goto L_RETU;
	}
//	writelog(LOG_DEBUG,"input card_id[%d] card_id[%d]",origin_card_id,tCard.card_id);
	tradeserial.customer_id = tCard.cosumer_id;							//客户标识
	if(strncmp(tCard.state_id,CARDSTAT_REG,4)==0)
	{
		//检查物理卡号是否一致
		trim(physical_no);
		trim(tCard.physical_no);
		if(strcmp(tCard.physical_no,physical_no)!=0)
		{
			DB_t_pif_card_free_lock_by_cur();
			writelog(LOG_ERR,"db physical_no[%s],input physical_no[%s]",tCard.physical_no,physical_no);
			*pRetCode= E_CARD_PHYNO_DIFFER;
			goto L_RETU;
		}
	}
	else if('2'==tCard.state_id[CARDSTAT_TYPE_REG])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode = E_CARDNO_LOGOUT;
		goto L_RETU;
	}
	//changed by hhd,泰州现场修改,复旦也有这种情况,必须人为干预
	//换卡写卡失败和其它写卡失败,都已库为准退卡,屏蔽掉这两判断
	/*
	else if('3'==tCard.state_id[CARDSTAT_TYPE_REG])
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_CARD_CHANGE;
		goto L_RETU;
	}
	*/
	else if(tCard.state_id[CARDSTAT_TYPE_FREEZE]==STATE_TRUE)
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_CARDNO_FREEZE;
		goto L_RETU;
	}
	/*
	else if(tCard.state_id[CARDSTAT_TYPE_WFAIL]==STATE_TRUE)
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_CARDNO_WFAIL;
		goto L_RETU;
	}
	*/
	else if(tCard.state_id[CARDSTAT_TYPE_LOST]==STATE_TRUE)
	{
		if(IS_YES==rPack->lvol12)
		{
			DB_t_pif_card_free_lock_by_cur();
			*pRetCode=E_CARDNO_LOST;
			goto L_RETU;
		}
		/*
		ret=DB_t_pif_cardlossinfo_read_by_card_id_and_state_id(origin_card_id, STATE_VALID, &cardlossinfo);
		if(ret)
		{
			DB_t_pif_card_free_lock_by_cur();
			writelog(LOG_ERR,"lost_card_id[%d]",origin_card_id);
			if(DB_NOTFOUND==ret)
				*pRetCode =  E_CARDNO_NOT_EXIST;
			else
				*pRetCode =  E_DB_CARD_R;
			goto L_RETU;
		}
		*/
		ret=get_latest_lost_date_by_card_no(origin_card_id,lost_date);
		if(ret)
		{
			DB_t_pif_card_free_lock_by_cur();
			writelog(LOG_ERR,"lost_card_id[%d]",origin_card_id);
			*pRetCode =ret;
			goto L_RETU;
		}
		//先检查客户的挂失的正式卡是否到了补办日期
		ret=GetLostCardValiddate(lost_date,sEndDate);
		if(ret)
		{
			DB_t_pif_card_free_lock_by_cur();
			*pRetCode =ret;
			goto L_RETU;
		}
		if(strncmp(sEndDate,sysdate,8)>0)
		{
			DB_t_pif_card_free_lock_by_cur();
			writelog(LOG_ERR,"lost_normal_card_id[%d]lost_date[%s]end_date[%s]",origin_card_id,lost_date,sEndDate);
			*pRetCode =  E_NORMALCARD_NOT_REACH_ENDDATE;
			goto L_RETU;
		}
/*
		//更新卡挂失日期表中该卡状态为无效
		ret=UpdateCardLossInfoState(origin_card_id,STATE_VALID,STATE_INVALID);
		if(ret)
		{
			DB_t_pif_card_free_lock_by_cur();
			*pRetCode =ret;
			goto L_RETU;
		}
*/
		//正常情况下的押金都是退的,但是如果卡丢失则不退的
//		IsReturnDeposit=IS_NO;
	}
	else if(IS_YES!=rPack->lvol12)
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=E_NOCARD;
		goto L_RETU;
	}
	//注销原卡
	des2src(tCard.state_id,CARDSTAT_LOGOUT);		//注销
	des2src(tCard.end_time,tradeserial.operate_date);	//注销日期
	ret=DB_t_pif_card_update_lock_by_cur(&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"card_id[%d]",tCard.card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode =   E_CARDNO_NOT_EXIST;
		else
			*pRetCode =  E_DB_CARD_R;
		goto L_RETU;
	}
	DB_t_pif_card_free_lock_by_cur();

	//是否退费,规定正式卡和临时卡退押金,非记名临时卡退押金
	if(IS_YES==rPack->lvol12)
	{
		IA.iUseCardFlag=USE_CARD_TYPE_ONLINE;		//联机交易
		IA.dInCardBala = rPack->damt2;				//入卡值
		IA.dOutCardBala=-1;							//-1 表示空值
		IA.iTxCnt = rPack->lvol10+1;					//当前卡交易次数
		tradeserial.in_balance = IA.dInCardBala;			//入卡值
		tradeserial.trade_count = IA.iTxCnt;
	}
	else
	{
		IA.iUseCardFlag=USE_CARD_TYPE_NULL;
		IA.dInCardBala = -1;				//-1 表示空值
		IA.dOutCardBala=-1;				//-1 表示空值
		IA.iTxCnt = -1;					//-1 表示空值
	}
	bill_type=TYPE_CASH;
//	IA.pVoidPointer=&tSavdtl.bill_type;
	IA.pVoidPointer=&bill_type;
	IA.iCardNo=tCard.card_id;

	ret=process(rPack,&IA,&tradeserial);
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	writelog(LOG_DEBUG,"input card_id[%d] card_id[%d]",origin_card_id,tCard.card_id);
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode= E_DB_TRADESERIAL_E;
		else
			*pRetCode= E_DB_TRADESERIAL_I;
		goto L_RETU;
	}

	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_DAMT0,F_DAMT1,F_DAMT2,F_DAMT3,F_DAMT4,F_SDATE0,F_LVOL1,F_SPHONE,F_LSERIAL1,F_VSMESS,0);
	sprintf(out_pack->vsmess,"流水号:%d 卡号:%d ",IA.iSerialNo,IA.iCardNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		switch(IA.iArrOutTxType[i])
		{
			case TXTYPE_DEDUCT_DEPOSIT:
				tradeserial.deposit_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_RETURN_DEPOSIT:
			case TXTYPE_RETURN_DEPOSIT_BILL:
			case TXTYPE_RETURN_DEPOSIT_FUNDBOOK:
				tradeserial.deposit_fee=IA.dArrOutAmt[i];
				out_pack->damt0+=IA.dArrOutAmt[i];
				break;
			case TXTYPE_DEDUCT_BOARD:
				tradeserial.boardfee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_RETURN_BOARD:
			case TXTYPE_RETURN_BOARD_BILL:
			case TXTYPE_RETURN_BOARD_FUNDBOOK:
				tradeserial.boardfee=IA.dArrOutAmt[i];
				out_pack->damt0+=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CHARGE:
				tradeserial.in_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CARDCOST:
				tradeserial.cost_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_DRAW_CASH:
			case TXTYPE_DRAW_BILL:
			case TXTYPE_DRAW_FUNDBOOK:
			case TXTYPE_DRAW_OTHER:
				tradeserial.trade_fee=IA.dArrOutAmt[i];
				out_pack->damt0+=IA.dArrOutAmt[i];
				break;
			default:
				break;
		}
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
			/*
			if((TXTYPE_DRAW_BILL==IA.iArrOutTxType[i])||
			   (TXTYPE_DRAW_FUNDBOOK==IA.iArrOutTxType[i])||
			   (TXTYPE_DRAW_OTHER==IA.iArrOutTxType[i]))
			{
				sprintf(sMsg,"票据号码:%s ",tSavdtl.bill_no);
				strcat(out_pack->vsmess,sMsg);
			}
			*/
		}
	}
	sprintf(sMsg,"实际应退金额:%.2lf元",out_pack->damt0);
		strcat(out_pack->vsmess,sMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);
	if(amtcmp(tradeserial.out_balance,0)<0)
	{
		*pRetCode=E_ENTER_ACCOUNT;
		goto L_RETU;
	}
//		out_pack->lvol1=tSavdtl.bill_type;
	out_pack->lvol1=bill_type;
//	des2src(out_pack->sdate0,tSavdtl.tx_date);
//	out_pack->damt1=tSavdtl.amount;							//经费本充值金额
	out_pack->lserial1=tradeserial.serial_no;						//流水号
//		des2src(out_pack->sphone,tSavdtl.bill_no);

	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #17
0
int F847183(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

    int ret=0;
    char    	tx_date[8+1]="";              	//发生日期
    char    	tx_time[6+1]="";      		//发生时间
    int		card_no=0;                    	//卡号
    char    	device_id[8+1]="";            	//终端机ID
    int		serial_no=0;                  	//终端机流水号
    double 	dUniqno=0;
    T_t_tif_tradeserial		tTradeserial;	//卡操作流水表
    T_t_tif_rcvdtl		tRcvdtl;
    char sysdate[11]="";
    char systime[9]="";
    ST_CPACK aPack;
    ST_PACK *out_pack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);
    memset(&tRcvdtl,0,sizeof(tRcvdtl));
    memset(&tTradeserial,0,sizeof(tTradeserial));
    getsysdate(sysdate);
    getsystime(systime);
    des2src(tTradeserial.enteract_time,systime);

    des2src(tx_date,rPack->sbank_pwd);
    des2src(tx_time,rPack->sbank_code);
    card_no=rPack->lvol0;
    des2src(device_id,rPack->sbank_pwd2);
    serial_no=rPack->lvol1;
    trim(rPack->scust_limit);
    trim(rPack->scust_limit2);
    trim(rPack->semp_pwd);

    if(strlen(rPack->scust_limit)==0)
    {
        *pRetCode=E_OPER_NOT_EXIST;
        goto L_RETU;
    }
    if(strlen(rPack->scust_limit2)==0)
    {
        *pRetCode=E_INPUT_AUTH_OPER_NULL;
        goto L_RETU;
    }
    if(strcmp(rPack->scust_limit,rPack->scust_limit2)==0)
    {
        writelog(LOG_ERR,"oper[%s]auth_oper[%s]",rPack->scust_limit,rPack->scust_limit2);
        *pRetCode=E_OPER_AND_AUTH_OPER_EQ;
        goto L_RETU;
    }
    ret=chk_oper_pwd(rPack->scust_limit2,rPack->semp_pwd);
    if(ret)
    {
        if(E_OPER_NOT_EXIST==ret)
            *pRetCode=E_AUTH_OPER_NOT_EXIST;
        else if(E_PASSWORD_WRONG==ret)
            *pRetCode=E_AUTH_OPER_PWD;
        else
            *pRetCode=ret;
        goto L_RETU;
    }
    ret=DB_t_tif_rcvdtl_read_lock_by_c0_and_tx_date_and_tx_time_and_card_no_and_device_id_and_serial_no(tx_date,tx_time,card_no,device_id,serial_no,&tRcvdtl);
    if(ret)
    {
        if(DB_NOTFOUND==ret)
        {
            writelog(LOG_ERR,"tx_date[%s],tx_time[%s],card_no[%d],device_id[%s],serial_no[%d]",tx_date,tx_time,card_no,device_id,serial_no);
            *pRetCode=E_SERIALNO_NOT_EXIST;
        }
        else
        {
            writelog(LOG_ERR,"read_lock t_tif_rcvdtl err ret[%d]",ret);
            *pRetCode=E_DB_RCVDTL_R;
        }
        goto L_RETU;
    }
    if(tRcvdtl.status[0]=='4')
    {
        *pRetCode=E_TX_SERIAL_CZ;
        DB_t_tif_rcvdtl_free_lock_c0();
        goto L_RETU;
    }
    if(tRcvdtl.status[0]!='3')
    {
        *pRetCode=E_TX_SERIAL_CANNOT_CZ;
        DB_t_tif_rcvdtl_free_lock_c0();
        goto L_RETU;
    }
    if(tRcvdtl.amount<0)
    {
        *pRetCode=E_TX_SERIAL_CANNOT_CZ;
        DB_t_tif_rcvdtl_free_lock_c0();
        goto L_RETU;
    }
    tRcvdtl.status[0]='4';				//冲正
    des2src(tRcvdtl.oper_no,rPack->scust_limit);
    des2src(tRcvdtl.deal_date,sysdate);
    des2src(tRcvdtl.deal_time,systime);
    ret=DB_t_tif_rcvdtl_update_lock_by_c0(&tRcvdtl);
    if(ret)
    {
        *pRetCode=E_DB_RCVDTL_U;
        writelog(LOG_ERR,"DB_t_tif_rcvdtl_update_lock_by_c0[%d]",ret);
        goto L_RETU;
    }
    DB_t_tif_rcvdtl_free_lock_c0();
    //赋值
    ret=getdata(&tTradeserial,&tRcvdtl);
    if(ret)
    {
        *pRetCode=ret;
        goto L_RETU;
    }
    des2src(tTradeserial.operate_date,sysdate);
    des2src(tTradeserial.operate_time,systime);
    des2src(tTradeserial.collect_date,sysdate);
    des2src(tTradeserial.collect_time,systime);
    ret=GetLogicDate(tTradeserial.enteract_date);						//业务日期
    if(ret)
    {
        *pRetCode=ret;
        writelog(LOG_ERR,"GetLogicDate  err ret[%d]",ret);
        goto L_RETU;
    }
    des2src(tTradeserial.enteract_time,systime);
    tTradeserial.in_balance =rPack->damt1;
    tTradeserial.trade_fee = -(tRcvdtl.amount/100.0);		//本次消费金额
    tTradeserial.out_balance=tTradeserial.in_balance-tTradeserial.trade_fee;
    tTradeserial.trade_count=rPack->lvol10;
    tTradeserial.maindevice_id=rPack->lvol6;
//	tTradeserial.sys_id=rPack->lvol6;
    des2src(tTradeserial.oper_code,rPack->sdate1);
    tTradeserial.reviseserial_no=tTradeserial.other_seri_no;

    //取流水号,从帐处理
    ret=getNewUniqNo(KEYTYPE_TRADESERIAL, &dUniqno);
    if(ret)
    {
        *pRetCode=ret;
        writelog(LOG_ERR,"getNewUniqNo err[%d]",ret);
        goto L_RETU;
    }
    tTradeserial.serial_no=(int)dUniqno;
    //######################################################
    //入账处理
    switch(tTradeserial.serial_type)
    {
    case 930031:
        if(0==tRcvdtl.amount)
            break;
        tTradeserial.serial_type=TXCODE_TX_REVEAL;
        ret=process930031(&tTradeserial);
        if(ret)
        {   //业务处理失败处理
            *pRetCode=ret;
            goto L_RETU;
        }
        break;
    default:
        *pRetCode=E_TXCODE_NOT_EXIST;	//交易码错误
        goto L_RETU;
    }
    //######################################################
    //添加交易流水
    tTradeserial.serial_state=SERISTAT_DEBT;
    ret = DB_t_tif_tradeserial_add(&tTradeserial);
    if (ret)
    {
        writelog(LOG_ERR,"DB_t_tif_tradeserial_add ret[%d]",ret);
        if(DB_REPEAT==ret)
            *pRetCode= E_DB_TRADESERIAL_E;
        else
            *pRetCode= E_DB_TRADESERIAL_I;
        goto L_RETU;
    }
    if(amtcmp(tTradeserial.out_balance,0)<0)
    {
        *pRetCode=E_ENTER_ACCOUNT;
        goto L_RETU;
    }
    SetCol(handle,0);
    SetCol(handle,F_LSERIAL1,F_DAMT2,F_DAMT3,F_VSMESS,0);
    out_pack->lserial1=tTradeserial.serial_no;
    out_pack->damt2=tTradeserial.out_balance;
    out_pack->damt3=-tTradeserial.trade_fee;
    sprintf(out_pack->vsmess,"流水号:%d 冲正金额:%.2lf元 冲正前卡余额:%.2lf元 卡当前余额:%.2lf元",tTradeserial.serial_no,-tTradeserial.trade_fee,tTradeserial.in_balance,tTradeserial.out_balance);
    writelog(LOG_DEBUG,out_pack->vsmess);
    PutRow(handle,out_pack,pRetCode,szMsg);
    return 0;
L_RETU:
    return -1;
}
Beispiel #18
0
int F847220(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

    int ret=0;
    double 	tx_money = 0.0;
    char  ia_buf[1024]="";
    char sMsg[256]="";
    double	dUniNo = 0;
    T_t_tif_tradeserial serial;
    T_t_group_cash_report group_cash;
    int groupid;
    T_t_groups groups;
    InAcc IA;
    ST_CPACK aPack;
    ST_PACK *out_pack = &(aPack.pack);
    int i;

    ResetNormalCPack(&aPack,0,1);

    if(strlen(rPack->scard0) <= 0)
    {
        *pRetCode = E_NOTEXIST_OPER;
        goto L_RETU;
    }
    ret = CheckOperatorPwd(rPack->scard0,rPack->semp_pwd);
    if(ret)
    {
        writelog(LOG_ERR,"操作员密码错误operator[%s]",rPack->scard0);
        *pRetCode = ret;
        goto L_RETU;
    }

    if(strlen(rPack->sbank_acc) <= 0)
    {
        *pRetCode = E_NOTEXIST_ACCNO;
        goto L_RETU;
    }

    tx_money = rPack->damt1;
    if(amtcmp(tx_money,0.0)<=0)
    {
        *pRetCode = E_INPUT_AMT;
        goto L_RETU;
    }

    memset(&groups,0,sizeof groups);

    //ret = DB_t_groups_read_by_group_acc(rPack->sbank_acc,&groups);
    ret = DB_t_groups_read_by_groupid(rPack->sbank_acc,&groups);
    if(ret)
    {
        if(DB_NOTFOUND == ret)
            *pRetCode = E_NOTEXIST_ACCNO;
        else
            *pRetCode = E_DB_GROUP_R;
        goto L_RETU;
    }

    ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniNo);
    if(ret)
    {
        *pRetCode = ret;
        goto L_RETU;
    }

    // 查询组可解款余额
    memset(&group_cash,0,sizeof group_cash);
    ret = DB_t_group_cash_report_read_lock_by_c1_and_groupid(groups.groupid,&group_cash);
    if(ret)
    {
        if(DB_NOTFOUND == ret)
            *pRetCode = E_FAN_ACC_NOT_EXISTS;
        else
            *pRetCode = E_DB_GRP_CASH_RPT_R;
        goto L_RETU;
    }

    if(amtcmp(tx_money,group_cash.cur_money)>0)
    {
        writelog(LOG_ERR,"操作员组余额[%.2lf], 解款金额[%.2lf]",group_cash.cur_money,tx_money);
        *pRetCode = E_FAN_ACC_INSUFFICIENT;
        DB_t_group_cash_report_free_lock_by_c1();
        goto L_RETU;
    }

    // 生成流水
    memset(&serial,0,sizeof serial);
    serial.serial_no = D2I(dUniNo);
    serial.serial_state = SERISTAT_DEBT;
    serial.serial_type = TXCODE_FAN_PAY_MONEY;
    getsysdate(serial.operate_date);
    getsystime(serial.operate_time);
    des2src(serial.collect_date,serial.operate_date);
    des2src(serial.collect_time,serial.operate_time);
    GetLogicDate(serial.enteract_date);
    des2src(serial.enteract_time,serial.operate_time);

    des2src(serial.opercode,rPack->scard0);
    des2src(serial.reserve_1,rPack->scert_addr);
    serial.cardbefbal = tx_money;
    serial.trade_fee = tx_money;
    des2src(serial.showid,group_cash.groupid);

    // 入账
    memset(&IA,0,sizeof IA);
    //IA.dInCardBala = serial.cardbefbal;
    IA.dArrInAmt[0] = serial.trade_fee;
    IA.iCardNo = 0;
    //收费类别为 1
    IA.iFeeType = 1;
    IA.pVoidPointer = ia_buf;
    ret = process(&IA,&serial);
    if(ret)
    {
        writelog(LOG_ERR,"入账失败ret [%d]",ret);
        *pRetCode  = ret;
        DB_t_group_cash_report_free_lock_by_c1();
        goto L_RETU;
    }
    SetCol(handle,0);
    SetCol(handle,F_VSMESS,F_LVOL1,F_DAMT1,0);

    sprintf(out_pack->vsmess,"流水号:%d ",IA.iSerialNo);
    for(i=1; i<=IA.iOutTxTypeCnt; i++)
    {
        if(amtcmp(IA.dArrOutAmt[i],0)!=0)
        {
            sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
            strcat(out_pack->vsmess,sMsg);
        }
    }
    //serial.cardaftbal =
    strcat(out_pack->vsmess,(char*)IA.pVoidPointer);
    writelog(LOG_DEBUG,out_pack->vsmess);
    out_pack->lvol1 = serial.serial_no;
    group_cash.cur_money = group_cash.cur_money - serial.trade_fee;

    des2src(group_cash.last_check_date,serial.operate_date);
    des2src(group_cash.last_check_time,serial.operate_time);
    out_pack->damt1 = group_cash.cur_money;

    //更新组未解款金额
    ret = DB_t_group_cash_report_update_lock_by_c1(&group_cash);
    if(ret)
    {
        *pRetCode = E_DB_GRP_CASH_RPT_U;
        goto L_RETU;
    }
    // add
    DB_t_group_cash_report_free_lock_by_c1();
    //保存流水
    ret = DB_t_tif_tradeserial_add(&serial);
    if(ret)
    {
        if(DB_REPEAT == ret)
            return E_DB_TRADESERIAL_E;
        else
            return E_DB_TRADESERIAL_I;
        goto L_RETU;
    }
    PutRow(handle,out_pack,pRetCode,szMsg);
    return 0;
L_RETU:
    return -1;
}
Beispiel #19
0
int F847119(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	char logicdate[11]="";
	char sysdate[11]="";
	char systime[9]="";
	char operate_date[11]="";
	char sSerialno[20]="";
	char physical_no[41]="";
	char old_physical_no[41]="";
	int 	iSerialno=0;
	int 	card_id=0;
	int 	serial_type=0;
	int   flag=0;
	double dSerialno=0;
	double  dAmt=0;
	char h_password[7] = "";							//卡密码
	char seed_key[17] = "";							//种子密钥

	int card_use_cnt=0;
	int seri_use_cnt=0;
	double seri_in_bala=0;
	double seri_out_bala=0;
	double seri_in_bala_next=0;
	double seri_out_bala_next=0;
	int amt_flag=0;
	char tx_date[11]="";

	T_t_pif_card tCard;
	T_t_cif_customer  tCustomer;
	T_t_pif_spefee 	tSpeFee;
	T_t_tif_tradeserial tradeserial;
	T_t_tif_tradeserial old_tradeserial;
	T_t_tif_tradeserial_his tradeserialhis;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	memset(&tCard,0,sizeof(tCard));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tSpeFee,0,sizeof(tSpeFee));
	memset(&old_tradeserial,0,sizeof(old_tradeserial));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&tradeserialhis,0,sizeof(tradeserialhis));
	memcpy(seed_key,STATIC_SEED_KEY,sizeof(seed_key));		//读种子密钥

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL5,F_LVOL6,
				F_SCUST_NO,	F_SCUST_NO2,F_SCUST_AUTH,F_SCUST_AUTH2,
				F_SDATE0,F_SNAME,F_SNAME2,
				F_SOPEN_EMP,F_SSTATUS0,
				F_DAMT2,F_LSERIAL1,F_VSMESS,0);
	des2src(physical_no,rPack->sbank_acc);
	card_id=rPack->lvol0;

	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	//判断卡状态是否为写卡未成功状态
	ret=DB_t_pif_card_read_by_card_id(card_id, &tCard);
	if(ret)
	{
		writelog(LOG_ERR,"card_id[%d]",card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_R;
		goto L_RETU;
	}
	if(STATE_FALSE==tCard.state_id[CARDSTAT_TYPE_WFAIL])
	{
		*pRetCode=E_CARDSTATE_NOTWRITEFAIL;
		goto L_RETU;
	}
	ret=GetXmlValue(sSerialno, sizeof(sSerialno), XML_KEY_SERIALNO, tCard.comments);
	if(ret)
	{
		DB_t_pif_card_free_lock_by_cur();
		*pRetCode=ret;
		goto L_RETU;
	}
	//修改账号表中的卡状态
	//根据流水号得到补卡的出卡值
	ret=GetXmlValue(operate_date, sizeof(operate_date), XML_KEY_OPERATEDATE, tCard.comments);
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	iSerialno=atoi(sSerialno);
	if(strncmp(logicdate,operate_date,8)==0)
	{
		ret=DB_t_tif_tradeserial_read_by_serial_no(iSerialno,&old_tradeserial);
		if(ret)
		{
			writelog(LOG_ERR,"Serialno[%d]",iSerialno);
			if(DB_NOTFOUND==ret)
				*pRetCode=E_SERIALNO_NOT_EXIST;
			else
				*pRetCode=E_DB_TRADESERIAL_R;
			goto L_RETU;
		}
		if(card_id!=old_tradeserial.card_id)
		{
			writelog(LOG_ERR,"input card_id [%d],tradeserial card_id[%d]",card_id,old_tradeserial.card_id);
			*pRetCode=E_CARDNO_SERIAL_NE;
			goto L_RETU;
		}
		serial_type=old_tradeserial.serial_type;
		flag=TYPE_CUR;
	}
	else
	{
		ret=DB_t_tif_tradeserial_his_read_by_bak_date_and_serial_no(operate_date,iSerialno,&tradeserialhis);
		if(ret)
		{
			writelog(LOG_ERR,"operate_date[%s]Serialno[%d]",operate_date,iSerialno);
			if(DB_NOTFOUND==ret)
				*pRetCode=E_SERIALNO_NOT_EXIST;
			else
				*pRetCode=E_DB_TRADESERIAL_R;
			goto L_RETU;
		}
		if(card_id!=tradeserialhis.card_id)
		{
			writelog(LOG_ERR,"input card_id [%d],tradeserial card_id[%d]",card_id,tradeserialhis.card_id);
			*pRetCode=E_CARDNO_SERIAL_NE;
			goto L_RETU;
		}
		serial_type=tradeserialhis.serial_type;
		flag=TYPE_HIS;
	}
	if(TYPE_CUR==flag)
	{
		seri_in_bala=old_tradeserial.in_balance;
		seri_out_bala=old_tradeserial.out_balance;
		strncpy(tx_date,old_tradeserial.operate_date,sizeof(tx_date));
		dAmt=D4U5(old_tradeserial.out_balance-old_tradeserial.in_balance,2); 		//发生额=出卡值-入卡值
	}
	else
	{
		seri_in_bala=tradeserialhis.in_balance;
		seri_out_bala=tradeserialhis.out_balance;
		strncpy(tx_date,tradeserialhis.operate_date,sizeof(tx_date));
		dAmt=D4U5(tradeserialhis.out_balance-tradeserialhis.in_balance,2); 		//发生额=出卡值-入卡值
	}
	des2src(old_physical_no,tCard.physical_no);
	trim(physical_no);
	trim(old_physical_no);
	switch(serial_type)
	{
		//发行正式卡
		case  847101:
		//补办正式卡
		case  847104:
		//发行过渡临时卡
		case 847116:
		//发行非记名临时卡
		case 847124:
		case 847125:
		case 847126:
			if(strcmp(old_physical_no,physical_no)!=0)
			{
				ret=IsExistCardByPhyCardNo(physical_no);
				if(ret)
				{
					*pRetCode = ret;
					goto L_RETU;
				}
				//修改卡标志,置为正常状态
				ret=DB_t_pif_card_read_lock_by_cur_and_card_id(card_id, &tCard);
				if(ret)
				{
					writelog(LOG_ERR,"card_id[%d]",card_id);
					if(DB_NOTFOUND==ret)
						*pRetCode= E_CARDNO_NOT_EXIST;
					else
						*pRetCode= E_DB_CARD_R;
					goto L_RETU;
				}
				des2src(tCard.physical_no,physical_no);			//物理卡号
				ret=DB_t_pif_card_update_lock_by_cur(&tCard);
				if(ret)
				{
					writelog(LOG_ERR,"card_id[%d]",card_id);
					if(DB_NOTFOUND==ret)
						*pRetCode= E_CARDNO_NOT_EXIST;
					else
						*pRetCode= E_DB_CARD_U;
					goto L_RETU;
				}
				DB_t_pif_card_free_lock_by_cur();
				// add by 汤成 2005-8-10
				// 增加向名单表写入记录
				switch(serial_type)
				{
				//补办正式卡
				case  847104:
				//发行过渡临时卡
				case 847116:
				// 记名临时卡
				//case 847124:
				// VIP 卡
				case 847126:
					ret = InsertToBlkList(tCard.card_id,CHCARD_BLACKLIST);
					if(ret)
					{
						*pRetCode = ret;
						goto L_RETU;
					}
					break;
				default:
					break;
				}
			}
			tradeserial.in_balance=0;													//入卡值
			break;
		//银行转帐-Added by hhd at 20051225
		//考虑到有可能圈存写卡成功,但是提示失败
		//避免重复写卡
		case 240001:
			//判断卡中交易次数是否等于发生错误的流水的交易次数
			if(card_use_cnt==seri_use_cnt)
			{
				//判断上传入卡值是否等于发生错误的流水的入卡值
				if(rPack->damt1==seri_in_bala)	   //入卡值等于入卡值,卡没有写上
					tradeserial.in_balance=rPack->damt1;
				if(rPack->damt1==seri_out_bala)  //入卡值等于出卡值,卡已经写上
				{
					tradeserial.in_balance=rPack->damt1;
					amt_flag=1;
				}
				else
				{
					writelog(LOG_ERR,"In_balance abnormity,in_bala=[%f]",rPack->damt1);
					*pRetCode= E_ENTER_ACCOUNT;
					goto L_RETU;
				}
			}
			if(card_use_cnt>seri_use_cnt)
			{
				ret=Get_card_next_serial(tCard.card_id,tx_date,rPack->lvol6,&seri_in_bala_next,&seri_out_bala_next);
				if(ret)
				{
					writelog(LOG_ERR,"Get_card_next_serial error,errcode=[%d]",ret);
					writelog(LOG_ERR,"没有找到下一笔流水");
					goto L_RETU;
				}
				if(seri_in_bala_next==seri_in_bala)
					tradeserial.in_balance=rPack->damt1;
				if(seri_in_bala_next==seri_out_bala)
				{
					tradeserial.in_balance=rPack->damt1;
					amt_flag=1;
				}
				else
				{
					writelog(LOG_ERR,"In_balance abnormity,in_bala=[%f]",rPack->damt1);
					*pRetCode= E_ENTER_ACCOUNT;
					goto L_RETU;
				}
			}
			else
			{
				writelog(LOG_ERR,"In_total_cnt abnormity,in_total_cnt=[%d]",card_use_cnt);
				*pRetCode= E_ENTER_ACCOUNT;
				goto L_RETU;
			}
		default:
			if(strcmp(old_physical_no,physical_no)!=0)
			{
				writelog(LOG_ERR,"db physical_no[%s],input physical_no[%s]",old_physical_no,physical_no);
				*pRetCode= E_CARD_PHYNO_DIFFER;
				goto L_RETU;
			}
			tradeserial.in_balance=rPack->damt1;										//入卡值
			break;
	}
	if(TYPE_CUR==flag)
		dAmt=D4U5(old_tradeserial.out_balance-old_tradeserial.in_balance,2); 		//发生额=出卡值-入卡值
	else
		dAmt=D4U5(tradeserialhis.out_balance-tradeserialhis.in_balance,2); 		//发生额=出卡值-入卡值
	//说明不需要写卡,则发生额置为0
	if(amt_flag==1)
	{
		tradeserial.trade_fee=0;											//补写卡值
	}
	else
	{
		tradeserial.trade_fee=dAmt;											//补写卡值
	}
	tradeserial.out_balance=tradeserial.in_balance+dAmt;					//出卡值
	if(tradeserial.out_balance<0||tradeserial.out_balance>999)
	{
		writelog(LOG_ERR,"tradeserial.out_balance[%lf]",tradeserial.out_balance);
		*pRetCode= E_TX_SERIAL;
		goto L_RETU;
	}
	writelog(LOG_DEBUG,"写卡失败日期%s,补写流水号%d,交易码%d,卡号%d,补写金额%.2lf,入卡值%lf,出卡值%lf",operate_date,iSerialno,serial_type,card_id,dAmt,tradeserial.in_balance,tradeserial.out_balance);

	ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(tCard.cosumer_id, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",tCard.cosumer_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode= E_DB_CUSTOMER_R;
		goto L_RETU;
	}
	EncodePwd(seed_key,h_password,tCard.password,0);			//卡密码
	//得到收费类别
	if(tCustomer.fee_type<1)
	{
		ret=DB_t_pif_spefee_read_by_dept_code_and_cut_type(tCustomer.classdept_no, tCustomer.cut_type,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.fee_type=tCustomer.cut_type;
			}
			else
			{
				DB_t_cif_customer_free_lock_cur();
				*pRetCode=E_DB_SPEFEE_R;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.fee_type=tSpeFee.fee_type;
		}
		//更新客户表的收费类别字段
		ret=DB_t_cif_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode= E_CUSTOMER_NOT_EXIST;
			else
				*pRetCode= E_DB_CUSTOMER_U;
			goto L_RETU;
		}
	}
	DB_t_cif_customer_free_lock_cur();

	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialno);  				//获得流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret [%d]",ret);
		goto L_RETU;
	}

	tradeserial.serial_no = (int)dSerialno;											//流水号
	tradeserial.other_seri_no = 0;												//上传端流水号
	tradeserial.serial_type = TXCODE_REWRITE_CARD;								//交易代码;备注:发卡+充值 用一个交易码,即847101; 发卡(不充值)另用一个交易码,即新的发卡程序文件名,从而区分发卡充值与发卡不充值的卡操作信息。
	tradeserial.serial_state = SERISTAT_DEBT;										//流水状态
	des2src(tradeserial.operate_date,sysdate);											//发生日期
	des2src(tradeserial.operate_time,systime);											//发生时间
	des2src(tradeserial.collect_date,sysdate);												//采集日期
	des2src(tradeserial.collect_time,systime);												//采集时间
	des2src(tradeserial.enteract_date,logicdate);											//处理日期
	des2src(tradeserial.enteract_time,systime);											//处理时间
	des2src(tradeserial.oper_code , rPack->scust_limit);
	tradeserial.maindevice_id = rPack->lvol6;											//上传工作站标识
	tradeserial.device_id = rPack->lvol7;												//采集设备标识
	tradeserial.card_id = tCard.card_id;											//卡号
	des2src(tradeserial.showid,tCard.showid);										//显示卡号
	tradeserial.purse_id = PURSE_NO_ONE;										//钱包号
	tradeserial.customer_id = tCard.cosumer_id;									//客户标识
	tradeserial.reviseserial_no=dSerialno;											//原写卡失败流水号
	//	插入交易流水表
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	if(amtcmp(tradeserial.out_balance,0)<0)
	{
		*pRetCode=E_ENTER_ACCOUNT;
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d 补写金额:%.2lf元 补写前卡余额:%.2lf元  卡当前余额:%.2lf元",tradeserial.serial_no,tradeserial.trade_fee,tradeserial.in_balance,tradeserial.out_balance);
	writelog(LOG_DEBUG,out_pack->vsmess);

	out_pack->lvol0 = tCard.card_id;								//交易卡号
	out_pack->lvol1 = tCustomer.cut_type;						//客户类别
	out_pack->lvol5 = tCustomer.fee_type;						//收费类别
	des2src(out_pack->scust_no,tCard.showid);					//显示卡号
	des2src(out_pack->scust_no2,tCustomer.classdept_no);			//部门号
	des2src(out_pack->scust_auth,tCustomer.stuemp_no);			//学号
	des2src(out_pack->scust_auth2,tCustomer.man_id);			//身份证号
	des2src(out_pack->sname,tCustomer.cut_name);				//客户姓名
	des2src(out_pack->sname2,tCustomer.lib_cardid);				//图书证号
	des2src(out_pack->sstatus0,tCustomer.sex);					//性别
	des2src(out_pack->sopen_emp,h_password);					//卡密码
	des2src(out_pack->sdate0,tCard.end_time);					//有效截至日期

	out_pack->damt2=tradeserial.out_balance;					//出卡值=入卡值+发生额
	out_pack->lserial1=tradeserial.serial_no;						//流水号

	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #20
0
/**
 * \brief 处理网银转账入账业务
 * \param in_pack 请求报文包
 * \param out_pack 输出报文包
 * \param online_tx 联机交易,当为1时,如果个人账户已注销,则不能交易,
 *					当为0时,如果个人账户已注销,则借记 现金,贷记 营业成本
 */
int do_849009(ST_PACK *in_pack,char *szMsg,ST_PACK *out_pack,int online_tx)
{
	int cust_id,card_id;
	int subsidy_no;
	int ret,count;
	char temp[64];
	double max_subsidy_money = 0.0;
	double total_money,dSerial;
	T_t_tif_subsidy subsidy;
	T_t_tif_tradeserial tSerial;
	T_t_aif_account account;
	T_t_tif_meslist tMesList;
	InAcc IA;
	if(amtcmp(in_pack->damt0,0.0) <= 0)
	{
		writelog(LOG_DEBUG,"input money error!");
		return E_INPUT_AMT;
	}

	memset(temp,0,sizeof temp);
	ret = GetParameter(GLOBAL_MAX_PER_SUBSIDY,temp);
	if(ret)
	{
		return ret;
	}
	max_subsidy_money = D4U5(atof(temp),2);
	
	// 流水号
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerial);
	if(ret)
	{
		return ret;
	}
	// 查询卡信息
	ret = do_849008_query(in_pack,&cust_id,&card_id);
	if(ret)
	{
		writelog(LOG_DEBUG,"query customer information error!,ret[%d]",ret);
		return ret;
	}

	// 账户信息
	memset(&account,0,sizeof account);
	ret = DB_t_aif_account_read_by_card_id_and_purse_id(card_id,in_pack->lvol3,&account);
	if(ret)
	{
		// 账户表无信息
		if(DB_NOTFOUND == ret)
			return E_DB_ACCOUNT_N;
		else
			return E_DB_ACCOUNT_R;

	}
	// 生成流水记录
	memset(&tSerial,0,sizeof tSerial);
	writelog(LOG_DEBUG,"cust_id[%d],Serial_no[%d]]",cust_id,in_pack->lvol2);
	ret = do_849008_query_serial(cust_id,in_pack->lvol2,&tSerial);
	if(ret)
	{
		return ret;
	}
	// 认为已经入账成功,直接返回结果
	if(tSerial.serial_no > 0)
	{
		out_pack->lvol0 = tSerial.card_id;
		out_pack->lvol1 = tSerial.serial_no;
		out_pack->lvol2 = tSerial.customer_id;
		out_pack->damt0 = tSerial.trade_fee;
		return 0;
	}
	
	memset(&IA,0,sizeof IA);

	tSerial.serial_no = D2I(dSerial);
	tSerial.serial_type = TXCODE_NETFEE_TRANS; // 网银转账
	tSerial.serial_state = SERISTAT_DEBT;
	des2src(tSerial.oper_code,in_pack->scust_no2);
	des2src(tSerial.operate_date,in_pack->sdate0);
	des2src(tSerial.operate_time,in_pack->stime0);
	GetLogicDate(tSerial.enteract_date);
	getsystime(tSerial.enteract_time);
	getsysdate(tSerial.collect_date);
	des2src(tSerial.collect_time,tSerial.enteract_time);
	tSerial.customer_id = cust_id;
	tSerial.card_id = card_id;
	tSerial.in_balance = 0.0;
	tSerial.out_balance = 0.0;
	tSerial.trade_fee = in_pack->damt0;
	tSerial.other_seri_no = in_pack->lvol2; // 银行端流水号

	if(account.current_state >= ACCOUNTSTAT_LOGOUT)
	{
		// 个人账户已经注销
		if(online_tx)
			return E_ACTNO_LOGOUT;
		// 借记 银行存款 贷记 营业成本
		des2src(IA.sArrInActno[3],"1021");
		IA.dArrInAmt[1] = tSerial.trade_fee;
	}
	else
	{
		// 个人账户号
		des2src(IA.sArrInActno[0],account.account_id);
		IA.dArrInAmt[0] = tSerial.trade_fee;
	}
	IA.iFeeType=1;
	ret = process(&IA,&tSerial);
	if(ret)
	{
		writelog(LOG_ERR,"入账失败,cust_id[%d],card_id[%d],ret[%d]"
				 ,cust_id,card_id,ret);
		return ret;
	}

	ret = DB_t_tif_tradeserial_add(&tSerial);
	if(ret)
	{
		writelog(LOG_ERR,"记录流水失败");
		return E_DB_TRADESERIAL_I;
	}
	// 先入账 
	total_money = 0.0;
	count = 0;
	memset(&subsidy,0,sizeof subsidy);
	subsidy.cust_no = cust_id;
	getsysdatetime(subsidy.batch_no);
	des2src(subsidy.oper_code,tSerial.oper_code);
	strcpy(subsidy.summary,"网银转账");
	strcpy(subsidy.expire_date,"20500101");
	subsidy.bill_type = TYPE_CASH;
	subsidy.card_no = card_id;
	des2src(subsidy.tx_date,tSerial.operate_date);
	des2src(subsidy.tx_time,tSerial.operate_time);
	subsidy.status[0] = SUBSIDY_STAT_NORMAL;
	strcpy(subsidy.subsidytype,"1");
    subsidy.amount = D4U5(in_pack->damt0 - total_money,2);
	if(amtcmp(subsidy.amount,0.0) <= 0)
	{
			// 剩余金额为 0, 不可能出现小于 0
	//		break;
	
		ret=E_MOBILE_TRANS_ZERO;
		return ret;
			
	}
	else if(amtcmp(subsidy.amount,max_subsidy_money) > 0.0)
	{
			// 单笔金额不能大于最大值
		//subsidy.amount = max_subsidy_money;
		ret=E_MOBILE_TRANS_MAX;
		return ret;
	}

	total_money = D4U5(total_money+subsidy.amount,2);

	ret = calc_card_max_subsidy_no(cust_id,card_id,&subsidy_no);
	if(ret)
	{
		writelog(LOG_DEBUG,"cannot calculate max subsidy NO,cust[%d],card[%d],ret[%d]",
				 cust_id,card_id,ret);
		return ret;
	}
	subsidy.subsidy_no = subsidy_no;
	ret = DB_t_tif_subsidy_add(&subsidy);
	if(ret)
	{
		// 记录信息失败
		if(DB_REPEAT == ret)
			return E_DB_SUBSIDY_E;
		else
			return E_DB_SUBSIDY_I;
	}

	out_pack->lvol0 = card_id;
	out_pack->lvol1 = tSerial.serial_no;
	out_pack->lvol2 = tSerial.customer_id;
	out_pack->damt0 = tSerial.trade_fee;
	return 0;	
}
Beispiel #21
0
int F847106(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int i=0;
	int ret =0;
	char logicdate[11]="";										//业务日期
	char sysdate[11]="";
	char systime[9]="";
	int	type=0;
	InAcc	IA;
	double dSerialNo = 0;
	int card_id=0;
	char physical_no[41]="";
	char sMaxCardBalance[20]="";
	char sMsg[256]="";
	double dMaxCardBalance=0;
	T_t_tif_tradeserial  tradeserial;
	T_t_pif_card		tCard;
	T_t_tif_savdtl		tSavdtl;
	T_t_cif_customer tCustomer;
	T_t_pif_spefee 	tSpeFee;
	T_t_aif_account	tAccount;		//帐户表

	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	memset(&tSavdtl,0,sizeof(tSavdtl));
	memset(&tCard,0,sizeof(tCard));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tSpeFee,0,sizeof(tSpeFee));
	memset(&IA,0,sizeof(IA));

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LSERIAL1,F_DAMT2,F_DAMT3,F_VSMESS,0);
	if(amtcmp(rPack->damt0,0)<=0)
	{
		*pRetCode=E_INPUT_AMT;
		goto L_RETU;
	}
	if(amtcmp(rPack->damt1,0)<0)
	{
		*pRetCode=E_INPUT_CARD_BALA;
		goto L_RETU;
	}
	if(rPack->lvol10<1)
	{
		*pRetCode=E_INPUT_CARD_TXCNT;
		goto L_RETU;
	}
	card_id=rPack->lvol0;
	tradeserial.trade_fee = rPack->damt0;					//充值金额
	des2src(physical_no, rPack->sbank_acc);				//物理卡号
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);							//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	ret=DB_t_pif_card_read_by_card_id(card_id, &tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			*pRetCode=E_CARDNO_NOT_EXIST;
		else
			*pRetCode=E_DB_CARD_R;
		goto L_RETU;
	}
	if(strncmp(tCard.state_id,CARDSTAT_REG,4)!=0)
	{
		if('2'==tCard.state_id[CARDSTAT_TYPE_REG])
			*pRetCode = E_CARDNO_LOGOUT;
		else if('3'==tCard.state_id[CARDSTAT_TYPE_REG])
			*pRetCode = E_CARD_CHANGE;
		else if(tCard.state_id[CARDSTAT_TYPE_LOST]==STATE_TRUE)
			*pRetCode=E_CARDNO_LOST;
		else if(tCard.state_id[CARDSTAT_TYPE_FREEZE]==STATE_TRUE)
			*pRetCode=E_CARDNO_FREEZE;
		else if(tCard.state_id[CARDSTAT_TYPE_WFAIL]==STATE_TRUE)
			*pRetCode=E_CARDNO_WFAIL;
		goto L_RETU;
	}
	trim(physical_no);
	trim(tCard.physical_no);
	if(strcmp(tCard.physical_no,physical_no)!=0)
	{
		writelog(LOG_ERR,"db physical_no[%s],input physical_no[%s]",tCard.physical_no,physical_no);
		*pRetCode= E_CARD_PHYNO_DIFFER;
		goto L_RETU;
	}
	//根据卡号和钱包号得到消费者账号(借方)
	ret=DB_t_aif_account_read_by_card_id_and_purse_id(card_id, PURSE_NO_ONE,&tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_aif_account_read_by_card_id_and_purse_id ret[%d]card_id[%d]",ret,card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode=E_ACTNO_NOT_EXIST;
		else
			*pRetCode=E_DB_ACCOUNT_R;
		goto L_RETU;
	}
	ret=GetParameter(GLOBE_MAXCARDBALANCE,sMaxCardBalance);
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	dMaxCardBalance=atof(sMaxCardBalance);

	if(amtcmp(tAccount.cur_bala+tradeserial.trade_fee,dMaxCardBalance)>0)
	{
		*pRetCode= E_AMT_EXCEED_MAX;
		goto L_RETU;
	}
	ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(tCard.cosumer_id, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",tCard.cosumer_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode= E_DB_CUSTOMER_R;
		goto L_RETU;
	}
	//得到收费类别
	if(0==tCustomer.fee_type)
	{
		ret=DB_t_pif_spefee_read_by_dept_code_and_cut_type(tCustomer.classdept_no, tCustomer.cut_type,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.fee_type=tCustomer.cut_type;
			}
			else
			{
				DB_t_cif_customer_free_lock_cur();
				*pRetCode=E_DB_SPEFEE_R;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.fee_type=tSpeFee.fee_type;
		}
		//更新客户表的收费类别字段
		ret=DB_t_cif_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode= E_CUSTOMER_NOT_EXIST;
			else
				*pRetCode= E_DB_CUSTOMER_U;
			goto L_RETU;
		}
	}
	DB_t_cif_customer_free_lock_cur();
	type=rPack->lvol4;										//交易类型
	IA.dArrInAmt[0]=tradeserial.trade_fee;
	switch(type)
	{
		case TYPE_CASH:	//现金
			IA.iArrInFeeSwitch[1]=1;
			break;
		case TYPE_BILL:	//支票
			IA.iArrInFeeSwitch[2]=1;
			break;
		case TYPE_FUNDBOOK:	//经费本
			IA.iArrInFeeSwitch[3]=1;
			break;
		default:
			*pRetCode=E_INPUT_DEPOSIT_TYPE;
			goto L_RETU;
	}
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialNo);  					//获得最大流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR," ERRCODE = [%d]",ret);
		goto L_RETU;
	}
	tradeserial.serial_no = D2I(dSerialNo);											//流水号
	tradeserial.other_seri_no = 0;															//上传端流水号
	tradeserial.serial_type = TXCODE_SAVING_CASH;
	tradeserial.serial_state = SERISTAT_DEBT;												//流水状态
	des2src(tradeserial.operate_date,sysdate);											//发生日期
	des2src(tradeserial.operate_time,systime);											//发生时间
	des2src(tradeserial.collect_date,sysdate);												//采集日期
	des2src(tradeserial.collect_time,systime);												//采集时间
	des2src(tradeserial.enteract_date,logicdate);											//处理日期
	des2src(tradeserial.enteract_time,systime);											//处理时间
	tradeserial.maindevice_id = rPack->lvol6;												//上传工作站标识
	tradeserial.device_id = rPack->lvol7;													//采集设备标识
	tradeserial.card_id =card_id;														//卡号
	tradeserial.purse_id = rPack->lvol1;													//钱包号
	//tradeserial.customer_id = rPack->lvol2;													//客户标识
	tradeserial.customer_id = tCustomer.cut_id;
	tradeserial.in_balance=rPack->damt1;
	tradeserial.trade_count=rPack->lvol10+1;		//交易次数
	Strncpy_t(tradeserial.oper_code , rPack->scust_limit, sizeof(tradeserial.oper_code));		//操作员代码
	tradeserial.sys_id = 0;																//外部系统标识
	switch(type)
	{
		case TYPE_CASH:		//现金
			break;
 		case TYPE_BILL:		//支票
		case TYPE_FUNDBOOK:	//经费本
		case TYPE_OTHER:	//其他
 			tSavdtl.amount=rPack->damt0;				//发生额
 			if(amtcmp(tSavdtl.amount,0)<=0)
				break;
			des2src(tSavdtl.bill_no,rPack->sphone);		//票据号码
			if(strlen(tSavdtl.bill_no)<1)
			{
				*pRetCode=E_INPUT_BILLNO;
				goto L_RETU;
			}
			tSavdtl.card_no=tCard.card_id;				//卡号
			des2src(tSavdtl.oper_no,rPack->scust_limit);	//操作员
			tSavdtl.seqno=tradeserial.serial_no;			//流水号
			des2src(tSavdtl.tx_date,sysdate);			//发生日期
			des2src(tSavdtl.tx_time,systime);			//发生时间
			tSavdtl.cnt=1;								//票据数量
			tSavdtl.bill_type=type;						//票据类型
			tSavdtl.tx_code=tradeserial.serial_type;		//交易码
			ret=DB_t_tif_savdtl_add(&tSavdtl);
			if(ret)
			{
				if(DB_REPEAT==ret)
					*pRetCode = E_DB_SAVDTL_E;
				else
					*pRetCode = E_DB_SAVDTL_I;
				goto L_RETU;
			}
			break;
		default:
			*pRetCode=E_TXCODE_NOT_EXIST;
			goto L_RETU;
	}
	des2src(IA.sArrInActno[0],tAccount.account_id);						//帐户
	IA.iCardNo=tCard.card_id;
	IA.iFeeType=tCustomer.fee_type;
	IA.dArrInAmt[0]=tradeserial.trade_fee;

	IA.iArrInFeeSwitch[0]=rPack->lvol0;
	IA.iArrInFeeSwitch[5]=rPack->lvol5;
	IA.iArrInFeeSwitch[6]=rPack->lvol6;
	IA.iArrInFeeSwitch[7]=rPack->lvol7;
	IA.iArrInFeeSwitch[8]=rPack->lvol8;
	IA.iArrInFeeSwitch[9]=rPack->lvol9;
	IA.iArrInFeeSwitch[10]=rPack->lvol10;

	ret=process(&IA,&tradeserial);
	if(ret)
	{
		writelog(LOG_ERR,"process ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d 卡号:%d ",IA.iSerialNo,IA.iCardNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		switch(IA.iArrOutTxType[i])
		{
			case TXTYPE_TOLL_DEPOSIT:
			case TXTYPE_TOLL_DEPOSIT_BILL:
			case TXTYPE_TOLL_DEPOSIT_FUNDBOOK:
			case TXTYPE_DEDUCT_DEPOSIT:
			case TXTYPE_RETURN_DEPOSIT:
				tradeserial.deposit_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_PRE_TOLL_BOARD:
			case TXTYPE_PRE_TOLL_BOARD_BILL:
			case TXTYPE_PRE_TOLL_BOARD_FUNDBOOK:
			case TXTYPE_TOLL_BOARD:
			case TXTYPE_DEDUCT_BOARD:
			case TXTYPE_RETURN_BOARD:
			case TXTYPE_RETURN_BOARD_BILL:
			case TXTYPE_RETURN_BOARD_FUNDBOOK:
			case TXTYPE_PRE_TOLL_MANAGE:
				tradeserial.boardfee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CHARGE:
			case TXTYPE_TOLL_CHARGE_BILL:
			case TXTYPE_TOLL_CHARGE_FUNDBOOK:
				tradeserial.in_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CARDCOST:
			case TXTYPE_TOLL_CARDCOST_BILL:
			case TXTYPE_TOLL_CARDCOST_FUNDBOOK:
				tradeserial.cost_fee=IA.dArrOutAmt[i];
				break;
			default:
				break;
		}
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	sprintf(sMsg,"充值前卡余额:%.2lf元 卡当前余额:%.2lf元",tradeserial.in_balance,tradeserial.out_balance);
	strcat(out_pack->vsmess,sMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	if(amtcmp(tradeserial.out_balance,0)<0)
	{
		*pRetCode=E_ENTER_ACCOUNT;
		goto L_RETU;
	}
	out_pack->damt2=tradeserial.out_balance;		//出卡值
	out_pack->damt3=tradeserial.boardfee;			//搭伙费
	out_pack->lserial1=tradeserial.serial_no;			//流水号
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #22
0
int F847121(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	char logicdate[11]="";
	char sysdate[11]="";
	char systime[9]="";
	double dSerialno=0;
	int cardno=0;
	char cardphyid[16+1]="";

	T_t_card tCard;
	T_t_tif_tradeserial tTradeserial;

	memset(&tCard,0,sizeof(tCard));
	memset(&tTradeserial,0,sizeof(tTradeserial));

	cardno=rPack->lvol0;
	des2src(cardphyid,rPack->sbank_acc);

	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	trim(rPack->scust_limit);
	trim(rPack->scust_limit2);
	trim(rPack->semp_pwd);
	/*
	if(rPack->lvol2!=IS_NO)
	{
		if(strlen(rPack->scust_limit)==0)
		{
			*pRetCode=E_OPER_NOT_EXIST;
			goto L_RETU;
		}
		if(strlen(rPack->scust_limit2)==0)
		{
			*pRetCode=E_INPUT_AUTH_OPER_NULL;
			goto L_RETU;
		}
		if(strcmp(rPack->scust_limit,rPack->scust_limit2)==0)
		{
			writelog(LOG_ERR,"oper[%s]auth_oper[%s]",rPack->scust_limit,rPack->scust_limit2);
			*pRetCode=E_OPER_AND_AUTH_OPER_EQ;
			goto L_RETU;
		}
		ret=chk_oper_pwd(rPack->scust_limit2,rPack->semp_pwd);
		if(ret)
		{
			if(E_OPER_NOT_EXIST==ret)
				*pRetCode=E_AUTH_OPER_NOT_EXIST;
			else if(E_PASSWORD_WRONG==ret)
				*pRetCode=E_AUTH_OPER_PWD;
			else
				*pRetCode=ret;
			goto L_RETU;
		}
	}
	*/
	trim(rPack->scust_no);
	ret=IsInvalidDateTime(rPack->sdate0, "YYYYMMDD");
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	//判断卡状态是否为写卡未成功状态
	if(cardno==0)
	{
		ret=get_cardno_by_physical_no(&cardno,cardphyid);
		if(ret)
		{
			*pRetCode= E_CARDNO_NOT_EXIST;
			writelog(LOG_ERR,"get_cardno_by_physical_no error,ret=[%d] cardphyid=[%s]",ret,cardphyid);
			goto L_RETU;
		}
	}

	ret=DB_t_card_read_lock_by_cur_and_cardno(cardno, &tCard);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",cardno);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_R;
		goto L_RETU;
	}
	if('2'==tCard.cardattr[CARDSTAT_TYPE_REG])
	{
		DB_t_card_free_lock_by_cur();
		*pRetCode=E_CARD_CLOSE;
		goto L_RETU;
	}
//		if('3'==tCard.cardattr[CARDSTAT_TYPE_REG])
//		{
//			DB_t_card_free_lock_by_cur();
//			*pRetCode=E_CARD_CHANGE;
//			goto L_RETU;
//		}
	trim(rPack->scust_no);
//		if(strlen(rPack->scust_no)!=0)
//		{
//			if(strcmp(tCard.showid,rPack->scust_no)!=0)
//			{
//				ret=IsExistShowCardNo(rPack->scust_no);
//				if(ret)
//				{
//					DB_t_card_free_lock_by_cur();
//					writelog(LOG_ERR,"showcardno[%s]",rPack->scust_no);
//					*pRetCode=ret;
//					goto L_RETU;
//				}
//			}
//		}
	trim(rPack->sbank_acc);
	if(strcmp(tCard.cardphyid,rPack->sbank_acc)!=0)
	{
		DB_t_card_free_lock_by_cur();
		writelog(LOG_ERR,"db cardphyid[%s],input cardphyid[%s]",tCard.cardphyid,rPack->sbank_acc);
		*pRetCode= E_CARD_PHYNO_DIFFER;
		goto L_RETU;
	}
	if(strlen(rPack->scust_no)==10)
		des2src(tCard.showid,rPack->scust_no);
	if(strlen(rPack->sdate0)==8)
		des2src(tCard.endtime,rPack->sdate0);
	ret=DB_t_card_update_lock_by_cur(&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",cardno);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CARDNO_NOT_EXIST;
		else
			*pRetCode= E_DB_CARD_U;
		goto L_RETU;
	}
	DB_t_card_free_lock_by_cur();
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialno);  				//获得流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret [%d]",ret);
		goto L_RETU;
	}
	tTradeserial.serial_no = D2I(dSerialno);											//流水号
	tTradeserial.other_seri_no = 0;												//上传端流水号
	tTradeserial.serial_type = 847121;												//交易代码;备注:发卡+充值 用一个交易码,即847101; 发卡(不充值)另用一个交易码,即新的发卡程序文件名,从而区分发卡充值与发卡不充值的卡操作信息。
	tTradeserial.serial_state = SERISTAT_DEBT;										//流水状态
	des2src(tTradeserial.operate_date,sysdate);									//发生日期
	des2src(tTradeserial.operate_time,systime);									//发生时间
	des2src(tTradeserial.collect_date,sysdate);										//采集日期
	des2src(tTradeserial.collect_time,systime);										//采集时间
	des2src(tTradeserial.enteract_date,logicdate);									//处理日期
	des2src(tTradeserial.enteract_time,systime);									//处理时间
	des2src(tTradeserial.opercode , rPack->scust_limit);
	tTradeserial.maindeviceid = rPack->lvol6;										//上传工作站标识
	tTradeserial.deviceid = rPack->lvol7;											//采集设备标识
	tTradeserial.cardno = tCard.cardno;											//卡号
	des2src(tTradeserial.showid,tCard.showid);										//显示卡号
	tTradeserial.purseno = PURSE_NO_ONE;										//钱包号
	tTradeserial.custid = tCard.custid;									//客户标识
//	tTradeserial.reviseserial_no=dSerialno;											//原写卡失败流水号
	des2src(tTradeserial.reserve_1,rPack->scust_limit2);							//授权操作员号
	des2src(tTradeserial.reserve_2,rPack->semp_pwd);								//授权操作员密码
	if(rPack->lvol2!=IS_NO)
	{
		// 如果写卡余额
		tTradeserial.in_balance = rPack->damt0;
		tTradeserial.out_balance = rPack->damt1;
		tTradeserial.trade_fee = rPack->damt1 - rPack->damt0;
		tTradeserial.trade_count = rPack->lvol1+1;
	}
	//	插入交易流水表
	ret = DB_t_tif_tradeserial_add(&tTradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	return 0;
L_RETU:
	return -1;
}
Beispiel #23
0
int F847183(TRUSERID *handle, int iRequest, ST_PACK *rPack, int *pRetCode, char *szMsg)
{

	int ret = 0;
	char    	tx_date[8+1] = "";              	//发生日期
//		char    	tx_time[6+1]="";      		//发生时间
	int		card_no = 0;                    	//卡号
	char    	device_id[8+1] = "";            	//终端机ID
	int		serial_no = 0;                  	//终端机流水号
	int 		flag = 0;
	double 	dUniqno = 0;
	T_t_tif_tradeserial		tOldTradeserial;	//当日流水表
	T_t_tif_tradeserial		tTradeserial;	//当日流水表
	T_t_tif_tradeserial_his	tTradeserialhis;	//历史流水表
	T_t_pif_tradecode tTradeCode;
	T_t_pif_card tCard;
	RevAcc revAcc;
	char sysdate[11] = "";
	char systime[9] = "";
	char sYear[5] = "";
	char sMonDay[5] = "";
	char logic_date[9] = "";
	int days = 0;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	ResetNormalCPack(&aPack, 0, 1);
	memset(&tTradeserial, 0, sizeof(tTradeserial));
	memset(&tOldTradeserial, 0, sizeof(tOldTradeserial));
	memset(&tTradeserialhis, 0, sizeof(tTradeserialhis));
	memset(&tTradeCode, 0, sizeof tTradeCode);
	memset(&tCard, 0, sizeof tCard);
	memset(&revAcc,0,sizeof revAcc);
	getsysdate(sysdate);
	getsystime(systime);
	des2src(tTradeserial.enteract_time, systime);

	//取流水号,入帐处理
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL, &dUniqno);
	if (ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR, "getNewUniqNo err[%d]", ret);
		goto L_RETU;
	}
	if(db_commit())
		return E_DB_COMMIT;
	
	writelog(LOG_ERR,"getNewUniqNo[%d]",D2I(dUniqno));
	des2src(tx_date, rPack->sbank_pwd);
//		des2src(tx_time,rPack->sbank_code);
	card_no = rPack->lvol0;
	des2src(device_id, rPack->sbank_pwd2);
	serial_no = rPack->lvol1;
	trim(rPack->scust_limit);
	trim(rPack->scust_limit2);
	trim(rPack->semp_pwd);
	des2src(sYear, tx_date);
	des2src(sMonDay, tx_date + 4);

	if (strlen(rPack->scust_limit) == 0)
	{
		*pRetCode = E_OPER_NOT_EXIST;
		goto L_RETU;
	}
	if (strlen(rPack->scust_limit2) == 0)
	{
		*pRetCode = E_INPUT_AUTH_OPER_NULL;
		goto L_RETU;
	}
	if (strcmp(rPack->scust_limit, rPack->scust_limit2) == 0)
	{
		writelog(LOG_ERR, "oper[%s]auth_oper[%s]", rPack->scust_limit, rPack->scust_limit2);
		*pRetCode = E_OPER_AND_AUTH_OPER_EQ;
		goto L_RETU;
	}
	ret = chk_oper_pwd(rPack->scust_limit2, rPack->semp_pwd);
	if (ret)
	{
		if (E_OPER_NOT_EXIST == ret)
			*pRetCode = E_AUTH_OPER_NOT_EXIST;
		else if (E_PASSWORD_WRONG == ret)
			*pRetCode = E_AUTH_OPER_PWD;
		else
			*pRetCode = ret;
		goto L_RETU;
	}
	ret = DB_t_pif_card_read_by_card_id(card_no, &tCard);
	if (ret)
	{
		if (DB_NOTFOUND == ret)
			*pRetCode = E_CARDNO_NOT_EXIST;
		else
			*pRetCode = E_DB_CARD_R;
		goto L_RETU;
	}
	if (tCard.state_id[CARDSTAT_TYPE_REG] == '2')
	{
		writelog(LOG_ERR, "冲正交易卡号已注销cardid[%d]", tCard.card_id);
		*pRetCode = E_ACTNO_LOGOUT;
		goto L_RETU;
	}
	//查询当前流水表
//	ret = DB_t_tif_tradeserial_read_lock_by_c4_and_operate_date_and_serial_no_and_card_id(tx_date, serial_no, card_no, &tOldTradeserial);
//	ret = DB_t_tif_tradeserial_read_lock_by_cur_and_serial_no(serial_no,&tOldTradeserial);
	ret = DB_t_tif_tradeserial_read_by_serial_no(serial_no,&tOldTradeserial);
	writelog(LOG_ERR, "tradeserial tx_date[%s]serial_no[%d]ret[%d]", tx_date, serial_no, ret);
	if (ret)
	{
		if (DB_NOTFOUND != ret)
		{
			*pRetCode = E_DB_TRADESERIAL_R;
			goto L_RETU;
		}
	}
	else
	{
		// 如果入账日期相同,表示同一笔流水
		if(strcmp(tOldTradeserial.enteract_date,tx_date) == 0)
		{
			flag = 1;
			memcpy(&tTradeserial, &tOldTradeserial, sizeof(tTradeserial));
			//上传端流水号
			tTradeserial.other_seri_no = tOldTradeserial.serial_no;	
			des2src(tTradeserial.reserve_1, tOldTradeserial.enteract_date);
			/*
			tOldTradeserial.serial_state = SERISTAT_RUSH;				//冲正
			ret = DB_t_tif_tradeserial_update_lock_by_cur(&tOldTradeserial);
			if (ret)
			{
				*pRetCode = E_DB_TRADESERIAL_U;
				writelog(LOG_ERR, "DB_t_tif_tradeserial_update_lock_by_c4[%d]", ret);
				goto L_RETU;
			}
			DB_t_tif_tradeserial_free_lock_cur();
			*/
			revAcc.iSerialNo= tOldTradeserial.serial_no;
			des2src(revAcc.sTxAccDate,tOldTradeserial.enteract_date);
		//	des2src(revAcc.sTxDate,tOldTradeserial.operate_date);
		}
	}
	if (!flag)
	{
		//查询历史流水表
//		ret = DB_t_tif_tradeserial_his_read_lock_by_c0_and_trans_year_and_trans_mon_day_and_serial_no_and_card_id(sYear, sMonDay, serial_no, card_no, &tTradeserialhis);
//		ret = DB_t_tif_tradeserial_his_read_lock_by_c1_and_enteract_date_and_serial_no(
		ret = DB_t_tif_tradeserial_his_read_by_bak_date_and_serial_no(
			tx_date,serial_no,&tTradeserialhis);
		writelog(LOG_ERR, "tradeserial_his enteract_date[%s]serialno[%d]ret[%d]", tx_date, serial_no, ret);
		if (ret)
		{
			if (DB_NOTFOUND == ret)
			{
				*pRetCode = E_SERIALNO_NOT_EXIST;
				goto L_RETU;
			}
			else
			{
				*pRetCode = E_DB_TRADESERIAL_R;
				goto L_RETU;
			}
		}
		tTradeserial.other_seri_no = tTradeserialhis.serial_no;					
		des2src(tTradeserial.reserve_1, tTradeserialhis.enteract_date);			// 被冲正的流水的入账日期
		tTradeserial.serial_state = tTradeserialhis.serial_state;				//流水状态
		tTradeserial.tmark = tTradeserialhis.tmark;								//999交易标记
		tTradeserial.maindevice_id = tTradeserialhis.maindevice_id;				//上传工作站标识(前置机注册号)
		tTradeserial.sys_id = tTradeserialhis.sys_id;
		tTradeserial.comu_ver = tTradeserialhis.comu_ver;						//通信版本号
		
		tTradeserial.device_id = tTradeserialhis.device_id;
		des2src(tTradeserial.devphy999_id, tTradeserialhis.devphy999_id);		//物理设备ID
		des2src(tTradeserial.dev_auth, tTradeserialhis.dev_auth);				//终端设备授权号
		des2src(tTradeserial.crc, tTradeserialhis.crc);							//CRC校验
		tTradeserial.card_id = tTradeserialhis.card_id;							//交易卡号
		tTradeserial.purse_id = tTradeserialhis.purse_id;						//消费钱包号
		tTradeserial.in_balance = tTradeserialhis.in_balance;					//入卡金额
		tTradeserial.out_balance = tTradeserialhis.out_balance;					//出卡金额
		tTradeserial.trade_fee = tTradeserialhis.trade_fee;						//本次消费金额
		tTradeserial.trade_count = tTradeserialhis.trade_count;					//当前卡中帐户消费次数(累计使用次数)
		tTradeserial.serial_type = tTradeserialhis.serial_type;					//交易代码
		tTradeserial.boardfee = tTradeserialhis.boardfee;						//搭伙费
		des2src(tTradeserial.operate_date, tTradeserialhis.operate_date);		//发生日期(格式化输入的日期)
		des2src(tTradeserial.operate_time, tTradeserialhis.operate_time);		//发生时间(格式化输入的时间)
		// 历史入账日期
		des2src(tTradeserial.enteract_date,tTradeserialhis.enteract_date);
		tTradeserial.condition_id = tTradeserialhis.condition_id;				// 收费科目
		
		// 保存被冲正交易的操作员号
		//des2src(tTradeserial.oper_code, tTradeserialhis.oper_code);
		tTradeserial.customer_id = tTradeserialhis.customer_id;
		/*
		tTradeserialhis.serial_state = SERISTAT_RUSH;							//冲正
		ret = DB_t_tif_tradeserial_his_update_lock_by_c1(&tTradeserialhis);
		if (ret)
		{
			*pRetCode = E_DB_TRADESERIAL_U;
			writelog(LOG_ERR, "DB_t_tif_tradeserial_update_lock_by_c1[%d]", ret);
			goto L_RETU;
		}
		DB_t_tif_tradeserial_his_free_lock_by_c1();		
		*/
		revAcc.iSerialNo = tTradeserialhis.serial_no;
		des2src(revAcc.sTxAccDate,tTradeserialhis.enteract_date);
	//	des2src(revAcc.sTxDate,tTradeserialhis.operate_date);
	}
	
	if (tTradeserial.card_id != card_no)
	{
		writelog(LOG_ERR, "流水中卡号不符cardid[%d]serial[%d]", card_no, tTradeserial.card_id);
		*pRetCode = E_SERIALNO_NOT_EXIST;
		goto L_RETU;
	}
	if (tTradeserial.serial_state == SERISTAT_RUSH)
	{
		*pRetCode = E_TX_SERIAL_CZ;
		goto L_RETU;
	}
	if (tTradeserial.serial_state != SERISTAT_DEBT)
	{
		*pRetCode = E_TX_SERIAL_CANNOT_CZ;
		goto L_RETU;
	}
	/*
	if (amtcmp(tTradeserial.trade_fee, 0) <= 0)
	{
		*pRetCode = E_TX_SERIAL_CANNOT_CZ;
		strcpy(szMsg,"交易金额有误!");
		goto L_RETU;
	}
	*/
	ret = DB_t_pif_tradecode_read_by_tradecode(tTradeserial.serial_type, &tTradeCode);
	if (ret)
	{
		if (DB_NOTFOUND == ret)
		{
			writelog(LOG_ERR,"补冲正交易码[%d]不存在",tTradeserial.serial_type);
			*pRetCode = E_DB_TRADECODE_N;
		}
		else
			*pRetCode = E_DB_TRADECODE_R;
		goto L_RETU;
	}

	if (strcmp(tTradeCode.flag,TYPE_YES) != 0)
	{
		*pRetCode = E_TX_SERIAL_CANNOT_CZ;
		goto L_RETU;
	}

	ret = GetLogicDate(logic_date);						//业务日期
	if (ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR, "GetLogicDate  err ret[%d]", ret);
		goto L_RETU;
	}
	/*// 小于 0 , 则不判断
	if (tTradeCode.rush_max_day >= 0)
	{
		ret = DiffDay(logic_date, tTradeserial.enteract_date, &days);
		if (ret)
		{
			writelog(LOG_ERR,"ret[%d]date1[%s]date2[%s]",ret,
					 logic_date,tTradeserial.enteract_date);
			*pRetCode = ret;
			goto L_RETU;
		}
		writelog(LOG_DEBUG,"tradecode[%d]max day[%d]diff day[%d]",tTradeCode.tradecode
				 ,tTradeCode.rush_max_day,days);
		if (days > tTradeCode.rush_max_day)
		{
			writelog(LOG_ERR, "流水入账日期[%s],已超过期限[%d]天",
					 tTradeserial.enteract_date, days-tTradeCode.rush_max_day);
			*pRetCode = E_TX_SERIAL_CANNOT_CZ;
			strcpy(szMsg, "流水入账日期已超过可冲正期限!");
			goto L_RETU;
		}
	}

	if (tTradeCode.restrict_oper == IS_YES)
	{
		if (strcmp(rPack->scust_limit, tTradeserial.oper_code) != 0)
		{
			strcpy(szMsg, "必须由作此次交易的操作员来冲正");
			*pRetCode = E_TX_SERIAL_CANNOT_CZ;
			goto L_RETU;
		}
	}
	*/
	des2src(revAcc.sMdeOper, rPack->scust_limit);
	des2src(revAcc.sChkOper,rPack->scust_limit2);
	des2src(revAcc.sTxDate,sysdate);
	des2src(revAcc.sTxTime,systime);
	
	des2src(tTradeserial.operate_date, sysdate);
	des2src(tTradeserial.operate_time, systime);
	des2src(tTradeserial.collect_date, sysdate);
	des2src(tTradeserial.collect_time, systime);
	des2src(tTradeserial.enteract_date, logic_date);						//业务日期
	des2src(tTradeserial.enteract_time, systime);

	/////有卡冲正
	if(rPack->lvol3)
	{
		if(rPack->lvol10 <=0)			//交易次数
			return E_INPUT_CARD_TXCNT;
		
		revAcc.iUseCardFlag = USE_CARD_TYPE_ONLINE;
		revAcc.iTradeCnt = rPack->lvol10 + 1;
		revAcc.dInCardBala = rPack->damt1;		//有卡冲正,卡片上余额
		tTradeserial.in_balance = rPack->damt1;			
		tTradeserial.trade_count = rPack->lvol10 + 1;        //交易次数增加
	}
	else												//使用流水的出卡值作为冲正流水的入卡值
	{
		revAcc.iUseCardFlag = USE_CARD_TYPE_NULL;
		tTradeserial.in_balance = tTradeserial.out_balance ;
		revAcc.dInCardBala = tTradeserial.in_balance;
		revAcc.iTradeCnt = tTradeserial.trade_count;
	}

	revAcc.dOutCardBala=revAcc.dInCardBala;						//在冲正模块中计算出卡值
	tTradeserial.trade_fee = -1 * tTradeserial.trade_fee;					//本次消费金额
	tTradeserial.boardfee = -1 * tTradeserial.boardfee;					//本次消费管理费
	tTradeserial.maindevice_id = rPack->lvol6;
	tTradeserial.device_id = 0;
	revAcc.maindevice_id = tTradeserial.maindevice_id;
	// 上传的操作员号
	des2src(tTradeserial.oper_code, rPack->scust_limit);
	tTradeserial.reviseserial_no = tTradeserial.other_seri_no;

	tTradeserial.serial_no = D2I(dUniqno);
	
	switch (tTradeserial.serial_type)
	{
	case 847106: // 现金充值冲正
		
		ret = process847106(&tTradeserial);		// 不是现金充值,不能冲正
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		break;
	default:
		break;
	}
	
	//######################################################
	//入账处理

	revAcc.iRevSeriNo = tTradeserial.serial_no;
	revAcc.iTradeNo = tTradeserial.serial_type;
	ret = ReverseProcess(&revAcc);
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR, "ReverseProcess err[%d]", ret);
		goto L_RETU;
	}
	
	//######################################################
	//添加交易流水
	tTradeserial.serial_type = TXCODE_TX_REVEAL;		//交易代码记录为冲正
	tTradeserial.serial_state = SERISTAT_DEBT;
	tTradeserial.out_balance = revAcc.dOutCardBala;
	tTradeserial.tmark = 254;
	ret = DB_t_tif_tradeserial_add(&tTradeserial);
	writelog(LOG_ERR, "DB_t_tif_tradeserial_add ret[%d]", ret);
	if (ret)
	{
		if (DB_REPEAT == ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	if (amtcmp(tTradeserial.out_balance, 0) < 0)
	{
		*pRetCode = E_ENTER_ACCOUNT;
		goto L_RETU;
	}
	if(db_commit())
			return E_DB_COMMIT;

	//更新原来流水的状态
	if(flag == 1)					//更新流水表
	{
		memset(&tOldTradeserial,0,sizeof tOldTradeserial);
		ret = DB_t_tif_tradeserial_read_lock_by_cur_and_serial_no(serial_no,&tOldTradeserial);
		writelog(LOG_ERR, "tradeserial tx_date[%s]serial_no[%d]ret[%d]", tx_date, serial_no, ret);			
		if (ret)
		{
			*pRetCode = E_DB_TRADESERIAL_R;
			goto L_RETU;
			
		}
		tOldTradeserial.serial_state = SERISTAT_RUSH;				//冲正
		ret = DB_t_tif_tradeserial_update_lock_by_cur(&tOldTradeserial);
		if (ret)
		{
			*pRetCode = E_DB_TRADESERIAL_U;
			writelog(LOG_ERR, "DB_t_tif_tradeserial_update_lock_by_c4[%d]", ret);
			goto L_RETU;
		}
		DB_t_tif_tradeserial_free_lock_cur();
	}
	else							//更新历史流水表
	{
		memset(&tTradeserialhis,0,sizeof tTradeserialhis);
		ret = DB_t_tif_tradeserial_his_read_lock_by_c1_and_bak_date_and_serial_no(
			tx_date,serial_no,&tTradeserialhis);
		writelog(LOG_ERR, "tradeserial_his enteract_date[%s]serialno[%d]ret[%d]",tx_date, serial_no, ret);	
		if (ret)
		{		
			*pRetCode = E_DB_TRADESERIAL_R;
			goto L_RETU;			
		}
		tTradeserialhis.serial_state = SERISTAT_RUSH;							//冲正
		ret = DB_t_tif_tradeserial_his_update_lock_by_c1(&tTradeserialhis);
		if (ret)
		{
			*pRetCode = E_DB_TRADESERIAL_U;
			writelog(LOG_ERR, "DB_t_tif_tradeserial_update_lock_by_c1[%d]", ret);
			goto L_RETU;
		}
		DB_t_tif_tradeserial_his_free_lock_by_c1();		
	}
	
	SetCol(handle, 0);
	SetCol(handle, F_LSERIAL1, F_DAMT2, F_DAMT3, F_VSMESS, 0);
	out_pack->lserial1 = tTradeserial.serial_no;
	out_pack->damt2 = tTradeserial.out_balance;
	out_pack->damt3 = -tTradeserial.trade_fee;
	sprintf(out_pack->vsmess, "流水号:%d 冲正金额:%.2lf元,搭伙费:%.2lf元,冲正前卡余额:%.2lf元,卡当前余额:%.2lf元", tTradeserial.serial_no, -tTradeserial.trade_fee,-tTradeserial.boardfee, tTradeserial.in_balance, tTradeserial.out_balance);
	writelog(LOG_DEBUG, out_pack->vsmess);
	PutRow(handle, out_pack, pRetCode, szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #24
0
int F847222(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	char  ia_buf[1024]="";
	char sMsg[256]="";
	double dUniNo;
	InAcc IA;
	T_t_tif_tradeserial serial;
	T_t_aif_account account;
	T_t_cif_shop shop;
	trade_param_t param;
	int shop_id;
	
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	int i;

	ResetNormalCPack(&aPack,0,1);

	shop_id = atoi(rPack->sbank_acc);
	if(shop_id <= 0)
	{
		*pRetCode = E_SHOP_ACTNO_NOT_EXIST;
		goto L_RETU;
	}
	if(strlen(rPack->scard0) <= 0)
	{
		*pRetCode = E_OPER_NOT_EXIST;
		goto L_RETU;
	}
	ret = CheckOperatorPwd(rPack->scard0,rPack->semp_pwd);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	memset(&account,0,sizeof account);
	memset(&shop,0,sizeof shop);
	
	ret = DB_t_cif_shop_read_by_shop_id(shop_id,&shop);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode  = E_SHOP_ACTNO_NOT_EXIST;
		else
			*pRetCode = E_DB_SHOP_R;
		goto L_RETU;
	}
	if(strcmp(shop.is_indep, TYPE_YES))
	{
		*pRetCode = E_FAN_SHOP_NOT_INDEP;
		goto L_RETU;
	}
	memset(&IA,0,sizeof IA);
	memset(&param,0,sizeof param);
	param.pIA = &IA;
	IA.pVoidPointer = ia_buf;
	param.shop_id = shop.shop_id;
	param.remain_balance = rPack->damt1;
	
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniNo);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	param.serial_no = D2I(dUniNo);

	//初始化流水记录
	memset(&serial,0,sizeof serial);
	serial.serial_no = param.serial_no;
	serial.serial_state = SERISTAT_DEBT;
	serial.serial_type = TXCODE_FAN_BALANCE;
	// 借用显示卡号字段保存商户号
	sprintf(serial.showid,"%d",param.shop_id);
	getsysdate(serial.operate_date);
	getsystime(serial.operate_time);
	des2src(serial.collect_date,serial.operate_date);
	des2src(serial.collect_time,serial.operate_time);
	des2src(serial.enteract_date,serial.operate_date);
	des2src(serial.enteract_time,serial.operate_time);

	des2src(serial.oper_code,rPack->scard0);
	des2src(serial.reserve_1,rPack->scert_addr);
	serial.in_balance = param.remain_balance;
	serial.trade_fee = param.remain_balance;

	des2src(param.tx_date,serial.operate_date);
	des2src(param.tx_time,serial.operate_time);
	des2src(param.oper_code,rPack->scard0);
	
	ret = do_parse_shop(&param);
	if(ret)
	{
		writelog(LOG_ERR,"商户解款失败shop[%d] ret [%d]",param.shop_id,ret);
		*pRetCode = ret;
		goto L_RETU;
	}
	
	SetCol(handle,0);
	SetCol(handle,F_VSMESS,F_LVOL1,F_DAMT1,0);
	sprintf(out_pack->vsmess,"流水号:%d ",IA.iSerialNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			//sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			//strcat(out_pack->vsmess,sMsg);
			writelog(LOG_INFO,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
		}
	}
	out_pack->lvol1 = IA.iSerialNo;
	out_pack->damt1 = param.free_balance;
	//strcat(out_pack->vsmess,IA.pVoidPointer);
	writelog(LOG_DEBUG,out_pack->vsmess);
	
	//保存流水
	ret = DB_t_tif_tradeserial_add(&serial);
	if(ret)
	{
		if(DB_REPEAT == ret)
			return E_DB_TRADESERIAL_E;
		else
			return E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
	
L_RETU:
	return -1;
}
Beispiel #25
0
int F847116(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int	hi_cutid = 0;											//客户ID
	int	hi_cuttype = 0;										//客户类型
	int i=0;
	int ret = 0;
	int len = 0;
	char h_showcardid[11] = "";								//显示卡号
	char h_password[7] = "";									//卡密码
	double h_temp_Card_id = 0;								//卡号
	char seed_key[17] = "";									//种子密钥
	char card_endtime[27 + 1] = "";							//卡的有效截至日期
	char logicdate[11]="";
	char sysdate[11]="";
	char systime[9]="";
	char sMsg[256]="";
	char sMaxCardBalance[20]="";
	double dMaxCardBalance=0;
	T_t_cif_customer tCustomer;
	T_t_pif_spefee 	tSpeFee;
	T_t_pif_card tCard;
	T_t_aif_account  tAccount;
	T_t_tif_tradeserial  tradeserial;
	InAcc	IA;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL5,
				F_SCUST_NO,	F_SCUST_NO2,F_SCUST_AUTH,F_SCUST_AUTH2,
				F_SDATE0,F_SNAME,F_SNAME2,
				F_SOPEN_EMP,F_SSTATUS0,
				F_DAMT2,F_DAMT3,F_LSERIAL1,F_VSMESS,0);

	memset(&IA,0,sizeof(IA));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tCard, 0, sizeof(tCard));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&tSpeFee,0,sizeof(tSpeFee));

#ifdef DEBUG
	writelog(LOG_DEBUG,"rPack->damt0[%lf]",rPack->damt0);
	writelog(LOG_DEBUG,"rPack->scust_auth2[%s]",rPack->scust_auth2);
#endif

	hi_cutid = rPack->lvol0;									//客户ID
	hi_cuttype = rPack->lvol3;									//客户类别
	tradeserial.trade_fee=rPack->damt0;					//发生额
	des2src(h_showcardid,rPack->scust_no);					//显示卡号

	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	ret=IsExistShowCardNo(h_showcardid);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	//	检查客户信息,判断是否可以发行临时卡
	ret = IsExistNoLostCardByCustomId(hi_cutid);
	if (ret)
	{
		writelog(LOG_ERR,"hi_cutid[%d]",hi_cutid);
		*pRetCode = ret;
		goto L_RETU;
	}
	des2src(tCard.physical_no, rPack->sbank_acc);				//物理卡号
	ret=IsExistCardByPhyCardNo(tCard.physical_no);			//物理卡号
	if(ret)
	{
		writelog(LOG_ERR,"physical_no[%s]",tCard.physical_no);
		*pRetCode = ret;
		goto L_RETU;
	}
	ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(hi_cutid, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",hi_cutid);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode= E_DB_CUSTOMER_R;
		goto L_RETU;
	}
	//得到收费类别
	if(tCustomer.fee_type<1)
	{
		ret=DB_t_pif_spefee_read_by_dept_code_and_cut_type(tCustomer.classdept_no, tCustomer.cut_type,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.fee_type=tCustomer.cut_type;
			}
			else
			{
				DB_t_cif_customer_free_lock_cur();
				*pRetCode=E_DB_SPEFEE_R;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.fee_type=tSpeFee.fee_type;
		}
		//更新客户表的收费类别字段
		ret=DB_t_cif_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode= E_CUSTOMER_NOT_EXIST;
			else
				*pRetCode= E_DB_CUSTOMER_U;
			goto L_RETU;
		}
	}
	DB_t_cif_customer_free_lock_cur();
	//检查金额是否超过最大额度
	ret=GetParameter(GLOBE_MAXCARDBALANCE,sMaxCardBalance);
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	dMaxCardBalance=atof(sMaxCardBalance);

	if(amtcmp(tradeserial.trade_fee,dMaxCardBalance)>0)
	{
		writelog(LOG_ERR,"tradeserial.trade_fee[%lf]",tradeserial.trade_fee);
		*pRetCode=E_AMT_EXCEED_MAX;
		goto L_RETU;
	}
	//	准备数据插入卡信息表
	memcpy(seed_key,STATIC_SEED_KEY,sizeof(seed_key));						//读种子密钥

	//	默认密码, 初始取身份证的后6位, 没有身份证号用666666.
	trim(rPack->sname2);
	len=strlen(rPack->sname2) ;
	if (len >= 6)
	{
		strncpy(h_password,&(rPack->sname2[len-6]),6);
		if(h_password[5]>'9'||h_password[5]<'0')
			h_password[5]='0';
	}
	else
	{
		strcpy(h_password,"666666");
	}
	ret = getNewUniqNo(KEYTYPE_CARD_ID,&h_temp_Card_id);						//获取最大卡号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret[%d]",ret);
		goto L_RETU;
	}
	tCard.card_id = (int)h_temp_Card_id;											//卡号
	des2src(tCard.showid,h_showcardid);										//显示卡号
	des2src(tCard.is_main,TYPE_YES);  											//是否为主卡
	des2src(tCard.state_id,CARDSTAT_REG);											//卡状态
	tCard.type_id = CT_TEMP;													//卡类别
	EncodePwd(seed_key,h_password,tCard.password,0);							//卡密码
	tCard.cosumer_id = hi_cutid;												//客户标识
	tCard.account_count = ACCOUNT_COUNT_ONE;									//卡对应帐户个数
	des2src(tCard.begin_time,logicdate);											//注册时间

	ret = GetTempCardValiddate(GLOBE_TMPCARDVALIDDATE,logicdate,card_endtime);						//计算卡的有效期
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	des2src(tCard.end_time, card_endtime);										//截至时间
	tCard.phytype = PHYTYPE_NO_ONE;											//设备物理型号;默认为1

	//	插入卡信息
	ret = DB_t_pif_card_add(&tCard);
	if (ret)
	{
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_CARD_E;
		else
			*pRetCode = E_DB_CARD_I;
		goto L_RETU;
	}

	//	准备数据插入帐户信息表
	ret = getNewActno(tAccount.account_id);  	    //获得最大帐号
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	des2src(tAccount.open_date,logicdate);		   								//开户时间
	des2src(tAccount.open_time,systime);
	tAccount.current_state = ACCOUNTSTAT_REGIST;      								//当前状态
	tAccount.act_type = ACCTYPE_PERMAIN;				        						//帐号类别
	tAccount.customer_id = rPack->lvol0;				        						//客户号
	des2src(tAccount.cut_name,rPack->sname);									//客户名称
	tAccount.cut_type = hi_cuttype;												//客户类别
	des2src(tAccount.stuemp_no,rPack->scust_auth2); 							//客户学号或员工号
	tAccount.card_id = (int)h_temp_Card_id; 											//关联卡号
	tAccount.purse_id = PURSE_NO_ONE;											//关联卡钱包号
	tAccount.card_type = CT_TEMP;													//卡类别
	des2src(tAccount.subno,SUBJECT_INDIVIDUALSAVING);							//所属科目
	des2src(tAccount.isautotra,TYPE_NO); 											//是否自动转帐
	//	插入帐户信息表
	ret = DB_t_aif_account_add(&tAccount);
	if (ret)
	{
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_ACCOUNT_E;
		else
			*pRetCode = E_DB_ACCOUNT_I;
		goto L_RETU;
	}
	//	准备数据插入交易流水表

	double h_temp_Serial_no = 0;
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&h_temp_Serial_no);  						//获得最大流水号
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	tradeserial.serial_no = (int)h_temp_Serial_no;											//流水号
	tradeserial.other_seri_no = 0;														//上传端流水号
	tradeserial.serial_type = TXCODE_TEMPCARD_OPEN;									//交易代码
	tradeserial.serial_state = SERISTAT_DEBT;												//流水状态
	des2src(tradeserial.operate_date,sysdate);											//发生日期
	des2src(tradeserial.operate_time,systime);											//发生时间
	des2src(tradeserial.collect_date,sysdate);												//采集日期
	des2src(tradeserial.collect_time,systime);												//采集时间
	des2src(tradeserial.enteract_date,logicdate);											//处理日期
	des2src(tradeserial.enteract_time,systime);											//处理时间
	tradeserial.maindevice_id = rPack->lvol6;												//上传工作站标识
	tradeserial.device_id = rPack->lvol7;													//采集设备标识
	tradeserial.card_id = tCard.card_id;													//卡号
	des2src(tradeserial.showid,tCard.showid);												//显示卡号
	tradeserial.purse_id = PURSE_NO_ONE;												//钱包号
	tradeserial.customer_id = rPack->lvol0;												//客户标识
	des2src(tradeserial.oper_code,rPack->scust_limit);									//操作员代码
	tradeserial.sys_id = 0;																//外部系统标识
	tradeserial.trade_count=1;														//当前卡交易次数

	des2src(IA.sArrInActno[0],tAccount.account_id);						//帐户
	IA.iCardNo=tCard.card_id;
	IA.iFeeType=tCustomer.fee_type;
	IA.dArrInAmt[0]=tradeserial.trade_fee;

	IA.iArrInFeeSwitch[0]=rPack->lvol0;
	IA.iArrInFeeSwitch[1]=rPack->lvol1;
	IA.iArrInFeeSwitch[2]=rPack->lvol2;
	IA.iArrInFeeSwitch[3]=rPack->lvol3;
	IA.iArrInFeeSwitch[4]=rPack->lvol4;
	IA.iArrInFeeSwitch[5]=rPack->lvol5;
	IA.iArrInFeeSwitch[6]=rPack->lvol6;
	IA.iArrInFeeSwitch[7]=rPack->lvol7;
	IA.iArrInFeeSwitch[8]=rPack->lvol8;
	IA.iArrInFeeSwitch[9]=rPack->lvol9;
	IA.iArrInFeeSwitch[10]=rPack->lvol10;

	//	调用入账子模块
	ret=process(&IA,&tradeserial);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"process ret[%d]",ret);
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d 卡号:%d ",IA.iSerialNo,IA.iCardNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		switch(IA.iArrOutTxType[i])
		{
			case TXTYPE_TOLL_DEPOSIT:
			case TXTYPE_DEDUCT_DEPOSIT:
			case TXTYPE_RETURN_DEPOSIT:
				tradeserial.deposit_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_PRE_TOLL_BOARD:
			case TXTYPE_TOLL_BOARD:
			case TXTYPE_DEDUCT_BOARD:
			case TXTYPE_RETURN_BOARD:
				tradeserial.boardfee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CHARGE:
				tradeserial.in_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CARDCOST:
				tradeserial.cost_fee=IA.dArrOutAmt[i];
				break;
			default:
				break;
		}
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	sprintf(sMsg,"卡当前余额:%.2lf元",tradeserial.out_balance);
	strcat(out_pack->vsmess,sMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);
	//	插入交易流水表
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	if(amtcmp(tradeserial.out_balance,0)<0)
	{
		*pRetCode=E_ENTER_ACCOUNT;
		goto L_RETU;
	}

	//	返回卡号\密码\显示卡号\客户类型\图书证号\有效截至日期
	out_pack->lvol0 = (int)h_temp_Card_id;						//交易卡号
	out_pack->lvol1 = tCustomer.cut_type;						//客户类别
	out_pack->lvol5 = tCustomer.fee_type;						//收费类别
	des2src(out_pack->scust_no,h_showcardid);					//显示卡号
	des2src(out_pack->scust_no2,tCustomer.classdept_no);			//部门号
	des2src(out_pack->scust_auth,tCustomer.stuemp_no);			//学号
	des2src(out_pack->scust_auth2,tCustomer.man_id);			//身份证号
	des2src(out_pack->sname,tCustomer.cut_name);				//客户姓名
	des2src(out_pack->sname2,tCustomer.lib_cardid);				//图书证号
	des2src(out_pack->sstatus0,tCustomer.sex);					//性别
	des2src(out_pack->sopen_emp,h_password);					//卡密码
	des2src(out_pack->sdate0,card_endtime);					//有效截至日期

	out_pack->damt2=tradeserial.out_balance;				//出卡值
	out_pack->damt3=tradeserial.boardfee;					//搭伙费
	out_pack->lserial1=tradeserial.serial_no;					//流水号

	// add by 汤成 2005-8-8
	// 增加向名单表写入记录
	ret = InsertToBlkList((int)h_temp_Card_id,CHCARD_BLACKLIST);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #26
0
int F847132(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	int i=0;
	int iTotalCnt=0;
	double dTotalAmt=0.0;
	double dSerialNo = 0;
	char logicdate[11]="";										//业务日期
	char sysdate[11]="";
	char systime[9]="";
	char sMsg[256]="";
	T_t_tif_tradeserial  tradeserial;
	T_t_tif_savdtl		tSavdtl;
	T_t_tif_subsidy  	tSubsidy;
	InAcc	IA;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	memset(&tSavdtl,0,sizeof(tSavdtl));
	memset(&tSubsidy,0,sizeof(tSubsidy));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&IA,0,sizeof(IA));

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_VSMESS,0);
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);					//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	if(strlen(rPack->scust_limit)<1)
	{
		*pRetCode=E_INPUT_BATCH_NO;
		goto L_RETU;
	}
	if(strlen(rPack->scust_no)<1)
	{
		*pRetCode=E_INPUT_OPER_NULL;
		goto L_RETU;
	}
	if(amtcmp(rPack->damt0,0)<=0)
	{
		*pRetCode=E_INPUT_AMT;
		goto L_RETU;
	}
	des2src(tSubsidy.summary,rPack->semail);		//补助摘要
	if(strlen(rPack->semail)<1)
	{
		*pRetCode=E_INPUT_SUMMARY;
		goto L_RETU;
	}
	des2src(tSubsidy.batch_no,rPack->scust_limit);
	tSubsidy.bill_type=rPack->lvol2;					//票据类型
	des2src(tSubsidy.bill_no,rPack->scust_auth2);	//票据号码
	tSubsidy.amount=rPack->damt0;				//补助金额
	des2src(tSubsidy.subsidytype,rPack->smain_flag);//补助标志(0增值1减值)
	des2src(tSubsidy.subsidytype,"1");			//补助标志(0增值1减值)
	des2src(tSubsidy.broker_id,rPack->sname);		//经办人身份证号
	des2src(tSubsidy.broker_name,rPack->semail2);	//经办人姓名

	IA.dArrInAmt[0]=tradeserial.trade_fee;
	switch(tSubsidy.bill_type)
	{
		case TYPE_CASH:	//现金
			IA.iArrInFeeSwitch[1]=1;
			break;
		case TYPE_BILL:	//支票
			IA.iArrInFeeSwitch[2]=1;
			break;
		case TYPE_FUNDBOOK:	//经费本
			IA.iArrInFeeSwitch[3]=1;
			break;
		default:
			*pRetCode=E_INPUT_DEPOSIT_TYPE;
			goto L_RETU;
	}
	ret=stat_subsidy_amount_by_batch_no(tSubsidy.batch_no, &iTotalCnt,&dTotalAmt);
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret[%d]",ret);
		goto L_RETU;
	}
	if(iTotalCnt!=rPack->lvol3)
	{
		strcpy(szMsg,"补助人数与导入的数据不符");
		*pRetCode=E_INPUT_DATA_INVAILD;
		goto L_RETU;
	}
	if(amtcmp(dTotalAmt,rPack->damt0)!=0)
	{
		strcpy(szMsg,"补助总金额与导入的补助数据不符");
		*pRetCode=E_INPUT_DATA_INVAILD;
		goto L_RETU;
	}
	// writelog(LOG_DEBUG,"subsidy no : %s",tSubsidy.batch_no);
	des2src(tSubsidy.tx_date,sysdate);
	des2src(tSubsidy.tx_time,systime);
	ret=update_subsidy_info_by_batch_no(&tSubsidy);
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret[%d]",ret);
		goto L_RETU;
	}
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialNo);  					//获得最大流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret[%d]",ret);
		goto L_RETU;
	}
	tradeserial.serial_no = D2I(dSerialNo);											//流水号
	tradeserial.other_seri_no = 0;															//上传端流水号
	tradeserial.serial_type = TXCODE_SET_SUBSIDY;
	tradeserial.serial_state = SERISTAT_DEBT;				//流水状态
	des2src(tradeserial.operate_date,logicdate);			//发生日期
	des2src(tradeserial.operate_time,systime);			//发生时间
	des2src(tradeserial.collect_date,sysdate);				//采集日期
	des2src(tradeserial.collect_time,systime);				//采集时间
	des2src(tradeserial.enteract_date,logicdate);			//处理日期
	des2src(tradeserial.enteract_time,systime);			//处理时间
	tradeserial.maindevice_id = rPack->lvol6;				//上传工作站标识
	tradeserial.device_id = rPack->lvol7;					//采集设备标识
	des2src(tradeserial.oper_code , rPack->scust_no);		//操作员代码
	tradeserial.sys_id = 0;								//外部系统标识
	// 设置发生金额
	tradeserial.trade_fee = dTotalAmt;
	switch(tSubsidy.bill_type)
	{
		case TYPE_CASH:		//现金
			break;
 		case TYPE_BILL:		//支票
		case TYPE_FUNDBOOK:	//经费本
 			tSavdtl.amount=rPack->damt0;				//发生额
 			if(amtcmp(tSavdtl.amount,0)<=0)
				break;
			des2src(tSavdtl.bill_no,tSubsidy.bill_no);		//票据号码
			if(strlen(tSavdtl.bill_no)<1)
			{
				*pRetCode=E_INPUT_BILLNO;
				goto L_RETU;
			}
			tSavdtl.card_no=0;							//卡号
			des2src(tSavdtl.oper_no,rPack->scust_limit);	//操作员
			tSavdtl.seqno=tradeserial.serial_no;			//流水号
			des2src(tSavdtl.tx_date,sysdate);			//发生日期
			des2src(tSavdtl.tx_time,systime);			//发生时间
			tSavdtl.cnt=1;								//票据数量
			tSavdtl.bill_type=tSubsidy.bill_type;			//票据类型
			tSavdtl.tx_code=tradeserial.serial_type;		//交易码
			ret=DB_t_tif_savdtl_add(&tSavdtl);
			if(ret)
			{
				if(DB_REPEAT==ret)
					*pRetCode = E_DB_SAVDTL_E;
				else
					*pRetCode = E_DB_SAVDTL_I;
				goto L_RETU;
			}
			break;
		default:
			*pRetCode=E_INPUT_DEPOSIT_TYPE;
			goto L_RETU;
	}
	IA.iFeeType=1;				//默认值
	IA.dArrInAmt[0]=tradeserial.trade_fee;
	// writelog(LOG_DEBUG,"补助金额[%lf]",tradeserial.trade_fee);
//	if(strncmp(tSubsidy.subsidytype,"1",1)==0)
//		IA.dArrInAmt[0]=tradeserial.trade_fee;
//	else if(strncmp(tSubsidy.subsidytype,"2",1)==0)
//	{
//		IA.dArrInAmt[0]=-tradeserial.trade_fee;
//		IA.iTxFlag=1;
//	}
//	else
//	{
//		*pRetCode=E_INPUT_DATA_INVAILD;
//		sprintf(szMsg,"输入的补助类型%s不存在",strncmp(tSubsidy.subsidytype);
//		goto L_RETU;
//	}
	IA.iArrInFeeSwitch[0]=rPack->lvol0;
	IA.iArrInFeeSwitch[5]=rPack->lvol5;
	IA.iArrInFeeSwitch[6]=rPack->lvol6;
	IA.iArrInFeeSwitch[7]=rPack->lvol7;
	IA.iArrInFeeSwitch[8]=rPack->lvol8;
	IA.iArrInFeeSwitch[9]=rPack->lvol9;
	IA.iArrInFeeSwitch[10]=rPack->lvol10;

	ret=process(&IA,&tradeserial);
	if(ret)
	{
		writelog(LOG_ERR,"process ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d ",IA.iSerialNo);
	// writelog(LOG_DEBUG,"out tx type count %d",IA.iOutTxTypeCnt);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	sprintf(sMsg,",共%d笔",iTotalCnt);
	strcat(out_pack->vsmess,sMsg);
	// strcat(out_pack->vsmess,sMsg);
	// writelog(LOG_DEBUG,out_pack->vsmess);
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #27
0
int F847132(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	int i=0;
	int iTotalCnt=0;
	double dTotalAmt=0.0;
	double dSerialNo = 0;
	char logicdate[11]="";										//业务日期
	char sysdate[11]="";
	char systime[9]="";
	char sMsg[256]="";
	T_t_tif_tradeserial  tradeserial;
	T_t_tif_savdtl		tSavdtl;
	T_t_tif_subsidy  	tSubsidy;
	InAcc	IA;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	T_t_tif_meslist tMesList;
	T_t_pif_device t_device;
	T_t_pif_syskey tSyskey;

	memset(&t_device,0,sizeof t_device);
	memset(&tMesList,0,sizeof tMesList);
	memset(&tSavdtl,0,sizeof(tSavdtl));
	memset(&tSubsidy,0,sizeof(tSubsidy));
	memset(&tSyskey,0,sizeof tSyskey);
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&IA,0,sizeof(IA));

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_VSMESS,0);
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);					//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	if(strlen(rPack->scust_limit)<1)
	{
		*pRetCode=E_INPUT_BATCH_NO;
		goto L_RETU;
	}
	if(strlen(rPack->scust_no)<1)
	{
		*pRetCode=E_INPUT_OPER_NULL;
		goto L_RETU;
	}
	//允许补助负金额
	if(amtcmp(rPack->damt0,0)==0)
	{
		*pRetCode=E_INPUT_AMT;
		goto L_RETU;
	}
	des2src(tSubsidy.summary,rPack->semail);		//补助摘要
	if(strlen(rPack->semail)<1)
	{
		*pRetCode=E_INPUT_SUMMARY;
		goto L_RETU;
	}
	
	des2src(tSubsidy.batch_no,rPack->scust_limit);
	tSubsidy.bill_type=rPack->lvol2;					//票据类型
	des2src(tSubsidy.bill_no,rPack->scust_auth2);	//票据号码
	tSubsidy.amount=rPack->damt0;				//补助金额
	des2src(tSubsidy.subsidytype,rPack->smain_flag);//补助标志(0增值1减值)
	des2src(tSubsidy.subsidytype,"1");			//补助标志(0增值1减值)
	des2src(tSubsidy.broker_id,rPack->sname);		//经办人身份证号
	des2src(tSubsidy.broker_name,rPack->semail2);	//经办人姓名

	IA.dArrInAmt[0]=tradeserial.trade_fee;
	switch(tSubsidy.bill_type)
	{
		case TYPE_CASH:	//现金
			IA.iArrInFeeSwitch[1]=1;
			break;
		case TYPE_BILL:	//支票
			IA.iArrInFeeSwitch[2]=1;
			break;
		case TYPE_FUNDBOOK:	//经费本
			IA.iArrInFeeSwitch[3]=1;
			break;
		default:
			*pRetCode=E_INPUT_DEPOSIT_TYPE;
			goto L_RETU;
	}

	/*
	ret=get_batch_no_by_subsidy_no(tSubsidy.subsidy_no,tSubsidy.batch_no);
	if(ret)
	{
		*pRetCode = E_DB_SUBSIDYTMP_R;
		goto L_RETU;
	}
	*/
	// 下发补助时才生成批次号
	/*
	ret=judge_with_max_subsidy_no_within_new(tSubsidy.subsidy_no);
	if(ret)
	{
		*pRetCode = E_SUBSIDY_DOWN_ERROR;
		goto L_RETU;
	}
	*/
	ret=stat_subsidy_amount_by_batch_no(tSubsidy.batch_no, &iTotalCnt,&dTotalAmt);
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret[%d]",ret);
		goto L_RETU;
	}
	
	if(iTotalCnt!=rPack->lvol3)
	{
		strcpy(szMsg,"补助人数与导入的数据不符");
		*pRetCode=E_INPUT_DATA_INVAILD;
		goto L_RETU;
	}
	if(amtcmp(dTotalAmt,rPack->damt0)!=0)
	{
		strcpy(szMsg,"补助总金额与导入的补助数据不符");
		*pRetCode=E_INPUT_DATA_INVAILD;
		goto L_RETU;
	}
	writelog(LOG_DEBUG,"download subsidy batch_no : %s",tSubsidy.batch_no);
	des2src(tSubsidy.tx_date,sysdate);
	des2src(tSubsidy.tx_time,systime);

	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialNo);  					//获得最大流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret[%d]",ret);
		goto L_RETU;
	}
	tradeserial.serial_no = D2I(dSerialNo);											//流水号
	tradeserial.other_seri_no = 0;															//上传端流水号
	if(amtcmp(dTotalAmt,0.0)>0)
		tradeserial.serial_type = TXCODE_SET_SUBSIDY;
	else tradeserial.serial_type = TXCODE_DESUBSIDY_DOWN;
	
	tradeserial.serial_state = SERISTAT_DEBT;				//流水状态
	des2src(tradeserial.operate_date,sysdate);			//发生日期
	des2src(tradeserial.operate_time,systime);			//发生时间
	des2src(tradeserial.collect_date,sysdate);				//采集日期
	des2src(tradeserial.collect_time,systime);				//采集时间
	des2src(tradeserial.enteract_date,logicdate);			//处理日期
	des2src(tradeserial.enteract_time,systime);			//处理时间
	tradeserial.maindevice_id = rPack->lvol6;				//上传工作站标识
	tradeserial.device_id = rPack->lvol7;					//采集设备标识
	des2src(tradeserial.oper_code , rPack->scust_no);		//操作员代码
	tradeserial.sys_id = 0;								//外部系统标识
	// 设置发生金额
	tradeserial.trade_fee = dTotalAmt;
	switch(tSubsidy.bill_type)
	{
		case TYPE_CASH:		//现金
			break;
 		case TYPE_BILL:		//支票
		case TYPE_FUNDBOOK:	//经费本
 			tSavdtl.amount=rPack->damt0;				//发生额
 			if(amtcmp(tSavdtl.amount,0)==0)
				break;
			des2src(tSavdtl.bill_no,tSubsidy.bill_no);		//票据号码
			if(strlen(tSavdtl.bill_no)<1)
			{
				*pRetCode=E_INPUT_BILLNO;
				goto L_RETU;
			}
			tSavdtl.card_no=0;							//卡号
			des2src(tSavdtl.oper_no,rPack->scust_limit);	//操作员
			tSavdtl.seqno=tradeserial.serial_no;			//流水号
			des2src(tSavdtl.tx_date,sysdate);			//发生日期
			des2src(tSavdtl.tx_time,systime);			//发生时间
			tSavdtl.cnt=1;								//票据数量
			tSavdtl.bill_type=tSubsidy.bill_type;			//票据类型
			tSavdtl.tx_code=tradeserial.serial_type;		//交易码
			ret=DB_t_tif_savdtl_add(&tSavdtl);
			if(ret)
			{
				if(DB_REPEAT==ret)
					*pRetCode = E_DB_SAVDTL_E;
				else
					*pRetCode = E_DB_SAVDTL_I;
				goto L_RETU;
			}
			break;
		default:
			*pRetCode=E_INPUT_DEPOSIT_TYPE;
			goto L_RETU;
	}
	IA.iFeeType=1;				//默认值
	//支持负金额扣款
	if(tradeserial.trade_fee<0)
		tradeserial.trade_fee=-tradeserial.trade_fee;
	IA.dArrInAmt[0]=tradeserial.trade_fee;

	IA.iArrInFeeSwitch[0]=rPack->lvol0;
	IA.iArrInFeeSwitch[5]=rPack->lvol5;
	IA.iArrInFeeSwitch[6]=rPack->lvol6;
	IA.iArrInFeeSwitch[7]=rPack->lvol7;
	IA.iArrInFeeSwitch[8]=rPack->lvol8;
	IA.iArrInFeeSwitch[9]=rPack->lvol9;
	IA.iArrInFeeSwitch[10]=rPack->lvol10;

	// 记入账户信息
	ret=process(&IA,&tradeserial,&tSubsidy);
	if(ret)
	{
		writelog(LOG_ERR,"process ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d ",IA.iSerialNo);
	// writelog(LOG_DEBUG,"out tx type count %d",IA.iOutTxTypeCnt);
	/*
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	*/
	sprintf(sMsg,",共%d笔",iTotalCnt);
	strcat(out_pack->vsmess,sMsg);
	// strcat(out_pack->vsmess,sMsg);
	// writelog(LOG_DEBUG,out_pack->vsmess);
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	
	// 广播下载补助名单任务
	memset(&tMesList,0,sizeof tMesList);
	tMesList.funid=930077;
	tMesList.level = MESLIST_PRIORITY_REALTIME;
	tMesList.msgtype = MESLIST_TYPE_NORMAL;
	tMesList.max_send_cnt = 5;
	ret=AddMsgLst(&tMesList);
	if(ret)
	{
		*pRetCode=E_DB_MESLIST_I;
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		return ret;
	}

////////////////////////新增
	ret=DB_t_pif_device_open_select_by_c5_and_devtype_and_phytype("5301",1001);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_pif_device_open_select_by_c5_and_devtype_and_phytype error,ret=[%d]",ret);
		*pRetCode = E_DB_DEVICE_R;
		goto L_RETU;
	}

	while(1)
	{
		// 初始化宿主变量
		ret=DB_t_pif_device_fetch_select_by_c5(&t_device);
		if (ret)    
		{
			DB_t_pif_device_close_select_by_c5();
			db_chk_err(__FILE__,__LINE__,&sqlca);
			if(DB_NOTFOUND==ret)
			{
				break;
			}
			else
			{
				*pRetCode=E_DB_DEVICE_R;
				writelog(LOG_ERR,"DB_t_pif_device_fetch_select_by_c5 err [%d]",ret);
				goto L_RETU;
			}
		}
		
		if(t_device.state_id == DEVISTAT_LOGOUT)   //设备已经注销
			continue;
		tMesList.devid = t_device.device_id;
		tMesList.device_id= t_device.subsystem_id;
		ret=AddMsgLst(&tMesList);
		if(ret)
		{
			*pRetCode=E_DB_MESLIST_I;
			DB_t_pif_device_close_select_by_c5();
			writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
			return ret;
		}
	}

	
	// 锁住批次号
	ret = DB_t_pif_syskey_read_lock_by_cur_and_key_code(KEYTYPE_TIF_SUBSIDY_NO,&tSyskey);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_DB_SYSKEY_N;
		else
			*pRetCode = E_DB_SYSKEY_R;
		goto L_RETU;
	}
	ret = calc_import_max_subsidy_no(tSubsidy.batch_no,tSubsidy.oper_code,&tSubsidy.subsidy_no);
	if(ret)
	{
		DB_t_tif_subsidy_close_select_by_c4();
		return ret;
	}
	writelog(LOG_DEBUG,"download subsidy no[%d]",tSubsidy.subsidy_no);
	ret=update_subsidy_info_by_batch_no(&tSubsidy);
	if(ret)
	{
		*pRetCode = ret;
		DB_t_pif_syskey_free_lock_cur();
		writelog(LOG_ERR,"ret[%d]",ret);
		goto L_RETU;
	}
	// 释放批次号
	DB_t_pif_syskey_free_lock_cur();
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #28
0
int F847107(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int i=0;
	int ret =0;
	char logicdate[11]="";										//业务日期
	char sysdate[11]="";
	char systime[9]="";
	int cardno=0;
	char sMsg[256]="";
	char cardphyid[41]="";
	T_t_tif_tradeserial  tradeserial;
	T_t_card		tCard;
	T_t_tif_savdtl tSavdtl;
	T_t_customer tCustomer;
	T_t_spefee 	tSpeFee;
	T_t_aif_account	tAccount;		//帐户表
	InAcc	IA;
	double dSerialNo = 0;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	*pRetCode=0;

	memset(&tCard,0,sizeof(tCard));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&IA,0,sizeof(IA));
	memset(&tSpeFee,0,sizeof(tSpeFee));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&tradeserial,0,sizeof(tradeserial));

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LSERIAL1,F_DAMT2,F_VSMESS,0);

	cardno=rPack->lvol0;
	des2src(cardphyid, rPack->sbank_acc);				//物理卡号

	if(amtcmp(rPack->damt0,0)<=0)
	{
		*pRetCode=E_INPUT_AMT;
		goto L_RETU;
	}
	if(amtcmp(rPack->damt1,0)<0)
	{
		*pRetCode=E_INPUT_CARD_BALA;
		goto L_RETU;
	}
	if(rPack->lvol10<1)
	{
		*pRetCode=E_INPUT_CARD_TXCNT;
		goto L_RETU;
	}

	if(amtcmp(rPack->damt1,rPack->damt0)<0)
	{
		writelog(LOG_ERR,"tCard balance[%lf] amount[%lf]",rPack->damt1,rPack->damt0);
		*pRetCode= E_BALANCE_SHORTAGE;
		goto L_RETU;
	}
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	ret=DB_t_card_read_by_cardno(cardno, &tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			*pRetCode=E_CARDNO_NOT_EXIST;
		else
			*pRetCode=E_DB_CARD_R;
		goto L_RETU;
	}
	if(strncmp(tCard.cardattr,CARDSTAT_REG,4)!=0)
	{
		if('2'==tCard.cardattr[CARDSTAT_TYPE_REG])
			*pRetCode = E_CARD_CLOSE;
		else if('3'==tCard.cardattr[CARDSTAT_TYPE_REG])
			*pRetCode = E_CARD_CHANGE;
		else if(tCard.cardattr[CARDSTAT_TYPE_LOST]==STATE_TRUE)
			*pRetCode=E_CARD_LOST;
		else if(tCard.cardattr[CARDSTAT_TYPE_FREEZE]==STATE_TRUE)
			*pRetCode=E_CARD_FREEZE;
		else if(tCard.cardattr[CARDSTAT_TYPE_WFAIL]==STATE_TRUE)
			*pRetCode=E_CARDNO_WFAIL;
		goto L_RETU;
	}
	trim(cardphyid);
	trim(tCard.cardphyid);
	if(strcmp(tCard.cardphyid,cardphyid)!=0)
	{
		writelog(LOG_ERR,"db cardphyid[%s],input cardphyid[%s]",tCard.cardphyid,cardphyid);
		*pRetCode= E_CARD_PHYNO_DIFFER;
		goto L_RETU;
	}
	tradeserial.trade_fee = rPack->damt0;													//支取金额
	ret=DB_t_aif_account_read_by_cardno_and_purseno(cardno,PURSE_NO_ONE,&tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_aif_account_read_by_cardno_and_purseno ret[%d]cardno[%d]purseno[%d]",ret,cardno);
		if(DB_NOTFOUND==ret)
			*pRetCode= 	E_ACTNO_NOT_EXIST;
		else
			*pRetCode= 	E_DB_ACCOUNT_R;
		goto L_RETU;
	}
	if(amtcmp(tradeserial.trade_fee,tAccount.cur_freebala)>0)
	{
		writelog(LOG_ERR,"tradeserial.trade_fee[%lf]tAccount.cur_freebala[%lf]",tradeserial.trade_fee,tAccount.cur_freebala);
		*pRetCode=  E_BALANCE_SHORTAGE;
		goto L_RETU;
	}

	//查询支票经费本有无充值记录
	ret=ChkSavdtl(cardno,&tSavdtl);
	if(ret)
	{
		writelog(LOG_ERR,"ChkSavdtl ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	IA.dArrInAmt[0]=tradeserial.trade_fee;
	switch(tSavdtl.billtype)
	{
		case TYPE_CASH:	//现金
			IA.iArrInFeeSwitch[1]=1;
			break;
		case TYPE_BILL:	//支票
			IA.iArrInFeeSwitch[2]=1;
			break;
		case TYPE_FUNDBOOK:	//经费本
			IA.iArrInFeeSwitch[3]=1;
			break;
		default:
			writelog(LOG_ERR,"type[%d]",tSavdtl.billtype);
			IA.iArrInFeeSwitch[1]=1;
			break;
	}
	ret=DB_t_customer_read_lock_by_cur_and_custid(tCard.custid, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"custid[%d]",tCard.custid);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode= E_DB_CUSTOMER_R;
		goto L_RETU;
	}
	//得到收费类别
	if(tCustomer.feetype<1)
	{
		ret=DB_t_spefee_read_by_deptcode_and_custtype(tCustomer.deptcode, tCustomer.custtype,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.feetype=tCustomer.custtype;
			}
			else
			{
				DB_t_customer_free_lock_cur();
				*pRetCode=E_DB_SPEFEE_R;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.feetype=tSpeFee.feetype;
		}
		//更新客户表的收费类别字段
		ret=DB_t_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode= E_CUSTOMER_NOT_EXIST;
			else
				*pRetCode= E_DB_CUSTOMER_U;
			goto L_RETU;
		}
	}
	DB_t_customer_free_lock_cur();

	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerialNo);  	//获得流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR," ERRCODE = [%d]",ret);
		goto L_RETU;
	}

	tradeserial.serial_no = D2I(dSerialNo);						//流水号
	tradeserial.other_seri_no = 0;							//上传端流水号
	tradeserial.serial_type = TXCODE_DRAW_DEPOSIT_LOG;		//交易代码
	tradeserial.serial_state = SERISTAT_DEBT;					//流水状态
	des2src(tradeserial.operate_date,sysdate);				//发生日期
	des2src(tradeserial.operate_time,systime);				//发生时间
	des2src(tradeserial.collect_date,sysdate);					//采集日期
	des2src(tradeserial.collect_time,systime);					//采集时间
	des2src(tradeserial.enteract_date,logicdate);				//处理日期
	des2src(tradeserial.enteract_time,systime);				//处理时间
	tradeserial.maindeviceid = rPack->lvol6;					//上传工作站标
	tradeserial.deviceid = rPack->lvol7;						//采集设备标识
	tradeserial.cardno = rPack->lvol0;						//卡号
	tradeserial.purseno = rPack->lvol1;						//钱包号
	tradeserial.custid = rPack->lvol2;					//客户标识
	tradeserial.in_balance=rPack->damt1;					//入卡值
	tradeserial.trade_count=rPack->lvol10+1;				//交易次数
	des2src(tradeserial.opercode , rPack->scust_limit);		//操作员代码
	tradeserial.sys_id = 0;									//外部系统标识

	IA.iCardNo=tCard.cardno;
	IA.iFeeType=tCustomer.feetype;
	strcpy(IA.sArrInActno[0],tAccount.account_id);
	IA.dArrInAmt[0]=tradeserial.trade_fee;					//账号

	IA.iArrInFeeSwitch[0]=rPack->lvol0;
	IA.iArrInFeeSwitch[5]=rPack->lvol5;
	IA.iArrInFeeSwitch[6]=rPack->lvol6;
	IA.iArrInFeeSwitch[7]=rPack->lvol7;
	IA.iArrInFeeSwitch[8]=rPack->lvol8;
	IA.iArrInFeeSwitch[9]=rPack->lvol9;
	IA.iArrInFeeSwitch[10]=rPack->lvol10;
	T_t_cardbitmap tCardBitmap;

	memset(&tCardBitmap,0,sizeof(tCardBitmap));
	ret=DB_t_cardbitmap_read_lock_by_cur_and_cardno(cardno,&tCardBitmap);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			*pRetCode= E_DB_CARD_N;
		else
			*pRetCode= E_DB_CARD_R;
		goto L_RETU;
	}
	if(tradeserial.trade_count-tCardBitmap.base_no%2000>2000)
	{
		memcpy(tCardBitmap.bitmap,tCardBitmap.bitmap+1000,1000);
		memset(tCardBitmap.bitmap+1000,'0',1000);
		tCardBitmap.base_no+=1000;
	}
	tCardBitmap.bitmap[tradeserial.trade_count-tCardBitmap.base_no-1]='1';
	ret=DB_t_cardbitmap_update_lock_by_cur(&tCardBitmap);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			*pRetCode= E_DB_CARD_N;
		else
			*pRetCode= E_DB_CARD_U;
		goto L_RETU;
	}
	DB_t_cardbitmap_free_lock_cur();
	//	调用入账子模块
	ret=process(&IA,&tradeserial);
	if(ret)
	{
		writelog(LOG_ERR,"process ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d 卡号:%d ",IA.iSerialNo,IA.iCardNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		switch(IA.iArrOutTxType[i])
		{
			case TXTYPE_TOLL_DEPOSIT:
			case TXTYPE_TOLL_DEPOSIT_BILL:
			case TXTYPE_TOLL_DEPOSIT_FUNDBOOK:
			case TXTYPE_DEDUCT_DEPOSIT:
			case TXTYPE_RETURN_DEPOSIT:
				tradeserial.depositfee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_PRE_TOLL_BOARD:
			case TXTYPE_PRE_TOLL_BOARD_BILL:
			case TXTYPE_PRE_TOLL_BOARD_FUNDBOOK:
			case TXTYPE_TOLL_BOARD:
			case TXTYPE_DEDUCT_BOARD:
			case TXTYPE_RETURN_BOARD:
			case TXTYPE_RETURN_BOARD_BILL:
			case TXTYPE_RETURN_BOARD_FUNDBOOK:
				tradeserial.managefee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CHARGE:
			case TXTYPE_TOLL_CHARGE_BILL:
			case TXTYPE_TOLL_CHARGE_FUNDBOOK:
				tradeserial.in_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CARDCOST:
			case TXTYPE_TOLL_CARDCOST_BILL:
			case TXTYPE_TOLL_CARDCOST_FUNDBOOK:
				tradeserial.cost_fee=IA.dArrOutAmt[i];
				break;
			default:
				break;
		}
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	sprintf(sMsg,"支取前卡余额:%.2lf元 卡当前余额:%.2lf元",tradeserial.in_balance,tradeserial.out_balance);
	strcat(out_pack->vsmess,sMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);
	//	插入卡操作流水表
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	if(amtcmp(tradeserial.out_balance,0)<0)
	{
		*pRetCode=E_ENTER_ACCOUNT;
		goto L_RETU;
	}
	out_pack->damt2=tradeserial.out_balance;							//出卡值
	out_pack->lserial1=tradeserial.serial_no;								//流水号
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #29
0
int F240157(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int i=0;
	int ret =0;
	char logicdate[11]="";										//业务日期
	char sysdate[11]="";
	char systime[9]="";
	InAcc	IA;
	double dUniqno = 0;
	int card_id=0;
	int iSerialno=0;
	char physical_no[41]="";
	char sMaxCardBalance[20]="";
	char sMsg[256]="";
	double dMaxCardBalance=0;
	T_t_pif_card		tCard;
	T_t_cif_customer tCustomer;
	T_t_pif_spefee 	tSpeFee;
	T_t_aif_account	tAccount;		//帐户表
	T_t_tif_tradeserial tradeserial;
	T_t_tif_diff_transfer tDiffTransfer;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	memset(&tCard,0,sizeof(tCard));
	memset(&tCustomer,0,sizeof(tCustomer));
	memset(&tSpeFee,0,sizeof(tSpeFee));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&tDiffTransfer,0,sizeof(tDiffTransfer));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&IA,0,sizeof(IA));
	ResetNormalCPack(&aPack,0,1);

	if(amtcmp(rPack->damt1,0)==0)
	{
		*pRetCode=E_INPUT_AMT;
		goto L_RETU;
	}
	trim(rPack->scust_limit);
	trim(rPack->scust_limit2);
	trim(rPack->semp_pwd);
	if(strlen(rPack->scust_limit)==0)
	{
		*pRetCode=E_OPER_NOT_EXIST;
		goto L_RETU;
	}
	if(strlen(rPack->scust_limit2)==0)
	{
		*pRetCode=E_INPUT_AUTH_OPER_NULL;
		goto L_RETU;
	}
	if(strcmp(rPack->scust_limit,rPack->scust_limit2)==0)
	{
		writelog(LOG_ERR,"oper[%s]auth_oper[%s]",rPack->scust_limit,rPack->scust_limit2);
		*pRetCode=E_OPER_AND_AUTH_OPER_EQ;
		goto L_RETU;
	}
	ret=chk_oper_pwd(rPack->scust_limit2,rPack->semp_pwd);
	if(ret)
	{
		if(E_OPER_NOT_EXIST==ret)
			*pRetCode=E_AUTH_OPER_NOT_EXIST;
		else if(E_PASSWORD_WRONG==ret)
			*pRetCode=E_AUTH_OPER_PWD;
		else
			*pRetCode=ret;
		goto L_RETU;
	}
	card_id=rPack->lvol0;
	des2src(physical_no, rPack->sbank_acc);				//物理卡号
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);							//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	ret=DB_t_pif_card_read_by_card_id(card_id, &tCard);
	if(ret)
	{
		writelog(LOG_ERR,"card_id[%d]",card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode=E_CARDNO_NOT_EXIST;
		else
			*pRetCode=E_DB_CARD_R;
		goto L_RETU;
	}
	if(card_id!=tCard.card_id)
	{
		writelog(LOG_ERR,"card_id[%d] db card_id[%d]",card_id,tCard.card_id);
		*pRetCode=E_DB_CARD_R;
		goto L_RETU;
	}
	if(strncmp(tCard.state_id,CARDSTAT_REG,4)!=0)
	{
		if('2'==tCard.state_id[CARDSTAT_TYPE_REG])
			*pRetCode=E_CARDNO_LOGOUT;
		else if('3'==tCard.state_id[CARDSTAT_TYPE_REG])
			*pRetCode=E_CARD_CHANGE;
		else if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_LOST])
			*pRetCode=E_CARDNO_LOST;
		else if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_FREEZE])
			*pRetCode=E_CARDNO_FREEZE;
		else if(STATE_TRUE==tCard.state_id[CARDSTAT_TYPE_WFAIL])
			*pRetCode=E_CARDNO_WFAIL;
		goto L_RETU;
	}
	trim(physical_no);
	trim(tCard.physical_no);
	if(strcmp(tCard.physical_no,physical_no)!=0)
	{
		writelog(LOG_ERR,"db physical_no[%s],input physical_no[%s]",tCard.physical_no,physical_no);
		*pRetCode= E_CARD_PHYNO_DIFFER;
		goto L_RETU;
	}
	iSerialno=rPack->lserial0;
	ret=DB_t_tif_diff_transfer_read_lock_by_c0_and_op_date_and_local_sn(rPack->sdate0,iSerialno,&tDiffTransfer);
	if(ret)
	{
		writelog(LOG_ERR,"operater_date[%s]Serialno[%d]",rPack->sdate0,iSerialno);
		if(DB_NOTFOUND==ret)
			*pRetCode=E_SERIALNO_NOT_EXIST;
		else
			*pRetCode=E_DB_TRADESERIAL_R;
		goto L_RETU;
	}
	if(card_id!=tDiffTransfer.card_id)
	{
		writelog(LOG_ERR,"input card_id [%d],DiffTransfer card_id[%d]",card_id,tDiffTransfer.card_id);
		DB_t_tif_diff_transfer_free_lock_by_c0();
		*pRetCode=E_CARDNO_SERIAL_NE;
		goto L_RETU;
	}
	if(SERISTAT_NODEBT!=tDiffTransfer.status)
	{
		DB_t_tif_diff_transfer_free_lock_by_c0();
		*pRetCode=E_TX_SERIAL_CANNOT_CZ;
		goto L_RETU;
	}
	if(amtcmp(tDiffTransfer.diff_amt,rPack->damt1)!=0)
	{
		DB_t_tif_diff_transfer_free_lock_by_c0();
		*pRetCode=E_INPUT_AMT;
		goto L_RETU;
	}
	tDiffTransfer.status=SERISTAT_DEBT;
	ret=DB_t_tif_diff_transfer_update_lock_by_c0(&tDiffTransfer);
	if(ret)
	{
		*pRetCode=E_DB_DIFF_TRANSFER_U;
		goto L_RETU;
	}
	DB_t_tif_diff_transfer_free_lock_by_c0();
	//根据卡号和钱包号得到消费者账号(借方)
	ret=DB_t_aif_account_read_by_card_id_and_purse_id(card_id, PURSE_NO_ONE,&tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_aif_account_read_by_card_id_and_purse_id ret[%d]card_id[%d]",ret,card_id);
		if(DB_NOTFOUND==ret)
			*pRetCode=E_ACTNO_NOT_EXIST;
		else
			*pRetCode=E_DB_ACCOUNT_R;
		goto L_RETU;
	}
	ret=GetParameter(GLOBE_MAXCARDBALANCE,sMaxCardBalance);
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	dMaxCardBalance=atof(sMaxCardBalance);

	tradeserial.trade_fee = rPack->damt1;				//充值金额
	if(amtcmp(tAccount.cur_bala+tradeserial.trade_fee,dMaxCardBalance)>0)
	{
		*pRetCode= E_AMT_EXCEED_MAX;
		goto L_RETU;
	}
	ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(tCard.cosumer_id, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",tCard.cosumer_id);
		if(DB_NOTFOUND==ret)
			*pRetCode= E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode= E_DB_CUSTOMER_R;
		goto L_RETU;
	}
	//得到收费类别
	if(tCustomer.fee_type<1)
	{
		ret=DB_t_pif_spefee_read_by_dept_code_and_cut_type(tCustomer.classdept_no, tCustomer.cut_type,&tSpeFee);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				tCustomer.fee_type=tCustomer.cut_type;
			}
			else
			{
				DB_t_cif_customer_free_lock_cur();
				*pRetCode=E_DB_SPEFEE_R;
				goto L_RETU;
			}
		}
		else
		{
			tCustomer.fee_type=tSpeFee.fee_type;
		}
		//更新客户表的收费类别字段
		ret=DB_t_cif_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode= E_CUSTOMER_NOT_EXIST;
			else
				*pRetCode= E_DB_CUSTOMER_U;
			goto L_RETU;
		}
	}
	DB_t_cif_customer_free_lock_cur();

	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqno);  					//获得最大流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR," ERRCODE = [%d]",ret);
		goto L_RETU;
	}

	tradeserial.serial_no = (int)dUniqno;					//流水号
	tradeserial.other_seri_no = 0;								//上传端流水号
	tradeserial.serial_type  = TXCODE_MAKEUPSERIAL;
	tradeserial.serial_state = SERISTAT_DEBT;						//流水状态
	des2src(tradeserial.operate_date,sysdate);					//发生日期
	des2src(tradeserial.operate_time,systime);					//发生时间
	des2src(tradeserial.collect_date,sysdate);						//采集日期
	des2src(tradeserial.collect_time,systime);						//采集时间
	des2src(tradeserial.enteract_date,logicdate);					//处理日期
	des2src(tradeserial.enteract_time,systime);					//处理时间
	tradeserial.maindevice_id = rPack->lvol6;						//上传工作站标识
//	tradeserial.device_id = rPack->lvol7;							//采集设备标识
	tradeserial.card_id =card_id;									//卡号
	tradeserial.purse_id = PURSE_NO_ONE;						//钱包号
	tradeserial.customer_id = tCard.cosumer_id;					//客户标识
	tradeserial.in_balance=rPack->damt0;						//入卡值
	tradeserial.trade_count=rPack->lvol1+1;					//交易次数
	des2src(tradeserial.oper_code,rPack->scust_limit);			//操作员代码
	tradeserial.sys_id = 0;										//外部系统标识

	des2src(IA.sArrInActno[0],tAccount.account_id);						//帐户
	IA.iCardNo=tCard.card_id;
	IA.iFeeType=tCustomer.fee_type;
	IA.dArrInAmt[0]=tradeserial.trade_fee;

	IA.iArrInFeeSwitch[0]=rPack->lvol0;
	IA.iArrInFeeSwitch[1]=rPack->lvol1;
	IA.iArrInFeeSwitch[2]=rPack->lvol2;
	IA.iArrInFeeSwitch[3]=rPack->lvol3;
	IA.iArrInFeeSwitch[4]=rPack->lvol4;
	IA.iArrInFeeSwitch[5]=rPack->lvol5;
	ret=process(&IA,&tradeserial);
	if(ret)
	{
		writelog(LOG_ERR,"process ret[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	sprintf(out_pack->vsmess,"流水号:%d ",IA.iSerialNo);
	for(i=1;i<=IA.iOutTxTypeCnt;i++)
	{
		switch(IA.iArrOutTxType[i])
		{
			case TXTYPE_TOLL_DEPOSIT:
			case TXTYPE_DEDUCT_DEPOSIT:
			case TXTYPE_RETURN_DEPOSIT:
				tradeserial.deposit_fee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_PRE_TOLL_BOARD:
			case TXTYPE_TOLL_BOARD:
			case TXTYPE_DEDUCT_BOARD:
			case TXTYPE_RETURN_BOARD:
				tradeserial.boardfee=IA.dArrOutAmt[i];
				break;
			case TXTYPE_TOLL_CHARGE:
				tradeserial.in_fee=IA.dArrOutAmt[i];
				break;
			default:
				break;
		}
		if(amtcmp(IA.dArrOutAmt[i],0)!=0)
		{
			sprintf(sMsg,"%s:%.2lf元 ",IA.sArrOutTxName[i],IA.dArrOutAmt[i]);
			strcat(out_pack->vsmess,sMsg);
		}
	}
	writelog(LOG_DEBUG,out_pack->vsmess);
	SetCol(handle,0);
	SetCol(handle,F_LSERIAL1,F_DAMT2,F_DAMT3,F_DAMT4,F_VSMESS,0);
	out_pack->lserial1=tradeserial.serial_no;			//流水号
	out_pack->damt2=tradeserial.trade_fee;			//充值金额
	out_pack->damt3=tradeserial.boardfee;			//搭伙费
	out_pack->damt4=tradeserial.out_balance;		//出卡值
	ret = DB_t_tif_tradeserial_add(&tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
Beispiel #30
0
int F847181(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	char    	tx_date[8+1]="";              	//发生日期
	char    	tx_time[6+1]="";      		//发生时间
	int		cardno=0;                    	//卡号
	char    	deviceid[8+1]="";            	//终端机ID
	int		serial_no=0;                  	//终端机流水号
	int 		shop_id=0;
	double 	iSeqNo=0;
	T_t_tif_tradeserial		tTradeserial;	//卡操作流水表
	T_t_tif_rcvdtl		tRcvdtl;
	char sysdate[11]="";
	char systime[9]="";

	memset(&tRcvdtl,0,sizeof(tRcvdtl));
	memset(&tTradeserial,0,sizeof(tTradeserial));
	getsysdate(sysdate);
	getsystime(systime);
	des2src(tx_date,rPack->sbank_pwd);
	des2src(tx_time,rPack->sbank_code);
	cardno=rPack->lvol0;
	des2src(deviceid,rPack->sbank_pwd2);
	serial_no=rPack->lvol1;
	shop_id=rPack->lvol12;
	ret=DB_t_tif_rcvdtl_read_lock_by_c0_and_tx_date_and_tx_time_and_cardno_and_deviceid_and_serial_no(tx_date,tx_time,cardno,deviceid,serial_no,&tRcvdtl);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
		{
			writelog(LOG_ERR,"tx_date[%s],tx_time[%s],cardno[%d],deviceid[%s],serial_no[%d]",tx_date,tx_time,cardno,deviceid,serial_no);
			*pRetCode=E_SERIALNO_NOT_EXIST;
		}
		else
		{
			*pRetCode=E_DB_RCVDTL_R;
			writelog(LOG_ERR,"read_lock t_tif_rcvdtl err ret[%d]",ret);
		}
		goto L_RETU;
	}
	if(tRcvdtl.status[0]!='2')
	{
		*pRetCode=E_TX_CANNOT_DEAL;
		DB_t_tif_rcvdtl_free_lock_c0();
		goto L_RETU;
	}
	des2src(tRcvdtl.oper_no,rPack->sdate1);
	des2src(tRcvdtl.deal_date,sysdate);
	des2src(tRcvdtl.deal_time,systime);
      	tRcvdtl.status[0]='3';          				//1-未处理2-失败3-成功
	ret=DB_t_tif_rcvdtl_update_lock_by_c0(&tRcvdtl);
	if(ret)
	{
	        *pRetCode=E_DB_RCVDTL_U;
	        writelog(LOG_ERR,"DB_t_tif_rcvdtl_update_lock_by_c1[%d]",ret);
	        goto L_RETU;
	}
	DB_t_tif_rcvdtl_free_lock_c0();
		//赋值
	ret=getdata(&tTradeserial,&tRcvdtl);
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	ret=GetLogicDate(tTradeserial.enteract_date);						//业务日期
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"GetLogicDate  err ret[%d]",ret);
		goto L_RETU;
	}
	des2src(tTradeserial.enteract_time,systime);
	tTradeserial.maindeviceid=rPack->lvol11;
	des2src(tTradeserial.opercode,rPack->sdate1);
	//取流水号,从帐处理
	ret=getNewUniqNo(KEYTYPE_TRADESERIAL, &iSeqNo);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"getNewUniqNo err[%d]",ret);
		goto L_RETU;
	}
	tTradeserial.serial_no=iSeqNo;
		//######################################################
	//入账处理
	switch(tTradeserial.serial_type)
	{
		case 930031:
			if(0==tRcvdtl.amount)
				break;
			tTradeserial.comu_ver=shop_id;
			ret=process930031(&tTradeserial);
			if(ret)
			{
				*pRetCode=ret;
				writelog(LOG_ERR,"process930031 err[%d]",ret);
				goto L_RETU;
			}
			break;
		default:
			*pRetCode=E_TXCODE_NOT_EXIST;	//交易码错误
			goto L_RETU;
	}
		//######################################################
	//业务处理成功处理
	tTradeserial.serial_state=SERISTAT_DEBT;			//已入帐
	//添加交易流水
	ret = DB_t_tif_tradeserial_add(&tTradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"DB_t_tif_tradeserial_add ret[%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_TRADESERIAL_E;
		else
			*pRetCode = E_DB_TRADESERIAL_I;
		goto L_RETU;
	}
	return 0;
L_RETU:
	return -1;
}