Example #1
0
        public ActionResult ComputeParkingFee(string licensePlate, string parkingId)
        {
            licensePlate = licensePlate.ToPlateNo();
            if (!string.IsNullOrWhiteSpace(licensePlate) && licensePlate.Length > 2)
            {
                string firstPlate = HttpUtility.UrlEncode(licensePlate.Substring(0, 2), Encoding.GetEncoding("UTF-8"));
                Response.Cookies.Add(new HttpCookie("SmartSystem_WeiXinUser_DefaultPlate", firstPlate));
            }
            try
            {
                OnlineOrder model = new OnlineOrder();
                model.OrderTime = DateTime.Now;

                TempParkingFeeResult result = RechargeService.WXTempParkingFee(licensePlate, parkingId, LoginAccountID, model.OrderTime);
                if (result.Result == APPResult.NoNeedPay || result.Result == APPResult.RepeatPay)
                {
                    int type = result.Result == APPResult.NoNeedPay ? 0 : 1;
                    return(RedirectToAction("NotNeedPayment", "ParkingPayment", new { licensePlate = licensePlate, type = type, surplusMinutes = result.OutTime, entranceTime = result.EntranceDate }));
                }
                RechargeService.CheckCalculatingTempCost(result.Result);
                if (result.OrderSource == PayOrderSource.Platform)
                {
                    bool testResult = CarService.WXTestClientProxyConnectionByPKID(result.ParkingID);
                    if (!testResult)
                    {
                        throw new MyException("车场网络异常,暂无法缴停车费!");
                    }
                    int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo);
                    if (interfaceOrderState != 1)
                    {
                        string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效";
                        return(PageAlert("Index", "H5ParkingPayment", new { RemindUserContent = msg }));
                    }
                }
                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.PayDetailID    = result.Pkorder.OrderNo;
                model.DiscountAmount = result.Pkorder.DiscountAmount;
                model.OrderSource    = result.OrderSource;
                model.ExternalPKID   = result.ExternalPKID;
                ViewBag.Result       = result.Result;
                ViewBag.PayAmount    = result.Pkorder.PayAmount;
                return(View(model));
            }
            catch (MyException ex)
            {
                return(PageAlert("Index", "H5ParkingPayment", new { RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "计算缴费金额失败", ex, LogFrom.WeiXin);
                return(PageAlert("Index", "H5ParkingPayment", new { RemindUserContent = "计算缴费金额失败" }));
            }
        }
Example #2
0
        public ActionResult CheckOrderState(decimal orderId)
        {
            try
            {
                OnlineOrder order = OnlineOrderServices.QueryByOrderId(orderId);
                //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(order.PayDetailID);

                int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(order.PayDetailID, order.PKID, order.InOutID);
                if (interfaceOrderState != 1)
                {
                    string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效";
                    return(Json(MyResult.Error(msg)));
                }
                return(Json(MyResult.Success()));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayment_Error", string.Format("检查订单是否有效失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId), ex, LogFrom.WeiXin);
                return(Json(MyResult.Error("检查订单是否有效失败")));
            }
        }
