/// <summary>
        /// 取消按钮点击方法
        /// </summary>
        protected void CancelButton_Click(object sender, EventArgs e)
        {
            OrderInfo order            = ButtoStart();
            int       startOrderStatus = order.OrderStatus;

            order.OrderStatus = (int)OrderStatus.NoEffect;
            #region 待付款状态,退还用户下单时抵现的积分
            if (startOrderStatus == (int)OrderStatus.WaitPay && order.Point > 0)
            {
                var accountRecord = new UserAccountRecordInfo
                {
                    RecordType = (int)AccountRecordType.Point,
                    Money      = 0,
                    Point      = order.Point,
                    Date       = DateTime.Now,
                    IP         = ClientHelper.IP,
                    Note       = "取消订单:" + order.OrderNumber + ",退回用户积分",
                    UserId     = order.UserId,
                    UserName   = order.UserName,
                };
                UserAccountRecordBLL.Add(accountRecord);
            }
            #endregion
            //更新商品库存数量
            ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Minus);
            ButtonEnd(order, Note.Text, OrderOperate.Cancle, startOrderStatus);
        }
Beispiel #2
0
 /// <summary>
 /// 待付款订单失效检查
 /// </summary>
 /// <param name="ids"></param>
 public static void CheckOrderPayTime(int[] ids)
 {
     dal.CheckOrderPayTime(ids);
     foreach (int orderId in ids)
     {
         OrderInfo order = Read(orderId);
         #region 待付款状态,退还用户下单时抵现的积分
         if (order.Point > 0)
         {
             var accountRecord = new UserAccountRecordInfo
             {
                 RecordType = (int)AccountRecordType.Point,
                 Money      = 0,
                 Point      = order.Point,
                 Date       = DateTime.Now,
                 IP         = ClientHelper.IP,
                 Note       = "取消订单:" + order.OrderNumber + ",退回用户积分",
                 UserId     = order.UserId,
                 UserName   = order.UserName,
             };
             UserAccountRecordBLL.Add(accountRecord);
         }
         #endregion
         //更新商品库存数量
         ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Minus);
     }
 }
        public int Add(UserAccountRecordInfo entity)
        {
            using (var conn = new SqlConnection(connectString))
            {
                string sql = @"INSERT INTO UsrAccountRecord( RecordType,Money,Point,Date,IP,Note,UserId,UserName) VALUES(@RecordType,@Money,@Point,@Date,@IP,@Note,@UserId,@UserName);
                            select SCOPE_IDENTITY()";

                return(conn.Query <int>(sql, entity).Single());
            }
        }
Beispiel #4
0
 public ActionResult UpdateUserInfo()
 {
     if (user.Id <= 0)
     {
         return(Json(new { ok = false, msg = "无效的请求" }));
     }
     else
     {
         string birthdayBeforeUpdate = user.Birthday;
         string realName             = RequestHelper.GetForm <string>("realname");
         string birthDay             = RequestHelper.GetForm <string>("birthday");
         string email = RequestHelper.GetForm <string>("email");
         if (string.IsNullOrEmpty(realName))
         {
             return(Json(new { ok = false, msg = "请填写真实姓名" }));
         }
         if (string.IsNullOrEmpty(birthDay))
         {
             return(Json(new { ok = false, msg = "请填写生日" }));
         }
         if (Convert.ToDateTime(birthDay) >= DateTime.Now)
         {
             return(Json(new { ok = false, msg = "请填写真实生日" }));
         }
         if (!string.IsNullOrEmpty(email) && !ShopCommon.CheckEmail(email))
         {
             return(Json(new { ok = false, msg = "邮箱格式错误" }));
         }
         Dictionary <string, object> dict = new Dictionary <string, object>();
         dict.Add("[RealName]", StringHelper.Substring(realName, 18, false));
         dict.Add("[Birthday]", StringHelper.Substring(birthDay, 30, false));
         dict.Add("[Email]", StringHelper.Substring(email, 30, false));
         UserBLL.UpdatePart("[usr]", dict, user.Id);
         //如果是首次填写生日信息则赠送积分20
         if (string.IsNullOrEmpty(birthdayBeforeUpdate))
         {
             UserAccountRecordInfo uar = new UserAccountRecordInfo
             {
                 RecordType = (int)AccountRecordType.Point,
                 Money      = 0,
                 Point      = 20,
                 Date       = DateTime.Now,
                 IP         = ClientHelper.IP,
                 Note       = "填写生日赠送积分",
                 UserId     = user.Id,
                 UserName   = user.UserName
             };
             if (UserAccountRecordBLL.Add(uar) > 0)
             {
                 user.PointLeft += 20;
             }
         }
         return(Json(new { ok = true }));
     }
 }
Beispiel #5
0
 public int AddUserAccountRecord(UserAccountRecordInfo userAccountRecord)
 {
     SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@money", SqlDbType.Decimal), new SqlParameter("@point", SqlDbType.Int), new SqlParameter("@date", SqlDbType.DateTime), new SqlParameter("@iP", SqlDbType.NVarChar), new SqlParameter("@note", SqlDbType.NVarChar), new SqlParameter("@userID", SqlDbType.Int), new SqlParameter("@userName", SqlDbType.NVarChar) };
     pt[0].Value = userAccountRecord.Money;
     pt[1].Value = userAccountRecord.Point;
     pt[2].Value = userAccountRecord.Date;
     pt[3].Value = userAccountRecord.IP;
     pt[4].Value = userAccountRecord.Note;
     pt[5].Value = userAccountRecord.UserID;
     pt[6].Value = userAccountRecord.UserName;
     return(Convert.ToInt32(ShopMssqlHelper.ExecuteScalar(ShopMssqlHelper.TablePrefix + "AddUserAccountRecord", pt)));
 }
        public static int AddUserAccountRecord(decimal money, int point, string note, int userID, string userName)
        {
            UserAccountRecordInfo userAccountRecord = new UserAccountRecordInfo();

            userAccountRecord.Money    = money;
            userAccountRecord.Point    = point;
            userAccountRecord.Date     = RequestHelper.DateNow;
            userAccountRecord.IP       = ClientHelper.IP;
            userAccountRecord.Note     = note;
            userAccountRecord.UserID   = userID;
            userAccountRecord.UserName = userName;
            userAccountRecord.ID       = AddUserAccountRecord(userAccountRecord);
            return(userAccountRecord.ID);
        }
