Example #1
0
        /// <summary>
        /// 礼品订单详情
        /// </summary>
        /// <returns></returns>
        public ActionResult OrderDetail(long id)
        {
            var order = _iGiftsOrderService.GetOrder(id, CurrentUser.Id);

            if (order == null)
            {
                throw new MallException("错误的参数");
            }
            var orderlist = new GiftOrderInfo[] { order };

            _iGiftsOrderService.OrderAddUserInfo(orderlist);
            order = orderlist.FirstOrDefault();
            var expressData = _iExpressService.GetExpressData(order.ExpressCompanyName, order.ShipOrderNumber);

            if (expressData.Success)
            {
                expressData.ExpressDataItems = expressData.ExpressDataItems.OrderByDescending(item => item.Time);//按时间逆序排列
            }
            MyGiftsOrderDetailModel result = new MyGiftsOrderDetailModel();

            result.OrderData   = order;
            result.OrderItems  = _iGiftsOrderService.GetOrderItemByOrder(id);
            result.ExpressData = expressData;
            return(View(result));
        }
Example #2
0
        public ActionResult OrderSuccess(long id)
        {
            GiftOrderInfo order = orderser.GetOrder(id, base.CurrentUser.Id);

            if (order == null)
            {
                throw new HimallException("错误的订单编号!");
            }
            ViewBag.Logo = ServiceHelper.Create <ISiteSettingService>().GetSiteSettings().Logo;
            ViewBag.Step = 3;
            return(View(order));
        }
Example #3
0
        public void ConfirmOrder(long id, long userId)
        {
            GiftOrderInfo nullable = context.GiftOrderInfo.FirstOrDefault((GiftOrderInfo a) => a.UserId == userId && a.Id == id && (int)a.OrderStatus == 3);

            if (nullable == null)
            {
                throw new HimallException("错误的订单编号,或订单状态不对!");
            }
            nullable.OrderStatus = GiftOrderInfo.GiftOrderStatus.Finish;
            nullable.FinishDate  = new DateTime?(DateTime.Now);
            context.SaveChanges();
        }
Example #4
0
        /// <summary>
        /// 发货
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="shipCompanyName"></param>
        /// <param name="shipOrderNumber"></param>
        public void SendGood(long id, string shipCompanyName, string shipOrderNumber)
        {
            GiftOrderInfo orderdata = GetOrder(id);

            if (string.IsNullOrWhiteSpace(shipCompanyName) || string.IsNullOrWhiteSpace(shipOrderNumber))
            {
                throw new HimallException("请填写快递公司与快递单号");
            }
            if (orderdata == null)
            {
                throw new HimallException("错误的订单编号");
            }
            if (orderdata.OrderStatus != GiftOrderInfo.GiftOrderStatus.WaitDelivery)
            {
                throw new HimallException("订单状态有误,不可重复发货");
            }
            orderdata.ExpressCompanyName = shipCompanyName;
            orderdata.ShipOrderNumber    = shipOrderNumber;
            orderdata.ShippingDate       = DateTime.Now;
            orderdata.OrderStatus        = GiftOrderInfo.GiftOrderStatus.WaitReceiving;
            DbFactory.Default.Update(orderdata);
        }
Example #5
0
        public void SendGood(long id, string shipCompanyName, string shipOrderNumber)
        {
            GiftOrderInfo order = GetOrder(id);

            if (string.IsNullOrWhiteSpace(shipCompanyName) || string.IsNullOrWhiteSpace(shipOrderNumber))
            {
                throw new HimallException("请填写快递公司与快递单号");
            }
            if (order == null)
            {
                throw new HimallException("错误的订单编号");
            }
            if (order.OrderStatus != GiftOrderInfo.GiftOrderStatus.WaitDelivery)
            {
                throw new HimallException("订单状态有误,不可重复发货");
            }
            order.ExpressCompanyName = shipCompanyName;
            order.ShipOrderNumber    = shipOrderNumber;
            order.ShippingDate       = new DateTime?(DateTime.Now);
            order.OrderStatus        = GiftOrderInfo.GiftOrderStatus.WaitReceiving;
            context.SaveChanges();
        }
