소스 검색

feat: 移动支付退费

zhengjie 1 년 전
부모
커밋
332553ef88
6개의 변경된 파일416개의 추가작업 그리고 31개의 파일을 삭제
  1. 7 2
      Business/AbstractProcess.cs
  2. 374 0
      Business/Local/LocalMobilePayProcess.cs
  3. 28 14
      Helper/InvokeHelper.cs
  4. 3 4
      Helper/JsonHelper.cs
  5. 2 11
      InsuBusiness.cs
  6. 2 0
      Variables/Struct.cs

+ 7 - 2
Business/AbstractProcess.cs

@@ -63,10 +63,15 @@ namespace PTMedicalInsurance.Business
 
         protected CallResult IrisReturn(string msg,JObject obj)
         {
-            outParam = JsonHelper.setIrisReturnValue(0, msg, obj).ToString();
-            return new CallResult(0, msg, outParam);
+            return IrisReturn(0, msg, obj);
+        }
+        protected CallResult IrisReturn(int code,string msg, JObject obj)
+        {
+            outParam = JsonHelper.setIrisReturnValue(code, msg, obj).ToString();
+            return new CallResult(code, msg, outParam);
         }
 
+
         /// <summary>
         /// 返回失败信息
         /// </summary>

+ 374 - 0
Business/Local/LocalMobilePayProcess.cs

@@ -168,10 +168,190 @@ namespace PTMedicalInsurance.Business
                 return Exception(-1, "保存结算信息失败",errMsg);
             }
 
+            // 返回给HIS
+            if (returnToHis(joSettle, out errMsg) != 0)
+            {
+                outParam = errMsg;
+                return Exception(-1,"返回结算信息给HIS失败",errMsg);
+            }
+
             MobilePayConfirmSettlement(joSettle,out outParam);
             return IrisReturn("结算成功",null);
         }
 
