Пример #1
0
        /// <summary>
        /// 检查用户优惠券
        /// </summary>
        protected void CheckUserCoupon()
        {
            string result   = string.Empty;
            string number   = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Number"));
            string password = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Password"));

            if (number != string.Empty && password != string.Empty)
            {
                UserCouponInfo userCoupon = UserCouponBLL.Read(number, password);
                if (userCoupon.Id > 0)
                {
                    if (userCoupon.UserId == 0)
                    {
                        if (userCoupon.IsUse == (int)BoolType.False)
                        {
                            CouponInfo coupon = CouponBLL.Read(userCoupon.CouponId);
                            if (RequestHelper.DateNow >= coupon.UseStartDate && RequestHelper.DateNow <= coupon.UseEndDate)
                            {
                                if (Sessions.ProductTotalPrice >= coupon.UseMinAmount)
                                {
                                    result = userCoupon.Id.ToString() + "|" + coupon.Money.ToString();
                                    if (base.UserId > 0)
                                    {
                                        userCoupon.UserId   = base.UserId;
                                        userCoupon.UserName = base.UserName;
                                        UserCouponBLL.Update(userCoupon);
                                    }
                                }
                                else
                                {
                                    result = "购物车的金额小于该优惠券要求的最低消费的金额";
                                }
                            }
                            else
                            {
                                result = "该优惠券没在使用期限内";
                            }
                        }
                        else
                        {
                            result = "该优惠券已经使用了";
                        }
                    }
                    else
                    {
                        result = "该优惠券已经绑定了用户";
                    }
                }
                else
                {
                    result = "不存在该优惠券";
                }
            }
            else
            {
                result = "编号或者密码不能为空";
            }
            ResponseHelper.Write(result);
            ResponseHelper.End();
        }
Пример #2
0
        /// <summary>
        /// 添加优惠劵
        /// </summary>
        protected void AddUserCoupon()
        {
            string result   = string.Empty;
            string number   = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Number"));
            string password = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Password"));

            if (number == string.Empty || password == string.Empty)
            {
                result = "请填写卡号和密码";
            }
            else
            {
                UserCouponInfo userCoupon = UserCouponBLL.Read(number, password);
                if (userCoupon.Id == 0)
                {
                    result = "卡号或者密码错误";
                }
                else
                {
                    if (userCoupon.UserId > 0)
                    {
                        result = "该优惠券已经绑定了用户";
                    }
                    else
                    {
                        userCoupon.UserId   = base.UserId;
                        userCoupon.UserName = base.UserName;
                        UserCouponBLL.Update(userCoupon);
                    }
                }
            }
            ResponseHelper.Write(result);
            ResponseHelper.End();
        }
Пример #3
0
        public UserCouponInfo ReadUserCouponByOrder(int orderID)
        {
            SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@orderID", SqlDbType.Int) };
            pt[0].Value = orderID;
            UserCouponInfo info = new UserCouponInfo();

            using (SqlDataReader reader = ShopMssqlHelper.ExecuteReader(ShopMssqlHelper.TablePrefix + "ReadUserCouponByOrder", pt))
            {
                if (reader.Read())
                {
                    info.ID                  = reader.GetInt32(0);
                    info.CouponID            = reader.GetInt32(1);
                    info.GetType             = reader.GetInt32(2);
                    info.Number              = reader[3].ToString();
                    info.Password            = reader[4].ToString();
                    info.IsUse               = reader.GetInt32(5);
                    info.OrderID             = reader.GetInt32(6);
                    info.UserID              = reader.GetInt32(7);
                    info.UserName            = reader[8].ToString();
                    info.Coupon.Money        = reader.GetDecimal(9);
                    info.Coupon.UseMinAmount = reader.GetDecimal(10);
                }
            }
            return(info);
        }
Пример #4
0
        protected void AddUserCoupon()
        {
            string content  = string.Empty;
            string number   = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Number"));
            string password = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Password"));

            if ((number == string.Empty) || (password == string.Empty))
            {
                content = "ÇëÌîд¿¨ºÅºÍÃÜÂë";
            }
            else
            {
                UserCouponInfo userCoupon = UserCouponBLL.ReadUserCouponByNumber(number, password);
                if (userCoupon.ID == 0)
                {
                    content = "¿¨ºÅ»òÕßÃÜÂë´íÎó";
                }
                else if (userCoupon.UserID > 0)
                {
                    content = "¸ÃÓÅ»ÝȯÒѾ­°ó¶¨ÁËÓû§";
                }
                else
                {
                    userCoupon.UserID   = base.UserID;
                    userCoupon.UserName = base.UserName;
                    UserCouponBLL.UpdateUserCoupon(userCoupon);
                }
            }
            ResponseHelper.Write(content);
            ResponseHelper.End();
        }