Example #6
0
        public JsonResult SubmitOrder(long id, long regionId, int count)
        {
            Result result = new Result()
            {
                success = false,
                msg     = "未知错误",
                status  = 0
            };
            Result str  = result;
            bool   flag = true;

            if (count < 1)
            {
                flag        = false;
                str.success = false;
                str.msg     = "错误的兑换数量!";
                str.status  = -8;
                return(Json(str));
            }
            List <GiftOrderItemModel> giftOrderItemModels = new List <GiftOrderItemModel>();
            UserMemberInfo            member = ServiceHelper.Create <IMemberService>().GetMember(base.CurrentUser.Id);
            GiftInfo byId = giftser.GetById(id);

            if (byId == null)
            {
                flag        = false;
                str.success = false;
                str.msg     = "礼品不存在!";
                str.status  = -2;
                return(Json(str));
            }
            if (byId.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal)
            {
                flag        = false;
                str.success = false;
                str.msg     = "礼品己失效!";
                str.status  = -2;
                return(Json(str));
            }
            if (count > byId.StockQuantity)
            {
                flag        = false;
                str.success = false;
                int stockQuantity = byId.StockQuantity;
                str.msg    = string.Concat("礼品库存不足,仅剩 ", stockQuantity.ToString(), " 件!");
                str.status = -3;
                return(Json(str));
            }
            if (byId.NeedIntegral < 1)
            {
                flag        = false;
                str.success = false;
                str.msg     = "礼品关联等级信息有误或礼品积分数据有误!";
                str.status  = -5;
                return(Json(str));
            }
            if (byId.LimtQuantity > 0 && orderser.GetOwnBuyQuantity(base.CurrentUser.Id, id) + count > byId.LimtQuantity)
            {
                flag        = false;
                str.success = false;
                str.msg     = "超过礼品限兑数量!";
                str.status  = -4;
                return(Json(str));
            }
            if (byId.NeedIntegral * count > member.AvailableIntegrals)
            {
                flag        = false;
                str.success = false;
                str.msg     = "积分不足!";
                str.status  = -6;
                return(Json(str));
            }
            if (member.HistoryIntegral < byId.GradeIntegral)
            {
                flag        = false;
                str.success = false;
                str.msg     = "用户等级不足!";
                str.status  = -6;
                return(Json(str));
            }
            ShippingAddressInfo shippingAddress = GetShippingAddress(new long?(regionId));

            if (shippingAddress == null)
            {
                flag        = false;
                str.success = false;
                str.msg     = "错误的收货人地址信息!";
                str.status  = -6;
                return(Json(str));
            }
            if (flag)
            {
                GiftOrderItemModel giftOrderItemModel = new GiftOrderItemModel()
                {
                    GiftId = byId.Id,
                    Counts = count
                };
                giftOrderItemModels.Add(giftOrderItemModel);
                GiftOrderModel giftOrderModel = new GiftOrderModel()
                {
                    Gifts          = giftOrderItemModels,
                    CurrentUser    = member,
                    ReceiveAddress = shippingAddress
                };
                GiftOrderInfo giftOrderInfo = orderser.CreateOrder(giftOrderModel);
                str.success = true;
                str.msg     = giftOrderInfo.Id.ToString();
                str.status  = 1;
            }
            return(Json(str));
        }
