public async Task <ActionResult> NotifyAsync(string notify_id, string sign, Guid out_trade_no, string trade_no, decimal total_fee, string returnUrl = null) { if (AlipayHelper.VerifyParameter("q12vmic8884u68lgvgczye89ga4bizli", Request.Form) == false) { return(Content("fail")); } if (await AlipayHelper.VerifyNotify("2088021994748781", notify_id) == false) { return(Content("fail")); } var order = _context.Order.Find(out_trade_no); if (order == null) { return(Content("fail")); } if (order.PaySuccess) { return(Redirect(returnUrl)); } //修改是否完成支付状态,获取支付成功后的订单后 LockedHelp.ThreadLock(order.ID); try { order.TradeNo = trade_no; order.PaySuccess = true; order.EnumOrdelStatus = EnumOrdelStatus.已付款; _context.SaveChanges(); } finally { LockedHelp.ThreadUnLocked(order.ID); } return(Redirect(returnUrl)); }
public ActionResult Buy(Guid id) { //1.判断用户登录凭据是否过期,如果过期跳转回登录页,登录成功后返回确认购买页 if (Session["LoginUserSessionModel"] == null) { return(RedirectToAction("login", "Account", new { returnUrl = Url.Action("Buy", "Order") })); } //2.读出当前用户Person var person = (Session["LoginUserSessionModel"] as LoginUserSessionModel).Person; var peraddress = person.PerAddress.SingleOrDefault(x => x.ID == id); var order = new Order(); order.Person = _context.Persons.Find(person.ID); //3.从会话中读出订单明细列表 order.OrdelDetails = new List <OrdelDetail>(); var details = (Session["Order"] as Order).OrdelDetails; foreach (var item in details) { item.Album = _context.Albums.Find(item.Album.ID); order.OrdelDetails.Add(item); _context.SaveChanges(); } order.TotalPrice = (from item in order.OrdelDetails select item.Count * item.Album.Price).Sum(); _context.SaveChanges(); //4.如果表单验证通过,则保存order到数据库(锁定进程),跳转到Pay / AliPay //加锁 LockedHelp.ThreadLock(order.ID); try { _context.Order.Add(order); //清空购物车 var carts = _context.Cart.Where(x => x.Person.ID == person.ID).ToList(); foreach (var item in order.OrdelDetails) { _context.Cart.Remove(_context.Cart.SingleOrDefault(x => x.Album.ID == item.Album.ID)); } order.AddressPerson = peraddress.AddressPerson; order.Address = peraddress.Address; order.MobiNumber = peraddress.MobiNumber; _context.SaveChanges(); } catch { } finally { LockedHelp.ThreadUnLocked(order.ID); } //跳转到支付页Pay/AliPay return(RedirectToAction("Alipay", "Pay", new { id = order.ID })); }
public ActionResult Buy(Order order) { //1.判断用户登录凭据是否过期,如果过期跳转回登录页,登录成功后返回确认购买页 if (Session["LoginUserSessionModel"] == null) { return(RedirectToAction("login", "Account", new { returnUrl = Url.Action("Buy", "Order") })); } //2.读出当前用户Person var person = (Session["LoginUserSessionModel"] as LoginUserSessionModel).Person; order.Person = _context.Persons.Find(person.ID); //3.从会话中读出订单明细列表 order.OrderDetails = new List <OrderDetail>(); var details = (Session["Order"] as Order).OrderDetails; foreach (var item in details) { item.Album = _context.Albums.Find(item.Album.ID); order.OrderDetails.Add(item); } order.TotalPrice = (from item in order.OrderDetails select item.Count * item.Album.Price).Sum(); //4.如果表单验证通过,则保存order到数据库(锁定进程),跳转到Pay/AliPay if (ModelState.IsValid) { //加锁 LockedHelp.ThreadLocked(order.ID); try { _context.Orders.Add(order); _context.SaveChanges(); //清空购物车 var carts = _context.Carts.Where(x => x.Person.ID == person.ID).ToList(); foreach (var cart in carts) { _context.Carts.Remove(cart); } _context.SaveChanges(); //把订单中的收件人信息保存到person中 var p = _context.Persons.Find(person.ID); p.MobileNumber = order.MobilNumber; p.Address = order.Address; p.Name = order.AddressPerson; p.FirstName = p.Name.Substring(0, 1); p.LastName = p.Name.Substring(1, p.Name.Length - 1); _context.SaveChanges(); } catch { } finally { LockedHelp.ThreadUnLocked(order.ID); } //跳转到支付页Pay/AliPay return(RedirectToAction("Alipay", "Pay", new { id = order.ID })); } //5.如果验证不通过,返回视图 return(View()); }