/// <summary> /// 支付跳转页 /// <para>完成支付前参数整理工作,并跳转到支付页面</para> /// </summary> /// <param name="pmtid"></param> /// <param name="ids"></param> /// <returns></returns> public ActionResult Index(string pmtid, string ids) { if (string.IsNullOrWhiteSpace(ids)) { return(RedirectToAction("index", "userCenter", new { url = "/userOrder", tar = "userOrder" })); } if (string.IsNullOrWhiteSpace(pmtid)) { return(RedirectToAction("Pay", "Order", new { orderIds = ids })); } var orderIdArr = ids.Split(',').Select(item => long.Parse(item)); //获取待支付的所有订单 var orders = _iOrderService.GetOrders(orderIdArr).Where(item => item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitPay && item.UserId == CurrentUser.Id).ToList(); if (orders == null || orders.Count == 0) //订单状态不正确 { return(RedirectToAction("index", "userCenter", new { url = "/userOrder", tar = "userOrder" })); } decimal total = orders.Sum(a => a.OrderTotalAmount - a.CapitalAmount); if (total == 0) { return(RedirectToAction("Pay", "Order", new { orderIds = ids })); } foreach (var item in orders) { if (item.OrderType == Entities.OrderInfo.OrderTypes.FightGroup) { if (!_iFightGroupService.OrderCanPay(item.Id)) { throw new HimallException("有拼团订单为不可付款状态"); } } } //获取所有订单中的商品名称 var productInfos = GetProductNameDescriptionFromOrders(orders); string webRoot = CurrentUrlHelper.CurrentUrlNoPort(); //获取同步返回地址 string returnUrl = webRoot + "/Pay/Return/{0}"; //获取异步通知地址 string payNotify = webRoot + "/Pay/Notify/{0}/"; var payment = Core.PluginsManagement.GetPlugins <IPaymentPlugin>(true).FirstOrDefault(d => d.PluginInfo.PluginId == pmtid); if (payment == null) { throw new HimallException("错误的支付方式"); } #region 支付流水获取 var orderPayModel = orders.Select(item => new Entities.OrderPayInfo { PayId = 0, OrderId = item.Id }); //保存支付订单 long payid = _iOrderService.SaveOrderPayInfo(orderPayModel, PlatformType.PC); #endregion //组织返回Model Himall.Web.Models.PayJumpPageModel model = new Himall.Web.Models.PayJumpPageModel(); model.PaymentId = pmtid; model.OrderIds = ids; model.TotalPrice = total; model.UrlType = payment.Biz.RequestUrlType;; model.PayId = payid; try { model.RequestUrl = payment.Biz.GetRequestUrl(string.Format(returnUrl, EncodePaymentId(payment.PluginInfo.PluginId)), string.Format(payNotify, EncodePaymentId(payment.PluginInfo.PluginId)), payid.ToString(), total, productInfos); } catch (Exception ex) { Core.Log.Error("支付页面加载支付插件出错", ex); model.IsErro = true; model.ErroMsg = ex.Message + ",请检查平台支付配置"; } if (string.IsNullOrWhiteSpace(model.RequestUrl)) { model.IsErro = true; model.ErroMsg = "获取支付地址为空,请检查平台支付配置"; } switch (model.UrlType) { case UrlType.Page: return(Redirect(model.RequestUrl)); case UrlType.QRCode: return(Redirect("/Pay/QRPay/?id=" + pmtid + "&url=" + HttpUtility.UrlEncode(model.RequestUrl) + "&orderIds=" + ids)); } ViewBag.Keyword = SiteSettings.Keyword; //form提交在页面组织参数并自动提交 return(View(model)); }
/// <summary> /// /// </summary> /// <param name="pmtid"></param> /// <param name="ids"></param> /// <returns></returns> public JsonResult Pay(string pmtid, string ids) { if (string.IsNullOrWhiteSpace(ids)) { Log.Error("payment/pay 参数异常:IDS为空"); return(Json(new { success = false, msg = "参数异常" }));; } if (string.IsNullOrWhiteSpace(pmtid)) { Log.Error("payment/pay 参数异常:pmtid为空"); return(Json(new { success = false, msg = "参数异常" }));; } #if DEBUG Log.Debug("Pay ids:" + ids); #endif var orderIdArr = ids.Split(',').Select(item => long.Parse(item)); //获取待支付的所有预约单 var orders = _iOrderService.GetOrders(orderIdArr).Where(item => item.OrderStatus == Model.OrderInfo.OrderOperateStatus.WaitPay && item.UserId == CurrentUser.Id).ToList(); if (orders == null || orders.Count == 0) //预约单状态不正确 { Log.Error("payment/pay 未找到可支付的预约单"); return(Json(new { success = false, msg = "未找到可支付的预约单" }));; } decimal total = orders.Sum(a => a.OrderTotalAmount); if (total == 0) { Log.Error("payment/pay 支付金额不能为0"); return(Json(new { success = false, msg = "支付金额不能为0" }));; } foreach (var item in orders) { if (item.OrderType == OrderInfo.OrderTypes.FightGroup) { if (!_iFightGroupService.OrderCanPay(item.Id)) { Log.Error("payment/pay 有拼团预约单为不可付款状态"); return(Json(new { success = false, msg = "有拼团预约单为不可付款状态" })); //throw new HimallException("有拼团预约单为不可付款状态"); } } } //获取所有预约单中的诊疗项目名称 var productInfos = GetProductNameDescriptionFromOrders(orders); string webRoot = Request.Url.Scheme + "://" + Request.Url.Authority; string urlPre = webRoot + "/m-" + PlatformType + "/Payment/"; //获取同步返回地址 string returnUrl = webRoot + "/Pay/Return/{0}"; //获取异步通知地址 string payNotify = webRoot + "/Pay/Notify/{0}"; string notifyPre = urlPre + "Notify/", returnPre = webRoot + "/m-" + PlatformType + "/Member/PaymentToOrders?ids=" + ids; if (pmtid.ToLower().Contains("weixin")) {//微信里跳转到分享页面 //支付成功后晒单地址(source=pay用来区分从哪个页面跳转过去的) returnPre = webRoot + "/m-" + PlatformType + "/Order/OrderShare?source=pay&orderids=" + ids; } var payment = Core.PluginsManagement.GetPlugins <IPaymentPlugin>(true).FirstOrDefault(d => d.PluginInfo.PluginId == pmtid); if (payment == null) { throw new HimallException("错误的支付方式"); } string openId = Core.Helper.WebHelper.GetCookie(CookieKeysCollection.HIMALL_USER_OpenID); if (!string.IsNullOrWhiteSpace(openId)) { openId = Core.Helper.SecureHelper.AESDecrypt(openId, "Mobile"); } else { var openUserInfo = _iMemberService.GetMember(CurrentUser.Id).MemberOpenIdInfo.FirstOrDefault(item => item.AppIdType == MemberOpenIdInfo.AppIdTypeEnum.Payment); if (openUserInfo != null) { openId = openUserInfo.OpenId; } } #region 支付流水获取 var orderPayModel = orders.Select(item => new OrderPayInfo { PayId = 0, OrderId = item.Id }); //保存支付预约单 long payid = _iOrderService.SaveOrderPayInfo(orderPayModel, PlatformType); #endregion #if DEBUG Log.Debug("Pay payid:" + payid); #endif //组织返回Model Himall.Web.Models.PayJumpPageModel model = new Himall.Web.Models.PayJumpPageModel(); model.PaymentId = pmtid; model.OrderIds = ids; model.TotalPrice = total; model.UrlType = payment.Biz.RequestUrlType;; model.PayId = payid; try { #if DEBUG Core.Log.Info("其他详情 : returnPre = " + returnPre + " notifyPre = " + notifyPre + payment.PluginInfo.PluginId.Replace(".", "-") + " ids = " + ids + " totalAmount=" + total + " productInfos=" + productInfos + " openId=" + openId); #endif model.RequestUrl = payment.Biz.GetRequestUrl(returnPre, notifyPre + payment.PluginInfo.PluginId.Replace(".", "-"), payid.ToString(), total, productInfos, openId); Log.Debug(string.Format("openId:{0} Url:{1}", openId, model.RequestUrl)); } catch (Exception ex) { Core.Log.Error("支付页面加载支付插件出错:", ex); throw new HimallException("错误的支付方式"); } #if DEBUG Core.Log.Info("支付方式详情 : id = " + payment.PluginInfo.PluginId + " name = " + payment.PluginInfo.DisplayName + " url = " + model.RequestUrl); #endif if (string.IsNullOrWhiteSpace(model.RequestUrl)) { throw new HimallException("错误的支付方式,获取支付地址为空"); } switch (model.UrlType) { case UrlType.Page: return(Json(new { success = true, msg = "", jumpUrl = model.RequestUrl })); //return Redirect(model.RequestUrl); break; case UrlType.QRCode: return(Json(new { success = true, msg = "", jumpUrl = "/Pay/QRPay/?id=" + pmtid + "&url=" + model.RequestUrl + "&orderIds=" + ids })); //return Redirect("/Pay/QRPay/?id=" + pmtid + "&url=" + model.RequestUrl + "&orderIds=" + ids); break; } return(Json(new { success = false, msg = "调用支付方式异常" })); }