Example #7
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public GiftOrderInfo CreateOrder(GiftOrderModel model)
        {
            if (model.CurrentUser == null)
            {
                throw new HimallException("错误的用户信息");
            }
            if (model.ReceiveAddress == null)
            {
                throw new HimallException("错误的收货人信息");
            }
            GiftOrderInfo result = new GiftOrderInfo()
            {
                Id             = GenerateOrderNumber(),
                UserId         = model.CurrentUser.Id,
                RegionId       = model.ReceiveAddress.RegionId,
                ShipTo         = model.ReceiveAddress.ShipTo,
                Address        = model.ReceiveAddress.Address + " " + model.ReceiveAddress.AddressDetail,
                RegionFullName = model.ReceiveAddress.RegionFullName,
                CellPhone      = model.ReceiveAddress.Phone,
                TopRegionId    = int.Parse(model.ReceiveAddress.RegionIdPath.Split(',')[0]),
                UserRemark     = model.UserRemark,
            };
            var giftOrderItemInfo = new List <GiftOrderItemInfo>();

            DbFactory.Default
            .InTransaction(() =>
            {
                //礼品信息处理,库存判断并减库存
                foreach (var item in model.Gifts)
                {
                    if (item.Counts < 1)
                    {
                        throw new HimallException("错误的兑换数量!");
                    }
                    GiftInfo giftdata = DbFactory.Default.Get <GiftInfo>().Where(d => d.Id == item.GiftId).FirstOrDefault();
                    if (giftdata != null && giftdata.GetSalesStatus == GiftInfo.GiftSalesStatus.Normal)
                    {
                        if (giftdata.StockQuantity >= item.Counts)
                        {
                            giftdata.StockQuantity = giftdata.StockQuantity - item.Counts; //先减库存
                            giftdata.RealSales    += item.Counts;                          //加销量

                            GiftOrderItemInfo gorditem = new GiftOrderItemInfo()
                            {
                                GiftId       = giftdata.Id,
                                GiftName     = giftdata.GiftName,
                                GiftValue    = giftdata.GiftValue,
                                ImagePath    = giftdata.ImagePath,
                                OrderId      = result.Id,
                                Quantity     = item.Counts,
                                SaleIntegral = giftdata.NeedIntegral
                            };
                            giftOrderItemInfo.Add(gorditem);
                            DbFactory.Default.Update(giftdata);
                        }
                        else
                        {
                            throw new HimallException("礼品库存不足!");
                        }
                    }
                    else
                    {
                        throw new HimallException("礼品不存在或已失效!");
                    }
                }
                //建立订单
                result.TotalIntegral = giftOrderItemInfo.Sum(d => d.Quantity * d.SaleIntegral);
                result.OrderStatus   = GiftOrderInfo.GiftOrderStatus.WaitDelivery;
                result.OrderDate     = DateTime.Now;
                DbFactory.Default.Add(result);
                DbFactory.Default.AddRange(giftOrderItemInfo);
                //减少积分
                var userdata = DbFactory.Default.Get <MemberInfo>().Where(d => d.Id == model.CurrentUser.Id).FirstOrDefault();
                DeductionIntegral(userdata, result.Id, (int)result.TotalIntegral);
            });
            return(result);
        }
Example #8
0
        /// <summary>
        /// 获取订单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public GiftOrderInfo GetOrder(long orderId, long userId)
        {
            GiftOrderInfo result = DbFactory.Default.Get <GiftOrderInfo>().Where(d => d.Id == orderId && d.UserId == userId).FirstOrDefault();

            return(result);
        }
