コード例 #1
0
ファイル: UserAddress.cs プロジェクト: skybluebin007/JW-Shop
        private void Read()
        {
            int id = RequestHelper.GetQueryString <int>("id");

            if (id < 1)
            {
                ResponseHelper.Write(Newtonsoft.Json.JsonConvert.SerializeObject(new { result = "error", msg = "无效的收货地址" }));
                ResponseHelper.End();
            }

            var entity = UserAddressBLL.Read(id, base.UserId);
            SingleUnlimitClass unlimitClass = new SingleUnlimitClass();

            unlimitClass.ClassID    = entity.RegionId;
            unlimitClass.DataSource = RegionBLL.ReadRegionUnlimitClass();

            ResponseHelper.Write(Newtonsoft.Json.JsonConvert.SerializeObject(new { result = "ok", consignee = entity.Consignee, address = entity.Address, mobile = entity.Mobile, tel = entity.Tel, regionId = unlimitClass.ShowContent() }));
            ResponseHelper.End();
        }
コード例 #2
0
ファイル: CheckOut.cs プロジェクト: skybluebin007/JW-Shop
        /// <summary>
        /// 提交数据
        /// </summary>
        protected override void PostBack()
        {
            string url = "/Mobile/CheckOut.html";
            //检查地址
            string consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee"));

            if (consignee == string.Empty)
            {
                ScriptHelper.AlertFront("收货人姓名不能为空", url);
            }
            string tel    = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel"));
            string mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile"));

            if (tel == string.Empty && mobile == string.Empty)
            {
                ScriptHelper.AlertFront("固定电话,手机必须得填写一个", url);
            }
            string zipCode = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode"));
            string address = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address"));

            if (address == string.Empty)
            {
                ScriptHelper.AlertFront("地址不能为空", url);
            }
            //验证配送方式
            int shippingID = RequestHelper.GetForm <int>("ShippingID");

            if (shippingID == int.MinValue)
            {
                ScriptHelper.AlertFront("请选择配送方式", url);
            }

            //检查金额
            decimal productMoney = 0;

            #region 计算订单金额
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));

            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Redirect("/Mobile/cart.html");
                ResponseHelper.End();
            }

            //关联的商品
            int   count    = 0;
            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格与库存判断
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord   = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    int leftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = standardRecord.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                        //规格集合
                        cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k)));
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
                else
                {
                    int leftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = cart.Product.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
            }
            #endregion
            productMoney = cartList.Sum(k => k.BuyCount * k.Price);

            decimal favorableMoney = 0;
            decimal shippingMoney  = 0;
            #region 计算运费与优惠金额
            string regionID = RequestHelper.GetForm <string>("RegionID");
            //计算配送费用
            ShippingInfo       shipping       = ShippingBLL.Read(shippingID);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingID, regionID);
            switch (shipping.ShippingType)
            {
            case (int)ShippingType.Fixed:
                shippingMoney = shippingRegion.FixedMoeny;
                break;

            case (int)ShippingType.Weight:
                decimal cartProductWeight = Sessions.ProductTotalWeight;
                if (cartProductWeight <= shipping.FirstWeight)
                {
                    shippingMoney = shippingRegion.FirstMoney;
                }
                else
                {
                    shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney;
                }
                break;

            case (int)ShippingType.ProductCount:
                int cartProductCount = Sessions.ProductBuyCount;
                shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny;
                break;

            default:
                break;
            }
            //计算优惠费用
            FavorableActivityInfo favorableActivity = FavorableActivityBLL.Read(DateTime.Now, DateTime.Now, 0);
            if (favorableActivity.Id > 0)
            {
                if (("," + favorableActivity.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && Sessions.ProductTotalPrice >= favorableActivity.OrderProductMoney)
                {
                    switch (favorableActivity.ReduceWay)
                    {
                    case (int)FavorableMoney.Money:
                        favorableMoney += favorableActivity.ReduceMoney;
                        break;

                    case (int)FavorableMoney.Discount:
                        favorableMoney += Sessions.ProductTotalPrice * (10 - favorableActivity.ReduceDiscount) / 10;
                        break;

                    default:
                        break;
                    }
                    if (favorableActivity.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionID, favorableActivity.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion

            decimal balance = RequestHelper.GetForm <decimal>("Balance");
            moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft;
            if (balance > moneyLeft)
            {
                balance = 0;
                ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            }


            decimal        couponMoney   = 0;
            string         userCouponStr = RequestHelper.GetForm <string>("UserCoupon");
            UserCouponInfo userCoupon    = new UserCouponInfo();
            if (userCouponStr != string.Empty)
            {
                int couponID = 0;
                if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID))
                {
                    userCoupon = UserCouponBLL.Read(couponID, base.UserId);
                    if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0)
                    {
                        couponMoney = CouponBLL.Read(userCoupon.CouponId).Money;
                    }
                }
            }
            if (productMoney - favorableMoney + shippingMoney - balance - couponMoney < 0)
            {
                ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            }
            //支付方式
            string         payKey     = RequestHelper.GetForm <string>("Pay");
            PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey);
            //添加订单
            OrderInfo order = new OrderInfo();
            order.OrderNumber = ShopCommon.CreateOrderNumber();
            order.IsActivity  = (int)BoolType.False;
            if (productMoney - favorableMoney + shippingMoney - balance - couponMoney == 0 || payPlugins.IsCod == (int)BoolType.True)
            {
                order.OrderStatus = (int)OrderStatus.WaitCheck;
            }
            else
            {
                order.OrderStatus = (int)OrderStatus.WaitPay;
            }
            order.OrderNote      = string.Empty;
            order.ProductMoney   = productMoney;
            order.Balance        = balance;
            order.FavorableMoney = favorableMoney;
            order.OtherMoney     = 0;
            order.CouponMoney    = couponMoney;
            order.Consignee      = consignee;
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();
            order.RegionId = singleUnlimitClass.ClassID;
            order.Address  = address;
            order.ZipCode  = zipCode;
            order.Tel      = tel;
            if (base.UserId == 0)
            {
                order.Email = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email"));
            }
            else
            {
                order.Email = CookiesHelper.ReadCookieValue("UserEmail");
            }
            order.Mobile              = mobile;
            order.ShippingId          = shippingID;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = shippingMoney;
            order.PayKey              = payKey;
            order.PayName             = payPlugins.Name;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityId = RequestHelper.GetForm <int>("FavorableActivityID");
            order.GiftId              = RequestHelper.GetForm <int>("GiftID");
            order.InvoiceTitle        = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceTitle"));
            order.InvoiceContent      = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceContent"));
            order.UserMessage         = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage"));
            order.AddDate             = RequestHelper.DateNow;
            order.IP       = ClientHelper.IP;
            order.UserId   = base.UserId;
            order.UserName = base.UserName;
            int orderID = OrderBLL.Add(order);
            //使用余额
            if (balance > 0)
            {
                UserAccountRecordInfo userAccountRecord = new UserAccountRecordInfo();
                userAccountRecord.Money    = -balance;
                userAccountRecord.Point    = 0;
                userAccountRecord.Date     = RequestHelper.DateNow;
                userAccountRecord.IP       = ClientHelper.IP;
                userAccountRecord.Note     = "支付订单:";
                userAccountRecord.UserId   = base.UserId;
                userAccountRecord.UserName = base.UserName;
                UserAccountRecordBLL.Add(userAccountRecord);
            }
            //使用优惠券
            string strUserCoupon = RequestHelper.GetForm <string>("UserCoupon");
            if (couponMoney > 0 && strUserCoupon != "0|0")
            {
                userCoupon.IsUse   = (int)BoolType.True;
                userCoupon.OrderId = orderID;
                UserCouponBLL.Update(userCoupon);
            }
            AddOrderProduct(orderID);
            //更改产品库存订单数量
            ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Plus);
            ResponseHelper.Redirect("/Mobile/Finish-I" + orderID.ToString() + ".html");
        }
