public ApiMessage<string> UpdateState(string orderNo, string trade_no) { var api = new ApiMessage<string>(); using (var tran = new PetaPoco.Transaction(_db)) { var model = order.FirstOrDefault("where orderno=@0", orderNo); if (model == null) return api; if (model.State != "待付款") return api; var orderd = orderdetail.Query("where orderno=@0", 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.OutAmount += d.Amount; storeModel.LuckAmount -= d.Amount; storeModel.UpdateDate = DateTime.Now; _db.Update(storeModel); } model.State = "待收货"; model.TradeNo = trade_no; model.Update(); var pointModel = new point(); pointModel.Money = model.Money; pointModel.ID = Guid.NewGuid().ToString(); pointModel.OrderNo = orderNo; pointModel.UserID = model.UserID; pointModel.Amount = (int)model.Money; var user = userinfo.FirstOrDefault("where id=@0", model.UserID); if (user.PointAmount.HasValue) { user.PointAmount += pointModel.Amount; } else { user.PointAmount = pointModel.Amount; } pointModel.Insert(); user.Update(); tran.Complete(); return api; } }