예제 #1
0
int F240000(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	trans.termid=atoi(rPack->sorder2);
	char seed_key[17] = "";
	char sInputPwd[33] = "";											//存放加密前的卡密钥
	char sCryptPwd[33] = "";									//存放加密后的卡密钥

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


	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_DAMT0,F_DAMT1,F_DAMT2,F_LVOL1,F_LVOL2,F_SDATE0,0);

	trans.cardno=rPack->lvol0;
	if(trans.cardno<1)
		trans.cardno=atoi(rPack->sserial0);
	ret=DB_t_card_read_by_cardno(trans.cardno,&card);
	if(ret)
	{
		writelog(LOG_ERR,"Create serial_no error,error code=[%d]",ret);
		return ERRINFO(E_CARD_LOGOUT,trans.cardno);
	}
	if(card.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARD_LOGOUT,trans.cardno);
	}	
	if('1'==card.frozeflag[0])
	{
		return ERRINFO(E_CARD_FREEZE,trans.cardno);
	}
	if('1'==card.lossflag[0])
	{
		return ERRINFO(E_CARD_LOST,trans.cardno);
	}	
	if('1'==card.badflag[0])
	{
		return ERRINFO(E_CARD_BADRECORD,trans.cardno);
	}	
	if('1'==card.lockflag[0])
	{
		return ERRINFO(E_CARDNO_LOCKED,trans.cardno);
	}	
	des2src(sInputPwd,rPack->scust_limit);		//卡密码
	strcpy(seed_key,STATIC_SEED_KEY);			//种子密钥
	EncodePwd(seed_key,sInputPwd,sCryptPwd,0);	//加密
	if(strcmp(sCryptPwd,card.cardpwd)!=0)
	{
		writelog(LOG_ERR,"card err input[%s]db[%s]",sCryptPwd,card.cardpwd);
		return E_CARDPWD;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
}
예제 #2
0
int F846336(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	des2src(pAccTrans->trans.opercode,rPack->semp);
	int transflag=rPack->lvol3;;
	if(transflag)
	{
		pAccTrans->trans.transcode=TC_EACC2CARD;
	}
	else
	{
		pAccTrans->trans.transcode=TC_CARD2EACC;
	}	
	
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;			
	TRANS& trans=pAccTrans->trans;

	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	char key[17]="";
	char pwd_plain[33]="";
	char pwd_crypt[33]="";
	strcpy(key,STATIC_SEED_KEY);
	des2src(pwd_plain,rPack->scust_limit);
	EncodePwd(key,pwd_plain,pwd_crypt, 0);
	
	trans.cardflag=1;
	pAccTrans->trans.usecardflag=1;	
	trans.cardno=rPack->lvol0;
	trans.purseno=PURSE_NO_ONE;
	trans.cardcnt=rPack->lvol6+1;
	trans.cardbefbal=rPack->lvol7/100.0;
	trans.cardaftbal=trans.cardbefbal;
	trans.inputamt=D4U5(rPack->damt0,2);
	
//	transdtl.cardaftbal=rPack->lvol8;
//	transdtl.siteno=rPack->lcert_code;
//	transdtl.frontno=0;
	//des2src(transdtl.devphyid,rPack->sname);
	//transdtl.devseqno=rPack->lserial0;
	//des2src(transdtl.bankcode,rPack->sbank_code);
	//des2src(transdtl.bankcardno,rPack->scard0);
	//des2src(transdtl.mobile,rPack->sphone2);
//	des2src(transdtl.remark,rPack->ssectypes);
	
	//检查客户
	des2src(trans.cardphyid,rPack->sstation0);
	T_t_card tCard;
	
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(tCard);
	if(ret)
	{
		return ret;
	}
	//查询卡帐户
	T_t_account tCardAccount;	
	memset(&tCardAccount,0,sizeof(tCardAccount));
	ret=DB_t_account_read_by_cardno_and_purseno(trans.cardno,trans.purseno,&tCardAccount);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_CARDNO_PURSENO_NOACCNO,trans.cardno,trans.purseno);
		else 
			return E_DB_ACCOUNT_R;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
	}
	//根据客户号查询电子钱包帐户
	T_t_netacc tNetAccount;	
	memset(&tNetAccount,0,sizeof(tNetAccount));
	ret=DB_t_netacc_read_by_custid(tCardAccount.custid,&tNetAccount);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_EACCNO,tCardAccount.custid);
		else 
			return E_DB_ACCOUNT_R;
	}
	if(tNetAccount.status[0]!=STATUS_NORMAL)
		return ERRINFO(E_EACCNO_LOGOUT,tNetAccount.accno);
	strcpy(trans.cardaccno,tCardAccount.accno);
	
	pAccTrans->trans.feetype=tCard.feetype;
	pAccTrans->trans.custid=tCard.custid;
	strcpy(pAccTrans->trans.cardaccno,tCardAccount.accno);
	strcpy(pAccTrans->trans.eaccno,tNetAccount.accno); 	
	if(TC_CARD2EACC==trans.transcode)
	{
		//检查卡密码
		if(strcmp(tCard.cardpwd,pwd_crypt)!=0)
		{
			return E_CARDPWD;
		}
		if(amtcmp(pAccTrans->trans.inputamt,trans.cardbefbal)>0)
			return ERRINFO(E_CARD_BALANCE_SHORTAGE,trans.cardbefbal-pAccTrans->trans.inputamt);
		strcpy(pAccTrans->trans.draccno,tCardAccount.accno);
		strcpy(pAccTrans->trans.craccno,tNetAccount.accno);		
	}
	else
	{
		char inpwd_crypt[65]="";
		char seedkey[33]="";
		char inpwd_plain[65]="";
		char dbpwd_plain[65]="";
		//检查电子钱包密码
		des2src(inpwd_crypt,rPack->snote2);
		if(!strlen(inpwd_crypt))
			return E_PWD_NULL;
		ret=GetSysParaVal(GLOBLE_SYSPARA_STATIC_KEY,seedkey);
		if(ret)
			return ret;
		ret=decrypt_elec_card_pwd(0,seedkey,inpwd_crypt,inpwd_plain);
		if(ret)
			return E_EACCPWD;
		ret=decrypt_elec_card_pwd(0,seedkey,tNetAccount.accpwd,dbpwd_plain);
		if(ret)
			return E_PWD_DECRYPT;
		if(strcmp(inpwd_plain,dbpwd_plain)!=0)
			return E_EACCPWD;

		if(tNetAccount.stoppayflag[0]=='1')
			return ERRINFO(E_EACC_STOPPAY,tNetAccount.accno);
		if(amtcmp(pAccTrans->trans.inputamt,tNetAccount.balance)>0)
			return ERRINFO(E_EACC_BALANCE_SHORTAGE,pAccTrans->trans.inputamt-tNetAccount.balance);
		if(amtcmp(pAccTrans->trans.inputamt+trans.cardbefbal,tCardAccount.cardmaxbal)>0)
			return ERRINFO(E_AMT_EXCEED_MAX,tCardAccount.cardmaxbal);	
		strcpy(pAccTrans->trans.draccno,tNetAccount.accno);		
		strcpy(pAccTrans->trans.craccno,tCardAccount.accno);
	}
	pAccTrans->trans.feetype=0;
	pAccTrans->trans.usecardflag=1;	
	pAccTrans->trans.custid=tCard.custid;
	ret=pAccTrans->doTrans();
	if(ret)
		return ret;
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));

	des2src(transdtl.transdate,trans.sysdate);
	des2src(transdtl.transtime,trans.systime);
	strcpy(transdtl.accdate,trans.sysdate);
	strcpy(transdtl.acctime,trans.systime);
	transdtl.termid=trans.termid;
	transdtl.termseqno=trans.termseqno;
	transdtl.transcode=trans.transcode;
	transdtl.cardno=trans.cardno;
	transdtl.purseno=trans.purseno;
	transdtl.cardcnt=trans.cardcnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.cardaftbal=pAccTrans->trans.cardaftbal;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.amount=trans.totalfeeamt;
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	transdtl.revflag[0]='0';
	transdtl.showcardno=atol(tCard.showcardno);
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
	  if(DB_REPEAT==ret)
	    return E_DB_TRANSDTL_E;
	  else
	    return E_DB_TRANSDTL_I;
	}		
	SetCol(handle,F_LVOL0,F_LVOL8,F_SDATE0,
		F_SDATE3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);	
	outPack->lvol0=tCard.cardno;
	outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
	des2src(outPack->sdate3,pAccTrans->trans.sysdate);
	des2src(outPack->semp,trans.opercode);
	outPack->lwithdraw_flag=trans.termid;
	outPack->lserial1=trans.termseqno;
	char temp[128]="";
	sprintf(temp,"卡余额:%.2f",pAccTrans->trans.cardaftbal);
	pAccTrans->remark+=temp;
	strcpy(outPack->vsmess,pAccTrans->remark.c_str());
	des2src(trans.remark,outPack->vsmess);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
예제 #3
0
static int DoCheck(ST_PACK *rPack,T_t_shopcard& tShopCard,T_t_shop& tShop)
{
    //检查卡是否已经使用
    int ret=0;

    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;

    des2src(tShopCard.cardphyid,rPack->sbank_acc);
    des2src(tShopCard.showcardno,rPack->sorder0);
    des2src(tShopCard.expiredate,rPack->sdate0);
    des2src(tShopCard.opendate,trans.accdate);
	des2src(tShopCard.lastsaved,trans.sysdatetime);
	tShopCard.status[0]=STATUS_NORMAL;
	tShopCard.lossflag[0]='0';
	tShopCard.shopid =rPack->lvol0;

    if(!strlen(tShopCard.cardphyid))
        return E_INPUT_CARDPHYID;
	if(!strlen(tShopCard.expiredate))
		return E_INPUT_EXPIREDATE;
    //判断到期日期
    ret=IsInvalidDateTime(tShopCard.expiredate,"YYYYMMDD");
    if (ret)
        return ERRINFO(E_INPUT_EXPIREDATE,tShopCard.expiredate);
    if (strncmp(tShopCard.expiredate,trans.accdate,8)<0)
        return ERRINFO(E_INPUT_EXPIREDATE,tShopCard.expiredate);
	//检查商户   
	ret=DB_t_shop_read_by_shopid(tShopCard.shopid,&tShop);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_SHOPID,tShopCard.shopid);
		else
			return E_DB_SHOPCARD_R;
	}
	if(tShop.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_SHOP_LOGOUT,tShop.shopid);
	}
    char cardpwd[33]={0};
    char key[17]={0};

    get_init_passwd_by_man_id(tShop.idno,cardpwd);
    strcpy(key,STATIC_SEED_KEY);
    EncodePwd(key,cardpwd,tShopCard.cardpwd, 0);

	strcpy(trans.cardpwd,cardpwd);//临时保存密码
	//检查是否存在商户卡
	T_t_shopcard tShopCardCheck;
	memset(&tShopCardCheck,0,sizeof(tShopCardCheck));
	ret=DB_t_shopcard_read_by_shopid_and_status(tShopCard.shopid,tShopCard.status,&tShopCardCheck);
	if(ret)
	{
		if(DB_NOTFOUND!=ret)
			return E_DB_SHOPCARD_R;
	}
	else
	{
		ERRTIP("该商户商户卡已发行");
		return E_COMMON_ERR;
	}
    ret=DB_t_shopcard_read_by_cardphyid_and_status(tShopCard.cardphyid,tShopCard.status,&tShopCardCheck);
    if (ret!=DB_NOTFOUND)
    {
        if (DB_SUCCESS==ret)
            return ERRINFO(E_EXIST_CARDPHYID,tShopCard.cardphyid);
        else
            return E_DB_CARD_R;
    }
    return 0;
}
예제 #4
0
파일: F847123.c 프로젝트: nykma/ykt4sungard
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;
}
예제 #5
0
int F843335(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int	dept_id=0;                    	//父商户标识
	int ret=0;
	int len=0;
	double dUniqno=0;
	char logicdate[11]="";
	char sysdate[11]="";
	char systime[9]="";
	char seed_key[17] = "";		//种子密钥
	char pwd[17] = "";				//密码
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	T_t_cif_shop	tShop;
	T_t_cif_customer  tCustomer;
	T_t_aif_account	tAccount;
	T_t_tif_tradeserial  tradeserial;
	
	 memset(&tShop,0,sizeof(tShop));
	 memset(&tCustomer,0,sizeof(tCustomer));
	 memset(&tAccount,0,sizeof(tAccount));
	memset(&tradeserial,0,sizeof(tradeserial));
	ResetNormalCPack(&aPack,0,1);

	getsysdate(sysdate);
	getsystime(systime);
	dept_id=rPack->lvol1;				//父商户ID
	if(dept_id<1)
	{
		*pRetCode= E_FAT_SHP_ID_NOT_EXIST;
		goto L_RETU;
	}
	ret=GetLogicDate(logicdate);		//业务日期
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	//判断商户名称是否已经使
	ret=IsExistSameShopName(rPack->scard1,0);
	if(ret)
	{
		*pRetCode= ret;
		goto L_RETU;
	}
	ret=DB_t_cif_shop_read_lock_by_cur1_and_shop_id(dept_id,&tShop);
	if(ret)
	{
		writelog(LOG_ERR,"dept_id[%d]",dept_id);
		if(DB_NOTFOUND==ret)	
			*pRetCode= E_FAT_SHP_ID_NOT_EXIST;
		else
			*pRetCode= E_DB_SHOP_R;
		goto L_RETU;
	}
	if(strncmp(tShop.is_leaf,TYPE_YES,1)!=0)
	{
		DB_t_cif_shop_free_lock_cur1();
	}
	else
	{
		//是叶结点,先判断有无设备
		ret=IsExistDeviceByShopId(dept_id,logicdate);
		if(ret)
		{
			DB_t_cif_shop_free_lock_cur1();
			*pRetCode= ret;
			goto L_RETU;
		}
		//更新叶子标志为非叶子
		des2src(tShop.is_leaf,TYPE_NO);
		ret=DB_t_cif_shop_update_lock_by_cur1(&tShop);
		if(ret)
		{
			writelog(LOG_ERR,"dept_id[%d] ",dept_id);
			if(DB_NOTFOUND==ret)	
				*pRetCode= E_FAT_SHP_ID_NOT_EXIST;
			else
				*pRetCode= E_DB_SHOP_U;
			goto L_RETU;
		}
		DB_t_cif_shop_free_lock_cur1();
		//注销帐户
		ret=DB_t_aif_account_read_lock_by_c5_and_customer_id_and_act_type(tShop .cut_id, ACCTYPE_SHOPMAIN, &tAccount);
		if(ret)
		{
			writelog(LOG_ERR,"shop.cut_id[%d]",tShop.cut_id);
			if(DB_NOTFOUND==ret)
			
				*pRetCode=E_ACTNO_NOT_EXIST;
			else
				*pRetCode=E_DB_ACCOUNT_R;
			goto L_RETU;
		}
		if(amtcmp(tAccount.cur_bala,0)>0)
		{
			DB_t_aif_account_free_lock_c5();
			writelog(LOG_ERR,"account.cur_bala[%lf]",tAccount.cur_bala);
			*pRetCode=E_SHP_ACC_NO_RECKONING;
			goto L_RETU;
		}
		tAccount.current_state=ACCOUNTSTAT_LOGOUT;
		des2src(tAccount.close_date,logicdate);
		des2src(tAccount.close_time,systime);
		ret=DB_t_aif_account_update_lock_by_c5(&tAccount);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				*pRetCode=E_ACTNO_NOT_EXIST;
			else
				*pRetCode=E_DB_ACCOUNT_U;
			goto L_RETU;
		}
		DB_t_aif_account_free_lock_c5();
	}
	//非叶子节点
	if(strcmp(rPack->smarket_code2,TYPE_YES)!=0)
	{
		// 不能收取搭伙费
		if(strcmp(rPack->smarket_code,TYPE_YES) == 0)
		{
			*pRetCode = E_SHOP_NOT_LEAF_GETFEE;
			goto L_RETU;
		}
	}
	memset(&tShop,0,sizeof(tShop));

