Beispiel #1
0
        //private string GetCompanyId(string pid, string bid) {
        //    try
        //    {
        //        if (!string.IsNullOrWhiteSpace(pid))
        //        {
        //            BaseCompany company = CompanyServices.QueryByParkingId(pid);
        //            if (company != null)
        //            {
        //                return company.CPID;
        //            }
        //        }
        //        if (!string.IsNullOrWhiteSpace(bid))
        //        {
        //            BaseCompany company = CompanyServices.QueryByBoxID(bid);
        //            if (company != null)
        //            {
        //                return company.CPID;
        //            }
        //        }
        //    }
        //    catch (Exception ex) {
        //        ExceptionsServices.AddExceptionToDbAndTxt("QRCodeParkPayment", "GetCompanyId方法处理异常", ex, LogFrom.WeiXin);

        //    }
        //    return string.Empty;
        //}
        /// <summary>
        /// 计算停车费
        /// </summary>
        /// <param name="pid">车场编号</param>
        /// <param name="licensePlate">车牌号</param>
        /// <param name="bid">岗亭编号</param>
        /// <param name="gid">通道编号</param>
        /// <returns></returns>
        public ActionResult ComputeParkingFee(string pid, string licensePlate, string bid, string gid)
        {
            licensePlate = licensePlate.ToPlateNo();
            TxtLogServices.WriteTxtLogEx("QRCodeParkPayment", "进入ComputeParkingFee,pid:{0}, licensePlate:{1}, bid:{2},gid:{3},opendId:{4}", pid, licensePlate, bid, gid, WeiXinOpenId);
            bool IsShowPlateNumber = true;

            try
            {
                OnlineOrder model = new OnlineOrder();
                model.OrderTime = DateTime.Now;

                TempParkingFeeResult result = null;
                bool bClient = false;
                if (!string.IsNullOrWhiteSpace(gid))
                {
                    //result = RechargeService.WXScanCodeTempParkingFeeByGateID(pid, gid, string.Empty, GetOrderSource());
                    result = ParkingFeeService.GetParkingFeeByGateID(pid, gid);
                    if (result == null)
                    {
                        TxtLogServices.WriteTxtLogEx("QRCodeParkPayment", "GetParkingFeeByGateID Result:null");
                    }
                    else
                    {
                        bClient = true;
                        TxtLogServices.WriteTxtLogEx("QRCodeParkPayment", "GetParkingFeeByGateID Result:{0}", (int)result.Result);
                    }
                    if (result == null)
                    {
                        result = RechargeService.WXScanCodeTempParkingFeeByParkGateID(pid, gid, string.Empty, GetOrderSource());
                    }
                    TxtLogServices.WriteTxtLogEx("QRCodeParkPayment", "Result:{0}", (int)result.Result);
                    if (result == null || result.Result == APPResult.NoNeedPay || result.Result == APPResult.RepeatPay)
                    {
                        int type = result.Result == APPResult.NoNeedPay ? 0 : 1;
                        return(RedirectToAction("NotNeedPayment", "QRCodeParkPayment", new { licensePlate = result.PlateNumber, type = type, surplusMinutes = result.OutTime, entranceTime = result.EntranceDate, backUrl = "/QRCode/Index" }));
                    }
                    if (result.Result == APPResult.NoLp)
                    {
                        return(RedirectToAction("Index", "ScanCodeInOut", new { pid = pid, io = gid, source = 1 }));
                    }
                }
                else if (!string.IsNullOrWhiteSpace(bid))
                {
                    result = ParkingFeeService.GetParkingFeeByBoxID(bid);

                    if (result == null)
                    {
                        TxtLogServices.WriteTxtLogEx("QRCodeParkPayment", "GetParkingFeeByBoxID Result:null");
                        result = RechargeService.WXScanCodeTempParkingFee(bid, string.Empty);
                    }
                    else
                    {
                        bClient = true;
                        TxtLogServices.WriteTxtLogEx("QRCodeParkPayment", "GetParkingFeeByBoxID Result:{0}", (int)result.Result);
                    }
                    if (result == null || result.Result == APPResult.NoNeedPay || result.Result == APPResult.RepeatPay)
                    {
                        int type = result.Result == APPResult.NoNeedPay ? 0 : 1;
                        return(RedirectToAction("NotNeedPayment", "QRCodeParkPayment", new { licensePlate = result.PlateNumber, type = type, surplusMinutes = result.OutTime, entranceTime = result.EntranceDate, backUrl = "/QRCode/Index" }));
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(licensePlate))
                    {
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取车牌信息失败" }));
                    }
                    result = ParkingFeeService.GetParkingFeeByParkingID(pid, licensePlate);

                    if (result == null)
                    {
                        result = RechargeService.WXTempParkingFee(licensePlate, pid, string.Empty, model.OrderTime);
                    }
                    else
                    {
                        bClient = true;
                    }
                    if (result == null || result.Result == APPResult.NoNeedPay || result.Result == APPResult.RepeatPay)
                    {
                        int type = result.Result == APPResult.NoNeedPay ? 0 : 1;
                        return(RedirectToAction("NotNeedPayment", "QRCodeParkPayment", new { licensePlate = licensePlate, type = type, surplusMinutes = result.OutTime, entranceTime = result.EntranceDate }));
                    }
                }

                if (!bClient)
                {
                    RechargeService.CheckCalculatingTempCost(result.Result, result.ErrorDesc);
                    if (result.OrderSource == PayOrderSource.Platform)
                    {
                        bool testResult = CarService.WXTestClientProxyConnectionByPKID(result.ParkingID);
                        if (!testResult)
                        {
                            throw new MyException("车场网络异常,暂无法缴停车费!");
                        }
                        //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo);
                        int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo, result.ParkingID, result.Pkorder.TagID);
                        TxtLogServices.WriteTxtLogEx("QRCodeParkPayment", "ComputeParkingFee,Tag:{0}, OrderNo:{1}, PKID:{2}\r\nResult:{3}", result.Pkorder.TagID, result.Pkorder.OrderNo, result.ParkingID, interfaceOrderState);

                        if (interfaceOrderState != 1)
                        {
                            string msg       = interfaceOrderState == 2 ? "重复支付" : "订单已失效";
                            string companyId = GetCompanyId(pid, bid, gid);
                            return(RedirectToAction("Index", "ErrorPrompt", new { message = msg, returnUrl = "/QRCode/Index?companyId=" + companyId + "" }));
                        }
                    }
                }
                model.OrderSource         = result.OrderSource;
                model.ExternalPKID        = result.ExternalPKID;
                model.ParkCardNo          = result.CardNo;
                model.PKID                = result.ParkingID;
                model.PKName              = result.ParkName;
                model.InOutID             = result.Pkorder.TagID;
                model.TagID               = result.Pkorder.TagID;
                model.PlateNo             = result.PlateNumber;
                model.EntranceTime        = result.EntranceDate;
                model.ExitTime            = model.OrderTime.AddMinutes(result.OutTime);
                model.Amount              = result.Pkorder.Amount;
                model.PayDetailID         = result.Pkorder.OrderNo;
                model.DiscountAmount      = result.Pkorder.DiscountAmount;
                ViewBag.Result            = result.Result;
                ViewBag.PayAmount         = result.Pkorder.PayAmount;
                ViewBag.IsShowPlateNumber = IsShowPlateNumber;

                if (result.ImageUrl.IsEmpty())
                {
                    ParkIORecord record  = ParkIORecordServices.QueryLastExitIORecordByPlateNumber(model.PlateNo);
                    string       htmlurl = "";
                    if (record != null && record.EntranceImage.IsEmpty() == false)
                    {
                        htmlurl = "http://www.yft166.net/Pic/" + record.EntranceImage.Replace('\\', '/');
                    }
                    else
                    {
                        result.ImageUrl = htmlurl;
                    }
                    result.ImageUrl = htmlurl;
                }
                //显示图片的
                ViewBag.url = result.ImageUrl;

                return(View(model));
            }
            catch (MyException ex)
            {
                string companyId = GetCompanyId(pid, bid, gid);
                string parkingId = GetParkingId(pid, bid, gid);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, parkingId = parkingId, returnUrl = "/QRCode/Index?companyId=" + companyId + "" }));
            }
            catch (Exception ex)
            {
                string companyId = GetCompanyId(pid, bid, gid);
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "扫描缴费计算缴费金额失败", ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "计算缴费金额失败", returnUrl = "/QRCode/Index?companyId=" + companyId + "" }));
            }
        }