コード例 #3
0
        public ActionResult AddAddress()
        {
            var entity = new UserAddressInfo();

            int updateId = RequestHelper.GetForm <int>("updateId");

            entity.Consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("consignee"));
            entity.Address   = StringHelper.AddSafe(RequestHelper.GetForm <string>("address"));
            entity.Mobile    = StringHelper.AddSafe(RequestHelper.GetForm <string>("mobile"));
            entity.Tel       = StringHelper.AddSafe(RequestHelper.GetForm <string>("tel"));
            entity.Email     = StringHelper.AddSafe(RequestHelper.GetForm <string>("email"));
            entity.IsDefault = Convert.ToInt32(RequestHelper.GetForm <bool>("isdefault"));

            if (entity.IsDefault > 0)
            {
                UserAddressBLL.SetDefault(entity.Id, uid);
            }

            SingleUnlimitClass unlimitClass = new SingleUnlimitClass();

            entity.RegionId = unlimitClass.ClassID;

            if (string.IsNullOrEmpty(entity.Consignee))
            {
                return(Content("请填写收货人"));
            }
            var region = StringHelper.AddSafe(RequestHelper.GetForm <string>("region"));

            if (!string.IsNullOrEmpty(region))
            {
                string[] regarr = region.Split(',');
                if (regarr.Length < 3)
                {
                    return(Content("请填写完整的地区信息"));
                }
                else
                {
                    string province = regarr[0];
                    string city     = regarr[1];
                    string town     = regarr[2];

                    if (!string.IsNullOrEmpty(town))
                    {
                        entity.RegionId = RegionBLL.ReadRegionIdList(province, city, town);
                    }
                    else
                    {
                        entity.RegionId = RegionBLL.ReadRegionIdList(city);
                    }
                }
            }
            else
            {
                return(Content("请填写完整的地区信息"));
            }
            if (string.IsNullOrEmpty(entity.Address))
            {
                return(Content("请填写详细地址"));
            }
            if (string.IsNullOrEmpty(entity.Mobile))
            {
                return(Content("手机号码不能为空"));
            }

            entity.UserId   = user.Id;
            entity.UserName = user.UserName;

            string msg = "添加成功";

            if (updateId > 0)
            {
                entity.Id = updateId;
                UserAddressBLL.Update(entity);
                msg = "修改成功";
            }
            else
            {
                updateId = UserAddressBLL.Add(entity);
            }

            return(Json(new { flag = true, msg = msg, id = updateId }));
        }
コード例 #4
0
        protected void Submit()
        {
            string             userName           = base.UserName;
            string             userEmail          = CookiesHelper.ReadCookieValue("UserEmail");
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();

            //检测积分
            int id = RequestHelper.GetForm <int>("updateId");

            if (id < 1)
            {
                ResponseHelper.Write("error|无效的请求");
                ResponseHelper.End();
            }
            if (singleUnlimitClass.ClassID.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Length < 3)
            {
                ResponseHelper.Write("error|请填写完整的地区信息");
                ResponseHelper.End();
                ResponseHelper.End();
            }

            var pointLeft = UserAccountRecordBLL.SumPoint(base.UserId);

            Gift = PointProductBLL.Read(id);
            if (Gift.Point > pointLeft)
            {
                ResponseHelper.Write("error|您当前的积分不足以兑取该礼品");
                ResponseHelper.End();
            }
            //库存
            int num = RequestHelper.GetForm <int>("num");

            if (num > (Gift.TotalStorageCount - Gift.SendCount))
            {
                ResponseHelper.Write("error|该礼品库存不足");
                ResponseHelper.End();
            }

            //添加订单
            OrderInfo order = new OrderInfo();

            order.OrderNumber         = ShopCommon.CreateOrderNumber();
            order.IsActivity          = (int)BoolType.True;
            order.OrderStatus         = (int)OrderStatus.WaitCheck;
            order.OrderNote           = "积分兑换奖品";
            order.ProductMoney        = 0;
            order.Balance             = 0;
            order.FavorableMoney      = 0;
            order.OtherMoney          = 0;
            order.CouponMoney         = 0;
            order.Consignee           = StringHelper.AddSafe(RequestHelper.GetForm <string>("username"));
            order.RegionId            = singleUnlimitClass.ClassID;
            order.Address             = StringHelper.AddSafe(RequestHelper.GetForm <string>("address"));
            order.ZipCode             = StringHelper.AddSafe(RequestHelper.GetForm <string>("zipcode"));
            order.Tel                 = StringHelper.AddSafe(RequestHelper.GetForm <string>("tel"));
            order.Email               = userEmail;
            order.Mobile              = StringHelper.AddSafe(RequestHelper.GetForm <string>("mobile"));
            order.ShippingId          = 0;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = 0;
            order.PayKey              = string.Empty;
            order.PayName             = string.Empty;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityId = 0;
            order.GiftId              = 0;
            order.InvoiceTitle        = string.Empty;
            order.InvoiceContent      = string.Empty;
            order.UserMessage         = string.Empty;
            order.AddDate             = RequestHelper.DateNow;
            order.IP            = ClientHelper.IP;
            order.UserId        = base.UserId;
            order.UserName      = userName;
            order.ActivityPoint = Gift.Point * num;
            int orderID = OrderBLL.Add(order);

            //添加订单详细
            OrderDetailInfo orderDetail = new OrderDetailInfo();

            orderDetail.OrderId       = orderID;
            orderDetail.ProductId     = Gift.Id;
            orderDetail.ProductName   = Gift.Name;
            orderDetail.ProductWeight = Gift.Weight;
            orderDetail.SendPoint     = 0;
            orderDetail.ProductPrice  = 0;
            orderDetail.ActivityPoint = Gift.Point;
            orderDetail.BuyCount      = num;
            orderDetail.ParentId      = 0;
            orderDetail.RandNumber    = string.Empty;
            orderDetail.GiftPackId    = 0;
            OrderDetailBLL.Add(orderDetail);

            //积分记录
            var accountRecord = new UserAccountRecordInfo
            {
                Money    = 0,
                Point    = -Gift.Point * num,
                Date     = DateTime.Now,
                IP       = ClientHelper.IP,
                Note     = "兑换礼品-" + Gift.Name,
                UserId   = base.UserId,
                UserName = base.UserName
            };

            UserAccountRecordBLL.Add(accountRecord);

            //更新商品的已兑换数量
            Dictionary <string, object> dict = new Dictionary <string, object>();

            dict.Add("SendCount", Gift.SendCount + num);
            PointProductBLL.UpdatePart(PointProductInfo.TABLENAME, dict, Gift.Id);

            ResponseHelper.Write("ok|" + orderID);
            ResponseHelper.End();
        }