//先增加客户
	ret=getNewUniqNo(KEYTYPE_CUSTOMER, &dUniqno);
	if(ret)
	{
		writelog(LOG_ERR,"getNewUniqNo err[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	tCustomer.cut_id=D2I(dUniqno);
	tCustomer.cut_type=CUSTTYPE_SHOP;				//客户类型-商户
	tCustomer.cut_state=CUSTSTAT_REGIST;
	des2src(tCustomer.cut_name,rPack->scard1);		//商户名称
	tCustomer.area=rPack->lvol8;					//区域
	des2src(tCustomer.stuemp_no,rPack->scust_auth);	//员工号
	des2src(tCustomer.classdept_no,rPack->scust_no);//部门号
	des2src(tCustomer.man,rPack->sname);			//姓名
	des2src(tCustomer.sex,rPack->sstatus0);			//性别
	tCustomer.nation=rPack->lvol4;					//民族
	des2src(tCustomer.man_id,rPack->sname2);		//身份证号
	des2src(tCustomer.tel,rPack->scust_auth2);		//电话
	des2src(tCustomer.address,rPack->scusttypes);	//地址
	des2src(tCustomer.reg_time,logicdate);			//注册日期
	des2src(tCustomer.can_time,rPack->sphone3);	//预计注销日期
	//des2src(tCustomer.comments,rPack->ssectypes);

	ret=DB_t_cif_customer_add(&tCustomer);
	if(ret)
	{
		*pRetCode=E_DB_CUSTOMER_I;
		goto L_RETU;
	}
	dUniqno=0;
	ret=getNewUniqNo(KEYTYPE_SHOP, &dUniqno);
	if(ret)
	{
		writelog(LOG_ERR,"getNewUniqNo err[%d]",ret);
		*pRetCode=ret;
		goto L_RETU;
	}
	tShop.shop_id=D2I(dUniqno);
	tShop.cut_id=tCustomer.cut_id;
	tShop.dept_id=dept_id;
	des2src(tShop.shop_name,tCustomer.cut_name);
	tShop.shop_type=rPack->lvol7;				//商户类别
	des2src(tShop.is_indep,rPack->smain_flag);		//是否独立核算
	des2src(tShop.is_leaf,rPack->smarket_code2);	//是否是叶结点
	tShop.shop_state=SHOPSTAT_REGIST;
	des2src(tShop.shop_manager,tCustomer.stuemp_no);	//学号
	des2src(tShop.man,tCustomer.man);			//联系人姓名
	des2src(tShop.sex,tCustomer.sex);				//性别
	tShop.nation=tCustomer.nation;					//民族
	des2src(tShop.man_id,tCustomer.man_id);		//联系人身份证号
	des2src(tShop.tel,tCustomer.tel);				//电话
	des2src(tShop.address,tCustomer.address);		//地址
	des2src(tShop.is_getfee,rPack->smarket_code);	//是否收取管理费
	des2src(tShop.b_act_id,rPack->sbank_acc);		// 银行账号
	des2src(tShop.b_act_name,rPack->sbankname);	// 银行名称
	tShop.ratio=rPack->damt0;					//汇率
	if(tShop.ratio>MAX_RATIO)
	{
		*pRetCode=E_FEERATIO_TOO_HIGH;
		goto L_RETU;
	}
	tShop.manager_type=rPack->lvol3;				//管理费计算方式
	tShop.duty_type=rPack->lvol2;					//商户税费计算方式
	des2src(tShop.reg_time,logicdate);				//商户注册日期
	des2src(tShop.comments,rPack->ssectypes);	

	des2src(tShop.rakeoff_type,rPack->sstatus1);	//佣金类型
	tShop.rakeoff_ratio=rPack->damt1;				//佣金费率
	ret=DB_t_cif_shop_add(&tShop);
	if(ret)
	{
		*pRetCode=E_DB_SHOP_I;
		goto L_RETU;
	}
	//如果是叶结点则开帐号
	if(strncmp(tShop.is_leaf,TYPE_YES,1)==0)
	{
/*		len=strlen(rPack->sserial0);
		if(len==0)
		{
			*pRetCode=E_PWD_NULL;
			goto L_RETU;	
		}
		else if(len!=6)
		{
			*pRetCode=E_PWD_LEN;
			goto L_RETU;
		}
*/
		memset(&tAccount,0,sizeof(tAccount));
		ret = getNewActno(tAccount.account_id);								//获得新帐号
		if (ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		des2src(tAccount.open_date,logicdate);									//开户日期
		des2src(tAccount.open_time,systime);
		des2src(tAccount.cut_name,tCustomer.cut_name);							//客户名称
		tAccount.customer_id=tCustomer.cut_id;									//客户号
		tAccount.cut_type =tCustomer.cut_type;									//客户类别
		des2src(tAccount.stuemp_no,tCustomer.stuemp_no); 						//客户学号或员工号
		tAccount.current_state = ACCOUNTSTAT_REGIST;							//当前状态
		tAccount.act_type = ACCTYPE_SHOPMAIN;				        				//帐号类别
		des2src(tAccount.subno,SUBJECT_SHOPSAVING);							//所属科目

		memcpy(seed_key,STATIC_SEED_KEY,sizeof(seed_key));					//读种子密钥
		strcpy(pwd,"666666");
		EncodePwd(seed_key,pwd,tAccount.password,0);							//帐户密码

		//	插入帐户信息表	
		ret = DB_t_aif_account_add(&tAccount);
		if (ret)
		{
			writelog(LOG_ERR,"tAccount.account_id[%s]",tAccount.account_id);
			if(DB_REPEAT==ret)
				*pRetCode = E_DB_ACCOUNT_E;
			else
				*pRetCode = E_DB_ACCOUNT_I;
			goto L_RETU;
		}
		dUniqno=0;
		ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqno);  						//获得最大流水号
		if(ret)
		{
			*pRetCode = ret;
			writelog(LOG_ERR,"ret [%d]",ret);
			goto L_RETU;
		}
		des2src(tradeserial.oper_code,rPack->scust_limit);							//操作员号
		tradeserial.maindevice_id=rPack->lvol10;										//工作站
		tradeserial.serial_no = D2I(dUniqno);											//流水号
		tradeserial.other_seri_no = 0;														//上传端流水号
		tradeserial.serial_type = TXCODE_SHOP_OPEN;											//交易代码;备注:发卡+充值 用一个交易码,即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);											//处理时间
		tradeserial.maindevice_id = rPack->lvol6;												//上传工作站标识
		tradeserial.device_id = rPack->lvol7;													//采集设备标识	
		tradeserial.customer_id=tAccount.customer_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;
		}		
	}
	SetCol(handle,0);
	SetCol(handle,F_LVOL5,0);
	out_pack->lvol5=tShop.shop_id;
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
예제 #6
0
//查询校园卡转帐流水
int Pos_QuerySerial(INNER_TRANS_REQUEST * pNode,TRUSERID *handle,int *pRetCode,char *szMsg)
{

	char key[32+1]="";
	char pwd[32+1]="";
	//char account_id[16+1]="";
	char account_pwd[6+1]="";
	int ret=0;
	int cnt=0;
	//double unique=0.0;
	INNER_TRANS_REQUEST  from_pos;
	T_t_tif_tradeserial  tradeserial;		//卡操作流水表
	T_t_aif_account account;
	T_t_pif_card card;

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

	memset(&from_pos,0,sizeof(from_pos));
	memset(&account,0,sizeof(account));
	memset(&card,0,sizeof(card));
	memcpy(&from_pos,pNode,sizeof(from_pos));


	//判断设备是否登陆
	if(0!=device_login_yes_or_no(atoi(from_pos.TerminalId)))
	{
		writelog(LOG_ERR,"Device don't login");
		return E_TRANS_TERM_NOLOGIN;
	}

	ret=DB_t_pif_card_read_by_card_id(atoi(from_pos.CardNo),&card);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_pif_card_read_lock_by_cur_and_card_id error,errcode=[%d]",ret);
		//sprintf(pNode->RetCode,"%d",E_TRANS_UNKNOW_ERROR);
		return E_TRANS_SCHACC_NOEXIT;
	}

	strcpy(key,STATIC_SEED_KEY);
	Strncpy_t(account_pwd, from_pos.AccountPwd,sizeof(account_pwd));
	EncodePwd(key,account_pwd,pwd, 0);

	//判断卡密码是否正确
	if(0!=memcmp(pwd,card.password,sizeof(pwd)))
	{
		writelog(LOG_ERR,"Card password error,clear_pwd[%s],input_pwd=[%s],db_pwd=[%s]",account_pwd,pwd,card.password);
		//sprintf(pNode->RetCode,"%d",E_TRANS_SCHCARD_PWDERR);
		return E_TRANS_SCHCARD_PWDERR;
	}
	if(strncmp(card.state_id,TYPE_YES,1)!=0)
	{
		DB_t_pif_card_free_lock_by_cur();
		writelog(LOG_ERR,"card_state=[%s]",card.state_id);
		return E_TRANS_SCHACC_DESTORY;
	}
	if(STATE_TRUE==card.state_id[CARDSTAT_TYPE_LOST])
	{
		DB_t_pif_card_free_lock_by_cur();
		writelog(LOG_ERR,"card_state=[%s]",card.state_id);
		return E_TRANS_SCHCARD_LOSTING;
	}
	if(STATE_TRUE==card.state_id[CARDSTAT_TYPE_FREEZE])
	{
		DB_t_pif_card_free_lock_by_cur();
		writelog(LOG_ERR,"card_state=[%s]",card.state_id);
		return E_TRANS_SCHCARD_FREEZE;
	}
	ret=DB_t_tif_tradeserial_open_select_by_cur3_and_serial_type_and_card_id(TRADE_INNER_TRANS,card.card_id);
	if(ret)
	{
			db_chk_err(__FILE__,__LINE__,&sqlca);
			writelog(LOG_ALERT,"declare cursor err sqlcode[%d]",ret);
			return E_TRANS_UNKNOW_ERROR;
	}
	SetCol(handle,0);
   	SetCol(handle,F_SCLOSE_EMP,F_SORDER0,F_SORDER1,F_SSERIAL1,F_LVOL0,F_LVOL1,F_SDATE0,F_STIME0,F_SDATE1,F_STIME1,F_SCUST_NO,F_SCHANGE_EMP,F_SSERIAL0,F_LVOL2,F_SCUST_AUTH,F_SSTATUS1,F_SEMP_PWD,F_SEMP_PWD2,F_SSTATION0,F_SSTATION1,F_SORDER2,0);

	while(1)
	{
		ret=DB_t_tif_tradeserial_fetch_select_by_cur3(&tradeserial);
		if(ret)
		{
			DB_t_tif_tradeserial_close_select_by_cur3();
			if(ret==DB_NOTFOUND)
			{
				if(cnt==0)
					{
						writelog(LOG_DEBUG,"There havn't record from t_tif_tradeserial table!");
						break;
					}
				else		break;
			}
			else
				return   E_TRANS_UNKNOW_ERROR;
		}
		cnt++;

		memcpy(from_pos.TradeDate,tradeserial.operate_date,sizeof(from_pos.TradeDate));
		memcpy(from_pos.TradeTime,tradeserial.operate_time,sizeof(from_pos.TradeTime));
		sprintf(from_pos.CardNo,"%d",tradeserial.card_id);
		memcpy(from_pos.BankCardNo,tradeserial.b_act_id,sizeof(from_pos.BankCardNo));
		sprintf(from_pos.TransMoney,"%d",int(tradeserial.trade_fee)*100);
		if(tradeserial.serial_state!=2)
		{
			sprintf(from_pos.RetCode,"%s","失败");
		}
		else sprintf(from_pos.RetCode,"%s","成功");

		//开始返回应答包
		Strncpy_t(out_pack->sclose_emp,from_pos.TradeCode,sizeof(out_pack->sclose_emp));
		Strncpy_t(out_pack->sorder0,from_pos.TransMoney,sizeof(out_pack->sorder0));
		Strncpy_t(out_pack->sorder1,from_pos.ExtraMoney,sizeof(out_pack->sorder1));
		Strncpy_t(out_pack->sserial1,from_pos.AccountMoney,sizeof(out_pack->sserial1));
		out_pack->lvol0=from_pos.SendNo;
		out_pack->lvol1=from_pos.RecvNo;
		memcpy(out_pack->sdate0,from_pos.TradeDate,sizeof(from_pos.TradeDate));
		memcpy(out_pack->stime0,from_pos.TradeTime,sizeof(from_pos.TradeTime));
		memcpy(out_pack->sdate1,from_pos.BankDate,sizeof(from_pos.BankDate));
		memcpy(out_pack->stime1,from_pos.BankTime,sizeof(from_pos.BankTime));
		Strncpy_t(out_pack->scust_no,from_pos.Balance,sizeof(out_pack->scust_no));
		Strncpy_t(out_pack->schange_emp,from_pos.RetCode,sizeof(out_pack->schange_emp));
		Strncpy_t(out_pack->sserial0,from_pos.CardNo,sizeof(out_pack->sserial0));
		out_pack->lvol2=from_pos.Notecase;
		Strncpy_t(out_pack->scust_auth,from_pos.BankCardNo,sizeof(out_pack->scust_auth));
		sprintf(out_pack->sstatus1,"%c",from_pos.MngFeeFlag);
		Strncpy_t(out_pack->semp_pwd,from_pos.AccountPwd,sizeof(out_pack->semp_pwd));
		Strncpy_t(out_pack->semp_pwd2,from_pos.AccountNewPwd,sizeof(out_pack->semp_pwd2));
		Strncpy_t(out_pack->sstation0,from_pos.BankCardPwd,sizeof(out_pack->sstation0));
		Strncpy_t(out_pack->sstation1,from_pos.BankCardNewPwd,sizeof(out_pack->sstation1));
		Strncpy_t(out_pack->sorder2,from_pos.TerminalId,sizeof(out_pack->sorder2));
//	printf("LINE:%d\n",__LINE__);

		PutRow(handle,out_pack,pRetCode,szMsg);
		if(cnt>=10)
		{
			DB_t_tif_tradeserial_close_select_by_cur3();
			break;
		}
	}
//	printf("LINE:%d\n",__LINE__);


	T_t_tif_tradeserial_his tradeserial_his;
	memset(&tradeserial_his,0,sizeof(tradeserial_his));

	if(cnt<10)
	{
		ret=DB_t_tif_tradeserial_his_open_select_by_cur1_and_serial_type_and_card_id(TRADE_INNER_TRANS,card.card_id);
		if(ret)
		{
				db_chk_err(__FILE__,__LINE__,&sqlca);
				writelog(LOG_ALERT,"declare cursor err sqlcode[%d]",ret);
				return E_TRANS_UNKNOW_ERROR;
		}
	//	printf("LINE:%d\n",__LINE__);

		while(1)
		{
			ret=DB_t_tif_tradeserial_his_fetch_select_by_cur1(&tradeserial_his);
			if(ret)
			{
				DB_t_tif_tradeserial_his_close_select_by_cur1();
				if(ret==DB_NOTFOUND)
				{
					writelog(LOG_DEBUG,"There havn't record from t_tif_tradeserial_his table!");
					break;
				}
				else
					return   E_TRANS_UNKNOW_ERROR;
			}
			cnt++;

			memcpy(from_pos.TradeDate,tradeserial_his.operate_date,sizeof(from_pos.TradeDate));
			memcpy(from_pos.TradeTime,tradeserial_his.operate_time,sizeof(from_pos.TradeTime));
			sprintf(from_pos.CardNo,"%d",tradeserial_his.card_id);
			memcpy(from_pos.BankCardNo,tradeserial_his.b_act_id,sizeof(from_pos.BankCardNo));
			sprintf(from_pos.TransMoney,"%d",int(tradeserial_his.trade_fee)*100);
			if(tradeserial_his.serial_state!=2)
			{
				sprintf(from_pos.RetCode,"%s","失败");
			}
			else sprintf(from_pos.RetCode,"%s","成功");

			//开始返回应答包
			Strncpy_t(out_pack->sclose_emp,from_pos.TradeCode,sizeof(out_pack->sclose_emp));
			Strncpy_t(out_pack->sorder0,from_pos.TransMoney,sizeof(out_pack->sorder0));
			Strncpy_t(out_pack->sorder1,from_pos.ExtraMoney,sizeof(out_pack->sorder1));
			Strncpy_t(out_pack->sserial1,from_pos.AccountMoney,sizeof(out_pack->sserial1));
			out_pack->lvol0=from_pos.SendNo;
			out_pack->lvol1=from_pos.RecvNo;
			Strncpy_t(out_pack->sdate0,from_pos.TradeDate,sizeof(out_pack->sdate0));
			Strncpy_t(out_pack->stime0,from_pos.TradeTime,sizeof(out_pack->stime0));
			Strncpy_t(out_pack->sdate1,from_pos.BankDate,sizeof(out_pack->sdate1));
			Strncpy_t(out_pack->stime1,from_pos.BankTime,sizeof(out_pack->stime1));
			Strncpy_t(out_pack->scust_no,from_pos.Balance,sizeof(out_pack->scust_no));
			Strncpy_t(out_pack->schange_emp,from_pos.RetCode,sizeof(out_pack->schange_emp));
			Strncpy_t(out_pack->sserial0,from_pos.CardNo,sizeof(out_pack->sserial0));
			out_pack->lvol2=from_pos.Notecase;
			Strncpy_t(out_pack->scust_auth,from_pos.BankCardNo,sizeof(out_pack->scust_auth));
			sprintf(out_pack->sstatus1,"%c",from_pos.MngFeeFlag);
			Strncpy_t(out_pack->semp_pwd,from_pos.AccountPwd,sizeof(out_pack->semp_pwd));
			Strncpy_t(out_pack->semp_pwd2,from_pos.AccountNewPwd,sizeof(out_pack->semp_pwd2));
			Strncpy_t(out_pack->sstation0,from_pos.BankCardPwd,sizeof(out_pack->sstation0));
			Strncpy_t(out_pack->sstation1,from_pos.BankCardNewPwd,sizeof(out_pack->sstation1));
			Strncpy_t(out_pack->sorder2,from_pos.TerminalId,sizeof(out_pack->sorder2));

			PutRow(handle,out_pack,pRetCode,szMsg);
			if(cnt>=10)
			{
				DB_t_tif_tradeserial_his_close_select_by_cur1();
				break;
			}

		}
	}


	writelog(LOG_INFO,"query trans record succeed!");
	return 0;
}
예제 #7
0
//取消换卡
static int DoCardInsteadCancel(TRUSERID *handle,ST_PACK *rPack,int *pRetCode,char *szMsg) {
    int ret=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;
    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);

    SetCol(handle,0);

    SetCol(handle,F_LVOL1,F_LSAFE_LEVEL2,F_LVOL4,F_LVOL5,
           F_SALL_NAME,F_SPAGER,F_SCERT_NO,
           F_SEMAIL2,F_SMARKET_CODE,F_SDATE0,
           F_LVOL0,F_STX_PWD,F_LVOL8,F_LVOL6,F_LSAFE_LEVEL,F_SMARKET_CODE2,F_SHOLDER_AC_NO,
           F_SORDER0,F_SEMP,F_SDATE3,F_STIME3,F_LVOL11,F_LVOL12,
           F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,F_SNAME2,0);

    T_t_card  tCard;
    memset(&tCard,0,sizeof(tCard));
    ret=DB_t_card_read_by_cardno(trans.cardno,&tCard);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDNO,trans.cardno);
        else
            return E_DB_CARD_R;
    }
    if(tCard.status[0]!=STATUS_NORMAL) {
        return ERRINFO(E_CARD_LOGOUT,trans.cardno);
    }
    if('1'==tCard.frozeflag[0]) {
        return ERRINFO(E_CARD_FREEZE,trans.cardno);
    }
    if('1'==tCard.lossflag[0]) {
        return ERRINFO(E_CARD_LOST,trans.cardno);
    }
    if('1'==tCard.badflag[0]) {
        return ERRINFO(E_CARD_BADRECORD,trans.cardno);
    }
    T_t_account tCardAccount;
    memset(&tCardAccount,0,sizeof(tCardAccount));
    ret=DB_t_account_read_by_accno(tCard.accno,&tCardAccount);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDACCNO,tCard.accno);
        else
            return E_DB_ACCOUNT_R;
    }

    T_t_customer  customer;
    memset(&customer,0,sizeof(customer));
    if(tCard.custid) {
        ret=DB_t_customer_read_by_custid(tCard.custid,&customer);
        if(ret) {
            if(DB_NOTFOUND==ret)
                return ERRINFO(E_NOTEXIST_CUSTOMER,tCard.custid);
            else
                return E_DB_CUSTOMER_R;
        }
    }
    char cardpwd[33]="";
    char key[17]="";
    strcpy(key,STATIC_SEED_KEY);
    EncodePwd(key,cardpwd,tCard.cardpwd, 1);
    T_t_cardinsteaddtl cardinsteaddtl;

    memset(&cardinsteaddtl,0,sizeof(cardinsteaddtl));
    ret=DB_t_cardinsteaddtl_read_lock_by_c0_and_cardno(trans.cardno,&cardinsteaddtl);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return E_DB_CARDINSTEADDTL_N;
        else
            return E_DB_CARDINSTEADDTL_R;
    }
    if(cardinsteaddtl.status[0]==STATUS_NORMAL) {
        T_t_transdtl transdtl;
        memset(&transdtl,0,sizeof(transdtl));

        des2src(transdtl.transdate,trans.transdate);
        des2src(transdtl.transtime,trans.transtime);
        des2src(transdtl.accdate,pAccTrans->trans.accdate);
        des2src(transdtl.acctime,trans.acctime);
        transdtl.termid=trans.termid;
        transdtl.termseqno=trans.termseqno;
        transdtl.transcode=trans.transcode;
        transdtl.paytype=trans.fundtype;
        des2src(transdtl.voucherno,trans.voucherno);
        transdtl.cardno=trans.cardno;
        transdtl.purseno=trans.purseno;
        transdtl.cardcnt=cardinsteaddtl.oldcardcnt;
        transdtl.cardbefbal=cardinsteaddtl.oldcardbal;
        transdtl.cardaftbal=transdtl.cardbefbal;

        transdtl.managefee=trans.totalfeeamt;
        transdtl.amount=trans.totaltransamt;
        transdtl.custid=tCard.custid;
        des2src(transdtl.custname,customer.custname);
        des2src(transdtl.stuempno,customer.stuempno);
        des2src(transdtl.opercode,trans.opercode);
        transdtl.status[0]=DTLSTATUS_SUCCESS;
        des2src(transdtl.showcardno,cardinsteaddtl.oldshowcardno);
        ret=DB_t_transdtl_add(&transdtl);
        if(ret) {
            if(DB_REPEAT==ret)
                return E_DB_TRANSDTL_E;
            else
                return E_DB_TRANSDTL_I;
        }
        outPack->lvol1=tCard.custid;
        outPack->lsafe_level2=customer.custtype;
        outPack->lvol5=tCard.feetype;
        des2src(outPack->sall_name,customer.custname);
        des2src(outPack->spager,customer.stuempno);
        des2src(outPack->scert_no,customer.deptcode);
        des2src(outPack->semail2,customer.idno);
        des2src(outPack->smarket_code,customer.sex);
        des2src(outPack->sdate0,tCard.expiredate);
        sprintf(outPack->sholder_ac_no,"%d",10);				//发行方标识
        des2src(outPack->smarket_code2,customer.idtype);
        des2src(outPack->sname2,tCard.cardverno);
        outPack->lsafe_level=tCard.cardtype;
        outPack->lvol0=tCard.cardno;
        outPack->lvol8=(int)(cardinsteaddtl.oldcardbal*100);
        outPack->lvol4=cardinsteaddtl.oldsubsidyno;
        outPack->lvol11=D4U5(tCardAccount.singlemaxamt*100,0);
        outPack->lvol12=D4U5(tCardAccount.daycostmaxamt*100,0);
        outPack->lvol6=cardinsteaddtl.oldcardcnt;
        des2src(outPack->sorder0,tCard.showcardno);
        des2src(outPack->sdate3,pAccTrans->trans.accdate);
        des2src(outPack->stime3,pAccTrans->trans.acctime);
        des2src(outPack->semp,trans.opercode);
        outPack->lwithdraw_flag=trans.termid;
        outPack->lserial1=trans.termseqno;
        des2src(outPack->stx_pwd,cardpwd);
        PutRow(handle,outPack,pRetCode,szMsg);
        return 0;
    }
    if(cardinsteaddtl.revflag[0]=='1') {
        return E_CARDINSTEAD_CANCEL;
    }
    T_t_card cardtmp;
    memset(&cardtmp,0,sizeof(cardtmp));
    ret=DB_t_card_read_by_cardphyid_and_status(trans.cardphyid,"1",&cardtmp);
    if(ret!=DB_NOTFOUND) {
        if(DB_SUCCESS==ret)
            return ERRINFO(E_EXIST_CARDPHYID,trans.cardphyid);
        else
            return E_DB_CARD_R;
    }
    if(pAccTrans->sysPara.bEnableCardMgr) {
        ret=DB_t_card_read_by_showcardno_and_status(trans.showcardno,"1",&tCard);
        if(ret!=DB_NOTFOUND) {
            if(DB_SUCCESS==ret)
                return ERRINFO(E_EXIST_SHOWCARDNO,trans.showcardno);
            else
                return E_DB_CARD_R;
        }
        //回收卡
        ret=UseShowCardNoBack(trans.opercode,cardinsteaddtl.showcardno);
        if(ret) {
            return ret;
        }
        T_t_carddtl carddtl;
        memset(&carddtl,0,sizeof(carddtl));

        des2src(carddtl.accdate,pAccTrans->trans.accdate);
        des2src(carddtl.acctime,trans.acctime);
        carddtl.termid=trans.termid;
        carddtl.termseqno=trans.termseqno;
        des2src(carddtl.opercode,trans.opercode);
        carddtl.cardtype=trans.cardtype;
        carddtl.usetype=CARDUSETYPE_REUSE;
        carddtl.inoutflag=INOUTFLAG_IN;
        carddtl.transcnt=1;
        strcpy(carddtl.summary,"换卡撤销(新卡回收)");
        des2src(carddtl.cardphyid,cardinsteaddtl.cardphyid);
        des2src(carddtl.showcardno,cardinsteaddtl.showcardno);

        ret=DB_t_carddtl_add(&carddtl);
        if(ret) {
            if(DB_REPEAT==ret)
                return E_DB_CARDDTL_E;
            else
                return E_DB_CARDDTL_I;
        }
        //使用原卡
        int cardtype=0;
        ret=UseShowCardNo(trans.opercode,cardinsteaddtl.oldshowcardno,cardtype);
        if(ret) {
            return ret;
        }
        memset(&carddtl,0,sizeof(carddtl));

        des2src(carddtl.accdate,pAccTrans->trans.accdate);
        des2src(carddtl.acctime,trans.acctime);
        carddtl.termid=trans.termid;
        carddtl.termseqno=trans.termseqno;
        des2src(carddtl.opercode,trans.opercode);
        carddtl.cardtype=cardinsteaddtl.oldcardtype;
        carddtl.usetype=CARDUSETYPE_USE;
        carddtl.inoutflag=INOUTFLAG_OUT;
        carddtl.transcnt=1;
        strcpy(carddtl.summary,"换卡撤销(重发原卡)");
        des2src(carddtl.cardphyid,cardinsteaddtl.oldcardphyid);
        des2src(carddtl.showcardno,cardinsteaddtl.oldshowcardno);
        ret=DB_t_carddtl_add(&carddtl);
        if(ret) {
            if(DB_REPEAT==ret)
                return E_DB_CARDDTL_E;
            else
                return E_DB_CARDDTL_I;
        }
    }
    //更新卡信息
    memset(&tCard,0,sizeof(tCard));
    ret=DB_t_card_read_lock_by_cur_and_cardno(trans.cardno,&tCard);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return E_NOTEXIST_CARDNO;
        else
            return E_DB_CARD_R;
    }
    if(tCard.status[0]!=STATUS_NORMAL) {
        DB_t_card_free_lock_by_cur();
        return E_CARD_LOGOUT;
    }
    tCard.cardtype=cardinsteaddtl.oldcardtype;
    des2src(tCard.cardphyid,cardinsteaddtl.oldcardphyid);
    des2src(tCard.showcardno,cardinsteaddtl.oldshowcardno);
    ret=DB_t_card_update_lock_by_cur(&tCard);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return E_NOTEXIST_CARDNO;
        else
            return E_DB_CARD_U;
    }
    T_t_transdtl transdtl;
    memset(&transdtl,0,sizeof(transdtl));

    des2src(transdtl.transdate,trans.transdate);
    des2src(transdtl.transtime,trans.transtime);
    strcpy(transdtl.accdate,trans.accdate);
    strcpy(transdtl.acctime,trans.acctime);
    transdtl.termid=trans.termid;
    transdtl.termseqno=trans.termseqno;
    transdtl.transcode=trans.transcode;
    transdtl.paytype=trans.fundtype;
    des2src(transdtl.voucherno,trans.voucherno);
    transdtl.cardno=trans.cardno;
    transdtl.purseno=trans.purseno;
    transdtl.cardcnt=cardinsteaddtl.oldcardcnt;
    transdtl.cardbefbal=cardinsteaddtl.oldcardbal;
    transdtl.cardaftbal=transdtl.cardbefbal;

    transdtl.managefee=trans.totalfeeamt;
    transdtl.amount=trans.totaltransamt;
    transdtl.custid=tCard.custid;
    des2src(transdtl.custname,customer.custname);
    des2src(transdtl.stuempno,customer.stuempno);
    des2src(transdtl.opercode,trans.opercode);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    des2src(transdtl.showcardno,cardinsteaddtl.oldshowcardno);
    ret=DB_t_transdtl_add(&transdtl);
    if(ret) {
        if(DB_REPEAT==ret)
            return E_DB_TRANSDTL_E;
        else
            return E_DB_TRANSDTL_I;
    }
    outPack->lvol1=tCard.custid;
    outPack->lsafe_level2=customer.custtype;
    outPack->lvol5=trans.feetype;
    des2src(outPack->sall_name,customer.custname);
    des2src(outPack->spager,customer.stuempno);
    des2src(outPack->scert_no,customer.deptcode);
    des2src(outPack->semail2,customer.idno);
    des2src(outPack->smarket_code,customer.sex);
    des2src(outPack->sdate0,tCard.expiredate);
    des2src(outPack->smarket_code2,customer.idtype);
    sprintf(outPack->sholder_ac_no,"%d",10);				//发行方标识
    des2src(outPack->sname2,tCard.cardverno);
    outPack->lsafe_level=tCard.cardtype;
    outPack->lvol0=tCard.cardno;
    outPack->lvol4=cardinsteaddtl.oldsubsidyno;
    outPack->lvol8=(int)(cardinsteaddtl.oldcardbal*100);
    outPack->lvol11=D4U5(tCardAccount.singlemaxamt*100,0);
    outPack->lvol12=D4U5(tCardAccount.daycostmaxamt*100,0);
    outPack->lvol6=cardinsteaddtl.oldcardcnt;
    des2src(outPack->sorder0,tCard.showcardno);
    des2src(outPack->sdate3,pAccTrans->trans.accdate);
    des2src(outPack->stime3,pAccTrans->trans.acctime);
    des2src(outPack->semp,trans.opercode);
    des2src(outPack->stx_pwd,cardpwd);
    outPack->lwithdraw_flag=trans.termid;
    outPack->lserial1=trans.termseqno;
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
예제 #8
0
static int doCard(TRANS& trans,T_t_card& tCard)
{

	int ret=0;

	ret=DB_t_card_read_lock_by_cur_and_cardno(trans.cardno,&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",trans.cardno);
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDNO,trans.cardno);
		else 
			return E_DB_CARD_R;
	}
	if(tCard.status[0]!=STATUS_NORMAL)
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_LOGOUT,trans.cardno);
	}	
	if('1'==tCard.frozeflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_FREEZE,trans.cardno);
	}
	if('1'==tCard.lossflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_LOST,trans.cardno);
	}	
	if('1'==tCard.badflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_BADRECORD,trans.cardno);
	}	
		//比较卡物理ID是否相同
	if(strcmp(tCard.cardphyid,trans.cardphyid)!=0)
	{
		writelog(LOG_ERR,"db cardphyid[%s],input cardphyid[%s]",tCard.cardphyid,trans.cardphyid);
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_PHYNO_DIFFER,trans.cardphyid,tCard.cardphyid);
	}
	//回收卡
	T_t_cardtype tCardType;

	memset(&tCardType,0,sizeof(tCardType));
		
	ret=DB_t_cardtype_read_by_cardtype(tCard.cardtype,&tCardType);
	if(tCardType.recycleable[0]!='1')
	{
		DB_t_card_free_lock_by_cur();
		return	ERRINFO(E_CARDTYPE_CANNOT_REUSE,tCardType.cardtype);
	}
	if(tCardType.fixdaycnt<1)
	{
		DB_t_card_free_lock_by_cur();		
		return ERRINFO(E_NOSET_CARDTYPE_VALIDDAYS,tCardType.cardtype);
	}
	ret=calcEndDate(trans.transdate,tCardType.fixdaycnt,tCard.expiredate);
	if(ret)
	{
		DB_t_card_free_lock_by_cur();		
		return ret;
	}
	char cardpwd[33]="";
	char key[17]="";
	get_init_passwd_by_man_id("",cardpwd);
	strcpy(key,STATIC_SEED_KEY);
	EncodePwd(key,cardpwd,tCard.cardpwd, 0);
