Пример #1
0
        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));
        }
Пример #2
0
        public ActionResult Buy(string 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;

            if (id != null)
            {
                Session["address"] = _context.PersonAddresss.Find(Guid.Parse(id));
                var addres = Session["address"] as PersonAddress;
                var order  = new Order();


                order.Person = _context.Persons.Find(person.ID);

                order.Addders      = addres.Address;
                order.AddresPerson = addres.AddresPerson;
                order.Mobilnumber  = addres.MobileNumber;
                //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(); //Linq表达式;

                //4.如果表单验证通过,则保存order到数据库(),跳转到Pay/AliPay

                if (ModelState.IsValid)
                {
                    //加锁
                    LockedHelp.ThreadLocked(order.ID);
                    try
                    {
                        _context.Orders.Add(order);

                        //清空购物车
                        var carts = _context.Carts.Where(x => x.Person.ID == order.Person.ID);
                        foreach (var item in order.OrderDetails)
                        {
                            _context.Carts.Remove(carts.FirstOrDefault(x => x.Album.ID == item.Album.ID));
                        }

                        _context.SaveChanges();
                    }
                    catch
                    {
                    }
                    finally
                    {
                        LockedHelp.ThreadUnlocked(order.ID);
                    }
                    //跳转到支付页Pay/AliPay
                    ViewBag.OrderID = order.ID;
                    var url = "<script>location.href='" + Url.Action("Alipay", "Pay", new { id = Guid.Parse(@ViewBag.OrderID.ToString()) }) + "'</script>";
                    return(Json(url));
                    // return RedirectToAction("Alipay", "Pay", new { id = order.ID });
                }
                //5.如果验证不通过,返回视图
                return(Content("<script>alert('购买失败!');location.href='" + Url.Action("index", "home") + "'</script>"));
            }

            var selectItemList = new List <SelectListItem>();

            foreach (var it in _context.PersonAddresss.Where(x => x.persons.ID == person.ID))
            {
                selectItemList.Add(new SelectListItem()
                {
                    Value = it.ID.ToString(), Text = "收件人:" + it.AddresPerson + ",收货地址:" + it.Address + ",手机号:" + it.MobileNumber, Selected = true
                });
            }
            ViewBag.Person = selectItemList;
            var orders = Session["Order"];

            return(View(orders));
        }
Пример #3
0
        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 }));
        }
Пример #4
0
        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());
        }