コード例 #5
0
        /// <summary>
        /// 提交按钮点击方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            //读取用户信息
            userID = Cookies.User.GetUserID(true);
            int    pointLeft = UserBLL.ReadUserMore(userID).PointLeft;
            string userName  = Cookies.User.GetUserName(false);
            string userEmail = CookiesHelper.ReadCookieValue("UserEmail");
            //检测积分
            int id = RequestHelper.GetQueryString <int>("ID");

            product = ProductBLL.ReadProduct(id);
            ExchangeAwardInfo exchangeAward = ExchangeAwardBLL.ReadConfigInfo();
            int productPoint = 0;

            if (exchangeAward.PorudctIDList != string.Empty)
            {
                string[] productArray = exchangeAward.PorudctIDList.Split(',');
                string[] pointArray   = exchangeAward.PointList.Split(',');
                for (int i = 0; i < productArray.Length; i++)
                {
                    if (productArray[i] == id.ToString())
                    {
                        productPoint = Convert.ToInt32(pointArray[i]);
                    }
                }
            }
            if (productPoint > pointLeft)
            {
                ScriptHelper.Alert("您当前的积分不足以兑取该奖品", RequestHelper.RawUrl);
            }
            //添加订单
            OrderInfo order = new OrderInfo();

            order.OrderNumber    = ShopCommon.CreateOrderNumber();
            order.IsActivity     = (int)BoolType.True;
            order.OrderStatus    = (int)OrderStatus.WaitCheck;
            order.OrderNote      = "积分兑换奖品";
            order.ProductMoney   = 0;
            order.Balance        = 0;
            order.FavorableMoney = 0;
            order.OtherMoney     = 0;
            order.CouponMoney    = 0;
            order.Consignee      = StringHelper.AddSafe(Consignee.Text);
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();

            order.RegionID            = singleUnlimitClass.ClassID;
            order.Address             = StringHelper.AddSafe(Address.Text);
            order.ZipCode             = StringHelper.AddSafe(ZipCode.Text);
            order.Tel                 = StringHelper.AddSafe(Tel.Text);
            order.Email               = userEmail;
            order.Mobile              = StringHelper.AddSafe(Mobile.Text);
            order.ShippingID          = 0;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = 0;
            order.PayKey              = string.Empty;
            order.PayName             = string.Empty;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityID = 0;
            order.GiftID              = 0;
            order.InvoiceTitle        = string.Empty;
            order.InvoiceContent      = string.Empty;
            order.UserMessage         = string.Empty;
            order.AddDate             = RequestHelper.DateNow;
            order.IP       = ClientHelper.IP;
            order.UserID   = userID;
            order.UserName = userName;
            int orderID = OrderBLL.AddOrder(order);
            //添加订单详细
            OrderDetailInfo orderDetail = new OrderDetailInfo();

            orderDetail.OrderID       = orderID;
            orderDetail.ProductID     = product.ID;
            orderDetail.ProductName   = product.Name;
            orderDetail.ProductWeight = product.Weight;
            orderDetail.SendPoint     = 0;
            orderDetail.ProductPrice  = 0;
            orderDetail.BuyCount      = 1;
            orderDetail.FatherID      = 0;
            orderDetail.RandNumber    = string.Empty;
            orderDetail.GiftPackID    = 0;
            OrderDetailBLL.AddOrderDetail(orderDetail);
            //积分操作
            UserAccountRecordBLL.AddUserAccountRecord(0, -productPoint, "兑换奖品-" + product.Name, userID, userName);
            //更改产品库存订单数量
            ProductBLL.ChangeProductOrderCountByOrder(orderID, ChangeAction.Plus);
            //保存记录
            string fileName = StringHelper.Encode(ShopConfig.ReadConfigInfo().SecureKey, ShopConfig.ReadConfigInfo().SecureKey) + ".txt";

            fileName = Server.MapPath("Admin/" + fileName);
            File.AppendAllText(fileName, userName + ",订单号:" + order.OrderNumber + ",商品:" + product.Name + "\r\n", System.Text.Encoding.Default);
            ScriptHelper.Alert("成功兑换", "/User/OrderDetail.aspx?ID=" + orderID.ToString());
        }