Пример #5
0
        public List <UserCouponInfo> ReadUserCouponCanUse(int userID)
        {
            List <UserCouponInfo> list = new List <UserCouponInfo>();

            SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@userID", SqlDbType.Int) };
            pt[0].Value = userID;
            using (SqlDataReader reader = ShopMssqlHelper.ExecuteReader(ShopMssqlHelper.TablePrefix + "ReadUserCouponCanUse", pt))
            {
                while (reader.Read())
                {
                    UserCouponInfo item = new UserCouponInfo();
                    item.ID                  = reader.GetInt32(0);
                    item.CouponID            = reader.GetInt32(1);
                    item.GetType             = reader.GetInt32(2);
                    item.Number              = reader[3].ToString();
                    item.Password            = reader[4].ToString();
                    item.IsUse               = reader.GetInt32(5);
                    item.OrderID             = reader.GetInt32(6);
                    item.UserID              = reader.GetInt32(7);
                    item.UserName            = reader[8].ToString();
                    item.Coupon.Money        = reader.GetDecimal(9);
                    item.Coupon.UseMinAmount = reader.GetDecimal(10);
                    list.Add(item);
                }
            }
            return(list);
        }
Пример #6
0
        public ActionResult GetBirthdayCoupon()
        {
            int count      = 0;
            var couponlist = CouponBLL.SearchList(1, 1, new CouponSearchInfo {
                Type = (int)CouponKind.BirthdayGet, CanUse = 1
            }, ref count);

            //如果有进行中的生日礼券,并且 用户本年度未领取生日礼券
            if (couponlist.Count > 0 && (user.HasBirthdayCoupon == 0 || (user.HasBirthdayCoupon != 0 && user.GetBirthdayCouponDate.Year != DateTime.Now.Year)))
            {
                UserCouponInfo userCoupon = UserCouponBLL.ReadLast(couponlist[0].Id);
                if (UserCouponBLL.UniqueUserCatch(user.Id, couponlist[0].Id))
                {
                    int startNumber = 0;
                    if (userCoupon.Id > 0)
                    {
                        string tempNumber = userCoupon.Number.Substring(3, 5);
                        while (tempNumber.Substring(0, 1) == "0")
                        {
                            tempNumber = tempNumber.Substring(1);
                        }
                        startNumber = Convert.ToInt32(tempNumber);
                    }
                    startNumber++;
                    int cpid = UserCouponBLL.Add(new UserCouponInfo
                    {
                        UserId   = user.Id,
                        UserName = user.UserName,
                        CouponId = couponlist[0].Id,
                        GetType  = (int)CouponType.CatchByUser,
                        Number   = ShopCommon.CreateCouponNo(couponlist[0].Id, startNumber),
                        Password = ShopCommon.CreateCouponPassword(startNumber),
                        IsUse    = (int)BoolType.False,
                        OrderId  = 0
                    });
                    //领取成功改变user表标识
                    if (cpid > 0)
                    {
                        Dictionary <string, object> dict = new Dictionary <string, object>();
                        dict.Add("[HasBirthdayCoupon]", 1);
                        dict.Add("[GetBirthdayCouponDate]", DateTime.Now);
                        UserBLL.UpdatePart("[usr]", dict, user.Id);
                        return(Json(new { ok = true }));
                    }
                    return(Json(new { ok = false, msg = "领取失败,请稍后重试" }));
                }
                else
                {
                    return(Json(new { ok = false, msg = "领取失败,您已领取过生日礼券" }));
                }
            }
            else
            {
                return(Json(new { ok = false, msg = "活动暂停或者您已领取过生日礼券" }));
            }
        }
Пример #7
0
 public void UpdateUserCoupon(UserCouponInfo userCoupon)
 {
     SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@isUse", SqlDbType.Int), new SqlParameter("@orderID", SqlDbType.Int), new SqlParameter("@userID", SqlDbType.Int), new SqlParameter("@userName", SqlDbType.NVarChar) };
     pt[0].Value = userCoupon.ID;
     pt[1].Value = userCoupon.IsUse;
     pt[2].Value = userCoupon.OrderID;
     pt[3].Value = userCoupon.UserID;
     pt[4].Value = userCoupon.UserName;
     ShopMssqlHelper.ExecuteNonQuery(ShopMssqlHelper.TablePrefix + "UpdateUserCoupon", pt);
 }
Пример #8
0
        public void Update(UserCouponInfo entity)
        {
            using (var conn = new SqlConnection(connectString))
            {
                string sql = @"UPDATE UsrCoupon SET CouponId = @CouponId, GetType = @GetType, Number = @Number, Password = @Password, IsUse = @IsUse, OrderId = @OrderId, UserId = @UserId, UserName = @UserName
                            where Id=@Id";

                conn.Execute(sql, entity);
            }
        }
Пример #9
0
        public int Add(UserCouponInfo entity)
        {
            using (var conn = new SqlConnection(connectString))
            {
                string sql = @"INSERT INTO UsrCoupon( CouponId,GetType,Number,Password,IsUse,OrderId,UserId,UserName) VALUES(@CouponId,@GetType,@Number,@Password,@IsUse,@OrderId,@UserId,@UserName);
                            select SCOPE_IDENTITY()";

                return(conn.Query <int>(sql, entity).Single());
            }
        }
