Exemple #1
0
int F850006(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	if(rPack->lbank_acc_type==1)
		pAccTrans->trans.transcode=TC_WATERJD2XT;
	else
		pAccTrans->trans.transcode=TC_WATERXT2JD;
	des2src(pAccTrans->trans.opercode,rPack->semp);
	pAccTrans->trans.termid=rPack->lwithdraw_flag;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;			

	trans.cardno= rPack->lvol0;
	if(pAccTrans->trans.cardno<1)
	{
		return E_INPUTNULL_CARDNO;
	}
	des2src(trans.cardphyid,rPack->sstation1);

	
	T_t_card  tCard;
	memset(&tCard,0,sizeof(tCard));
	T_t_account tAccount;
	memset(&tAccount,0,sizeof(tAccount));
	
	ret=pAccTrans->CheckAcc(&tCard,&tAccount);
	if(ret)
	{
		writelog(LOG_INFO,"检查卡状态失败");
		return ret;
	}
	ret=check_card_pwd_by_card(trans.cardno,rPack->stx_pwd);
	if(ret)
		return ret;

	double waterbefbal = rPack->lsafe_level/100.0;

	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));
	
	strcpy(transdtl.accdate,trans.accdate);
	strcpy(transdtl.acctime,trans.acctime);
	transdtl.termid=trans.termid;
	transdtl.termseqno=trans.termseqno;
	des2src(transdtl.transdate,trans.transdate);
	des2src(transdtl.transtime,trans.transtime);
	transdtl.transcode=trans.transcode;
	transdtl.cardno=trans.cardno;
//	transdtl.purseno=PURSE_NO_TWO;
//	transdtl.transflag= TF_PAY;
//	transdtl.cardcnt=trans.paycnt;
//	transdtl.cardbefbal=waterbefbal;
//	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.custid=tCard.custid;
//	transdtl.exttype= exttype_
	sprintf(transdtl.extdata,"%.2lf",waterbefbal);
	des2src(transdtl.custname,trans.custname);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	des2src(transdtl.showcardno,tCard.showcardno);
	if(transdtl.custid)
	{	
		ret=GetStuempnoByCustid(transdtl.custid,trans.stuempno);
		if(ret)
			return ret;
	}
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
		writelog(LOG_ERR,"accdate[%s]termid[%d]termseqno[%d]",transdtl.accdate,transdtl.termid,transdtl.termseqno);
	 	 if(DB_REPEAT==ret)
			return E_DB_TRANSDTL_E;
	  	else
			return E_DB_TRANSDTL_I;
	}		
	return 0;
}
Exemple #2
0
int F846310(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
//	ret=pAccTrans->checkCfgUpdate();
//	if(ret)
//		return ret;
	des2src(pAccTrans->trans.opercode,rPack->semp);
	pAccTrans->trans.transcode=TC_CARDRETURN;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;			
	TRANS& trans=pAccTrans->trans;

	char anonymflag[2]="";

	int returnForgiftFlag=0;
	
	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
		
	SetCol(handle,0);

	//检查客户
	trans.cardflag=1;
	trans.usecardflag=1;
	trans.cardno=rPack->lvol0;	
	trans.purseno=PURSE_NO_ONE;
	trans.paycnt = rPack->lvol6+1;
	trans.cardbefbal=rPack->lvol7/100.0;	
	trans.cardaftbal=trans.cardbefbal;
	des2src(trans.cardphyid,rPack->sstation0);
	
	T_t_card tCard;
	
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(trans,tCard);
	if(ret)
	{
		return ret;
	}
	ret=UpdateCardBitmap(trans.cardno,trans.paycnt,CARDBITMAPTYPE_SYS_ONLINE);
	if(ret)
		return ret;
	T_t_account tCardAccount;	
	memset(&tCardAccount,0,sizeof(tCardAccount));
	ret=DB_t_account_read_by_accno(tCard.accno,&tCardAccount);
	if(ret)
	{
			writelog(LOG_ERR,"cardno[%d]",tCard.cardno);
			if(DB_NOTFOUND==ret)
				return ERRINFO(E_NOTEXIST_CARDACCNO,tCard.accno);
			else
				return E_DB_ACCOUNT_R;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
	}
	if(amtcmp(tCardAccount.balance,0)<0)
	{
		ERRTIP("账户余额小于0不能直接回收");
		return E_COMMON_ERR;
	}
	else if(amtcmp(tCardAccount.balance,0)==0)
	{
		trans.cardaftbal=0;
	}
	else
	{
		strcpy(trans.cardaccno,tCardAccount.accno);
		trans.feetype=tCard.feetype;
		trans.inputamt=tCardAccount.balance;
		trans.unusedamt = trans.inputamt;
		ret=pAccTrans->doTrans();
		if(ret)
			return ret;	
		ret=pAccTrans->doTransEnd();
		if(ret)
			return ret;	
		//修改帐户
		ret=doAccount(trans,tCardAccount.accno);
		if(ret)
			return ret;
	}
	T_t_customer tCustomer;

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

	if(tCard.custid>0)
	{
		ret=DB_t_customer_read_by_custid(tCard.custid,&tCustomer);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				return E_NOTEXIST_CUSTOMER;
			else
				return E_DB_CUSTOMER_R;
		}
	}
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));

	strcpy(transdtl.transdate,trans.transdate);
	strcpy(transdtl.transtime,trans.transtime);
	strcpy(transdtl.accdate,trans.accdate);
	strcpy(transdtl.acctime,trans.acctime);
	transdtl.termid=trans.termid;
	transdtl.termseqno=trans.termseqno;
//	des2src(transdtl.collectdate,rPack->sdate1);
//	des2src(transdtl.collecttime,rPack->stime1);
	transdtl.transcode=trans.transcode;
//	transdtl.paytype=rPack->lvol9;
//	des2src(transdtl.voucherno,rPack->scust_auth2);
	transdtl.cardno=trans.cardno;
	transdtl.purseno=PURSE_NO_ONE;
	transdtl.transflag=TF_PAY;
	transdtl.cardcnt=trans.paycnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.cardaftbal=trans.cardaftbal;
    transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
////	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.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	transdtl.revflag[0]='0';
	transdtl.errcode=0;
	transdtl.custid=tCardAccount.custid;
    des2src(transdtl.showcardno,tCard.showcardno);	
	GetCustBaseInfoByCustID(transdtl.custid,transdtl.custname,transdtl.stuempno,NULL);
	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_LVOL1,F_LSAFE_LEVEL2,F_LVOL5,F_LVOL6,
           F_SALL_NAME,F_SPAGER,F_SCERT_NO,F_SHOLDER_AC_NO,F_LSAFE_LEVEL,F_SMARKET_CODE2,
           F_SEMAIL2,F_SMARKET_CODE,F_SDATE0,F_SNOTE,
           F_SSTAT_TYPE,F_SSTAT_TYPE2,F_SNATION_CODE,F_SBRANCH_CODE0,
           F_LVOL0,F_STX_PWD,F_LVOL8,F_LVOL11,F_LVOL12,
           F_SORDER0,F_SORDER1,F_SORDER2,F_SDATE3,F_STIME3,F_SEMP,
           F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,F_SNAME2,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->smarket_code2,tCustomer.idtype);
	outPack->lsafe_level=tCard.cardtype;
	des2src(outPack->sdate0,tCard.expiredate);
	outPack->lvol0=tCard.cardno;
	outPack->lvol6=trans.paycnt;
	des2src(outPack->stx_pwd,tCard.cardpwd);  
	des2src(outPack->sorder0,tCard.showcardno); 
    des2src(outPack->sname2,tCard.cardverno);
	//	des2src(outPack->sorder0,tCard.showcardno);   
	strcpy(outPack->snote,CARD_STRUCT_VERSION);			  //制卡版本号
	strcpy(outPack->sorder1,CARD_REGISTER_PUBLISH_CODE);	  //发卡注册标识号
	strcpy(outPack->sorder2,CARD_REGISTER_SERVICE_CODE);	  //服务注册标识号
	outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
	outPack->lvol11=D4U5(tCardAccount.singlemaxamt*100,0);
	outPack->lvol12=D4U5(tCardAccount.daycostmaxamt*100,0);
	sprintf(outPack->sholder_ac_no,"%d",tCustomer.custid);  //客户号
	des2src(outPack->sstat_type,tCustomer.idtype);		  //证件类型
	des2src(outPack->snation_code,tCustomer.country); 	  //国籍
	des2src(outPack->sstat_type2,tCustomer.nation); //民族
	des2src(outPack->sbranch_code0,tCustomer.areacode);	  //院校代码  
	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;
	sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
	des2src(outPack->vsmess,trans.remark);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 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;
}
int F846333(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) {
    int ret=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    des2src(pAccTrans->trans.opercode,rPack->semp);
    pAccTrans->trans.transcode=TC_EACCDEPOSIT;
    ret=pAccTrans->InitTrans();
    if(ret)
        return ret;
    TRANS& trans=pAccTrans->trans;
    T_t_transdtl transdtl;		//add by chen 2012-01-04
    memset(&transdtl, 0, sizeof(transdtl));		//add by chen 2012-01-04
    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);
    ResetNormalCPack(&aPack,0,1);

    SetCol(handle,0);

    des2src(trans.craccno,rPack->sbank_acc);	//贷方账号
    des2src(trans.eaccno,rPack->sbank_acc);	//电子钱包账号
    if(!strlen(trans.eaccno))
        return E_INPUTNULL_ACCNO;
    //检查客户
    //去帐户信息
    T_t_netacc tNetAcc;
    memset(&tNetAcc,0,sizeof(tNetAcc));
    ret=DB_t_netacc_read_by_accno(trans.eaccno,&tNetAcc);
    if(ret) {
        writelog(LOG_ERR,"accno[%s]",trans.eaccno);
        if(DB_NOTFOUND==ret)
            return E_NOTEXIST_EACCNO;
        else
            return E_DB_ACCOUNT_R;
    }
    if(tNetAcc.status[0]!=STATUS_NORMAL) {
        return E_EACCNO_LOGOUT;
    }
    //	创建账号
    pAccTrans->trans.custid=tNetAcc.custid;		//客户号
    pAccTrans->trans.inputamt=rPack->damt0;		//输入金额
    pAccTrans->trans.unusedamt = trans.inputamt;	//剩余金额
    if(!pAccTrans->trans.inputamt)
        return E_INPUT_AMT_NULL;
    pAccTrans->trans.fundtype=rPack->lvol9;	//资金类型
    des2src(pAccTrans->trans.voucherno,rPack->scust_auth2);
    ret=pAccTrans->doTrans();
    if(ret)
        return ret;
    SetCol(handle,F_LVOL0,F_LVOL8,F_SDATE3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);
    des2src(outPack->sdate3,pAccTrans->trans.accdate);
    des2src(outPack->semp,trans.opercode);
    outPack->lwithdraw_flag=trans.termid;
    outPack->lserial1=trans.termseqno;
    sprintf(outPack->vsmess,"客户[%s] %s 帐户余额:%.2f元",tNetAcc.accname,pAccTrans->remark.c_str(),pAccTrans->trans.craccaftbal);
    des2src(trans.remark,outPack->vsmess);
    PutRow(handle,outPack,pRetCode,szMsg);
//start add by chen 2012-01-04
    transdtl.transflag = 1;		//交易标志 1为充值
    transdtl.status[0] = '3';		//流水状态 3是成功
    transdtl.termid = trans.termid;			//终端编号
    transdtl.termseqno = trans.termseqno;	//终端流水号
    strncpy(transdtl.transdate, trans.transdate, 8);	//交易日期
    strncpy(transdtl.transtime, trans.transtime, 6);	//交易时间
    transdtl.transcode = trans.transcode;	//交易码
    transdtl.custid = trans.custid;			//客户号
    GetStuempnoByCustid(transdtl.custid,transdtl.stuempno);	//学工号
    strncpy(transdtl.custname, tNetAcc.accname, 61);	//客户名
    strncpy(transdtl.voucherno, trans.voucherno, 21);	//凭证号
    transdtl.amount= trans.transamt;		//交易金额
    transdtl.cardbefbal= trans.craccbefbal;	//交易前余额
    transdtl.cardaftbal = trans.craccaftbal;	//交易后余额
    transdtl.paytype = rPack->lvol9;		//支付方式
    strncpy(transdtl.accdate, trans.accdate, 8);	//记账日期
    strncpy(transdtl.acctime, trans.acctime, 6);	//记账时间
    strncpy(transdtl.opercode, trans.opercode, 9);	//操作员
    // 产生交易参考号
    T_t_refno tRefno;

    memset(&tRefno,0,sizeof(tRefno));
    get_random(tRefno.mac);
    ret= GetNewRefno(tRefno.refno);
    if(ret)
        return ret;

    des2src(tRefno.lastsaved,trans.sysdatetime);
    des2src(tRefno.accdate,trans.accdate);
    tRefno.termid = trans.termid;
    tRefno.termseqno = trans.termseqno;
    tRefno.status = RS_SUCC;

    ret=DB_t_refno_add(&tRefno);
    if(ret) {
        if(DB_REPEAT==ret)
            return E_DB_REFNO_E;
        else
            return E_DB_REFNO_I;
    }
    strncpy(transdtl.refno, tRefno.refno, 14);	//交易参考号
    //添加交易流水记录
    ret = DB_t_transdtl_add(&transdtl);
    if(ret) {
        if(DB_REPEAT == ret)
            return E_DB_TRANSDTL_E;
        else
            return E_DB_TRANSDTL_I;
    }
//end add by chen 2012-01-04
    return 0;
}
int F846323(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans& ats=CAccTrans::GetInst();
	TRANS& trans=ats.trans;
	des2src(ats.trans.opercode,rPack->semp);
	if(strlen(ats.trans.opercode)<1)
	{
		ats.trans.termid=rPack->lwithdraw_flag;
	}
	ats.trans.transcode=TC_WATERCARDBALMOD;
	ret=ats.InitTrans();
	if(ret)
		return ret;			
	trans.transamt=rPack->damt0;
	
	trans.cardflag=1;
	trans.usecardflag=1;	
	trans.cardno=rPack->lvol0;	
	trans.purseno=PURSE_NO_THREE;
	trans.cardbefbal=rPack->lvol7/100.0;
	trans.cardaftbal= D4U5(trans.cardbefbal+trans.transamt);
	des2src(trans.cardphyid,rPack->sstation1);
	if(amtcmp(trans.transamt,0)==0)
	{
		ERRTIP("充值金额不能为0");
		return E_COMMON_ERR;
	}
	T_t_card tCard;
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(trans,tCard);
	if(ret)
	{
		return ret;
	}
	trans.feetype=tCard.feetype;
	trans.cardtype=tCard.cardtype;
	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;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
	}
	trans.custid=tCard.custid;
	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.amount=trans.transamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.custid=tCardAccount.custid;
	des2src(transdtl.custname,tCardAccount.accname);
	des2src(transdtl.opercode,trans.opercode);
    des2src(transdtl.showcardno,tCard.showcardno);
	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,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(ats.trans.cardaftbal*100,0);
	des2src(outPack->sdate3,ats.trans.accdate);
	des2src(outPack->semp,trans.opercode);
	outPack->lwithdraw_flag=trans.termid;
	outPack->lserial1=trans.termseqno;
    sprintf(trans.remark,"%s卡余额%.2lf元",ats.remark.c_str(),ats.trans.cardaftbal);
    des2src(outPack->vsmess,trans.remark);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