//	memset(tCard.cardstatus,'0',sizeof(tCard.cardstatus));
	des2src(tCard.lastsaved,trans.sysdatetime);

	ret=DB_t_card_update_lock_by_cur(&tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_CARD_N;
		else 
			return E_DB_CARD_U;
	}
	//用来输出卡密码
	strcpy(tCard.cardpwd,cardpwd);
	/*
	//添加卡片回收明细记录
	T_t_carddtl tCarddtl;
	
	memset(&tCarddtl,0,sizeof(tCarddtl));
	/////////////////////////////////rPack2TableStuct////////////////////////
	des2src(tCarddtl.accdate,pAccTrans->sysPara.sSettleDate);
	tCarddtl.termid=trans.termid;
	tCarddtl.termseqno=trans.termseqno;
	tCarddtl.cardtype=tCard.cardtype;
	des2src(tCarddtl.showcardno,tCard.showcardno);
	des2src(tCarddtl.cardphyid,tCard.cardphyid);
	tCarddtl.cardusetype=CARDUSETYPE_RETURNCARD;
	des2src(tCarddtl.opercode,trans.opercode);
	ret=DB_t_carddtl_add(&tCarddtl);
	if(ret)
	{
		if(DB_REPEAT==ret)
			return E_DB_CARDDTL_E;
		else
			return E_DB_CARDDTL_I;
	}
	*/
	return 0;
}
예제 #9
0
파일: F847125.c 프로젝트: nykma/ykt4sungard
int F847125(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
    int	hi_cuttype = 0;										//客户类型
    int i=0;
    int ret = 0;
    double dUniqno=0;
    char h_showcardid[11] = "";								//显示卡号
    char h_password[7] = "";									//卡密码
    double h_temp_Card_id = 0;								//卡号
    char seed_key[17] = "";									//种子密钥
    char card_endtime[8 + 1] = "";							//卡的有效截至日期
    char logicdate[11]="";
    char sysdate[11]="";
    char systime[9]="";
    char sMsg[256]="";
    double dSerial_no = 0;
    char sMaxCardBalance[20]="";
    double dMaxCardBalance=0;
    T_t_pif_card tCard;
    T_t_aif_account  tAccount;
    T_t_tif_tradeserial  tradeserial;
    T_t_cif_customer  tCustomer;
    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_DAMT4,F_DAMT5,F_LSERIAL1,F_VSMESS,0);

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

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

    tradeserial.trade_fee=rPack->damt0;					//发生额
    hi_cuttype = rPack->lvol3;									//客户类别
    trim(rPack->scust_no);
    des2src(h_showcardid,rPack->scust_no);					//显示卡号
    des2src(tCard.physical_no, rPack->sbank_acc);				//物理卡号
    des2src(card_endtime,rPack->sdate0);
    getsysdate(sysdate);
    getsystime(systime);
    ret=GetLogicDate(logicdate);								//业务日期
    if(ret)
    {
        *pRetCode=ret;
        goto L_RETU;
    }
    ret=IsInvalidDateTime(card_endtime,"YYYYMMDD");
    if(ret)
    {
        *pRetCode=ret;
        goto L_RETU;
    }
    if(strlen(h_showcardid)!=10)
    {
        *pRetCode=E_INPUT_SHOWID;
        goto L_RETU;
    }
    ret=IsExistShowCardNo(h_showcardid);
    if(ret)
    {
        *pRetCode = ret;
        goto L_RETU;
    }
    ret=IsExistCardByPhyCardNo(tCard.physical_no);			//物理卡号
    if(ret)
    {
        writelog(LOG_ERR,"physical_no[%s]",tCard.physical_no);
        *pRetCode = ret;
        goto L_RETU;
    }
    //检查金额是否超过最大额度
    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;
    }
