Beispiel #1
0
        public string AddToShoppingCar(Guid goodId, int count)
        {
            bool res       = false;
            var  loginUser = (UserInfo)ViewBag.User;
            var  goodsInfo = _manager.GetGoodInfoById(goodId);
            int  boxspec   = Utils.ParseInt(goodsInfo.BoxSpec);

            if (boxspec == 0 || !goodsInfo.IsBoxSale)
            {
                boxspec = 1;
            }
            decimal   Stock   = _manager.GetGoodsStock(goodsInfo.ErpId, boxspec);
            OrderItem basItem = new OrderItem();

            if (!_active.CheckCanBuy(goodId, loginUser.AreaNum))
            {
                _response.Msg = "您无法购买该商品!";
                return(Utils.SerializeObject(_response));
            }
            if (count > Stock)
            {
                _response.Msg = "您无法购买该商品!已超过库存!";
                return(Utils.SerializeObject(_response));
            }
            if (goodsInfo.LimitCount > 0 && count > goodsInfo.LimitCount)
            {
                _response.Msg = "该商品限购" + goodsInfo.LimitCount;
                return(Utils.SerializeObject(_response));
            }

            if (_order.IsExitInCar(goodId, loginUser.UserId, out basItem))
            {
                count += basItem.Count;
                if (count > Stock)
                {
                    _response.Msg = "您无法购买该商品!已超过库存!";
                }
                else if (goodsInfo.LimitCount > 0 && count > goodsInfo.LimitCount)
                {
                    _response.Msg = "该商品限购" + goodsInfo.LimitCount;
                    return(Utils.SerializeObject(_response));
                }
                else if (goodsInfo.MinCount > count)
                {
                    _response.Msg = "该商品最少购买" + goodsInfo.MinCount;
                    return(Utils.SerializeObject(_response));
                }
                else
                {
                    _response.Stutas = _order.SaveOrderItem(basItem.Id, count);
                }
            }
            else
            {
                if (goodsInfo.MinCount > count)
                {
                    _response.Msg = "该商品最少购买" + goodsInfo.MinCount;
                    return(Utils.SerializeObject(_response));
                }

                var       model = _manager.GetGoodsWithPrice(goodId, loginUser.TypeId);
                OrderItem item  = new OrderItem();
                item.Count        = count;
                item.CreateUserId = loginUser.UserId;
                decimal discount = _active.CheckDiscountDetail(model.FirstTypeId, loginUser.AreaNum, loginUser.TypeId.ToString());
                if (_active.CheckInBlack(ViewBag.ManagerId, model.Id))
                {
                    discount = 100;
                }
                item.Id            = Guid.NewGuid();
                item.LessPrice     = Math.Round((100 - discount) * model.RetailtPrice / 100, 10);
                item.Price         = model.RetailtPrice;
                item.RealPrice     = item.Price - item.LessPrice;
                item.ProductId     = model.Id;
                item.ProductTittle = model.GoodsTittle;
                item.TotalPrice    = item.RealPrice * count;
                item.ProductType   = model.FirstTypeName;
                item.ProductTypeId = model.FirstTypeId;
                item.ProductId     = model.Id;
                item.BarCode       = model.BarCode;
                item.Spec          = model.Spec;
                item.Unit          = model.Unit;
                item.SupplierId    = model.SupplierId;
                item.SupplierName  = model.SupplierName;
                item.BrandId       = model.BrandId;
                item.Brand         = model.BrandName;
                item.Pic           = model.pic1;
                _response.Stutas   = _order.AddOrderItem(item);
            }
            return(Utils.SerializeObject(_response));
        }