int F846322(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) {
    int ret=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;
    des2src(pAccTrans->trans.opercode,rPack->semp);
    if(strlen(pAccTrans->trans.opercode)<1) {
        pAccTrans->trans.termid=rPack->lwithdraw_flag;
    }
    pAccTrans->trans.transcode=TC_CARDBALMOD;
    ret=pAccTrans->InitTrans();
    if(ret)
        return ret;

    des2src(pAccTrans->trans.chkopercode,rPack->semp_no);
    ret=chk_oper_pwd(pAccTrans->trans.chkopercode,rPack->scust_limit);
    if(ret)
        return ret;
    trans.cardflag=1;
    trans.usecardflag=1;
    trans.cardno=rPack->lvol0;
    pAccTrans->SetCardCntAndCardBal(rPack->lvol5,rPack->lvol6,rPack->lvol7);
    des2src(trans.cardphyid,rPack->sstation1);
    if(rPack->lbank_acc_type>0) {
        trans.transamt=rPack->damt0;
        trans.transflag=TF_DPS;
        trans.aftdpscnt++;
    } else {
        trans.transamt=-rPack->damt0;
        trans.transflag=TF_PAY;
        trans.aftpaycnt++;
    }
    if(amtcmp(trans.transamt,0)==0) {
        ERRTIP("调整金额不能为0");
        return E_COMMON_ERR;
    }
    trans.cardaftbal= D4U5(trans.cardbefbal+trans.transamt);
    T_t_card tCard;
    memset(&tCard,0,sizeof(tCard));
    ret=doCard(trans,tCard);
    if(ret) {
        return ret;
    }
    trans.feetype=tCard.feetype;
    trans.cardtype=tCard.cardtype;
    T_t_account tCardAccount;
    memset(&tCardAccount,0,sizeof(tCardAccount));
    ret=DB_t_account_read_lock_by_c0_and_accno(tCard.accno,&tCardAccount);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDACCNO,tCard.accno);
        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);
    }
    if(amtcmp(trans.cardbefbal,tCardAccount.availbal)==0) {
        DB_t_account_free_lock_by_c0();
        ERRTIP("该卡余额与账户余额一致,不需要调整");
        return E_COMMON_ERR;
    }
    if(amtcmp(trans.cardbefbal,tCardAccount.balance)==0) {
        DB_t_account_free_lock_by_c0();
        ERRTIP("该卡余额与账户余额一致,不需要调整");
        return E_COMMON_ERR;
    }
    if(amtcmp(trans.cardaftbal,tCardAccount.balance)>0) {
        DB_t_account_free_lock_by_c0();
        ERRTIP("调整后卡余额不能大于账户余额");
        return E_COMMON_ERR;
    }
    tCardAccount.dpscnt=trans.dpscnt;
    tCardAccount.paycnt=trans.paycnt;
    if(rPack->lbank_acc_type>0)
        tCardAccount.dpscnt=trans.aftdpscnt;
    if(rPack->lbank_acc_type<0)
        tCardAccount.paycnt=trans.aftpaycnt;
    tCardAccount.cardbal=trans.cardaftbal;
    strcpy(tCardAccount.transtime,trans.sysdatetime);
    ret=DB_t_account_update_lock_by_c0(&tCardAccount);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDACCNO,tCard.accno);
        else
            return E_DB_ACCOUNT_U;
    }
    trans.custid=tCard.custid;
    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.amount=trans.transamt;
    transdtl.managefee=trans.totalfeeamt;
    transdtl.cardaftbal=trans.cardaftbal;
    transdtl.custid=trans.custid;
    des2src(transdtl.opercode,trans.opercode);
    des2src(transdtl.showcardno,tCard.showcardno);
    GetCustBaseInfoByCustID(transdtl.custid,transdtl.custname,transdtl.stuempno,NULL);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    transdtl.transflag = trans.transflag;
    if(TF_DPS==transdtl.transflag) {
        transdtl.cardcnt=trans.aftdpscnt;
    } else {
        transdtl.cardcnt=trans.aftpaycnt;
        ret=UpdateCardBitmap(trans.cardno,transdtl.cardcnt,CARDBITMAPTYPE_SYS_ONLINE);
        if(ret)
            return ret;
    }
    ret=SaveCardTransInfo();
    if(ret) {
        writelog(LOG_ERR,"SaveCardTransInfo ret=%d",ret);
    }
    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,F_LVOL0,F_LVOL8,F_SDATE0,
           F_SDATE3,F_STIME3,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.accdate);
    des2src(outPack->stime3,pAccTrans->trans.acctime);
    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;
}
Exemple #7
0
int F846326(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	des2src(pAccTrans->trans.opercode,rPack->semp);
	if(strlen(pAccTrans->trans.opercode)<1)
	{
		pAccTrans->trans.termid=rPack->lwithdraw_flag;
	}
	pAccTrans->trans.transcode=TC_WATERCARDBALMOD;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;	

		des2src(pAccTrans->trans.chkopercode,rPack->semp_no);
	ret=chk_oper_pwd(pAccTrans->trans.chkopercode,rPack->scust_limit);
	if(ret)
		return ret;
	if(rPack->lbank_acc_type>0)
		trans.transamt=rPack->damt0;
	else
		trans.transamt=-rPack->damt0;
	
	trans.cardflag=1;
	trans.usecardflag=1;	
	trans.cardno=rPack->lvol0;	
	trans.purseno=PURSE_NO_TWO;
	trans.cardbefbal=rPack->lvol7/100.0;
	trans.cardaftbal= D4U5(trans.cardbefbal+trans.transamt);
	des2src(trans.cardphyid,rPack->sstation1);
	if(amtcmp(trans.transamt,0)==0)
	{
		ERRTIP("调整金额不能为0");
		return E_COMMON_ERR;
	}
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_TWO,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(trans.cardaftbal,CardMaxBal)>0)
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
		
	T_t_card tCard;
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(trans,tCard);
	if(ret)
	{
		return ret;
	}
	trans.feetype=tCard.feetype;
	trans.cardtype=tCard.cardtype;
	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;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
	}
	trans.custid=tCard.custid;
	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.amount=trans.transamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.custid=tCardAccount.custid;
	des2src(transdtl.custname,tCardAccount.accname);
	des2src(transdtl.opercode,trans.opercode);
    transdtl.showcardno=atol(tCard.showcardno);
	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,F_LVOL0,F_LVOL8,F_LVOL10,F_LVOL11,F_LVOL12,F_SDATE0,
		F_SDATE3,F_STIME3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);	
	int price1=0;
	int price2=0;
	int price3=0;
	ret=GetWaterPrice(price1,price2,price3);
	if(ret)
	{
		writelog(LOG_ERR,"读水价失败ret=%d",ret);
		return ret;
	}
	outPack->lvol10=price1;
	outPack->lvol11=price2;
	outPack->lvol12=price3;
	outPack->lvol0=tCard.cardno;
	outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
	des2src(outPack->sdate0,pAccTrans->trans.accdate);
	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;
    sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
    des2src(outPack->vsmess,trans.remark);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
Exemple #8
0
static int doReverse(char* oldaccdate,int oldtermid,int oldtermseqno,char *cardphyid)
{
	//查找操作员流水
	int ret=0;
	T_t_card tCard;
	
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;

	trans.revflag=1;//冲正标志

	char transdtlname[61]={0};
	ret=GetTransdtlTableName(oldaccdate,transdtlname);
	if(ret)
	{
		writelog(LOG_ERR,"GetTransdtlTableName err");
		return ret;
	}
	T_t_transdtl transdtl;
	
	ret=ReadTransdtlData(transdtlname,oldaccdate,oldtermid,oldtermseqno,transdtl);
	if(ret)
	{
		writelog(LOG_ERR,"ReadTransdtlData transdtlname[%s],oldaccdate[%s],oldtermid[%d],oldtermseqno[%d]",transdtlname,oldaccdate,oldtermid,oldtermseqno);
		return ret;
	}
	trans.cardno=transdtl.cardno;
	if('1'==transdtl.revflag[0])
	{
		memset(&tCard,0,sizeof(tCard));
		ret=DB_t_card_read_by_cardno(transdtl.cardno,&tCard);
		if(ret)
		{
			writelog(LOG_ERR,"cardno[%d]",transdtl.cardno);
			if(DB_NOTFOUND==ret)
				return ERRINFO(E_NOTEXIST_CARDNO,tCard.cardno);
			else 
				return E_DB_CARD_R;
		}		
		pAccTrans->remark="该交易已冲正";
		strcpy(cardphyid,tCard.cardphyid);
		return 0;
	}	
	if(transdtl.cardcnt>0&&transdtl.cardno>0)
	{
		ret=UpdateCardBitmap(transdtl.cardno,transdtl.cardcnt,CARDBITMAPTYPE_REV);
		if(ret)
			return ret;
	}
	if(strlen(transdtl.opercode))
	{
		if(strcmp(transdtl.opercode,pAccTrans->trans.opercode)!=0)
		{
			return ERRINFO(E_REVOPER,transdtl.opercode);
		}
	}
	else
	{
		des2src(transdtl.opercode,trans.opercode);
	}
	ret=UpdateTransdtlHisRevFlag(transdtlname,oldaccdate,oldtermid,oldtermseqno);
	if(ret)
	{
		writelog(LOG_ERR,"UpdateTransdtlRevFlag ret[%d] transdtlname[%s]accdate[%s]termid[%d]termseqno[%d]",ret,transdtlname,oldaccdate,oldtermid,oldtermseqno);
		return ret;
	}
	transdtl.termid=trans.termid;
	transdtl.termseqno=trans.termseqno;
	strcpy(transdtl.accdate,trans.accdate);
	strcpy(transdtl.acctime,trans.acctime);
	des2src(transdtl.transdate,trans.transdate);
	des2src(transdtl.transtime,trans.transtime);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.transcode=TC_CARDOPENREV;
	transdtl.cardcnt=trans.paycnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.cardaftbal=0;
	transdtl.amount=-transdtl.amount;
	if(amtcmp(trans.cardbefbal,0)>0)
	{	
		transdtl.transflag=TF_PAY;
		transdtl.cardcnt=trans.paycnt;
	}
	transdtl.managefee=-transdtl.managefee;
	transdtl.revflag[0]=0;
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
		if(DB_REPEAT==ret)
			return E_DB_TRANSDTL_E;
		else
			return E_DB_TRANSDTL_I;
	}
	memset(&tCard,0,sizeof(tCard));
	ret=DB_t_card_read_lock_by_cur_and_cardno(transdtl.cardno,&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",transdtl.cardno);
		if(DB_NOTFOUND==ret)
			return E_DB_CARD_N;
		else 
			return E_DB_CARD_R;
	}
	if(tCard.status[0]!=STATUS_NORMAL)
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_LOGOUT,transdtl.cardno);
	}	
	if('1'==tCard.frozeflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_FREEZE,transdtl.cardno);
	}
	if('1'==tCard.lossflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_LOST,transdtl.cardno);
	}	
	if('1'==tCard.badflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_BADRECORD,transdtl.cardno);
	}	
	ret=getCardVerNo(tCard.cardverno);
	if(ret)
	{
		DB_t_card_free_lock_by_cur();
		return ret;
	}
	tCard.status[0]=STATUS_DELETE;
	strcpy(cardphyid,tCard.cardphyid);
	strcpy(tCard.closedate,trans.transdate);
	des2src(tCard.lastsaved,trans.sysdatetime);
	ret=DB_t_card_update_lock_by_cur(&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",tCard.cardno);
		if(DB_NOTFOUND==ret)
			return E_DB_CARD_N;
		else 
			return E_DB_CARD_U;
	}	
	T_t_customer tCustomer;
	
	memset(&tCustomer,0,sizeof(tCustomer));
	//检查客户
	if(tCard.custid)
	{
		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)
				return E_DB_CUSTOMER_N;
			else 
				return E_DB_CUSTOMER_R;
		}
		if(tCustomer.status[0]!=STATUS_NORMAL)

		{
			DB_t_customer_free_lock_cur();
			return E_CUSTOMER_LOGOUT;		
		}
		tCustomer.holdcardcnt--;
		des2src(tCustomer.lastsaved,trans.sysdatetime);
		ret=DB_t_customer_update_lock_by_cur(&tCustomer);
		if(ret)
		{
			writelog(LOG_ERR,"custid[%d]",tCard.custid);
			if(DB_NOTFOUND==ret)
				return E_DB_CUSTOMER_N;
			else 
				return E_DB_CUSTOMER_U;
		}
		des2src(trans.stuempno,tCustomer.stuempno);		
	}
	////添加卡版本号记录
	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.cardno=tCard.cardno;
	cardver.status[0]=STATUS_NORMAL;	
	des2src(cardver.cardphyid,tCard.cardphyid);
	des2src(cardver.stuempno,tCustomer.stuempno);
	cardver.cardvertype=CARDVERTYPE_CARDCLOSE;	
	des2src(cardver.cardverno,tCard.cardverno);
	ret=DB_t_cardver_add(&cardver);
	if(ret)
	{
		writelog(LOG_ERR,"cardverno[%s]",cardver.cardverno);
		if(DB_REPEAT==ret)
			return E_DB_CARDVER_E;
		else
			return E_DB_CARDVER_I;
	}
	if(pAccTrans->sysPara.bEnableCardMgr)
	{
		ret=UseShowCardNoRev(tCard.showcardno);
		if(ret)
			return ret;
		trans.cardno=tCard.cardno;
		T_t_carddtl carddtl;
		memset(&carddtl,0,sizeof(carddtl));
		
		des2src(carddtl.accdate,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_GET;
		carddtl.inoutflag=INOUTFLAG_IN;
		carddtl.transcnt=1;
		strcpy(carddtl.summary,"发卡冲正");	
		des2src(carddtl.cardphyid,tCard.cardphyid);
		des2src(carddtl.showcardno,tCard.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_cardbook tCardBook;

	memset(&tCardBook,0,sizeof(tCardBook));
	ret=getCardBookRecordNo(tCardBook.recordno);
	if(ret)
		return ret;
	tCardBook.cardtype=tCard.cardtype;
//	strcpy(tCardBook.curno,tCard.showcardno);
//	strcpy(tCardBook.startno,tCard.showcardno);
//	strcpy(tCardBook.endno,tCard.showcardno);	
////	tCardBook.usedcnt=0;
//	tCardBook.unusedcnt=1;
	tCardBook.status[0]=STATUS_NORMAL;
	strcpy(tCardBook.opercode,trans.opercode);
	ret=DB_t_cardbook_add(&tCardBook);
	if(ret)
	{
		if(DB_REPEAT==ret)
			return E_DB_CARDBOOK_E;
		else
			return E_DB_CARDBOOK_I;
	}
	//添加卡片回收明细记录
	T_t_carddtl tCarddtl;
	
	memset(&tCarddtl,0,sizeof(tCarddtl));

	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_REUSE;
	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;
	}
	*/
	//删除卡交易位图数据
	/*
	ret=DB_t_cardbitmap_del_by_cardno(tCard.cardno);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",trans.cardno);		
		return E_DB_CARDBITMAP_D;
	}
	*/
	T_t_account tCardAccount;

	memset(&tCardAccount,0,sizeof(tCardAccount));
	ret=DB_t_account_read_by_accno(tCard.accno,&tCardAccount);
	if(ret)
	{
		writelog(LOG_ERR,"transdtl.cardno[%d],transdtl.purseno[%d]",transdtl.cardno,transdtl.purseno);
		if(DB_NOTFOUND==ret)
			return E_NOTEXIST_CARDACCNO;
		else
			return E_DB_ACCOUNT_R;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return E_CARDACC_LOGOUT;
	}
	des2src(trans.cardaccno,tCardAccount.accno);
	ret=pAccTrans->doHistoryReverseTrans(oldaccdate,oldtermid,oldtermseqno);	
	if(ret)
	{
		if(E_DB_ACCDTL_N!=ret)
			return ret;
	}
	//注销帐户
	memset(&tCardAccount,0,sizeof(tCardAccount));

	ret=DB_t_account_read_lock_by_c0_and_accno(tCard.accno,&tCardAccount);
	if(ret)
	{
		writelog(LOG_ERR,"transdtl.cardno[%d],transdtl.purseno[%d]",transdtl.cardno,transdtl.purseno);
		if(DB_NOTFOUND==ret)
			return E_NOTEXIST_CARDACCNO;
		else
			return E_DB_ACCOUNT_R;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		DB_t_account_free_lock_by_c0();
		return E_CARDACC_LOGOUT;
	}
	if(amtcmp(tCardAccount.balance,0)!=0)
	{
		writelog(LOG_ERR,"balance[%.2lf]",tCardAccount.balance);
		DB_t_account_free_lock_by_c0();
		return E_CARDACC_BALANCE_NOZERO;
	}
	if(amtcmp(tCardAccount.foregift,0)!=0)
	{
		writelog(LOG_ERR,"foregift[%.2lf]",tCardAccount.foregift);
		DB_t_account_free_lock_by_c0();
		return E_CARDACC_FOREGIFT_NOZERO;
	}
	tCardAccount.status[0]=STATUS_DELETE;
	tCardAccount.cardbal=0;
	strcpy(tCardAccount.closedate,trans.transdate);
	ret=DB_t_account_update_lock_by_c0(&tCardAccount);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_NOTEXIST_CARDACCNO;
		else 
			return E_DB_ACCOUNT_U;

	}
	return 0;
}
int F846336(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) {
    int ret=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;

    //des2src(pAccTrans->trans.opercode,rPack->semp);
    trans.termid=rPack->lcert_code;

    int transflag=rPack->lvol3;
    if(transflag) {
        trans.transcode=TC_EACC2CARD;
    } else {
        trans.transcode=TC_CARD2EACC;
    }

    ret=pAccTrans->InitTrans();
    if(ret)
        return ret;

    char pwd_crypt[33]="";
    des2src(pwd_crypt,rPack->scust_limit); // 卡密码

    trans.cardflag=1;
    trans.usecardflag=1;
    trans.cardno=rPack->lvol0;
    trans.purseno=PURSE_NO_ONE;
    trans.dpscnt=rPack->lvol5+1;
    trans.paycnt=rPack->lvol6+1;
    trans.cardbefbal=rPack->lvol7/100.0;
    trans.cardaftbal=trans.cardbefbal;
    trans.inputamt=D4U5(rPack->damt0,2);
    trans.unusedamt = trans.inputamt;

//	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);

    T_t_refno tRefno;
    memset(&tRefno,0,sizeof(tRefno));

    get_random(tRefno.mac);
    ret= GetNewRefno(tRefno.refno);
    if(ret)
        return ret;
    des2src(tRefno.lastsaved,trans.sysdatetime);
    des2src(tRefno.accdate,trans.accdate);
    tRefno.termid = trans.termid;
    tRefno.termseqno = trans.termseqno;
    tRefno.status = RS_SUCC;

    ret=DB_t_refno_add(&tRefno);
    if(ret) {
        if(DB_REPEAT==ret)
            return E_DB_REFNO_E;
        else
            return E_DB_REFNO_I;
    }

    //检查客户
    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_accno(tCard.accno,&tCardAccount);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_CARDACCNO,tCard.accno);
        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);

    trans.feetype=tCard.feetype;
    trans.custid=tCard.custid;
    strcpy(trans.cardaccno,tCardAccount.accno);
    strcpy(trans.eaccno,tNetAccount.accno);

    if(TC_CARD2EACC==trans.transcode) {
        //检查卡密码
        if(strcmp(tCard.cardpwd,pwd_crypt)!=0) {
            return E_CARDPWD;
        }

        if(amtcmp(trans.inputamt,trans.cardbefbal)>0)
            return ERRINFO(E_CARD_BALANCE_SHORTAGE,trans.cardbefbal);
    } else {
        char inpwd_crypt[65]="";
        des2src(inpwd_crypt,rPack->snote2); //检查电子钱包密码
        if(!strlen(inpwd_crypt))
            return E_EACCPWD;

        if(strcmp(inpwd_crypt,tNetAccount.paypwd)!=0)
            return E_EACCPWD;

        //if(tNetAccount.stoppayflag[0]=='1')
        //	return ERRINFO(E_EACC_STOPPAY,tNetAccount.accno);

        if(amtcmp(trans.inputamt,tNetAccount.balance)>0)
            return ERRINFO(E_EACC_BALANCE_SHORTAGE,trans.inputamt-tNetAccount.balance);

        double CardMaxBal=0;
        ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
        if(ret)
            return ret;
        if(amtcmp(trans.inputamt+trans.cardbefbal,CardMaxBal)>0)
            return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
    }
    trans.feetype=0;
    trans.usecardflag=1;
    trans.custid=tCard.custid;
    ret=pAccTrans->doTrans();
    if(ret)
        return ret;
    T_t_transdtl transdtl;
    memset(&transdtl,0,sizeof(transdtl));

    des2src(transdtl.refno,tRefno.refno); // 交易参考号
    des2src(transdtl.transdate,trans.accdate);
    des2src(transdtl.transtime,trans.acctime);
    des2src(transdtl.coldate,trans.accdate);
    des2src(transdtl.coltime,trans.acctime);
    strcpy(transdtl.accdate,trans.accdate);
    strcpy(transdtl.acctime,trans.acctime);
    transdtl.termid=trans.termid;
    transdtl.termseqno=trans.termseqno;
    transdtl.transcode=trans.transcode;
    transdtl.cardno=trans.cardno;
    transdtl.purseno=trans.purseno;
    des2src(transdtl.custname,tNetAccount.accname);
    if(TC_EACC2CARD==trans.transcode) {
        transdtl.transflag=TF_DPS;
        transdtl.cardcnt = trans.dpscnt;
    } else {
        transdtl.transflag=TF_PAY;
        transdtl.cardcnt = trans.paycnt;
    }
    transdtl.cardbefbal=trans.cardbefbal;
    transdtl.cardaftbal=trans.cardaftbal;
    transdtl.managefee=trans.totalfeeamt;
    transdtl.amount=trans.inputamt;
    des2src(transdtl.opercode,trans.opercode);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    transdtl.revflag[0]='0';
    des2src(transdtl.showcardno,tCard.showcardno);
    transdtl.custid=tCard.custid;
    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_LVOL0,F_LVOL8,F_SDATE0,F_SPHONE3,F_SADDR,
           F_SDATE3,F_STIME3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);

    strcpy(outPack->sphone3,tRefno.refno);
    strcpy(outPack->saddr,tRefno.mac);
    outPack->lvol0=tCard.cardno;
    outPack->lvol8=D4U5(trans.cardaftbal*100,0);
    des2src(outPack->sdate3,trans.accdate);
    des2src(outPack->stime3,trans.acctime);
    des2src(outPack->semp,trans.opercode);
    outPack->lwithdraw_flag=trans.termid;
    outPack->lserial1=trans.termseqno;
    char temp[128]="";
    if(TC_EACC2CARD==trans.transcode) {
        sprintf(temp,"电子账户向卡转账 %.2f 元成功,电子账户余额:%.2f 卡余额:%.2f",
                trans.inputamt,
                trans.draccaftbal,
                trans.cardaftbal);
    } else {
        sprintf(temp,"卡向电子账户转账 %.2f 元成功,电子账户余额:%.2f 卡余额:%.2f",
                trans.inputamt,
                trans.craccaftbal,
                trans.cardaftbal);
    }

    pAccTrans->remark+=temp;
    strcpy(outPack->vsmess,pAccTrans->remark.c_str());
    des2src(trans.remark,outPack->vsmess);
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
Exemple #10
0
static int NormalTrans(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_LVOL0,F_LVOL1,F_LVOL2,F_LVOL8,F_LVOL10,F_LVOL11,F_LVOL12,F_SDATE0,F_SPHONE3,F_SADDR,F_LSAFE_LEVEL2,
		F_SDATE3,F_STIME3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);

	if(rPack->lvol0<1)
	{
		ERRTIP("请输入付款方卡号");
		return E_COMMON_ERR;
	}
	if(rPack->lvol2<1)
	{
		ERRTIP("请输入收款方卡号");
		return E_COMMON_ERR;
	}
	des2src(trans.refno,rPack->sphone3);		//交易参考号
	if(strlen(trans.refno)!=14)
	{
		 ERRTIP("交易参考号错误");
		 return E_COMMON_ERR;
	}
	T_t_refno tRefno;
	memset(&tRefno,0,sizeof(tRefno));

	ret=DB_t_refno_read_by_refno(trans.refno,&tRefno);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_REFNO_N;
		else
			return E_DB_REFNO_R;
	}
	if(strncmp(tRefno.mac,rPack->saddr,8)!=0)
	{
		ERRTIP("交易参考号MAC校验错误");
		return E_COMMON_ERR;
	}
	if(RS_FAIL==tRefno.status)
	{
		ERRTIP("交易已失败");
		return E_COMMON_ERR;
	}
	T_t_transdtl transdtl;	
	memset(&transdtl,0,sizeof(transdtl));
	ret=DB_t_transdtl_read_by_accdate_and_termid_and_termseqno(tRefno.accdate,tRefno.termid,tRefno.termseqno,&transdtl);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_NOTEXIST_TRANSDTL;
		else
			return E_DB_TRANSDTL_R;
	}
	if(RS_SUCC==tRefno.status)
	{
		outPack->lvol0=transdtl.cardno;
		outPack->lvol1=D4U5(transdtl.amount*100,0);
		outPack->lvol8=D4U5(transdtl.cardaftbal*100,0);
		outPack->lsafe_level2=rPack->lsafe_level+D4U5(transdtl.amount*100,0);
		des2src(outPack->sdate3,transdtl.transdate);
		des2src(outPack->stime3,transdtl.transtime);
		des2src(outPack->semp,transdtl.opercode);
		outPack->lwithdraw_flag=transdtl.termid;
		outPack->lserial1=transdtl.termseqno;
		des2src(outPack->sphone3,transdtl.refno);	
		PutRow(handle,outPack,pRetCode,szMsg);
		return 0;
	}
	int cardno=atoi(transdtl.voucherno);
	if(rPack->lvol2!=cardno)
	{
		ERRTIP("收款方卡号错误");
		return E_COMMON_ERR;
	}
	if(transdtl.status[0]!=DTLSTATUS_INIT)
	{
		ERRTIP("交易流水表状态错误");
		return E_COMMON_ERR;
	}
	des2src(trans.opercode,transdtl.opercode);
	trans.termid=transdtl.termid;
	trans.termseqno=transdtl.termseqno;
	trans.cardflag=0;
	trans.usecardflag=0;	
	trans.transcode=transdtl.transcode;
	trans.cardno=transdtl.cardno;	
	trans.purseno=transdtl.purseno;
	trans.paycnt=transdtl.cardcnt;
	trans.cardbefbal=transdtl.cardbefbal;
	trans.cardaftbal=transdtl.cardaftbal;
	trans.inputamt= transdtl.amount;	
	trans.unusedamt = trans.inputamt;
	
	T_t_card tOutCard;
	memset(&tOutCard,0,sizeof(tOutCard));

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

	ret=DB_t_card_read_by_cardno(trans.cardno,&tOutCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDNO,trans.cardno);
		else
			return E_DB_CARD_R;
	}
	ret=DB_t_card_read_by_cardno(rPack->lvol2,&tInCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDNO,rPack->lvol2);
		else
			return E_DB_CARD_R;
	}
	trans.feetype=tOutCard.feetype;
	trans.custid=tOutCard.custid;
