Пример #1
0
        public IHttpActionResult ConfirmOrder([FromBody] ConfirmOrderModel model)
        {
            using (var client = new SmtpClient("localhost"))
            {
                var message = new MailMessage()
                {
                    From    = new MailAddress("*****@*****.**"),
                    Subject = "New Order",
                    Body    = $"Hi, {model.FullName}. " +
                              $"You have confirmed order at products.com site. " +
                              $"Your address: {model.Address}. " +
                              $"Total price: {model.TotalPrice}"
                };
                message.To.Add(model.Email);
                client.Send(message);
            }

            return(Ok());
        }
Пример #2
0
        /// <summary>
        /// 确认订单
        /// </summary>
        public ActionResult ConfirmOrder()
        {
            //选中的购物车项键列表
            string selectedCartItemKeyList = WebHelper.GetRequestString("selectedCartItemKeyList");

            //订单商品列表
            List<OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid);
            if (orderProductList.Count < 1)
                return PromptView("购物车中没有商品,请先添加商品");

            //选中的订单商品列表
            List<OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List<CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);
            if (selectedOrderProductList.Count < 1)
                return PromptView("请先选择购物车商品");

            ConfirmOrderModel model = new ConfirmOrderModel();

            model.SelectedCartItemKeyList = selectedCartItemKeyList;

            model.DefaultFullShipAddressInfo = ShipAddresses.GetDefaultFullShipAddress(WorkContext.Uid);

            model.DefaultPayPluginInfo = Plugins.GetDefaultPayPlugin();
            model.PayPluginList = Plugins.GetPayPluginList();

            model.DefaultShipPluginInfo = Plugins.GetDefaultShipPlugin();
            model.ShipPluginList = Plugins.GetShipPluginList();

            model.PayCreditName = Credits.PayCreditName;
            model.UserPayCredits = WorkContext.PartUserInfo.PayCredits;
            model.MaxUsePayCredits = Credits.GetOrderMaxUsePayCredits(WorkContext.PartUserInfo.PayCredits);

            model.TotalWeight = Carts.SumOrderProductWeight(selectedOrderProductList);
            model.TotalCount = Carts.SumOrderProductCount(selectedOrderProductList);

            model.ProductAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            model.FullCut = Carts.SumFullCut(cartItemList);

            decimal amount = model.ProductAmount - model.FullCut;
            //计算配送费用
            if (model.DefaultFullShipAddressInfo != null && model.DefaultShipPluginInfo != null)
            {
                model.ShipFee = ((IShipPlugin)model.DefaultShipPluginInfo.Instance).GetShipFee(model.TotalWeight, amount, selectedOrderProductList, DateTime.Now, model.DefaultFullShipAddressInfo.ProvinceId, model.DefaultFullShipAddressInfo.CityId, model.DefaultFullShipAddressInfo.RegionId, WorkContext.PartUserInfo);
            }
            //计算支付费用
            if (model.DefaultPayPluginInfo != null)
            {
                IPayPlugin payPlugin = (IPayPlugin)model.DefaultPayPluginInfo.Instance;
                if (payPlugin.PayMode == 0)
                {
                    if (model.DefaultFullShipAddressInfo != null && model.DefaultShipPluginInfo != null)
                    {
                        IShipPlugin shipPlugin = (IShipPlugin)model.DefaultShipPluginInfo.Instance;
                        if (shipPlugin.SupportCOD)
                            model.PayFee = shipPlugin.GetCODPayFee(amount, DateTime.Now, model.DefaultFullShipAddressInfo.ProvinceId, model.DefaultFullShipAddressInfo.CityId, model.DefaultFullShipAddressInfo.RegionId, WorkContext.PartUserInfo);
                    }
                }
                else
                {
                    model.PayFee = payPlugin.GetPayFee(amount, DateTime.Now, WorkContext.PartUserInfo);
                }
            }

            model.OrderAmount = model.ProductAmount - model.FullCut + model.ShipFee + model.PayFee;

            model.CartItemList = cartItemList;

            model.IsVerifyCode = CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.ShopConfig.VerifyPages);

            return View(model);
        }