Example #9
0
        public GiftOrderInfo CreateOrder(GiftOrderModel model)
        {
            if (model.CurrentUser == null)
            {
                throw new HimallException("错误的用户信息");
            }
            if (model.ReceiveAddress == null)
            {
                throw new HimallException("错误的收货人信息");
            }
            GiftOrderInfo giftOrderInfo = new GiftOrderInfo()
            {
                Id             = GenerateOrderNumber(),
                UserId         = model.CurrentUser.Id,
                RegionId       = new int?(model.ReceiveAddress.RegionId),
                ShipTo         = model.ReceiveAddress.ShipTo,
                Address        = model.ReceiveAddress.Address,
                RegionFullName = model.ReceiveAddress.RegionFullName,
                CellPhone      = model.ReceiveAddress.Phone
            };
            string regionIdPath = model.ReceiveAddress.RegionIdPath;

            char[] chrArray = new char[] { ',' };
            giftOrderInfo.TopRegionId = new int?(int.Parse(regionIdPath.Split(chrArray)[0]));
            giftOrderInfo.UserRemark  = model.UserRemark;
            GiftOrderInfo now = giftOrderInfo;

            using (TransactionScope transactionScope = new TransactionScope())
            {
                foreach (GiftOrderItemModel gift in model.Gifts)
                {
                    if (gift.Counts < 1)
                    {
                        throw new HimallException("错误的兑换数量!");
                    }
                    GiftInfo stockQuantity = context.GiftInfo.FirstOrDefault((GiftInfo d) => d.Id == gift.GiftId);
                    if (stockQuantity == null || stockQuantity.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal)
                    {
                        throw new HimallException("礼品不存在或己失效!");
                    }
                    if (stockQuantity.StockQuantity < gift.Counts)
                    {
                        throw new HimallException("礼品库存不足!");
                    }
                    stockQuantity.StockQuantity = stockQuantity.StockQuantity - gift.Counts;
                    GiftInfo realSales = stockQuantity;
                    realSales.RealSales = realSales.RealSales + gift.Counts;
                    GiftOrderItemInfo giftOrderItemInfo = new GiftOrderItemInfo()
                    {
                        GiftId       = stockQuantity.Id,
                        GiftName     = stockQuantity.GiftName,
                        GiftValue    = stockQuantity.GiftValue,
                        ImagePath    = stockQuantity.ImagePath,
                        OrderId      = new long?(now.Id),
                        Quantity     = gift.Counts,
                        SaleIntegral = new int?(stockQuantity.NeedIntegral)
                    };
                    now.Himall_GiftOrderItem.Add(giftOrderItemInfo);
                }
                now.TotalIntegral = now.Himall_GiftOrderItem.Sum <GiftOrderItemInfo>((GiftOrderItemInfo d) => {
                    int quantity     = d.Quantity;
                    int?saleIntegral = d.SaleIntegral;
                    if (!saleIntegral.HasValue)
                    {
                        return(null);
                    }
                    return(new int?(quantity * saleIntegral.GetValueOrDefault()));
                });
                now.OrderStatus = GiftOrderInfo.GiftOrderStatus.WaitDelivery;
                now.OrderDate   = DateTime.Now;
                context.GiftOrderInfo.Add(now);
                context.SaveChanges();
                UserMemberInfo userMemberInfo = context.UserMemberInfo.FirstOrDefault((UserMemberInfo d) => d.Id == model.CurrentUser.Id);
                DeductionIntegral(userMemberInfo, now.Id, now.TotalIntegral.Value);
                transactionScope.Complete();
            }
            return(now);
        }
        public JsonResult SubmitOrder(long id, long regionId, int count)
        {
            Result result = new Result()
            {
                success = false, msg = "未知错误", status = 0
            };
            bool isdataok = true;

            if (count < 1)
            {
                isdataok       = false;
                result.success = false;
                result.msg     = "错误的兑换数量!";
                result.status  = -8;

                return(Json(result));
            }
            //Checkout
            List <GiftOrderItemModel> gorditemlist = new List <GiftOrderItemModel>();

            #region 礼品信息判断
            //礼品信息
            GiftInfo giftdata = _iGiftService.GetById(id);
            if (giftdata == null)
            {
                isdataok       = false;
                result.success = false;
                result.msg     = "礼品不存在!";
                result.status  = -2;

                return(Json(result));
            }

            if (giftdata.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal)
            {
                isdataok       = false;
                result.success = false;
                result.msg     = "礼品已失效!";
                result.status  = -2;

                return(Json(result));
            }

            //库存判断
            if (count > giftdata.StockQuantity)
            {
                isdataok       = false;
                result.success = false;
                result.msg     = "礼品库存不足,仅剩 " + giftdata.StockQuantity.ToString() + " 件!";
                result.status  = -3;

                return(Json(result));
            }

            //积分数
            if (giftdata.NeedIntegral < 1)
            {
                isdataok       = false;
                result.success = false;
                result.msg     = "礼品关联等级信息有误或礼品积分数据有误!";
                result.status  = -5;

                return(Json(result));
            }
            #endregion

            #region 用户信息判断
            //限购数量
            if (giftdata.LimtQuantity > 0)
            {
                int ownbuynumber = _iGiftsOrderService.GetOwnBuyQuantity(CurrentUser.Id, id);
                if (ownbuynumber + count > giftdata.LimtQuantity)
                {
                    isdataok       = false;
                    result.success = false;
                    result.msg     = "超过礼品限兑数量!";
                    result.status  = -4;

                    return(Json(result));
                }
            }
            var userInte = MemberIntegralApplication.GetMemberIntegral(CurrentUser.Id);
            if (giftdata.NeedIntegral * count > userInte.AvailableIntegrals)
            {
                isdataok       = false;
                result.success = false;
                result.msg     = "积分不足!";
                result.status  = -6;

                return(Json(result));
            }
            if (giftdata.NeedGrade > 0)
            {
                var memgradeid = _iMemberGradeService.GetMemberGradeByUserId(CurrentUser.Id);
                //等级判定
                if (!_iMemberGradeService.IsOneGreaterOrEqualTwo(memgradeid, giftdata.NeedGrade))
                {
                    isdataok       = false;
                    result.success = false;
                    result.msg     = "用户等级不足!";
                    result.status  = -6;

                    return(Json(result));
                }
            }
            #endregion

            ShippingAddressInfo shipdata = GetShippingAddress(regionId);
            if (shipdata == null)
            {
                isdataok       = false;
                result.success = false;
                result.msg     = "错误的收货人地址信息!";
                result.status  = -6;

                return(Json(result));
            }

            if (isdataok)
            {
                gorditemlist.Add(new GiftOrderItemModel {
                    GiftId = giftdata.Id, Counts = count
                });
                GiftOrderModel createorderinfo = new GiftOrderModel();
                createorderinfo.Gifts          = gorditemlist;
                createorderinfo.CurrentUser    = CurrentUser;
                createorderinfo.ReceiveAddress = shipdata;
                GiftOrderInfo orderdata = _iGiftsOrderService.CreateOrder(createorderinfo);
                result.success = true;
                result.msg     = orderdata.Id.ToString();
                result.status  = 1;
            }

            return(Json(result));
        }
        /// <summary>
        /// 创建预约单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public GiftOrderInfo CreateOrder(GiftOrderModel model)
        {
            if (model.CurrentUser == null)
            {
                throw new HimallException("错误的用户信息");
            }
            if (model.ReceiveAddress == null)
            {
                throw new HimallException("错误的收货人信息");
            }
            GiftOrderInfo result = new GiftOrderInfo()
            {
                Id             = GenerateOrderNumber(),
                UserId         = model.CurrentUser.Id,
                RegionId       = model.ReceiveAddress.RegionId,
                ShipTo         = model.ReceiveAddress.ShipTo,
                Address        = model.ReceiveAddress.Address,
                RegionFullName = model.ReceiveAddress.RegionFullName,
                CellPhone      = model.ReceiveAddress.Phone,
                TopRegionId    = int.Parse(model.ReceiveAddress.RegionIdPath.Split(',')[0]),
                UserRemark     = model.UserRemark
            };

            using (TransactionScope scope = new TransactionScope())
            {
                //礼品信息处理,库存判断并减库存
                foreach (var item in model.Gifts)
                {
                    if (item.Counts < 1)
                    {
                        throw new HimallException("错误的兑换数量!");
                    }
                    GiftInfo giftdata = Context.GiftInfo.FirstOrDefault(d => d.Id == item.GiftId);
                    if (giftdata != null && giftdata.GetSalesStatus == GiftInfo.GiftSalesStatus.Normal)
                    {
                        if (giftdata.StockQuantity >= item.Counts)
                        {
                            giftdata.StockQuantity = giftdata.StockQuantity - item.Counts; //先减库存
                            giftdata.RealSales    += item.Counts;                          //加销量

                            GiftOrderItemInfo gorditem = new GiftOrderItemInfo()
                            {
                                GiftId       = giftdata.Id,
                                GiftName     = giftdata.GiftName,
                                GiftValue    = giftdata.GiftValue,
                                ImagePath    = giftdata.ImagePath,
                                OrderId      = result.Id,
                                Quantity     = item.Counts,
                                SaleIntegral = giftdata.NeedIntegral
                            };
                            result.Himall_GiftOrderItem.Add(gorditem);
                        }
                        else
                        {
                            throw new HimallException("礼品库存不足!");
                        }
                    }
                    else
                    {
                        throw new HimallException("礼品不存在或已失效!");
                    }
                }
                //建立预约单
                result.TotalIntegral = result.Himall_GiftOrderItem.Sum(d => d.Quantity * d.SaleIntegral);
                result.OrderStatus   = GiftOrderInfo.GiftOrderStatus.WaitDelivery;
                result.OrderDate     = DateTime.Now;
                Context.GiftOrderInfo.Add(result);
                Context.SaveChanges();
                //减少积分
                var userdata = Context.UserMemberInfo.FirstOrDefault(d => d.Id == model.CurrentUser.Id);
                DeductionIntegral(userdata, result.Id, (int)result.TotalIntegral);

                scope.Complete();
            }

            return(result);
        }
        /// <summary>
        /// 获取预约单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public GiftOrderInfo GetOrder(long orderId, long userId)
        {
            GiftOrderInfo result = Context.GiftOrderInfo.FirstOrDefault(d => d.Id == orderId && d.UserId == userId);

            return(result);
        }
        public JsonResult SubmitOrder(long id, long regionId, int count)
        {
            Result result = new Result()
            {
                success = false,
                msg     = "Unknown error",
                status  = 0
            };
            Result str  = result;
            bool   flag = true;

            if (count < 1)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Exchange quantity error!";
                str.status  = -8;
                return(Json(str));
            }
            List <GiftOrderItemModel> giftOrderItemModels = new List <GiftOrderItemModel>();
            UserMemberInfo            member = ServiceHelper.Create <IMemberService>().GetMember(base.CurrentUser.Id);
            GiftInfo byId = giftser.GetById(id);

            if (byId == null)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Gift does not exist!";
                str.status  = -2;
                return(Json(str));
            }
            if (byId.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Gift expired!";
                str.status  = -2;
                return(Json(str));
            }
            if (count > byId.StockQuantity)
            {
                flag        = false;
                str.success = false;
                int stockQuantity = byId.StockQuantity;
                str.msg    = string.Concat("Gift inventory shortage, only remain ", stockQuantity.ToString(), " items!");
                str.status = -3;
                return(Json(str));
            }
            if (byId.NeedIntegral < 1)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Gifts associated level information is wrong or points wrong!";
                str.status  = -5;
                return(Json(str));
            }
            if (byId.LimtQuantity > 0 && orderser.GetOwnBuyQuantity(base.CurrentUser.Id, id) + count > byId.LimtQuantity)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Exceed gift exchange quantity!";
                str.status  = -4;
                return(Json(str));
            }
            if (byId.NeedIntegral * count > member.AvailableIntegrals)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Lack of points!";
                str.status  = -6;
                return(Json(str));
            }
            if (member.HistoryIntegral < byId.GradeIntegral)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Lack of Level!";
                str.status  = -6;
                return(Json(str));
            }
            ShippingAddressInfo shippingAddress = GetShippingAddress(new long?(regionId));

            if (shippingAddress == null)
            {
                flag        = false;
                str.success = false;
                str.msg     = "Shipping address error!";
                str.status  = -6;
                return(Json(str));
            }
            if (flag)
            {
                GiftOrderItemModel giftOrderItemModel = new GiftOrderItemModel()
                {
                    GiftId = byId.Id,
                    Counts = count
                };
                giftOrderItemModels.Add(giftOrderItemModel);
                GiftOrderModel giftOrderModel = new GiftOrderModel()
                {
                    Gifts          = giftOrderItemModels,
                    CurrentUser    = member,
                    ReceiveAddress = shippingAddress
                };
                GiftOrderInfo giftOrderInfo = orderser.CreateOrder(giftOrderModel);
                str.success = true;
                str.msg     = giftOrderInfo.Id.ToString();
                str.status  = 1;
            }
            return(Json(str));
        }