//	trans.cardaftbal=trans.cardbefbal;
	strcpy(pAccTrans->trans.draccno,tOutCard.accno);
	strcpy(pAccTrans->trans.craccno,tInCard.accno);
	
	ret=pAccTrans->doTrans();
	if(ret)
		return ret;
	ret=pAccTrans->doTransEnd();
	if(ret)
		return ret;
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	ret=DB_t_transdtl_update_by_accdate_and_termid_and_termseqno(tRefno.accdate,tRefno.termid,tRefno.termseqno,&transdtl);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_TRANSDTL_N;
		else
			return E_DB_TRANSDTL_U;
	}
	tRefno.status=RS_SUCC;
	des2src(tRefno.lastsaved,trans.sysdatetime);
	ret=DB_t_refno_update_by_refno(tRefno.refno,&tRefno);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_REFNO_N;
		else
			return E_DB_REFNO_U;
	}
	/////////////////////////////////////////////////////////////////////////////////////////////////
	//记录转入卡的卡交易流水	
	pAccTrans->Reset();
	trans.termid=transdtl.termid;
	trans.dpscnt=rPack->lvol3+1;
	trans.cardbefbal=rPack->lsafe_level/100.0;
	trans.cardaftbal=(rPack->lvol1+rPack->lsafe_level)/100.0;
	trans.cardno=atoi(transdtl.voucherno);
	if(trans.cardno!=rPack->lvol2)
	{
		ERRTIP("收款卡号不符");
		return E_COMMON_ERR;
	}
	ret=GetCustBaseInfoByCustID(tInCard.custid,trans.custname,trans.stuempno,trans.remark);
	if(ret)
		return ret;
	ret=pAccTrans->GetTermSeqno();
	if(ret)
	{
		return ret;
	}
	T_t_transdtl transdtl2;
	memset(&transdtl2,0,sizeof(transdtl2));
	des2src(transdtl2.refno,transdtl.refno);
	des2src(transdtl2.transdate,transdtl.transdate);
	des2src(transdtl2.transtime,transdtl.transtime);
	strcpy(transdtl2.accdate,transdtl.accdate);
	strcpy(transdtl2.acctime,transdtl.acctime);
	transdtl2.termid=trans.termid;
	transdtl2.termseqno=trans.termseqno;
	transdtl2.transcode=transdtl.transcode;
	sprintf(transdtl2.voucherno,"%d",transdtl.cardno);
	transdtl2.cardno=trans.cardno;
	transdtl2.purseno=trans.purseno;
	transdtl2.transflag =TF_DPS;
	transdtl2.cardcnt=trans.dpscnt;
	transdtl2.cardbefbal=trans.cardbefbal;
	transdtl2.cardaftbal=trans.cardaftbal;
	transdtl2.amount= transdtl.amount;
	transdtl2.managefee=0;
	transdtl2.custid=tInCard.custid;
	des2src(transdtl2.custname,trans.custname);
	des2src(transdtl2.opercode,trans.opercode);
	transdtl2.status[0]=DTLSTATUS_SUCCESS;
	des2src(transdtl2.showcardno,tInCard.showcardno);
	des2src(transdtl2.stuempno,trans.stuempno);
	transdtl2.exttype=EXTTYPE_OPPSNO;	
	des2src(transdtl2.extdata,transdtl.stuempno);
	sprintf(transdtl2.remark,"由(%s)转出",transdtl.custname);
	ret=DB_t_transdtl_add(&transdtl2);
	if(ret)
	{
	  if(DB_REPEAT==ret)
		return E_DB_TRANSDTL_E;
	  else
		return E_DB_TRANSDTL_I;
	}		
	T_t_account OutAccount;
	memset(&OutAccount,0,sizeof(OutAccount));
	ret=DB_t_account_read_lock_by_c0_and_accno(tOutCard.accno,&OutAccount);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDACCNO,tOutCard.accno);
		else
			return E_DB_ACCOUNT_R;
	}
	OutAccount.paycnt=transdtl.cardcnt;
	OutAccount.cardbal=transdtl.cardaftbal;
	OutAccount.lastpaycnt=transdtl.cardcnt-1;
	OutAccount.lastcardbal=transdtl.cardbefbal;
	strcpy(OutAccount.lastaccdate,transdtl.transdate);
	ret=DB_t_account_update_lock_by_c0(&OutAccount);
	if(ret)
	{
		writelog(LOG_ERR,"更新付款方账户表错误ret=%d",ret);
		return E_DB_ACCOUNT_U;
	}

	T_t_account InAccount;
	memset(&InAccount,0,sizeof(InAccount));
	ret=DB_t_account_read_lock_by_c0_and_accno(tInCard.accno,&InAccount);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDACCNO,tInCard.accno);
		else
			return E_DB_ACCOUNT_R;
	}
	InAccount.dpscnt=transdtl2.cardcnt;
	InAccount.cardbal=transdtl2.cardaftbal;
	InAccount.lastdpscnt=transdtl2.cardcnt-1;
	InAccount.lastcardbal=transdtl2.cardbefbal;
	strcpy(InAccount.lastaccdate,transdtl2.transdate);
	ret=DB_t_account_update_lock_by_c0(&InAccount);
	if(ret)
	{
		writelog(LOG_ERR,"更新收款方账户表错误ret=%d",ret);
		return E_DB_ACCOUNT_U;
	}
	outPack->lvol0=transdtl.cardno;
	outPack->lvol2=transdtl2.cardno;
	outPack->lvol1=D4U5(transdtl.amount*100,0);
	outPack->lvol8=D4U5(transdtl.cardaftbal*100,0);	
	outPack->lsafe_level2=D4U5(transdtl2.cardaftbal*100,0);
	des2src(outPack->sdate3,trans.accdate);
	des2src(outPack->stime3,trans.acctime);
	des2src(outPack->semp,trans.opercode);
	outPack->lwithdraw_flag=transdtl.termid;
	outPack->lserial1=transdtl.termseqno;
	des2src(outPack->sphone3,transdtl.refno);
	des2src(outPack->vsmess,trans.remark);
	
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
Exemple #11
0
// 退水控钱包到主钱包
static int waterbalareturn(CAccTrans *pAccTrans,ST_PACK *rPack,ST_PACK *outPack)
{
	int ret=0;
	double waterbefbal = 0;
	double wateraftbal = 0;
	TRANS& trans=pAccTrans->trans;
	
	trans.cardno=rPack->lvol0;	
	trans.purseno=PURSE_NO_ONE;
	trans.cardflag=1;
	trans.usecardflag=1;	
	pAccTrans->SetCardCntAndCardBal(rPack->lvol5,rPack->lvol6,rPack->lvol7);
	trans.aftdpscnt++;
	des2src(trans.cardphyid,rPack->sstation1);

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

	T_t_account tAccount;
	memset(&tAccount,0,sizeof(tAccount));
	
	/*
	if(!rPack->lvol2)		// 有卡
	{
		ERRTIP("无卡小钱包余额不退");
		return E_COMMON_ERR;
	}
	ret=pAccTrans->CheckAcc(&tCard,&tAccount);		
	if(ret)
	{
		writelog(LOG_ERR,"检查状态失败");
		return ret;
	}
	*/

	ret = DB_t_card_read_by_cardno(trans.cardno,&tCard);
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			return ERRINFO(E_NOTEXIST_CARDNO,trans.cardno);
		return ret;
	}

	trans.custid=tCard.custid;
	des2src(trans.showcardno,tCard.showcardno);
	des2src(trans.cardaccno,tCard.accno);
	

	ret=DB_t_account_read_by_accno(tCard.accno,&tAccount);
	if(ret)
	{
		return E_DB_ACCOUNT_R;
	}

	strcpy(trans.custname,tAccount.accname);

	// 小钱包类型
	T_t_pursetype  pursetype;
	memset(&pursetype,0,sizeof(pursetype));

	pursetype.pursetype=rPack->lvol1;
	if(pursetype.pursetype<1)
	{
		ERRTIP("请输入小钱包类型");
		return E_COMMON_ERR;
	}
	ret=DB_t_pursetype_read_by_pursetype(pursetype.pursetype,&pursetype);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
		{	
			ERRTIP("钱包类型[%d]不存在",pursetype.pursetype);
			return E_COMMON_ERR;
		}
		else
			return E_DB_PURSETYPE_R;
	}
	if(!pursetype.enableflag)
	{
		ERRTIP("钱包类型[%d]未启用",pursetype.pursetype);
		return E_COMMON_ERR;
	}
	if(!pursetype.refundflag)
	{
		//ERRTIP("钱包类型[%d]不允许退款",pursetype.pursetype);
		outPack->lvol0=tCard.cardno;
		outPack->lvol9=D2I(pAccTrans->trans.cardaftbal*100);
		outPack->lvol8=0;
		outPack->lsafe_level2=0;
		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;
		//sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
		sprintf(trans.remark,"小钱包不允许退款");
		des2src(outPack->vsmess,trans.remark);
		return 0;		
	}
	/*
	T_t_cardbalance  cardbalance;
	memset(&cardbalance,0,sizeof(cardbalance));
	ret=DB_t_cardbalance_read_lock_by_c0_and_accno_and_pursetype(tAccount.accno,pursetype.pursetype,&cardbalance);
	if(ret)
	{
		if(DB_NOTFOUND==ret)			// 早期的卡没开小钱包账户
		{
			return E_DB_CARDBALANCE_N;
		}

		else
			return E_DB_CARDBALANCE_R;
	}
	
	if(rPack->lvol2)			//有卡
	{
		trans.cardflag=1;
		trans.usecardflag=1;	
		pAccTrans->SetCardCntAndCardBal(rPack->lvol5,rPack->lvol6,rPack->lvol7);
		trans.aftdpscnt++;
		des2src(trans.cardphyid,rPack->sstation1);
		
		waterbefbal = D4U5(rPack->lsafe_level/100.0);
		trans.inputamt= waterbefbal;	

		if(amtcmp(trans.inputamt,pursetype.pursemaxbal)>0)
			trans.inputamt=pursetype.pursemaxbal;
		
		if(amtcmp(trans.inputamt,cardbalance.balance)>0)
			trans.inputamt=cardbalance.balance;	
	}
	else
	{
		//无卡
		if(amtcmp(cardbalance.cardbal,cardbalance.balance)>0)
			trans.inputamt=cardbalance.balance;
		else		
			trans.inputamt=cardbalance.cardbal;
		
		waterbefbal = trans.inputamt;
		trans.cardflag=1;							// 涉及到计算卡余额,不然退大钱包有问题
		trans.cardbefbal=tAccount.cardbal;				// 大钱包卡余额
		trans.cardaftbal=tAccount.cardbal;
		des2src(trans.custname,tAccount.accname);
		des2src(trans.showcardno,tCard.showcardno);
		des2src(trans.cardaccno,tCard.accno);
	}
	*/	
	//waterbefbal = D4U5(rPack->lsafe_level/100.0);


	if(rPack->lvol2)//有卡
	{
		waterbefbal = D4U5(rPack->lsafe_level/100.0);
	}
	else//无卡
	{
		if(pursetype.refundflag == 1)//无卡退小钱包
		{
			T_t_cardbalance  cardbalance;
			memset(&cardbalance,0,sizeof(cardbalance));
			ret=DB_t_cardbalance_read_lock_by_c0_and_accno_and_pursetype(tAccount.accno,pursetype.pursetype,&cardbalance);
			if(ret)
			{
				if(DB_NOTFOUND==ret)			// 早期的卡没开小钱包账户
				{
					return E_DB_CARDBALANCE_N;
				}
				else
					return E_DB_CARDBALANCE_R;
			}
			
			if(amtcmp(cardbalance.cardbal,cardbalance.balance)>0)
				waterbefbal=cardbalance.balance;
			else		
				waterbefbal=cardbalance.cardbal;

			trans.cardflag=1;							
			trans.cardbefbal=tAccount.cardbal;				// 大钱包卡余额
			trans.cardaftbal=tAccount.cardbal;

			// 更新水控卡余额
			cardbalance.balance = 0;
			cardbalance.cardbal = 0;			
			ret=DB_t_cardbalance_update_lock_by_c0(&cardbalance);
			if(ret)
			{
				return E_DB_CARDBALANCE_U;
			}			
		}
	}


	trans.inputamt= waterbefbal;	
	if(amtcmp(trans.inputamt,pursetype.pursemaxbal)>0)
	{
		//"小钱包余额大于最大钱包余额,只能按最大余额退卡";
		trans.inputamt=pursetype.pursemaxbal;
	}
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(trans.cardbefbal+trans.inputamt,CardMaxBal)>0)
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
	trans.feetype=tCard.feetype;
	trans.custid=tCard.custid;		
	trans.transamt=trans.inputamt;
	trans.unusedamt = trans.inputamt;
	if(pursetype.onlineflag)
	{
		//联机水控退款
		pAccTrans->trans.transtype=TRANSTYPE_WATERREFUND;
		ret=pAccTrans->DoTransByTransType();
		if(ret)
			return ret;	
		ret=pAccTrans->doTransEnd();
		if(ret)
			return ret;
	}
	else
	{
		if(pursetype.shopid<1)
		{
			ERRTIP("钱包类型[%d]没有设置对应的水控商户",pursetype.pursetype);
			return E_COMMON_ERR;
		}
		//否则脱机水控
		int shoptype=0;
		char shopstatus[2]={0};
		ret=ShopAccReadbyShopid(pursetype.shopid,trans.shopaccno,&shoptype,shopstatus);
		if(ret)
		{
			writelog(LOG_ERR,"shopid[%d]",pursetype.shopid);
			return ret;
		}
		if(shopstatus[0]!=STATUS_NORMAL)
			return ERRIF_SHOP_CLOSE;
		if(shoptype!=SHOPTYPE_COSUMESHOP)
			return ERRIF_SHOP_TYPE;
		pAccTrans->trans.transtype=TRANSTYPE_SHOPREFUND;
		ret=pAccTrans->DoTransByTransType();
		if(ret)
			return ret;	
		ret=pAccTrans->doTransEnd();
		if(ret)
			return ret;
	}
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));
	des2src(transdtl.refno,trans.refno);
	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.cardno=trans.cardno;
	transdtl.purseno=trans.purseno;
	transdtl.transflag= TF_DPS;
	transdtl.cardcnt=trans.aftdpscnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.cardaftbal=trans.cardaftbal;
    	transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.custid=trans.custid;
	des2src(transdtl.custname,trans.custname);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
    	des2src(transdtl.showcardno,trans.showcardno);
	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;
	}		
	T_t_pursetransdtl pursetransdtl;
	memset(&pursetransdtl,0,sizeof(pursetransdtl));
	des2src(pursetransdtl.refno,transdtl.refno);
	des2src(pursetransdtl.transdate,transdtl.transdate);
	des2src(pursetransdtl.transtime,transdtl.transtime);
	strcpy(pursetransdtl.accdate,transdtl.accdate);
	strcpy(pursetransdtl.acctime,transdtl.acctime);
	pursetransdtl.termid=transdtl.termid;
	pursetransdtl.termseqno=transdtl.termseqno;
	pursetransdtl.transcode=transdtl.transcode;
	pursetransdtl.cardno=transdtl.cardno;
	pursetransdtl.pursetype=pursetype.pursetype;
	pursetransdtl.transflag= TF_PAY;
	pursetransdtl.cardcnt=0;
	pursetransdtl.cardbefbal=waterbefbal;
	pursetransdtl.cardaftbal=wateraftbal;
	pursetransdtl.amount=transdtl.amount;
	pursetransdtl.custid=transdtl.custid;
	des2src(pursetransdtl.custname,transdtl.custname);
	des2src(pursetransdtl.opercode,transdtl.opercode);
	pursetransdtl.status[0]=transdtl.status[0];
	des2src(pursetransdtl.showcardno,trans.showcardno);
	des2src(pursetransdtl.stuempno,transdtl.stuempno);
	ret=DB_t_pursetransdtl_add(&pursetransdtl);
	if(ret)
	{
	  if(DB_REPEAT==ret)
		return E_DB_PURSETRANSDTL_E;
	  else
		return E_DB_PURSETRANSDTL_I;
	}		
	outPack->lvol0=tCard.cardno;
	outPack->lvol9=D2I(pAccTrans->trans.cardaftbal*100);
	outPack->lvol8=D2I(pAccTrans->trans.totaltransamt*100);
	//outPack->lsafe_level=D2I(wateraftbal*100);
	outPack->lsafe_level2=0;
	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;
	sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
	des2src(outPack->vsmess,trans.remark);
	return 0;
}
Exemple #12
0
int F849003(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret =0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	ret=pAccTrans->CheckCfgUpdate();
	if(ret)
		return ret;
	T_t_authcard 	tAuthCard;
	T_t_transdtl 	transdtl;
	T_t_dpsoper   	tDepositOper;
	T_t_dpsoperpos 	tDepositOperpos;
	T_t_dpsshoppos 	tDepositShoppos;
	T_t_shop 		tDepositShop;
	T_t_account	tAccount;		//帐户表

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

	memset(&tAuthCard,0,sizeof(tAuthCard));
	memset(&tDepositOper,0,sizeof(tDepositOper));
	memset(&tDepositOperpos,0,sizeof(tDepositOperpos));
	memset(&tDepositShoppos,0,sizeof(tDepositShoppos));
	memset(&tDepositShop,0,sizeof(tDepositShop));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&transdtl,0,sizeof(transdtl));
	int opercardno=rPack->lvol3;			//操作员号
	if(!opercardno)
		return E_INPUTNULL_CARDNO;
	trans.cardflag=1;
	trans.usecardflag=1;	
	trans.cardno=rPack->lvol5;
	trans.purseno=PURSE_NO_ONE;
	trans.cardbefbal=rPack->lvol9/100.0;			//入卡金额
	trans.cardaftbal=trans.cardbefbal;				
	trans.dpscnt= rPack->lvol7;					//入卡金额
	trans.inputamt= rPack->lvol8/100.0;			//充值金额	
	trans.unusedamt = trans.inputamt;
	trans.fundtype=1;

	ret=IsWaterExceptCard(trans.cardno);
	if(ret)
	{
		ERRTIP("卡号[%d]水控余额异常,充值功能暂停使用,请联系一卡通管理中心处理!!!",trans.cardno);
		return	ERRIF_CARDACC_EXCEPT;
	}
	
	T_t_card tCard;
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(trans,tCard);
	if(ret)
	{
		return ret;
	}
	trans.feetype=tCard.feetype;
	trans.cardtype=tCard.cardtype;