Beispiel #2
0
        public string Pay()
        {
            string sTag = Request["paytype"];
            //string sBody = Request["body"];
            string sAmount      = Request["fee"];
            string sPayAccount  = Request["auth_code"];
            string sPlateNumber = Request["PlateNumber"];
            string sPKID        = Request["PKID"];

            if (sTag.IsEmpty() || (sTag != "0" && sTag != "1" && sTag != "2"))
            {
                return("2");
            }

            //if (string.IsNullOrEmpty(sBody))
            //{
            //    return "2sBody";
            //}
            if (string.IsNullOrEmpty(sAmount))
            {
                return("2");
            }

            if (sTag != "2")
            {
                if (string.IsNullOrEmpty(sPayAccount))
                {
                    return("2");
                }
            }
            if (string.IsNullOrEmpty(sPlateNumber))
            {
                return("2");
            }
            if (string.IsNullOrEmpty(sPKID))
            {
                return("2");
            }

            OnlineOrder model = new OnlineOrder();

            model.OrderTime = DateTime.Now;

            TempParkingFeeResult result = RechargeService.WXTempParkingFee(sPlateNumber, sPKID, sPayAccount, model.OrderTime);

            if (result.Result == APPResult.NoNeedPay)
            {
                return("3"); //不需要交费
            }
            if (result.Result == APPResult.RepeatPay)
            {
                return("4"); //重复交费
            }

            decimal dAmount = decimal.Parse(sAmount) / 100;

            //if (result.Pkorder.Amount != dAmount)
            //{
            //    return "6"; //金额不一致
            //}
            try
            {
                RechargeService.CheckCalculatingTempCost(result.Result);
            }
            catch (Exception ex)
            {
                return(((int)result.Result).ToString());
            }

            if (result.OrderSource == PayOrderSource.Platform)
            {
                bool testResult = CarService.WXTestClientProxyConnectionByPKID(result.ParkingID);
                if (!testResult)
                {
                    throw new MyException("车场网络异常,暂无法缴停车费!");
                }
                //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo);

                int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo, result.ParkingID, result.Pkorder.TagID);
                if (interfaceOrderState != 1)
                {
                    if (interfaceOrderState == 2)
                    {
                        return("4"); //重复交费
                    }
                    else
                    {
                        return("5"); //订单已失效
                    }
                }
            }

            model.ParkCardNo   = result.CardNo;
            model.PKID         = result.ParkingID;
            model.PKName       = result.ParkName;
            model.InOutID      = result.Pkorder.TagID;
            model.PlateNo      = result.PlateNumber;
            model.EntranceTime = result.EntranceDate;
            model.ExitTime     = model.OrderTime.AddMinutes(result.OutTime);
            //model.Amount = result.Pkorder.Amount;
            model.Amount         = dAmount;
            model.PayDetailID    = result.Pkorder.OrderNo;
            model.DiscountAmount = result.Pkorder.DiscountAmount;
            // model.OrderSource = PayOrderSource.HAND;
            model.ExternalPKID = result.ExternalPKID;

            model.OrderID   = IdGenerator.Instance.GetId();
            model.Status    = OnlineOrderStatus.WaitPay;
            model.OrderType = OnlineOrderType.ParkFee;

            BaseCompany company = CompanyServices.QueryByParkingId(model.PKID);

            if (company == null)
            {
                throw new MyException("获取单位信息失败");
            }

            if (sTag == "0")
            {
                WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID);
                if (config == null)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }
                if (!config.Status)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }

                model.PayeeUser      = config.SystemName;
                model.PayeeAccount   = config.PartnerId;
                model.PayAccount     = sPayAccount;
                model.Payer          = sPayAccount;
                model.AccountID      = model.AccountID;
                model.CardId         = model.AccountID;
                model.PayeeChannel   = PaymentChannel.WeiXinPay;
                model.PaymentChannel = PaymentChannel.WeiXinPay;
                model.CompanyID      = config.CompanyID;

                bool isSuc = OnlineOrderServices.Create(model);
                if (!isSuc)
                {
                    throw new MyException("生成待缴费订单失败");
                }
            }
            else if (sTag == "1")
            {
                //支付宝
                AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID);
                if (config == null)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }
                if (!config.Status)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin);
                    return("-1");
                }

                model.AccountID      = string.Empty;
                model.CardId         = string.Empty;
                model.PayeeChannel   = PaymentChannel.AliPay;
                model.PaymentChannel = PaymentChannel.AliPay;
                model.PayeeUser      = config.SystemName;
                model.PayeeAccount   = config.PayeeAccount;
                model.Payer          = sPayAccount;
                model.PayAccount     = sPayAccount;
                model.CompanyID      = config.CompanyID;

                bool isSuc = OnlineOrderServices.Create(model);
                if (!isSuc)
                {
                    throw new MyException("生成待缴费订单失败");
                }
            }
            else if (sTag == "2")
            {
                //现金支付的
                model.AccountID  = string.Empty;
                model.CardId     = string.Empty;
                model.Payer      = sPayAccount;
                model.PayAccount = sPayAccount;
                model.CompanyID  = company.CPID;
            }

            //调用刷卡支付,如果内部出现异常则在页面上显示异常原因
            try
            {
                //int status=1;

                string tradeNo   = "";
                string sDataInfo = "";
                if (sTag == "0")    //微信
                {
                    if (!MicroPay.Run(model, out sDataInfo))
                    {
                        return("-2");
                    }
                    else
                    {
                        tradeNo = sDataInfo;
                        //发送通知开闸
                        bool isPayState = OnlineOrderServices.PaySuccess(model.OrderID, tradeNo, DateTime.Now, sPayAccount);
                        if (!isPayState)
                        {
                            throw new Exception("修改微信订单状态失败");
                        }

                        TxtLogServices.WriteTxtLogEx("WXPayReturn", string.Format("WXPayResult:{0}支付完成", tradeNo));
                    }
                }
                else if (sTag == "1")   //支付宝
                {
                    if (AliPayPay.Run(model, out sDataInfo) == false)
                    {
                        return("-3");
                    }
                    else
                    {
                        tradeNo = sDataInfo;

                        bool isPayState = OnlineOrderServices.PaySuccess(model.OrderID, tradeNo, DateTime.Now, sPayAccount);
                        if (!isPayState)
                        {
                            throw new Exception("修改支付宝订单状态失败");
                        }

                        TxtLogServices.WriteTxtLogEx("AliPayReturn", string.Format("AliPayShowResult:{0}支付完成", tradeNo));
                    }
                }
                else if (sTag == "2") //现金支付的
                {
                    TempStopPaymentResult payResult = RechargeService.WXTempStopPayment(result.Pkorder.OrderNo, (int)OrderPayWay.Cash, dAmount, sPKID, "", model.OrderID.ToString(), DateTime.Now);
                    TxtLogServices.WriteTxtLogEx("CashReturn", string.Format("CashShowResult:{1}:{0} 支付完成", payResult.ToXml(System.Text.Encoding.UTF8), dAmount));
                    if (payResult.Result != APPResult.Normal)
                    {
                        return("5");
                    }
                }

                //不是预支付的订单 就暂时不修改了
                //bool results = OnlineOrderServices.UpdatePrepayIdById(tradeNo, model.OrderID);
                //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result + "</span>");
                ParkingFeeService.DeleteParkingFee(model.PlateNo + model.PKID);
                return("0");
            }
            //catch (WxPayException ex)
            //{
            //    return "1";
            //    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
            //}
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("PayError", "该支付失败", "单位编号:" + model.CompanyID + "<br/>" + ex.StackTrace, LogFrom.UnKnown);
                return("-4");
                //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
            }
        }