Beispiel #7
0
        public ActionResult BindMobile()
        {
            bool   ok           = false;
            string msg          = string.Empty;
            int    pointLeft    = user.PointLeft;
            string mobileBefore = user.Mobile;

            try
            {
                string mobile = RequestHelper.GetForm <string>("mobile");
                if (!string.IsNullOrEmpty(mobile))
                {
                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    dict.Add("Mobile", mobile.Trim());
                    UserBLL.UpdatePart(UserInfo.TABLENAME, dict, user.Id);
                    //首次绑定手机号默认赠送20积分
                    if (string.IsNullOrEmpty(mobileBefore))
                    {
                        UserAccountRecordInfo uar = new UserAccountRecordInfo
                        {
                            RecordType = (int)AccountRecordType.Point,
                            Money      = 0,
                            Point      = 20,
                            Date       = DateTime.Now,
                            IP         = ClientHelper.IP,
                            Note       = "绑定手机号赠送积分",
                            UserId     = user.Id,
                            UserName   = user.UserName
                        };

                        if (UserAccountRecordBLL.Add(uar) > 0)
                        {
                            user.PointLeft += 20;
                        }
                    }
                    ok        = true;
                    pointLeft = user.PointLeft;
                }
                else
                {
                    msg = "mobile empty";
                }
            }
            catch (Exception ex)
            {
                ok  = false;
                msg = ex.Message;
            }
            return(Json(new { ok = ok, msg = msg, pointleft = pointLeft }));
        }
Beispiel #8
0
 public void PrepareUserAccountRecordModel(SqlDataReader dr, List <UserAccountRecordInfo> userAccountRecordList)
 {
     while (dr.Read())
     {
         UserAccountRecordInfo item = new UserAccountRecordInfo();
         item.ID       = dr.GetInt32(0);
         item.Money    = dr.GetDecimal(1);
         item.Point    = dr.GetInt32(2);
         item.Date     = dr.GetDateTime(3);
         item.IP       = dr[4].ToString();
         item.Note     = dr[5].ToString();
         item.UserID   = dr.GetInt32(6);
         item.UserName = dr[7].ToString();
         userAccountRecordList.Add(item);
     }
 }
        /// <summary>
        /// 提交按钮点击方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            UserAccountRecordInfo uarInfo = new UserAccountRecordInfo();

            uarInfo.UserId = RequestHelper.GetQueryString <int>("UserID");
            //uarInfo.Money = Convert.ToDecimal(Money.Text);
            uarInfo.Point      = Convert.ToInt32(Point.Text);
            uarInfo.Note       = Note.Text;
            uarInfo.RecordType = (int)AccountRecordType.Point;//积分类型
            uarInfo.IP         = ClientHelper.IP;
            string alertMessage = ShopLanguage.ReadLanguage("AddOK");

            CheckAdminPower("AddUserAccountRecord", PowerCheckType.Single);
            int id = UserAccountRecordBLL.Add(uarInfo);

            AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("UserAccountRecord"), id);
            ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl);
        }
        /// <summary>
        /// 退款按钮点击方法【不支持】
        /// </summary>
        protected void RefundButton_Click(object sender, EventArgs e)
        {
            OrderInfo order = ButtoStart();
            //余额处理
            decimal money = order.Balance;
            int     isCod = PayPlugins.ReadPayPlugins(order.PayKey).IsCod;

            if (order.OrderStatus == (int)OrderStatus.HasReturn && isCod == (int)BoolType.False)
            {
                money += OrderBLL.ReadNoPayMoney(order);
            }
            else if (order.OrderStatus == (int)OrderStatus.NoEffect && OrderActionBLL.ReadLast(order.Id, order.OrderStatus).StartOrderStatus == (int)OrderStatus.WaitCheck && isCod == (int)BoolType.False)
            {
                money += OrderBLL.ReadNoPayMoney(order);
            }
            if (money > 0)
            {
                var accountRecord = new UserAccountRecordInfo
                {
                    RecordType = (int)AccountRecordType.Money,
                    Money      = money,
                    Point      = 0,
                    Date       = DateTime.Now,
                    IP         = ClientHelper.IP,
                    Note       = "退还订单:" + order.OrderNumber + "的金额",
                    UserId     = order.UserId,
                    UserName   = order.UserName
                };
                UserAccountRecordBLL.Add(accountRecord);
            }
            //更新订单
            int startOrderStatus = order.OrderStatus;

            order.OrderStatus = (int)order.OrderStatus;
            order.Balance     = 0;
            order.CouponMoney = 0;
            order.IsRefund    = (int)BoolType.True;
            ButtonEnd(order, Note.Text, OrderOperate.Refund, startOrderStatus);
        }
Beispiel #11
0
        public UserAccountRecordInfo ReadUserAccountRecord(int id, int userID)
        {
            SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@id", SqlDbType.NVarChar), new SqlParameter("@userID", SqlDbType.Int) };
            pt[0].Value = id;
            pt[1].Value = userID;
            UserAccountRecordInfo info = new UserAccountRecordInfo();

            using (SqlDataReader reader = ShopMssqlHelper.ExecuteReader(ShopMssqlHelper.TablePrefix + "ReadUserAccountRecord", pt))
            {
                if (reader.Read())
                {
                    info.ID       = reader.GetInt32(0);
                    info.Money    = reader.GetDecimal(1);
                    info.Point    = reader.GetInt32(2);
                    info.Date     = reader.GetDateTime(3);
                    info.IP       = reader[4].ToString();
                    info.Note     = reader[5].ToString();
                    info.UserID   = reader.GetInt32(6);
                    info.UserName = reader[7].ToString();
                }
            }
            return(info);
        }