//	ret=UpdateCardBitmap(trans.cardno,trans.cardcnt,CARDBITMAPTYPE_INC,0);
//	if(ret)
//		return ret;
	transdtl.sysid= rPack->lcert_code;						//上传工作站标识(前置机注册号)
	des2src(transdtl.devphyid, rPack->sphone3);		//物理设备ID
	transdtl.devseqno=rPack->lvol4;					//上传端流水号
	// 读取操作员号
	ret = DB_t_authcard_read_by_cardno(opercardno,&tAuthCard);
	if(ret)
	{
		writelog(LOG_ERR,"get operator code from auth card error, auth_card_id[%d]",opercardno);
		if(DB_NOTFOUND == ret)
			 return E_DB_AUTHCARD_N;
		else
			 return  E_DB_OPERATOR_R;
	}
	if(tAuthCard.status[0]!=STATUS_NORMAL)
	{
		return E_OPERLOGON_UNREG;
	}
	des2src(trans.opercode,tAuthCard.opercode);
	ret=GetDevIdByDevPhyId(&(trans.termid),transdtl.devphyid);
	if (ret)
	{
		writelog(LOG_ERR,"GetDevIdByDevPhyId err[%d] devphy999_id[%s]",ret,transdtl.devphyid);
		return ret;
	}
	ret=DB_t_dpsoper_read_lock_by_c0_and_opercode(trans.opercode,&tDepositOper);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_DEPOSITOPER_R;
		else
			return E_DB_DEPOSITOPER_N;
	}
	if(tDepositOper.status[0]!=STATUS_NORMAL)
	{
		DB_t_dpsoper_free_lock_by_c0();
		return E_DEPOSITOPER_STOP;
	}
	//判断是否是重复交易
	if(tDepositOper.lastdevseqno==transdtl.devseqno)
	{
		DB_t_dpsoper_free_lock_by_c0();
		ret=DB_t_transdtl_read_by_accdate_and_termid_and_devseqno(trans.accdate,trans.termid,tDepositOper.lastdevseqno,&transdtl);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				return E_DB_TRANSDTL_N;
			else
				return E_DB_TRANSDTL_R;
		}
		//if(transdtl.revflag[0]=='1')
		//	return E_TRANSDTL_REV;
		ResetNormalCPack(&aPack,0,1);
		SetCol(handle,0);
		SetCol(handle,F_LVOL5,F_LVOL10,F_LCERT_CODE,0);

		out_pack->lvol5 = transdtl.cardno;
		out_pack->lvol10 = (int)D4U5(transdtl.cardaftbal*100,0);
		out_pack->lcert_code = transdtl.termseqno;
		writelog(LOG_INFO,"该交易已成功,卡号[%d]充值金额[%.2lf]卡余额[%.2lf]",transdtl.cardno,transdtl.amount,transdtl.cardaftbal);
		PutRow(handle,out_pack,pRetCode,szMsg);
		return 0;		
	}
	if(strncmp(tDepositOper.lasttransdate,trans.transdate,8)!=0)
	{
		des2src(tDepositOper.lasttransdate,trans.transdate);
		tDepositOper.depositcnt=0;
		tDepositOper.depositamt=0;
	}
	tDepositOper.depositcnt++;
	tDepositOper.depositamt+=trans.inputamt;
	tDepositOper.lastdevseqno=transdtl.devseqno;
	des2src(tDepositOper.lastdevphyid,transdtl.devphyid);
	des2src(tDepositOper.lastsaved,trans.sysdatetime);
	if(amtcmp(tDepositOper.maxdepositamt,0)>0)
	{
		DB_t_dpsoper_free_lock_by_c0();
		if(amtcmp(tDepositOper.depositamt,tDepositOper.maxdepositamt)>0)
		{
			return E_OPER_OVER_MAX_DEPOSIT_AMT;
		}
	}
	ret=DB_t_dpsoper_update_lock_by_c0(&tDepositOper);
	if(ret)
	{
			return E_DB_DEPOSITOPER_U;
	}
	if('1'==tDepositOper.shopoperflag[0])
	{
		ret=DB_t_dpsshoppos_read_by_deviceid(trans.termid, &tDepositShoppos);

		if(ret)
		{
			if(DB_NOTFOUND==ret)
			{
				writelog(LOG_INFO,"PosDeposit termid[%d] ",trans.termid);
				return E_DB_DEPOSITSHOPPOS_N;
			}
			else
			{
				return E_DB_DEPOSITSHOPPOS_R;
			}
		}
		ret=DB_t_shop_read_by_shopid(tDepositShoppos.shopid, &tDepositShop);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				return ERRINFO(E_NOTEXIST_SHOPID,tDepositShoppos.shopid);
			else
				return E_DB_SHOP_R;
		}
		if(tDepositShop.status[0]!=STATUS_NORMAL)
		{
			return ERRINFO(E_SHOP_LOGOUT,tDepositShop.shopid);
		}
		trans.transcode = TC_SHOPPOSDEPOSIT;
		des2src(trans.shopaccno,tDepositShop.accno);		
		writelog(LOG_INFO,"充值商户充值");
	}
	else
	{
		ret=DB_t_dpsshoppos_read_by_deviceid(trans.termid, &tDepositShoppos);

		if(ret)
		{
			if(DB_NOTFOUND!=ret)
			{
				writelog(LOG_INFO,"PosDeposit termid[%d] ",trans.termid);
				return E_DB_DEPOSITSHOPPOS_R;
			}
		}
		else
		{
			ERRTIP("设备号[%d]属于属于充值商户,非充值商户操作员不能使用该设备",trans.termid);
			return E_COMMON_ERR;

		}
		trans.transcode = TC_POSDEPOSIT;
	}
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;
	//根据卡号和钱包号得到消费者账号(借方)
	ret=DB_t_account_read_by_accno(tCard.accno,&tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_account_read_by_accno ret[%d]cardno[%d]accno[%s]",ret,trans.cardno,tCard.accno);
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_ACCNO,tCard.accno);
		else
			return E_DB_ACCOUNT_R;
	}
	if(tAccount.lastdpscnt>trans.dpscnt)
	{
		return ERRINFO(E_CARDCNT_LT_LASTCARDCNT,trans.dpscnt,tAccount.lastdpscnt);
	}
