public bool Save(productprice p) { using (var scope = new PetaPoco.Transaction(_db)) { if (string.IsNullOrEmpty(p.ID)) {//新增 p.ID = Guid.NewGuid().ToString(); _db.Insert(p); } else {//编辑 var old = _db.FirstOrDefault <productprice>("where id=@0", p.ID); var model = new oldprice(); model.ID = Guid.NewGuid().ToString(); model.PriceID = old.ID; model.LimitNum = old.LimitNum; model.Price = old.Price; model.MemberPrice = old.MemberPrice; model.StaffName = p.StaffName; model.CreatDate = DateTime.Now; model.ProductName = ""; model.ProductID = old.ProductID; _db.Update(p); _db.Insert(model); } scope.Complete(); return(true); } }
public ApiMessage<bool> CloseOrder(string orderNo) { var api = new ApiMessage<bool>(); api.Msg = "数据有误"; api.Success = false; using (var tran = new PetaPoco.Transaction(_db)) { var model = _db.FirstOrDefault<order>("where OrderNo =@0", orderNo); if (model.State != "待付款") return api; model.State = "已关闭"; var orderd = _db.Query<orderdetail>("where OrderNo=@0", model.OrderNo); orderd = JsonConvert.DeserializeObject<List<orderdetail>>(JsonConvert.SerializeObject(orderd)); foreach (var d in orderd) { var storeModel = _db.FirstOrDefault<store>("where ProductID=@0 and UnitID=@1", d.ProductID, d.UnitID); storeModel.Amount += d.Amount; storeModel.LuckAmount -= d.Amount; storeModel.UpdateDate = DateTime.Now; _db.Update(storeModel); } var sign = _db.Update(model); tran.Complete(); if (sign > 0) return new ApiMessage<bool>(); else return api; } }
public ApiMessage <string> Save(instore model) { var api = new ApiMessage <string>(); model.UnitName = model.UnitID; model.ID = Guid.NewGuid().ToString(); using (var scope = new PetaPoco.Transaction(_db)) { var sModel = _db.FirstOrDefault <store>("where ProductID=@ProductID AND UnitID=@UnitID", model); if (sModel == null) { sModel = new store(); sModel.Amount = model.Amount; sModel.ProductID = model.ProductID; sModel.ProductName = model.ProductName; sModel.UnitID = model.UnitID; sModel.UnitName = model.UnitID; sModel.UpdateDate = DateTime.Now; sModel.CreateDate = DateTime.Now; sModel.ID = Guid.NewGuid().ToString(); sModel.OutAmount = 0; sModel.OutAmount = 0; _db.Insert(sModel); } else { sModel.Amount = sModel.Amount + model.Amount; _db.Update(sModel); } _db.Insert(model); scope.Complete(); } return(api); }
public ApiMessage <ProductEx> Get(string id) { var json = new ApiMessage <ProductEx>(); var m = _db.FirstOrDefault <ProductEx>(" where id=@0", id); if (m == null) { json.Success = false; json.Msg = "不存在"; return(json); } var imgs = productimg.Fetch("where ProductID=@0", m.ID).ToList(); m.Imgs = imgs?.Select(n => new ProImg { url = n.Url })?.ToList(); json.Data = m; return(json); }
public Page <swiper> List(BaseParm parm) { var page = new Page <swiper>(parm); var strSql = new StringBuilder(); strSql.Append(" where 1=1"); if (!string.IsNullOrEmpty(parm.Name)) { parm.Name = "%" + parm.Name + "%"; strSql.Append(" AND ProductName like @Name"); } strSql.Append(" order by CreateDate Desc"); page.rows = swiper.Fetch(strSql.ToString(), parm) .Take(parm.rows) .Skip((parm.page - 1) * parm.rows) .ToList(); page.total = _db.FirstOrDefault <int>("select count(1) from Swiper " + strSql, parm); return(page); }