+        public CallResult Cancel(JObject input)
+        {
+            init(input);
+            int ret = MobilePayCancelSettlement(out outParam);
+           if(ret !=0)
+            {
+                return IrisReturn(-1,"退费失败", JObject.Parse(outParam));
+            }
+            return IrisReturn("退费成功", null);
+        }
+
+        public int MobilePayCancelSettlement(out string outPar)
+        {
+            string errMsg;
+            outPar = "";
+            try
+            {
+                if (MSettl.onlineYBFalg != "Y")
+                {
+                    Global.businessType = "01301"; //结算
+                    //读电子凭证
+                    if (ReadEc(out errMsg) != 0)
+                    {
+                        outPar = errMsg;
+                        return -1;
+                    }
+                }
+
+               
+                //获取6203入参
+                if (Get6203Inpar(out errMsg) != 0)
+                {
+                    outPar = errMsg;
+                    return -1;
+                }
+                JObject joInput = JObject.Parse(errMsg);
+                // 调用his服务(移动支付院内退款服务)
+                JObject jo6203Rtn = invoker.invokeHISService(JsonHelper.setIrisInpar("05110036", joInput).ToString(), "移动支付退费");
+                if (JsonHelper.parseIrisRtnValue(jo6203Rtn, out errMsg) != 0)
+                {
+                    outPar = errMsg;
+                    return -1;
+                }
+                else
+                {
+                    //处理撤销数据
+                    if (cancleSettlement(Global.pat.settlID, out errMsg) != 0)
+                    {
+                        outPar = errMsg;
+                        return -1;
+                    }
+                    joParam.Add("middleSettleFlag", "");
+                    //退HIS结算
+                    if (hIS.cancleSettlementInfo(joParam, out errMsg) != 0)
+                    {
+                        outPar = errMsg;
+                        return -1;
+                    }
+                    else
+                    {
+                        outPar = JsonHelper.setIrisReturnValue(0, errMsg, null).ToString();
+                        return 0;
+                    }
+                }
+
+
+            }
+            catch (Exception ex)
+            {
+                Global.writeLog("MobilePayCancelSettlement:" + ex.Message);
+                outPar = ex.Message;
+                return -1;
+            }
+        }
+
+        /// <summary>
+        /// 取消结算
+        /// </summary>
+        /// <param name="outParam"></param>
+        /// <returns></returns>
+        public int cancleSettlement(string newSettlID, out string outParam)
+        {
+            JObject joTmp = new JObject();
+            string errMsg = "";
+            try
+            {
+                joTmp.Add("HospitalDr", Global.inf.hospitalDr);
+                joTmp.Add("InterfaceDr", Global.inf.interfaceDr);
+                joTmp.Add("admID", MPat.adm_Dr);
+                joTmp.Add("mdtrt_id", MPat.mdtrtID);
+                joTmp.Add("setl_id", MPat.settlID);
+                joTmp.Add("new_setl_id", newSettlID);
+                joTmp.Add("updateUserID", Global.user.ID);
+                joTmp.Add("msgid", Global.curEvt.msgid);
+                joTmp.Add("OccurTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
+                JObject joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010052", joTmp).ToString(), "取消结算信息");
+
+                if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
+                {
+                    outParam = errMsg;
+                    return -1;
+                }
+                else
+                {
+                    outParam = JsonHelper.setExceptionJson(0, "云医保平台", "取消结算成功").ToString();
+                    return 0;
+                }
+            }
+            catch (Exception ex)
+            {
+                outParam = "取消结算信息:" + ex.Message;
+                return -1;
+            }
+        }
+
+        #region 读卡
+        public int ReadEc(out string outPar)
+        {
+            outPar = "";
+            try
+            {
+                PatientService patientService = new PatientService();
+                int ret = patientService.trade1161(out outPar);
+                if (ret != 0)
+                {
+                    return -1;
+                }
+                return 0;
+            }
+            catch (Exception ex)
+            {
+                outPar = ex.Message;
+                return -1;
+            }
+        }
+
+        public void setPatientByEc(JObject jo)
+        {
+            MPat.name = JsonHelper.getDestValue(jo, "userName");
+            MPat.IDNO = JsonHelper.getDestValue(jo, "idNo");
+            MPat.certType = JsonHelper.getDestValue(jo, "idType");
+            MPat.token = JsonHelper.getDestValue(jo, "ecToken");
+            MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "insuOrg");
+            MPat.payAuthNo = JsonHelper.getDestValue(jo, "authNo");
+            MPat.gend = JsonHelper.getDestValue(jo, "gender");
+            MPat.brdy = JsonHelper.getDestValue(jo, "birthday");
+            MPat.naty = JsonHelper.getDestValue(jo, "nationality");
+        }
+
+        #endregion
+
+        private int returnToHis(JObject joPreSettl,out string errMsg)
+        {
+            //返回给HIS后端 
+            //JObject joTmp = JObject.Parse(JsonHelper.getDestValue(joM6201Rtn, "encData"));
+            JObject joTmp = new JObject();
+            joTmp.Add("insutype", MPat.insuType);
+            joTmp.Add("psn_no", MPat.psn_no);
+            joTmp.Add("insuplc_admdvs", MPat.insuplc_admdvs);
+            joTmp.Add("mdtrtId", MPat.mdtrtID);
+            joTmp.Add("mdtrt_id", MPat.mdtrtID);
+            joTmp.Add("mdtrt_cert_type", JsonHelper.getDestValue(joPreSettl, "mdtrt_cert_type"));
+            joTmp.Add("mdtrt_cert_no", JsonHelper.getDestValue(joPreSettl, "certno"));
+            joTmp.Add("med_type", JsonHelper.getDestValue(joPreSettl, "med_type"));
+
+            if (returnMPSettlementInfo(joTmp, joPreSettl, out errMsg) != 0)
+            {
+                return -1;
+            }
+            return 0;
+
+        }
+
         private int MobilePayConfirmSettlement(JObject joSettlInfo,out string outPar)
         {
             string errMsg;
@@ -496,6 +676,91 @@ namespace PTMedicalInsurance.Business
             MPat.insuplc_admdvs = JsonHelper.getDestValue(jo, "data.InsuranceAreaCode");
         }
 
