/// <summary> /// /// </summary> /// <param name="parm"></param> /// <param name="msgType">1 add 0 del</param> /// <returns></returns> public ApiMessage <bool> Add(cart parm) { var api = new ApiMessage <bool>(); var list = _db.Query <cart>(@"SELECT * FROM Cart WHERE UserID=@UserID AND ProductID=@ProductID", parm).ToList(); if (list.Any()) { var node = list.FirstOrDefault(); if (parm.Amount == 0) { node.Delete(); } else { node.Amount = parm.Amount; node.CreatDate = DateTime.Now; node.Update(); } } else { parm.CreatDate = DateTime.Now; parm.ID = Guid.NewGuid().ToString(); parm.Insert(); } api.Msg = "添加成功"; return(api); }
public ApiMessage <bool> Exists(favorite parm) { var msg = _db.Query <favorite> (@"SELECT * FROM FAVORITE WHERE UserID=@UserID AND ProductID=@ProductID", parm); var api = new ApiMessage <bool>() { Data = msg.Any() }; return(api); }
public List<CartEx> GetPrice(List<PriceEx> p) { var list = _db.Query<CartEx>( @"SELECT p1.ProductID,p1.Price,p1.MemberPrice MPrice,p1.UnitName,p2.ID UnitID,p.Name ProductName,0 Amount,p3.Url FROM product p LEFT JOIN productprice p1 ON p.ID=p1.ProductID LEFT JOIN (SELECT * FROM productimg n WHERE n.RowNO=0) p3 ON p3.ProductID=p.ID LEFT JOIN productunit p2 ON p1.UnitID = p2.ID WHERE p.ID in (@0) AND p2.ID in (@1) AND p.IsActive=1", p.Select(n => n.ProductID), p.Select(n => n.UnitID)).ToList(); return list; }
public ApiMessage <swiper> Get(string id) { var api = new ApiMessage <swiper>(); api.Data = _db.Query <swiper>(@"select * from swiper where id=@id", new { id }).FirstOrDefault(); return(api); }
public ApiMessage <List <Goods> > GetLikeGoods(string userId) { var ids = _db.Query <string>(@"SELECT o.ProductID FROM orderdetail o LEFT JOIN `order` o1 ON o.OrderNo = o1.OrderNo WHERE o1.UserID=@0 GROUP BY o.ProductID ORDER BY SUM(o.Amount) DESC", userId); var page = new ApiMessage <List <Goods> >(); var list = _db.Fetch <Goods>( @"SELECT p.ID,p.`Name` title,p.ImgUrl image,p.ImgUrl2 image2,p.ImgUrl3 image3,p.Sales sales,MIN(p1.Price) price FROM product p LEFT JOIN price p1 ON p.ID = p1.ProductID WHERE p1.Price>0 AND p.IsActive=1 AND p.ID IN (@0) GROUP BY p.ID LIMIT 0,10", ids); page.Data = list; return(page); }