示例#1
0
        /// <summary>
        /// 获取前台展示的店铺类目
        /// </summary>
        internal List <ShopCat> GetDPLM()
        {
            ITopClient             client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
            ShopcatsListGetRequest req    = new ShopcatsListGetRequest();

            req.Fields = "cid,parent_cid,name,is_parent";
            ShopcatsListGetResponse       response    = client.Execute(req);
            List <Top.Api.Domain.ShopCat> listshopcat = response.ShopCats;
            List <ShopCat> Listshopcate = new List <ShopCat>();

            foreach (Top.Api.Domain.ShopCat item in listshopcat)
            {
                ShopCat shopcat = new ShopCat();
                shopcat.Cid       = item.Cid;
                shopcat.IsParent  = item.IsParent;
                shopcat.Name      = item.Name;
                shopcat.ParentCid = item.ParentCid;
                Listshopcate.Add(shopcat);
            }
            return(Listshopcate);
        }
示例#2
0
        /// <summary>
        /// 添加购物车
        /// </summary>
        /// <param name="ProductID">产品ID</param>
        /// <param name="Count">产品数量</param>
        /// <returns></returns>
        public JsonResult InsertCat(int ProductID, int Count, string guige)
        {
            try
            {
                ShopProduct product      = DB.ShopProduct.FindEntity(ProductID);
                var         category     = DB.ShopProduct.GetCategoryId2(product.CategoryID.Value);
                var         guigeproduct = DB.GuiGeName.Where(a => a.CName == category.Name).Count();

                if (product.CategoryID1.Value == DB.XmlConfig.XmlSite.Scores && Count != 1)
                {
                    throw new Exception("拼团专区只能买一个");
                }


                string[] strlist = guige.Split('_');

                if (strlist.Length < guigeproduct)
                {
                    throw new Exception("请选择完整规格");
                }

                var gproduct = DB.ShopProduct.GetSPrice(product, guige);
                if (gproduct == null)
                {
                    throw new Exception("库存不足下单失败");
                }

                //判断购物车中是否都是同一个大类中的产品
                ShopCat fistPro = DB.ShopCat.Where(q => q.MemberID == CurrentUserID).FirstOrDefault();
                if (fistPro != null)
                {
                    //if (fistPro.ShopProduct.CategoryID1 != product.CategoryID1)
                    //    return Error("在一次下单中,只能结算同一类商品");
                    if (fistPro.ShopProduct.ID != product.ID && fistPro.ShopProduct.CategoryID1 == DB.XmlConfig.XmlSite.Scores)
                    {
                        return(Error("在一次下单中,拼团专区只能加入同一种购物车商品"));
                    }
                }

                //如果是订单商品,判断用户是否是注册30天之内,否则不允许再次下单
                //if (product.IsDingDan())
                //{
                //    if (CurrentUser.MemberLevelId > 0)//会员用户
                //    {
                //        //规定等级的订单商品不能
                //        var levels = DB.Sys_Level.ToList();
                //        if (levels.Any(q => q.Investment == product.PriceShopping))
                //            return Error("会员用户只能购买升级商品");
                //    }
                //    else
                //    {//粉丝用户
                //        var levels = DB.Sys_Level.ToList();
                //        if (levels.Any(q => q.Investment == product.PriceShopping) == false)
                //            return Error("粉丝用户只能购买订单商品");
                //    }
                //}


                if (Count > gproduct.KuCun)
                {
                    throw new Exception("库存不足");
                }
                //判断用户的产品是否存在,存在购买数量++
                if (DB.ShopCat.Any(q => q.ProductID == ProductID && q.GuiGe == guige && q.MemberID == CurrentUserID))
                {
                    ShopCat model = DB.ShopCat.FindEntity(q => q.ProductID == ProductID && q.MemberID == CurrentUserID);
                    if (product.CategoryID1 == DB.XmlConfig.XmlSite.Scores)
                    {
                        model.Count = 1;
                    }
                    else
                    {
                        model.Count += Count;
                    }
                    if (model.Count > gproduct.KuCun)
                    {
                        throw new Exception("库存不足");
                    }
                    if (DB.ShopCat.Update(model))
                    {
                        return(Success("添加购物车成功"));
                    }
                    return(Error("添加购物车失败"));
                }
                else
                {
                    ShopCat cat = new ShopCat();
                    cat.ProductID  = ProductID;
                    cat.Count      = Count;
                    cat.GuiGe      = guige;
                    cat.MemberID   = CurrentUserID;
                    cat.CreateTime = DateTime.Now;
                    if (DB.ShopCat.Insert(cat))
                    {
                        return(Success("添加购物车成功"));
                    }
                    return(Error("添加购物车失败"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex));
            }
        }