//先增加客户
    ret=getNewUniqNo(KEYTYPE_CUSTOMER, &dUniqno);
    if(ret)
    {
        *pRetCode=ret;
        writelog(LOG_ERR,"getNewUniqNo err[%d]",ret);
        goto L_RETU;
    }
    tCustomer.cut_id=(int)dUniqno;
    tCustomer.cut_type=hi_cuttype;					//客户类型
    tCustomer.fee_type=tCustomer.cut_type;
    tCustomer.cut_state=CUSTSTAT_REGIST;
    des2src(tCustomer.is_havecard,TYPE_YES);
//	tCustomer.area=rPack->lvol10;						//区域
    /*
    	ret=GetTempPersonId(tCustomer.stuemp_no);	//员工号
    	if(ret)
    	{
    		*pRetCode=ret;
    		goto L_RETU;
    	}
    */
//	des2src(tCustomer.stuemp_no,h_showcardid);
    snprintf(tCustomer.cut_name,20,"临%.10s",h_showcardid);			//客户 名称
    des2src(tCustomer.reg_time,sysdate);							//注册日期
    ret=DB_t_cif_customer_add(&tCustomer);
    if(ret)
    {
        *pRetCode = E_DB_CUSTOMER_I;
        writelog(LOG_ERR,"DB_t_cif_customer_add ret[%d]",ret);
        goto L_RETU;
    }
    //	准备数据插入卡信息表
    memcpy(seed_key,STATIC_SEED_KEY,sizeof(seed_key));						//读种子密钥

    //	默认密码, 初始取身份证的后6位, 没有身份证号用666666.
    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_NONAME;											//卡类别
    EncodePwd(seed_key,h_password,tCard.password,0);							//卡密码
    tCard.cosumer_id = tCustomer.cut_id;											//客户标识
    tCard.account_count = ACCOUNT_COUNT_ONE;									//卡对应帐户个数
    des2src(tCard.begin_time,logicdate);											//注册时间
    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 = tCustomer.cut_id;				        					//客户号
    des2src(tAccount.cut_name,tCustomer.cut_name);								//客户名称
    tAccount.cut_type = hi_cuttype;												//客户类别
    des2src(tAccount.stuemp_no,tCustomer.stuemp_no); 							//客户学号或员工号
    tAccount.card_id =tCard.card_id; 											//关联卡号
    tAccount.purse_id = PURSE_NO_ONE;										//关联卡钱包号
    tAccount.card_type = tCard.type_id;											//卡类别
    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;
    }
    //准备数据插入交易流水表
    ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dSerial_no);  						//获得最大流水号
    if(ret)
    {
        *pRetCode = ret;
        goto L_RETU;
    }
    tradeserial.serial_no = (int)dSerial_no;											//流水号
    tradeserial.other_seri_no = 0;														//上传端流水号
    tradeserial.serial_type = TXCODE_CARD_OPEN_FOR_TEMP;								//交易代码
    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 = tCustomer.cut_id;											//客户标识
    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->damt4=tradeserial.cost_fee;						//卡 成本 费
    out_pack->damt5=tradeserial.in_fee;							//手续费
    out_pack->lserial1=tradeserial.serial_no;						//流水号

    PutRow(handle,out_pack,pRetCode,szMsg);
    return 0;
L_RETU:
    return -1;
}
예제 #10
0
int F847101(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int	hi_custid = 0;											//客户ID
	int	hi_custtype = 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[8 + 1] = "";						//卡的有效截至日期
	char logicdate[11]="";								//业务日期
	char sysdate[11]="";
	char systime[9]="";
	char sMsg[256]="";
	char sMaxCardBalance[20]="";
	double dMaxCardBalance=0;
	int 	type=0;										//充值类型
	T_t_customer tCustomer;
	T_t_card tCard;

	T_t_aif_account  tAccount;
	T_t_tif_tradeserial  tradeserial;
	T_t_tif_savdtl		tSavdtl;
	T_t_spefee 	tSpeFee;
	double dUniqNo = 0;
	InAcc	IA;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

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

#ifdef DEBUG
	writelog(LOG_DEBUG,"rPack->scust_auth2[%s]",rPack->scust_auth2);
#endif
	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);
	hi_custid = rPack->lvol0;									//客户ID
	hi_custtype = rPack->lvol3;									//客户类别
	des2src(h_showcardid,rPack->scust_no);					//显示卡号
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	//检查客户信息,判断是否可以发行卡
	des2src(tCard.cardphyid, rPack->sbank_acc);				//物理卡号
	trim(h_showcardid);
	if(strlen(h_showcardid))
	{
		ret=IsExistShowCardNo(h_showcardid);
		if(ret)
		{
			*pRetCode = ret;
			goto L_RETU;
		}
	}
	ret=IsExistCardByPhyCardNo(tCard.cardphyid);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	ret=IsExistCardByCustomId(hi_custid);
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	//ret = DB_t_customer_read_by_custid(hi_custid, &tCustomer);

	//得到收费类别

	memset(&tCustomer,0,sizeof tCustomer);
	ret=DB_t_customer_read_lock_by_cur_and_custid(hi_custid, &tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"custid[%d]",hi_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();

	tradeserial.trade_fee =D4U5(rPack->damt0,2);

	//检查金额是否超过最大额度
	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,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);
	}
	//	默认密码, 初始取身份证的后6位, 没有身份证号用666666.
	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,DEFAULT_CUST_PWD);
	}
	EncodePwd(seed_key,h_password,tCard.password,0);							//卡密码
	ret = getNewUniqNo(KEYTYPE_CARD_ID,&h_temp_Card_id);						//获取最大卡号
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	tCard.cardno = D2I(h_temp_Card_id);											//卡号
	des2src(tCard.showid,h_showcardid);										//显示卡号
	des2src(tCard.is_main,TYPE_YES);  											//是否为主卡
	des2src(tCard.cardattr,CARDSTAT_REG);										//卡状态
	tCard.type_id = CT_NORMAL;													//卡类别
	EncodePwd(seed_key,h_password,tCard.password,0);							//卡密码
	tCard.custid = hi_custid;													//客户标识
	tCard.account_count = ACCOUNT_COUNT_ONE;									//卡对应帐户个数
	des2src(tCard.begintime,sysdate);											//注册时间
	des2src(tCard.endtime, card_endtime);										//截至时间

	tCard.phytype = PHYTYPE_NO_ONE;											//设备物理型号;默认为1
	//	插入卡信息
	ret = DB_t_card_add(&tCard);
	if (ret)
	{
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_CARD_E;
		else
			*pRetCode = E_DB_CARD_I;
		goto L_RETU;
	}

	T_t_cardbitmap tCardBitmap;

	tCardBitmap.cardno=tCard.cardno;
	tCardBitmap.base_no=0;
	memset(tCardBitmap.bitmap,'0',sizeof(tCardBitmap.bitmap));
	tCardBitmap.bitmap[0]='1';
	
	ret=DB_t_cardbitmap_add(&tCardBitmap);
	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,sysdate);		   								//开户时间
	des2src(tAccount.open_time,systime);
	tAccount.current_state = ACCOUNTSTAT_REGIST;      							//当前状态
	tAccount.act_type = ACCTYPE_PERMAIN;				        					//帐号类别
	tAccount.custid = tCustomer.custid;				        					//客户号
	des2src(tAccount.custname,tCustomer.custname);								//客户名称
	tAccount.custtype = tCustomer.custtype;										//客户类别
	des2src(tAccount.stuempno,tCustomer.stuempno); 							//客户学号或员工号
	tAccount.cardno = tCard.cardno;		 										//关联卡号
	tAccount.purseno = PURSE_NO_ONE;											//关联卡钱包号
	tAccount.card_type = CT_NORMAL;											//卡类别
	des2src(tAccount.subno,SUBJECT_INDIVIDUALSAVING);							//所属科目
	des2src(tAccount.isautotra,TYPE_NO); 										//是否自动转帐
	//	插入帐户信息表
	ret = DB_t_aif_account_add(&tAccount);
	if (ret)
	{
		writelog(LOG_ERR,"ret [%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_ACCOUNT_E;
		else
			*pRetCode = E_DB_ACCOUNT_I;
		goto L_RETU;
	}

	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqNo);  						//获得最大流水号
	if(ret)
	{
		*pRetCode = ret;
		writelog(LOG_ERR,"ret [%d]",ret);
		goto L_RETU;
	}
	// add by 汤成2005-09-05
	// 记录发行正式卡信息
	/////////////////////////////////////////////////////////////////////////
	ret = InsertToCutUpdList(tCard.cardno, CUTUPD_ADD,tCard.cardphyid);
	if( ret )
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	/////////////////////////////////////////////////////////////////////////
	tradeserial.serial_no = D2I(dUniqNo);											//流水号
	tradeserial.other_seri_no = 0;														//上传端流水号
	tradeserial.serial_state = SERISTAT_DEBT;												//流水状态
	tradeserial.serial_type =TXCODE_CARD_OPEN_CASH;
	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 = tCard.cardno;													//卡号
	des2src(tradeserial.showid,tCard.showid);												//显示卡号
	tradeserial.purseno = PURSE_NO_ONE;												//钱包号
	tradeserial.custid = hi_custid;													//客户标识

	des2src(tradeserial.opercode , rPack->scust_limit);			//操作员代码
	tradeserial.sys_id = 0;																//外部系统标识
	tradeserial.trade_count=1;														//当前卡交易次数
	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;
	}
	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.billno,rPack->sphone);		//票据号码
			if(strlen(tSavdtl.billno)<1)
			{
				*pRetCode=E_INPUT_BILLNO;
				goto L_RETU;
			}
			tSavdtl.cardno=tCard.cardno;				//卡号
			des2src(tSavdtl.oper_no,rPack->scust_limit);	//操作员
			tSavdtl.seqno=tradeserial.serial_no;			//流水号
			des2src(tSavdtl.tx_date,logicdate);			//发生日期
			des2src(tSavdtl.tx_time,systime);			//发生时间
			tSavdtl.cnt=1;								//票据数量
			tSavdtl.billtype=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.cardno;
	IA.iFeeType=tCustomer.feetype;
	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)
	{
		*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_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元",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 = CheckNewCardHook(&tCustomer, tCard.cardno);
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	*/
	//	返回卡号\密码\显示卡号\客户类型\图书证号\有效截至日期
	out_pack->lvol0 = (int)h_temp_Card_id;                      //交易卡号
	out_pack->lvol1 = tCustomer.custtype;						//客户类别
	out_pack->lvol5 = tCustomer.feetype;						//收费类别
	des2src(out_pack->scust_no,h_showcardid);					//显示卡号
	des2src(out_pack->scust_no2,tCustomer.deptcode);			//部门号
	des2src(out_pack->scust_auth,tCustomer.stuempno);			//学号
	des2src(out_pack->scust_auth2,tCustomer.man_id);			//身份证号
	des2src(out_pack->sname,tCustomer.custname);				//客户姓名
	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;						//流水号

	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
예제 #11
0
int F847124(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[8 + 1] = "";						//卡的有效截至日期
	char logicdate[11]="";								//业务日期
	char sysdate[11]="";
	char systime[9]="";
	char sMsg[256]="";
	char sMaxCardBalance[20]="";
	double dMaxCardBalance=0;
	int 	type=0;										//充值类型
	T_t_pif_card tCard;
	T_t_cif_customer tCustomer;
	T_t_aif_account  tAccount;
	T_t_tif_tradeserial  tradeserial;
	T_t_tif_savdtl		tSavdtl;
	T_t_pif_spefee 	tSpeFee;
	double h_temp_Serial_no = 0;
	InAcc	IA;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

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

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL5,
				F_SCUST_NO,	F_SCUST_NO2,F_SCUST_AUTH,F_SCERT_NO,
				F_SDATE0,F_SNAME,F_SNAME2,
				F_SOPEN_EMP,F_SSTATUS0,
				F_DAMT2,F_LSERIAL1,F_VSMESS,
   			       F_SORDER0,F_SORDER1,F_SORDER2,
   			       F_SHOLDER_AC_NO,F_SSTAT_TYPE,F_SSTAT_TYPE2,
   			       F_SNATION_CODE,F_SBRANCH_CODE0,
				0);

	hi_cutid = rPack->lvol0;									//客户ID
	hi_cuttype = rPack->lvol3;									//客户类别
	//满足大学城的需求,用客户号替代显示卡号
	//des2src(h_showcardid,rPack->scust_no);					//显示卡号
	sprintf(h_showcardid,"%010d",hi_cutid);
	getsysdate(sysdate);
	getsystime(systime);
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		*pRetCode=ret;
		goto L_RETU;
	}
	//检查客户信息,判断是否可以发行卡
	des2src(tCard.physical_no, rPack->sbank_acc);				//物理卡号
	trim(h_showcardid);
	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=IsExistCardByCustomId(hi_cutid);
	if (ret)
	{
		*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;
		}
		//更新客户表的收费类别字段
	}
	tCustomer.use_flag[0]='1';
	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 =rPack->damt0;

	//检查金额是否超过最大额度
	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));			//读种子密钥
	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);