//	double CardMaxBal=0;
//	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
//	if(ret)
//		return ret;
//	if(amtcmp(trans.inputamt+trans.cardbefbal,CardMaxBal)>0)
//		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
	trans.custid=tCard.custid;
	des2src(trans.cardaccno,tAccount.accno);
	ret=pAccTrans->doTrans();
	if(ret)
		return ret;
	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.transflag=TF_DPS;
	transdtl.cardcnt=trans.dpscnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.custid=trans.custid;
    transdtl.showcardno=atol(tCard.showcardno);
	des2src(transdtl.custname,tAccount.accname);
	des2src(transdtl.opercode,trans.opercode);
	GetStuempnoByCustid(transdtl.custid,transdtl.stuempno);	
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
		if(DB_REPEAT==ret)
			return E_DB_TRANSDTL_E;
		else
			return E_DB_TRANSDTL_I;
	} 	
	sprintf(trans.remark,"卡号%d 充值前卡余额:%.2lf元 卡当前余额:%.2lf元",trans.cardno,trans.cardbefbal,trans.cardaftbal);
	writelog(LOG_INFO,trans.remark);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL5,F_LVOL10,F_LCERT_CODE,0);

	out_pack->lvol5 = trans.cardno;
	out_pack->lvol10 = (int)D4U5(trans.cardaftbal*100,0);
	out_pack->lcert_code = trans.termseqno;
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
}
Exemple #13
0
int F240002(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	pAccTrans->trans.transcode=TC_BANKTRANS;
	TRANS& trans=pAccTrans->trans;
	trans.termid=atoi(rPack->sorder2);
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;			
	trans.inputamt = rPack->lvol5/100.0;
	trans.unusedamt=trans.inputamt;
	trans.cardflag=1;
	trans.usecardflag=1;
	trans.cardbefbal=rPack->lvol6/100.00;
	trans.dpscnt=rPack->lvol1+1;
	trans.cardaftbal=trans.cardbefbal;
	//转账不允许转小数金额
	if((rPack->lvol5)%100>0)
	{
		writelog(LOG_ERR,"trans money is not a integer!,transmoney=[%f]",rPack->lvol5/100.0);
		strcpy(szMsg,"转账金额必须是整数");
		return E_TRANS_TRANSMONEY_OUTRANGE;
	}
	if(rPack->lvol5<1)
	{
		writelog(LOG_ERR,"trans money is not a integer!,transmoney=[%f]",rPack->lvol5/100.0);
		strcpy(szMsg,"转账金额不能为0");
		return E_TRANS_TRANSMONEY_OUTRANGE;
	}
	T_t_account		tAccount;		//帐户表
	T_t_card		card;

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


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


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


	//判断设备是否登陆
	if(0!=device_login_yes_or_no(trans.termid))
	{
		writelog(LOG_ERR,"Device don't login");
		return E_TRANS_TERM_NOLOGIN;
	}
	trans.cardno=atoi(rPack->sserial0);
	ret=pAccTrans->CheckAcc(&card,&tAccount);
	if(ret)
		return ret;
	if(amtcmp(trans.cardbefbal-tAccount.balance,MAXAMT_CARDGTACC)>=0)
	{
		writelog(LOG_ERR,"cardbefbal[%.2lf]account balance[%.2lf]",trans.cardbefbal,tAccount.balance);
		return ERRIF_CARDBAL_EXCEPT;
	}		
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(trans.inputamt+trans.cardbefbal,CardMaxBal)>0)
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
	trans.feetype=card.feetype;
	trans.cardtype=card.cardtype;
	trans.custid=card.custid;
	des2src(trans.cardaccno,tAccount.accno);		//贷方帐户,持卡人账户
	des2src(trans.draccno,rPack->sstation0);		//借方帐号,由前置机上传
	ret=pAccTrans->doFeeTrans();
	if(ret)
		return ret;
	ret=pAccTrans->doMainTrans();
	if(ret)
		return ret;
	ret=pAccTrans->doTransEnd();
	if(ret)
		return ret;	
	//业务结束后,回滚事务
	ret=db_rollback();
	if(ret)
	{
		writelog(LOG_ERR,"db_rollback error,error code=[%d]",ret);
		return E_DB_ROLLBACK;
	}
	//重新取流水号
	ret=pAccTrans->GetTermSeqno();
	if(ret)
	{
		writelog(LOG_ERR,"GetTermSeqno error,error code=[%d]",ret);
		return ret;
	}
	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.transflag=TF_DPS;
	transdtl.cardcnt=trans.dpscnt;
	transdtl.cardbefbal=trans.cardbefbal;
    transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.custid=card.custid;
	//transdtl.sysid= rPack->lvol2;
	transdtl.exttype=EXTTYPE_BANKCARD;	
	des2src(transdtl.extdata,rPack->scust_auth);
	des2src(transdtl.showcardno,card.showcardno);
	transdtl.status[0]=DTLSTATUS_FAIL;
	ret=GetNewRefno(transdtl.refno);
	if(ret)
	{
		ERRTIP("取交易参考号失败");
		return ret;
	}		
	GetCustBaseInfoByCustID(card.custid,transdtl.custname,transdtl.stuempno,NULL);
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
	  if(DB_REPEAT==ret)
	    return E_DB_TRANSDTL_E;
	  else
	    return E_DB_TRANSDTL_I;
	}	
	char sMsg[255]="";
	char sDebugMsg[255]="";
	sprintf(sDebugMsg,"流水号:%d ",trans.termseqno);
	sprintf(sMsg,"充值前卡余额:%.2lf 转帐后卡余额:%.2lf ",trans.cardbefbal,trans.cardaftbal);
    strcat(sDebugMsg,sMsg);
	writelog(LOG_DEBUG,sDebugMsg);

	des2src(out_pack->sname2,transdtl.refno);
	out_pack->lserial0=trans.termseqno;
	out_pack->damt0=trans.cardaftbal;
	out_pack->damt1=transdtl.amount;
	out_pack->damt2=transdtl.managefee;
	out_pack->lvol1=transdtl.termseqno;
	out_pack->lvol2=D2I(trans.cardaftbal*100);
	
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
}
static int doReverse(char* oldaccdate,int oldtermid,int oldtermseqno) {
    //查找操作员流水
    int ret=0;
    T_t_card tCard;

    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;
    char transdtlname[61]= {0};
    ret=GetTransdtlTableName(oldaccdate,transdtlname);
    if(ret) {
        writelog(LOG_ERR,"GetTransdtlTableName err");
        return ret;
    }
    T_t_transdtl transdtl;

    ret=ReadTransdtlData(transdtlname,oldaccdate,oldtermid,oldtermseqno,transdtl);
    if(ret) {
        writelog(LOG_ERR,"ReadTransdtlData transdtlname[%s]oldaccdate[%s]oldtermid[%d]oldtermseqno[%d]",transdtlname,oldaccdate,oldtermid,oldtermseqno);
        return ret;
    }
    if('1'==transdtl.revflag[0]) {
        return E_TRANS_REVERSED;
    }
    if(strlen(transdtl.opercode)) {
        if(strcmp(transdtl.opercode,pAccTrans->trans.opercode)!=0) {
            return ERRINFO(E_REVOPER,transdtl.opercode);
        }
    }
    if(trans.cardno!=transdtl.cardno) {
        return E_CARDNO_DIFFER;
    }
    if(transdtl.transcode!=TC_POSDRAW&&
            transdtl.transcode!=TC_POSDRAW&&
            transdtl.transcode!=TC_CARDDRAW&&
            transdtl.transcode!=TC_BUSDRAW&&
            transdtl.transcode!=TC_CARD2CARD&&
            transdtl.transcode!=TC_WATERTRANS&&
            transdtl.transcode!=TC_CARDPAYMENT) {
        return E_TRANSCODE_NOT_DRAW;
    }
    if(transdtl.revflag[0]=='1') {
        /*
        memset(&tCard,0,sizeof(tCard));
        ret=DB_t_card_read_by_cardno(vTransdtl.cardno,&tCard);
        if(ret)
        {
        	writelog(LOG_ERR,"cardno[%d]",vTransdtl.cardno);
        	if(DB_NOTFOUND==ret)
        		return E_DB_CARD_N;
        	else
        		return E_DB_CARD_R;
        }
        */
        pAccTrans->remark="该交易已冲正";
        return E_TRANS_REVERSED;
    }
    ret=UpdateTransdtlHisRevFlag(transdtlname,oldaccdate,oldtermid,oldtermseqno);
    if(ret) {
        writelog(LOG_ERR,"UpdateTransdtlRevFlag ret[%d]accdate[%s]termid[%d]termseqno[%d]",ret,oldaccdate,oldtermid,oldtermseqno);
        return ret;
    }
    memset(&tCard,0,sizeof(tCard));
    ret=DB_t_card_read_by_cardno(transdtl.cardno,&tCard);
    if(ret) {
        writelog(LOG_ERR,"cardno[%d]",transdtl.cardno);
        if(DB_NOTFOUND==ret)
            return E_DB_CARD_N;
        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);
    }
//	ret=UpdateCardBitmap(trans.cardno,trans.cardcnt,CARDBITMAPTYPE_DECREV,0);
//	if(ret)
//		return ret;
    T_t_transdtl transdtlrev;
    memset(&transdtlrev,0,sizeof(transdtlrev));

    des2src(transdtlrev.transdate,trans.transdate);
    des2src(transdtlrev.transtime,trans.transtime);
    des2src(transdtlrev.accdate,trans.accdate);
    strcpy(transdtlrev.acctime,trans.acctime);
    transdtlrev.termid=trans.termid;
    transdtlrev.termseqno=trans.termseqno;
    transdtlrev.transcode=trans.transcode;
    transdtlrev.paytype=0;
    transdtlrev.exttype=transdtl.exttype;
    des2src(transdtlrev.extdata,transdtl.extdata);
    des2src(transdtlrev.refno,transdtl.refno);
    transdtlrev.cardbefbal=trans.cardbefbal;
    transdtlrev.cardno=transdtl.cardno;
    transdtlrev.purseno=transdtl.purseno;
    transdtlrev.transflag=TF_DPS;
    transdtlrev.cardcnt=trans.aftdpscnt;
    transdtlrev.amount=transdtl.amount;
    transdtlrev.managefee=transdtl.managefee;
    transdtlrev.custid=transdtl.custid;
    des2src(transdtlrev.showcardno,transdtl.showcardno);
    des2src(transdtlrev.custname,transdtl.custname);
    des2src(transdtlrev.stuempno,transdtl.stuempno);
    transdtlrev.cardaftbal=transdtlrev.cardbefbal+(transdtl.cardbefbal-transdtl.cardaftbal);
    if(amtcmp(transdtlrev.cardaftbal,0)<0)
        return ERRIF_CARDACC_OVERDRAW;;
    des2src(transdtlrev.opercode,trans.opercode);
    transdtlrev.status[0]=DTLSTATUS_SUCCESS;
    transdtlrev.errcode=0;
    ret=DB_t_transdtl_add(&transdtlrev);
    if(ret) {
        if(DB_REPEAT==ret)
            return E_DB_TRANSDTL_E;
        else
            return E_DB_TRANSDTL_I;
    }
    trans.cardflag=1;
    trans.cardphytype=tCard.cardphytype;
    strcpy(pAccTrans->trans.cardaccno,tCard.accno);
    ret=pAccTrans->doHistoryReverseTrans(oldaccdate,oldtermid,oldtermseqno);
    if(ret)
        return ret;
    trans.cardaftbal=transdtlrev.cardaftbal;
    trans.transamt=transdtlrev.amount;
    return 0;
}
Exemple #15
0
int F846314(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
//	ret=pAccTrans->checkCfgUpdate();
//	if(ret)
//		return ret;
	des2src(pAccTrans->trans.opercode,rPack->semp);
	pAccTrans->trans.transcode=TC_CARDDRAW;
	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);
	trans.cardflag=1;
	trans.usecardflag=1;	
	trans.cardno=rPack->lvol0;	
	trans.purseno=PURSE_NO_ONE;
	trans.paycnt=rPack->lvol6+1;
	trans.cardbefbal=rPack->lvol7/100.0;
	trans.cardaftbal=trans.cardbefbal;
//	trans.fundtype=PAYTYPE_CASH;
	des2src(trans.cardphyid,rPack->sstation0);
	trans.inputamt=rPack->damt0;	
	trans.unusedamt = trans.inputamt;
	if(amtcmp(trans.inputamt,trans.cardbefbal)>0)
	{
		return ERRINFO(E_CARD_BALANCE_SHORTAGE,trans.cardbefbal);
	}
	T_t_card tCard;
	
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(trans,tCard);
	if(ret)
	{
		return ret;
	}
//	ret=UpdateCardBitmap(trans.cardno,trans.cardcnt,CARDBITMAPTYPE_DEC,0);
//	if(ret)
//		return ret;
	T_t_account tCardAccount;	
	memset(&tCardAccount,0,sizeof(tCardAccount));
	ret=DB_t_account_read_by_accno(tCard.accno,&tCardAccount);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",tCard.cardno);
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDACCNO,tCard.accno);
		else
			return E_DB_ACCOUNT_R;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
	}
	if(tCardAccount.lastpaycnt>trans.paycnt)
	{
		return ERRINFO(E_CARDCNT_LT_LASTCARDCNT,trans.paycnt,tCardAccount.lastpaycnt);
	}
	strcpy(trans.cardaccno,tCardAccount.accno);
	trans.feetype=tCard.feetype;
	trans.custid=tCard.custid;
	strcpy(trans.draccno,tCardAccount.accno);
	ret=pAccTrans->doTrans();
	if(ret)
		return ret;
	ret=pAccTrans->doTransEnd();
	if(ret)
		return ret;
	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.transflag =TF_PAY;
	transdtl.cardcnt=trans.paycnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.cardaftbal=trans.cardaftbal;
    transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.custid=tCardAccount.custid;
	des2src(transdtl.custname,tCardAccount.accname);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
    transdtl.showcardno=atol(tCard.showcardno);
	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;
	}		
	SetCol(handle,F_LVOL0,F_LVOL8,F_SDATE0,
		F_SDATE3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,F_STIME3,0);	
	outPack->lvol0=tCard.cardno;
	outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
	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;
    sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
    des2src(outPack->vsmess,trans.remark);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
Exemple #16
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;
}
Exemple #17
0
int F850020(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	pAccTrans->trans.transcode=TC_WATERBALRETURN;
	des2src(pAccTrans->trans.opercode,rPack->semp);
	pAccTrans->trans.termid=rPack->lwithdraw_flag;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;			
    ST_CPACK aPack;
    ST_PACK *outPack = &(aPack.pack);
    memset(&aPack,0,sizeof(aPack));
    ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL2,F_LVOL3,F_LVOL8,F_SDATE0,F_SPHONE3,F_SADDR,F_LVOL5,F_LVOL9,F_LSAFE_LEVEL,F_LSAFE_LEVEL2,
		F_SDATE3,F_STIME3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);
	trans.cardflag=1;
	trans.usecardflag=1;	
	trans.cardno=rPack->lvol0;	
	trans.purseno=PURSE_NO_ONE;
	trans.dpscnt=rPack->lvol5+1;
	trans.cardbefbal=rPack->lvol7/100.0;
	trans.cardaftbal=trans.cardbefbal;
	des2src(trans.cardphyid,rPack->sstation1);
	
	double waterbefbal = D4U5(rPack->lsafe_level/100.0);
	double wateraftbal = 0;
	trans.inputamt= waterbefbal;	

	T_t_pursetype  pursetype;

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

	pursetype.pursetype=rPack->lvol1;
	if(pursetype.pursetype<1)
	{
		ERRTIP("请输入小钱包类型");
		return E_COMMON_ERR;
	}
	ret=DB_t_pursetype_read_by_pursetype(pursetype.pursetype,&pursetype);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
		{	
			ERRTIP("钱包类型[%d]不存在",pursetype.pursetype);
			return E_COMMON_ERR;
		}
		else
			return E_DB_PURSETYPE_R;
	}
	if(!pursetype.enableflag)
	{
		ERRTIP("钱包类型[%d]未启用",pursetype.pursetype);
		return E_COMMON_ERR;
	}
	if(!pursetype.refundflag)
	{
		ERRTIP("钱包类型[%d]不允许退款",pursetype.pursetype);
		return E_COMMON_ERR;		
	}
	if(amtcmp(trans.inputamt,pursetype.pursemaxbal)>0)
		trans.inputamt=pursetype.pursemaxbal;
	T_t_card  tCard;
	memset(&tCard,0,sizeof(tCard));

	T_t_account tAccount;
	memset(&tAccount,0,sizeof(tAccount));
	
	ret=pAccTrans->CheckAcc(&tCard,&tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"检查状态失败");
		return ret;
	}
	T_t_cardbalance  cardbalance;
	memset(&cardbalance,0,sizeof(cardbalance));
	ret=DB_t_cardbalance_read_lock_by_c0_and_accno_and_pursetype(tAccount.accno,pursetype.pursetype,&cardbalance);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_CARDBALANCE_N;
		else
			return E_DB_CARDBALANCE_R;
	}
	if(rPack->lvol2)
	{
		//有卡
		if(amtcmp(trans.inputamt,cardbalance.balance)>0)
			trans.inputamt=cardbalance.balance;	
	}
	else
	{
		//无卡
		if(amtcmp(cardbalance.cardbal,cardbalance.balance)>0)
			trans.inputamt=cardbalance.balance;
		else		
			trans.inputamt=cardbalance.cardbal;
	}
	cardbalance.balance =D4U5(cardbalance.balance - trans.inputamt);
	cardbalance.cardbal=0;	