Example #3
0
        public ActionResult SubmitParkingPaymentRequest(OnlineOrder model)
        {
            try
            {
                if (model.OrderSource == PayOrderSource.Platform)
                {
                    //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID);

                    int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID, model.PKID, model.InOutID);
                    if (interfaceOrderState != 1)
                    {
                        string msg       = interfaceOrderState == 2 ? "重复支付" : "订单已失效";
                        string companyId = GetCompanyId(model.PKID, string.Empty, string.Empty);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = msg, returnUrl = "/QRCode/Index?companyId=" + companyId + "" }));
                    }
                }
                model.OrderID   = IdGenerator.Instance.GetId();
                model.Status    = OnlineOrderStatus.WaitPay;
                model.OrderType = OnlineOrderType.ParkFee;
                model.Amount    = model.Amount;

                BaseCompany company = CompanyServices.QueryByParkingId(model.PKID);
                if (company == null)
                {
                    throw new MyException("获取单位信息失败");
                }

                if (model.PaymentChannel == PaymentChannel.AliPay)
                {
                    if (string.IsNullOrWhiteSpace(AliPayUserId))
                    {
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取用户信息失败,请重新扫码进入" }));
                    }
                    AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID);
                    if (config == null)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝配置信息失败!" }));
                    }
                    if (!config.Status)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用支付宝支付!" }));
                    }
                    if (model.OrderSource == PayOrderSource.Platform && (CurrLoginAliPayApiConfig == null || CurrLoginAliPayApiConfig.CompanyID != config.CompanyID))
                    {
                        string loginCompanyId = CurrLoginAliPayApiConfig != null ? CurrLoginAliPayApiConfig.CompanyID : string.Empty;
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "支付宝配置信息和当前支付宝配置信息不匹配,不能支付", string.Format("支付单位:{0},用户单位:{1}", config.CompanyID, loginCompanyId), LogFrom.WeiXin);
                        if (CurrLoginAliPayApiConfig == null)
                        {
                            return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝授权信息失败,请重试!" }));
                        }
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付宝配置信息和当前支付宝配置信息不匹配,不能支付!" }));
                    }
                    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          = AliPayUserId;
                    model.PayAccount     = AliPayUserId;
                    model.CompanyID      = config.CompanyID;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(WeiXinOpenId))
                    {
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取用户信息失败,请重新扫码进入" }));
                    }

                    WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID);
                    if (config == null)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信配置信息失败!" }));
                    }
                    if (!config.Status)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用微信支付!" }));
                    }
                    if (model.OrderSource == PayOrderSource.Platform && (CurrLoginWeiXinApiConfig == null || config.CompanyID != CurrLoginWeiXinApiConfig.CompanyID))
                    {
                        string loginCompanyId = CurrLoginWeiXinApiConfig != null ? CurrLoginWeiXinApiConfig.CompanyID : string.Empty;
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "车场所属公众号和当前公众号不匹配,不能支付", string.Format("支付单位:{0},微信用户单位:{1}", config.CompanyID, loginCompanyId), LogFrom.WeiXin);
                        if (CurrLoginWeiXinApiConfig == null)
                        {
                            return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信授权信息失败,请重试!" }));
                        }
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "车场所属公众号和当前公众号不匹配,不能支付!" }));
                    }

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

                bool result = OnlineOrderServices.Create(model);
                if (!result)
                {
                    throw new MyException("生成待缴费订单失败");
                }

                switch (model.PaymentChannel)
                {
                case PaymentChannel.WeiXinPay:
                {
                    return(RedirectToAction("ParkCarPayment", "WeiXinPayment", new { orderId = model.OrderID, source = 1 }));
                }

                case PaymentChannel.AliPay:
                {
                    return(RedirectToAction("ParkCarPayment", "AliPayment", new { orderId = model.OrderID, source = 1 }));
                }

                default: throw new MyException("支付方式错误");
                }
            }
            catch (MyException ex)
            {
                return(RedirectToAction("ComputeParkingFee", "QRCodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "保存临停缴费订单失败", ex, LogFrom.WeiXin);
                return(RedirectToAction("ComputeParkingFee", "QRCodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = "提交支付失败" }));
            }
        }
Example #4
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 + "" }));
            }
        }
Example #5
0
        public ActionResult SubmitParkingPaymentRequest(OnlineOrder model)
        {
            try
            {
                if (model.OrderSource == PayOrderSource.Platform)
                {
                    int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID);
                    if (interfaceOrderState != 1)
                    {
                        string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效";
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = msg, returnUrl = "/H5ParkingPayment/Index" }));
                    }
                }
                model.OrderID   = IdGenerator.Instance.GetId();
                model.Status    = OnlineOrderStatus.WaitPay;
                model.OrderType = OnlineOrderType.ParkFee;
                model.Amount    = model.Amount;

                BaseCompany company = CompanyServices.QueryByParkingId(model.PKID);
                if (company == null)
                {
                    throw new MyException("获取单位信息失败");
                }

                if (model.PaymentChannel == PaymentChannel.AliPay)
                {
                    AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID);
                    if (config == null)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝配置信息失败!" }));
                    }
                    if (!config.Status)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用支付宝支付!" }));
                    }
                    AliPayApiConfig requestConfig = AliPayApiConfigServices.QueryAliPayConfig(GetRequestCompanyId);
                    if (requestConfig == null)
                    {
                        throw new MyException("获取请求单位微信配置失败");
                    }

                    if (config.CompanyID != requestConfig.CompanyID)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "支付的支付宝配置和请求的支付配置不匹配,不能支付", string.Format("支付单位:{0},请求单位:{1}", config.CompanyID, requestConfig.CompanyID), LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付的支付宝配置和请求的支付配置不匹配,不能支付!" }));
                    }
                    model.AccountID      = LoginAccountID;
                    model.CardId         = string.Empty;
                    model.PayeeChannel   = PaymentChannel.AliPay;
                    model.PaymentChannel = PaymentChannel.AliPay;
                    model.PayeeUser      = config.SystemName;
                    model.PayeeAccount   = config.PayeeAccount;
                    model.PayAccount     = string.Empty;
                    model.Payer          = model.PayAccount;
                    model.CompanyID      = config.CompanyID;
                }
                else
                {
                    WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID);
                    if (config == null)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信配置信息失败!" }));
                    }
                    if (!config.Status)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用微信支付!" }));
                    }
                    WX_ApiConfig requestConfig = WXApiConfigServices.QueryWXApiConfig(GetRequestCompanyId);
                    if (requestConfig == null)
                    {
                        throw new MyException("获取请求单位微信配置失败");
                    }

                    if (config.CompanyID != requestConfig.CompanyID)
                    {
                        ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "微信支付配置和当前请求微信支付配置不匹配,不能支付", string.Format("支付单位:{0},请求单位:{1}", config.CompanyID, requestConfig.CompanyID), LogFrom.WeiXin);
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "微信支付配置和当前请求微信支付配置不匹配,不能支付!" }));
                    }
                    model.PayeeUser      = config.SystemName;
                    model.PayeeAccount   = config.PartnerId;
                    model.PayAccount     = string.Empty;
                    model.Payer          = model.PayAccount;
                    model.AccountID      = LoginAccountID;
                    model.CardId         = model.AccountID;
                    model.PayeeChannel   = PaymentChannel.WeiXinPay;
                    model.PaymentChannel = PaymentChannel.WeiXinPay;
                    model.CompanyID      = config.CompanyID;
                }

                bool result = OnlineOrderServices.Create(model);
                if (!result)
                {
                    throw new MyException("生成待缴费订单失败");
                }

                switch (model.PaymentChannel)
                {
                case PaymentChannel.WeiXinPay:
                {
                    return(RedirectToAction("ParkCarPayment", "H5WeiXinPayment", new { orderId = model.OrderID }));
                }

                case PaymentChannel.AliPay:
                {
                    return(RedirectToAction("AliPayRequest", "H5Order", new { orderId = model.OrderID, requestSource = 1 }));
                }

                default: throw new MyException("支付方式错误");
                }
            }
            catch (MyException ex)
            {
                return(RedirectToAction("ComputeParkingFee", "H5CodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("H5ParkingPaymentError", "保存临停缴费订单失败", ex, LogFrom.WeiXin);
                return(RedirectToAction("ComputeParkingFee", "H5CodeParkPayment", new { licensePlate = model.PlateNo, RemindUserContent = "提交支付失败" }));
            }
        }
Example #6
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>");
            }
        }