Пример #10
0
        public ActionResult GetCouponByUser()
        {
            int couponId = RequestHelper.GetForm <int>("couponId");

            if (uid > 0 && couponId > 0)
            {
                CouponInfo coupon = CouponBLL.Read(couponId);
                if (UserCouponBLL.UniqueUserCatch(uid, couponId))
                {
                    if (coupon.TotalCount - 1 < coupon.UsedCount)
                    {
                        return(Json(new { ok = false, msg = "优惠券余量不足" }));
                    }
                    UserCouponInfo userCoupon  = UserCouponBLL.ReadLast(couponId);
                    int            startNumber = 0;
                    if (userCoupon.Id > 0)
                    {
                        string tempNumber = userCoupon.Number.Substring(3, 5);
                        while (tempNumber.Substring(0, 1) == "0")
                        {
                            tempNumber = tempNumber.Substring(1);
                        }
                        startNumber = Convert.ToInt32(tempNumber);
                    }
                    startNumber++;
                    UserCouponInfo tmpCoupon = new UserCouponInfo();
                    tmpCoupon.CouponId = couponId;
                    tmpCoupon.GetType  = (int)CouponType.CatchByUser;
                    tmpCoupon.Number   = ShopCommon.CreateCouponNo(couponId, startNumber);
                    tmpCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
                    tmpCoupon.IsUse    = (int)BoolType.False;
                    tmpCoupon.OrderId  = 0;
                    tmpCoupon.UserId   = uid;
                    tmpCoupon.UserName = user.UserName;
                    if (UserCouponBLL.Add(tmpCoupon) > 0)
                    {//如果领取成功,增加优惠券的发放(领取)量
                        coupon.UsedCount++;
                        Dictionary <string, object> dict = new Dictionary <string, object>();
                        dict.Add("[UsedCount]", coupon.UsedCount);
                        CouponBLL.UpdatePart("[Coupon]", dict, coupon.Id);
                    }
                    return(Json(new { ok = true, msg = "领券成功" }));
                }
                else
                {
                    return(Json(new { ok = false, msg = "您已领过此优惠券" }));
                }
            }
            else
            {
                return(Json(new { ok = false, msg = "请先登录" }));
            }
        }
Пример #11
0
 public int AddUserCoupon(UserCouponInfo userCoupon)
 {
     SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@couponID", SqlDbType.Int), new SqlParameter("@getType", SqlDbType.Int), new SqlParameter("@number", SqlDbType.NVarChar), new SqlParameter("@password", SqlDbType.NVarChar), new SqlParameter("@isUse", SqlDbType.Int), new SqlParameter("@orderID", SqlDbType.Int), new SqlParameter("@userID", SqlDbType.Int), new SqlParameter("@userName", SqlDbType.NVarChar) };
     pt[0].Value = userCoupon.CouponID;
     pt[1].Value = userCoupon.GetType;
     pt[2].Value = userCoupon.Number;
     pt[3].Value = userCoupon.Password;
     pt[4].Value = userCoupon.IsUse;
     pt[5].Value = userCoupon.OrderID;
     pt[6].Value = userCoupon.UserID;
     pt[7].Value = userCoupon.UserName;
     return(Convert.ToInt32(ShopMssqlHelper.ExecuteScalar(ShopMssqlHelper.TablePrefix + "AddUserCoupon", pt)));
 }
Пример #12
0
        /// <summary>
        /// 添加优惠劵
        /// </summary>
        protected void AddUserCoupon()
        {
            string result   = string.Empty;
            string number   = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Number"));
            string password = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("Password"));

            if (number == string.Empty || password == string.Empty)
            {
                result = "请填写优惠券卡号和密码";
            }
            else
            {
                UserCouponInfo userCoupon = UserCouponBLL.Read(number, password);
                if (userCoupon.Id <= 0)
                {
                    result = "卡号或者密码错误";
                }
                else
                {
                    if (userCoupon.UserId > 0)
                    {
                        result = "该优惠券已经绑定了用户";
                    }
                    else
                    {
                        if (userCoupon.IsUse == (int)BoolType.True)
                        {
                            result = "该优惠券已经使用了";
                        }
                        else
                        {
                            CouponInfo coupon = CouponBLL.Read(userCoupon.CouponId);
                            if (RequestHelper.DateNow >= coupon.UseStartDate && RequestHelper.DateNow <= coupon.UseEndDate)
                            {
                                userCoupon.UserId   = base.UserId;
                                userCoupon.UserName = base.UserName;
                                UserCouponBLL.Update(userCoupon);
                            }
                            else
                            {
                                result = "该优惠券没在使用期限内";
                            }
                        }
                    }
                }
            }
            ResponseHelper.Write(result);
            ResponseHelper.End();
        }
