public bool ValiActivePro(int aid, int pid, string attr, int qty, ref string msg) { DateTime now = DateTime.Now; DAO.Active a = db.Active.Where(m => m.ID == aid && m.StarDate <= now && now <= m.EndDate && m.Status == "1").FirstOrDefault(); if (a != null) { DAO.ActivePros p = db.ActivePros.Where(m => m.ProID == pid && m.ActiveID == aid).FirstOrDefault(); if (p != null) { if (string.IsNullOrEmpty(attr)) { if (p.Stock < qty) { msg = "活动产品:" + p.ProName + "库存数量不足!"; return(false); } else { return(true); } } else { int attrID = int.Parse(attr); DAO.ActiveAttr at = db.ActiveAttr.Where(m => m.ActiveID == aid && m.AProID == pid && m.AtrrID == attrID).FirstOrDefault(); if (at != null) { if (at.Stock < qty) { msg = "活动产品:" + p.ProName + "该款库存数量不足!"; return(false); } else { return(true); } } else { msg = "活动产品:" + p.ProName + "属性错误!"; return(false); } } } else { msg = "活动产品不存在"; return(false); } } else { msg = "活动不存在或已过期"; return(false); } //&& m.StarDate<= now && now<=m.EndDate &&m.Status=="1" }
/// <summary> /// 获取购物车数据 /// </summary> /// <param name="id"></param> /// <param name="AttID"></param> /// <returns></returns> public CarProductDetail GetProDetail(int id, int AttID, string atID = "-1") { CarProductDetail proDetail = new CarProductDetail(); string sql = "select a.ID,a.CategoryID,a.PartName,a.PartModel,a.PartSuppyNo,a.Price,b.BrandName from Parts a left join PartBrand b on a.PartBrand=b.ID where a.ID={0} "; CarProDetail model = db.Database.SqlQuery <CarProDetail>(string.Format(sql, id)).FirstOrDefault(); if (model != null) { string imgSql = " select * from ImgStock where PartID={0} "; DAO.ImgStock img = db.Database.SqlQuery <DAO.ImgStock>(string.Format(imgSql, id)).FirstOrDefault(); proDetail.imgStock = img; string CSql = " select * from PartsCategory where ID={0} and IsShow=1 "; DAO.PartsCategory pc = db.Database.SqlQuery <DAO.PartsCategory>(string.Format(CSql, model.CategoryID)).FirstOrDefault(); proDetail.partCate = pc; PartExtendBll extBll = new PartExtendBll(); List <DAO.PartsExtend> att = extBll.GetCarItems(id, AttID); proDetail.partExt = att; if (att.Count > 0) { if (atID != "-1" && atID != null) { int aid = int.Parse(atID); DAO.ActiveAttr a = db.ActiveAttr.Where(o => o.AProID == id && o.AtrrID == AttID && o.ActiveID == aid).FirstOrDefault(); if (a != null) { model.Price = a.NewPrice; proDetail.activeM = db.Active.Where(o => o.ID == aid).FirstOrDefault(); } } else { model.Price = att.Last().AttrPrice; } } else { if (atID != "-1" && atID != null) { int aid = int.Parse(atID); DAO.ActivePros p = db.ActivePros.Where(o => o.ActiveID == aid && o.ProID == id).FirstOrDefault(); if (p != null) { model.Price = p.NewPrice; proDetail.activeM = db.Active.Where(o => o.ID == aid).FirstOrDefault(); } } } proDetail.proDetail = model; return(proDetail); } else { return(null); } }
public bool addActivePro(DAO.ActivePros m) { DAO.ActivePros a = db.ActivePros.Where(b => b.ActiveID == m.ActiveID && b.ProID == m.ProID).FirstOrDefault(); if (a == null) { db.ActivePros.Add(m); } else { a.NewPrice = m.NewPrice; db.Entry(a).State = System.Data.EntityState.Modified; } int i = db.SaveChanges(); if (i > 0) { return(true); } else { return(false); } }
/// <summary> /// 订单价格校验 /// </summary> /// <param name="shopList"></param> /// <param name="oAmount"></param> /// <returns></returns> public bool OrderAmountCheck(List <Shop> shopList, decimal oAmount, decimal ratio, out decimal shopListTotle) { shopListTotle = 0; decimal normTotle = 0; decimal ActTotle = 0; PartExtendBll pbll = new PartExtendBll(); ProductBll proBll = new ProductBll(); foreach (Shop item in shopList) { var qty = 0; if (int.TryParse(item.Qty, out qty)) { //产品 DAO.Parts product = proBll.GetPartModel(item.ID); //先检查产品是否有属性,是否是最后一个属性 if (!string.IsNullOrEmpty(item.Attrs)) { //先检查是否是最终属性,没有子属性 DAO.PartsExtend childAttr = pbll.GetChildAttrModel(item.ID, item.Attrs); if (childAttr == null) { //没有子属性为有效的属性 DAO.PartsExtend currAttr = pbll.GetPartAttrModel(item.ID, item.Attrs); if (currAttr == null) { //属性没有效 return(false); } else { if (item.Type != "-1") { int aid = int.Parse(item.Type); int pid = int.Parse(item.ID); int tid = int.Parse(item.Attrs); DAO.ActiveAttr att = db.ActiveAttr.Where(m => m.ActiveID == aid && m.AProID == pid && m.AtrrID == tid).FirstOrDefault(); if (att != null) { ActTotle += qty * att.NewPrice; } else { normTotle += qty * currAttr.AttrPrice; } } else { normTotle += qty * currAttr.AttrPrice; } } } else { //不是最终属性 错误 return(false); } } else { //没有属性 if (item.Type != "-1") { int aid = int.Parse(item.Type); int pid = int.Parse(item.ID); DAO.ActivePros pro = db.ActivePros.Where(m => m.ActiveID == aid && m.ProID == pid).FirstOrDefault(); if (pro != null) { ActTotle += qty * pro.NewPrice; } else { normTotle += qty * product.Price; } } else { //没有活动 normTotle += qty * product.Price; } } } else { //数量不是数字 return(false); } } //获取会员等级折扣 shopListTotle = Math.Round(ActTotle + Math.Round(normTotle * 1, 2), 2); if (shopListTotle == oAmount) { //价格验证成功 return(true); } else { //价格验证失败 return(false); } }