Beispiel #12
0
        private void UserOrderOperate()
        {
            string result = string.Empty;

            if (base.UserId <= 0)
            {
                ResponseHelper.Write("登录状态已过期,请重新登录");
                ResponseHelper.End();
            }
            int       orderID      = RequestHelper.GetQueryString <int>("OrderID");
            int       orderOperate = RequestHelper.GetQueryString <int>("operate");
            OrderInfo order        = OrderBLL.Read(orderID, base.UserId);

            if (order.Id > 0 && ((orderOperate == (int)OrderOperate.Cancle && (order.OrderStatus == (int)OrderStatus.WaitCheck || order.OrderStatus == (int)OrderStatus.WaitPay)) ||
                                 (orderOperate == (int)OrderOperate.Received && order.OrderStatus == (int)OrderStatus.HasShipping)))
            {
                if (orderOperate == (int)OrderOperate.Cancle)
                {
                    int startOrderStatus = order.OrderStatus;
                    order.OrderStatus = (int)OrderStatus.NoEffect;
                    //库存变化
                    ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Minus);
                    OrderBLL.UserUpdateOrderAddAction(order, "用户取消订单", orderOperate, startOrderStatus);
                    //返还积分
                    if (order.Point > 0)
                    {
                        var accountRecord = new UserAccountRecordInfo
                        {
                            RecordType = (int)AccountRecordType.Point,
                            Money      = 0,
                            Point      = order.Point,
                            Date       = DateTime.Now,
                            IP         = ClientHelper.IP,
                            Note       = "取消订单:" + order.OrderNumber + ",返还积分",
                            UserId     = base.UserId,
                            UserName   = base.UserName
                        };
                        UserAccountRecordBLL.Add(accountRecord);
                    }
                }
                else if (orderOperate == (int)OrderOperate.Received)
                {
                    //赠送积分
                    int sendPoint = OrderBLL.ReadOrderSendPoint(order.Id);
                    if (sendPoint > 0)
                    {
                        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     = base.UserId,
                            UserName   = base.UserName
                        };
                        UserAccountRecordBLL.Add(accountRecord);
                    }
                    int startOrderStatus = order.OrderStatus;
                    order.OrderStatus = (int)OrderStatus.ReceiveShipping;
                    OrderBLL.UserUpdateOrderAddAction(order, "用户确认收货", orderOperate, startOrderStatus);
                }
            }
            else
            {
                result = "订单不存在或状态错误";
            }
            ResponseHelper.Write(result);
            ResponseHelper.End();
        }
Beispiel #13
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();
        }
Beispiel #14
0
 public static int Add(UserAccountRecordInfo entity)
 {
     return(dal.Add(entity));
 }
        /// <summary>
        /// 撤销按钮点击方法
        /// </summary>
        protected void BackButton_Click(object sender, EventArgs e)
        {
            OrderInfo order            = ButtoStart();
            int       startOrderStatus = order.OrderStatus;

            order.OrderStatus = OrderActionBLL.ReadLast(order.Id, order.OrderStatus).StartOrderStatus;
            //减去用户积分,积分为负数
            int sendPoint = 0;

            if (startOrderStatus == (int)OrderStatus.ReceiveShipping && order.IsActivity == (int)BoolType.False)
            {
                //sendPoint = -OrderBLL.ReadOrderSendPoint(order.Id);
                //根据订单付款金额全额返还积分
                sendPoint = -(int)Math.Floor(OrderBLL.ReadNoPayMoney(order));
            }
            if (startOrderStatus == (int)OrderStatus.HasShipping && order.OrderStatus == (int)OrderStatus.ReceiveShipping && order.IsActivity == (int)BoolType.False)//相当于收货确认
            {
                //sendPoint = OrderBLL.ReadOrderSendPoint(order.Id);
                //根据订单付款金额全额返还积分
                sendPoint = -(int)Math.Floor(OrderBLL.ReadNoPayMoney(order));
            }
            if (sendPoint != 0)
            {
                var accountRecord = new UserAccountRecordInfo
                {
                    RecordType = (int)AccountRecordType.Point,
                    Money      = 0,
                    Point      = sendPoint,
                    Date       = DateTime.Now,
                    IP         = ClientHelper.IP,
                    Note       = ShopLanguage.ReadLanguage("OrderBack").Replace("$OrderNumber", order.OrderNumber),
                    UserId     = order.UserId,
                    UserName   = order.UserName
                };
                UserAccountRecordBLL.Add(accountRecord);
            }

            //更新商品库存数量
            switch (startOrderStatus)
            {
            case (int)OrderStatus.WaitPay:
            case (int)OrderStatus.WaitCheck:
                if (order.OrderStatus == (int)OrderStatus.NoEffect)    //相当于取消操作
                {
                    ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Minus);
                }
                break;

            case (int)OrderStatus.NoEffect:
                ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus);
                break;

            case (int)OrderStatus.HasReturn:
                ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus);
                ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Plus);
                break;

            case (int)OrderStatus.Shipping:
                if (order.OrderStatus == (int)OrderStatus.HasShipping)
                {
                    ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Plus);
                }
                break;

            case (int)OrderStatus.HasShipping:
                if (order.OrderStatus == (int)OrderStatus.Shipping)
                {
                    ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Minus);
                }
                if (order.OrderStatus == (int)OrderStatus.HasReturn)    //相当于退货确认操作
                {
                    ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Minus);
                    ProductBLL.ChangeSendCountByOrder(order.Id, ChangeAction.Minus);
                }
                break;

            default:
                break;
            }
            //更新订单
            ButtonEnd(order, Note.Text, OrderOperate.Back, startOrderStatus);
        }
        /// <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);
        }
Beispiel #17
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");
        }