//	cardbalance.paycnt;
	if(rPack->lvol4)
		cardbalance.paycnt = rPack->lvol4-1;
	des2src(cardbalance.transdate,trans.transdate);
	des2src(cardbalance.transtime,trans.transtime);
	ret=DB_t_cardbalance_update_lock_by_c0(&cardbalance);
	if(ret)
	{
		return E_DB_CARDBITMAP_U;
	}
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(trans.cardbefbal+rPack->lsafe_level,CardMaxBal)>0)
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
		
	trans.feetype=tCard.feetype;
	trans.custid=tCard.custid;		
	trans.transamt=trans.inputamt;
	trans.unusedamt = trans.inputamt;
	if(pursetype.onlineflag)
	{
		//联机水控退款
		pAccTrans->trans.transtype=TRANSTYPE_WATERREFUND;
		ret=pAccTrans->DoTransByTransType();
		if(ret)
			return ret;	
		ret=pAccTrans->doTransEnd();
		if(ret)
			return ret;
	}
	else
	{
		if(pursetype.shopid<1)
		{
			ERRTIP("钱包类型[%d]没有设置对应的水控商户",pursetype.pursetype);
			return E_COMMON_ERR;
		}
		//否则脱机水控
		int shoptype=0;
		char shopstatus[2]={0};
		ret=ShopAccReadbyShopid(pursetype.shopid,trans.shopaccno,&shoptype,shopstatus);
		if(ret)
		{
			writelog(LOG_ERR,"shopid[%d]",pursetype.shopid);
			return ret;
		}
		if(shopstatus[0]!=STATUS_NORMAL)
			return ERRIF_SHOP_CLOSE;
		if(shoptype!=SHOPTYPE_COSUMESHOP)
			return ERRIF_SHOP_TYPE;
		pAccTrans->trans.transtype=TRANSTYPE_SHOPREFUND;
		ret=pAccTrans->DoTransByTransType();
		if(ret)
			return ret;	
		ret=pAccTrans->doTransEnd();
		if(ret)
			return ret;
	}
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));
	des2src(transdtl.refno,trans.refno);
	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.cardno=trans.cardno;
	transdtl.purseno=trans.purseno;
	transdtl.transflag= TF_DPS;
	transdtl.cardcnt=trans.dpscnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.cardaftbal=trans.cardaftbal;
    transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.custid=trans.custid;
	des2src(transdtl.custname,trans.custname);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
    des2src(transdtl.showcardno,trans.showcardno);
	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;
	}		
	T_t_pursetransdtl pursetransdtl;
	memset(&pursetransdtl,0,sizeof(pursetransdtl));
	des2src(pursetransdtl.refno,transdtl.refno);
	des2src(pursetransdtl.transdate,transdtl.transdate);
	des2src(pursetransdtl.transtime,transdtl.transtime);
	strcpy(pursetransdtl.accdate,transdtl.accdate);
	strcpy(pursetransdtl.acctime,transdtl.acctime);
	pursetransdtl.termid=transdtl.termid;
	pursetransdtl.termseqno=transdtl.termseqno;
	pursetransdtl.transcode=transdtl.transcode;
	pursetransdtl.cardno=transdtl.cardno;
	pursetransdtl.pursetype=pursetype.pursetype;
	pursetransdtl.transflag= TF_PAY;
	pursetransdtl.cardcnt=cardbalance.paycnt;
	pursetransdtl.cardbefbal=waterbefbal;
	pursetransdtl.cardaftbal=wateraftbal;
	pursetransdtl.amount=transdtl.amount;
	pursetransdtl.custid=transdtl.custid;
	des2src(pursetransdtl.custname,transdtl.custname);
	des2src(pursetransdtl.opercode,transdtl.opercode);
	pursetransdtl.status[0]=transdtl.status[0];
	des2src(pursetransdtl.showcardno,trans.showcardno);
	des2src(pursetransdtl.stuempno,transdtl.stuempno);
	ret=DB_t_pursetransdtl_add(&pursetransdtl);
	if(ret)
	{
	  if(DB_REPEAT==ret)
		return E_DB_PURSETRANSDTL_E;
	  else
		return E_DB_PURSETRANSDTL_I;
	}		
	outPack->lvol0=tCard.cardno;
	outPack->lvol9=D4U5(pAccTrans->trans.cardaftbal*100,0);
	outPack->lvol8=D4U5(pAccTrans->trans.totaltransamt*100,0);
	outPack->lsafe_level=D4U5(wateraftbal*100,0);
	outPack->lsafe_level2=0;
	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;
    sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
    des2src(outPack->vsmess,trans.remark);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
Exemple #18
0
int F240020(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{

	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	pAccTrans->trans.transcode=TC_BANKTRANS;
	TRANS& trans=pAccTrans->trans;
	trans.termid=rPack->lcert_code;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;			
	trans.inputamt = rPack->lvol5/100.0;
	trans.unusedamt=trans.inputamt;
	trans.cardflag=1;
	trans.usecardflag=1;
	trans.cardbefbal=rPack->lvol6/100.00;
	trans.dpscnt=rPack->lvol1+1;	//充值次数
	trans.cardaftbal=trans.cardbefbal;
	//转账不允许转小数金额
	if((rPack->lvol5)%100>0)
	{
		writelog(LOG_ERR,"trans money is not a integer!,transmoney=[%f]",rPack->lvol5/100.0);
		strcpy(szMsg,"转账金额必须是整数");
		return E_TRANS_TRANSMONEY_OUTRANGE;
	}
	if(rPack->lvol5<1)
	{
		writelog(LOG_ERR,"trans money is not a integer!,transmoney=[%f]",rPack->lvol5/100.0);
		strcpy(szMsg,"转账金额不能为0");
		return E_TRANS_TRANSMONEY_OUTRANGE;
	}
	T_t_account		tAccount;		//帐户表
	T_t_card		card;
	T_t_bankcard 	bankcard;
	T_t_cfgbank     cfgbank;
	T_t_device device;
	
	memset(&cfgbank,0,sizeof cfgbank);
	memset(&tAccount,0,sizeof(tAccount));
	memset(&card,0,sizeof(card));
	memset(&bankcard,0,sizeof(bankcard));
	memset(&device,0,sizeof device);

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


	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_SCUST_AUTH,F_SNAME,F_SNAME2,F_LSERIAL0,F_STX_PWD,F_LVOL5,F_LVOL6,0);


	/*判断设备是否登陆
	if(0!=device_login_yes_or_no(trans.termid))
	{
		writelog(LOG_ERR,"Device don't login");
		return E_TRANS_TERM_NOLOGIN;
	}
	*/
	
	/*
	char buffer[16]="";
	//判断是否处于日终结算状态
 	ret=GetSysParaVal(GLOBE_FLAG_BALANCE,buffer);
	if(ret)
	{
		writelog(LOG_ERR,"GetSysParaVal error,errcode=[%d]",ret);
		return E_TRANS_UNKNOW_ERROR;
	}
	else if(strncmp(buffer,"0",1)!=0)
	{
		writelog(LOG_ERR,"System is balance now!");
		return E_TRANS_BANK_SERVICE_NOEXIT;
	}
	*/

	ret=DB_t_device_read_by_deviceid(trans.termid, &device);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_device_read_by_deviceid err,errcode=[%d],device_id=[%d]",ret,trans.termid);
		return E_DB_DEVICE_R;
	}
		
	trans.cardno=rPack->lvol0;
	ret=pAccTrans->CheckAcc(&card,&tAccount);
	if(ret)
		return ret;
	if(amtcmp(trans.cardbefbal-tAccount.balance,MAXAMT_CARDGTACC)>=0)
	{
		writelog(LOG_ERR,"cardbefbal[%.2lf]account balance[%.2lf]",trans.cardbefbal,tAccount.balance);
		return ERRIF_CARDBAL_EXCEPT;
	}
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(trans.inputamt+trans.cardbefbal,CardMaxBal)>0)
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);

	trans.feetype=card.feetype;
	trans.cardtype=card.cardtype;
	trans.custid=card.custid;
//	if(tAccount.lastdpscnt>trans.dpscnt)
//	{
//		return ERRINFO(E_CARDCNT_LT_LASTCARDCNT,trans.dpscnt,tAccount.lastdpscnt);
//	}

	//校验绑定关系
	ret = DB_t_bankcard_read_by_custid(card.custid, &bankcard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
		{
			strcpy(szMsg,"学工号和银行卡号未绑定");
			return E_DB_BANKCARD_N;
		}
		else
		{
			return E_DB_BANKCARD_R;
		}
	}
	
	ret = DB_t_cfgbank_read_by_bankcode(bankcard.bankcode,&cfgbank);
	if(ret)
	{
		return E_DB_CFGBANK_R;
	}
	
	if(strncmp(trans.acctime,cfgbank.bankstarttime,6) < 0
		|| strncmp(trans.acctime,cfgbank.bankendtime,6) > 0)
	{
		return E_OUT_BANKTIME;
	}

	//取流水号
	ret=pAccTrans->GetTermSeqno();
	if(ret)
	{
		writelog(LOG_ERR,"GetTermSeqno error,error code=[%d]",ret);
		return ret;
	}

	T_t_refno tRefno;

	memset(&tRefno,0,sizeof(tRefno));
	
	get_random(tRefno.mac);

	ret= GetNewRefno(tRefno.refno);
	if(ret)
		return ret;
	des2src(tRefno.lastsaved,trans.sysdatetime);
	des2src(tRefno.accdate,trans.transdate);
	tRefno.termid = trans.termid;
	tRefno.termseqno = trans.termseqno;
	ret=DB_t_refno_add(&tRefno);
	if(ret)
	{
		if(DB_REPEAT==ret)
			return E_DB_REFNO_E;
		else
			return E_DB_REFNO_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.cardno=trans.cardno;
	transdtl.purseno=trans.purseno;
	transdtl.transflag = TF_DPS;
	transdtl.cardcnt=trans.dpscnt;
	transdtl.cardbefbal=trans.cardbefbal;
    transdtl.amount=trans.inputamt;
	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.custid=tAccount.custid;
	//transdtl.sysid= rPack->lvol2;
	transdtl.exttype=EXTTYPE_BANKCARD;
	des2src(transdtl.extdata,bankcard.bankcardno);
	des2src(transdtl.showcardno,card.showcardno);
	transdtl.status[0]=DTLSTATUS_INIT;
	des2src(transdtl.refno,tRefno.refno);
	des2src(transdtl.devphyid,device.devphyid);
	GetCustBaseInfoByCustID(card.custid,transdtl.custname,transdtl.stuempno,NULL);
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
	  if(DB_REPEAT==ret)
	    return E_DB_TRANSDTL_E;
	  else
	    return E_DB_TRANSDTL_I;
	}	
	des2src(out_pack->scust_auth,bankcard.bankcardno);					// 银行卡号
	des2src(out_pack->sname,transdtl.stuempno);							// 学工号
	des2src(out_pack->sname2,transdtl.refno);							// 交易参考号
	des2src(out_pack->stx_pwd,tRefno.mac);								// 随机数
	out_pack->lserial0=trans.termseqno;									// 终端流水号
	out_pack->lvol5 = D2I(trans.inputamt*100);									// 交易金额 (分)
	out_pack->lvol6 = D2I(trans.cardbefbal*100);									// 入卡值(分)

	writelog(LOG_INFO,"bankcardno[%s],stuempno[%s],refno[%s],termseqno[%d],inputamt[%d],befbal[%d]",out_pack->scust_auth,
		out_pack->sname,out_pack->sname2,out_pack->lserial0,out_pack->lvol5,out_pack->lvol6);
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
}
Exemple #19
0
int F843343(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
    int ret=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
    des2src(pAccTrans->trans.opercode,rPack->scust_limit);
    pAccTrans->trans.transcode=TC_SHOPCARDOPEN;
    ret=pAccTrans->InitTrans();
    if (ret)
        return ret;
    TRANS& trans=pAccTrans->trans;

    T_t_shop tShop;
	T_t_shopcard  tShopCard;

	memset(&tShop,0,sizeof(tShop));
	memset(&tShopCard,0,sizeof(tShopCard));
	
    ret=DoCheck(rPack,tShopCard,tShop);
    if (ret)
        return ret;
    ret=DoUpdate(tShopCard);
    if (ret)
        return ret;
    T_t_transdtl transdtl;
    memset(&transdtl,0,sizeof(transdtl));

    transdtl.purseno=trans.purseno;
    transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
    transdtl.paytype=trans.fundtype;
    des2src(transdtl.voucherno,trans.voucherno);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    transdtl.revflag[0]='0';
    transdtl.errcode=0;
    transdtl.custid=trans.custid;
    strcpy(transdtl.custname,tShop.shopname);
    strcpy(transdtl.transdate,trans.transdate);
    strcpy(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;
    des2src(transdtl.opercode,trans.opercode);
    transdtl.cardno=tShopCard.cardno;
    transdtl.cardbefbal=trans.cardbefbal;
    transdtl.cardaftbal=trans.cardaftbal;
    des2src(transdtl.showcardno,tShopCard.showcardno);
    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);
    memset(&aPack,0,sizeof(aPack));
    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_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,F_LVOL10,F_LVOL11,
				0);

	outPack->lvol10=SHOPCARDTYPE;							//卡类型
	outPack->lvol11=tShopCard.shopid;						//商户号
	outPack->lvol0 = tShopCard.cardno;						//交易卡号
	outPack->lvol1 = CUSTTYPE_SHOP;							//客户类别
	outPack->lvol5 = SHOPFEETYPE;							//收费类别
	des2src(outPack->scust_no,tShopCard.showcardno);		//显示卡号
	des2src(outPack->scust_no2,tShop.deptcode);				//部门号
	des2src(outPack->scert_no,tShop.idno);					//身份证号
	des2src(outPack->sname,tShop.shopname);					//客户姓名
	des2src(outPack->sopen_emp,trans.cardpwd);				//卡密码
	des2src(outPack->sdate0,tShopCard.expiredate); 			//有效截至日期
	strcpy(outPack->sorder0,CARD_STRUCT_VERSION);			//制卡版本号
	strcpy(outPack->sorder1,CARD_REGISTER_PUBLISH_CODE);	//发卡注册标识号
	strcpy(outPack->sorder2,CARD_REGISTER_SERVICE_CODE);	//服务注册标识号
	sprintf(outPack->sholder_ac_no,"%d",tShop.shopid); 		//商户号
	des2src(outPack->sstat_type,tShop.idtype); 				//证件类型
	des2src(outPack->sbranch_code0,tShop.areacode);		//院校代码
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
Exemple #20
0
static int doReverse(char* oldaccdate,int oldtermid,int oldtermseqno)
{
	//查找操作员流水
	int ret=0;
	T_t_card tCard;
	
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));
	ret=DB_t_transdtl_read_lock_by_c0_and_accdate_and_termid_and_termseqno(oldaccdate,oldtermid,oldtermseqno,&transdtl);
	if(ret)
	{
	    if(DB_NOTFOUND==ret)
	        return E_DB_TRANSDTL_N;
	    else
	        return E_DB_TRANSDTL_R;
	}	
	if(trans.cardno!=transdtl.cardno)
	{
		DB_t_transdtl_free_lock_by_c0();
		return E_CARDNO_DIFFER;
	}
	if(transdtl.transcode!=TC_POSDEPOSIT&&
		transdtl.transcode!=TC_POSDEPOSITREV&&
		transdtl.transcode!=TC_SHOPPOSDEPOSIT&&
		transdtl.transcode!=TC_SHOPPOSDEPOSITREV&&
		transdtl.transcode!=TC_CARDDEPOSIT&&
		transdtl.transcode!=TC_CARDDEPOSITREV)
	{
		DB_t_transdtl_free_lock_by_c0();
		return E_TRANSCODE_NOT_SAVING;
	}
	if(transdtl.revflag[0]=='1')
	{
		DB_t_transdtl_free_lock_by_c0();

		memset(&tCard,0,sizeof(tCard));
		ret=DB_t_card_read_by_cardno(transdtl.cardno,&tCard);
		if(ret)
		{
			writelog(LOG_ERR,"cardno[%d]",transdtl.cardno);
			if(DB_NOTFOUND==ret)
				return E_DB_CARD_N;
			else 
				return E_DB_CARD_R;
		}		
		//pAccTrans->remark="该交易已冲正";
		//strcpy(cardphyid,tCard.cardphyid);
		return E_TRANS_REVERSED;
	}
	transdtl.revflag[0]='1';
	ret=DB_t_transdtl_update_lock_by_c0(&transdtl);
	if(ret)
	{
	    return E_DB_TRANSDTL_U;
	}	
	memset(&tCard,0,sizeof(tCard));
	ret=DB_t_card_read_lock_by_cur_and_cardno(transdtl.cardno,&tCard);
	if(ret)
	{
		writelog(LOG_ERR,"cardno[%d]",transdtl.cardno);
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDNO,transdtl.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,transdtl.cardno);
	}	
	if('1'==tCard.frozeflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_FREEZE,transdtl.cardno);
	}
	if('1'==tCard.lossflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_LOST,transdtl.cardno);
	}	
	if('1'==tCard.badflag[0])
	{
		DB_t_card_free_lock_by_cur();
		return ERRINFO(E_CARD_BADRECORD,transdtl.cardno);
	}	