Example #7
0
        public ActionResult SubmitParkingPaymentRequest(OnlineOrder model)
        {
            try
            {
                int time = WXOtherConfigServices.GetTempParkingWeiXinPayTimeOut(model.CompanyID);
                if (model.OrderTime.AddMinutes(time - 1) < DateTime.Now)
                {
                    throw new MyException("页面等待超时,请重新点击“立即结算”按钮");
                }
                if (model.OrderSource == PayOrderSource.Platform)
                {
                    //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID);
                    int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(model.PayDetailID, model.PKID, model.InOutID);
                    if (interfaceOrderState != 1)
                    {
                        string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效";
                        return(PageAlert("LicensePlatePayment", "ParkingPayment", new { RemindUserContent = msg }));
                    }
                }

                BaseCompany company = CompanyServices.QueryByParkingId(model.PKID);
                if (company == null)
                {
                    throw new MyException("获取单位信息失败");
                }

                WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID);
                if (config == null)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信配置信息失败!" }));
                }
                if (!config.Status)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "该车场暂停使用微信支付!" }));
                }
                if (config.CompanyID != WeiXinUser.CompanyID)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "微信用户所属公众号和当前公众号不匹配,不能支付", string.Format("支付单位:{0},微信用户单位:{1}", config.CompanyID, WeiXinUser.CompanyID), LogFrom.WeiXin);
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "微信用户所属公众号和当前公众号不匹配,不能支付!" }));
                }
                if (model.OrderSource == PayOrderSource.Platform && (CurrLoginWeiXinApiConfig == null || config.CompanyID != CurrLoginWeiXinApiConfig.CompanyID))
                {
                    string loginCompanyId = CurrLoginWeiXinApiConfig != null ? CurrLoginWeiXinApiConfig.CompanyID : string.Empty;
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "车场所属公众号和当前公众号不匹配,不能支付", string.Format("支付单位:{0},微信用户单位:{1}", config.CompanyID, loginCompanyId), LogFrom.WeiXin);
                    if (CurrLoginWeiXinApiConfig == null)
                    {
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信授权信息失败,请重试!" }));
                    }
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "车场所属公众号和当前公众号不匹配,不能支付!" }));
                }

                model.OrderID      = IdGenerator.Instance.GetId();
                model.Status       = OnlineOrderStatus.WaitPay;
                model.PayAccount   = WeiXinUser.OpenID;
                model.Payer        = WeiXinUser.OpenID;
                model.PayeeUser    = config.SystemName;
                model.PayeeAccount = config.PartnerId;
                model.OrderType    = OnlineOrderType.ParkFee;
                model.AccountID    = WeiXinUser.AccountID;
                model.Amount       = model.Amount;
                model.CardId       = WeiXinUser.AccountID;
                model.CompanyID    = config.CompanyID;
                bool result = OnlineOrderServices.Create(model);
                if (!result)
                {
                    throw new MyException("生成待缴费订单失败");
                }
                DateTime maxWaitTime = model.OrderTime.AddMinutes(time);
                switch (model.PaymentChannel)
                {
                case PaymentChannel.WeiXinPay:
                {
                    return(RedirectToAction("ParkCarPayment", "WeiXinPayment", new { orderId = model.OrderID, maxWaitTime = maxWaitTime }));
                }

                default: throw new MyException("支付方式错误");
                }
            }
            catch (MyException ex)
            {
                return(PageAlert("ComputeParkingFee", "ParkingPayment", new { licensePlate = model.PlateNo, RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "保存临停缴费订单失败", ex, LogFrom.WeiXin);
                return(PageAlert("ComputeParkingFee", "ParkingPayment", new { licensePlate = model.PlateNo, RemindUserContent = "提交支付失败" }));
            }
        }
Example #8
0
        /// <summary>
        /// 计算停车费
        /// </summary>
        /// <returns></returns>
        ///
        public ActionResult ComputeParkingFee(string licensePlate, string parkingId)
        {
            string htmlurl = string.Empty;

            licensePlate = licensePlate.ToPlateNo();
            if (!string.IsNullOrWhiteSpace(licensePlate) && licensePlate.Length > 2)
            {
                string firstPlate = HttpUtility.UrlEncode(licensePlate.Substring(0, 2), Encoding.GetEncoding("UTF-8"));
                Response.Cookies.Add(new HttpCookie("SmartSystem_WeiXinUser_DefaultPlate", firstPlate));
                //licensePlate = "浙B81X83";
                //string errMsg = "";
                ////string aa = string.Empty;
                ////aa=WXotherServices.GETURL(licensePlate).ToString();
                //ParkIORecord record =  ParkIORecordServices.GetNoExitIORecordByPlateNumber(parkingId, licensePlate, out errMsg);

                //if (record != null && record.EntranceImage.IsEmpty() == false)
                //{
                //    htmlurl = "http://www.yft166.net/Pic/" + record.EntranceImage;
                //}
                //else {
                //    htmlurl = "/Content/mobile/images/images.png";
                //}
                //
                //ViewBag.meas = parkingId;
            }


            bool IsShowPlateNumber = true;

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

                List <WX_CarInfo> myPlates = CarService.GetCarInfoByAccountID(WeiXinUser.AccountID);
                if (myPlates.Count(p => p.PlateNo.ToPlateNo() == licensePlate) == 0)
                {
                    IsShowPlateNumber = false;
                }
                TempParkingFeeResult result = RechargeService.WXTempParkingFee(licensePlate, parkingId, WeiXinUser.AccountID, model.OrderTime);
                if (result.Result == APPResult.NoNeedPay || result.Result == APPResult.RepeatPay)
                {
                    int type = result.Result == APPResult.NoNeedPay ? 0 : 1;
                    return(RedirectToAction("NotNeedPayment", "ParkingPayment", new { licensePlate = licensePlate, type = type, surplusMinutes = result.OutTime, entranceTime = result.EntranceDate }));
                }
                RechargeService.CheckCalculatingTempCost(result.Result);
                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)
                    {
                        string msg = interfaceOrderState == 2 ? "重复支付" : "订单已失效";
                        return(PageAlert("LicensePlatePayment", "ParkingPayment", new { RemindUserContent = msg }));
                    }
                }
                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;
                model.OrderSource    = result.OrderSource;
                model.ExternalPKID   = result.ExternalPKID;

                ParkIORecord record = ParkIORecordServices.QueryLastExitIORecordByPlateNumber(licensePlate);

                if (record != null && record.EntranceImage.IsEmpty() == false)
                {
                    htmlurl = "http://www.yft166.net/Pic/" + record.EntranceImage.Replace('\\', '/');
                }
                else
                {
                    htmlurl = "/Content/mobile/images/images.png";
                }

                ViewBag.url = htmlurl;

                ViewBag.Result            = result.Result;
                ViewBag.PayAmount         = result.Pkorder.PayAmount;
                ViewBag.IsShowPlateNumber = IsShowPlateNumber;
                return(View(model));
            }
            catch (MyException ex)
            {
                return(PageAlert("LicensePlatePayment", "ParkingPayment", new { RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "计算缴费金额失败", ex, LogFrom.WeiXin);
                return(PageAlert("LicensePlatePayment", "ParkingPayment", new { RemindUserContent = "计算缴费金额失败" }));
            }
        }