Beispiel #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //检查待付款订单是否超时失效,超时则更新为失效状态
                OrderBLL.CheckOrderPayTime();
                //订单自动收货
                OrderBLL.CheckOrderRecieveTimeProg();

                CheckAdminPower("ReadOrder", PowerCheckType.Single);

                OrderNumber.Text  = RequestHelper.GetQueryString <string>("OrderNumber");
                OrderStatus.Text  = RequestHelper.GetQueryString <string>("OrderStatus");
                Consignee.Text    = RequestHelper.GetQueryString <string>("Consignee");
                StartAddDate.Text = RequestHelper.GetQueryString <string>("StartAddDate");
                EndAddDate.Text   = RequestHelper.GetQueryString <string>("EndAddDate");
                SelfPick.Text     = RequestHelper.GetQueryString <string>("SelfPick");
                OrderSearchInfo orderSearch = new OrderSearchInfo();
                orderSearch.OrderNumber = RequestHelper.GetQueryString <string>("OrderNumber");
                intOrderStatus          = RequestHelper.GetQueryString <int>("OrderStatus");

                //如果查找已删除订单
                if (intOrderStatus == (int)Entity.OrderStatus.HasDelete)
                {
                    orderSearch.IsDelete = (int)BoolType.True;//已删除
                }
                else
                {
                    orderSearch.OrderStatus = intOrderStatus;
                    orderSearch.IsDelete    = (int)BoolType.False;//未删除
                }
                orderSearch.Consignee    = RequestHelper.GetQueryString <string>("Consignee");
                orderSearch.StartAddDate = RequestHelper.GetQueryString <DateTime>("StartAddDate");
                orderSearch.EndAddDate   = RequestHelper.GetQueryString <DateTime>("EndAddDate");
                orderSearch.SelfPick     = RequestHelper.GetQueryString <int>("SelfPick");
                PageSize           = Session["AdminPageSize"] == null ? 20 : Convert.ToInt32(Session["AdminPageSize"]);
                AdminPageSize.Text = Session["AdminPageSize"] == null ? "20" : Session["AdminPageSize"].ToString();
                var orderList = OrderBLL.SearchList(CurrentPage, PageSize, orderSearch, ref Count);

                //取得订单最后一次操作的时间
                var orderActinList = OrderActionBLL.ReadListLastDate(orderList.Select(k => k.Id).ToArray());
                foreach (var order in orderList)
                {
                    var orderAction = orderActinList.FirstOrDefault(k => k.OrderId == order.Id) ?? new OrderActionInfo();
                    //此处使用InvoiceTitle字段来临时存储
                    order.InvoiceTitle = orderAction.OrderId > 0 ? orderAction.Date.ToString() : "";
                }
                BindControl(orderList, RecordList, MyPager);
                #region  除订单
                if (RequestHelper.GetQueryString <string>("Action") == "delete")
                {
                    CheckAdminPower("DeleteOrder", PowerCheckType.Single);
                    int orderId = RequestHelper.GetQueryString <int>("orderId");
                    if (orderId > 0)
                    {
                        OrderInfo tmpOrder = OrderBLL.Read(orderId);
                        if (tmpOrder.OrderStatus == (int)JWShop.Entity.OrderStatus.WaitPay)
                        {//待付款直接删除退还积分库存
                            #region 退还积分
                            if (tmpOrder.Point > 0)
                            {
                                var accountRecord = new UserAccountRecordInfo
                                {
                                    RecordType = (int)AccountRecordType.Point,
                                    Money      = 0,
                                    Point      = tmpOrder.Point,
                                    Date       = DateTime.Now,
                                    IP         = ClientHelper.IP,
                                    Note       = "取消订单:" + tmpOrder.OrderNumber + ",退回用户积分",
                                    UserId     = tmpOrder.UserId,
                                    UserName   = tmpOrder.UserName,
                                };
                                UserAccountRecordBLL.Add(accountRecord);
                            }
                            #endregion
                            //更新商品库存数量
                            ProductBLL.ChangeOrderCountByOrder(tmpOrder.Id, ChangeAction.Minus);
                            OrderBLL.Delete(orderId);
                            AdminLogBLL.Add(ShopLanguage.ReadLanguage("DeleteRecordCompletely"), ShopLanguage.ReadLanguage("Order"), orderId);
                        }
                        else
                        { //已付款逻辑删除可恢复
                            if (tmpOrder.IsDelete == (int)BoolType.False)
                            {
                                tmpOrder.IsDelete = (int)BoolType.True;
                                OrderBLL.Update(tmpOrder);
                                AdminLogBLL.Add(ShopLanguage.ReadLanguage("DeleteRecord"), ShopLanguage.ReadLanguage("Order"), orderId);
                            }
                        }
                    }

                    ScriptHelper.Alert(ShopLanguage.ReadLanguage("DeleteOK"), Request.UrlReferrer.ToString());
                }
                #endregion
            }
        }