Пример #13
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            CheckAdminPower("SendCoupon", PowerCheckType.Single);
            int sendCount = 0;

            int.TryParse(SendCount.Text.Trim(), out sendCount);
            int    couponID = RequestHelper.GetQueryString <int>("CouponID");
            string sendUser = RequestHelper.GetForm <string>("RelationUser");

            if (sendCount + sendUser.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length > 0)
            {
                CouponInfo     coupon      = CouponBLL.Read(couponID);
                UserCouponInfo userCoupon  = UserCouponBLL.ReadLast(couponID);
                int            startNumber = 0;
                if (userCoupon.Id > 0)
                {
                    string tempNumber = userCoupon.Number.Substring(3, 5);
                    while (tempNumber.Substring(0, 1) == "0")
                    {
                        tempNumber = tempNumber.Substring(1);
                    }
                    startNumber = Convert.ToInt32(tempNumber);
                }
                //如果线上、线下发放数量超过了优惠券剩余量
                if (coupon.UsedCount + sendCount + sendUser.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length > coupon.TotalCount)
                {
                    ScriptHelper.Alert("优惠券剩余量不足");
                }
                else
                {
                    CreateOfflineCoupon(couponID, sendCount, ref startNumber);
                    SeandUserCoupon(couponID, sendUser, ref startNumber);
                    //优惠券发放量增加
                    coupon.UsedCount += sendCount + sendUser.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length;
                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    dict.Add("[UsedCount]", coupon.UsedCount);
                    CouponBLL.UpdatePart("[Coupon]", dict, coupon.Id);
                }
                AdminLogBLL.Add(ShopLanguage.ReadLanguage("SendCoupon"), coupon.Id);
                string alertMessage = ShopLanguage.ReadLanguage("SendOK");
                ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl);
            }
            else
            {
                //ScriptHelper.Alert("请选择在线发放用户或输入线下发放数量");
                ScriptHelper.Alert("请选择在线发放用户");
            }
        }
Пример #14
0
 public void PrepareUserCouponModel(SqlDataReader dr, List <UserCouponInfo> userCouponList)
 {
     while (dr.Read())
     {
         UserCouponInfo item = new UserCouponInfo();
         item.ID       = dr.GetInt32(0);
         item.CouponID = dr.GetInt32(1);
         item.GetType  = dr.GetInt32(2);
         item.Number   = dr[3].ToString();
         item.Password = dr[4].ToString();
         item.IsUse    = dr.GetInt32(5);
         item.OrderID  = dr.GetInt32(6);
         item.UserID   = dr.GetInt32(7);
         item.UserName = dr[8].ToString();
         userCouponList.Add(item);
     }
 }
Пример #15
0
 /// <summary>
 /// 生成线下优惠券
 /// </summary>
 private void CreateOfflineCoupon(int couponID, int sendCount, ref int startNumber)
 {
     if (sendCount > 0)
     {
         for (int i = 0; i < sendCount; i++)
         {
             startNumber++;
             UserCouponInfo userCoupon = new UserCouponInfo();
             userCoupon.CouponId = couponID;
             userCoupon.GetType  = (int)CouponType.Offline;
             userCoupon.Number   = ShopCommon.CreateCouponNo(couponID, startNumber);
             userCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
             userCoupon.IsUse    = (int)BoolType.False;
             userCoupon.OrderId  = 0;
             userCoupon.UserId   = 0;
             userCoupon.UserName = string.Empty;
             UserCouponBLL.Add(userCoupon);
         }
     }
 }
Пример #16
0
 /// <summary>
 /// 生成按用户发放的优惠券
 /// </summary>
 private void SeandUserCoupon(int couponID, string sendUser, ref int startNumber)
 {
     if (sendUser != string.Empty)
     {
         foreach (string user in sendUser.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
         {
             startNumber++;
             int            userID     = Convert.ToInt32(user.Split('|')[0]);
             string         userName   = user.Split('|')[1];
             UserCouponInfo userCoupon = new UserCouponInfo();
             userCoupon.CouponId = couponID;
             userCoupon.GetType  = (int)CouponType.Online;
             userCoupon.Number   = ShopCommon.CreateCouponNo(couponID, startNumber);
             userCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
             userCoupon.IsUse    = (int)BoolType.False;
             userCoupon.OrderId  = 0;
             userCoupon.UserId   = userID;
             userCoupon.UserName = userName;
             UserCouponBLL.Add(userCoupon);
         }
     }
 }
Пример #17
0
        public UserCouponInfo ReadUserCouponByNumber(string number, string password)
        {
            SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@number", SqlDbType.NVarChar), new SqlParameter("@password", SqlDbType.NVarChar) };
            pt[0].Value = number;
            pt[1].Value = password;
            UserCouponInfo info = new UserCouponInfo();

            using (SqlDataReader reader = ShopMssqlHelper.ExecuteReader(ShopMssqlHelper.TablePrefix + "ReadUserCouponByNumber", pt))
            {
                if (reader.Read())
                {
                    info.ID       = reader.GetInt32(0);
                    info.CouponID = reader.GetInt32(1);
                    info.GetType  = reader.GetInt32(2);
                    info.Number   = reader[3].ToString();
                    info.Password = reader[4].ToString();
                    info.IsUse    = reader.GetInt32(5);
                    info.OrderID  = reader.GetInt32(6);
                    info.UserID   = reader.GetInt32(7);
                    info.UserName = reader[8].ToString();
                }
            }
            return(info);
        }
Пример #18
0
        public UserCouponInfo ReadUserCoupon(int id, int userID)
        {
            SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@userID", SqlDbType.Int) };
            pt[0].Value = id;
            pt[1].Value = userID;
            UserCouponInfo info = new UserCouponInfo();

            using (SqlDataReader reader = ShopMssqlHelper.ExecuteReader(ShopMssqlHelper.TablePrefix + "ReadUserCoupon", pt))
            {
                if (reader.Read())
                {
                    info.ID       = reader.GetInt32(0);
                    info.CouponID = reader.GetInt32(1);
                    info.GetType  = reader.GetInt32(2);
                    info.Number   = reader[3].ToString();
                    info.Password = reader[4].ToString();
                    info.IsUse    = reader.GetInt32(5);
                    info.OrderID  = reader.GetInt32(6);
                    info.UserID   = reader.GetInt32(7);
                    info.UserName = reader[8].ToString();
                }
            }
            return(info);
        }
Пример #19
0
        /// <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");
        }