/*
	ret = GetCardValiddate(hi_cuttype,logicdate,card_endtime);				//计算卡的有效期
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
*/
	//规则如下: 当发卡人在系统中的证件类别为身份证并有身份证号时,卡密码取身份证的后六位数字(例如...987654321则为654321;...98765432X则为765432),否则都为“888888”。
	if(strcmp(tCustomer.man_idtype,"1")==0)
	{
		get_init_passwd_by_man_id(tCustomer.man_id,h_password);
	}
	else
		strcpy(h_password,DEFAULT_CUST_PWD);
	ret = getNewUniqNo(KEYTYPE_CARD_ID,&h_temp_Card_id);						//获取最大卡号
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	tCard.card_id = D2I(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_NAME;													//卡类别
	EncodePwd(seed_key,h_password,tCard.password,0);							//卡密码
	tCard.cosumer_id = hi_cutid;													//客户标识
	tCard.account_count = ACCOUNT_COUNT_ONE;									//卡对应帐户个数
	des2src(tCard.begin_time,logicdate);											//注册时间
	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,sysdate);		   									//开户时间
	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 = tCard.card_id;		 										//关联卡号
	tAccount.purse_id = PURSE_NO_ONE;											//关联卡钱包号
	tAccount.card_type = tCard.type_id;												//卡类别
	des2src(tAccount.subno,SUBJECT_INDIVIDUALSAVING);							//所属科目
	des2src(tAccount.isautotra,TYPE_NO); 											//是否自动转帐
	//	插入帐户信息表
	ret = DB_t_aif_account_add(&tAccount);
	if (ret)
	{
		writelog(LOG_ERR,"ret [%d]",ret);
		if(DB_REPEAT==ret)
			*pRetCode = E_DB_ACCOUNT_E;
		else
			*pRetCode = E_DB_ACCOUNT_I;
		goto L_RETU;
	}

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

	tradeserial.serial_no = D2I(h_temp_Serial_no);											//流水号
	tradeserial.other_seri_no = 0;														//上传端流水号
	tradeserial.serial_type=TXCODE_CARD_OPEN_TMP_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 = tCard.card_id;													//卡号
	des2src(tradeserial.showid,tCard.showid);												//显示卡号
	tradeserial.purse_id = PURSE_NO_ONE;												//钱包号
	tradeserial.customer_id = hi_cutid;													//客户标识

	des2src(tradeserial.oper_code , rPack->scust_limit);									//操作员代码
	tradeserial.sys_id = 0;																//外部系统标识
	tradeserial.trade_count=1;															//当前卡交易次数
	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;
	}
	switch(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,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,logicdate);			//发生日期
			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;

	//调用入账子模块
	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_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:
				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元",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->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->scert_no,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);					//有效截至日期
	strcpy(out_pack->sorder0,CARD_STRUCT_VERSION);			//制卡版本号
	strcpy(out_pack->sorder1,CARD_REGISTER_PUBLISH_CODE);	//发卡注册标识号
	strcpy(out_pack->sorder2,CARD_REGISTER_SERVICE_CODE);	//服务注册标识号
	sprintf(out_pack->sholder_ac_no,"%ld",tCustomer.cut_id);		//客户号
	des2src(out_pack->sstat_type,tCustomer.man_idtype);			//证件类型
	des2src(out_pack->snation_code,tCustomer.country);			//国籍
	sprintf(out_pack->sstat_type2,"%d",tCustomer.nation);			//民族
	des2src(out_pack->sbranch_code0,tCustomer.school_code);		//院校代码


	out_pack->damt2=tradeserial.out_balance;					//出卡值
	out_pack->lserial1=tradeserial.serial_no;						//流水号

	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
예제 #12
0
int F847119(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	char h_password[7] = "";							//卡密码
	char seed_key[17] = "";							//种子密钥
	T_t_pif_card tCard;
	T_t_tif_tradeserial tradeserial;
	T_t_tif_writefailed tWriteFailed;
	T_t_cif_customer tCustomer;

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

	memset(&tCard,0,sizeof(tCard));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&tWriteFailed, 0, sizeof tWriteFailed);
	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,
		F_SORDER0,F_SORDER1,F_SORDER2,
		F_SHOLDER_AC_NO,F_SSTAT_TYPE,F_SSTAT_TYPE2,
		F_SNATION_CODE,F_SBRANCH_CODE0,
		   0);
	/************************************************************************/
	ret = do_process(&tCard, &tWriteFailed, rPack, &tradeserial);
	if (ret)
	{
		*pRetCode = ret;
		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;
	}
	EncodePwd(seed_key,h_password,tCard.password,1);			//卡密码
	DB_t_cif_customer_free_lock_cur();
	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);					//有效截至日期
	strcpy(out_pack->sorder0,CARD_STRUCT_VERSION);			//制卡版本号
	strcpy(out_pack->sorder1,CARD_REGISTER_PUBLISH_CODE);	//发卡注册标识号
	strcpy(out_pack->sorder2,CARD_REGISTER_SERVICE_CODE);	//服务注册标识号
	sprintf(out_pack->sholder_ac_no,"%d",tCustomer.cut_id);		//客户号
	des2src(out_pack->sstat_type,tCustomer.man_idtype);			//证件类型
	des2src(out_pack->snation_code,tCustomer.country);			//国籍
	sprintf(out_pack->sstat_type2,"%d",tCustomer.nation);			//民族
	des2src(out_pack->sbranch_code0,tCustomer.school_code);		//院校代码
	out_pack->damt2=tradeserial.out_balance;					//出卡值=入卡值+发生额
	out_pack->lserial1=tradeserial.serial_no;						//流水号

	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
예제 #13
0
int F846305(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
    int i=0;
    int ret=0;
    char sysdate[9]="";
    char systime[7]="";
    char sMsg[256]="";

    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;
    ret=pAccTrans->checkCfgUpdate();
    if(ret)
        return ret;
    pAccTrans->clear();
    ret=pAccTrans->initOperDtl(rPack->semp);
    if(ret)
        return ret;
    GetCpackDataString(rPack,pAccTrans->cpackdata);
    pAccTrans->trans.transcode=TC_CARDRENEW;
    ret=pAccTrans->addOperDtl();
    if(ret)
        return ret;
    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);


    SetCol(handle,0);


    //检查操作员

    //检查客户
    T_t_customer tCustomer;
    T_t_card  tOldCard;

    memset(&tCustomer,0,sizeof(tCustomer));
    memset(&tOldCard,0,sizeof(tOldCard));

    int cardno=rPack->lvol0;
    ret=check(cardno,tCustomer,tOldCard);
    if(ret)
        return ret;
    //注销原卡
    ret=DB_t_card_read_lock_by_cur_and_cardno(tOldCard.cardno,&tOldCard);
    if(ret)
    {
        writelog(LOG_ERR,"lost_cardno[%d]",tOldCard.cardno);
        if(DB_NOTFOUND==ret)
            return E_CARDNO_NOT_EXIST;
        else
            return E_DB_CARD_R;
    }
    tOldCard.status[0]=STATUS_LOGOUT;			//注销
    des2src(tOldCard.closedate,sysdate);		//注销日期
    ret=DB_t_card_update_lock_by_cur(&tOldCard);
    if(ret)
    {
        writelog(LOG_ERR,"lost_cardno[%d]",tOldCard.cardno);
        if(DB_NOTFOUND==ret)
            return E_CARDNO_NOT_EXIST;
        else
            return E_DB_CARD_R;
    }
    //使用卡片
    T_t_card  tCard;
    memset(&tCard,0,sizeof(tCard));

    des2src(tCard.cardphyid,rPack->sstation0);
    des2src(tCard.showcardno,rPack->sorder0);
    des2src(tCard.expiredate,tOldCard.expiredate);
    tCard.cardtype=tOldCard.cardtype;
    tCard.feetype=tOldCard.feetype;
    des2src(tCard.cardpwd,tOldCard.cardpwd);

    ret=chkShowCardNo(trans.opercode,tCard.cardtype,tCard.showcardno);
    if(ret)
    {
        return ret;
    }
    char cardpwd[33]="";
    char key[17]="";

    //get_init_passwd_by_man_id(tCustomer.idno,cardpwd);
    strcpy(key,STATIC_SEED_KEY);
    EncodePwd(key,cardpwd,tOldCard.cardpwd, 1);

    ret=AddCard(tCustomer,tCard);
    if(ret)
        return ret;
    //添加卡片使用明细
    T_t_carddtl tCarddtl;

    memset(&tCarddtl,0,sizeof(tCarddtl));
    /////////////////////////////////rPack2TableStuct////////////////////////
    des2src(tCarddtl.accdate,trans.accdate);
    tCarddtl.termid=trans.termid;
    tCarddtl.termseqno=trans.termseqno;
    tCarddtl.cardtype=tCard.cardtype;
    des2src(tCarddtl.showcardno,tCard.showcardno);
    des2src(tCarddtl.cardphyid,tCard.cardphyid);
    tCarddtl.cardusetype[0]=CARDUSETYPE_OPENCARD;
    des2src(tCarddtl.opercode,trans.opercode);
    ret=DB_t_carddtl_add(&tCarddtl);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDDTL_E;
        else
            return E_DB_CARDDTL_I;
    }

    //添加换卡记录
    T_t_cardinstead tCardinstead;

    memset(&tCardinstead,0,sizeof(tCardinstead));

    des2src(tCardinstead.accdate,trans.accdate);
    tCardinstead.termid=trans.termid;
    tCardinstead.termseqno=trans.termseqno;
    tCardinstead.oldcardno=tOldCard.cardno;
    des2src(tCardinstead.oldcardphyid,tOldCard.cardphyid);
    tCardinstead.cardno=tCard.cardno;
    des2src(tCardinstead.cardphyid,tCard.cardphyid);
    ret=DB_t_cardinstead_add(&tCardinstead);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDINSTEAD_E;
        else
            return E_DB_CARDINSTEAD_I;
    }
    //插入卡位图表
    T_t_cardbitmap tCardBitmap;

    tCardBitmap.cardno=tCard.cardno;
    tCardBitmap.baseno=0;
    memset(tCardBitmap.bitmap,'0',sizeof(tCardBitmap.bitmap));
    tCardBitmap.bitmap[0]='1';

    ret=DB_t_cardbitmap_add(&tCardBitmap);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDBITMAP_E;
        else
            return E_DB_CARDBITMAP_I;
    }

    T_t_account tCardaccount;
    memset(&tCardaccount,0,sizeof(tCardaccount));
    ret=DB_t_account_read_lock_by_c1_and_cardno_and_purseno(tOldCard.cardno,PURSE_NO_ONE,&tCardaccount);
    if(ret)
    {
        if(DB_NOTFOUND==ret)
            return E_DB_ACCOUNT_N;
        else
            return E_DB_ACCOUNT_R;

    }
    tCardaccount.cardno=tCard.cardno;
    //考虑补助
    tCardaccount.availbal= tCardaccount.availbal+ tCardaccount.subsidybal;
    tCardaccount.subsidybal=0;
    tCardaccount.lastcardcnt=1;
    tCardaccount.lastcardbal=tCardaccount.availbal;
    getsysdate(tCardaccount.lasttransdate);
    ret=DB_t_account_update_lock_by_c1(&tCardaccount);
    if(ret)
    {
        return E_DB_ACCOUNT_U;
    }
    ///////////////////////////////
    pAccTrans->trans.usecardflag=1;
    pAccTrans->trans.custid=tCustomer.custid;
    pAccTrans->trans.feetype=tCard.feetype;
    //////////////////////////////
    pAccTrans->trans.fundtype=rPack->lvol9;
    pAccTrans->trans.inputamt=rPack->damt0;

    des2src(pAccTrans->cti.cardaccno,tCardaccount.accno);
    pAccTrans->cti.cardno=tCardaccount.cardno;
    pAccTrans->cti.purseno=tCardaccount.purseno;
    pAccTrans->cti.cardtype=tCard.cardtype;
    pAccTrans->cti.cardbefbal=0;
    pAccTrans->cti.cardaftbal=0;
    pAccTrans->cti.cardcnt=1;
    pAccTrans->cti.calaftbalflag=0;

    ret=pAccTrans->doAccTrans();
    if(ret)
        return ret;
    T_t_cardtransdtl cardtransdtl;
    memset(&cardtransdtl,0,sizeof(cardtransdtl));

    strcpy(cardtransdtl.transdate,trans.transdate);
    strcpy(cardtransdtl.transtime,trans.transtime);
    strcpy(cardtransdtl.accdate,trans.accdate);
    strcpy(cardtransdtl.acctime,trans.acctime);
    cardtransdtl.termid=trans.termid;
    cardtransdtl.termseqno=trans.termseqno;
    cardtransdtl.transcode=trans.transcode;
    des2src(cardtransdtl.opercode,trans.opercode);
    cardtransdtl.status[0]=DTLSTATUS_SUCCESS;
    cardtransdtl.errcode=0;
    ret=DB_t_cardtransdtl_add(&cardtransdtl);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDTRANSDTL_E;
        else
            return E_DB_CARDTRANSDTL_I;
    }
    SetCol(handle,F_LVOL1,F_LSAFE_LEVEL2,F_LVOL5,
           F_SALL_NAME,F_SPAGER,F_SCERT_NO,
           F_SEMAIL2,F_SMARKET_CODE,F_SDATE0,
           F_LVOL0,F_STX_PWD,F_LVOL8,
           F_SORDER0,F_SDATE3,F_SEMP,
           F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);
    outPack->lvol1=tCustomer.custid;
    outPack->lsafe_level2=tCustomer.custtype;
    outPack->lvol5=tCard.feetype;
    des2src(outPack->sall_name,tCustomer.custname);
    des2src(outPack->spager,tCustomer.stuempno);
    des2src(outPack->scert_no,tCustomer.deptcode);
    des2src(outPack->semail2,tCustomer.idno);
    des2src(outPack->smarket_code,tCustomer.sex);
    des2src(outPack->sdate0,tCard.expiredate);
    outPack->lvol0=tCard.cardno;
    des2src(outPack->stx_pwd,cardpwd);
    outPack->lvol8=0;
    des2src(outPack->sorder0,tCard.showcardno);
    des2src(outPack->sdate3,trans.accdate);
    des2src(outPack->semp,trans.opercode);
    outPack->lwithdraw_flag=trans.termid;
    outPack->lserial1=trans.termseqno;
    strcpy(outPack->vsmess,pAccTrans->remark.c_str());
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
예제 #14
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;
}
예제 #15
0
int F847119(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	char h_password[7] = "";							//卡密码
	char seed_key[17] = "";							//种子密钥
	T_t_card tCard;
	T_t_tif_tradeserial tradeserial;
	T_t_tif_writefailed tWriteFailed;
	T_t_customer tCustomer;

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

	memset(&tCard,0,sizeof(tCard));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&tWriteFailed, 0, sizeof tWriteFailed);
	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);
	/************************************************************************/
	ret = do_process(&tCard, &tWriteFailed, rPack, &tradeserial);
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	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;
	}
	EncodePwd(seed_key,h_password,tCard.password,1);			//卡密码
	DB_t_customer_free_lock_cur();
	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.cardno;								//交易卡号
	out_pack->lvol1 = tCustomer.custtype;						//客户类别
	out_pack->lvol5 = tCustomer.feetype;						//收费类别
	des2src(out_pack->scust_no,tCard.showid);					//显示卡号
	des2src(out_pack->scust_no2,tCustomer.deptcode);			//部门号
	des2src(out_pack->scust_auth,tCustomer.stuempno);			//学号
	des2src(out_pack->scust_auth2,tCustomer.man_id);			//身份证号
	des2src(out_pack->sname,tCustomer.custname);				//客户姓名
	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.endtime);					//有效截至日期

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

	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}
예제 #16
0
파일: F847119.c 프로젝트: nykma/ykt4sungard
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;
}
예제 #17
0
int F846305(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
    int ret=0;
    int freefeeflag=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    des2src(pAccTrans->trans.opercode,rPack->semp);
    pAccTrans->trans.transcode=TC_CARDRENEW;
    ret=pAccTrans->InitTrans();
    if(ret)
        return ret;
    TRANS& trans=pAccTrans->trans;

    trans.usecardflag=1;
    trans.cardno=rPack->lvol0;
    des2src(trans.showcardno,rPack->sorder0);
    des2src(trans.cardphyid,rPack->sstation0);
    if (!strlen(trans.cardphyid))
        return E_INPUT_CARDPHYID;
//	if (!strlen(trans.showcardno))
//	    return E_INPUT_SHOWCARDNO;
    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);


    SetCol(handle,0);

    //检查卡
    T_t_card tCard;

    memset(&tCard,0,sizeof(tCard));
    ret=DB_t_card_read_lock_by_cur_and_cardno(trans.cardno,&tCard);
    if(ret)
    {
        writelog(LOG_ERR,"cardno[%d]",trans.cardno);
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDNO,trans.cardno);
        else
            return E_DB_CARD_R;
    }
    trans.cardtype=tCard.cardtype;
    trans.feetype=tCard.feetype;
    trans.custid=tCard.custid;
    if(tCard.status[0]!=STATUS_NORMAL)
    {
        DB_t_card_free_lock_by_cur();
        return ERRINFO(E_CARD_LOGOUT,trans.cardno);
    }
    if('1'==tCard.frozeflag[0])
    {
        DB_t_card_free_lock_by_cur();
        return ERRINFO(E_CARD_FREEZE,trans.cardno);
    }
    if('1'==tCard.badflag[0])
    {
        if((CARDBADFLAG_CARDBAL==tCard.badtype[0])||(CARDBADFLAG_ACCBAL==tCard.badtype[0]))
        {
            DB_t_card_free_lock_by_cur();
            ERRTIP("该卡余额错误,请使用坏卡修复功能来处理,不必补办");
            return E_CARD_BAD_AND_NEED_UPDATE;
        }
    }
    //无卡只有挂失或卡物理损坏的情况下才可以补办卡
    if(tCard.lossflag[0]!='1'&&
            tCard.badflag[0]!='1')
    {
        DB_t_card_free_lock_by_cur();
        ERRTIP("该卡状态正常,不能补办");
        return E_COMMON_ERR;
    }
    //检查该客户是否存在未注销的卡