Beispiel #19
0
        public override void ProcessNotify()
        {
            WxPayData notifyData = GetNotifyData();


            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml());
                //page.Response.Write(res.ToXml());
                //page.Response.End();
            }
            else
            {
                string transaction_id = notifyData.GetValue("transaction_id").ToString();

                //查询订单,判断订单真实性
                if (!QueryOrder(transaction_id))
                ////沙箱测试只能用out_trade_no
                //if (notifyData.IsSet("out_trade_no") && !QueryOrderByout_trade_no(notifyData.GetValue("out_trade_no").ToString()))
                {
                    //若订单查询失败,则立即返回结果给微信支付后台
                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "FAIL");
                    res.SetValue("return_msg", "订单查询失败");
                    Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml());
                    //page.Response.Write(res.ToXml());
                    //page.Response.End();
                }
                //查询订单成功
                else
                {
                    Log.Debug(this.GetType().ToString(), "订单查询成功 ");
                    /************在这里加入商户自己的逻辑***********************************************************/

                    //attach:以逗号分开的订单Id字符串,与支付时提交的数据一致
                    if (notifyData.IsSet("attach"))
                    {
                        string attach = notifyData.GetValue("attach").ToString();

                        string[] orderIds = attach.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string orderId in orderIds)
                        {
                            var order = OrderBLL.Read(int.Parse(orderId));
                            if (order.Id > 0)
                            {
                                #region 正常流程 待付款--》待审核
                                if (order.OrderStatus == (int)OrderStatus.WaitPay)
                                {
                                    order.PayKey  = "WxPay";
                                    order.PayName = "微信支付";

                                    order.WxPayTradeNo = transaction_id;
                                    //沙箱测试用out_trade_no
                                    //order.WxPayTradeNo = notifyData.GetValue("out_trade_no").ToString();

                                    order.OrderStatus = (int)OrderStatus.WaitCheck;
                                    order.PayDate     = RequestHelper.DateNow;
                                    OrderBLL.Update(order);
                                    #region 拼团订单付款:团长付款--开团+增加参团记录;成员付款--增加参团记录
                                    if (order.IsActivity == (int)OrderKind.GroupBuy)
                                    {
                                        var orderDetail = OrderDetailBLL.ReadList(order.Id).FirstOrDefault() ?? new OrderDetailInfo();
                                        if (orderDetail.Id > 0)
                                        {
                                            var product = ProductBLL.Read(orderDetail.ProductId);
                                            //团长付款
                                            if (order.FavorableActivityId <= 0)
                                            {
                                                //开团
                                                int groupId = GroupBuyBLL.Add(new GroupBuyInfo
                                                {
                                                    Leader    = order.UserId,
                                                    ProductId = product.Id,
                                                    StartTime = DateTime.Now,
                                                    EndTime   = DateTime.Now.AddDays(ShopConfig.ReadConfigInfo().GroupBuyDays),
                                                    Quantity  = product.GroupQuantity,
                                                    //团购订单支付成功之后计数加1
                                                    SignCount = 1
                                                });
                                                //订单绑定团购Id
                                                Dictionary <string, object> dict = new Dictionary <string, object>();
                                                dict.Add("[FavorableActivityId]", groupId);
                                                OrderBLL.UpdatePart("[Order]", dict, order.Id);
                                                //增加参团记录
                                                GroupSignBLL.Add(new GroupSignInfo
                                                {
                                                    GroupId  = groupId,
                                                    UserId   = order.UserId,
                                                    OrderId  = order.Id,
                                                    SignTime = DateTime.Now
                                                });
                                            }
                                            else//参团者付款--放到参团者checkout
                                            {
                                                ////增加参团记录
                                                //GroupSignBLL.Add(new GroupSignInfo
                                                //{
                                                //    GroupId = order.FavorableActivityId,
                                                //    UserId = order.UserId,
                                                //    OrderId = order.Id,
                                                //    SignTime = DateTime.Now
                                                //});
                                                ////开团表signcount加1
                                                //GroupBuyBLL.PlusSignCount(order.FavorableActivityId);
                                            }
                                        }
                                    }
                                    #endregion
                                    #region 自提订单 生成提货码
                                    //避免重复数据,一个订单对应一个提货码,提货码没有有效期,使用过后失效
                                    if (order.SelfPick == 1 && PickUpCodeBLL.ReadByOrderId(order.Id).Id <= 0)
                                    {
                                        PickUpCodeInfo pkCode = new PickUpCodeInfo();
                                        pkCode.OrderId  = order.Id;
                                        pkCode.Status   = 0;
                                        pkCode.PickCode = PickUpCodeBLL.CreatePickUpCode();
                                        int pickCodeId = PickUpCodeBLL.Add(pkCode);
                                    }
                                    #endregion
                                    #region  价订单
                                    if (order.IsActivity == (int)OrderKind.Bargain)
                                    {
                                        BargainOrderBLL.HandleBargainOrderPay(order.FavorableActivityId);
                                    }
                                    #endregion
                                    //发送订单支付成功通知
                                    SendPayOrderMsg(order);
                                    //增加操作记录
                                    OrderActionInfo orderAction = new OrderActionInfo();
                                    orderAction.OrderId          = order.Id;
                                    orderAction.OrderOperate     = (int)OrderOperate.Pay;
                                    orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                                    orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                                    orderAction.Note             = "客户微信在线支付";
                                    orderAction.IP        = ClientHelper.IP;
                                    orderAction.Date      = RequestHelper.DateNow;
                                    orderAction.AdminID   = 0;
                                    orderAction.AdminName = string.Empty;
                                    OrderActionBLL.Add(orderAction);
                                }
                                #endregion
                                #region 非正常流程 待付款超时已失效(未退款)--》待审核
                                if (order.OrderStatus == (int)OrderStatus.NoEffect && order.IsRefund == 0)
                                {
                                    order.PayKey       = "WxPay";
                                    order.PayName      = "微信支付";
                                    order.WxPayTradeNo = transaction_id;
                                    order.OrderStatus  = (int)OrderStatus.WaitCheck;
                                    order.PayDate      = RequestHelper.DateNow;
                                    OrderBLL.Update(order);
                                    #region 拼团订单付款:团长付款--开团+增加参团记录;成员付款--增加参团记录
                                    if (order.IsActivity == (int)OrderKind.GroupBuy)
                                    {
                                        var orderDetail = OrderDetailBLL.ReadList(order.Id).FirstOrDefault() ?? new OrderDetailInfo();
                                        if (orderDetail.Id > 0)
                                        {
                                            var product = ProductBLL.Read(orderDetail.ProductId);
                                            //团长付款
                                            if (order.FavorableActivityId <= 0)
                                            {
                                                //开团
                                                int groupId = GroupBuyBLL.Add(new GroupBuyInfo
                                                {
                                                    Leader    = order.UserId,
                                                    ProductId = product.Id,
                                                    StartTime = DateTime.Now,
                                                    EndTime   = DateTime.Now.AddDays(ShopConfig.ReadConfigInfo().GroupBuyDays),
                                                    Quantity  = product.GroupQuantity,
                                                    //团购订单支付成功之后计数加1
                                                    SignCount = 1
                                                });
                                                //订单绑定团购Id
                                                Dictionary <string, object> dict = new Dictionary <string, object>();
                                                dict.Add("[FavorableActivityId]", groupId);
                                                OrderBLL.UpdatePart("[Order]", dict, order.Id);
                                                //增加参团记录
                                                GroupSignBLL.Add(new GroupSignInfo
                                                {
                                                    GroupId  = groupId,
                                                    UserId   = order.UserId,
                                                    OrderId  = order.Id,
                                                    SignTime = DateTime.Now
                                                });
                                            }
                                            else//参团者付款--放到参团者checkout
                                            {
                                                ////增加参团记录
                                                //GroupSignBLL.Add(new GroupSignInfo
                                                //{
                                                //    GroupId = order.FavorableActivityId,
                                                //    UserId = order.UserId,
                                                //    OrderId = order.Id,
                                                //    SignTime = DateTime.Now
                                                //});
                                                ////开团表signcount加1
                                                //GroupBuyBLL.PlusSignCount(order.FavorableActivityId);
                                            }
                                        }
                                    }
                                    #endregion
                                    #region 自提订单 生成提货码
                                    //避免重复数据,一个订单对应一个提货码,提货码没有有效期,使用过后失效
                                    if (order.SelfPick == 1 && PickUpCodeBLL.ReadByOrderId(order.Id).Id <= 0)
                                    {
                                        PickUpCodeInfo pkCode = new PickUpCodeInfo();
                                        pkCode.OrderId  = order.Id;
                                        pkCode.Status   = 0;
                                        pkCode.PickCode = PickUpCodeBLL.CreatePickUpCode();
                                        int pickCodeId = PickUpCodeBLL.Add(pkCode);
                                    }
                                    #endregion
                                    #region  价订单
                                    if (order.IsActivity == (int)OrderKind.Bargain)
                                    {
                                        BargainOrderBLL.HandleBargainOrderPay(order.FavorableActivityId);
                                    }
                                    #endregion
                                    #region 扣除支付积分
                                    if (order.Point > 0)
                                    {
                                        //减少积分
                                        UserAccountRecordInfo uarInfo = new UserAccountRecordInfo();
                                        uarInfo.RecordType = (int)AccountRecordType.Point;
                                        uarInfo.UserId     = order.UserId;
                                        uarInfo.UserName   = order.UserName;
                                        uarInfo.Note       = "支付订单:" + order.OrderNumber;
                                        uarInfo.Point      = -order.Point;
                                        uarInfo.Money      = 0;
                                        uarInfo.Date       = DateTime.Now;
                                        uarInfo.IP         = ClientHelper.IP;
                                        UserAccountRecordBLL.Add(uarInfo);
                                    }
                                    #endregion
                                    #region 减少商品库存
                                    ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus);
                                    #endregion
                                    //发送订单支付成功通知
                                    SendPayOrderMsg(order);
                                    //增加操作记录
                                    OrderActionInfo orderAction = new OrderActionInfo();
                                    orderAction.OrderId          = order.Id;
                                    orderAction.OrderOperate     = (int)OrderOperate.Pay;
                                    orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                                    orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                                    orderAction.Note             = "客户微信在线支付";
                                    orderAction.IP        = ClientHelper.IP;
                                    orderAction.Date      = RequestHelper.DateNow;
                                    orderAction.AdminID   = 0;
                                    orderAction.AdminName = string.Empty;
                                    OrderActionBLL.Add(orderAction);
                                }
                                #endregion
                                //记录微信支付交易单号
                                if (order.OrderStatus == (int)OrderStatus.WaitCheck && string.IsNullOrEmpty(order.WxPayTradeNo))
                                {
                                    order.WxPayTradeNo = transaction_id;
                                    OrderBLL.Update(order);
                                }
                                notifyResult = true;
                            }
                        }
                    }

                    /************在这里加入商户自己的逻辑***********************************************************/

                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "SUCCESS");
                    res.SetValue("return_msg", "OK");
                    Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml());
                    //page.Response.Write(res.ToXml());
                    //page.Response.End();
                }
            }
        }
