Exemplo n.º 1
0
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return Redirect("/Home/Error?message="+HttpUtility.UrlEncode("请输入正确的产品ID"));
            }

            int product_id = 0;
            int.TryParse(id, out product_id);
            if (product_id == 0)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的产品ID"));
            }
            BProduct product = null;
            string user_id = HttpContext.User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            Shop MainShop = userMgr.Main_Shop;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                product = pdtManager.GetProductFullInfo(product_id);
            }
            catch (KMJXCException kex)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode(kex.Message));
            }
            catch
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("未知错误"));
            }
            return View(product);
        }
Exemplo n.º 2
0
        public ApiMessage BatchEditCategory()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            ApiMessage message = new ApiMessage();
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            string products=request["products"];
            if (string.IsNullOrEmpty(products))
            {
                message.Status = "failed";
                message.Message = "没有选择产品,不能批量编辑类目";
                return message;
            }

            int[] product_ids = base.ConvertToIntArrar(products);
            int category = 0;
            int.TryParse(request["category"],out category);
            try
            {
                bool ret = pdtManager.BatchUpdateCategory(category, product_ids);
                if (ret)
                {
                    message.Status = "ok";
                }
            }
            catch (KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "未知错误";
            }
            return message;
        }
Exemplo n.º 3
0
        public ApiMessage UpdateProduct()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            ApiMessage message = new ApiMessage();
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int product_id = 0;
            int categoryId = 0;
            string description = "";
            string props = "";
            string images = "";
            string title = "";
            int.TryParse(request["cid"], out categoryId);
            int.TryParse(request["product_id"],out product_id);
            description = request["desc"];
            title = request["title"];
            images = request["images"];
            props = request["props"];
            string suppliers = request["sids"];
            try
            {
                BProduct product = new BProduct();
                product.ID = product_id;
                product.Parent = null;
                product.Category = new BCategory() { ID = categoryId };
                product.Title = title;
                product.Description = description;
                product.Properties = null;
                product.FileRootPath = request.PhysicalApplicationPath;
                if (!string.IsNullOrEmpty(images))
                {
                    product.Images = new List<Image>();
                    string[] ims = images.Split(',');
                    foreach (string img in ims)
                    {
                        int image_id = 0;
                        int.TryParse(img,out image_id);
                        if (image_id > 0)
                        {
                            product.Images.Add(new Image() { ID = image_id });
                        }
                    }
                }

                if (!string.IsNullOrEmpty(suppliers))
                {
                    product.Suppliers = new List<Supplier>();
                    string[] sids = suppliers.Split(',');
                    foreach (string sid in sids)
                    {
                        product.Suppliers.Add(new Supplier() { Supplier_ID = int.Parse(sid), Enabled = true });
                    }
                }

                if (!string.IsNullOrEmpty(props))
                {
                    if (product.Children == null)
                    {
                        product.Children = new List<BProduct>();
                    }
                    string[] groups = props.Split(';');
                    foreach (string group in groups)
                    {
                        string groupp = group.Split('|')[1];
                        int pdtId = int.Parse(group.Split('|')[0]);
                        BProduct child = new BProduct();
                        child.ID = pdtId;
                        child.Title = product.Title;
                        child.Description = product.Description;
                        child.Category = product.Category;
                        List<BProductProperty> properties = new List<BProductProperty>();
                        string[] pops = groupp.Split(',');
                        foreach (string pop in pops)
                        {
                            BProductProperty prop = new BProductProperty();
                            prop.PID = int.Parse(pop.Split(':')[0]);
                            prop.PVID = int.Parse(pop.Split(':')[1]);
                            properties.Add(prop);
                        }
                        child.Properties = properties;
                        product.Children.Add(child);
                    }
                }

                pdtManager.UpdateProduct(ref product);
                message.Status = "ok";
                message.Item = product;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            return message;
        }