Пример #20
0
 public static void UpdateUserCoupon(UserCouponInfo userCoupon)
 {
     dal.UpdateUserCoupon(userCoupon);
 }
Пример #21
0
 public static int AddUserCoupon(UserCouponInfo userCoupon)
 {
     userCoupon.ID = dal.AddUserCoupon(userCoupon);
     return(userCoupon.ID);
 }
Пример #22
0
        public ActionResult Index()
        {
            int[] arrT = new int[5];
            //检查用户的待付款订单是否超时失效,超时则更新为失效状态
            OrderBLL.CheckOrderPayTime(user.Id);
            //订单自动收货
            OrderBLL.CheckOrderRecieveTimeProg(user.Id);

            OrderSearchInfo orderSearch = new OrderSearchInfo();

            orderSearch.OrderStatus = (int)(OrderStatus.WaitPay);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            arrT[0] = OrderBLL.SearchList(orderSearch).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.WaitCheck);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            //待审核
            var orderList = OrderBLL.SearchList(orderSearch);

            arrT[1] = orderList.Count;
            #region 待分享
            var list1     = orderList.Where(k => k.IsActivity == (int)OrderKind.GroupBuy && k.FavorableActivityId > 0);
            var groupIds  = list1.Select(k => k.FavorableActivityId).ToArray();
            var groupList = GroupBuyBLL.ReadList(groupIds).Where(k => k.StartTime <= DateTime.Now && k.EndTime >= DateTime.Now && k.Quantity > k.SignCount);
            var ids       = groupList.Select(k => k.Id);
            var list2     = list1.Where(k => ids.Contains(k.FavorableActivityId));
            arrT[4] = list2.Count();
            #endregion

            orderSearch.OrderStatus = (int)(OrderStatus.HasShipping);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            arrT[2] = OrderBLL.SearchList(orderSearch).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.ReceiveShipping);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            arrT[3] = OrderBLL.SearchList(orderSearch).Count;
            //是否填写手机号
            bool hasMobile = !string.IsNullOrEmpty(user.Mobile.Trim());
            #region 生日前后5天登录会员中心,自动发放本年度生日礼券。( 是否获取生日优惠券,本年生日前后5天出现提示)
            //判断是否能够获取本年度生日礼券
            bool     canGetBirthdayCoupon = true;
            DateTime birthday             = DateTime.MinValue;
            //如果用户已填写生日,则在生日前后5天提示领取生日礼券
            if (DateTime.TryParse(user.Birthday, out birthday) && (birthday.AddDays(-5).Month == DateTime.Now.Month && birthday.AddDays(-5).Day <= DateTime.Now.Day) && (birthday.AddDays(5).Month == DateTime.Now.Month && birthday.AddDays(5).Day >= DateTime.Now.Day))
            {
                int count      = 0;
                var couponlist = CouponBLL.SearchList(1, 1, new CouponSearchInfo {
                    Type = (int)CouponKind.BirthdayGet, CanUse = 1
                }, ref count);
                //如果有生日礼券活动进行中
                if (couponlist.Count > 0)
                {
                    ////如果本年度已获取,则不能再获取
                    //if (user.HasBirthdayCoupon != 0 && user.GetBirthdayCouponDate.Year == DateTime.Now.Year) canGetBirthdayCoupon = false;
                    #region 自动发放,每年度限领1次
                    if (user.HasBirthdayCoupon == 0 || (user.HasBirthdayCoupon != 0 && user.GetBirthdayCouponDate.Year != DateTime.Now.Year))
                    {
                        UserCouponInfo userCoupon = UserCouponBLL.ReadLast(couponlist[0].Id);
                        if (UserCouponBLL.UniqueUserCatch(user.Id, couponlist[0].Id))
                        {
                            int startNumber = 0;
                            if (userCoupon.Id > 0)
                            {
                                string tempNumber = userCoupon.Number.Substring(3, 5);
                                while (tempNumber.Substring(0, 1) == "0")
                                {
                                    tempNumber = tempNumber.Substring(1);
                                }
                                startNumber = Convert.ToInt32(tempNumber);
                            }
                            startNumber++;
                            int cpid = UserCouponBLL.Add(new UserCouponInfo
                            {
                                UserId   = user.Id,
                                UserName = user.UserName,
                                CouponId = couponlist[0].Id,
                                GetType  = (int)CouponType.BirthdayGet,
                                Number   = ShopCommon.CreateCouponNo(couponlist[0].Id, startNumber),
                                Password = ShopCommon.CreateCouponPassword(startNumber),
                                IsUse    = (int)BoolType.False,
                                OrderId  = 0
                            });
                            //领取成功改变user表标识
                            if (cpid > 0)
                            {
                                Dictionary <string, object> dict = new Dictionary <string, object>();
                                dict.Add("[HasBirthdayCoupon]", 1);
                                dict.Add("[GetBirthdayCouponDate]", DateTime.Now);
                                UserBLL.UpdatePart("[usr]", dict, user.Id);
                                //user对应的未使用优惠券数量加1
                                user.CouPonLeft++;
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    //如果商家后台没有设置正在进行中的会员生日券,则不能获取
                    canGetBirthdayCoupon = false;
                }
            }
            else
            {
                canGetBirthdayCoupon = false;
            }
            #endregion
            //计算是否
            return(Json(new { ordercount = arrT, hasmobile = hasMobile, usergrade = userGradeInfo, cangetbirthdaycoupon = canGetBirthdayCoupon, couponleft = user.CouPonLeft, pointleft = user.PointLeft }, JsonRequestBehavior.AllowGet));
        }
Пример #23
0
        public JsonResult CouponRegister(int userId, int couponId)
        {
            try
            {
                UserInfo   user   = UserBLL.Read(userId);
                CouponInfo coupon = CouponBLL.Read(couponId);
                if (user == null || user.Id <= 0 || coupon.Id <= 0)
                {
                    return(Json(new { ok = false, error = "未登录或登录失效", code = -1 }));
                }

                if (UserCouponBLL.UniqueUserCatch(user.Id, couponId))
                {
                    //新人券暂时不限制总数
                    //if (coupon.TotalCount - 1 < coupon.UsedCount)
                    //{
                    //    return Json(new { ok = false, msg = "优惠券余量不足" });
                    //}
                    UserCouponInfo userCoupon  = UserCouponBLL.ReadLast(couponId);
                    int            startNumber = 0;
                    if (userCoupon.Id > 0)
                    {
                        string tempNumber = userCoupon.Number.Substring(3, 5);
                        while (tempNumber.Substring(0, 1) == "0")
                        {
                            tempNumber = tempNumber.Substring(1);
                        }
                        startNumber = Convert.ToInt32(tempNumber);
                    }
                    startNumber++;
                    UserCouponInfo tmpCoupon = new UserCouponInfo();
                    tmpCoupon.CouponId = couponId;
                    tmpCoupon.GetType  = (int)CouponType.RegisterGet;
                    tmpCoupon.Number   = ShopCommon.CreateCouponNo(couponId, startNumber);
                    tmpCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
                    tmpCoupon.IsUse    = (int)BoolType.False;
                    tmpCoupon.OrderId  = 0;
                    tmpCoupon.UserId   = user.Id;
                    tmpCoupon.UserName = user.UserName;
                    if (UserCouponBLL.Add(tmpCoupon) > 0)
                    {//如果领取成功,增加优惠券的发放(领取)量
                        coupon.UsedCount++;
                        Dictionary <string, object> dict = new Dictionary <string, object>();
                        dict.Add("[UsedCount]", coupon.UsedCount);
                        CouponBLL.UpdatePart("[Coupon]", dict, coupon.Id);
                        //该变用户标识:已领过新人券
                        dict = new Dictionary <string, object>();
                        dict.Add("[HasRegisterCoupon]", 1);
                        UserBLL.UpdatePart("[usr]", dict, userId);
                    }
                    return(Json(new { ok = true, error = "领券成功" }));
                }
                else
                {
                    //该变用户标识:已领过新人券
                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    dict.Add("[HasRegisterCoupon]", 1);
                    UserBLL.UpdatePart("[usr]", dict, userId);
                    return(Json(new { ok = false, error = "您已领过", code = 0 }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { ok = false, error = "系统忙", code = 0 }));
            }
        }
Пример #24
0
        /// <summary>
        /// 完成确认按钮点击方法
        /// </summary>
        protected void ReceivedButton_Click(object sender, EventArgs e)
        {
            OrderInfo order = ButtoStart();

            #region 确认收货赠送优惠券
            int count      = 0;
            var couponlist = CouponBLL.SearchList(1, 1, new CouponSearchInfo {
                Type = (int)CouponKind.ReceiveShippingGet, CanUse = 1
            }, ref count);
            if (couponlist.Count > 0)
            {
                UserCouponInfo userCoupon  = UserCouponBLL.ReadLast(couponlist[0].Id);
                int            startNumber = 0;
                if (userCoupon.Id > 0)
                {
                    string tempNumber = userCoupon.Number.Substring(3, 5);
                    while (tempNumber.Substring(0, 1) == "0")
                    {
                        tempNumber = tempNumber.Substring(1);
                    }
                    startNumber = Convert.ToInt32(tempNumber);
                }
                startNumber++;
                UserCouponBLL.Add(new UserCouponInfo
                {
                    UserId   = order.UserId,
                    UserName = order.UserName,
                    CouponId = couponlist[0].Id,
                    GetType  = (int)CouponType.ReceiveShippingGet,
                    Number   = ShopCommon.CreateCouponNo(couponlist[0].Id, startNumber),
                    Password = ShopCommon.CreateCouponPassword(startNumber),
                    IsUse    = (int)BoolType.False,
                    OrderId  = 0
                });
            }
            #endregion
            #region 赠送积分
            //赠送积分--根据商品信息填写的赠送积分额度
            //int sendPoint = OrderBLL.ReadOrderSendPoint(order.Id);
            //根据订单付款金额全额返还积分
            int sendPoint = (int)Math.Floor(OrderBLL.ReadNoPayMoney(order));
            if (sendPoint > 0 && order.IsActivity == (int)BoolType.False)
            {
                var accountRecord = new UserAccountRecordInfo
                {
                    RecordType = (int)AccountRecordType.Point,
                    Money      = 0,
                    Point      = sendPoint,
                    Date       = DateTime.Now,
                    IP         = ClientHelper.IP,
                    Note       = ShopLanguage.ReadLanguage("OrderReceived").Replace("$OrderNumber", order.OrderNumber),
                    UserId     = order.UserId,
                    UserName   = order.UserName
                };
                UserAccountRecordBLL.Add(accountRecord);
            }
            #endregion
            #region 确认收货给分销商返佣
            //订单实际支付金额
            decimal paid_money = OrderBLL.ReadNoPayMoney(order);
            //购买人
            var user = UserBLL.Read(order.UserId);
            //购买者有推荐人 且 实际支付金额大于0才进行返佣
            if (user.Recommend_UserId > 0 && paid_money > 0)
            {
                RebateBLL.RebateToDistributor(user, paid_money, order.Id);
            }
            #endregion
            int startOrderStatus = order.OrderStatus;
            order.OrderStatus = (int)OrderStatus.ReceiveShipping;
            ButtonEnd(order, Note.Text, OrderOperate.Received, startOrderStatus);
        }
Пример #25
0
 public static int Add(UserCouponInfo entity)
 {
     return(dal.Add(entity));
 }
Пример #26
0
        private void Submit()
        {
            /*-----------重新验证选择的商品------------------------------------------*/
            checkCart = StringHelper.AddSafe(RequestHelper.GetForm <string>("CheckCart"));
            int[]  cartIds          = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            string checkCartCookies = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));

            if (checkCart != checkCartCookies)
            {
                ResponseHelper.Write("error|购买商品发生了变化,请重新提交|/cart.html");
                ResponseHelper.End();
            }

            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品|/cart.html");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/

            /*-----------读取购物车清单---------------------------------------------*/
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId);

            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count <= 0)
            {
                ResponseHelper.Write("error|请选择需要购买的商品|/cart.html");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/

            /*-----------必要性检查:收货地址,配送方式,支付方式-------------------*/
            var address = new UserAddressInfo {
                Id = RequestHelper.GetForm <int>("address_id")
            };
            var shipping = new ShippingInfo {
                Id = RequestHelper.GetForm <int>("ShippingId")
            };
            var pay = new PayPluginsInfo {
                Key = StringHelper.AddSafe(RequestHelper.GetForm <string>("pay"))
            };
            //订单优惠活动
            var favor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("FavorableActivity")
            };
            //商品优惠
            var productfavor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("ProductFavorableActivity")
            };
            bool reNecessaryCheck = false;