+
+        //组织M6203入参
+        public int Get6203Inpar(out string outparam)
+        {
+            string errMsg = "";
+            outparam = "";
+            try
+            {
+                JObject joInpar = new JObject();
+                //获取医保平台结算信息
+                if (QuerySettleInfo(out errMsg) != 0)
+                {
+                    outparam = errMsg;
+                    return -1;
+                }
+                JObject joRtn = JObject.Parse(errMsg);
+                string settlInfo = JsonHelper.getDestValue(joRtn, "result.data[0]");
+                if (string.IsNullOrEmpty(settlInfo))
+                {
+                    outparam = "没有查询到结算信息,请检查参数";
+                    return -1;
+                }
+
+                // 组织调用参数
+                Global.curEvt.msgid = Global.inf.hospitalNO + DateTime.Now.ToString("yyyyMMddHHmmssffff");
+                JObject joSettl = JObject.Parse(settlInfo);
+
+                MPat.settlID = JsonHelper.getDestValue(joSettl, "SettlementID");
+                //入参
+                joInpar.Add("outtradeno", JsonHelper.getDestValue(joSettl, "PayOrdID"));//支付订单号
+                joInpar.Add("appRefdSn", Global.curEvt.msgid);//应用退款流水号
+                string appRefdTime = JsonHelper.getDestValue(joInsuAdmObj, "appRefdTime");
+                if (string.IsNullOrEmpty(appRefdTime))
+                {
+                    appRefdTime = Utils.GetDateTimeNow();
+                }
+                joInpar.Add("businessType", "DWREFUND");//应用退费时间
+                joInpar.Add("hospitalCode", Global.inf.hospitalNO);
+                joInpar.Add("ec_code", Global.pat.ecToken);
+                joInpar.Add("patName", Global.pat.name);
+                joInpar.Add("idType", "01");
+                joInpar.Add("idCardNo", Global.pat.IDNO);
+                outparam = joInpar.ToString();
+                return 0;
+            }
+            catch (Exception ex)
+            {
+
+                outparam = "Get6203Inpar:" + ex.Message;
+                return -1;
+            }
+            finally
+            {
+                Global.writeLog("Get6203Inpar", "", outparam);
+            }
+        }
+
+        //查询结算信息
+        public int QuerySettleInfo(out string errMsg)
+        {
+            errMsg = "";
+            try
+            {
+                string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE Hospital_Dr=  " + Global.inf.hospitalDr;
+                sqlStr = sqlStr + " and AdmType = 3 and Adm_Dr= " + MPat.adm_Dr + " and PayOrdID= '" + MPat.payOrdId + "'";
+                JObject joSqlstr = new JObject();
+                joSqlstr.Add("sqlStr", sqlStr);
+                JObject joRtn = mIS.DynamicQuerySettlInfo(joSqlstr);
+                if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
+                {
+                    return -1;
+                }
+                else
+                {
+                    errMsg = joRtn.ToString();
+                    return 0;
+                }
+            }
+            catch (Exception ex)
+            {
+                errMsg = ex.Message;
+                return -1;
+            }
+        }
+
         //获取入参,入参基本为类局部变量
         public int Get6301Inpar(out string outparam)
         {
@@ -536,6 +801,115 @@ namespace PTMedicalInsurance.Business
             }
         }
 