Beispiel #20
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();
        }
Beispiel #21
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|购买商品发生了变化,请重新提交|" + isMobile + "/cart.html");
                ResponseHelper.End();
            }

            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品|" + isMobile + "/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|请选择需要购买的商品|" + isMobile + "/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"))
            };

            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;
            }
            /*----------------------------------------------------------------------*/

            /*-----------商品清单、商品总价、邮费价格、库存检查---------------------*/
            decimal productMoney = 0;
            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);
                    cart.Price            = standardRecord.SalePrice;
                    cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                }
                else
                {
                    cart.Price            = cart.Product.SalePrice;
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount;
                }

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

                productMoney += cart.BuyCount * cart.Price;
            }

            decimal shippingMoney = 0;
            //首先根据ShopId分组,根据供应商的不同来分别计算运费
            //然后将分拆后的供应商商品,按单个商品独立计算运费(相同商品购买多个则叠加计算)
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shipping.Id, address.RegionId);

            var shopIds = cartList.GroupBy(k => k.Product.ShopId).Select(k => k.Key).ToList();

            foreach (var shopId in shopIds)
            {
                var shopCartList = cartList.Where(k => k.Product.ShopId == shopId).ToList();
                foreach (var shopCartSplit in shopCartList)
                {
                    shippingMoney += ShippingRegionBLL.ReadShippingMoney(shipping, shippingRegion, shopCartSplit);
                }
            }
            /*----------------------------------------------------------------------*/

            int     point      = 0;
            decimal pointMoney = 0;

            /*-----------计算积分金额(不可使用积分)-----------------------------------
             * decimal totalRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointTotalRate;
             * decimal pointRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointMoneyRate;
             * int point = RequestHelper.GetForm<int>("point");
             * decimal pointMoney = 0;
             * if (totalRate > 0 && pointRate > 0 && point > 0)
             * {
             *  var member = WebService.Member.GetMember();
             *  decimal leftPoint = member.Point;
             *  if (point > leftPoint)
             *  {
             *      ResponseHelper.Write("error|您的积分不足|");
             *      ResponseHelper.End();
             *  }
             *  else
             *  {
             *      pointMoney = Math.Round(point / pointRate, 2);
             *
             *      if (pointMoney > productMoney * totalRate)
             *      {
             *          ResponseHelper.Write("error|" + "您最多可以使用 " + (productMoney * totalRate * pointRate) + " 积分|");
             *          ResponseHelper.End();
             *      }
             *  }
             * }
             * ------------------------------------------------------------------------*/

            /*-----------应付总价---------------------------------------------------*/
            //decimal payMoney = productMoney + shippingMoney - pointMoney;
            decimal payMoney = productMoney + shippingMoney;
            /*----------------------------------------------------------------------*/

            var user = UserBLL.Read(base.UserId);
            /*-----------计算图楼卡余额---------------------------------------------*/
            decimal balance = RequestHelper.GetForm <decimal>("money");

            if (balance > 0)
            {
                bool isSuccess; string msg;
                isSuccess = true;
                msg       = "";
                //var account = WebService.Account.GetAccount(user.CardNo, user.CardPwd, out isSuccess, out msg);
                if (!isSuccess)
                {
                    ResponseHelper.Write("error|" + msg + "|");
                    ResponseHelper.End();
                }

                if (balance > 0 /*(account.Zacc + account.Sacc)*/)
                {
                    ResponseHelper.Write("error|您的图楼卡余额不足|");
                    ResponseHelper.End();
                }
                else
                {
                    if (balance > payMoney)
                    {
                        ResponseHelper.Write("error|" + "您只需使用 " + payMoney + " 元即可支付订单|");
                        ResponseHelper.End();
                    }
                }
            }
            payMoney -= balance;
            /*----------------------------------------------------------------------*/

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

            /*-----------组装基础订单模型,循环生成订单-----------------------------*/
            OrderInfo order = new OrderInfo();

            order.ProductMoney  = productMoney;
            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.Email         = CookiesHelper.ReadCookieValue("UserEmail");
            order.ShippingId    = shipping.Id;
            order.ShippingDate  = RequestHelper.DateNow;
            order.ShippingMoney = shippingMoney;
            order.Point         = point;
            order.PointMoney    = pointMoney;
            order.Balance       = balance;
            order.PayKey        = pay.Key;
            order.PayName       = pay.Name;
            order.PayDate       = RequestHelper.DateNow;
            order.IsRefund      = (int)BoolType.False;
            order.UserMessage   = StringHelper.AddSafe(RequestHelper.GetForm <string>("msg"));
            order.AddDate       = RequestHelper.DateNow;
            order.IP            = ClientHelper.IP;
            order.UserId        = base.UserId;
            order.UserName      = base.UserName;

            //循环生成订单
            var orderIds = SplitShopProduct(cartList, order);
            /*----------------------------------------------------------------------*/

            var orders = OrderBLL.ReadList(orderIds.ToArray(), base.UserId);

            /*-----------如果使用了图楼卡支付,需同步到会员管理系统中---------------*/
            /*第二步,在订单付款操作(用户端)中,同步图楼卡余额*/
            if (balance > 0)
            {
                List <string[]> paras = new List <string[]>();
                foreach (var oo in orders)
                {
                    if (oo.Balance > 0 && oo.OrderStatus == (int)OrderStatus.WaitCheck)
                    {
                        string[] para = new string[2];
                        para[0] = oo.OrderNumber;
                        para[1] = oo.Balance.ToString();
                        paras.Add(para);
                    }
                }

                //如果有全额使用了图楼卡余额支付的订单,需同步到会员管理系统中
                if (paras.Count > 0)
                {
                    bool isSuccess; string msg;
                    isSuccess = true;
                    msg       = "";
                    //WebService.Account.Purchase(user.CardNo, user.CardPwd, paras, out isSuccess, out msg);

                    //同步失败,删除订单及相关信息
                    if (!isSuccess)
                    {
                        //删除订单、订单详细、订单状态相关数据
                        OrderBLL.Delete(orderIds.ToArray(), base.UserId);

                        //更改产品库存订单数量
                        foreach (var orderId in orderIds)
                        {
                            ProductBLL.ChangeOrderCountByOrder(orderId, ChangeAction.Minus);
                        }
                        ResponseHelper.Write("error|" + msg + "|");
                        ResponseHelper.End();
                    }
                    else
                    {
                        //记录用户余额消费记录
                        foreach (var par in paras)
                        {
                            var accountRecord = new UserAccountRecordInfo
                            {
                                RecordType = (int)AccountRecordType.Money,
                                Money      = -decimal.Parse(par[1]),
                                Point      = 0,
                                Date       = DateTime.Now,
                                IP         = ClientHelper.IP,
                                Note       = "支付订单:" + par[0],
                                UserId     = base.UserId,
                                UserName   = base.UserName
                            };
                            UserAccountRecordBLL.Add(accountRecord);
                        }
                    }
                }
            }
            /*----------------------------------------------------------------------*/

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

            /*如果所有订单均由图楼卡支付完成,则跳转到会员中心,否则跳转到支付提示页面*/
            if (orders.Count(k => k.OrderStatus == (int)OrderStatus.WaitPay) > 0)
            {
                ResponseHelper.Write("ok||/finish.html?id=" + string.Join(",", orders.Select(k => k.Id).ToArray()));
            }
            else
            {
                ResponseHelper.Write("ok||/user/index.html");
            }
            ResponseHelper.End();
            /*----------------------------------------------------------------------*/
        }
 private static int AddUserAccountRecord(UserAccountRecordInfo userAccountRecord)
 {
     userAccountRecord.ID = dal.AddUserAccountRecord(userAccountRecord);
     return(userAccountRecord.ID);
 }