//	ret=IsExistOtherCardByCustid(tCard.custid,tCard.cardno);
    ret=IsExistNormalTmpCardByCustid(tCard.custid);
    if(ret)
    {
        DB_t_card_free_lock_by_cur();
        if(DB_EXIST==ret)
        {
            ERRTIP("该客户存在正常的过渡临时卡,请先注销过渡临时卡再补办");
            return E_EXIST_OTHERCARD;
        }
        else
            return ret;
    }
    if('1'==tCard.badflag[0])
    {
        //检查卡是否到了销卡的时间
        char enddate[9]="";
        ret=calcEndDate(tCard.baddate,pAccTrans->sysPara.iPosdtlMaxDayCnt,enddate);
        if(ret)
        {
            DB_t_card_free_lock_by_cur();
            return ret;
        }
        if(strncmp(enddate,pAccTrans->trans.transdate,8)>0)
        {
            DB_t_card_free_lock_by_cur();
            ERRTIP("请等到期后再补办");
            return ERRINFO(E_BADCARD_RECORDDATE_NOTREACH,enddate);
        }
        if(CARDBADFLAG_QUALITY==tCard.badtype[0])
            freefeeflag=1;
    }
    else if('1'==tCard.lossflag[0])
    {
        char enddate[9]="";
        ret=calcEndDate(tCard.lossdate,pAccTrans->sysPara.iPosdtlMaxDayCnt,enddate);
        if(ret)
        {
            DB_t_card_free_lock_by_cur();
            return ret;
        }
        if(strncmp(enddate,pAccTrans->trans.transdate,8)>0)
        {
            DB_t_card_free_lock_by_cur();
            ERRTIP("请等到期后再补办");
            return ERRINFO(E_CARDLOSSDATE_NOREACH,enddate);
        }
    }
    ret=getCardVerNo(tCard.cardverno);
    if(ret)
    {
        DB_t_card_free_lock_by_cur();
        return ret;
    }
    tCard.status[0]=STATUS_DELETE;
    strcpy(tCard.closedate,trans.transdate);
    getfmtsysdatetime(tCard.lastsaved);
    ret=DB_t_card_update_lock_by_cur(&tCard);
    if(ret)
    {
        writelog(LOG_ERR,"cardno[%d]",tCard.cardno);
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDNO,tCard.cardno);
        else
            return E_DB_CARD_U;
    }
    //删除卡库不平表该卡的记录
    ret=DelCardAccDiffByCardno(trans.cardno);
    if(ret)
        return ret;
    T_t_customer tCustomer;

    memset(&tCustomer,0,sizeof(tCustomer));
    if(trans.custid>0)
    {
        ret=DB_t_customer_read_by_custid(trans.custid,&tCustomer);
        if(ret)
        {
            if(DB_NOTFOUND==ret)
                return ERRINFO(E_NOTEXIST_CUSTOMER,trans.custid);
            else
                return E_DB_CUSTOMER_R;
        }
        trans.custid=tCustomer.custid;
        des2src(trans.custname,tCustomer.custname);
        des2src(trans.stuempno,tCustomer.stuempno);
    }

    T_t_cardtyperight cardtyperight;

    memset(&cardtyperight,0,sizeof(cardtyperight));
    ret=DB_t_cardtyperight_read_by_cardtype_and_feetype(tCard.cardtype,tCard.feetype,&cardtyperight);
    if(ret)
    {
        writelog(LOG_ERR,"cardtype[%d]feetype[%d]",tCard.cardtype,tCard.feetype);
        if(DB_NOTFOUND==ret)
            return E_NOCARDTYPERIGHT;
        else
            return E_DB_CARDTYPERIGHT_R;
    }
    ////添加旧卡版本号记录
    T_t_cardver cardver;

    memset(&cardver,0,sizeof(cardver));
    cardver.cardno=tCard.cardno;
    des2src(cardver.accdate,pAccTrans->trans.sysdate);
    cardver.termid=trans.termid;
    cardver.termseqno=trans.termseqno;
    cardver.cardno=tCard.cardno;
    cardver.status[0]=STATUS_NORMAL;
    des2src(cardver.cardphyid,tCard.cardphyid);
    des2src(cardver.stuempno,trans.stuempno);
    cardver.cardvertype=CARDVERTYPE_CARDCLOSE;
    des2src(cardver.cardverno,tCard.cardverno);
    ret=DB_t_cardver_add(&cardver);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDVER_E;
        else
            return E_DB_CARDVER_I;
    }
    T_t_card  tCardTest;
    ret=DB_t_card_read_by_cardphyid_and_status(trans.cardphyid,"1",&tCardTest);
    if (ret!=DB_NOTFOUND)
    {
        if (DB_SUCCESS==ret)
            return ERRINFO(E_EXIST_CARDPHYID,trans.cardphyid);
        else
            return E_DB_CARD_R;
    }
    if(pAccTrans->sysPara.bEnableCardMgr)
    {
        //使用新的显示卡号
        ret=DB_t_card_read_by_showcardno_and_status(trans.showcardno,"1",&tCardTest);
        if (ret!=DB_NOTFOUND)
        {
            if (DB_SUCCESS==ret)
                return ERRINFO(E_EXIST_SHOWCARDNO,trans.showcardno);
            else
                return E_DB_CARD_R;
        }
        int cardtype=0;
        ret=UseShowCardNo(trans.opercode,trans.showcardno,cardtype);
        if(ret)
        {
            return ret;
        }
        if(cardtype!=tCard.cardtype)
        {
            return ERRINFO(E_DIFF_CARDTYPE,cardtype,tCard.cardtype);
        }
        T_t_carddtl carddtl;
        memset(&carddtl,0,sizeof(carddtl));

        des2src(carddtl.accdate,pAccTrans->trans.sysdate);
        des2src(carddtl.acctime,trans.systime);
        carddtl.termid=trans.termid;
        carddtl.termseqno=trans.termseqno;
        des2src(carddtl.opercode,trans.opercode);
        carddtl.cardtype=tCard.cardtype;
        carddtl.usetype=CARDUSETYPE_USE;
        carddtl.inoutflag=INOUTFLAG_OUT;
        carddtl.transcnt=1;
        strcpy(carddtl.summary,"补办卡");
        des2src(carddtl.cardphyid,trans.cardphyid);
        des2src(carddtl.showcardno,trans.showcardno);
        ret=DB_t_carddtl_add(&carddtl);
        if(ret)
        {
            if(DB_REPEAT==ret)
                return E_DB_CARDDTL_E;
            else
                return E_DB_CARDDTL_I;
        }
    }
    //使用卡片
    T_t_card  tNewCard;
    memset(&tNewCard,0,sizeof(tNewCard));

    des2src(tNewCard.cardphyid,trans.cardphyid);
    des2src(tNewCard.showcardno,trans.showcardno);
    des2src(tNewCard.expiredate,tCard.expiredate);
    des2src(tNewCard.accno,tCard.accno);
    tNewCard.cardtype=tCard.cardtype;
    tNewCard.feetype=tCard.feetype;
    des2src(tNewCard.cardpwd,tCard.cardpwd);
    tNewCard.custid=tCustomer.custid;
    tNewCard.lossflag[0]='0';
    tNewCard.frozeflag[0]='0';
    tNewCard.badflag[0]='0';
    tNewCard.status[0]=STATUS_NORMAL;
    des2src(tNewCard.opendate,pAccTrans->trans.transdate);
    getfmtsysdatetime(tNewCard.lastsaved);
    ret = getNewUniqNo(KEYTYPE_CARDNO,&tNewCard.cardno);	//获取最大卡号
    if(ret)
    {
        return ret;
    }
    ret=getCardVerNo(tNewCard.cardverno);
    if(ret)
    {
        return ret;
    }
    ret=DB_t_card_add(&tNewCard);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARD_E;
        else
            return E_DB_CARD_I;
    }
    ////添加新卡版本号记录
//	T_t_cardver cardver;

    memset(&cardver,0,sizeof(cardver));
    des2src(cardver.accdate,pAccTrans->trans.sysdate);
    cardver.termid=trans.termid;
    cardver.termseqno=trans.termseqno;
    cardver.cardno=tNewCard.cardno;
    cardver.status[0]=STATUS_NORMAL;
    des2src(cardver.cardphyid,tNewCard.cardphyid);
    des2src(cardver.stuempno,trans.stuempno);
    cardver.cardvertype=CARDVERTYPE_CARDOPEN;
    des2src(cardver.cardverno,tNewCard.cardverno);
    ret=DB_t_cardver_add(&cardver);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDVER_E;
        else
            return E_DB_CARDVER_I;
    }
    //添加换卡记录
    T_t_cardnochange tCardnoChange;

    memset(&tCardnoChange,0,sizeof(tCardnoChange));
    des2src(tCardnoChange.changedate,pAccTrans->trans.sysdate);
    tCardnoChange.oldcardno=tCard.cardno;
    tCardnoChange.newcardno=tNewCard.cardno;
    ret=DB_t_cardnochange_add(&tCardnoChange);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDNOCHANGE_E;
        else
            return E_DB_CARDNOCHANGE_I;
    }
    //插入卡位图表
    T_t_cardbitmap tCardBitmap;

    memset(&tCardBitmap,0,sizeof(tCardBitmap));
    tCardBitmap.cardno=tNewCard.cardno;
    tCardBitmap.baseno=0;
    memset(tCardBitmap.bitmap0,'0',sizeof(tCardBitmap.bitmap0));
    memset(tCardBitmap.bitmap1,'0',sizeof(tCardBitmap.bitmap1));
    memset(tCardBitmap.bitmap2,'0',sizeof(tCardBitmap.bitmap2));
    memset(tCardBitmap.bitmap3,'0',sizeof(tCardBitmap.bitmap3));
    memset(tCardBitmap.bitmap4,'0',sizeof(tCardBitmap.bitmap4));
    memset(tCardBitmap.bitmap5,'0',sizeof(tCardBitmap.bitmap5));
    memset(tCardBitmap.bitmap6,'0',sizeof(tCardBitmap.bitmap6));
    memset(tCardBitmap.bitmap7,'0',sizeof(tCardBitmap.bitmap7));
    memset(tCardBitmap.bitmap8,'0',sizeof(tCardBitmap.bitmap8));
    memset(tCardBitmap.bitmap9,'0',sizeof(tCardBitmap.bitmap9));
    tCardBitmap.bitmap0[0]=CARDBITMAPTYPE_INC;
    ret=DB_t_cardbitmap_add(&tCardBitmap);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_CARDBITMAP_E;
        else
            return E_DB_CARDBITMAP_I;
    }
    //领取补助
    T_t_account tCardAccount;
    memset(&tCardAccount,0,sizeof(tCardAccount));
    ret=DB_t_account_read_by_cardno_and_purseno(trans.cardno,trans.purseno,&tCardAccount);
    if(ret)
    {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_CARDNO_PURSENO_NOACCNO,trans.cardno,trans.purseno);
        else
            return E_DB_ACCOUNT_R;
    }
    if(tCardAccount.status[0]!=STATUS_NORMAL)
    {
        return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
    }
    double subsidyamt=0;
    int maxsubsidyno=0;
    //检查补助信息
    ret = GetSubsidy(tCard.cardno,tCardAccount.subsidyno,0,subsidyamt,maxsubsidyno);
    if(ret)
    {
        writelog(LOG_ERR,"DoGetSubsidy ret=[%d]",ret);
        return ret;
    }
    strcpy(trans.cardaccno,tCardAccount.accno);
    //押金处理