コード例 #6
0
ファイル: UserAddress.cs プロジェクト: skybluebin007/JW-Shop
        private void Add()
        {
            var entity = new UserAddressInfo();

            int updateId = RequestHelper.GetForm <int>("updateId");

            entity.Consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("consignee"));
            entity.Address   = StringHelper.AddSafe(RequestHelper.GetForm <string>("address"));
            entity.Mobile    = StringHelper.AddSafe(RequestHelper.GetForm <string>("mobile"));
            entity.Tel       = StringHelper.AddSafe(RequestHelper.GetForm <string>("tel"));
            entity.Email     = StringHelper.AddSafe(RequestHelper.GetForm <string>("email"));
            entity.IsDefault = RequestHelper.GetForm <int>("isdefault");

            SingleUnlimitClass unlimitClass = new SingleUnlimitClass();

            entity.RegionId = unlimitClass.ClassID;

            dynamic dymic = new System.Dynamic.ExpandoObject();

            dymic.result = "error";

            if (string.IsNullOrEmpty(entity.Consignee))
            {
                dymic.msg = "请填写收货人";
                ResponseHelper.Write(Newtonsoft.Json.JsonConvert.SerializeObject(dymic));
                ResponseHelper.End();
            }
            if (entity.RegionId.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Length < 3)
            {
                dymic.msg = "请填写完整的地区信息";
                ResponseHelper.Write(Newtonsoft.Json.JsonConvert.SerializeObject(dymic));
                ResponseHelper.End();
            }
            if (string.IsNullOrEmpty(entity.Address))
            {
                dymic.msg = "请填写详细地址";
                ResponseHelper.Write(Newtonsoft.Json.JsonConvert.SerializeObject(dymic));
                ResponseHelper.End();
            }
            if (string.IsNullOrEmpty(entity.Mobile) && string.IsNullOrEmpty(entity.Tel))
            {
                dymic.msg = "手机号码或固定电话至少填写一个";
                ResponseHelper.Write(Newtonsoft.Json.JsonConvert.SerializeObject(dymic));
                ResponseHelper.End();
            }

            entity.UserId   = base.UserId;
            entity.UserName = base.UserName;

            if (updateId > 0)
            {
                entity.Id = updateId;
                UserAddressBLL.Update(entity);
            }
            else
            {
                updateId = UserAddressBLL.Add(entity);
            }

            dymic.result    = "ok";
            dymic.id        = updateId;
            dymic.consignee = entity.Consignee;
            dymic.address   = RegionBLL.RegionNameList(entity.RegionId) + " " + entity.Address;
            dymic.mobile    = entity.Mobile;
            dymic.tel       = entity.Tel;
            ResponseHelper.Write(Newtonsoft.Json.JsonConvert.SerializeObject(dymic));
            ResponseHelper.End();
        }
コード例 #7
0
        private void SelectShipping()
        {
            int productId = RequestHelper.GetQueryString <int>("productId");

            if (productId < 1)
            {
                ResponseHelper.Write("-1");
                ResponseHelper.End();
            }

            SingleUnlimitClass singleUnlimitClass2 = new SingleUnlimitClass();
            string             regionId            = singleUnlimitClass2.ClassID;

            //当前产品
            var product = ProductBLL.Read(productId);
            //所有可用的配送方式
            var shippingList = ShippingBLL.ReadList().Where(k => k.IsEnabled == (int)BoolType.True).ToList();

            //无可用的配送方式,返回-10
            if (shippingList.Count < 1)
            {
                ResponseHelper.Write("-10");
                ResponseHelper.End();
            }

            var shippingIds = new List <int>();

            shippingList.ForEach(k => shippingIds.Add(k.Id));

            //读取配送区域列表
            List <ShippingRegionInfo> shippingRegionList = ShippingRegionBLL.ReadList(shippingIds.ToArray());

            //该区域没有物流配送,返回-11
            if (shippingRegionList.Count < 1)
            {
                ResponseHelper.Write("-11");
                ResponseHelper.End();
            }

            //比较匹配出来的配送数据,取最高价(只计算单件商品的价格)
            List <decimal> listShippingMoney = new List <decimal>();

            foreach (ShippingInfo shipping in shippingList)
            {
                string tempRegionId = regionId;
                while (tempRegionId.Length >= 1)
                {
                    bool isFind = false;
                    foreach (ShippingRegionInfo temp in shippingRegionList)
                    {
                        if (("|" + temp.RegionId + "|").IndexOf("|" + tempRegionId + "|") > -1 && temp.ShippingId == shipping.Id)
                        {
                            isFind = true;

                            decimal shippingMoney = 0;
                            switch (shipping.ShippingType)
                            {
                            case (int)ShippingType.Fixed:
                                shippingMoney = temp.FixedMoeny;
                                listShippingMoney.Add(shippingMoney);
                                break;

                            case (int)ShippingType.Weight:
                                if (product.Weight <= shipping.FirstWeight)
                                {
                                    shippingMoney = temp.FirstMoney;
                                }
                                else
                                {
                                    shippingMoney = temp.FirstMoney + Math.Ceiling((product.Weight - shipping.FirstWeight) / shipping.AgainWeight) * temp.AgainMoney;
                                }
                                listShippingMoney.Add(shippingMoney);
                                break;

                            case (int)ShippingType.ProductCount:
                                int productCount = 1;
                                shippingMoney = temp.OneMoeny + (productCount - 1) * temp.AnotherMoeny;
                                listShippingMoney.Add(shippingMoney);
                                break;

                            default:
                                break;
                            }
                            break;
                        }
                    }
                    if (isFind)
                    {
                        break;
                    }
                    else
                    {
                        tempRegionId = tempRegionId.Substring(0, tempRegionId.Length - 1);
                        tempRegionId = tempRegionId.Substring(0, tempRegionId.LastIndexOf('|') + 1);
                    }
                }
            }

            CookiesHelper.AddCookie("usr_region", regionId, 1, TimeType.Year);
            //该区域没有物流配送,返回-11
            if (listShippingMoney.Count < 1)
            {
                ResponseHelper.Write("-11");
                ResponseHelper.End();
            }
            else
            {
                ResponseHelper.Write(listShippingMoney.Max().ToString());
                ResponseHelper.End();
            }
        }