Beispiel #23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string out_trade_no = RequestHelper.GetQueryString <string>("order_id");

            string[] orderIds = out_trade_no.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string orderId in orderIds)
            {
                var order = OrderBLL.Read(int.Parse(orderId));
                if (order.Id > 0)
                {
                    #region 正常流程 待付款--》待审核
                    if (order.OrderStatus == (int)OrderStatus.WaitPay)
                    {
                        order.PayKey      = "WxPay";
                        order.PayName     = "微信支付";
                        order.OrderStatus = (int)OrderStatus.WaitCheck;
                        order.PayDate     = RequestHelper.DateNow;
                        OrderBLL.Update(order);

                        //增加操作记录
                        OrderActionInfo orderAction = new OrderActionInfo();
                        orderAction.OrderId          = order.Id;
                        orderAction.OrderOperate     = (int)OrderOperate.Pay;
                        orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                        orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                        orderAction.Note             = "客户微信在线支付";
                        orderAction.IP        = ClientHelper.IP;
                        orderAction.Date      = RequestHelper.DateNow;
                        orderAction.AdminID   = 0;
                        orderAction.AdminName = string.Empty;
                        OrderActionBLL.Add(orderAction);
                    }
                    #endregion
                    #region 非正常流程 待付款超时已失效--》待审核
                    if (order.OrderStatus == (int)OrderStatus.NoEffect)
                    {
                        order.PayKey      = "WxPay";
                        order.PayName     = "微信支付";
                        order.OrderStatus = (int)OrderStatus.WaitCheck;
                        order.PayDate     = RequestHelper.DateNow;
                        OrderBLL.Update(order);
                        #region 扣除支付积分
                        if (order.Point > 0)
                        {
                            //减少积分
                            UserAccountRecordInfo uarInfo = new UserAccountRecordInfo();
                            uarInfo.RecordType = (int)AccountRecordType.Point;
                            uarInfo.UserId     = order.UserId;
                            uarInfo.UserName   = order.UserName;
                            uarInfo.Note       = "支付订单:" + order.OrderNumber;
                            uarInfo.Point      = -order.Point;
                            uarInfo.Money      = 0;
                            uarInfo.Date       = DateTime.Now;
                            uarInfo.IP         = ClientHelper.IP;
                            UserAccountRecordBLL.Add(uarInfo);
                        }
                        #endregion
                        #region 减少商品库存
                        ProductBLL.ChangeOrderCountByOrder(order.Id, ChangeAction.Plus);
                        #endregion

                        //增加操作记录
                        OrderActionInfo orderAction = new OrderActionInfo();
                        orderAction.OrderId          = order.Id;
                        orderAction.OrderOperate     = (int)OrderOperate.Pay;
                        orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                        orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                        orderAction.Note             = "客户微信在线支付";
                        orderAction.IP        = ClientHelper.IP;
                        orderAction.Date      = RequestHelper.DateNow;
                        orderAction.AdminID   = 0;
                        orderAction.AdminName = string.Empty;
                        OrderActionBLL.Add(orderAction);
                    }
                    #endregion
                }
            }
        }