//	double returncashamt=0;
    if(freefeeflag)
    {
        pAccTrans->SetFreeFlag();
    }
    else
    {
        //扣押金
        if(amtcmp(tCardAccount.foregift,0)>0)
        {
            trans.transamt=tCardAccount.foregift;
            trans.inputamt=tCardAccount.foregift;
            trans.fundtype=0;
            pAccTrans->trans.transtype=TRANSTYPE_FOREGIFT2COSTFEE;
            ret=pAccTrans->DoTransByTransType();
            if(ret)
                return ret;
            if(amtcmp(pAccTrans->trans.unusedamt,0)>0)
                return E_INPUT_AMT;
            if(amtcmp(pAccTrans->trans.unusedamt,0)<0)
                return E_AMT_LACK;
        }
    }
    if(amtcmp(tCardAccount.availbal,tCardAccount.lastcardbal)<=0)
        trans.cardbefbal=D4U5(tCardAccount.availbal+tCardAccount.subsidybal);
    else
        trans.cardbefbal=D4U5(tCardAccount.lastcardbal+tCardAccount.subsidybal);

    if(amtcmp(tCardAccount.subsidybal,0)!=0)
    {
        //领取补助
        memset(&tCardAccount,0,sizeof(tCardAccount));
        ret=DB_t_account_read_lock_by_c0_and_accno(trans.cardaccno,&tCardAccount);
        if(ret)
        {
            if(DB_NOTFOUND==ret)
                return ERRINFO(E_NOTEXIST_ACCNO,trans.cardaccno);
            else
                return E_DB_ACCOUNT_R;
        }
        tCardAccount.availbal=D4U5(tCardAccount.availbal+tCardAccount.subsidybal);
        tCardAccount.subsidybal=0;
        ret=DB_t_account_update_lock_by_c0(&tCardAccount);
        if(ret)
        {
            if(DB_NOTFOUND==ret)
                return E_DB_ACCOUNT_U;
            else
                return E_DB_ACCOUNT_R;
        }
    }

    if(amtcmp(tCardAccount.balance-tCardAccount.frozebal,trans.cardbefbal)>0)
    {
        //走长款处理
        trans.transamt=D4U5(tCardAccount.balance-tCardAccount.frozebal-trans.cardbefbal);
        trans.inputamt=trans.transamt;
        trans.fundtype=0;
        pAccTrans->trans.transtype=TRANSTYPE_MORE_CARDBALINCOME;
        ret=pAccTrans->DoTransByTransType();
        if(ret)
            return ret;
        if(amtcmp(pAccTrans->trans.unusedamt,0)>0)
            return E_INPUT_AMT;
        if(amtcmp(pAccTrans->trans.unusedamt,0)<0)
            return E_AMT_LACK;
    }
    trans.cardflag=1;
    trans.usecardflag=1;
    trans.feetype=tCard.feetype;
    trans.fundtype=rPack->lvol9;
    trans.cardcnt=1;
    trans.inputamt=rPack->damt0;
    if(trans.fundtype>4)
    {
        //如果从账户中扣卡成本费,则没有充值业务
        trans.fundtype=0;
        ret=pAccTrans->doFeeTrans();
        if(ret)
            return ret;
    }
    else
    {
        des2src(trans.voucherno,rPack->scust_auth2);
        ret=pAccTrans->doTrans();
        if(ret)
            return ret;
    }
    ret=pAccTrans->doTransEnd();
    if(ret)
        return ret;
    memset(&tCardAccount,0,sizeof(tCardAccount));
    ret=DB_t_account_read_lock_by_c0_and_accno(trans.cardaccno,&tCardAccount);
    if(ret)
    {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDACCNO,trans.cardaccno);
        else
            return E_DB_ACCOUNT_R;
    }
    if(tCardAccount.status[0]!=STATUS_NORMAL)
    {
        DB_t_account_free_lock_by_c0();
        return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
    }
    //取可用余额作为出卡值
    trans.cardaftbal=tCardAccount.availbal;
    if(amtcmp(trans.cardaftbal,0)<0)
    {
        DB_t_account_free_lock_by_c0();
        return ERRINFO(E_CARD_BALANCE_SHORTAGE,trans.cardaftbal);
    }
    if(amtcmp(trans.cardaftbal,tCardAccount.cardmaxbal)>=0)
    {
        DB_t_account_free_lock_by_c0();
        return ERRINFO(E_AMT_EXCEED_MAX,tCardAccount.cardmaxbal);
    }
    tCardAccount.cardno=tNewCard.cardno;
    tCardAccount.lastcardcnt=1;
    tCardAccount.lastsubsidyno=maxsubsidyno;
    tCardAccount.lastcardbal=trans.cardaftbal;
    des2src(tCardAccount.lasttransdate,trans.transdate);
    ret=DB_t_account_update_lock_by_c0(&tCardAccount);
    if(ret)
    {
        if(DB_NOTFOUND==ret)
            return E_DB_ACCOUNT_U;
        else
            return E_DB_ACCOUNT_R;
    }
    T_t_transdtl transdtl;
    memset(&transdtl,0,sizeof(transdtl));

    strcpy(transdtl.transdate,trans.transdate);
    strcpy(transdtl.transtime,trans.transtime);
    strcpy(transdtl.accdate,trans.sysdate);
    strcpy(transdtl.acctime,trans.systime);
    transdtl.amount=trans.totaltransamt;
    transdtl.managefee=trans.totalfeeamt;
    transdtl.cardno=tNewCard.cardno;
    transdtl.cardcnt=trans.cardcnt;
    transdtl.cardbefbal=trans.cardbefbal;
    transdtl.cardaftbal=trans.cardaftbal;
    transdtl.termid=trans.termid;
    transdtl.termseqno=trans.termseqno;
    transdtl.transcode=trans.transcode;
    transdtl.paytype=trans.fundtype;
    des2src(transdtl.voucherno,trans.voucherno);
    des2src(transdtl.opercode,trans.opercode);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    transdtl.errcode=0;
    transdtl.custid=tCustomer.custid;
    des2src(transdtl.custname,tCustomer.custname);
    transdtl.showcardno=atol(tNewCard.showcardno);
    ret=DB_t_transdtl_add(&transdtl);
    if(ret)
    {
        if(DB_REPEAT==ret)
            return E_DB_TRANSDTL_E;
        else
            return E_DB_TRANSDTL_I;
    }
    char cardpwd[33]="";
    char key[17]="";

    //get_init_passwd_by_man_id(tCustomer.idno,cardpwd);
    strcpy(key,STATIC_SEED_KEY);
    EncodePwd(key,cardpwd,tNewCard.cardpwd, 1);

    SetCol(handle,F_LVOL1,F_LSAFE_LEVEL2,F_LVOL4,F_LVOL5,
           F_SALL_NAME,F_SPAGER,F_SCERT_NO,
           F_SEMAIL2,F_SMARKET_CODE,F_SDATE0,
           F_LVOL0,F_STX_PWD,F_LVOL8,F_LVOL11,F_LVOL12,
           F_SORDER0,F_SDATE3,F_SEMP,
           F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);
    outPack->lvol1=tNewCard.custid;
    outPack->lsafe_level2=tCustomer.custtype;
    outPack->lvol5=tNewCard.feetype;
    des2src(outPack->sall_name,tCustomer.custname);
    des2src(outPack->spager,tCustomer.stuempno);
    des2src(outPack->scert_no,tCustomer.deptcode);
    des2src(outPack->semail2,tCustomer.idno);
    des2src(outPack->smarket_code,tCustomer.sex);
    des2src(outPack->sdate0,tNewCard.expiredate);
    outPack->lvol0=tNewCard.cardno;
    des2src(outPack->stx_pwd,cardpwd);
    outPack->lvol4=maxsubsidyno;
    outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
    outPack->lvol11=D4U5(tCardAccount.singlemaxamt*100,0);
    outPack->lvol12=D4U5(tCardAccount.daycostmaxamt*100,0);
    des2src(outPack->sorder0,tNewCard.showcardno);
    des2src(outPack->sdate3,pAccTrans->trans.sysdate);
    des2src(outPack->semp,trans.opercode);
    outPack->lwithdraw_flag=trans.termid;
    outPack->lserial1=trans.termseqno;
    sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
    des2src(outPack->vsmess,trans.remark);
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
예제 #18
0
static int DoCardInstead(TRUSERID *handle,ST_PACK *rPack,int *pRetCode,char *szMsg) {
    int ret=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;
    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);


    SetCol(handle,0);

    SetCol(handle,F_LVOL1,F_LSAFE_LEVEL2,F_LVOL4,F_LVOL5,
           F_SALL_NAME,F_SPAGER,F_SCERT_NO,F_LSAFE_LEVEL,F_SMARKET_CODE2,F_SHOLDER_AC_NO,
           F_SEMAIL2,F_SMARKET_CODE,F_SDATE0,
           F_LVOL0,F_STX_PWD,F_LVOL8,F_LVOL6,
           F_SORDER0,F_SEMP,F_SDATE3,F_STIME3,F_LVOL11,F_LVOL12,
           F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,F_SNAME2,0);

    T_t_card  tCard;
    memset(&tCard,0,sizeof(tCard));
    ret=DB_t_card_read_lock_by_cur_and_cardno(trans.cardno,&tCard);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDNO,trans.cardno);
        else
            return E_DB_CARD_R;
    }
    if(tCard.status[0]!=STATUS_NORMAL) {
        DB_t_card_free_lock_by_cur();
        return ERRINFO(E_CARD_LOGOUT,trans.cardno);
    }
    if('1'==tCard.frozeflag[0]) {
        DB_t_card_free_lock_by_cur();
        return ERRINFO(E_CARD_FREEZE,trans.cardno);
    }
    if('1'==tCard.lossflag[0]) {
        DB_t_card_free_lock_by_cur();
        return ERRINFO(E_CARD_LOST,trans.cardno);
    }
    if('1'==tCard.badflag[0]) {
        DB_t_card_free_lock_by_cur();
        return ERRINFO(E_CARD_BADRECORD,trans.cardno);
    }
    tCard.status[0]=STATUS_DELETE;
    des2src(tCard.closedate,trans.transdate);
    ret=DB_t_card_update_lock_by_cur(&tCard);
    if(ret) {
        return E_DB_CARD_U;
    }
    memset(tCard.closedate,0,sizeof(tCard.closedate));
    tCard.status[0]=STATUS_NORMAL;
    T_t_account tCardAccount;
    memset(&tCardAccount,0,sizeof(tCardAccount));
    ret=DB_t_account_read_by_accno(tCard.accno,&tCardAccount);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDACCNO,tCard.accno);
        else
            return E_DB_ACCOUNT_R;
    }
    int existflag=0;
    ret=IsExistUnGetSubsidy(tCard.cardno,&existflag);
    if(ret) {
        return ret;
    }
    if(existflag) {
        ERRTIP("有未领补助,请领取补助后再换卡");
        return E_COMMON_ERR;
    }
    T_t_customer  customer;
    memset(&customer,0,sizeof(customer));
    if(tCard.custid) {
        ret=DB_t_customer_read_by_custid(tCard.custid,&customer);
        if(ret) {
            if(DB_NOTFOUND==ret)
                return ERRINFO(E_NOTEXIST_CUSTOMER,tCard.custid);
            else
                return E_DB_CUSTOMER_R;
        }
        des2src(trans.stuempno,customer.stuempno);
        des2src(trans.custname,customer.custname);
        trans.custid=customer.custid;
    }
    char cardpwd[33]="";
    char key[17]="";
    strcpy(key,STATIC_SEED_KEY);
    EncodePwd(key,cardpwd,tCard.cardpwd, 1);
    T_t_cardinsteaddtl cardinsteaddtl;
    memset(&cardinsteaddtl,0,sizeof(cardinsteaddtl));
    ret=DB_t_cardinsteaddtl_read_lock_by_c0_and_cardno(trans.cardno,&cardinsteaddtl);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return E_DB_CARDINSTEADDTL_N;
        else
            return E_DB_CARDINSTEADDTL_R;
    }
    //核对登记信息与卡表是否一致
    if(strcmp(cardinsteaddtl.oldcardphyid,tCard.cardphyid)!=0) {
        DB_t_cardinsteaddtl_free_lock_by_c0();
        strcpy(szMsg,"保存的卡信息与原卡物理ID不一致");
        return E_CARD_PHYNO_DIFFER;
    }
    //核对原物理ID是否一致
    if(strcmp(cardinsteaddtl.oldcardphyid,rPack->scust_no)!=0) {
        DB_t_cardinsteaddtl_free_lock_by_c0();
        return E_CARD_PHYNO_DIFFER;
    }
    if(cardinsteaddtl.revflag[0]=='1') {
        DB_t_cardinsteaddtl_free_lock_by_c0();
        return E_CARDINSTEAD_CANCEL;
    }
    if(cardinsteaddtl.status[0]=='2') {
        DB_t_cardinsteaddtl_free_lock_by_c0();
        if(strcmp(cardinsteaddtl.cardphyid,trans.cardphyid)!=0) {
            return ERRINFO(E_CARD_PHYNO_DIFFER,trans.cardphyid,cardinsteaddtl.cardphyid);
        }
        outPack->lvol1=tCard.custid;
        outPack->lsafe_level2=customer.custtype;
        outPack->lvol5=tCard.feetype;
        des2src(outPack->sall_name,customer.custname);
        des2src(outPack->spager,customer.stuempno);
        des2src(outPack->scert_no,customer.deptcode);
        des2src(outPack->semail2,customer.idno);
        des2src(outPack->smarket_code,customer.sex);
        des2src(outPack->sdate0,tCard.expiredate);
        sprintf(outPack->sholder_ac_no,"%d",10);				//发行方标识
        des2src(outPack->smarket_code2,customer.idtype);
        outPack->lsafe_level=tCard.cardtype;
        des2src(outPack->sname2,tCard.cardverno);
        outPack->lvol0=tCard.cardno;
        outPack->lvol8=(int)(cardinsteaddtl.oldcardbal*100);
        outPack->lvol11=D4U5(tCardAccount.singlemaxamt*100,0);
        outPack->lvol12=D4U5(tCardAccount.daycostmaxamt*100,0);
        outPack->lvol6=cardinsteaddtl.oldcardcnt;
        outPack->lvol4=cardinsteaddtl.oldsubsidyno;
        des2src(outPack->sorder0,tCard.showcardno);
        des2src(outPack->sdate3,pAccTrans->trans.accdate);
        des2src(outPack->semp,trans.opercode);
        des2src(outPack->stx_pwd,cardpwd);
        outPack->lwithdraw_flag=trans.termid;
        outPack->lserial1=trans.termseqno;
        PutRow(handle,outPack,pRetCode,szMsg);
        return 0;
    }
    cardinsteaddtl.status[0]=STATUS_DELETE;
    des2src(cardinsteaddtl.cardphyid,trans.cardphyid);
    des2src(cardinsteaddtl.showcardno,trans.showcardno);
    ret=DB_t_cardinsteaddtl_update_lock_by_c0(&cardinsteaddtl);
    if(ret) {
        return E_DB_CARDINSTEADDTL_U;
    }
    //检查新卡物理id
    T_t_card cardtmp;
    memset(&cardtmp,0,sizeof(cardtmp));
    ret=DB_t_card_read_by_cardphyid_and_status(trans.cardphyid,"1",&cardtmp);
    if(ret!=DB_NOTFOUND) {
        if(DB_SUCCESS==ret)
            return ERRINFO(E_EXIST_CARDPHYID,trans.cardphyid);
        else
            return E_DB_CARD_R;
    }
    if(pAccTrans->sysPara.bEnableCardMgr) {
        ret=DB_t_card_read_by_showcardno_and_status(trans.showcardno,"1",&cardtmp);
        if(ret!=DB_NOTFOUND) {
            if(DB_SUCCESS==ret)
                return ERRINFO(E_EXIST_SHOWCARDNO,trans.showcardno);
            else
                return E_DB_CARD_R;
        }
        //回收旧卡
        ret=UseShowCardNoBack(trans.opercode,tCard.showcardno);
        if(ret)
            return ret;
        T_t_carddtl carddtl;
        memset(&carddtl,0,sizeof(carddtl));

        des2src(carddtl.accdate,pAccTrans->trans.accdate);
        des2src(carddtl.acctime,trans.acctime);
        carddtl.termid=trans.termid;
        carddtl.termseqno=trans.termseqno;
        des2src(carddtl.opercode,trans.opercode);
        carddtl.cardtype=tCard.cardtype;
        carddtl.usetype=CARDUSETYPE_REUSE;
        carddtl.inoutflag=INOUTFLAG_IN;
        carddtl.transcnt=1;
        strcpy(carddtl.summary,"换卡(回收旧卡)");
        des2src(carddtl.cardphyid,cardinsteaddtl.oldcardphyid);
        des2src(carddtl.showcardno,cardinsteaddtl.oldshowcardno);
        ret=DB_t_carddtl_add(&carddtl);
        if(ret) {
            if(DB_REPEAT==ret)
                return E_DB_CARDDTL_E;
            else
                return E_DB_CARDDTL_I;
        }
    }
    ////添加卡版本号记录
