Exemple #1
0
        /// <summary>
        /// 获取属性集合
        /// </summary>
        /// <param name="classId"></param>
        /// <returns></returns>
        public static void LisAttr(int classId, List <Attr> attrList)
        {
            Product_Class model = BllProduct_Class.First(o => o.Id == classId);

            if (model != null && model.ParId > 0)
            {
                LisAttr((int)model.ParId, attrList);
            }
            var attrlist = Query(o => o.ClassId == classId, o => o.Sequence, "asc");

            foreach (var item in attrlist)
            {
                Attr attr = new Attr();
                attr.id         = item.Id;
                attr.name       = item.AttributeName;
                attr.value      = item.DefaultValue;
                attr.inputtype  = item.InputType.Value;
                attr.attrlist   = BllProduct_AttributeSelect.ListAttrVale(attr.id);
                attr.sequence   = item.Sequence.Value;
                attr.isrequired = (bool)item.IsRequired;
                attr.isshow     = (bool)item.IsShow;
                attr.issort     = (bool)item.IsSort;
                attr.isspecial  = (bool)item.IsSpecial;
                attrList.Add(attr);
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public List <Product_Class> GetCategories(BUser user)
        {
            List <Product_Class>     categories = new List <Product_Class>();
            SellercatsListGetRequest req        = new SellercatsListGetRequest();

            req.Nick = user.Mall_Name;
            SellercatsListGetResponse response = client.Execute(req);

            if (response.IsError)
            {
                throw new KMJXCException(response.ErrMsg);
            }

            if (response.SellerCats != null)
            {
                foreach (TB.SellerCat cat in response.SellerCats)
                {
                    Product_Class category = new Product_Class();
                    category.Create_Time      = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    category.Create_User_ID   = user.ID;
                    category.Enabled          = true;
                    category.Mall_CID         = cat.Cid.ToString();
                    category.Mall_PCID        = cat.ParentCid.ToString();
                    category.Name             = cat.Name;
                    category.Parent_ID        = 0;
                    category.Product_Class_ID = 0;
                    categories.Add(category);
                }
            }
            return(categories);
        }
        public ActionResult SaveSpu()
        {
            Product_Info modPro  = new Product_Info();
            int          classId = RequestInt("classid");
            string       spu     = RequestString("spu");

            //产品分类验证
            Product_Class modClass = null;

            if (classId > 0)
            {
                modClass = Bll.BllProduct_Class.First(o => o.Id == classId);
                if (modClass == null)
                {
                    return(LayerAlertErrorAndReturn("分类不存在!"));
                }
                var classIds = modClass.ParPath.TrimEnd(',').Split(',');
                modPro.ClassId_1    = classIds.Length > 0 ? classIds[0].ToInt32() : 0;
                modPro.ClassId_2    = classIds.Length > 1 ? classIds[1].ToInt32() : 0;
                modPro.ClassId      = modClass.Id;
                modPro.ClassParPath = modClass.ParPath;
            }
            else
            {
                return(LayerAlertErrorAndReturn("请选择一个产品分类!"));
            }

            //spu编号重复验证
            if (Bll.BllProduct_Info.IsExistsSpu(spu))
            {
                return(LayerAlertErrorAndReturn("该SPU编号已存在,请修改!"));
            }

            modPro.Spu        = spu;
            modPro.IsShow     = false;
            modPro.CreateDate = DateTime.Now;
            modPro.AdminId    = MyInfo.Id;
            int proId = Bll.BllProduct_Info.Insert(modPro);

            if (proId > 0)
            {
                return(LayerAlertSuccessAndRefresh("添加成功"));
            }
            else
            {
                return(LayerAlertErrorAndReturn("添加失败"));
            }
        }
        //产品模型绑定处理
        private Product_Info BindProModel(Product_Info modPro, Product_Class modClass, List <AttrJson> listAttr, List <AttrJson> listAttrCustom)
        {
            //产品图片
            string firstPic = string.Empty;
            string pics     = GetPics("pic", ref firstPic);

            //分类信息
            if (modClass != null)
            {
                var classIds = modClass.ParPath.TrimEnd(',').Split(',');
                modPro.ClassId_1    = classIds.Length > 0 ? classIds[0].ToInt32() : 0;
                modPro.ClassId_2    = classIds.Length > 1 ? classIds[1].ToInt32() : 0;
                modPro.ClassId      = modClass.Id;
                modPro.ClassParPath = modClass.ParPath;
            }
            //产品特性
            string features = string.Empty;

            for (int i = 0; i < 5; i++)
            {
                string temp = RequestString("feature" + i);
                if (temp != "")
                {
                    features += temp + "|";
                }
            }
            modPro.Features = features.TrimEnd('|');
            //图案
            int patternid = RequestInt("patternid");

            if (patternid > 0)
            {
                modPro.PatternId = patternid;
                modPro.Pattern   = Bll.BllProduct_Pattern.GetPatternName(patternid);
            }
            //上架时间
            modPro.FirstPic        = firstPic;
            modPro.Pics            = pics;
            modPro.AdminId         = MyInfo.Id;
            modPro.Attribute       = Tools.Tool.JsonHelper.Serialize(listAttr);
            modPro.AttributeCustom = Tools.Tool.JsonHelper.Serialize(listAttrCustom);
            modPro.Attachment      = GetFile("attachment");
            modPro.Videos          = GetFile("video");
            return(modPro);
        }
Exemple #5
0
        public object GetProAttr(int id)
        {
            ResultJson    result = new ResultJson();
            Product_Class model  = Bll.BllProduct_Class.First(o => o.Id == id);

            if (id == 0 || (model == null || model.ChildNum > 0))
            {
                result.state = 0;
                result.error = "无效分类";
                return(Json(result));
            }
            else
            {
                result.state = 1;
                result.attr  = new List <Attr>();
                Bll.BllProduct_Attribute.LisAttr(id, result.attr);
                return(Json(result));
            }
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public List <BProperty> GetProperities(Product_Class category, Shop shop)
        {
            List <BProperty>    properities = new List <BProperty>();
            ItempropsGetRequest req         = new ItempropsGetRequest();

            req.Fields = "pid,name,must,multi,prop_values";
            if (category != null && !string.IsNullOrEmpty(category.Mall_CID))
            {
                req.Cid = long.Parse(category.Mall_CID);
            }
            else
            {
                req.Cid = 0;
            }
            //req.IsKeyProp = true;
            req.IsSaleProp  = true;
            req.IsColorProp = true;
            req.IsEnumProp  = true;
            req.IsInputProp = true;
            req.IsItemProp  = true;
            //1=>Taobao
            //2=>TMall, need to check Mall Type from Shop object
            req.Type = 1L;

            ItempropsGetResponse response = client.Execute(req);

            if (response.IsError)
            {
                throw new KMJXCException(response.ErrMsg);
            }

            if (response.ItemProps != null)
            {
                foreach (TB.ItemProp prop in response.ItemProps)
                {
                    BProperty pro = new BProperty();
                    pro.Created    = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    pro.MID        = prop.Pid.ToString();
                    pro.Name       = prop.Name;
                    pro.CategoryId = category.Product_Class_ID;
                    pro.ID         = 0;
                    pro.Shop       = new BShop()
                    {
                        ID = category.Shop_ID
                    };
                    pro.Created_By = new BUser()
                    {
                        ID = category.Create_User_ID
                    };
                    properities.Add(pro);
                    if (prop.PropValues != null)
                    {
                        foreach (TB.PropValue pv in prop.PropValues)
                        {
                            Product_Spec_Value psv = new Product_Spec_Value();
                            psv.Name = pv.Name;
                            pro.Values.Add(psv);
                        }
                    }
                }
            }

            return(properities);
        }
        public ActionResult Save(ProductInfoModel model)
        {
            Product_Info modPro = null;

            //产品分类验证
            if (model.classid == 0)
            {
                return(LayerAlertErrorAndReturn("请选择一个产品分类!"));
            }
            Product_Class modClass = null;

            if (model.classid > 0)
            {
                modClass = Bll.BllProduct_Class.First(o => o.Id == model.classid);
                if (modClass == null)
                {
                    return(LayerAlertErrorAndReturn("分类不存在!"));
                }
            }

            //spu编号重复验证
            if (model.id == 0 && Bll.BllProduct_Info.IsExistsSpu(model.spu))
            {
                return(LayerAlertErrorAndReturn("该SPU编号已存在,请修改!"));
            }

            //产品属性
            List <Product_AttributeSet> attrsetlist    = new List <Product_AttributeSet>();                          //属性关联
            List <AttrJson>             listAttr       = GetAttrList(model.classid, ref attrsetlist);                //分类配置属性
            List <AttrJson>             listAttrCustom = GetCustomAttrList("myAttrId", "myAttrName", "myAttrValue"); //自定义属性

            model.content = TransferImgToLocal(EscapeSpace(model.content ?? ""));

            if (model.id == 0)
            {
                modPro = new Product_Info();
                //DTO转换,模型数据处理
                modPro            = BindProModel(model.MapTo(modPro), modClass, listAttr, listAttrCustom);
                modPro.CreateDate = DateTime.Now;
                modPro.Url        = GetFormatUrl(model.title);
                int proId = Bll.BllProduct_Info.Insert(modPro);
                if (proId > 0)
                {
                    //绑定可筛选属性
                    InsertAttrlist(attrsetlist, proId);
                    return(LayerAlertSuccessAndRefresh("添加成功"));
                }
                else
                {
                    return(LayerAlertErrorAndReturn("添加失败"));
                }
            }
            else
            {
                //获取产品信息
                modPro = Bll.BllProduct_Info.First(o => o.Id == model.id);
                if (modPro == null)
                {
                    return(LayerAlertErrorAndReturn("产品不存在!"));
                }
                //绑定模型
                modPro            = BindProModel(model.MapTo(modPro), modClass, listAttr, listAttrCustom);
                modPro.Url        = GetFormatUrl(model.title);
                modPro.UpdateDate = DateTime.Now;
                if (Bll.BllProduct_Info.Update(modPro, o => o.Id == modPro.Id) > 0)
                {
                    //绑定可筛选属性
                    InsertAttrlist(attrsetlist, modPro.Id);
                    return(LayerAlertSuccessAndRefresh("修改成功"));
                }
                else
                {
                    return(LayerAlertErrorAndReturn("修改失败"));
                }
            }
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public List <BProduct> SearchProducts(int[] product_ids, int[] suppliers, string title, string description, int startTime, int endTime, int?category_id, int pageIndex, int pageSize, out int total, bool includeProps = false, bool paging = true, bool includeSupplier = false)
        {
            total = 0;
            List <BProduct> products = new List <BProduct>();

            if (pageIndex <= 0)
            {
                pageIndex = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 30;
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                int[] childshop_ids = (from c in this.DBChildShops select c.Shop_ID).ToArray <int>();

                var dbps = from product in db.Product
                           //join employee in db.Employee on product.User_ID equals employee.User_ID
                           where product.Parent_ID == 0
                           //&& (product.Shop_ID == this.Shop.Shop_ID || product.Shop_ID == this.Main_Shop.Shop_ID || childshop_ids.Contains(product.Shop_ID))
                           select new
                {
                    Pdt = product,
                    //Emp=employee,
                };

                if (product_ids != null && product_ids.Length > 0)
                {
                    dbps = dbps.Where(a => product_ids.Contains(a.Pdt.Product_ID));
                }

                if (childshop_ids != null && childshop_ids.Length > 0)
                {
                    dbps = dbps.Where(a => a.Pdt.Shop_ID == this.Shop.Shop_ID || a.Pdt.Shop_ID == this.Main_Shop.Shop_ID || childshop_ids.Contains(a.Pdt.Shop_ID));
                }
                else
                {
                    dbps = dbps.Where(a => a.Pdt.Shop_ID == this.Shop.Shop_ID || a.Pdt.Shop_ID == this.Main_Shop.Shop_ID);
                }
                if (!string.IsNullOrEmpty(title))
                {
                    dbps = dbps.Where(a => a.Pdt.Name.Contains(title.Trim()));
                }

                if (!string.IsNullOrEmpty(description))
                {
                    dbps = dbps.Where(a => a.Pdt.Description.Contains(description));
                }

                if (startTime > 0)
                {
                    dbps = dbps.Where(a => a.Pdt.Create_Time >= startTime);
                }

                if (endTime > 0)
                {
                    dbps = dbps.Where(a => a.Pdt.Create_Time <= endTime);
                }

                if (suppliers != null && suppliers.Length > 0)
                {
                    //int[] pdtIds=(from ps in db.Product_Supplier where suppliers.Contains(ps.Supplier_ID) && ps.Enabled==true select ps.Product_ID).ToArray<int>();
                    var pdtIds = from ps in db.Product_Supplier where suppliers.Contains(ps.Supplier_ID) && ps.Enabled == true orderby ps.Created descending select ps.Product_ID;
                    dbps = dbps.Where(a => pdtIds.Contains(a.Pdt.Product_ID));
                }

                if (category_id != null)
                {
                    Product_Class cate = (from ca in db.Product_Class where ca.Product_Class_ID == category_id select ca).FirstOrDefault <Product_Class>();
                    if (cate != null)
                    {
                        if (cate.Parent_ID == 0)
                        {
                            int[] ccids = (from c in db.Product_Class where c.Parent_ID == category_id select c.Product_Class_ID).ToArray <int>();
                            if (ccids != null && ccids.Length > 0)
                            {
                                dbps = dbps.Where(a => (ccids.Contains(a.Pdt.Product_Class_ID) || a.Pdt.Product_Class_ID == category_id));
                            }
                            else
                            {
                                dbps = dbps.Where(a => a.Pdt.Product_Class_ID == category_id);
                            }
                        }
                        else
                        {
                            dbps = dbps.Where(a => a.Pdt.Product_Class_ID == category_id);
                        }
                    }
                }
                dbps  = dbps.OrderBy(a => a.Pdt.Shop_ID).OrderBy(b => b.Pdt.Create_Time);
                total = dbps.Count();
                if (total > 0)
                {
                    var bps = from bpss in dbps
                              select new BProduct
                    {
                        Description = bpss.Pdt.Description,
                        Shop        = (from sp in db.Shop where sp.Shop_ID == bpss.Pdt.Shop_ID select sp).FirstOrDefault <Shop>(),
                        Price       = bpss.Pdt.Price,
                        ID          = bpss.Pdt.Product_ID,
                        Title       = bpss.Pdt.Name,
                        CreateTime  = bpss.Pdt.Create_Time,
                        Code        = bpss.Pdt.Code,
                        Unit        = (from u in db.Product_Unit where u.Product_Unit_ID == bpss.Pdt.Product_Unit_ID select u).FirstOrDefault <Product_Unit>(),
                        Category    = (from c in db.Product_Class
                                       where bpss.Pdt.Product_Class_ID == c.Product_Class_ID
                                       select new BCategory
                        {
                            Name = c.Name,
                            ID = c.Product_Class_ID,
                        }).FirstOrDefault <BCategory>(),
                        User = (from u in db.User
                                where u.User_ID == bpss.Pdt.User_ID
                                select new BUser
                        {
                            ID = u.User_ID,
                            Mall_Name = u.Mall_Name,
                            Mall_ID = u.Mall_ID,
                        }).FirstOrDefault <BUser>()
                    };

                    if (paging)
                    {
                        products = bps.OrderBy(a => a.ID).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList <BProduct>();
                    }
                    else
                    {
                        products = bps.OrderBy(a => a.ID).ToList <BProduct>();
                    }
                }

                List <BProduct>         childProducts = null;
                List <BProductProperty> properties    = null;
                if (includeProps)
                {
                    int[] parent_ids       = (from p in products select p.ID).ToArray <int>();
                    var   tmpchildProducts = from p in db.Product
                                             where parent_ids.Contains(p.Parent_ID)
                                             select new BProduct
                    {
                        ID       = p.Product_ID,
                        Title    = p.Name,
                        ParentID = p.Parent_ID
                    };

                    childProducts = tmpchildProducts.ToList <BProduct>();
                    int[] child_product_ids = (from c in childProducts select c.ID).ToArray <int>();
                    properties = (from pv in db.Product_Specifications
                                  join prop in db.Product_Spec on pv.Product_Spec_ID equals prop.Product_Spec_ID into LProp
                                  from l_prop in LProp.DefaultIfEmpty()
                                  join propV in db.Product_Spec_Value on pv.Product_Spec_Value_ID equals propV.Product_Spec_Value_ID into LPropv
                                  from l_propv in LPropv.DefaultIfEmpty()
                                  where child_product_ids.Contains(pv.Product_ID)
                                  select new BProductProperty
                    {
                        PID = pv.Product_Spec_ID,
                        PName = l_prop.Name,
                        ProductID = pv.Product_ID,
                        PValue = l_propv.Name,
                        PVID = pv.Product_Spec_Value_ID
                    }).ToList <BProductProperty>();
                }

                List <BProductSupplier> bsuppliers = new List <BProductSupplier>();

                if (includeSupplier)
                {
                    int[] parent_ids = (from p in products select p.ID).ToArray <int>();
                    bsuppliers = (from s in db.Product_Supplier
                                  join supplier in db.Supplier on s.Supplier_ID equals supplier.Supplier_ID into LSupplier
                                  from l_supplier in LSupplier.DefaultIfEmpty()
                                  where parent_ids.Contains(s.Product_ID)
                                  select new BProductSupplier
                    {
                        Supplier = new BSupplier {
                            ID = s.Supplier_ID, Name = l_supplier.Name
                        },
                        Product = new BProduct {
                            ID = s.Product_ID
                        }
                    }).ToList <BProductSupplier>();
                }

                foreach (BProduct product in products)
                {
                    if (product.Shop.Shop_ID == this.Main_Shop.Shop_ID)
                    {
                        product.FromMainShop = true;
                    }
                    else if (childshop_ids != null && childshop_ids.Length > 0 && childshop_ids.Contains(product.Shop.Shop_ID))
                    {
                        product.FromChildShop = true;
                    }

                    if (includeProps)
                    {
                        List <BProduct> children = (from c in childProducts where c.ParentID == product.ID select c).ToList <BProduct>();
                        if (children.Count > 0)
                        {
                            product.Children = new List <BProduct>();
                            foreach (BProduct child in children)
                            {
                                child.Properties = (from prop in properties where prop.ProductID == child.ID select prop).ToList <BProductProperty>();
                                product.Children.Add(child);
                            }
                        }
                    }

                    if (includeSupplier)
                    {
                        product.Suppliers = (from ps in bsuppliers where ps.Product.ID == product.ID select new Supplier {
                            Supplier_ID = ps.Supplier.ID, Name = ps.Supplier.Name
                        }).ToList <Supplier>();
                    }
                }
            }

            return(products);
        }