def CrtCustInfo( ): #检查个人协议是否存在 if ( not ChkCustInfo( ) ): return False #自动生成个人协议编号 if ( AfaFunc.GetSerialno() < 0 ): return ExitSubTrade( '9000', '生成个人协议编号失败' ) #组织个人协议编码(交易日期 + 中间业务流水号) TradeContext.PROTOCOLNO = TradeContext.WorkDate + TradeContext.agentSerialno #个人协议不存在,登记个人协议信息 if ( not InsertCustInfo( ) ): return False return True
if not AfaFunc.ChkUnitStatus( ) : raise AfaFlowControl.flowException( ) #=====================判断渠道状态====================================== if not AfaFunc.ChkChannelStatus( ) : raise AfaFlowControl.flowException( ) #=====================判断缴费介质状态================================== if not AfaFunc.ChkActStatus( ) : raise AfaFlowControl.flowException( ) #=====================获取平台流水号==================================== if AfaFunc.GetSerialno( ) == -1 : raise AfaFlowControl.flowException( ) #=====================插入流水表======================================== if not AfaTransDtlFunc.InsertDtl( ) : raise AfaFlowControl.flowException( ) #=====================与主机交换======================================== AfaHostFunc.CommHost() #=====================更新流水表======================================== if( not AfaTransDtlFunc.UpdateDtl( 'TRADE' ) ): raise AfaFlowControl.flowException( )
def main( ): AfaLoggerFunc.tradeInfo('******代收代付.补打发票模板[' + TradeContext.TemplateCode + ']进入******') try: #=====================初始化返回报文变量================================ TradeContext.tradeResponse=[] #=====================获取当前系统时间================================== TradeContext.workDate=AfaUtilTools.GetSysDate( ) TradeContext.workTime=AfaUtilTools.GetSysTime( ) #=====================判断应用系统状态================================== if not AfaFunc.ChkSysStatus( ) : raise AfaFlowControl.flowException( ) #=====================校验公共节点的有效性============================== if( not TradeContext.existVariable( "sysId") ): raise AfaFlowControl.flowException( 'A0001', '系统标识[sysId]值不存在,不能进行补打发票' ) if( not TradeContext.existVariable( "userno") ): raise AfaFlowControl.flowException( 'A0001', '用户号[userno]值不存在,不能进行补打发票' ) #=====================判断应用系统状态================================== if not AfaFunc.ChkSysStatus( ) : raise AfaFlowControl.flowException( ) #=====================判断商户状态====================================== if not AfaFunc.ChkUnitStatus( ) : raise AfaFlowControl.flowException( ) #=====================判断渠道状态====================================== if not AfaFunc.ChkChannelStatus( ) : raise AfaFlowControl.flowException( ) #操作标志(0-查询发票信息 1-修改打印次数 2-从第三方获取发票信息,进行打印) if( not TradeContext.existVariable( "procFlag") ): raise AfaFlowControl.flowException( 'A0001', '操作标志[tradeFlag"]值不存在,不能进行补打发票' ) if(TradeContext.procFlag=="0"): #查询发票信息 sql="SELECT BILLDATA,ITEM1,ITEM2,ITEM3,ITEM4,ITEM5,ITEM6,BILLSERNO,SERIALNO,PRTNUM,WORKDATE,BILLSTATUS FROM AFA_BILLDTL WHERE " sql=sql + " SYSID='" + TradeContext.sysId + "'" sql=sql + " AND UNITNO='" + TradeContext.unitno + "'" if( TradeContext.existVariable( "subUnitno") ): sql=sql + " AND SUBUNITNO='" + TradeContext.subUnitno + "'" if( TradeContext.existVariable( "userno") ): sql=sql + " AND USERNO='" + TradeContext.userno + "'" if( TradeContext.existVariable( "payMonth") ): sql=sql + " AND WORKDATE LIKE '" + TradeContext.payMonth + "%'" if( TradeContext.existVariable( "item1") ): sql=sql + " AND ITEM1='" + TradeContext.item1 + "'" if( TradeContext.existVariable( "item2") ): sql=sql + " AND ITEM2='" + TradeContext.item1 + "'" if( TradeContext.existVariable( "item3") ): sql=sql + " AND ITEM3='" + TradeContext.item1 + "'" if( TradeContext.existVariable( "item4") ): sql=sql + " AND ITEM4='" + TradeContext.item1 + "'" if( TradeContext.existVariable( "item5") ): sql=sql + " AND ITEM5='" + TradeContext.item1 + "'" if( TradeContext.existVariable( "item6") ): sql=sql + " AND ITEM6='" + TradeContext.item1 + "'" sql=sql + " ORDER BY WORKDATE DESC,WORKTIME DESC " AfaLoggerFunc.tradeInfo( sql ) records = AfaDBFunc.SelectSql(sql) if( records == None ): raise AfaFlowControl.flowException( 'A0002', '数据库操作异常:' + AfaDBFunc.sqlErrMsg ) if(len(records)==0): raise AfaFlowControl.flowException( 'A0002', '无符合条件的记录' ) if(int(records[0][9])==3): raise AfaFlowControl.flowException( 'A0002', '最多3次重打' ) if(int(records[0][11])==1): raise AfaFlowControl.flowException( 'A0002', '票据已作废,不允许打印' ) TradeContext.billNum = str(len(records)) #发票数量 if ( TradeContext.TransType=='0' ): #变量初始化 TradeContext.billData = [] #发票信息 TradeContext.item1 = [] #附加项1 TradeContext.item2 = [] #附加项2 TradeContext.item3 = [] #附加项3 TradeContext.item4 = [] #附加项4 TradeContext.item5 = [] #附加项5 TradeContext.item6 = [] #附加项6 TradeContext.billserno= [] #发票序号 TradeContext.serialno = [] #中间业务流水号 TradeContext.prtnum = [] #打印次数 TradeContext.paydate = [] #支付日期 #打包 for i in range( 0, len(records) ): TradeContext.billData.append(records[i][0]) TradeContext.item1.append(records[i][1]) TradeContext.item2.append(records[i][2]) TradeContext.item3.append(records[i][3]) TradeContext.item4.append(records[i][4]) TradeContext.item5.append(records[i][5]) TradeContext.item6.append(records[i][6]) TradeContext.billserno.append(records[i][7]) TradeContext.serialno.append(records[i][8]) TradeContext.prtnum.append(records[i][9]) TradeContext.paydate.append(records[i][10]) else: MxFileName = os.environ['AFAP_HOME'] + '/tmp/MX' + TradeContext.zoneno + TradeContext.brno + TradeContext.tellerno + '.TXT' AfaLoggerFunc.tradeInfo('>>>明细文件:['+MxFileName+']') if (os.path.exists(MxFileName) and os.path.isfile(MxFileName)): #文件存在,先删除-再创建 os.system("rm " + MxFileName) #创建明细文件 sfp = open(MxFileName, "w") for i in range( 0, len(records) ): wBuffer = "" wBuffer = wBuffer + records[i][0] wBuffer = wBuffer + records[i][1] wBuffer = wBuffer + records[i][2] wBuffer = wBuffer + records[i][3] wBuffer = wBuffer + records[i][4] wBuffer = wBuffer + records[i][5] wBuffer = wBuffer + records[i][6] wBuffer = wBuffer + records[i][7] wBuffer = wBuffer + records[i][8] wBuffer = wBuffer + records[i][9] wBuffer = wBuffer + records[i][10] sfp.write(wBuffer + '\n') sfp.close() elif(TradeContext.procFlag=="1"): #从第三方获取发票信息,进行打印 #=====================获取平台流水号==================================== if( not AfaFunc.GetSerialno( ) ): raise AfaFlowControl.flowException( ) #=====================外调接口(前处理)================================== subModuleExistFlag=0 subModuleName = 'T'+TradeContext.TemplateCode+'_'+TradeContext.TransCode try: subModuleHandle=__import__( subModuleName ) except Exception, e: AfaLoggerFunc.tradeInfo( e) else: AfaLoggerFunc.tradeInfo( '执行['+subModuleName+']模块' ) subModuleExistFlag=1 if not subModuleHandle.SubModuleDoFst( ) : raise AfaFlowControl.flowException( ) #与通讯前置交换 AfaAfeFunc.CommAfe() if TradeContext.errorCode!='0000' : raise AfaFlowControl.flowException( ) #发票数量 TradeContext.billNum = Party3Context.billNum if ( TradeContext.TransType=='0' ): #变量初始化 TradeContext.billData = [] #发票信息 TradeContext.item1 = [] #附加项1 TradeContext.item2 = [] #附加项2 TradeContext.item3 = [] #附加项3 TradeContext.item4 = [] #附加项4 TradeContext.item5 = [] #附加项5 TradeContext.item6 = [] #附加项6 TradeContext.billserno= [] #发票序号 TradeContext.serialno = [] #中间业务流水号 TradeContext.prtnum = [] #打印次数 TradeContext.paydate = [] #支付日期 if ( int(Party3Context.billNum) == 1 ): #打包(一张发票) TradeContext.billData = Party3Context.billData TradeContext.item1 = Party3Context.item1 TradeContext.item2 = Party3Context.item2 TradeContext.item3 = Party3Context.item3 TradeContext.item4 = Party3Context.item4 TradeContext.item5 = Party3Context.item5 TradeContext.item6 = Party3Context.item6 TradeContext.billserno = Party3Context.billserno TradeContext.serialno = Party3Context.serialno TradeContext.prtnum = Party3Context.prtnum TradeContext.paydate = Party3Context.paydate else: #打包(多张发票) for i in range( 0, int(Party3Context.billNum) ): TradeContext.billData.append(Party3Context.billData[i]) TradeContext.item1.append(Party3Context.item1[i]) TradeContext.item2.append(Party3Context.item2[i]) TradeContext.item3.append(Party3Context.item3[i]) TradeContext.item4.append(Party3Context.item4[i]) TradeContext.item5.append(Party3Context.item5[i]) TradeContext.item6.append(Party3Context.item6[i]) TradeContext.billserno.append(Party3Context.billserno[i]) TradeContext.serialno.append(Party3Context.serialno[i]) TradeContext.prtnum.append(Party3Context.prtnum[i]) TradeContext.paydate.append(Party3Context.paydate[i]) else: MxFileName = os.environ['AFAP_HOME'] + '/tmp/MX' + TradeContext.zoneno + TradeContext.brno + TradeContext.tellerno + '.TXT' AfaLoggerFunc.tradeInfo('>>>明细文件:['+MxFileName+']') if (os.path.exists(MxFileName) and os.path.isfile(MxFileName)): #文件存在,先删除-再创建 os.system("rm " + MxFileName) #创建明细文件 sfp = open(MxFileName, "w") if ( int(Party3Context.billNum) == 1 ): #打包(一张发票) wBuffer = "" wBuffer = wBuffer + Party3Context.billData wBuffer = wBuffer + Party3Context.item1 wBuffer = wBuffer + Party3Context.item2 wBuffer = wBuffer + Party3Context.item3 wBuffer = wBuffer + Party3Context.item4 wBuffer = wBuffer + Party3Context.item5 wBuffer = wBuffer + Party3Context.item6 wBuffer = wBuffer + Party3Context.billserno wBuffer = wBuffer + Party3Context.serialno wBuffer = wBuffer + Party3Context.prtnum wBuffer = wBuffer + Party3Context.paydate sfp.write(wBuffer + '\n') sfp.close() else: #打包(多张发票) for i in range( 0, int(Party3Context.billNum) ): wBuffer = "" wBuffer = wBuffer + Party3Context.billData[i] wBuffer = wBuffer + Party3Context.item1[i] wBuffer = wBuffer + Party3Context.item2[i] wBuffer = wBuffer + Party3Context.item3[i] wBuffer = wBuffer + Party3Context.item4[i] wBuffer = wBuffer + Party3Context.item5[i] wBuffer = wBuffer + Party3Context.item6[i] wBuffer = wBuffer + Party3Context.billserno[i] wBuffer = wBuffer + Party3Context.serialno[i] wBuffer = wBuffer + Party3Context.prtnum[i] wBuffer = wBuffer + Party3Context.paydate[i] sfp.write(wBuffer + '\n') sfp.close() #=====================外调接口(后处理)================================== if ( subModuleExistFlag==1 ) : if not subModuleHandle.SubModuleDoSnd(): raise AfaFlowControl.flowException( ) #=====================自动打包========================================== TradeContext.errorCode = '0000' TradeContext.errorMsg = '交易成功' AfaFunc.autoPackData() #=====================程序退出========================================== AfaLoggerFunc.tradeInfo('******代收代付.补打发票模板[' + TradeContext.TemplateCode + ']退出******' )
if ( not AfaFsFunc.Cancel_ChkVariableExist( ) ): raise AfaFlowControl.flowException( ) #=============判断应用状态==================== if( not AfaFsFunc.ChkAppStatus( ) ): raise AfaFlowControl.flowException( ) #=============判断反交易数据是否匹配原交易==================== if( not AfaFsFunc.ChkRevInfo( TradeContext.preAgentSerno ) ): raise AfaFlowControl.flowException( ) #=============获取平台流水号==================== if( not AfaFunc.GetSerialno( ) ): raise AfaFlowControl.flowException( ) #=============转换==================== TradeContext.channelCode = "005" TradeContext.userno = TradeContext.userNo TradeContext.tellerno = TradeContext.teller TradeContext.cashTelno = TradeContext.teller TradeContext.unitno = "00000001" TradeContext.subUnitno = "00000000" if (TradeContext.catrFlag == '0'): #现金 TradeContext.accType = "000" else: TradeContext.accType = "001"
def TrxMain( ): AfaLoggerFunc.tradeInfo('**********录入企业信息(8423)开始**********') #TradeContext.tradeResponse.append(['O1AFAPDATE', TradeContext.TranDate]) #工作日期 #TradeContext.tradeResponse.append(['O1AFAPTIME', TradeContext.TranTime]) #工作时间 #判断单位协议是否有效 if ( not NGSFAbdtFunc.ChkUnitInfo( ) ): return False #判断企业协议是否存在 if ( not ChkCustInfo( ) ): return False #查询账户信息(主机) if ( not NGSFAbdtFunc.QueryAccInfo( ) ): return False #合法性校验 AfaLoggerFunc.tradeInfo('>>>判断银行账户状态') if ( TradeContext.ACCSTATUS != "0"): return ExitSubTrade( '9000', '客户银行账户状态异常,不能进行注册' ) #AfaLoggerFunc.tradeInfo('>>>判断是否需要校验证件号码') #if ( TradeContext.I1IDCHKFLAG == "1" ): # if (TradeContext.IDCODE != TradeContext.I1IDCODE): # return ExitSubTrade( '9000', '客户证件号码不正确,不能进行注册' ) AfaLoggerFunc.tradeInfo('>>>判断是否需要校验客户姓名') if (TradeContext.USERNAME != TradeContext.PayerName): return ExitSubTrade( '9000', '客户名称不正确,不能进行注册' ) #自动生成企业协议编号 if ( AfaFunc.GetSerialno() < 0 ): return ExitSubTrade( '9000', '生成企业协议编号失败' ) #组织企业协议编码(交易日期 + 中间业务流水号) TradeContext.Protocolno = TradeContext.TranDate + TradeContext.agentSerialno #签约方式 三方签约 #if (TradeContext.SIGNUPMODE=="1"): # #系统标识 # TradeContext.sysId = TradeContext.Appno + TradeContext.PayeeUnitno # # #不使用转换返回码 # TradeContext.__respFlag__="0" # # AfaAfeFunc.CommAfe() # # if TradeContext.errorCode!='0000' : # return ExitSubTrade( TradeContext.errorCode, TradeContext.errorMsg ) #增加企业协议信息 if ( not InsertCustInfo( ) ): return False AfaLoggerFunc.tradeInfo('**********录入企业信息(8423)结束**********') #返回 TradeContext.tradeResponse.append(['errorCode', '0000']) TradeContext.tradeResponse.append(['errorMsg', '交易成功']) return True
def TrxMain( ): AfaLoggerFunc.tradeInfo('**********录入个人信息(8404)开始**********') TradeContext.tradeResponse.append(['O1AFAPDATE', TradeContext.TranDate]) #工作日期 TradeContext.tradeResponse.append(['O1AFAPTIME', TradeContext.TranTime]) #工作时间 #判断单位协议是否有效 if ( not AbdtFunc.ChkUnitInfo( ) ): return False #判断个人协议是否存在 if ( not ChkCustInfo( ) ): return False #查询账户信息(主机) if ( not AbdtFunc.QueryAccInfo( ) ): return False #合法性校验 AfaLoggerFunc.tradeInfo('>>>判断银行账户状态') if ( TradeContext.ACCSTATUS != "0"): return ExitSubTrade( '9000', '客户银行账户状态异常,不能进行注册' ) AfaLoggerFunc.tradeInfo('>>>判断是否需要校验证件号码') if ( TradeContext.I1IDCHKFLAG == "1" ): if (TradeContext.IDCODE != TradeContext.I1IDCODE): return ExitSubTrade( '9000', '客户证件号码不正确,不能进行注册' ) AfaLoggerFunc.tradeInfo('>>>判断是否需要校验客户姓名') if ( TradeContext.I1NAMECHKFLAG == "1"): if (TradeContext.USERNAME != TradeContext.I1USERNAME): return ExitSubTrade( '9000', '客户名称不正确,不能进行注册' ) #自动生成个人协议编号 if ( AfaFunc.GetSerialno() < 0 ): return ExitSubTrade( '9000', '生成个人协议编号失败' ) #组织个人协议编码(交易日期 + 中间业务流水号) TradeContext.PROTOCOLNO = TradeContext.TranDate + TradeContext.agentSerialno #签约方式 if (TradeContext.SIGNUPMODE=="1"): #系统标识 TradeContext.sysId = TradeContext.I1APPNO + TradeContext.I1BUSINO #不使用转换返回码 TradeContext.__respFlag__="0" AfaAfeFunc.CommAfe() if TradeContext.errorCode!='0000' : return ExitSubTrade( TradeContext.errorCode, TradeContext.errorMsg ) #增加个人协议信息 if ( not InsertCustInfo( ) ): return False AfaLoggerFunc.tradeInfo('**********录入个人信息(8404)结束**********') #返回 TradeContext.tradeResponse.append(['errorCode', '0000']) TradeContext.tradeResponse.append(['errorMsg', '交易成功']) return True