//		T_t_cardver cardver;
//
//		memset(&cardver,0,sizeof(cardver));
//		cardver.cardno=trans.cardno;
//		des2src(cardver.accdate,pAccTrans->sysPara.sSettleDate);
//		cardver.termid=trans.termid;
//		cardver.termseqno=trans.termseqno;
//		cardver.status[0]=STATUS_NORMAL;
//		des2src(cardver.cardphyid,cardinsteaddtl.oldcardphyid);
//		des2src(cardver.stuempno,trans.stuempno);
//		cardver.cardvertype=CARDVERTYPE_CARDINSTEADOLD;
//
//		ret=getCardVerNo(cardver.cardverno);
//		if(ret)
//			return ret;
//		ret=DB_t_cardver_add(&cardver);
//		if(ret)
//		{
//			if(DB_REPEAT==ret)
//				return E_DB_CARDVER_E;
//			else
//				return E_DB_CARDVER_I;
//		}
    if(pAccTrans->sysPara.bEnableCardMgr) {
        int cardtype=0;
        //使用新卡
        ret=UseShowCardNo(trans.opercode,trans.showcardno,cardtype);
        if(ret) {
            return ret;
        }
        if(cardtype!=tCard.cardtype) {
            if(CARDTYPE_TEMP==tCard.cardtype||CARDTYPE_TEMP==cardtype) {
                ERRTIP("过渡临时卡与其他卡不能互换");
                return E_COMMON_ERR;
            }
        }
        tCard.cardtype=cardtype;
        T_t_cardtyperight cardtyperight;

        memset(&cardtyperight,0,sizeof(cardtyperight));
        ret=DB_t_cardtyperight_read_by_cardtype_and_feetype(tCard.cardtype,tCard.feetype,&cardtyperight);
        if (ret) {
            writelog(LOG_ERR,"cardtype[%d]feetype[%d]",tCard.cardtype,tCard.feetype);
            if (DB_NOTFOUND==ret)
                return ERRINFO(E_NOCARDTYPERIGHT,tCard.feetype,tCard.cardtype);
            else
                return E_DB_CARDTYPERIGHT_R;
        }
        T_t_carddtl carddtl;
        memset(&carddtl,0,sizeof(carddtl));

        des2src(carddtl.accdate,pAccTrans->trans.accdate);
        des2src(carddtl.acctime,trans.acctime);
        carddtl.termid=trans.termid;
        carddtl.termseqno=trans.termseqno;
        des2src(carddtl.opercode,trans.opercode);
        carddtl.cardtype=tCard.cardtype;
        carddtl.usetype=CARDUSETYPE_USE;
        carddtl.inoutflag=INOUTFLAG_OUT;
        carddtl.transcnt=1;
        strcpy(carddtl.summary,"换卡(发行新卡)");
        des2src(carddtl.cardphyid,cardinsteaddtl.cardphyid);
        des2src(carddtl.showcardno,cardinsteaddtl.showcardno);
        ret=DB_t_carddtl_add(&carddtl);
        if(ret) {
            if(DB_REPEAT==ret)
                return E_DB_CARDDTL_E;
            else
                return E_DB_CARDDTL_I;
        }
    }
    ret = getNewUniqNo(KEYTYPE_CARDNO,&tCard.cardno);	//获取最大卡号
    if(ret) {
        return ret;
    }
    T_t_cardver cardver;

    memset(&cardver,0,sizeof(cardver));
    cardver.cardno=tCard.cardno;
    des2src(cardver.accdate,pAccTrans->trans.accdate);
    cardver.termid=trans.termid;
    cardver.termseqno=trans.termseqno;
    cardver.status[0]=STATUS_NORMAL;
    des2src(cardver.cardphyid,cardinsteaddtl.oldcardphyid);
    des2src(cardver.stuempno,trans.stuempno);
    cardver.cardvertype=CARDVERTYPE_CARDINSTEADNEW;
    ret=getCardVerNo(cardver.cardverno);
    if(ret)
        return ret;
    ret=DB_t_cardver_add(&cardver);
    if(ret) {
        if(DB_REPEAT==ret)
            return E_DB_CARDVER_E;
        else
            return E_DB_CARDVER_I;
    }
    //使用卡片
    des2src(tCard.cardphyid,trans.cardphyid);
    des2src(tCard.showcardno,trans.showcardno);
    des2src(tCard.lastsaved,trans.sysdatetime);
    des2src(tCard.cardverno,cardver.cardverno);
    tCard.status[0]=STATUS_NORMAL;
    ret=DB_t_card_add(&tCard);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return E_NOTEXIST_CARDNO;
        else
            return E_DB_CARD_U;
    }
    tCardAccount.cardno=tCard.cardno;
    tCardAccount.dpscnt=0;
    tCardAccount.paycnt=0;
    strcpy(tCardAccount.transtime,trans.sysdatetime);
    ret=DB_t_account_update_by_accno(tCard.accno,&tCardAccount);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return E_DB_ACCOUNT_N;
        else
            return E_DB_ACCOUNT_R;
    }
    //插入卡位图表
    T_t_cardbitmap tCardBitmap;

    memset(&tCardBitmap,0,sizeof(tCardBitmap));
    tCardBitmap.cardno=tCard.cardno;
    tCardBitmap.baseno=0;
    memset(tCardBitmap.bitmap0,'0',sizeof(tCardBitmap.bitmap0)-1);
    memset(tCardBitmap.bitmap1,'0',sizeof(tCardBitmap.bitmap1)-1);
    memset(tCardBitmap.bitmap2,'0',sizeof(tCardBitmap.bitmap2)-1);
    memset(tCardBitmap.bitmap3,'0',sizeof(tCardBitmap.bitmap3)-1);
    memset(tCardBitmap.bitmap4,'0',sizeof(tCardBitmap.bitmap4)-1);
    memset(tCardBitmap.bitmap5,'0',sizeof(tCardBitmap.bitmap5)-1);
    memset(tCardBitmap.bitmap6,'0',sizeof(tCardBitmap.bitmap6)-1);
    memset(tCardBitmap.bitmap7,'0',sizeof(tCardBitmap.bitmap7)-1);
    memset(tCardBitmap.bitmap8,'0',sizeof(tCardBitmap.bitmap8)-1);
    memset(tCardBitmap.bitmap9,'0',sizeof(tCardBitmap.bitmap9)-1);
    ret=DB_t_cardbitmap_add(&tCardBitmap);
    if (ret) {
        if (DB_REPEAT==ret)
            return E_DB_CARDBITMAP_E;
        else
            return E_DB_CARDBITMAP_I;
    }
    T_t_transdtl transdtl;
    memset(&transdtl,0,sizeof(transdtl));

    des2src(transdtl.transdate,trans.transdate);
    des2src(transdtl.transtime,trans.transtime);
    strcpy(transdtl.accdate,trans.accdate);
    strcpy(transdtl.acctime,trans.acctime);
    transdtl.termid=trans.termid;
    transdtl.termseqno=trans.termseqno;
    transdtl.transcode=trans.transcode;
    transdtl.paytype=trans.fundtype;
    des2src(transdtl.voucherno,trans.voucherno);
    transdtl.cardno=trans.cardno;
    transdtl.exttype=EXTTYPE_NEWCARD;
    sprintf(transdtl.extdata,"%d",tCard.cardno);
    transdtl.purseno=trans.purseno;
    transdtl.cardcnt=cardinsteaddtl.oldcardcnt;
    transdtl.cardbefbal=cardinsteaddtl.oldcardbal;
    transdtl.cardaftbal=cardinsteaddtl.oldcardbal;

    transdtl.managefee=trans.totalfeeamt;
    transdtl.amount=trans.totaltransamt;
    transdtl.custid=tCard.custid;
    des2src(transdtl.custname,customer.custname);
    des2src(transdtl.stuempno,customer.stuempno);
    des2src(transdtl.opercode,trans.opercode);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    des2src(transdtl.showcardno,tCard.showcardno);
    ret=DB_t_transdtl_add(&transdtl);
    if(ret) {
        if(DB_REPEAT==ret)
            return E_DB_TRANSDTL_E;
        else
            return E_DB_TRANSDTL_I;
    }
    outPack->lvol1=tCard.custid;
    outPack->lsafe_level2=customer.custtype;
    outPack->lvol5=tCard.feetype;
    des2src(outPack->sall_name,customer.custname);
    des2src(outPack->spager,customer.stuempno);
    des2src(outPack->scert_no,customer.deptcode);
    des2src(outPack->semail2,customer.idno);
    des2src(outPack->smarket_code,customer.sex);
    des2src(outPack->sdate0,tCard.expiredate);
    sprintf(outPack->sholder_ac_no,"%d",10);				//发行方标识
    des2src(outPack->smarket_code2,customer.idtype);
    outPack->lsafe_level=tCard.cardtype;
    outPack->lvol0=tCard.cardno;
    outPack->lvol4=cardinsteaddtl.oldsubsidyno;
    outPack->lvol8=(int)(cardinsteaddtl.oldcardbal*100);
    outPack->lvol11=D4U5(tCardAccount.singlemaxamt*100,0);
    outPack->lvol12=D4U5(tCardAccount.daycostmaxamt*100,0);
    outPack->lvol6=cardinsteaddtl.oldcardcnt;
    des2src(outPack->sorder0,tCard.showcardno);
    des2src(outPack->stx_pwd,cardpwd);
    des2src(outPack->sdate3,pAccTrans->trans.accdate);
    des2src(outPack->stime3,pAccTrans->trans.acctime);
    des2src(outPack->semp,trans.opercode);
    outPack->lwithdraw_flag=trans.termid;
    outPack->lserial1=trans.termseqno;
    des2src(outPack->sname2,cardver.cardverno);
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
예제 #19
0
int F240010(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) {

    char key[32+1]="";
    char pwd[32+1]="";
    char account_pwd[6+1]="";
    int ret=0;
    T_t_card card;
    int custid=0;
    char stuempno[20+1]="";
    int cardno=0;
    T_t_card	tCard1;

    memset(&card,0,sizeof(card));
    custid=rPack->lvol8;
    des2src(stuempno,rPack->scust_auth);
    cardno=atoi(rPack->sserial0);
    //writelog(LOG_ERR," stuempno=[%s],custid=[%d],cardno=[%s]",rPack->scust_auth,rPack->lvol8,rPack->sserial0);
    if(cardno<1) {
        if(custid<1) { //学号,无卡使用
            //挂失时使用,其他不使用
            if(strlen(stuempno)<1) {
                return E_TRANS_SCHACC_NOEXIT;
            }
            ret=get_custid_by_stuempno(stuempno,&custid);
            if(ret) {
                return ret;
            }
        }
        //客户号
        memset(&tCard1,0,sizeof(tCard1));
        ret=get_cardno_by_custid(custid, &cardno);
        if(ret) {
            return ret;
        }
    }
    ret=DB_t_card_read_by_cardno(cardno,&card);
    if(ret) {
        writelog(LOG_ERR,"DB_t_card_read_by_cardno error,errcode=[%d],cardno=[%d]",ret,cardno);
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDNO,cardno);
        else
            return E_DB_CARD_R;
    }
    if(card.status[0]!=STATUS_NORMAL) {
        return ERRINFO(E_CARD_LOGOUT,card.cardno);
    }
    strcpy(key,STATIC_SEED_KEY);
    des2src(account_pwd, rPack->semp_pwd);
    EncodePwd(key,account_pwd,pwd, 0);

    //判断卡密码是否正确
    if(0!=strncmp(pwd,card.cardpwd,sizeof(pwd))) {
        writelog(LOG_ERR,"Card password error,clear_pwd[%s],input_pwd=[%s],db_pwd=[%s]",account_pwd,pwd,card.cardpwd);
        return E_TRANS_SCHCARD_PWDERR;
    }
    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);


    SetCol(handle,F_LVOL0,0);
    outPack->lvol0=card.cardno;
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
예제 #20
0
파일: F847116.c 프로젝트: nykma/ykt4sungard
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;
}
예제 #21
0
int F847109(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	char seed_key[17] = "";							//种子密钥
	char logicdate[11]="";
	T_t_aif_account  tAccount;
	T_t_cif_customer	tCustomer;
	
	ST_CPACK aPack;
	ST_PACK *pp = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);

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

	memcpy(seed_key,STATIC_SEED_KEY,sizeof(seed_key));			//读种子密钥
	tCustomer.cut_id = in_pack->lvol1;				        					//客户号

	ret=GetLogicDate(logicdate);							//业务日期
	if(ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	ret=DB_t_cif_customer_read_by_cut_id(tCustomer.cut_id,&tCustomer);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",tCustomer.cut_id);
		if(DB_NOTFOUND==ret)
			*pRetCode=E_CUSTOMER_NOT_EXIST;
		else
			*pRetCode=E_DB_CUSTOMER_R;
		goto L_RETU;		
	}
	if(CUSTSTAT_LOGOUT==tCustomer.cut_state)
	{
		*pRetCode=E_CUSTOMER_LOGOUT;
		goto L_RETU;		
	}
	ret=DB_t_aif_account_read_by_customer_id_and_act_type(tCustomer.cut_id,ACCTYPE_SHOPMAIN, &tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"cut_id[%d]",tCustomer.cut_id);
		if(DB_NOTFOUND!=ret)
		{
			*pRetCode=E_DB_ACCOUNT_R;
			goto L_RETU;		
		}
	}
	else
	{
		if(tAccount.current_state!=ACCOUNTSTAT_LOGOUT)
		{
			*pRetCode=E_ACTNO_EXIST;
			goto L_RETU;		
		}
	}
	memset(&tAccount,0,sizeof(tAccount));
	des2src(tAccount.open_date,logicdate);									//开户日期
	des2src(tAccount.cut_name,in_pack->sname);							//客户名称
	tAccount.customer_id=tCustomer.cut_id;									//客户号
	tAccount.cut_type = in_pack->lvol2;									//客户类别
	des2src(tAccount.stuemp_no,in_pack->sname2); 						//客户学号或员工号
	tAccount.current_state = ACCOUNTSTAT_REGIST;							//当前状态

	ret = getNewActno(tAccount.account_id);								//获得新帐号
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}

	tAccount.act_type = ACCTYPE_SHOPMAIN;				        			//帐号类别
	tAccount.card_id = 0; 													//关联卡号
	tAccount.purse_id = 0;													//关联卡钱包号
//	tAccount.card_state = 0;												//卡状态
	tAccount.card_type = 0;												//卡类别
	des2src(tAccount.subno,SUBJECT_SHOPSAVING);							//所属科目
	EncodePwd(seed_key,in_pack->sserial0,tAccount.password,0);				//帐户密码
	Strncpy_t(tAccount.isautotra,in_pack->scust_type,sizeof(tAccount.isautotra)); 	//是否自动转帐
	tAccount.last_bala = 0.00;					//前次帐户总余额
	tAccount.last_freebala = 0.00;				//前次帐户可用余额
	tAccount.last_frozebala = 0.00;				//前次帐户冻结余额
	tAccount.cur_bala = 0.00;					//当前帐户总余额
	tAccount.cur_freebala = 0.00;				//当前帐户可用余额
	tAccount.cur_frozebala = 0.00;				//当前帐户冻结余额
	tAccount.out_bala = 0.00;					//借方发生总额
	tAccount.in_bala = 0.00;					//贷方发生总额
	tAccount.out_count = 0;					//借方发生总数
	tAccount.in_count = 0;						//贷方发生总数
	tAccount.card_balance = 0.00;				//当前卡中帐户余额
	tAccount.consume_count = 0;				//当前卡中帐户消费次数

	//	插入帐户信息表	
	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;
	}
	//	返回帐号到前台	
	SetCol(handle,0);
	SetCol(handle,F_SSTATION0,0);
	des2src(pp->sstation0, tAccount.account_id);			//帐号
	PutRow(handle,pp,pRetCode,szMsg);
	return 0;
L_RETU:
	return -1;
}                                                 
예제 #22
0
파일: F847104.c 프로젝트: nykma/ykt4sungard
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;
}
예제 #23
0
int RewriteCardInfo(TRUSERID *handle,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans& ats=CAccTrans::GetInst();
	TRANS& trans=ats.trans;
	T_t_card tCard;
	memset(&tCard,0,sizeof(tCard));


	ret=DB_t_card_read_by_cardphyid_and_status(trans.cardphyid,"1",&tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDPHYID,trans.cardphyid);
		else 
			return E_DB_CARD_R;
	}
	trans.cardno=tCard.cardno;
	trans.custid=tCard.custid;
	trans.cardtype=tCard.cardtype;
	trans.feetype=tCard.feetype;
//	if(tCard.status[0]!=STATUS_NORMAL)
//	{
//		return ERRINFO(E_CARD_LOGOUT,trans.cardno);
//	}	
	if('1'==tCard.frozeflag[0])
	{
		return ERRINFO(E_CARD_FREEZE,trans.cardno);
	}
	if('1'==tCard.lossflag[0])
	{
		return ERRINFO(E_CARD_LOST,trans.cardno);
	}	
    char cardpwd[33]="";
    char key[17]="";
    strcpy(key,STATIC_SEED_KEY);
    EncodePwd(key,cardpwd,tCard.cardpwd, 1);

	T_t_customer customer;

	memset(&customer,0,sizeof(customer));
	if(tCard.custid)
	{
		ret=DB_t_customer_read_by_custid(tCard.custid,&customer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				return ERRINFO(E_NOTEXIST_CUSTOMER,tCard.custid);
			else
				return E_DB_CUSTOMER_R;
		}
	}	
	T_t_account tCardAccount;	
	memset(&tCardAccount,0,sizeof(tCardAccount));
	ret=DB_t_account_read_by_accno(tCard.accno,&tCardAccount);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_ACCNO,tCard.accno);
		else 
			return E_DB_ACCOUNT_R;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
	}
	T_t_newcardchange newcardchange;

	memset(&newcardchange,0,sizeof(newcardchange));
	ret=DB_t_newcardchange_read_by_showcardno(tCard.showcardno,&newcardchange);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
		{
			ERRTIP("该卡没有换卡成功,请用前台换卡操作中的撤销换卡功能,恢复该卡信息");
			return E_COMMON_ERR;
		}
		else
			return E_DB_NEWCARDCHANGE_R;
	}
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));

	des2src(transdtl.transdate,trans.transdate);
	des2src(transdtl.transtime,trans.transtime);
	strcpy(transdtl.accdate,trans.accdate);
	strcpy(transdtl.acctime,trans.acctime);
	transdtl.termid=trans.termid;
	transdtl.termseqno=trans.termseqno;
	transdtl.transcode=trans.transcode;
	transdtl.paytype=trans.fundtype;
	des2src(transdtl.voucherno,trans.voucherno);
	transdtl.cardno=trans.cardno;
	transdtl.purseno=trans.purseno;
	transdtl.cardbefbal=trans.cardbefbal;	

	transdtl.cardcnt=tCardAccount.dpscnt;
	transdtl.cardaftbal=tCardAccount.cardbal;		

	transdtl.managefee=trans.totalfeeamt;
	transdtl.amount=trans.totaltransamt;
	transdtl.custid=trans.custid;
	des2src(transdtl.custname,customer.custname);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	GetStuempnoByCustid(transdtl.custid,transdtl.stuempno);
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
	  if(DB_REPEAT==ret)
		return E_DB_TRANSDTL_E;
	  else
		return E_DB_TRANSDTL_I;
	}	

	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);	
	ResetNormalCPack(&aPack,0,1);
		
	SetCol(handle,0);
	SetCol(handle,F_LVOL1,F_LSAFE_LEVEL2,F_LVOL4,F_LVOL5,
				F_SALL_NAME,F_SPAGER,F_SCERT_NO,
				F_SEMAIL2,F_SMARKET_CODE,F_SMARKET_CODE2,F_SDATE0,
				F_LVOL0,F_STX_PWD,F_LVOL8,F_LVOL6,
				F_SORDER0,F_SEMP,F_LVOL11,F_LVOL12,
				F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,F_STIME3,F_SDATE3,0);	
	outPack->lvol0=trans.cardno;
	outPack->lvol1=trans.custid;
	outPack->lsafe_level2=customer.custtype;
	outPack->lvol5=tCard.feetype;
	strncpy(outPack->sall_name,customer.custname,8);
	des2src(outPack->spager,customer.stuempno);
	des2src(outPack->scert_no,customer.deptcode);
	des2src(outPack->smarket_code2,customer.idtype);
	des2src(outPack->semail2,customer.idno);
	des2src(outPack->smarket_code,customer.sex);
	des2src(outPack->sdate0,tCard.expiredate);
	outPack->lvol8=D4U5(transdtl.cardaftbal*100,0);
	outPack->lvol6=tCardAccount.paycnt;
	outPack->lvol11=D4U5(tCardAccount.singlemaxamt*100,0);
	outPack->lvol12=D4U5(tCardAccount.daycostmaxamt*100,0);
//	outPack->lvol4=tCardAccount.subsidyno;
	des2src(outPack->sorder0,tCard.showcardno);
	des2src(outPack->sdate3,ats.trans.accdate);
	des2src(outPack->stime3,ats.trans.acctime);
	des2src(outPack->semp,trans.opercode);
	outPack->lwithdraw_flag=trans.termid;
	outPack->lserial1=trans.termseqno;
    des2src(outPack->stx_pwd,cardpwd);
	des2src(outPack->vsmess,"重写卡信息成功");
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}