Beispiel #24
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");
        }
Beispiel #25
0
        /// <summary>
        /// 用户操作订单
        /// </summary>
        private void UserOrderOperate()
        {
            string result = string.Empty;

            if (base.UserId <= 0)
            {
                ResponseHelper.Write("登录状态已过期,请重新登录");
                ResponseHelper.End();
            }
            int       orderID      = RequestHelper.GetQueryString <int>("OrderID");
            int       orderOperate = RequestHelper.GetQueryString <int>("operate");
            OrderInfo order        = OrderBLL.Read(orderID, base.UserId);
            //根据订单应支付金额计算赠送的积分额
            int orderPoint = (int)Math.Floor(OrderBLL.ReadNoPayMoney(order));

            if (order.Id > 0 && ((orderOperate == (int)OrderOperate.Cancle && (order.OrderStatus == (int)OrderStatus.WaitCheck || order.OrderStatus == (int)OrderStatus.WaitPay)) ||
                                 (orderOperate == (int)OrderOperate.Received && order.OrderStatus == (int)OrderStatus.HasShipping)))
            {
                if (orderOperate == (int)OrderOperate.Cancle)
                {//取消订单
                    int startOrderStatus = order.OrderStatus;
                    order.OrderStatus = (int)OrderStatus.NoEffect;
                    //库存变化
                    ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Minus);
                    OrderBLL.UserUpdateOrderAddAction(order, "用户取消订单", orderOperate, startOrderStatus);

                    //返还积分--用户付款时兑换抵现的积分额
                    if (order.Point > 0)
                    {
                        var accountRecord = new UserAccountRecordInfo
                        {
                            RecordType = (int)AccountRecordType.Point,
                            Money      = 0,
                            Point      = order.Point,
                            Date       = DateTime.Now,
                            IP         = ClientHelper.IP,
                            Note       = "取消订单:" + order.OrderNumber + ",退回用户积分",
                            UserId     = base.UserId,
                            UserName   = base.UserName
                        };
                        UserAccountRecordBLL.Add(accountRecord);
                    }
                    //发送取消订单通知
                    int    isSendNotice  = ShopConfig.ReadConfigInfo().CancleOrder;
                    int    isSendEmail   = ShopConfig.ReadConfigInfo().CancleOrderEmail;
                    int    isSendMessage = ShopConfig.ReadConfigInfo().CancleOrderMsg;
                    string key           = "CancleOrder";
                    SendOrderOperateMsg(isSendNotice, isSendEmail, isSendMessage, key, order);
                }
                else if (orderOperate == (int)OrderOperate.Received)
                {//确认收货
                    //赠送积分
                    //int sendPoint = OrderBLL.ReadOrderSendPoint(order.Id);
                    if (orderPoint > 0)
                    {
                        var accountRecord = new UserAccountRecordInfo
                        {
                            RecordType = (int)AccountRecordType.Point,
                            Money      = 0,
                            Point      = orderPoint,
                            Date       = DateTime.Now,
                            IP         = ClientHelper.IP,
                            Note       = ShopLanguage.ReadLanguage("OrderReceived").Replace("$OrderNumber", order.OrderNumber),
                            UserId     = base.UserId,
                            UserName   = base.UserName
                        };
                        UserAccountRecordBLL.Add(accountRecord);
                    }
                    int startOrderStatus = order.OrderStatus;
                    order.OrderStatus = (int)OrderStatus.ReceiveShipping;
                    OrderBLL.UserUpdateOrderAddAction(order, "用户确认收货", orderOperate, startOrderStatus);

                    //发送订单收货通知
                    int    isSendNotice  = ShopConfig.ReadConfigInfo().CancleOrder;
                    int    isSendEmail   = ShopConfig.ReadConfigInfo().CancleOrderEmail;
                    int    isSendMessage = ShopConfig.ReadConfigInfo().CancleOrderMsg;
                    string key           = "ReceivedOrder";
                    SendOrderOperateMsg(isSendNotice, isSendEmail, isSendMessage, key, order);
                }
            }
            else
            {
                result = "订单不存在或状态错误";
            }
            ResponseHelper.Write(result);
            ResponseHelper.End();
        }