public string GetMZInsurance(request <getMZInsurance> getMZInsurance)
        {
            if (getMZInsurance == null)
            {
                return(RsXmlHelper.ResXml(-1, "XML格式错误"));
            }

            var ptInfo = ptInfoBLL.GetPtInfoByCardNo("", Convert.ToInt32(getMZInsurance.model.patCardType), getMZInsurance.model.patCardNo);

            if (ptInfo == null)
            {
                return(RsXmlHelper.ResXml(-1, "患者信息为空"));
            }

            var dept   = sysDeptBLL.GetDeptByCode(getMZInsurance.model.deptCode);
            var doctor = sysUserinfoBLL.GetRDoctor(getMZInsurance.model.doctorCode);

            var regInfo = reginfoBLL.Get(x => x.regid == Convert.ToInt32(getMZInsurance.model.mzFeeId));

            if (regInfo == null)
            {
                return(RsXmlHelper.ResXml(-1, "挂号信息为空"));
            }

            var orderInfoList   = orderInfoBLL.Get(getMZInsurance.model.mzFeeId, getMZInsurance.model.mzBillId);
            var orderFeedetails = orderfeedetailBLL.GetOrder_Feedetails(orderInfoList.Select(x => x.billid).ToArray());

            var ybsssno = commKeyBLL.GetYBNO();
            var ybSno   = "HZS10" + DateTime.Now.ToString("yyyyMMdd") + ybsssno;

            FY001 fY001 = new FY001()
            {
                akc190   = "HZS10" + regInfo.mzno,
                bke384   = ybSno,
                listsize = orderFeedetails.Count,
            };

            fY001.inputlist = new List <inputlistfy001>();
            foreach (var order_Feedetail in orderFeedetails)
            {
                if (order_Feedetail.itemtype == "中草药" || order_Feedetail.itemtype == "中成药" || order_Feedetail.itemtype == "西药")
                {
                    var commMed = commMedBLL.Get(x => x.itemid == order_Feedetail.itemid);
                    fY001.inputlist.Add(new inputlistfy001()
                    {
                        aae072 = order_Feedetail.billid.ToString(),
                        bkc369 = "1",
                        bkf500 = order_Feedetail.bdfeeid.ToString(),
                        ake001 = commMed.ybcode,
                        ake002 = commMed.itemname,
                        bkm017 = commMed.stdcode,
                        ake005 = commMed.itemid,
                        ake006 = commMed.itemname,
                        akc225 = order_Feedetail.prices.ToString(),
                        akc264 = order_Feedetail.totalprices.ToString(),
                        aka067 = commMed.bscunit,
                        aka070 = commYbCodeBLL.GetYbCodeByName("AKA070", commMed.dosage),
                        aka074 = commMed.spec,
                        akc226 = (Convert.ToInt32(order_Feedetail.total) * Convert.ToInt32(order_Feedetail.dppack)).ToString(),
                        akc271 = Convert.ToDateTime(order_Feedetail.addtime).ToString("yyyyMMdd"),
                        bkc320 = doctor.ybno
                    });
                }
                else
                {
                    var commFee   = new comm_fee();
                    var isPackage = commFeeBLL.IsPackage(x => x.itemid == order_Feedetail.itemid && x.costtype == "5");
                    if (isPackage)
                    {
                        commFee = commFeeBLL.Get(Convert.ToInt32(order_Feedetail.itemid));
                    }
                    else
                    {
                        commFee = commFeeBLL.Get(x => x.itemid == order_Feedetail.itemid && x.costtype == "5");
                    }
                    fY001.inputlist.Add(new inputlistfy001()
                    {
                        aae072 = order_Feedetail.billid.ToString(),
                        bkc369 = "1",
                        bkf500 = order_Feedetail.bdfeeid.ToString(),
                        ake001 = commFee.scode,
                        ake002 = commFee.itemname,
                        bkm017 = commFee.scode,
                        ake005 = commFee.itemid,
                        ake006 = commFee.itemname,
                        ala026 = "",
                        aka070 = "",
                        aka074 = order_Feedetail.spec,
                        akc225 = decimal.Round(Convert.ToDecimal(order_Feedetail.prices), 2).ToString(),
                        akc226 = Convert.ToInt32(order_Feedetail.total).ToString(),
                        akc264 = decimal.Round(Convert.ToDecimal(order_Feedetail.totalprices), 2).ToString(),
                        aka067 = order_Feedetail.dpunit,
                        akc271 = Convert.ToDateTime(order_Feedetail.addtime).ToString("yyyyMMdd"),
                        bkc320 = doctor.ybno,
                        cke400 = ""
                    });
                }
            }

            FY004 fY004 = new FY004()
            {
                akc190 = "HZS10" + regInfo.mzno,
                aka130 = "11",
                bkc320 = doctor.ybno,
                ckc350 = doctor.username,
                aka030 = "12",
                akc264 = Math.Round(Convert.ToDecimal(orderInfoList.Sum(x => x.totprice)), 2).ToString(),
                ckc601 = "0",
                bke384 = "HZS10" + DateTime.Now.ToString("yyyyMMdd") + ybsssno
            };

            var getVerifyCodeResult = JsonOperator.JsonDeserialize <Entity.SResponse.getVerifyCode>(HttpHelper.Post("http://192.168.88.134:8300/YBDLL/domain/getVerifyCode", JsonOperator.JsonSerialize(new getVerifyCode()
            {
                inParam = "FY001|" + ybSno + "|HZS10|"
            }), Encoding.UTF8, 1));

            if (getVerifyCodeResult.resultCode != 0 || getVerifyCodeResult.resultCode != 00000000)
            {
                return(RsXmlHelper.ResXml(-1, getVerifyCodeResult.resultMsg));
            }

            var version = getVerifyCodeResult.outParam.Split("|")[2];
            var verify  = getVerifyCodeResult.outParam.Split("|")[0] + "|" + getVerifyCodeResult.outParam.Split("|")[1];

            var resultFy001 = HealthInsuranceHelper.RegTrial <BaseMedInsurance <Entity.SResponse.FY001> >("FY001", version, verify, ybsssno.ToString(), fY001);

            if (resultFy001.transReturnCode != "0" && resultFy001.transReturnCode != "00000000")
            {
                return(RsXmlHelper.ResXml(-1, resultFy001.transReturnMessage + JsonOperator.JsonSerialize(fY001) + "出参:" + JsonOperator.JsonSerialize(resultFy001)));
            }

            getVerifyCodeResult = JsonOperator.JsonDeserialize <Entity.SResponse.getVerifyCode>(HttpHelper.Post("http://192.168.88.134:8300/YBDLL/domain/getVerifyCode", JsonOperator.JsonSerialize(new getVerifyCode()
            {
                inParam = "FY004|" + ybSno + "|HZS10|"
            }), Encoding.UTF8, 1));

            var result = HealthInsuranceHelper.RegTrial <BaseMedInsurance <Entity.SResponse.FY004> >("FY004", version, verify, ybsssno.ToString(), fY004);

            if (result.transReturnCode == "0" || result.transReturnCode == "00000000")
            {
                feeTrialBLL.Add(new fee_trial()
                {
                    akc190 = fY004.akc190,
                    aka130 = fY004.aka130,
                    bkc320 = fY004.bkc320,
                    ckc350 = fY004.ckc350,
                    aka030 = fY004.aka030,
                    akc264 = Convert.ToDecimal(fY004.akc264),
                    ckc601 = fY004.ckc601,
                    bke384 = fY004.bke384
                });

                return(XMLHelper.XmlSerialize(new response <Entity.SResponse.getMZInsurance>()
                {
                    model = new Entity.SResponse.getMZInsurance()
                    {
                        resultCode = 0,
                        mzFeeId = regInfo.regid,
                        mzBillId = string.Join(",", orderInfoList.Select(x => x.billid)),
                        time = DateTime.Now,
                        SSFeeNo = fY004.akc190,
                        SSSerNum = fY004.bke384,
                        recipeCount = orderInfoList.Count.ToString(),
                        mzCategory = "普通",
                        doctorCode = doctor.userno,
                        doctorName = doctor.username,
                        deptCode = dept.code,
                        deptName = dept.name,
                        payType = "医保",
                        payAmount = result.transBody.akb067.ToString(),
                        accountAmount = result.transBody.akb066.ToString(),
                        medicareAmount = result.transBody.akb068.ToString(),
                        insuranceAmout = (result.transBody.akb068 + result.transBody.akb066).ToString(),
                        totalAmout = result.transBody.akc264.ToString(),
                        akc190 = fY004.akc190,
                        cardArea = result.cardArea,
                        SSInfoNew = JsonOperator.JsonSerialize(result.transBody)
                    }
                }));
            }
            else
            {
                return(RsXmlHelper.ResXml(-1, result.transReturnMessage));
            }
        }
        public string OrderCurReg(request <Entity.SRequest.orderCurReg> orderCurRegInfo)
        {
            if (orderCurRegInfo == null)
            {
                return(RsXmlHelper.ResXml(-1, "XML格式错误"));
            }
            var feeinfo = feeinfoBLL.Get(orderCurRegInfo.model.psOrdNum);

            if (feeinfo != null)
            {
                return(XMLHelper.XmlSerialize(new response <Entity.SResponse.orderCurReg>()
                {
                    model = new Entity.SResponse.orderCurReg()
                    {
                        resultCode = 0,
                        resultMessage = "",
                        hisOrdNum = feeinfo.regid.ToString(),
                        treatFee = orderCurRegInfo.model.regFee
                    }
                }));
            }

            reg_arrange reg_Arrange = null;
            pt_info     pt_Info     = null;
            var         dept        = new sys_dept();
            var         doctor      = new sys_userinfo();


            if (!string.IsNullOrWhiteSpace(orderCurRegInfo.model.workId))
            {
                reg_Arrange = regArrangeBLL.GetReg_Arrange(Convert.ToInt32(orderCurRegInfo.model.workId));
            }
            else
            {
                dept        = sysDeptBLL.GetDeptByCode(orderCurRegInfo.model.deptCode);
                doctor      = sysUserinfoBLL.GetRDoctor(orderCurRegInfo.model.doctorCode);
                reg_Arrange = regArrangeBLL.GetReg_Arrange(dept.name, doctor.username, orderCurRegInfo.model.beginTime, orderCurRegInfo.model.endTime, Convert.ToInt32(orderCurRegInfo.model.timeFlag));
            }
            if (reg_Arrange == null)
            {
                return(RsXmlHelper.ResXml(-1, "无号源信息"));
            }

            var feetype = "";

            if (!string.IsNullOrWhiteSpace(orderCurRegInfo.model.SSCardNumber) && !string.IsNullOrWhiteSpace(orderCurRegInfo.model.SSCodeId))
            {
                feetype = "医疗保险";
                if (string.IsNullOrWhiteSpace(orderCurRegInfo.model.SSPwd))
                {
                    orderCurRegInfo.model.SSPwd = "000000";
                }
                pt_Info = ptInfoBLL.GetPt_Info(x => x.yno == orderCurRegInfo.model.SSCardNumber);
                if (pt_Info == null)
                {
                    pt_Info = ptInfoBLL.GetPt_Info(x => x.cno == orderCurRegInfo.model.patCardNo || x.idno == orderCurRegInfo.model.patCardNo);
                    if (string.IsNullOrWhiteSpace(pt_Info.yno))
                    {
                        pt_Info.yno = orderCurRegInfo.model.SSCardNumber;
                        ptInfoBLL.Update(pt_Info);
                    }
                }
            }
            else
            {
                feetype = "自费";
                pt_Info = ptInfoBLL.GetPt_Info(x => x.cno == orderCurRegInfo.model.patCardNo || x.idno == orderCurRegInfo.model.patCardNo);
            }

            var regInfo = reginfoBLL.Get(x => x.doctor == doctor.username && x.dept == dept.name && pt_Info.pid == x.pid && x.status == "候诊" && x.validate > DateTime.Now);

            if (regInfo != null && regInfo.del == true)
            {
                return(XMLHelper.XmlSerialize(new response <Entity.SResponse.orderCurReg>()
                {
                    model = new Entity.SResponse.orderCurReg()
                    {
                        resultCode = 0,
                        resultMessage = "",
                        hisOrdNum = regInfo.regid.ToString(),
                        treatFee = orderCurRegInfo.model.ghhj.ToString()
                    }
                }));
            }

            if (regInfo != null && regInfo.del == false)
            {
                return(RsXmlHelper.ResXml(-1, "你已挂当前科室号"));
            }

            var reg_Info = reginfoBLL.Add(new reg_info()
            {
                feetype = feetype
            }, pt_Info, reg_Arrange, orderCurRegInfo.model.orderNo, orderCurRegInfo.model.psOrdNum, out decimal amount, out int mzno, out int feeid, out List <comm_fee> commFees);

            if (reg_Info == null)
            {
                return(RsXmlHelper.ResXml(99, "挂号失败"));
            }

            if (feetype == "医疗保险")
            {
                var regtrialId = regTrialBLL.AddReturnId(new reg_trial()
                {
                    akc190 = "HZS10" + mzno,
                    aaz500 = orderCurRegInfo.model.SSCodeId,
                    bzz269 = orderCurRegInfo.model.SSPwd,
                    aka130 = "11",
                    akf001 = dept.ybno,
                    bkc368 = CodeConvertUtils.SwichRegType(reg_Arrange.regtype).ToString(),
                    bke384 = "HZS10" + DateTime.Now.ToString("yyyyMMdd") + feeid,
                    akc264 = commFees.Sum(x => x.prices),
                    regid  = reg_Info.regid
                });

                List <reg_trialdetail> reg_Trialdetails = new List <reg_trialdetail>();
                foreach (var commFee in commFees)
                {
                    reg_Trialdetails.Add(new reg_trialdetail()
                    {
                        regtrialid = regtrialId,
                        aae072     = commKeyBLL.GetYBDJH().ToString(),
                        bkf500     = commKeyBLL.GetYBXLH().ToString(),
                        ake001     = commFee.scode,
                        ake005     = commFee.itemid,
                        ake006     = commFee.itemname,
                        aae019     = commFee.prices
                    });
                }
                regTrialdetailBLL.Adds(reg_Trialdetails);
            }

            return(XMLHelper.XmlSerialize(new response <Entity.SResponse.orderCurReg>()
            {
                model = new Entity.SResponse.orderCurReg()
                {
                    resultCode = 0,
                    resultMessage = "",
                    hisOrdNum = reg_Info.regid.ToString(),
                    treatFee = amount.ToString()
                }
            }));
        }