doReNecessaryCheck:
            if (address.Id < 1)
            {
                ResponseHelper.Write("error|请选择收货地址|");
                ResponseHelper.End();
            }
            if (shipping.Id < 1)
            {
                ResponseHelper.Write("error|请选择配送方式|");
                ResponseHelper.End();
            }
            if (string.IsNullOrEmpty(pay.Key))
            {
                ResponseHelper.Write("error|请选择支付方式|");
                ResponseHelper.End();
            }

            //读取数据库中的数据,进行重复验证
            if (!reNecessaryCheck)
            {
                address  = UserAddressBLL.Read(address.Id, base.UserId);
                shipping = ShippingBLL.Read(shipping.Id);
                pay      = PayPlugins.ReadPayPlugins(pay.Key);

                reNecessaryCheck = true;
                goto doReNecessaryCheck;
            }
            /*----------------------------------------------------------------------*/

            /*-----------商品清单、商品总价、邮费价格、库存检查---------------------*/
            var     user = UserBLL.ReadUserMore(base.UserId);
            decimal productMoney = 0, pointMoney = 0;
            int     count = 0;
            //输入的兑换积分数
            var costPoint = RequestHelper.GetForm <int>("costPoint");

            int[] ids         = cartList.Select(k => k.ProductId).ToArray();
            var   productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            foreach (var cart in cartList)
            {
                cart.Product = productList.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                    productMoney         += ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID) * (cart.BuyCount);
                }
                else
                {
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount;
                    productMoney         += ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID) * (cart.BuyCount);
                }

                //检查库存
                if (cart.BuyCount > cart.LeftStorageCount)
                {
                    ResponseHelper.Write("error|商品[" + cart.ProductName + "]库存不足,无法购买|");
                    ResponseHelper.End();
                }
            }

            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shipping.Id, address.RegionId);
            decimal            shippingMoney  = ShippingRegionBLL.ReadShippingMoney(shipping.Id, shippingRegion.RegionId, cartList);

            /*----------------------------------------------------------------------*/
            #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
                        {
                            ResponseHelper.Write("error|结算金额小于该优惠券要求的最低消费的金额|");
                            ResponseHelper.End();
                        }
                    }
                }
            }
            #endregion
            #region 如果开启了:使用积分抵现,计算积分抵现的现金金额
            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 productfavorableMoney = 0;
            var     theFavor = FavorableActivityBLL.Read(productfavor.Id);
            if (theFavor.Id > 0)
            {
                decimal tmoney = 0;
                foreach (var tmpcart in cartList)
                {
                    tmpcart.Product = productList.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(address.RegionId, favor.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion
            /*-----------应付总价---------------------------------------------------*/
            decimal payMoney = productMoney + shippingMoney - couponMoney - pointMoney - favorableMoney - productfavorableMoney;
            /*----------------------------------------------------------------------*/

            /*-----------检查金额---------------------------------------------------*/
            if (payMoney <= 0)
            {
                ResponseHelper.Write("error|金额有错误,请重新检查|");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/


            /*-----------组装基础订单模型,循环生成订单-----------------------------*/
            OrderInfo order = new OrderInfo();
            order.ProductMoney = productMoney;
            order.OrderNumber  = ShopCommon.CreateOrderNumber();
            string         payKey     = RequestHelper.GetForm <string>("Pay");
            PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey);
            if (payMoney == 0 || payPlugins.IsCod == (int)BoolType.True)
            {
                order.OrderStatus = (int)OrderStatus.WaitCheck;
            }
            else
            {
                order.OrderStatus = (int)OrderStatus.WaitPay;
            }
            order.Consignee      = address.Consignee;
            order.RegionId       = address.RegionId;
            order.Address        = address.Address;
            order.ZipCode        = address.ZipCode;
            order.Tel            = address.Tel;
            order.Mobile         = address.Mobile;
            order.InvoiceTitle   = RequestHelper.GetForm <string>("InvoiceTitle");
            order.InvoiceContent = RequestHelper.GetForm <string>("InvoiceContent");
            order.GiftMessige    = RequestHelper.GetForm <string>("GiftMessige");
            order.Email          = CookiesHelper.ReadCookieValue("UserEmail");
            order.ShippingId     = shipping.Id;
            order.ShippingDate   = RequestHelper.DateNow;
            order.ShippingMoney  = shippingMoney;
            order.CouponMoney    = couponMoney;
            order.Point          = costPoint;
            order.PointMoney     = pointMoney;
            order.FavorableMoney = favorableMoney + productfavorableMoney;
            order.Balance        = 0;
            order.PayKey         = pay.Key;
            order.PayName        = pay.Name;
            order.PayDate        = RequestHelper.DateNow;
            order.IsRefund       = (int)BoolType.False;
            order.AddDate        = RequestHelper.DateNow;
            order.IP             = ClientHelper.IP;
            order.UserId         = base.UserId;
            order.UserName       = base.UserName;
            order.UserMessage    = RequestHelper.GetForm <string>("userMessage");
            order.GiftId         = RequestHelper.GetForm <int>("GiftID");
            order.IsNoticed      = 0;
            int orderId = OrderBLL.Add(order);

            //添加订单产品
            foreach (var cart in cartList)
            {
                var orderDetail = new OrderDetailInfo();
                orderDetail.OrderId           = orderId;
                orderDetail.ProductId         = cart.ProductId;
                orderDetail.ProductName       = cart.ProductName;
                orderDetail.StandardValueList = cart.StandardValueList;
                orderDetail.ProductWeight     = cart.Product.Weight;
                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    orderDetail.ProductPrice = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                }
                else
                {
                    orderDetail.ProductPrice = ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID);
                }

                orderDetail.BidPrice = cart.Product.BidPrice;
                orderDetail.BuyCount = cart.BuyCount;

                OrderDetailBLL.Add(orderDetail);
            }
            #region 更新优惠券状态--已使用
            //使用优惠券
            if (couponMoney > 0 && userCouponStr != "0|0")
            {
                userCoupon.IsUse   = (int)BoolType.True;
                userCoupon.OrderId = orderId;
                UserCouponBLL.Update(userCoupon);
            }
            #endregion
            #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
            /*-----------更改产品库存订单数量---------------------------------------*/
            ProductBLL.ChangeOrderCountByOrder(orderId, ChangeAction.Plus);
            /*----------------------------------------------------------------------*/

            /*-----------删除购物车中已下单的商品-----------------------------------*/
            CartBLL.Delete(cartIds, base.UserId);
            CookiesHelper.DeleteCookie("CheckCart");
            /*----------------------------------------------------------------------*/

            ResponseHelper.Write("ok||/Finish.html?id=" + orderId);
            ResponseHelper.End();
        }
Пример #27
0
        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");
        }
Пример #28
0
        /// <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");
        }
Пример #29
0
 public static void Update(UserCouponInfo entity)
 {
     dal.Update(entity);
 }