コード例 #8
0
        protected void Submit()
        {
            if (base.UserId <= 0)
            {
                ResponseHelper.Write("error|还未登录");
                ResponseHelper.End();
            }



            int    pointLeft = UserAccountRecordBLL.SumPoint(base.UserId);
            string userName  = base.UserName;
            string userEmail = CookiesHelper.ReadCookieValue("UserEmail");

            //检测积分
            int id = RequestHelper.GetForm <int>("updateId");

            if (id < 1)
            {
                ResponseHelper.Write("error|无效的请求");
                ResponseHelper.End();
            }

            gift = PointProductBLL.Read(id);
            if (gift.IsSale != (int)BoolType.True)
            {
                ResponseHelper.Write("error|该商品已下架");
                ResponseHelper.End();
            }
            if (gift.Point > pointLeft)
            {
                ResponseHelper.Write("error|您当前的积分不足以兑取该商品");
                ResponseHelper.End();
            }
            if (gift.EndDate.Date < DateTime.Now.Date)
            {
                ResponseHelper.Write("error|该商品已过有效兑取时间");
                ResponseHelper.End();
            }

            //库存
            if (gift.TotalStorageCount - gift.SendCount < 1)
            {
                ResponseHelper.Write("error|该商品库存不足");
                ResponseHelper.End();
            }

            //添加订单
            var order = new PointProductOrderInfo();

            order.OrderNumber = ShopCommon.CreateOrderNumber();
            order.OrderStatus = (int)PointProductOrderStatus.Shipping;
            order.Point       = gift.Point;
            order.ProductId   = gift.Id;
            order.ProductName = gift.Name;
            order.BuyCount    = 1;
            order.Consignee   = StringHelper.AddSafe(RequestHelper.GetForm <string>("username"));
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();

            order.RegionId = singleUnlimitClass.ClassID;
            order.Address  = StringHelper.AddSafe(RequestHelper.GetForm <string>("address"));
            order.Tel      = StringHelper.AddSafe(RequestHelper.GetForm <string>("mobile"));
            order.AddDate  = DateTime.Now;
            order.IP       = ClientHelper.IP;
            order.UserId   = base.UserId;
            order.UserName = base.UserName;
            order.Id       = PointProductOrderBLL.Add(order);

            if (order.Id > 0)
            {
                //扣减积分
                UserAccountRecordBLL.Add(new UserAccountRecordInfo
                {
                    RecordType = (int)AccountRecordType.Point,
                    Money      = 0,
                    Point      = -order.Point,
                    Date       = DateTime.Now,
                    IP         = ClientHelper.IP,
                    Note       = "兑取商品:" + order.ProductName + " 订单号:" + order.OrderNumber,
                    UserId     = order.UserId,
                    UserName   = order.UserName
                });

                //扣减库存
                PointProductBLL.ChangeSendCount(order.ProductId, ChangeAction.Plus);
            }

            ResponseHelper.Write("ok|" + order.Id);
            ResponseHelper.End();
        }
コード例 #9
0
ファイル: CheckOut.cs プロジェクト: xuefuruanjian/ems
        protected override void PostBack()
        {
            string url  = "/CheckOut.aspx";
            string str2 = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee"));

            if (str2 == string.Empty)
            {
                ScriptHelper.Alert("收货人姓名不能为空", url);
            }
            string str3 = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel"));
            string str4 = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile"));

            if ((str3 == string.Empty) && (str4 == string.Empty))
            {
                ScriptHelper.Alert("固定电话,手机必须得填写一个", url);
            }
            string str5 = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode"));

            if (str5 == string.Empty)
            {
                ScriptHelper.Alert("邮编不能为空", url);
            }
            string str6 = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address"));

            if (str6 == string.Empty)
            {
                ScriptHelper.Alert("地址不能为空", url);
            }
            int form = RequestHelper.GetForm <int>("ShippingID");

            if (form == -2147483648)
            {
                ScriptHelper.Alert("请选择配送方式", url);
            }
            decimal productTotalPrice = Sessions.ProductTotalPrice;
            decimal num3 = RequestHelper.GetForm <decimal>("FavorableMoney");
            decimal num4 = RequestHelper.GetForm <decimal>("ShippingMoney");
            decimal num5 = RequestHelper.GetForm <decimal>("Balance");
            decimal num6 = RequestHelper.GetForm <decimal>("CouponMoney");

            if (((((productTotalPrice - num3) + num4) - num5) - num6) < 0M)
            {
                ScriptHelper.Alert("金额有错误,请重新检查", url);
            }
            string         key   = RequestHelper.GetForm <string>("Pay");
            PayPluginsInfo info  = PayPlugins.ReadPayPlugins(key);
            OrderInfo      order = new OrderInfo();

            order.OrderNumber = ShopCommon.CreateOrderNumber();
            order.IsActivity  = 0;
            if ((((((productTotalPrice - num3) + num4) - num5) - num6) == 0M) || (info.IsCod == 1))
            {
                order.OrderStatus = 2;
            }
            else
            {
                order.OrderStatus = 1;
            }
            order.OrderNote      = string.Empty;
            order.ProductMoney   = productTotalPrice;
            order.Balance        = num5;
            order.FavorableMoney = num3;
            order.OtherMoney     = 0M;
            order.CouponMoney    = num6;
            order.Consignee      = str2;
            SingleUnlimitClass class2 = new SingleUnlimitClass();

            order.RegionID = class2.ClassID;
            order.Address  = str6;
            order.ZipCode  = str5;
            order.Tel      = str3;
            if (base.UserID == 0)
            {
                order.Email = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email"));
            }
            else
            {
                order.Email = CookiesHelper.ReadCookieValue("UserEmail");
            }
            order.Mobile              = str4;
            order.ShippingID          = form;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = num4;
            order.PayKey              = key;
            order.PayName             = info.Name;
            order.PayDate             = RequestHelper.DateNow;
            order.IsRefund            = 0;
            order.FavorableActivityID = RequestHelper.GetForm <int>("FavorableActivityID");
            order.GiftID              = RequestHelper.GetForm <int>("GiftID");
            order.InvoiceTitle        = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceTitle"));
            order.InvoiceContent      = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceContent"));
            order.UserMessage         = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage"));
            order.AddDate             = RequestHelper.DateNow;
            order.IP       = ClientHelper.IP;
            order.UserID   = base.UserID;
            order.UserName = base.UserName;
            int orderID = OrderBLL.AddOrder(order);

            if (num5 > 0M)
            {
                UserAccountRecordBLL.AddUserAccountRecord(-num5, 0, "支付订单:" + order.OrderNumber, base.UserID, base.UserName);
            }
            string str8 = RequestHelper.GetForm <string>("UserCoupon");

            if ((num6 > 0M) && (str8 != "0|0"))
            {
                UserCouponInfo userCoupon = UserCouponBLL.ReadUserCoupon(Convert.ToInt32(str8.Split(new char[] { '|' })[0]), base.UserID);
                userCoupon.IsUse   = 1;
                userCoupon.OrderID = orderID;
                UserCouponBLL.UpdateUserCoupon(userCoupon);
            }
            this.AddOrderProduct(orderID);
            ProductBLL.ChangeProductOrderCountByOrder(orderID, ChangeAction.Plus);
            ResponseHelper.Redirect("/Finish-I" + orderID.ToString() + ".aspx");
        }