Exemplo n.º 4
0
        public PQGridData SearchProducts()
        {
            PQGridData data = new PQGridData();
            int page = 0;
            int pageSize = 30;
            int total = 0;
            int? category_id = null;
            string keyword = "";
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int.TryParse(request["page"],out page);
            int.TryParse(request["pageSize"],out pageSize);

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

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

            if (request["cid"] != null && request["cid"].ToString() != "" && request["cid"].ToString()!="0")
            {
                int cid = 0;
                int.TryParse(request["cid"],out cid);
                if (cid > 0) {
                    category_id = cid;
                }
            }
            keyword = request["keyword"];
            int[] sids = null;
            string suppliers = request["suppliers"];
            if (!string.IsNullOrEmpty(suppliers))
            {
                string[] ss = suppliers.Split(',');
                sids = new int[ss.Length];
                for (int i = 0; i < ss.Length; i++)
                {
                    sids[i] = int.Parse(ss[i]);
                }
            }
            bool includeProps = false;
            if (!string.IsNullOrEmpty(request["include_prop"]) && request["include_prop"] == "1")
            {
                includeProps = true;
            }
            else
            {
                includeProps = false;
            }

            int[] product_ids = null;
            if (!string.IsNullOrEmpty(request["product_ids"]))
            {
                product_ids = base.ConvertToIntArrar(request["product_ids"]);
            }

            bool paging = true;

            if (!string.IsNullOrEmpty(request["paging"]) && request["paging"]=="0")
            {
                paging=false;
            }

            bool includeSupplier = false;
            if (!string.IsNullOrEmpty(request["include_supplier"]) && request["include_supplier"] == "1")
            {
                includeSupplier = true;
            }
            else
            {
                includeSupplier = false;
            }
            data.data = pdtManager.SearchProducts(product_ids, sids, keyword, "", 0, 0, category_id, page, pageSize, out total, includeProps, paging, includeSupplier);
            data.totalRecords = total;
            data.curPage = page;
            data.pageSize = pageSize;
            return data;
        }
Exemplo n.º 5
0
        public ApiMessage GetProductProperties()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            List<BProduct> properties = new List<BProduct>();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int product_id = 0;
            int.TryParse(request["product_id"], out product_id);

            try
            {
                properties = pdtManager.GetProductProperties(product_id);
                if (properties != null)
                {
                    message.Item = properties;
                }
                else
                {
                    message.Status = "ok";
                }
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "未知错误";
            }

            return message;
        }
