private void DeleteBankTran(PosInOutputData thePosInputData, PosInOutputData theOutPutData) { LogService.GlobalInfoMessage("HIS处理失败,请用银行的撤消交易开始!"); DateTime dtCurrenTime = new CommonFacade().GetServerDateTime(); PosInOutputData theCancelInput = new PosInOutputData(); theCancelInput.TransType = "02"; theCancelInput.TransAmount = thePosInputData.TransAmount; theCancelInput.TransDate = dtCurrenTime.ToString("yyyyMMdd"); theCancelInput.TransTime = dtCurrenTime.ToString("HHmmss"); theCancelInput.HISLSH = thePosInputData.HISLSH.Trim() + "R"; theCancelInput.ReceiptNo = theOutPutData.ReceiptNo; theCancelInput.RefNo = theOutPutData.RefNo; StringBuilder sbInput = new StringBuilder(theCancelInput.GetInput()); try { StringBuilder sbOutPut = new StringBuilder(150); //调用银行交易 int intResult = Pos_ECRCOMM(sbInput, sbOutPut); if (intResult != 1) { throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult); } } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法ECRCOMM失败:" + ex.Message); throw ex; } }
/// <summary> /// 交易方法 /// </summary> /// <param name="TranType">交易类型,1为消费,2消费确认,-2取消消费,5签到,6结算</param> /// <param name="htParams">交易参数,HIS流水号,病人ID,金额</param> /// <returns></returns> public override int Trans(string TranType, Hashtable htParams) { base.Trans(TranType, htParams); #region 消费 if (TranType == "1") { #region 组织参数 PosInOutputData thePosInOutputData = new PosInOutputData(); DateTime dtCurrenTime = new CommonFacade().GetServerDateTime(); thePosInOutputData.TransType = "01"; //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位 string strMoney = CheckMoney(htParams, "MONEY"); thePosInOutputData.TransAmount = strMoney; thePosInOutputData.TransDate = dtCurrenTime.ToString("yyyyMMdd"); thePosInOutputData.TransTime = dtCurrenTime.ToString("HHmmss"); string Seqno = Check(htParams, "SEQNO"); thePosInOutputData.HISLSH = Seqno; string strDiagnoseID = Check(htParams, "DIAGNOSEID"); string CardID = Check(htParams, "CARDID"); #endregion #region 调用POS接口 StringBuilder sbInput = new StringBuilder(thePosInOutputData.GetInput()); StringBuilder sbOutPut = new StringBuilder(256); PosInOutputData theOutputData = null; try { //调用银行交易的第一次调用 int intResult = Pos_ECRCOMM(sbInput, sbOutPut); if (intResult != 1) { if (intResult == -37 || intResult == -38 || intResult == -44) { thePosInOutputData.TransType = "03"; sbInput = new StringBuilder(thePosInOutputData.GetInput()); //如果第二次调用 intResult = Pos_ECRCOMM(sbInput, sbOutPut); if (intResult != 1) { if (intResult == -37 || intResult == -38 || intResult == -44) { //第三次调用 intResult = Pos_ECRCOMM(sbInput, sbOutPut); if (intResult != 1) { throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult); } } } } else { throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult); } } } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法ECRCOMM失败:" + ex.Message); throw ex; } try { theOutputData = new PosInOutputData(sbOutPut); } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法成功,解析银行返回字符串失败:" + ex.Message); throw ex; } #endregion #region 保存POS结算结果 try { TBankhisexchangeTransData data = new TBankhisexchangeTransData(); //银行行号+批次号+授权号 data.Remark = theOutputData.CardType + "|" + theOutputData.BatchNo + "|" + theOutputData.ApprovalCode; //银行卡号 data.ITEM1 = theOutputData.CardNumber; //凭证号 data.Bankseqno = theOutputData.ReceiptNo; //金额 data.Trfamt = Check(htParams, "MONEY"); //商户号 data.Buscd = theOutputData.MerchantID; //终端号 data.TerminalNo = theOutputData.TerminalID; //批次号 data.ITEM2 = theOutputData.BatchNo; //交易日期 data.Operatetime = theOutputData.YHJYSJ; data.Operatorid = SysOperatorInfo.OperatorID; //交易参考号 data.Ohisseqno = theOutputData.RefNo; data.Usetype = "充值"; data.Hisid = CardID; data.DIAGNOSEID = strDiagnoseID; data.Hisseqno = Seqno; data.DataSources = "自助"; data.BusinessType = "POS充值"; data.Bankstate = "0"; data.Hisstate = "0"; TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade(); facade.Insert(data); LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!"); htParams.Add("CARDNO", theOutputData.CardNumber); htParams.Add("BANKSEQNO", theOutputData.RefNo + "|" + theOutputData.ReceiptNo); } catch (Exception ex) { LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message); DeleteBankTran(thePosInOutputData, theOutputData); throw ex; } #endregion } #endregion #region 消费确认 if (TranType == "2") { //更新交易中间层的记录标识T_BANKHISEXCHANGE_RECORD TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade(); string Seqno = Check(htParams, "SEQNO"); facade.UpdateState(Seqno, "HISSTATE", "1"); } #endregion #region 消费撤消 if (TranType == "-2") { //根据交易流水号查询HIS中已经存在的交易记录 string Seqno = Check(htParams, "SEQNO"); string strDiagnoseID = Check(htParams, "DIAGNOSEID"); string CardID = Check(htParams, "CARDID"); TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade(); EntityList <TBankhisexchangeTransData> list = facade.Get("HISSEQNO = '" + Seqno + "'"); if (list.Count > 0) { #region 如果已经存在,则调用撤消方法 #region 组织相关参数 LogService.GlobalInfoMessage("HIS处理失败,请用银行的撤消交易开始!"); PosInOutputData thePosInOutputData = new PosInOutputData(); DateTime dtCurrenTime = new CommonFacade().GetServerDateTime(); thePosInOutputData.TransType = "02"; //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位 decimal decMoney = 0; decimal.TryParse(list[0].Trfamt, out decMoney); string strMoney = GetMoneyString(list[0].Trfamt); thePosInOutputData.TransAmount = strMoney; thePosInOutputData.TransDate = dtCurrenTime.ToString("yyyyMMdd"); thePosInOutputData.TransTime = dtCurrenTime.ToString("HHmmss"); Seqno = list[0].Hisseqno + "R"; thePosInOutputData.HISLSH = Seqno; thePosInOutputData.ReceiptNo = list[0].Bankseqno; #endregion #region 调用POS接口 StringBuilder sbInput = new StringBuilder(thePosInOutputData.GetInput()); StringBuilder sbOutPut = new StringBuilder(150); PosInOutputData theOutputData = null; try { //调用银行交易 int intResult = Pos_ECRCOMM(sbInput, sbOutPut); if (intResult != 1) { throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult); } } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法ECRCOMM失败:" + ex.Message); throw ex; } try { theOutputData = new PosInOutputData(sbOutPut); } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法成功,解析银行返回字符串失败:" + ex.Message); throw ex; } #endregion #region 保存POS结算结果 try { TBankhisexchangeTransData data = new TBankhisexchangeTransData(); //银行行号+批次号+授权号 data.Remark = theOutputData.CardType + "|" + theOutputData.BatchNo + "|" + theOutputData.ApprovalCode; //银行卡号 data.ITEM1 = theOutputData.CardNumber; //凭证号 data.Bankseqno = theOutputData.ReceiptNo; //金额 data.Trfamt = (decMoney * (-1)).ToString(); //商户号 data.Buscd = theOutputData.MerchantID; //终端号 data.TerminalNo = theOutputData.TerminalID; //批次号 data.ITEM2 = theOutputData.BatchNo; //交易日期 data.Operatetime = theOutputData.YHJYSJ; data.Operatorid = SysOperatorInfo.OperatorID; //交易参考号 data.Ohisseqno = theOutputData.RefNo; data.Usetype = "充值冲正"; data.Hisid = CardID; data.DIAGNOSEID = strDiagnoseID; data.Hisseqno = Seqno; data.DataSources = "自助"; data.BusinessType = "POS冲正"; data.Bankstate = "1"; data.Hisstate = "1"; facade.Insert(data); LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!"); //htParams.Add("CARDNO", theOutputData.CardNumber); //htParams.Add("BANKSEQNO", theOutputData.RefNo + "|" + theOutputData.ReceiptNo); } catch (Exception ex) { LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message); //DeleteBankTran(thePosInOutputData, theOutputData); throw ex; } #endregion #endregion } else { LogService.GlobalInfoMessage("HIS结算失败,调用银行冲正查询数据未找到,条件:" + "HISSEQNO = '" + Seqno + "'"); } } #endregion #region 签到 if (TranType == "5") { } #endregion #region 结算 if (TranType == "6") { } #endregion return(0); }
/// <summary> /// 交易方法 /// </summary> /// <param name="TranType">交易类型,1为消费,2消费确认,-2取消消费,5签到,6结算</param> /// <param name="htParams">交易参数,HIS流水号,病人ID,金额</param> /// <returns></returns> public override int Trans(string TranType, Hashtable htParams) { base.Trans(TranType, htParams); #region 消费 if (TranType == "1") { #region 组织参数 //POS机号使用自助机的编号 string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8); //POS机操作员 strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' '); //交易类型 strInput += "00"; //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位 string strMoney = CheckMoney(htParams, "MONEY"); strInput += strMoney; //原交易日期 strInput += "".PadRight(8, ' '); //原交易参考号 strInput += "".PadRight(12, ' '); //原凭证号 strInput += "".PadRight(6, ' '); //LRC校验 Random rm = new Random(); int intrm = rm.Next(100, 999); strInput += intrm.ToString(); string strDiagnoseID = Check(htParams, "DIAGNOSEID"); string Seqno = Check(htParams, "SEQNO"); string CardID = Check(htParams, "CARDID"); #endregion #region 调用POS接口 StringBuilder sbInput = new StringBuilder(strInput); StringBuilder sbOutPut = new StringBuilder(150); OutputData theOutputData = null; try { //调用银行交易 Pos_BankAll(sbInput, sbOutPut); theOutputData = new OutputData(sbOutPut); } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法bankall失败:" + ex.Message); throw ex; } #endregion #region 保存POS结算结果 try { DateTime ServerDate = new CommonFacade().GetServerDateTime(); TBankhisexchangeTransData data = new TBankhisexchangeTransData(); //银行行号+批次号+授权号 data.Remark = theOutputData.BankCode + "|" + theOutputData.BatchNo + "|" + theOutputData.LicenseNo; //银行卡号 data.ITEM1 = theOutputData.CardNo; //凭证号 data.Bankseqno = theOutputData.VoucherNo; //金额 data.Trfamt = theOutputData.TranMoney.ToString(); //商户号 data.Buscd = theOutputData.MchId; //终端号 data.TerminalNo = theOutputData.TerminalNo; //批次号 data.ITEM2 = theOutputData.BatchNo; //交易日期 data.Operatetime = theOutputData.YHJYSJ; data.Operatorid = SysOperatorInfo.OperatorID; //交易参考号 data.Ohisseqno = theOutputData.RefNo; data.Usetype = "充值"; data.Hisid = CardID; data.DIAGNOSEID = strDiagnoseID; data.Hisseqno = Seqno; data.DataSources = "自助"; data.BusinessType = "POS充值"; data.Bankstate = "0"; data.Hisstate = "0"; TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade(); facade.Insert(data); LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!"); htParams.Add("CARDNO", theOutputData.CardNo); htParams.Add("BANKSEQNO", theOutputData.RefNo + "|" + theOutputData.VoucherNo); } catch (Exception ex) { LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message); DeleteBankTran(htParams, theOutputData.VoucherNo); throw ex; } #endregion } #endregion #region 消费确认 if (TranType == "2") { //更新交易中间层的记录标识T_BANKHISEXCHANGE_RECORD TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade(); string Seqno = Check(htParams, "SEQNO"); facade.UpdateState(Seqno, "HISSTATE", "1"); } #endregion #region 消费撤消 if (TranType == "-2") { //根据交易流水号查询HIS中已经存在的交易记录 string Seqno = Check(htParams, "SEQNO"); string strDiagnoseID = Check(htParams, "DIAGNOSEID"); string CardID = Check(htParams, "CARDID"); TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade(); EntityList <TBankhisexchangeTransData> list = facade.Get("HISSEQNO = '" + Seqno + "'"); if (list.Count > 0) { #region 如果已经存在,则调用撤消方法 #region 组织相关参数 LogService.GlobalInfoMessage("HIS处理失败,请用银行的撤消交易开始!"); //POS机号使用自助机的编号 string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8); //POS机操作员 strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' '); //交易类型 strInput += "01"; //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位 string strMoney = CheckMoney(htParams, "MONEY"); strInput += strMoney; //原交易日期 strInput += "".PadRight(8, ' '); //原交易参考号 strInput += "".PadRight(12, ' '); //原凭证号 strInput += list[0].Bankseqno; //LRC校验 Random rm = new Random(); int intrm = rm.Next(100, 999); strInput += intrm.ToString(); #endregion #region 调用POS接口 StringBuilder sbInput = new StringBuilder(strInput); StringBuilder sbOutPut = new StringBuilder(150); OutputData theOutputData = null; try { //调用银行交易 Pos_BankAll(sbInput, sbOutPut); theOutputData = new OutputData(sbOutPut); } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法bankall失败:" + ex.Message); throw ex; } #endregion #region 保存POS结算结果 try { facade.UpdateState(Seqno, "HISSTATE", "-1"); DateTime ServerDate = new CommonFacade().GetServerDateTime(); TBankhisexchangeTransData data = new TBankhisexchangeTransData(); //银行行号+批次号+授权号 data.Remark = theOutputData.BankCode + "|" + theOutputData.BatchNo + "|" + theOutputData.LicenseNo; //银行卡号 data.ITEM1 = theOutputData.CardNo; //凭证号 data.Bankseqno = theOutputData.VoucherNo; //金额 data.Trfamt = (theOutputData.TranMoney * -1).ToString(); //商户号 data.Buscd = theOutputData.MchId; //终端号 data.TerminalNo = theOutputData.TerminalNo; //批次号 data.ITEM2 = theOutputData.BatchNo; //交易日期 data.Operatetime = theOutputData.YHJYSJ; data.Operatorid = SysOperatorInfo.OperatorID; //交易参考号 data.Ohisseqno = theOutputData.RefNo; data.Usetype = "冲正"; data.Hisid = CardID; data.DIAGNOSEID = strDiagnoseID; data.Hisseqno = Seqno + "R"; data.DataSources = "自助"; data.BusinessType = "POS充值"; data.Bankstate = "0"; data.Hisstate = "-2"; facade.Insert(data); LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!"); } catch (Exception ex) { LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message); throw ex; } #endregion #endregion } else { LogService.GlobalInfoMessage("HIS结算失败,调用银行冲正查询数据未找到,条件:" + "HISSEQNO = '" + Seqno + "'"); } } #endregion #region 签到 if (TranType == "5") { string PosNo = Check(htParams, "POSNO").Trim(); //判断当天是否已经进行签到,如果签到不再进行签到 DateTime ServerDate = new CommonFacade().GetServerDateTime(); string Currdate = ServerDate.ToString("yyyyMMdd"); HealthCardAuthkeyFacade theAuthKeyfacade = new HealthCardAuthkeyFacade(); HealthCardAuthkeyData theEntitydata = theAuthKeyfacade.GetByPrimaryKey(PosNo, Currdate); if (theEntitydata != null) { return(0); } try { Trans("6", htParams); } catch (Exception ex) { LogService.GlobalInfoMessage("调用 POS结算业务失败:" + ex.Message); } #region 组织参数 //POS机号使用自助机的编号 string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8); //POS机操作员 strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' '); //交易类型 strInput += "05"; //获取交易金额 strInput += "000000000000"; //原交易日期 strInput += "".PadRight(8, ' '); //原交易参考号 strInput += "".PadRight(12, ' '); //原凭证号 strInput += "".PadRight(6, ' '); //LRC校验 Random rm = new Random(); int intrm = rm.Next(100, 999); strInput += intrm.ToString(); #endregion #region 调用POS接口 StringBuilder sbInput = new StringBuilder(strInput); StringBuilder sbOutPut = new StringBuilder(150); OutputData theOutputData = null; try { //调用银行交易 Pos_BankAll(sbInput, sbOutPut); theOutputData = new OutputData(sbOutPut); theEntitydata = new HealthCardAuthkeyData(); theEntitydata.Orgcode = PosNo; theEntitydata.Username = Currdate; theEntitydata.Authkey = theOutputData.MchId + "|" + theOutputData.TranTime; theAuthKeyfacade.Insert(theEntitydata); LogService.GlobalInfoMessage("调用银行交易方法bankall签到交易成功!"); } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法bankall签到失败:" + ex.Message); throw ex; } #endregion } #endregion #region 结算 if (TranType == "6") { #region 组织参数 //POS机号使用自助机的编号 string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8); //POS机操作员 strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' '); //交易类型 strInput += "06"; //获取交易金额 strInput += "000000000000"; //原交易日期 strInput += "".PadRight(8, ' '); //原交易参考号 strInput += "".PadRight(12, ' '); //原凭证号 strInput += "".PadRight(6, ' '); //LRC校验 Random rm = new Random(); int intrm = rm.Next(100, 999); strInput += intrm.ToString(); #endregion #region 调用POS接口 StringBuilder sbInput = new StringBuilder(strInput); StringBuilder sbOutPut = new StringBuilder(150); OutputData theOutputData = null; try { //调用银行交易 Pos_BankAll(sbInput, sbOutPut); theOutputData = new OutputData(sbOutPut); LogService.GlobalInfoMessage("调用银行交易方法bankall结算交易成功!"); } catch (Exception ex) { LogService.GlobalInfoMessage("调用银行交易方法bankall结算失败:" + ex.Message); throw ex; } #endregion } #endregion return(0); }