コード例 #10
0
ファイル: CheckOut.cs プロジェクト: skybluebin007/JW-Shop
        /// <summary>
        /// 提交数据
        /// </summary>
        protected override void PostBack()
        {
            string url = "/Mobile/CheckOut.html";
            //检查地址
            string consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee"));

            if (consignee == string.Empty)
            {
                ScriptHelper.AlertFront("收货人姓名不能为空", url);
            }
            string tel    = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel"));
            string mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile"));

            if (tel == string.Empty && mobile == string.Empty)
            {
                ScriptHelper.AlertFront("固定电话,手机必须得填写一个", url);
            }
            string zipCode = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode"));
            string address = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address"));

            if (address == string.Empty)
            {
                ScriptHelper.AlertFront("地址不能为空", url);
            }
            //验证配送方式
            int shippingID = RequestHelper.GetForm <int>("ShippingID");

            if (shippingID == int.MinValue)
            {
                ScriptHelper.AlertFront("请选择配送方式", url);
            }
            //检查支付方式
            string payKey = RequestHelper.GetForm <string>("Pay");

            if (string.IsNullOrEmpty(payKey))
            {
                ScriptHelper.AlertFront("请选择付款方式", url);
            }
            PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey);
            //检查金额
            decimal productMoney = 0, pointMoney = 0;
            var     user = UserBLL.ReadUserMore(base.UserId);

            #region 计算订单金额
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));

            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Redirect("/Mobile/cart.html");
                ResponseHelper.End();
            }

            //关联的商品
            int   count    = 0;
            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格与库存判断
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord   = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    int leftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = standardRecord.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                        //规格集合
                        cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k)));
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
                else
                {
                    int leftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = cart.Product.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
            }
            #endregion
            productMoney = cartList.Sum(k => k.BuyCount * k.Price);


            decimal shippingMoney = 0;
            //订单优惠活动
            var favor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("FavorableActivity")
            };
            //商品优惠
            var productfavor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("ProductFavorableActivity")
            };
            #region 计算运费
            string regionID = RequestHelper.GetForm <string>("RegionID");
            //计算配送费用
            ShippingInfo       shipping       = ShippingBLL.Read(shippingID);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingID, regionID);
            switch (shipping.ShippingType)
            {
            case (int)ShippingType.Fixed:
                shippingMoney = shippingRegion.FixedMoeny;
                break;

            case (int)ShippingType.Weight:
                decimal cartProductWeight = Sessions.ProductTotalWeight;
                if (cartProductWeight <= shipping.FirstWeight)
                {
                    shippingMoney = shippingRegion.FirstMoney;
                }
                else
                {
                    shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney;
                }
                break;

            case (int)ShippingType.ProductCount:
                int cartProductCount = Sessions.ProductBuyCount;
                shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny;
                break;

            default:
                break;
            }
            #endregion

            //decimal balance = RequestHelper.GetForm<decimal>("Balance");
            //moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft;
            //if (balance > moneyLeft)
            //{
            //    balance = 0;
            //    ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            //}
            #region 如果开启了:使用积分抵现,计算积分抵现的现金金额
            //输入的兑换积分数
            var costPoint = RequestHelper.GetForm <int>("costPoint");
            if (ShopConfig.ReadConfigInfo().EnablePointPay == 1)
            {
                if (costPoint > user.PointLeft || costPoint < 0)
                {
                    ResponseHelper.Write("error|输入的兑换积分数[" + costPoint + "]错误,请检查|");
                    ResponseHelper.End();
                }
                if (costPoint > 0)
                {
                    var PointToMoneyRate = ShopConfig.ReadConfigInfo().PointToMoney;
                    pointMoney = costPoint * (decimal)PointToMoneyRate / 100;
                }
            }
            #endregion
            #region 优惠券
            decimal        couponMoney   = 0;
            string         userCouponStr = RequestHelper.GetForm <string>("UserCoupon");
            UserCouponInfo userCoupon    = new UserCouponInfo();
            if (userCouponStr != string.Empty)
            {
                int couponID = 0;
                if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID))
                {
                    userCoupon = UserCouponBLL.Read(couponID, base.UserId);
                    if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0)
                    {
                        CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId);
                        if (tempCoupon.UseMinAmount <= productMoney)
                        {
                            couponMoney = CouponBLL.Read(userCoupon.CouponId).Money;
                        }
                        else
                        {
                            ScriptHelper.AlertFront("结算金额小于该优惠券要求的最低消费的金额", url);
                        }
                    }
                }
            }
            #endregion
            #region 结算商品优惠金额
            decimal productfavorableMoney = 0;
            var     theFavor = FavorableActivityBLL.Read(productfavor.Id);
            if (theFavor.Id > 0)
            {
                decimal tmoney = 0;
                foreach (var tmpcart in cartList)
                {
                    tmpcart.Product = products.FirstOrDefault(k => k.Id == tmpcart.ProductId) ?? new ProductInfo();
                    if (tmpcart.Product.ClassId.IndexOf(theFavor.ClassIds) > -1)
                    {
                        if (!string.IsNullOrEmpty(tmpcart.StandardValueList))
                        {
                            //使用规格的库存
                            var standardRecord = ProductTypeStandardRecordBLL.Read(tmpcart.ProductId, tmpcart.StandardValueList);
                            tmpcart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                            tmpcart.Price            = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                            tmoney += tmpcart.Price * tmpcart.BuyCount;
                        }
                        else
                        {
                            tmpcart.Price = ProductBLL.GetCurrentPrice(tmpcart.Product.SalePrice, base.GradeID);
                            tmoney       += tmpcart.Price * tmpcart.BuyCount;
                        }
                    }
                }
                switch (theFavor.ReduceWay)
                {
                case (int)FavorableMoney.Money:
                    productfavorableMoney += theFavor.ReduceMoney;
                    break;

                case (int)FavorableMoney.Discount:
                    productfavorableMoney += tmoney * (100 - theFavor.ReduceDiscount) / 100;
                    break;

                default:
                    break;
                }
            }
            #endregion
            #region 计算订单优惠活动金额
            decimal favorableMoney = 0;
            favor = FavorableActivityBLL.Read(favor.Id);
            if (favor.Id > 0)
            {
                if (("," + favor.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && productMoney >= favor.OrderProductMoney)
                {
                    switch (favor.ReduceWay)
                    {
                    case (int)FavorableMoney.Money:
                        favorableMoney += favor.ReduceMoney;
                        break;

                    case (int)FavorableMoney.Discount:
                        favorableMoney += productMoney * (100 - favor.ReduceDiscount) / 100;
                        break;

                    default:
                        break;
                    }
                    if (favor.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionID, favor.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion
            /*-----------应付总价---------------------------------------------------*/
            decimal payMoney = productMoney + shippingMoney - couponMoney - pointMoney - favorableMoney - productfavorableMoney;
            //if (productMoney - favorableMoney + shippingMoney - balance - couponMoney <= 0)
            if (payMoney < 0)
            {
                ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            }

            //添加订单
            OrderInfo order = new OrderInfo();
            order.OrderNumber = ShopCommon.CreateOrderNumber();
            order.IsActivity  = (int)BoolType.False;
            if (payMoney == 0 || payPlugins.IsCod == (int)BoolType.True)
            {
                order.OrderStatus = (int)OrderStatus.WaitCheck;
            }
            else
            {
                order.OrderStatus = (int)OrderStatus.WaitPay;
            }
            order.OrderNote      = string.Empty;
            order.ProductMoney   = productMoney;
            order.Balance        = 0;
            order.FavorableMoney = favorableMoney + productfavorableMoney;
            order.OtherMoney     = 0;
            order.CouponMoney    = couponMoney;
            order.Point          = costPoint;
            order.PointMoney     = pointMoney;
            order.Consignee      = consignee;
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();
            order.RegionId = singleUnlimitClass.ClassID;
            order.Address  = address;
            order.ZipCode  = zipCode;
            order.Tel      = tel;
            if (base.UserId == 0)
            {
                order.Email = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email"));
            }
            else
            {
                order.Email = CookiesHelper.ReadCookieValue("UserEmail");
            }
            order.Mobile              = mobile;
            order.ShippingId          = shippingID;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = shippingMoney;
            order.PayKey              = payKey;
            order.PayName             = payPlugins.Name;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityId = RequestHelper.GetForm <int>("FavorableActivityID");
            order.GiftId              = RequestHelper.GetForm <int>("GiftID");
            order.InvoiceTitle        = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceTitle"));
            order.InvoiceContent      = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceContent"));
            order.UserMessage         = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage"));
            order.AddDate             = RequestHelper.DateNow;
            order.IP          = ClientHelper.IP;
            order.UserId      = base.UserId;
            order.UserName    = base.UserName;
            order.GiftMessige = RequestHelper.GetForm <string>("GiftMessige");
            order.IsNoticed   = 0;

            int orderID = OrderBLL.Add(order);
            //使用余额

            /*if (balance > 0)
             * {
             *  UserAccountRecordInfo userAccountRecord = new UserAccountRecordInfo();
             *  userAccountRecord.Money = -balance;
             *  userAccountRecord.Point = 0;
             *  userAccountRecord.Date = RequestHelper.DateNow;
             *  userAccountRecord.IP = ClientHelper.IP;
             *  userAccountRecord.Note = "支付订单:";
             *  userAccountRecord.UserId = base.UserId;
             *  userAccountRecord.UserName = base.UserName;
             *  UserAccountRecordBLL.Add(userAccountRecord);
             * }*/
            #region 减少积分
            if (ShopConfig.ReadConfigInfo().EnablePointPay == 1 && costPoint > 0)
            {
                //减少积分
                UserAccountRecordInfo uarInfo = new UserAccountRecordInfo();
                uarInfo.RecordType = (int)AccountRecordType.Point;
                uarInfo.UserId     = base.UserId;
                uarInfo.UserName   = base.UserName;
                uarInfo.Note       = "支付订单:" + order.OrderNumber;
                uarInfo.Point      = -costPoint;
                uarInfo.Money      = 0;
                uarInfo.Date       = DateTime.Now;
                uarInfo.IP         = ClientHelper.IP;
                UserAccountRecordBLL.Add(uarInfo);
            }
            #endregion
            #region 使用优惠券
            string strUserCoupon = RequestHelper.GetForm <string>("UserCoupon");
            if (couponMoney > 0 && !string.IsNullOrEmpty(strUserCoupon) && strUserCoupon != "0|0")
            {
                userCoupon.IsUse   = (int)BoolType.True;
                userCoupon.OrderId = orderID;
                UserCouponBLL.Update(userCoupon);
            }
            #endregion
            AddOrderProduct(orderID);
            //更改产品库存订单数量
            ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Plus);
            /*----------------------------------------------------------------------*/

            ResponseHelper.Redirect("/Mobile/Finish-I" + orderID.ToString() + ".html");
        }
コード例 #11
0
        /// <summary>
        /// 提交数据
        /// </summary>
        protected override void PostBack()
        {
            int groupID = RequestHelper.GetForm <int>("groupID");

            buyCount = RequestHelper.GetForm <int>("buyCount");
            string url = "/GroupBuyOrder-" + groupID + "-" + buyCount + ".aspx";

            groupBuy = GroupBuyBLL.ReadGroupBuy(groupID);
            if (groupBuy.ID <= 0)
            {
                ScriptHelper.AlertFront("该团购不存在!", url);
            }
            if (UserGroupBuyBLL.ReadUserGroupBuyByUser(groupID, base.UserID).ID > 0)
            {
                ScriptHelper.AlertFront("您已经参加该团购了!", url);
            }
            if (groupBuy.StartDate > DateTime.Now)
            {
                ScriptHelper.AlertFront("该团购还未开始,不能购买!", url);
            }
            if (groupBuy.EndDate < DateTime.Now)
            {
                ScriptHelper.AlertFront("该团购已经结束,不能购买!", url);
            }
            if (buyCount <= 0)
            {
                ScriptHelper.AlertFront("购买数量有误!", url);
            }
            if (buyCount > groupBuy.EachNumber)
            {
                ScriptHelper.AlertFront("购买数量超过了该团购个人限购数!", url);
            }
            int hasBuy = 0;

            foreach (UserGroupBuyInfo userGroupBuy in UserGroupBuyBLL.ReadUserGroupBuyList(groupID))
            {
                hasBuy += userGroupBuy.BuyCount;
            }
            if (buyCount > (groupBuy.MaxCount - hasBuy))
            {
                ScriptHelper.AlertFront("购买数量超过了该团购剩余数!", url);
            }
            product = ProductBLL.ReadProduct(groupBuy.ProductID);

            //检查地址
            string consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee"));

            if (consignee == string.Empty)
            {
                ScriptHelper.AlertFront("收货人姓名不能为空", url);
            }
            string tel    = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel"));
            string mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile"));

            if (tel == string.Empty && mobile == string.Empty)
            {
                ScriptHelper.AlertFront("固定电话,手机必须得填写一个", url);
            }
            string zipCode = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode"));

            if (zipCode == string.Empty)
            {
                ScriptHelper.AlertFront("邮编不能为空", url);
            }
            string address = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address"));

            if (address == string.Empty)
            {
                ScriptHelper.AlertFront("地址不能为空", url);
            }
            //验证配送方式
            int shippingID = RequestHelper.GetForm <int>("ShippingID");

            if (shippingID == int.MinValue)
            {
                ScriptHelper.AlertFront("请选择配送方式", url);
            }
            //检查金额
            decimal productMoney   = groupBuy.Price * buyCount;
            decimal favorableMoney = RequestHelper.GetForm <decimal>("FavorableMoney");
            decimal shippingMoney  = RequestHelper.GetForm <decimal>("ShippingMoney");
            decimal balance        = RequestHelper.GetForm <decimal>("Balance");
            decimal couponMoney    = RequestHelper.GetForm <decimal>("CouponMoney");

            if (productMoney - favorableMoney + shippingMoney - balance - couponMoney < 0)
            {
                ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            }
            //支付方式
            string         payKey     = RequestHelper.GetForm <string>("Pay");
            PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey);
            //添加订单
            OrderInfo order = new OrderInfo();

            order.OrderNumber = ShopCommon.CreateOrderNumber();
            order.IsActivity  = (int)BoolType.True;
            if (productMoney - favorableMoney + shippingMoney - balance - couponMoney == 0 || payPlugins.IsCod == (int)BoolType.True)
            {
                order.OrderStatus = (int)OrderStatus.WaitCheck;
            }
            else
            {
                order.OrderStatus = (int)OrderStatus.WaitPay;
            }
            order.OrderNote      = "团购活动:" + groupBuy.Name;
            order.ProductMoney   = productMoney;
            order.Balance        = balance;
            order.FavorableMoney = favorableMoney;
            order.OtherMoney     = 0;
            order.CouponMoney    = couponMoney;
            order.Consignee      = consignee;
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();

            order.RegionID = singleUnlimitClass.ClassID;
            order.Address  = address;
            order.ZipCode  = zipCode;
            order.Tel      = tel;
            string userEmail = string.Empty;

            if (base.UserID == 0)
            {
                userEmail = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email"));
            }
            else
            {
                userEmail = CookiesHelper.ReadCookieValue("UserEmail");
            }
            order.Email               = userEmail;
            order.Mobile              = mobile;
            order.ShippingID          = shippingID;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = shippingMoney;
            order.PayKey              = payKey;
            order.PayName             = payPlugins.Name;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityID = 0;
            order.GiftID              = 0;
            order.InvoiceTitle        = string.Empty;
            order.InvoiceContent      = string.Empty;
            order.UserMessage         = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage"));
            order.AddDate             = RequestHelper.DateNow;
            order.IP       = ClientHelper.IP;
            order.UserID   = base.UserID;
            order.UserName = base.UserName;
            int orderID = OrderBLL.AddOrder(order);

            OrderDetailInfo orderDetail = new OrderDetailInfo();

            orderDetail.OrderID       = orderID;
            orderDetail.ProductID     = product.ID;
            orderDetail.ProductName   = product.Name;
            orderDetail.ProductWeight = product.Weight;
            orderDetail.SendPoint     = 0;
            orderDetail.ProductPrice  = groupBuy.Price;
            orderDetail.BuyCount      = buyCount;
            orderDetail.FatherID      = 0;
            orderDetail.RandNumber    = string.Empty;
            orderDetail.GiftPackID    = 0;
            OrderDetailBLL.AddOrderDetail(orderDetail);
            //更改产品库存订单数量
            ProductBLL.ChangeProductOrderCountByOrder(orderID, ChangeAction.Plus);

            //添加团购单
            UserGroupBuyInfo buyInfo = new UserGroupBuyInfo();

            buyInfo.GroupBuyID = groupBuy.ID;
            buyInfo.Date       = RequestHelper.DateNow;
            buyInfo.IP         = ClientHelper.IP;
            buyInfo.BuyCount   = buyCount;
            buyInfo.OrderID    = orderID;
            buyInfo.UserID     = base.UserID;
            buyInfo.UserName   = base.UserName;
            buyInfo.Consignee  = consignee;
            buyInfo.RegionID   = singleUnlimitClass.ClassID;
            buyInfo.Address    = address;
            buyInfo.ZipCode    = zipCode;
            buyInfo.Tel        = tel;
            buyInfo.Email      = userEmail;
            buyInfo.Mobile     = mobile;
            UserGroupBuyBLL.AddUserGroupBuy(buyInfo);

            ResponseHelper.Redirect("/Finish-I" + orderID.ToString() + ".aspx");
        }