public Response <string> AccountCart(int memberId, List <Cart> carts) { var res = new Response <string>(); try { var orderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff"); ordersDao.Insert(new Orders { MemberId = memberId, OrderNo = orderNo, Enabled = 0, OrderTime = DateTime.Now, TotalQty = carts.Count + carts.Sum(t => string.IsNullOrEmpty(t.GiftIds) ? 0 : t.GiftIds.Split(',').Length), TotalAmount = carts.Sum(t => t.Price * t.Number) }, "MemberId", "OrderNo", "Enabled", "OrderTime", "TotalQty", "TotalAmount"); int id = ordersDao.GetModels(" OrderNo=@0 ", orderNo).First().OrderId; var details = new List <OrderDetail>(); carts.ForEach(b => { for (var j = 0; j < b.Number; j++) { details.Add(new OrderDetail { CardId = b.CardId, OrderId = id, Qty = 1, Amount = b.Price, AssignNum = 0, IsAssign = 0 }); if (!string.IsNullOrEmpty(b.GiftIds)) { foreach (var t in b.GiftIds.Split(',')) { details.Add(new OrderDetail { CardId = int.Parse(t), OrderId = id, Qty = 1, Amount = 0, AssignNum = 0, IsAssign = 0 }); } } } }); detailDao.BatchInsert(details, "Qty", "CardId", "OrderId", "Amount", "AssignNum", "IsAssign"); cartDao.BatchDelete(carts.Select(t => new MemberCart() { CartId = t.Id }).ToList(), "CartId"); res.Result = orderNo; } catch (Exception ex) { res.ErrMsg = "结算失败!" + ex.Message; } return(res); }