//	strcpy(cardphyid,tCard.cardphyid);
	getfmtsysdatetime(tCard.lastsaved);
	ret=DB_t_card_update_lock_by_cur(&tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_CARDNO,transdtl.cardno);
		else 
			return E_DB_CARD_U;
	}	
	ret=UpdateCardBitmap(trans.cardno,trans.cardcnt,CARDBITMAPTYPE_INCREV,0);
	if(ret)
		return ret;
	T_t_transdtl transdtlrev;
	memset(&transdtlrev,0,sizeof(transdtlrev));

	des2src(transdtlrev.transdate,trans.transdate);
	des2src(transdtlrev.transtime,trans.transtime);
	des2src(transdtlrev.accdate,pAccTrans->trans.sysdate);
	strcpy(transdtlrev.acctime,trans.systime);
	transdtlrev.termid=trans.termid;
	transdtlrev.termseqno=trans.termseqno;
	transdtlrev.transcode=trans.transcode;
	transdtlrev.paytype=0;
	transdtlrev.cardno=transdtl.cardno;
	transdtlrev.purseno=transdtl.purseno;
	transdtlrev.cardcnt=trans.cardcnt;
	transdtlrev.cardbefbal=trans.cardbefbal;
	transdtlrev.amount = -transdtl.amount;
	transdtlrev.managefee= -transdtl.managefee;
	transdtlrev.custid=transdtl.custid;
	des2src(transdtlrev.custname,transdtl.custname);
	if(TC_POSDEPOSITREV==transdtl.transcode||
	   TC_SHOPPOSDEPOSITREV==transdtl.transcode)
		transdtlrev.cardaftbal=transdtlrev.cardbefbal+(transdtl.cardbefbal-transdtl.cardaftbal);
	else
		transdtlrev.cardaftbal=transdtlrev.cardbefbal-(transdtl.cardaftbal-transdtl.cardbefbal);	
	if(amtcmp(transdtlrev.cardaftbal,0)<0)
		return ERRINFO(E_CARD_BALANCE_SHORTAGE,transdtlrev.cardaftbal);
	des2src(transdtlrev.opercode,trans.opercode);
	transdtlrev.status[0]=DTLSTATUS_SUCCESS;
	transdtlrev.errcode=0;
	ret=DB_t_transdtl_add(&transdtlrev);
	if(ret)
	{
	  if(DB_REPEAT==ret)
	    return E_DB_TRANSDTL_E;
	  else
	    return E_DB_TRANSDTL_I;
	}		
	ret=pAccTrans->doReverseTrans(oldaccdate,oldtermid,oldtermseqno);	
	if(ret)
		return ret;
	trans.cardaftbal=transdtlrev.cardaftbal;
	trans.transamt=transdtlrev.amount;
	return 0;
}
Exemple #21
0
//联机冲正,当日即时冲正
static int doTransRev(char *oldaccdate, int oldtermid, int oldtermseqno)
{
    int ret = 0;
    CAccTrans *pAccTrans = CAccTrans::getInstance();
    TRANS& trans = pAccTrans->trans;

    T_t_transdtl transdtl;
    memset(&transdtl, 0, sizeof(transdtl));
    ret = DB_t_transdtl_read_lock_by_c0_and_accdate_and_termid_and_termseqno(oldaccdate, oldtermid, oldtermseqno, &transdtl);
    if(ret)
    {
        writelog(LOG_ERR, "ret[%d]accdate[%s]termid[%d]termseqno[%d]", ret, oldaccdate, oldtermid, oldtermseqno);
        if(DB_NOTFOUND == ret)
            return E_DB_TRANSDTL_N;
        else
            return E_DB_TRANSDTL_R;
    }
    if('1' == transdtl.revflag[0])
    {
        DB_t_transdtl_free_lock_by_c0();
        pAccTrans->remark = "该交易已冲正";
        return 0;
    }
    transdtl.revflag[0] = '1';
    ret = DB_t_transdtl_update_lock_by_c0(&transdtl);
    if(ret)
    {
        writelog(LOG_ERR, "UpdateTransdtlRevFlag ret[%d]accdate[%s]termid[%d]termseqno[%d]", ret, oldaccdate, oldtermid, oldtermseqno);
        return ret;
    }
    if(transdtl.cardcnt > 0 && transdtl.cardno > 0)
    {
        if(TF_PAY == transdtl.transflag)
        {
            ret = UpdateCardBitmap(transdtl.cardno, transdtl.cardcnt, CARDBITMAPTYPE_REV);
            if(ret)
            {
                writelog(LOG_ERR, "UpdateCardBitmap err ret[%d]cardno[%d]cardcnt[%d]", ret, transdtl.cardno, transdtl.cardcnt);
            }
        }
    }
    if(strlen(trans.opercode))
    {
        if(strcmp(transdtl.opercode, pAccTrans->trans.opercode) != 0)
        {
            des2src(transdtl.opercode, trans.opercode);
        }
    }

    trans.cardno = transdtl.cardno;
    trans.cardflag = 0;
    trans.offlineflag = 1;
    trans.revflag = 1; //冲正标志
    trans.cardbefbal = transdtl.cardbefbal;
    trans.cardaftbal = transdtl.cardbefbal;
    trans.transflag = transdtl.transflag;
    if(TF_DPS == trans.transflag)
    {
        trans.dpscnt = transdtl.cardcnt - 1;
        trans.aftdpscnt = trans.dpscnt;
    }
    if(TF_PAY == trans.transflag)
    {
        trans.paycnt = transdtl.cardcnt - 1;
        trans.aftpaycnt = trans.paycnt;
    }

    ret = pAccTrans->doTodayReverseTrans(oldaccdate, oldtermid, oldtermseqno);
    if(ret)
        return ret;
    transdtl.cardaftbal = transdtl.cardbefbal;
    transdtl.revflag[0] = '0';
    strcpy(transdtl.accdate, pAccTrans->trans.accdate);
    strcpy(transdtl.acctime, pAccTrans->trans.acctime);
    des2src(transdtl.transdate, pAccTrans->trans.transdate);
    des2src(transdtl.transtime, pAccTrans->trans.transtime);
    transdtl.transcode = pAccTrans->trans.transcode;
    transdtl.termid = pAccTrans->trans.termid;
    transdtl.termseqno = pAccTrans->trans.termseqno;
    transdtl.amount = -transdtl.amount;
    transdtl.managefee = -transdtl.managefee;
    ret = DB_t_transdtl_add(&transdtl);
    if(ret)
    {
        if(DB_REPEAT == ret)
            return E_DB_TRANSDTL_E;
        else
            return E_DB_TRANSDTL_I;
    }
    return 0;
}
Exemple #22
0
int F846308(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
    int ret=0;
    CAccTrans *pAccTrans=CAccTrans::getInstance();
//	ret=pAccTrans->checkCfgUpdate();
//	if(ret)
//		return ret;
    des2src(pAccTrans->trans.opercode,rPack->semp);
    TRANS& trans=pAccTrans->trans;
    trans.cardno = rPack->lvol0;
    char frozeflag=rPack->sstatus1[0];

    if('1'==frozeflag)
    {
        trans.transcode=TC_CARDFROZE;
        ret=pAccTrans->InitTrans();
        if(ret)
            return ret;
        ret=DoFrozeCard(trans.cardno);
    }
    else
    {
        trans.transcode=TC_CARDUNFROZE;
        ret=pAccTrans->InitTrans();
        if(ret)
            return ret;
        ret=DoUnFrozeCard(trans.cardno);
    }
    if(ret)
        return ret;
    T_t_transdtl transdtl;
    memset(&transdtl,0,sizeof(transdtl));

    transdtl.cardno=trans.cardno;
    transdtl.custid=trans.custid;
    des2src(transdtl.custname,trans.custname);
    strcpy(transdtl.transdate,trans.transdate);
    strcpy(transdtl.transtime,trans.transtime);
    strcpy(transdtl.accdate,trans.sysdate);
    strcpy(transdtl.acctime,trans.systime);
    transdtl.termid=trans.termid;
    transdtl.termseqno=trans.termseqno;
    transdtl.transcode=trans.transcode;
    transdtl.amount=trans.totaltransamt;
    transdtl.managefee=trans.totalfeeamt;
    des2src(transdtl.opercode,trans.opercode);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    transdtl.errcode=0;
    transdtl.showcardno=atol(trans.showcardno);
    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);
    memset(&aPack,0,sizeof(aPack));

    ResetNormalCPack(&aPack,0,1);


    SetCol(handle,0);
    SetCol(handle,F_SSERIAL0,F_VSMESS,0);
    strncpy(outPack->sserial0,trans.summary,12);
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
Exemple #23
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;
}
Exemple #24
0
int F843351(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;	
	ret=pAccTrans->CheckCfgUpdate();
	if(ret)
		return ret;
	des2src(trans.opercode,rPack->semp);	
	trans.transcode=TC_SHOPSAVING;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;
	char accno[21]="";
	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);

	trans.shopid=rPack->lvol0;
	double depositamt=rPack->damt0;
	
	if(trans.shopid<1||amtcmp(depositamt,0)<=0)
	{
		return E_INPUT_DATA_INVAILD;
	}
	T_t_shop shop;

	memset(&shop,0,sizeof(shop));
	ret=DB_t_shop_read_lock_by_c0_and_shopid(trans.shopid,&shop);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_SHOP_N;
		else
			return E_DB_SHOP_R;
	}
	if(shop.status[0]=='2')
	{
		DB_t_shop_free_lock_by_c0();
		return ERRINFO(E_SHOP_LOGOUT,shop.shopid);
	}
	double discount_amt=D4U5(depositamt*shop.depositagio);
	shop.depositamt+=depositamt;
	shop.depositcnt++;
	shop.discountamt+=discount_amt;
	ret=DB_t_shop_update_lock_by_c0(&shop);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_SHOP_N;
		else
			return E_DB_SHOP_U;
	}	
	//检查客户
	//去帐户信息
	T_t_shopacc tShopAccount;	
	memset(&tShopAccount,0,sizeof(tShopAccount));
	ret=DB_t_shopacc_read_by_accno(shop.accno,&tShopAccount);
	if(ret)
	{
		writelog(LOG_ERR,"shopid[%d]",trans.shopid);
		if(DB_NOTFOUND==ret)
			return ERRINFO(E_NOTEXIST_SHOPACCNO,shop.accno);
		else 
			return E_DB_ACCOUNT_R;
	}
	if(tShopAccount.status[0]!=STATUS_NORMAL)
	{
		return E_SHOPACC_LOGOUT;
	}
	pAccTrans->trans.custid=0;
	strcpy(trans.shopaccno,tShopAccount.accno);
	strcpy(trans.craccno,tShopAccount.accno);
	trans.inputamt=depositamt;
	trans.transamt=trans.inputamt;
	trans.fundtype=rPack->lvol9;
	des2src(trans.voucherno,rPack->scust_auth2);
	trans.transtype=TRANSTYPE_DEPOSITSHOPSAV;
	ret=pAccTrans->DoTransByTransType();
	if(ret)
		return ret; 	
	if(amtcmp(discount_amt,0)>0)
	{
		strcpy(pAccTrans->trans.craccno,tShopAccount.accno);
		trans.inputamt=discount_amt;
		trans.fundtype=0;
		trans.transamt=trans.inputamt;
		trans.transtype=TRANSTYPE_DEPOSITSHOPSAVDISCNT;
		ret=pAccTrans->DoTransByTransType();
		if(ret)
			return ret; 	
	}
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));

	des2src(transdtl.transdate,trans.transdate);
	des2src(transdtl.transtime,trans.transtime);
	strcpy(transdtl.accdate,trans.sysdate);
	strcpy(transdtl.acctime,trans.systime);
	transdtl.termid=trans.termid;
	transdtl.termseqno=trans.termseqno;
	transdtl.transcode=trans.transcode;
	transdtl.paytype=rPack->lvol9;
    transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	des2src(transdtl.voucherno,trans.voucherno);
	des2src(transdtl.custname,shop.shopname);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
	  if(DB_REPEAT==ret)
	    return E_DB_TRANSDTL_E;
	  else
	    return E_DB_TRANSDTL_I;
	}
	sprintf(trans.remark,"商户[%s]存入%.2lf元提成金额%.2lf余额%.2lf",tShopAccount.accname,depositamt,discount_amt,trans.craccaftbal);
	SetCol(handle,F_SDATE3,F_LWITHDRAW_FLAG,F_LSERIAL1,F_SORDER0,F_DAMT0,F_DAMT1,F_DAMT2,F_LVOL0,F_VSVARSTR0,F_VSMESS,0);
	des2src(outPack->sdate3,trans.sysdate);
	des2src(outPack->semp,trans.opercode);
	outPack->lwithdraw_flag=trans.termid;
	outPack->lserial1=trans.termseqno;
	outPack->damt0=depositamt;
	outPack->damt1=discount_amt;
	outPack->damt2=pAccTrans->trans.craccaftbal;
	outPack->lvol0=shop.shopid;
	des2src(outPack->vsvarstr0,shop.shopname);
	des2src(outPack->sorder0,trans.transdate);
	
	sprintf(outPack->vsmess,"%s %s 帐户余额%.2f元",tShopAccount.accname,pAccTrans->remark.c_str(),pAccTrans->trans.craccaftbal);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
int F846340(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) {
    int ret=0;

    CAccTrans *pAccTrans=CAccTrans::getInstance();
    TRANS& trans=pAccTrans->trans;
    trans.transcode=TC_EACC2SHOP;
    trans.transtype = TRANSTYPE_EACCPAYMENT; // 支付交易
    //trans.termid=TERMID_WEB;
    trans.termid=rPack->lcert_code; // 使用支付网关的注册ID

    ret=pAccTrans->InitTrans();
    if(ret)
        return ret;

    trans.inputamt=D4U5(rPack->damt0,2);
    trans.unusedamt = trans.inputamt;
    trans.transamt=trans.inputamt;

    if(amtcmp(trans.inputamt,0)==0)
        return E_INPUT_AMT_NULL;

    if(amtcmp(trans.inputamt,0)<0)
        return E_INPUT_AMT;

    //查询电子钱包帐户
    T_t_netacc tNetAccount;
    memset(&tNetAccount,0,sizeof(tNetAccount));
    ret=DB_t_netacc_read_by_accno(rPack->scust_no,&tNetAccount);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return ERRINFO(E_NOTEXIST_EACCNO,rPack->scust_no);
        else
            return E_DB_ACCOUNT_R;
    }

    //检查电子钱包密码
    if(rPack->lvol1 == 0) { // 检查电子账户密码 检查账户余额
        if(strcmp(rPack->snote2,tNetAccount.paypwd)!=0)
            return E_EACCPWD;
    }

    if(tNetAccount.status[0]!=STATUS_NORMAL) // 账户状态
        return ERRINFO(E_EACCNO_LOGOUT,tNetAccount.accno);

    if(tNetAccount.stoppayflag[0]=='1') // 止付标志
        return ERRINFO(E_EACC_STOPPAY,tNetAccount.accno);

    if(rPack->lvol1 == 0) { // 检查电子账户密码 检查账户余额
        if(amtcmp(trans.inputamt,tNetAccount.balance)>0)
            return ERRINFO(E_EACC_BALANCE_SHORTAGE,trans.inputamt-tNetAccount.balance);
    }
    /*
    double CardMaxBal=0;
    ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
    if(ret)
    	return ret;
    if(amtcmp(trans.inputamt+trans.cardbefbal,CardMaxBal)>0)
    	return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
    */
    des2src(trans.draccno,tNetAccount.accno);

    trans.custid=tNetAccount.custid;
    des2src(trans.custname,tNetAccount.accname);

    // 支付转账
    T_t_shop shop;

    memset(&shop,0,sizeof(shop));
    ret=DB_t_shop_read_by_shopid(rPack->lvol0,&shop);
    if(ret) {
        if(DB_NOTFOUND==ret)
            return E_NOTEXIST_SHOPID;
        else
            return E_DB_SHOP_R;
    }
    if(shop.status[0]!=STATUS_NORMAL)
        return E_SHOP_LOGOUT;

    if(shop.shoptype!=SHOPTYPE_ESHOP)
        return ERRIF_SHOP_TYPE;

    des2src(trans.craccno,shop.accno);

    // 产生交易参考号
    T_t_refno tRefno;

    memset(&tRefno,0,sizeof(tRefno));
    get_random(tRefno.mac);
    ret= GetNewRefno(tRefno.refno);
    if(ret)
        return ret;

    des2src(tRefno.lastsaved,trans.sysdatetime);
    des2src(tRefno.accdate,trans.accdate);
    tRefno.termid = trans.termid;
    tRefno.termseqno = trans.termseqno;
    tRefno.status = RS_SUCC;

    ret=DB_t_refno_add(&tRefno);
    if(ret) {
        if(DB_REPEAT==ret)
            return E_DB_REFNO_E;
        else
            return E_DB_REFNO_I;
    }

    des2src(trans.refno, tRefno.refno);

    ret=pAccTrans->doTrans();
    if(ret)
        return ret;

    // 添加电子账户支付信息
    T_t_epay_record t_epay_record;
    memset(&t_epay_record,0,sizeof(t_epay_record));

    des2src(t_epay_record.refno, tRefno.refno);
    t_epay_record.shopid = shop.shopid;
    des2src(t_epay_record.oid, rPack->sbankname);
    des2src(t_epay_record.accno,tNetAccount.accno);
    des2src(t_epay_record.accname,tNetAccount.accname);
    t_epay_record.amount = trans.inputamt;
    des2src(t_epay_record.currency,rPack->sstock_code);

    des2src(t_epay_record.epay_date,trans.accdate);
    des2src(t_epay_record.epay_time,trans.acctime);
    t_epay_record.status = 1; // 交易成功
    t_epay_record.transcode = trans.transcode;
    des2src(t_epay_record.remark,rPack->snote);

    ret=DB_t_epay_record_add(&t_epay_record);
    if(ret)
        return ret;

    // 添加交易流水
    T_t_transdtl transdtl;
    memset(&transdtl,0,sizeof(transdtl));

    des2src(transdtl.refno,tRefno.refno); // 交易参考号
    des2src(transdtl.transdate,trans.accdate);
    des2src(transdtl.transtime,trans.acctime);
    strcpy(transdtl.accdate,trans.accdate);
    strcpy(transdtl.acctime,trans.acctime);
    transdtl.termid=trans.termid;
    transdtl.termseqno=trans.termseqno;
    transdtl.transcode=trans.transcode;
    transdtl.transflag=TF_PAY;
    transdtl.managefee=trans.totalfeeamt;
    des2src(transdtl.custname,tNetAccount.accname);
    transdtl.amount = trans.inputamt;
    des2src(transdtl.opercode,trans.opercode);
    transdtl.cardbefbal = trans.draccbefbal;
    transdtl.cardaftbal = trans.draccaftbal;
    des2src(transdtl.coldate,trans.accdate);
    des2src(transdtl.coltime,trans.acctime);
    transdtl.status[0]=DTLSTATUS_SUCCESS;
    transdtl.revflag[0]='0';
    transdtl.custid=tNetAccount.custid;
    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_LVOL0,F_SCUST_NO, F_SDATE0,F_STIME0,
           F_DAMT0,F_SPHONE3,F_SADDR,F_VSMESS,0);
    outPack->lvol0=shop.shopid;
    des2src(outPack->scust_no,tNetAccount.accno);
    des2src(outPack->sdate0,trans.accdate);
    des2src(outPack->stime0,trans.acctime);

    des2src(outPack->sphone3,tRefno.refno); // 一卡通流水号,冲正使用
    des2src(outPack->saddr,tRefno.mac); // MAC 冲正使用

    outPack->damt0=trans.draccaftbal; // 余额
    char temp[128]="";
    sprintf(temp,"%s 支付成功,电子钱包余额:%.2f",
            tNetAccount.accname, trans.draccaftbal);

    pAccTrans->remark+=temp;
    strcpy(outPack->vsmess,pAccTrans->remark.c_str());
    des2src(trans.remark,outPack->vsmess);
    PutRow(handle,outPack,pRetCode,szMsg);
    return 0;
}
Exemple #26
0
int F846312(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	des2src(pAccTrans->trans.opercode,rPack->semp);
	pAccTrans->trans.transcode=TC_CARDDEPOSIT;
	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);

	trans.cardflag=1;
	trans.usecardflag=1;	
	trans.cardno=rPack->lvol0;	
	trans.purseno=PURSE_NO_ONE;
	trans.cardbefbal=rPack->lvol7/100.0;
	trans.cardaftbal=trans.cardbefbal;
	trans.dpscnt=rPack->lvol5+1;
	if(trans.dpscnt<=1)
	{
		if(amtcmp(trans.cardbefbal,0)>0)
			trans.dpscnt=rPack->lvol6+1;	//考虑兼容性
	}
	des2src(trans.cardphyid,rPack->sstation0);
	trans.fundtype=rPack->lvol9;
	if(!trans.fundtype)
		return E_INPUTNULL_PAYTYPE;
	des2src(trans.voucherno,rPack->scust_auth2);
	trans.inputamt=rPack->damt0;
	trans.unusedamt = trans.inputamt;
	if(amtcmp(trans.inputamt,500)>0)
	{
		ERRTIP("单笔充值不能超过500元");
		return E_COMMON_ERR;
	}
	T_t_card tCard;
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(trans,tCard);
	if(ret)
	{
		return ret;
	}
	trans.feetype=tCard.feetype;
	trans.cardtype=tCard.cardtype;
