/// <summary> /// 商品详情页 /// </summary> /// <param name="goodsId">商品id</param> /// <param name="usersId">用户id</param> /// <returns></returns> public IActionResult Index2(int goodsId, int usersId) { ViewBag.usersId = tmpUser1.Id; goodsId = goodsId == 0 ? 1 : goodsId; ApiHelper apiHelper = new ApiHelper(); string str = apiHelper.GetApiResult("get", $"Goodscollect/GetGoodscollectDto?id={tmpUser1.Id}&goodsId=" + goodsId, null); GoodscollectDto GoodscollectDto = JsonConvert.DeserializeObject <GoodscollectDto>(str); ViewBag.goods = GoodscollectDto.Goods; ViewBag.imgs = GoodscollectDto.Imgs; ViewBag.conllect = GoodscollectDto.Conllect; return(View()); }
/// <summary> /// 商品详情页显示 /// </summary> /// <param name="id">用户id</param> /// <param name="goodsId">商品Id</param> /// <returns></returns> public GoodscollectDto GetGoodscollectDto(int id, int goodsId) { GoodscollectDto goodscollectDto = new GoodscollectDto(); //是否收藏 string sql1 = $"select count(1) from collection where GoodsId={goodsId} and UsersId={id}"; //根据商品Id查询该商品的图片 string sql2 = $"select pictureUrl from picture where GoodsId={goodsId} "; string sql3 = $@"select goods.*,Aroma.AromaName,place.PlaceName,brand.BrandName from goods join price on goods.Id = price.Goodsid join Aroma ON Aroma.GoodsId = goods.Id join Place on Place.GoodsId = goods.Id join brand on brand.GoodsId = goods.Id where goods.id={goodsId} "; using (MySqlConnection con = new MySqlConnection(connStr)) { goodscollectDto.Conllect = con.ExecuteScalar <int>(sql1); goodscollectDto.Imgs = con.Query <img>(sql2).ToList(); goodscollectDto.Goods = con.QueryFirst <GoodsDto1>(sql3); } return(goodscollectDto); }