+        /// <summary>
+        /// 返回移动支付结算信息给HIS
+        /// </summary>
+        /// <param name="joSetlInpar"></param>
+        /// <param name="joSetlinfo"></param>中心返回的信息
+        /// <param name="outParam"></param>
+        /// <returns></returns>
+        public int returnMPSettlementInfo(JObject joReg, JObject joSettl, out string outParam)
+        {
+            string errMsg;
+            try
+            {
+                JObject joSumFee = new JObject();
+                if (sumInsuRtnSettlInfo(joSettl, out joSumFee, out errMsg) != 0)
+                {
+                    outParam = "返回结算结果给HIS失败,请联系管理员!" + errMsg;
+                    return -1;
+                }
+
+                dynamic joTmp = new JObject();
+                joTmp.settleInfo = joSettl;
+                joTmp.updateUserID = Global.user.ID;
+                joTmp.regInfo = joReg;
+                joTmp.middleSettleFlag = "";
+                joTmp.interfaceDr = Global.inf.interfaceDr;
+                dynamic joHisInfo = new JObject();
+                joHisInfo.admID = MPat.adm_Dr;
+                joHisInfo.billID = MPat.billID;
+                joHisInfo.recordID = MPat.recordID;
+                joTmp.hisInfo = joHisInfo;
+                joTmp.psn_type = MPat.psn_type;
+                joTmp.mobilePayFlag = "Y";
+                joTmp.sumFeeObj = joSumFee;
+                joTmp.mdtrtinfo = MPat.mdtrtID;
+                JObject joRtn = invoker.invokeHISService(JsonHelper.setIrisInpar("05110018", joTmp).ToString(), "返回移动支付结算结果给HIS");
+                if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
+                {
+                    outParam = "返回移动支付结算结果给HIS失败,请联系管理员!" + errMsg;
+                    return -1;
+                }
+                else
+                {
+                    joSumFee.Add("payAuthNo", MPat.payAuthNo);
+                    joSumFee.Add("payOrdId", MPat.payOrdId);
+                    joSumFee.Add("setlLatlnt", MPat.uldLatlnt);
+                    joSumFee.Add("org_no", Global.inf.hospitalNO);
+                    joSumFee.Add("medOrgOrd", MPat.recordID);
+                    joSumFee.Add("mdtrtId", MPat.mdtrtID);
+                    joSumFee.Add("gmt_out_create", MSettl.settlTime.ToString("yyyy-MM-dd HH:mm:ss"));
+                    joRtn["result"] = joSumFee;
+                    outParam = joRtn.ToString();
+                    return 0;
+                }
+            }
+            catch (Exception ex)
+            {
+                outParam = "返回移动支付结算结果给HIS出现异常:!" + ex.Message;
+                return -1;
+            }
+
+        }
+
+
+        /// <summary>
+        /// 汇总医保返回的结算金额(按照HIS的原则汇总,后期HIS按照这个来进行勾稽关系判断)
+        /// </summary>
+        /// <param name="jo"></param>
+        /// <returns></returns>
+        public int sumInsuRtnSettlInfo(JObject jo, out JObject joSumFee, out string errMsg)
+        {
+            //            医疗费总额是患者在医药机构花费的所有诊疗、药品、耗材、服务设施等项目费用的总和 = 基金支付总额 + 个人负担总金额 + 其他(如医院负担金额);
+            //3、基金支付总额 = 基本医保统筹基金支出(含职工基本医疗保险、居民基本医疗保险)+补充医疗保险基金支出 (含覆盖全体参保人的居民大病保险和大额医疗费用补助、覆盖部分参保人的企业职工大额医疗费用补助和公务员医疗补助等)+医疗救助基金支出 + 其他支出(如伤残人员医疗保障基金支出);
+            //5、个人账户支出中包含账户共济支付金额
+
+            joSumFee = new JObject();
+            errMsg = "";
+            decimal ybAmt, psnAcctAmt, hospAmt, psnCashAmt, medFee;
+            try
+            {
+                ybAmt = 0; psnAcctAmt = 0; hospAmt = 0; psnCashAmt = 0; medFee = 0;
+                ybAmt = MSettl.fundPaySumamt;
+                psnAcctAmt = MSettl.accountPaySumamt;
+                psnCashAmt = MSettl.personCashPay;
+                hospAmt = MSettl.hospitalPartAmount;
+                medFee = MSettl.sumamt;
+
+                joSumFee.Add("sumamt", medFee);
+                joSumFee.Add("ybAmt", ybAmt);
+                joSumFee.Add("psnAcctAmt", psnAcctAmt);
+                joSumFee.Add("hospAmt", hospAmt);
+                joSumFee.Add("psnCashAmt", psnCashAmt);
+
+                if (medFee != (ybAmt + psnAcctAmt + psnCashAmt + hospAmt))
+                {
+                    errMsg = "ybAmt(" + ybAmt.ToString() + ")+" + "psnAcctAmt(" + psnAcctAmt.ToString() + ")+" + "psnCashAmt(" + psnCashAmt.ToString() + ")+" + "hospAmt(" + hospAmt.ToString() + ")" + "!=medFee(" + medFee.ToString() + ")";
+                    return -1;
+                }
+
+                return 0;
+            }
+            catch (Exception ex)
+            {
+                errMsg = ex.Message;
+                return 1;
+            }
+
+        }
+
+
         private int MobilePayQuery(out string outPar)
         {
             string errMsg, M6301Inpar;

+ 28 - 14
Helper/InvokeHelper.cs

@@ -37,25 +37,42 @@ namespace PTMedicalInsurance.Helper
 
         public InvokeHelper()
         {
-            if (string.IsNullOrEmpty(Global.inf.centerURL))
+            LoadCenterURL(false);
+        }
+
+        private void LoadCenterURL(bool reloadFromCfgFile)
+        {
+            IniFile ini = new IniFile(Global.curEvt.path + @"\CenterServiceURL.ini");
+            // 默认采用的是后台配置的地址
+            if (reloadFromCfgFile)
             {
-                IniFile ini = new IniFile(Global.curEvt.path + @"\CenterServiceURL.ini");
                 Global.inf.centerURL = ini.ReadValue("CENTER", "url");
                 Global.inf.uploadURL = ini.ReadValue("CENTER", "upload");
                 Global.inf.downURL = ini.ReadValue("CENTER", "download");
                 Global.inf.ecURL = ini.ReadValue("CENTER", "ecToken");
             }
+            Global.inf.mobilePayURL = ini.ReadValue("CENTER", "mobilePay");
+            Global.inf.ecPrescURL = ini.ReadValue("CENTER", "prescription");
+            // 移动支付
+            if (string.IsNullOrEmpty(Global.inf.mobilePayURL))
+            {
+                Global.inf.mobilePayURL = "http://10.13.1.26:9001/CSB/hsa-fsi-no";
+            }
+            // 电子处方
+            if (string.IsNullOrEmpty(Global.inf.ecPrescURL))
+            {
+                Global.inf.ecPrescURL = "http://10.77.245.22:9001/epc/api";
+            }
         }
 
+            #region 内部服务调用
 
-        #region 内部服务调用
-
-        /// <summary>
-        /// iris服务调用的封装
-        /// </summary>
-        /// <param name="data"></param>
-        /// <returns></returns>
-        public JObject invokeIrisService(string data, string serviceDesc)
+            /// <summary>
+            /// iris服务调用的封装
+            /// </summary>
+            /// <param name="data"></param>
+            /// <returns></returns>
+            public JObject invokeIrisService(string data, string serviceDesc)
         {
             string rtn = "", url = "";
             JObject joRtn = new JObject();
@@ -334,13 +351,10 @@ namespace PTMedicalInsurance.Helper
             String outPar = "";
             try
             {
-                Global.curEvt.URL = Global.inf.centerURL + funNO;
+                Global.curEvt.URL = Global.inf.mobilePayURL;
                 joRtn = invokeCenterService(data);
                 outPar = JsonHelper.Compress(joRtn);
                 return joRtn;
-
-                
-
             }
             catch (Exception ex)
             {

+ 3 - 4
Helper/JsonHelper.cs

@@ -530,11 +530,10 @@ namespace PTMedicalInsurance.Helper
         {
             try
             {
-                string success = getDestValue(joRtn, "success");
-                string message = getDestValue(joRtn, "message");
-                string encData = getDestValue(joRtn, "encData");
+                string success = getDestValue(joRtn, "errorcode");
+                string message = getDestValue(joRtn, "errortext");
                 //Global.writeLog("success:" + success);
-                if (success != "True")
+                if (success != "0")
                 {
                     errorMsg = message;
                     return -1;

+ 2 - 11
InsuBusiness.cs

@@ -458,17 +458,8 @@ namespace PTMedicalInsurance
                     case "M6C"://门诊移动支付结算撤销
                         {
                             #region 移动支付取消
-                            //MobilePay mp = new MobilePay(InParam, out errMsg);
-                            //if (errMsg != "")
-                            //{
-                            //    rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", errMsg).ToString();
-                            //    return rtnResult;
-                            //}
-                            //if (mp.MobilePayCancelSettlement(out outParam) != 0)
-                            //    rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", outParam).ToString();
-                            //else
-                            //    rtnResult = outParam;
-                            //return rtnResult;
+                            LocalMobilePayProcess mp = new LocalMobilePayProcess();
+                            rtnResult = mp.Cancel(JObject.Parse(InParam)).Data;
                             #endregion
                             break;
                         }

+ 2 - 0
Variables/Struct.cs

@@ -42,6 +42,8 @@ namespace PTMedicalInsurance.Variables
         public string downURL;
         public string cardURL;
         public string ecURL;
+        public string mobilePayURL;
+        public string ecPrescURL;
         public string areaCode;
         public string dllName;
         public string version;