public ActionResult Index(int?page)
        {
            ShopBusinessLogic.LoginMember    loginMember = new ShopBusinessLogic.LoginMember();
            ShopBusinessLogic.SellerSell     sellerSell  = new ShopBusinessLogic.SellerSell();
            ShopBusinessLogic.MemberPurchase purchase    = new ShopBusinessLogic.MemberPurchase();
            if (Session["mem_phone"] == null)
            {
                return(Redirect("/Login"));
            }
            if (Session["mem_phone"] != null && Convert.ToInt32(Session["mem_type"]) == 1)
            {
                return(Redirect("/SignUp/Seller"));
            }
            string now_goods_id     = this.Request.QueryString["goods_id"];
            int    now_goods_id_int = Convert.ToInt32(now_goods_id);

            if (now_goods_id == null || !sellerSell.isInGoodsList(now_goods_id_int))
            {
                return(Redirect("/Error"));
            }
            string phone        = Session["mem_phone"].ToString();
            var    now_goods    = sellerSell.getSellGoods(phone, now_goods_id_int);
            var    now_img_list = purchase.getGoodsImgs(now_goods_id_int).Select(img_info => new GoodsImgView()
            {
                img_path = img_info.img_path,
            }).ToList();
            var tag_list = purchase.getAllTags().Select(tag => new GoodsTag()
            {
                goods_tag = tag.tag,
            }).ToList();
            var sell_list = sellerSell.getPerGoodsSellList(phone, now_goods_id_int).Select(p_list => new MemberPurchaseListViewModel()
            {
                plist_id    = p_list.plist_id,
                goods_num   = p_list.goods_num,
                mem_phone   = p_list.mem_phone,
                mem_name    = loginMember.GetMemberByPhone(p_list.mem_phone).mem_name,
                unit_price  = p_list.unit_price,
                total_price = p_list.total_price,
                date        = p_list.date,
                goods_name  = p_list.goods_name,
            }).ToList();
            int pageNumber = page ?? 1;
            int pageSize   = 10;
            var resView    = new SellGoodsViewModel()
            {
                goods_id             = now_goods_id_int,
                goods_detail         = now_goods.goods_details,
                goods_name           = now_goods.goods_name,
                goods_price          = now_goods.goods_price,
                goods_img_path       = now_goods.goods_img_path,
                goods_tag            = now_goods.goods_tag,
                sell_stock           = now_goods.goods_stock,
                sell_volume          = now_goods.goods_volume,
                img_list             = now_img_list,
                total_goods_tags     = tag_list,
                goods_page_sell_list = (PagedList <MemberPurchaseListViewModel>)sell_list.ToPagedList(pageNumber, pageSize),
            };

            return(Request.IsAjaxRequest() ? (ActionResult)PartialView("SellGoodsPart1", resView) : View(resView));
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            List <SellGoodsViewModel> sellGoodsViewModels = new List <SellGoodsViewModel>();
            // 分类列表
            var brandList = await _context.Brands.Where(b => !b.IsDelete).ToListAsync();

            // 所有商品
            var goodsList = await _context.Goods.Where(g => !g.IsDelete).ToListAsync();

            // 商品价格
            var priceList = await _context.GoodsPrices.Where(g => !g.IsDelete).ToListAsync();

            foreach (var item in brandList)
            {
                // 获取分类下的所有商品
                var sellGoods = goodsList.Where(g => g.BrandId == item.Id).Select(goods =>
                                                                                  new SellGoods
                {
                    Id        = goods.Id,
                    GoodsImg  = goods.GoodsImg,
                    GoodsCode = goods.GoodsCode,
                    GoodsName = goods.GoodsName,
                    GoodsSepc = goods.GoodsSepc,
                    GoodsUnit = goods.GoodsUnit
                }).ToList();

                if (sellGoods.Count > 0)
                {
                    var sellGoodsViewModel = new SellGoodsViewModel();
                    sellGoodsViewModel.Name = item.Name;
                    // 遍历商品,获取商品价格
                    foreach (var goods in sellGoods)
                    {
                        var goodsPrice = priceList.FirstOrDefault(p => p.GoodsId == goods.Id && p.ShopId == Sid && !p.IsDelete);
                        if (goodsPrice != null)
                        {
                            goods.Price = goodsPrice.Price;
                        }
                        else
                        {
                            // 取商品默认价格
                            goodsPrice = priceList.FirstOrDefault(p => p.GoodsId == goods.Id && p.ShopId == 0);
                            if (goodsPrice != null)
                            {
                                goods.Price = goodsPrice.Price;
                            }
                        }
                        sellGoodsViewModel.SellGoods = sellGoods;
                    }
                    sellGoodsViewModels.Add(sellGoodsViewModel);
                }
            }

            var res = new ResultModel();

            res.Code = 100;
            res.Data = sellGoodsViewModels;

            return(Json(res));
        }
        public ActionResult Index(SellGoodsViewModel sellGoodsViewModel)
        {
            string  phone        = Session["mem_phone"].ToString();
            int     goods_id     = sellGoodsViewModel.goods_id;
            string  goods_name   = sellGoodsViewModel.goods_name;
            decimal goods_price  = sellGoodsViewModel.goods_price;
            string  goods_detail = sellGoodsViewModel.goods_detail;
            string  goods_tag    = sellGoodsViewModel.goods_tag;
            int     sell_stock   = sellGoodsViewModel.sell_stock;

            if (goods_detail == null)
            {
                goods_detail = "暂无";
            }

            ShopBusinessLogic.SellerSell     sellerSell = new ShopBusinessLogic.SellerSell();
            ShopBusinessLogic.MemberPurchase purchase   = new ShopBusinessLogic.MemberPurchase();
            if (sellerSell.modifyGoods(phone, goods_id, goods_name, goods_tag, goods_price, goods_detail, sell_stock))
            {
                var now_goods = sellerSell.getSellGoods(phone, goods_id);
                var tag_list  = purchase.getAllTags().Select(tag => new GoodsTag()
                {
                    goods_tag = tag.tag,
                }).ToList();
                var now_img_list = purchase.getGoodsImgs(goods_id).Select(img_info => new GoodsImgView()
                {
                    img_path = img_info.img_path,
                }).ToList();
                var resView = new SellGoodsViewModel()
                {
                    goods_id         = goods_id,
                    goods_detail     = now_goods.goods_details,
                    goods_name       = now_goods.goods_name,
                    goods_price      = now_goods.goods_price,
                    goods_img_path   = now_goods.goods_img_path,
                    goods_tag        = now_goods.goods_tag,
                    sell_stock       = now_goods.goods_stock,
                    sell_volume      = now_goods.goods_volume,
                    img_list         = now_img_list,
                    total_goods_tags = tag_list,
                };
                return(Redirect("/SellGoods/?goods_id=" + goods_id.ToString()));
            }
            else
            {
                return(Redirect("/SellGoods/?goods_id=" + goods_id.ToString()));
            }
        }
        public ActionResult DeleteGoods(int deleteGoodsId)
        {
            string phone = Session["mem_phone"].ToString();

            ShopBusinessLogic.SellerSell     sellerSell = new ShopBusinessLogic.SellerSell();
            ShopBusinessLogic.MemberPurchase purchase   = new ShopBusinessLogic.MemberPurchase();

            sellerSell.deleteGoods(phone, deleteGoodsId);

            string nowpath = savepath + phone + @"\" + deleteGoodsId.ToString();

            if (Directory.Exists(nowpath))
            {
                Directory.Delete(nowpath, true);
            }

            var sell_goods_list = sellerSell.getAllSellGoods(phone).Select(goods_info => new SellGoodsViewModel()
            {
                goods_id       = goods_info.goods_id,
                goods_name     = goods_info.goods_name,
                goods_tag      = goods_info.goods_tag,
                goods_img_path = goods_info.goods_img_path,
                goods_price    = goods_info.goods_price,
                sell_stock     = goods_info.goods_stock,
                sell_volume    = goods_info.goods_volume,
            }).ToList();
            var tag_list = purchase.getAllTags().Select(tag => new GoodsTag()
            {
                goods_tag = tag.tag,
            }).ToList();
            var resView = new SellGoodsViewModel()
            {
                total_sell_goods = sell_goods_list,
                total_goods_tags = tag_list,
            };

            return(PartialView("SellHomePart1", resView));
        }
        // GET: SellHome
        public ActionResult Index()
        {
            if (Session["mem_phone"] == null)
            {
                return(Redirect("/Login"));
            }
            if (Session["mem_phone"] != null && Convert.ToInt32(Session["mem_type"]) == 1)
            {
                return(Redirect("/SignUp/Seller"));
            }
            string phone = Session["mem_phone"].ToString();

            ShopBusinessLogic.SellerSell     sellerSell = new ShopBusinessLogic.SellerSell();
            ShopBusinessLogic.MemberPurchase purchase   = new ShopBusinessLogic.MemberPurchase();
            var sell_goods_list = sellerSell.getAllSellGoods(phone).Select(goods_info => new SellGoodsViewModel()
            {
                goods_id       = goods_info.goods_id,
                goods_name     = goods_info.goods_name,
                goods_tag      = goods_info.goods_tag,
                goods_img_path = goods_info.goods_img_path,
                goods_price    = goods_info.goods_price,
                sell_stock     = goods_info.goods_stock,
                sell_volume    = goods_info.goods_volume,
            }).ToList();
            var tag_list = purchase.getAllTags().Select(tag => new GoodsTag()
            {
                goods_tag = tag.tag,
            }).ToList();
            var resView = new SellGoodsViewModel()
            {
                total_sell_goods = sell_goods_list,
                total_goods_tags = tag_list,
            };

            return(View(resView));
        }
        public ActionResult Index(SellGoodsViewModel sellGoodsViewModel)
        {
            ShopBusinessLogic.SellerSell     sellerSell = new ShopBusinessLogic.SellerSell();
            ShopBusinessLogic.MemberPurchase purchase   = new ShopBusinessLogic.MemberPurchase();


            string             phone        = Session["mem_phone"].ToString();
            int                add_goods_id = sellerSell.getAddGoodsId();
            string             nowpath      = savepath + phone + @"\" + add_goods_id.ToString() + @"\";
            HttpPostedFileBase fileBase     = Request.Files["image"];
            string             file_name    = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            string             img_path     = "";

            if (fileBase.ContentType == "image/jpeg" || fileBase.ContentType == "image/png")
            {
                if (int.Parse(fileBase.ContentLength.ToString()) > (4 * 1024 * 1024))
                {
                    return(Redirect("/SellHome"));
                }
                //图片存储路径
                if (!Directory.Exists(nowpath))
                {
                    Directory.CreateDirectory(nowpath);
                }
                fileBase.SaveAs(nowpath + file_name + ".jpg");
                img_path = "/content/image/" + phone + "/" + add_goods_id.ToString() + "/" + file_name + ".jpg";
            }


            string  goods_name     = sellGoodsViewModel.goods_name;
            decimal goods_price    = sellGoodsViewModel.goods_price;
            string  goods_detail   = sellGoodsViewModel.goods_detail;
            string  goods_tag      = sellGoodsViewModel.goods_tag;
            string  goods_img_path = img_path == ""?"暂无": img_path;
            int     sell_stock     = sellGoodsViewModel.sell_stock;

            if (goods_detail == null)
            {
                goods_detail = "暂无";
            }
            if (sellerSell.addGoods(phone, goods_name, goods_tag, Convert.ToDecimal(goods_price), goods_detail, sell_stock, goods_img_path))
            {
                var sell_goods_list = sellerSell.getAllSellGoods(phone).Select(goods_info => new SellGoodsViewModel()
                {
                    goods_id       = goods_info.goods_id,
                    goods_name     = goods_info.goods_name,
                    goods_tag      = goods_info.goods_tag,
                    goods_img_path = goods_info.goods_img_path,
                    goods_price    = goods_info.goods_price,
                    sell_stock     = goods_info.goods_stock,
                    sell_volume    = goods_info.goods_volume,
                }).ToList();
                var tag_list = purchase.getAllTags().Select(tag => new GoodsTag()
                {
                    goods_tag = tag.tag,
                }).ToList();
                var resView = new SellGoodsViewModel()
                {
                    total_sell_goods = sell_goods_list,
                    total_goods_tags = tag_list,
                };
                return(Redirect("/SellHome"));
            }
            else
            {
                return(Redirect("/SellHome"));
            }
        }