//	ret=UpdateCardBitmap(trans.cardno,trans.cardcnt,CARDBITMAPTYPE_INC,0);
//	if(ret)
//		return ret;
	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;
	}
	if(tCardAccount.status[0]!=STATUS_NORMAL)
	{
		return ERRINFO(E_CARDACC_LOGOUT,tCardAccount.accno);
	}
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(trans.inputamt+trans.cardbefbal,CardMaxBal)>0)
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
	trans.custid=tCard.custid;
	if(trans.custid)
	{
		ret=GetCustBaseInfoByCustID(trans.custid,trans.custname,trans.stuempno,NULL);
		if(ret)
			return ret;
	}
    des2src(trans.cardaccno,tCardAccount.accno);
	ret=pAccTrans->doFeeTrans();
	if(ret)
		return ret;
    des2src(trans.craccno,tCardAccount.accno);
	ret=pAccTrans->doMainTrans();
	if(ret)
		return ret;
	ret=pAccTrans->doTransEnd();
	if(ret)
		return ret;	
	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.transflag=TF_DPS;	
	transdtl.cardcnt=trans.dpscnt;
	transdtl.cardbefbal=trans.cardbefbal;
    transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.custid=trans.custid;
    des2src(transdtl.custname,trans.custname);
    des2src(transdtl.stuempno,trans.stuempno);
	des2src(transdtl.opercode,trans.opercode);
    des2src(transdtl.showcardno,tCard.showcardno);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	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_STIME0,
		F_SDATE3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,F_STIME3,0);	
	outPack->lvol0=tCard.cardno;
	outPack->lvol8=D4U5(pAccTrans->trans.cardaftbal*100,0);
	des2src(outPack->sdate0,transdtl.transdate);
	des2src(outPack->stime0,transdtl.transtime);
	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;
    sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
    des2src(outPack->vsmess,trans.remark);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 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;
}
Exemple #28
0
//冲账交易
int AccTransRev(char *oldaccdate,int oldtermid,int oldtermseqno)
{
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	trans.revflag=1;//冲正标志

	char transdtlname[61]={0};
	int ret=GetTransdtlTableName(oldaccdate,transdtlname);
	if(ret)
	{
		writelog(LOG_ERR,"GetTransdtlTableName err");
		return ret;
	}
	T_t_transdtl transdtl;
	
	ret=ReadTransdtlData(transdtlname,oldaccdate,oldtermid,oldtermseqno,transdtl);
	if(ret)
	{
		writelog(LOG_ERR,"ReadTransdtlData transdtlname[%s],oldaccdate[%s],oldtermid[%d],oldtermseqno[%d]",transdtlname,oldaccdate,oldtermid,oldtermseqno);
		return ret;
	}
	if('1'==transdtl.revflag[0])
	{
//		DB_t_transdtl_free_lock_by_c0();
		pAccTrans->remark="该交易已冲正";
		return 0;
	}	
	ret=UpdateTransdtlHisRevFlag(transdtlname,oldaccdate,oldtermid,oldtermseqno);
	if(ret)
	{
		writelog(LOG_ERR,"UpdateTransdtlRevFlag ret[%d]accdate[%s]termid[%d]termseqno[%d]",ret,oldaccdate,oldtermid,oldtermseqno);
		return ret;
	}
	if(transdtl.cardcnt>0&&transdtl.cardno>0)
	{
		if(TF_PAY==transdtl.transflag)
		{
			ret=UpdateCardBitmap(transdtl.cardno,transdtl.cardcnt,CARDBITMAPTYPE_REV);
			if(ret)
			{
				writelog(LOG_ERR,"UpdateCardBitmap err ret[%d]cardno[%d]cardcnt[%d]",ret,transdtl.cardno,transdtl.cardcnt);
			}
		}
	}
	if(strlen(transdtl.opercode))
	{
		if(strcmp(transdtl.opercode,pAccTrans->trans.opercode)!=0)
		{
			return ERRINFO(E_REVOPER,transdtl.opercode);
		}
	}
	else
	{
		des2src(transdtl.opercode,trans.opercode);
	}
	trans.cardno=transdtl.cardno;
	trans.cardflag=1;
	trans.offlineflag=1;
	trans.revflag=1;//冲正标志
	trans.cardbefbal=transdtl.cardaftbal;
	trans.cardaftbal=transdtl.cardbefbal;
	ret=GetAccnoByCardno(trans.cardno,trans.cardaccno);
	if(ret)
		return ret;			
/*
	if(transdtl.cardno)
	{
		T_t_card card;
		memset(&card,0,sizeof(card));
		ret=DB_t_card_read_by_cardno(transdtl.cardno,&card);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				return ERRINFO(E_NOTEXIST_CARDNO,transdtl.cardno);
			else
				return E_DB_CARD_R;
		}
		strcpy(pAccTrans->trans.cardaccno,card.accno);
	}
*/
	ret=pAccTrans->doHistoryReverseTrans(oldaccdate,oldtermid,oldtermseqno);	
	if(ret)
		return ret; 
	ret=UpdCardBalByAccno(trans.cardaccno,transdtl.cardbefbal,transdtl.transflag,transdtl.cardcnt,1,1);
	if(ret)
		return ret;		
	transdtl.cardaftbal=transdtl.cardbefbal;
	transdtl.revflag[0]='0';
	strcpy(transdtl.accdate,pAccTrans->trans.accdate);
	strcpy(transdtl.acctime,pAccTrans->trans.acctime);
	des2src(transdtl.transdate,pAccTrans->trans.transdate);
	des2src(transdtl.transtime,pAccTrans->trans.transtime);
	transdtl.transcode= pAccTrans->trans.transcode;
	transdtl.termid = pAccTrans->trans.termid;
	transdtl.termseqno = pAccTrans->trans.termseqno;
	transdtl.amount = -transdtl.amount;
	transdtl.managefee = -transdtl.managefee;
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
		if(DB_REPEAT==ret)
			return E_DB_TRANSDTL_E;
		else
			return E_DB_TRANSDTL_I;
	}		
	return 0;
}
Exemple #29
0
int F950052(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret =0;
	//writelog(LOG_INFO,"start pos deposit");
	cpu_trade_t cpu_trade;
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	ret=pAccTrans->CheckCfgUpdate();
	if(ret)
		return ret;
	T_t_authcard tAuthCard;
	T_t_transdtl transdtl;
	T_t_dpsoper   tDepositOper;
	T_t_dpsoperpos tDepositOperpos;
	T_t_dpsshoppos tDepositShoppos;
	T_t_shop 					tDepositShop;
	T_t_account	tAccount;		//帐户表
	T_t_device tDevice;

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

	memset(&tAuthCard,0,sizeof(tAuthCard));
	memset(&tDepositOper,0,sizeof(tDepositOper));
	memset(&tDepositOperpos,0,sizeof(tDepositOperpos));
	memset(&tDepositShoppos,0,sizeof(tDepositShoppos));
	memset(&tDepositShop,0,sizeof(tDepositShop));
	memset(&tAccount,0,sizeof(tAccount));
	memset(&transdtl,0,sizeof(transdtl));
	int opercardno=rPack->lvol3;			//操作员号
	if(!opercardno)
		return E_INPUTNULL_CARDNO;
	trans.cardflag=1;
	trans.usecardflag=1;	
	trans.cardno=rPack->lvol5;
	trans.purseno=PURSE_NO_ONE;
	trans.cardbefbal=rPack->lvol9/100.0;				//入卡金额
	trans.dpscnt= rPack->lvol7;					//入卡金额
	trans.inputamt= rPack->lvol8/100.0;			//充值金额	
	trans.unusedamt = trans.inputamt;
	trans.fundtype=1;
	transdtl.sysid= rPack->lcert_code;						//上传工作站标识(前置机注册号)
	des2src(transdtl.devphyid, rPack->sdate1);		//物理设备ID
	transdtl.devseqno=rPack->lvol4;					//上传端流水号
	ret=GetDevIdByDevPhyId(&(trans.termid),transdtl.devphyid);
	if (ret)
	{
		writelog(LOG_ERR,"GetDevIdByDevPhyId err[%d] devphy999_id[%s]",ret,transdtl.devphyid);
		return ret;
	}
	ret = DB_t_device_read_by_deviceid(trans.termid,&tDevice);
	if(ret)
	{
		writelog(LOG_ERR," DB_t_device_read_by_deviceid err[%d]",ret);
		return E_DB_DEVICE_R;
	}

	//writelog(LOG_DEBUG,"trans.inputamt[%d]",trans.inputamt);
	T_t_card tCard;
	memset(&tCard,0,sizeof(tCard));
	ret=doCard(trans,tCard);
	if(ret)
	{
		return ret;
	}
	memset(&cpu_trade,0,sizeof cpu_trade);
	des2src(cpu_trade.random_key,rPack->sstock_code);//fixme
	cpu_trade.tradeamt = rPack->lvol8;
	cpu_trade.balance = rPack->lvol9;
	cpu_trade.termsno = rPack->lvol4;
	sprintf(cpu_trade.termno,"%012d",tDevice.deviceno); // 终端号
	cpu_trade.tradecnt = trans.dpscnt;
	sprintf(cpu_trade.tx_datetime,"%s%s",rPack->spost_code,rPack->spost_code2);

	ret = doCheckMac(&cpu_trade,NULL,out_pack->sstock_code2);
	if(ret)
	{
		writelog(LOG_ERR,"doCheckMac err[%d]",ret);
		return ret;
	}

	trans.feetype=tCard.feetype;
	trans.cardtype=tCard.cardtype;
//	ret=UpdateCardBitmap(trans.cardno,trans.cardcnt,CARDBITMAPTYPE_INC,0);
//	if(ret)
//		return ret;
	// 读取操作员号
	ret = DB_t_authcard_read_by_cardno(opercardno,&tAuthCard);
	if(ret)
	{
		writelog(LOG_ERR,"get operator code from auth card error, auth_card_id[%d]",opercardno);
		if(DB_NOTFOUND == ret)
			 return E_DB_AUTHCARD_N;
		else
			 return  E_DB_OPERATOR_R;
	}
	if(tAuthCard.status[0]!=STATUS_NORMAL)
	{
		return E_OPERLOGON_UNREG;
	}
	des2src(trans.opercode,tAuthCard.opercode);
		ret=DB_t_dpsoper_read_lock_by_c0_and_opercode(trans.opercode,&tDepositOper);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			return E_DB_DEPOSITOPER_R;
		else
			return E_DB_DEPOSITOPER_N;
	}
	if(tDepositOper.status[0]!=STATUS_NORMAL)
	{
		DB_t_dpsoper_free_lock_by_c0();
		return E_DEPOSITOPER_STOP;
	}
	//判断是否是重复交易
	if(tDepositOper.lastdevseqno==transdtl.devseqno)
	{
		DB_t_dpsoper_free_lock_by_c0();
		ret=DB_t_transdtl_read_by_accdate_and_devphyid_and_devseqno(
			trans.transdate,tDepositOper.lastdevphyid,tDepositOper.lastdevseqno,
			&transdtl);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				return E_DB_TRANSDTL_N;
			else
				return E_DB_TRANSDTL_R;
		}
		//if(transdtl.revflag[0]=='1')
		//	return E_TRANSDTL_REV;
		ResetNormalCPack(&aPack,0,1);
		SetCol(handle,0);
		SetCol(handle,F_LVOL5,F_LVOL10,F_LCERT_CODE,0);

		out_pack->lvol5 = transdtl.cardno;
		out_pack->lvol10 = (int)D4U5(transdtl.cardaftbal*100,0);
		out_pack->lcert_code = transdtl.termseqno;
		writelog(LOG_INFO,"该交易已成功,卡号[%d]充值金额[%.2lf]卡余额[%.2lf]",transdtl.cardno,
				 transdtl.amount,transdtl.cardaftbal);
		PutRow(handle,out_pack,pRetCode,szMsg);
		return 0;		
	}
	if(strncmp(tDepositOper.lasttransdate,trans.transdate,8)!=0)
	{
		des2src(tDepositOper.lasttransdate,trans.transdate);
		tDepositOper.depositcnt=0;
		tDepositOper.depositamt=0;
	}
	tDepositOper.depositcnt++;
	tDepositOper.depositamt+=trans.inputamt;
	tDepositOper.lastdevseqno=transdtl.devseqno;
	des2src(tDepositOper.lastdevphyid,transdtl.devphyid);
	des2src(tDepositOper.lastsaved,trans.sysdatetime);
	if(amtcmp(tDepositOper.maxdepositamt,0)>0)
	{
		DB_t_dpsoper_free_lock_by_c0();
		if(amtcmp(tDepositOper.depositamt,tDepositOper.maxdepositamt)>0)
		{
			return E_OPER_OVER_MAX_DEPOSIT_AMT;
		}
	}
	ret=DB_t_dpsoper_update_lock_by_c0(&tDepositOper);
	if(ret)
	{
			return E_DB_DEPOSITOPER_U;
	}
	ret=DB_t_dpsshoppos_read_by_deviceid(trans.termid, &tDepositShoppos);

	if(ret)
	{
		if(DB_NOTFOUND==ret)
		{
			writelog(LOG_INFO,"PosDeposit termid[%d] ",trans.termid);
			trans.transcode = TC_POSDEPOSIT;
		}
		else
		{
			return E_DB_DEPOSITSHOPPOS_R;
		}
	}
	else
	{
		writelog(LOG_INFO,"ShopPosDeposit termid[%d] ",trans.termid);
		trans.transcode = TC_SHOPPOSDEPOSIT;
		ret=DB_t_shop_read_by_shopid(tDepositShoppos.shopid, &tDepositShop);
		if(ret)
		{
			if(DB_NOTFOUND==ret)
				return E_DB_SHOP_N;
			else
				return E_DB_SHOP_R;
		}
		if(tDepositShop.status[0]!=STATUS_NORMAL)
		{
			return E_SHOP_LOGOUT;
		}
		des2src(trans.draccno,tDepositShop.accno);		
	}
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;
	//根据卡号和钱包号得到消费者账号(借方)
	ret=DB_t_account_read_by_accno(tCard.accno,&tAccount);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_account_read_by_accno ret[%d]cardno[%d]",ret,trans.cardno);
		if(DB_NOTFOUND==ret)
			return E_NOTEXIST_ACCNO;
		else
			return E_DB_ACCOUNT_R;
	}
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(trans.inputamt+trans.cardbefbal,CardMaxBal)>=0)
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
	trans.custid=tCard.custid;
	des2src(trans.cardaccno,tAccount.accno);
	ret=pAccTrans->doTrans();
	if(ret)
		return ret;
	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.transflag = TF_DPS;
	transdtl.cardcnt=trans.dpscnt;
	transdtl.cardbefbal=trans.cardbefbal;
	transdtl.amount=trans.totaltransamt;
	transdtl.managefee=trans.totalfeeamt;
	transdtl.cardaftbal=trans.cardaftbal;
	transdtl.custid=trans.custid;
	des2src(transdtl.custname,tAccount.accname);
	des2src(transdtl.opercode,trans.opercode);
	transdtl.status[0]=DTLSTATUS_SUCCESS;
	ret=DB_t_transdtl_add(&transdtl);
	if(ret)
	{
		if(DB_REPEAT==ret)
			return E_DB_TRANSDTL_E;
		else
			return E_DB_TRANSDTL_I;
	} 	
	sprintf(trans.remark,"卡号%d 充值前卡余额:%.2lf元 卡当前余额:%.2lf元",trans.cardno,trans.cardbefbal,trans.cardaftbal);
	writelog(LOG_INFO,trans.remark);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL5,F_LVOL10,F_LCERT_CODE,F_SSTOCK_CODE2,0);

	out_pack->lvol5 = trans.cardno;
	out_pack->lvol10 = (int)D4U5(trans.cardaftbal*100,0);
	out_pack->lcert_code = trans.termseqno;
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 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;
}