Exemplo n.º 6
0
        public ApiMessage MapMallProductSku()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            ShopManager shopManager = new ShopManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission, userMgr);
            ProductManager pdtManager = new ProductManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                string skuId = request["sku_id"];
                int product_id;
                int.TryParse(request["product_id"], out product_id);

                bool result = shopManager.MapSku(skuId, product_id);
                if (!result)
                {
                    message.Status = "failed";
                    message.Message = "未知错误,请联系客服";
                }
            }
            catch (KMJXCException kex)
            {
                message.Message = kex.Message;
                message.Status = "failed";
            }
            catch (Exception ex)
            {
                message.Message = ex.Message;
                message.Status = "failed";
            }
            finally
            {

            }
            return message;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="shop_id"></param>
        /// <param name="user_id"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecords"></param>
        /// <returns></returns>
        public List<BBuy> SearchBuys(int[] buyids, int[] order_ids, int[] user_ids, int[] supplier_ids, int[] product_ids, int startTime, int endTime, int pageIndex, int pageSize, out int totalRecords,bool getFullProductInfo=false)
        {
            List<KM.JXC.BL.Models.BBuy> verifications = new List<Models.BBuy>();
            totalRecords = 0;
            ProductManager pdtManager=new ProductManager(this.CurrentUser,this.Shop,this.CurrentUserPermission);
            if (pageIndex <= 0)
            {
                pageIndex = 1;
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var vbo = from vb in db.Buy
                          //where vb.Shop_ID == this.Shop.Shop_ID || vb.Shop_ID==this.Main_Shop.Shop_ID
                          select vb;

                int[] spids = (from sp in this.DBChildShops select sp.Shop_ID).ToArray<int>();
                if (spids != null && spids.Length > 0)
                {
                    vbo = vbo.Where(o => (o.Shop_ID == this.Shop.Shop_ID || spids.Contains(o.Shop_ID)));
                }
                else
                {
                    vbo = vbo.Where(o => (o.Shop_ID == this.Shop.Shop_ID));
                }

                if (user_ids != null && user_ids.Length>0)
                {
                    vbo = vbo.Where(vb1 => user_ids.Contains(vb1.User_ID));
                }

                if (startTime > 0)
                {
                    vbo = vbo.Where(vb1 => vb1.Create_Date >= startTime);
                }

                if (order_ids != null && order_ids.Length > 0)
                {
                    int[] buyIds=(from bu in db.Buy where order_ids.Contains(bu.Buy_Order_ID) select bu.Buy_ID).ToArray<int>();
                    if (buyIds != null && buyIds.Length > 0)
                    {
                        vbo = vbo.Where(vb1 => buyIds.Contains(vb1.Buy_ID));
                    }
                }

                if (endTime > 0)
                {
                    vbo = vbo.Where(vb1 => vb1.Create_Date <= endTime);
                }

                if (buyids != null && buyids.Length > 0)
                {
                    vbo = vbo.Where(vb1 => buyids.Contains(vb1.Buy_ID));
                }

                totalRecords = vbo.Count();
                if (totalRecords > 0)
                {
                    var vboo = from vbb in vbo
                               join border in db.Buy_Order on vbb.Buy_Order_ID equals border.Buy_Order_ID into LBorder
                               from l_border in LBorder.DefaultIfEmpty()
                               select new BBuy
                               {
                                   ID = vbb.Buy_ID,
                                   Status = (int)vbb.Status,
                                   Order = l_border != null ? new BBuyOrder { ID = l_border.Buy_Order_ID } : new BBuyOrder { ID = 0 },
                                   ComeDate = (int)vbb.Come_Date,
                                   Description = vbb.Description,
                                   Created = (int)vbb.Create_Date,
                                   User = (from u in db.User
                                           where u.User_ID == vbb.User_ID
                                           select new BUser
                                           {
                                               ID = u.User_ID,
                                               //EmployeeInfo = (from e in db.Employee where e.User_ID == u.User_ID select e).ToList<Employee>()[0],
                                               Mall_ID = u.Mall_ID,
                                               Mall_Name = u.Mall_Name,
                                               Parent_ID = (int)u.Parent_User_ID,
                                               Name = u.Name,
                                               Password = u.Password,
                                               //Type = (from t in db.Mall_Type where t.Mall_Type_ID == u.Mall_Type select t).ToList<Mall_Type>()[0]
                                           }).FirstOrDefault<BUser>(),
                                   Shop = (from sp in db.Shop
                                           where sp.Shop_ID == vbb.Shop_ID
                                           select new BShop
                                           {
                                               ID = sp.Shop_ID,
                                               Title = sp.Name
                                           }).FirstOrDefault<BShop>()
                               };
                    vboo = vboo.OrderBy(b => b.ID).Skip((pageIndex - 1) * pageSize).Take(pageSize);
                    verifications = vboo.ToList<BBuy>();
                    int[] orderIds;
                    orderIds = (from verify in verifications select verify.Order.ID).ToArray<int>();
                    if (orderIds != null && orderIds.Length > 0)
                    {
                        foreach (BBuy b in verifications)
                        {
                            b.Details = (from bd in db.Buy_Detail
                                         where bd.Buy_ID == b.ID
                                         select new BBuyDetail
                                         {
                                             Buy_Order_ID = b.Order.ID,
                                             CreateDate = bd.Create_Date,
                                             Price = bd.Price,
                                             Quantity = bd.Quantity,
                                             ProductId = bd.Product_ID,
                                             Product = (from pdt in db.Product
                                                        where pdt.Product_ID == bd.Product_ID
                                                        select new BProduct
                                                        {
                                                            ID = pdt.Product_ID,
                                                            Title = pdt.Name,
                                                        }).FirstOrDefault<BProduct>()
                                         }).ToList<BBuyDetail>();

                            if (b.Shop.ID == this.Main_Shop.Shop_ID)
                            {
                                b.FromMainShop = true;
                            }
                            else if (spids != null && spids.Contains(b.Shop.ID))
                            {
                                b.FromChildShop = true;
                            }
                        }
                    }
                }
            }

            return verifications;
        }