public IHttpActionResult FinshOrder2([FromBody] int orderId) { CsOrder order = _csOrderBll.GetModel(orderId); List <CsProducts> productList = _csProductsBll.GetModelList(""); var proList = _csOrderDetailBll.GetModelList(" and OrderId=" + orderId + " and ChoseType=1").Select(x => new { x.ProductId, ProductWeight = productList.FirstOrDefault(y => y.ProductId == x.ProductId).ProductWeight *x.ProductNumber }); decimal totalWeight = 0; foreach (var pro in proList) { totalWeight += pro.ProductWeight; } int number = _csOrderBll.FinshOrder(order.OrderId, order.UserId, totalWeight, order.OrderCopies); if (number > 0) { return(Json(new { status = true })); } else { return(Json(new { status = false })); } }
public bool Update(CsOrder model) { var strSql = new StringBuilder(); strSql.Append("UPDATE CrabShop.dbo.[CsOrder] SET "); strSql.Append("OrderNumber = @OrderNumber,UserId = @UserId,TotalMoney = @TotalMoney,DiscountMoney = @DiscountMoney,ActualMoney = @ActualMoney,OrderDate = @OrderDate,OrderState = @OrderState,OrderAddress = @OrderAddress,SendAddress = @SendAddress,OrderDelivery = @OrderDelivery,CargoNumber = @CargoNumber,OrderCopies = @OrderCopies,TotalWeight = @TotalWeight,BillWeight = @BillWeight,RowStatus = @RowStatus,DeleteDate = @DeleteDate,DeleteDescribe = @DeleteDescribe,PrepaymentId = @PrepaymentId,ExpressMoney = @ExpressMoney,ServiceMoney = @ServiceMoney,IsInvoice = @IsInvoice,OrderRemarks = @OrderRemarks"); strSql.Append(" WHERE OrderId = @OrderId"); return(DbClient.Excute(strSql.ToString(), model) > 0); }
public int Add(CsOrder model) { var strSql = new StringBuilder(); strSql.Append("INSERT INTO CrabShop.dbo.[CsOrder] ("); strSql.Append("OrderNumber,UserId,TotalMoney,DiscountMoney,ActualMoney,OrderDate,OrderState,OrderAddress,SendAddress,OrderDelivery,CargoNumber,OrderCopies,TotalWeight,BillWeight,RowStatus,DeleteDate,DeleteDescribe,PrepaymentId,ExpressMoney,ServiceMoney,IsInvoice,OrderRemarks"); strSql.Append(") VALUES ("); strSql.Append("@OrderNumber,@UserId,@TotalMoney,@DiscountMoney,@ActualMoney,@OrderDate,@OrderState,@OrderAddress,@SendAddress,@OrderDelivery,@CargoNumber,@OrderCopies,@TotalWeight,@BillWeight,@RowStatus,@DeleteDate,@DeleteDescribe,@PrepaymentId,@ExpressMoney,@ServiceMoney,@IsInvoice,@OrderRemarks);"); strSql.Append("SELECT @@IDENTITY"); return(DbClient.ExecuteScalar <int>(strSql.ToString(), model)); }
/// <summary> /// 修改预支付信息 /// </summary> /// <param name="order"></param> /// <returns></returns> public IHttpActionResult UpdatePrepaymentId(CsOrder order) { int number = _csOrderBll.UpdatePrepaymentId(order.OrderId, order.PrepaymentId); if (number > 0) { return(Json(new { status = true })); } else { return(Json(new { status = false })); } }
public IHttpActionResult UpdateOrderState(CsOrder order) { int number = _csOrderBll.UpdateOrderState(order.OrderId, order.OrderState); //int number = 0; if (number > 0) { return(Json(new { status = true })); } else { return(Json(new { status = false })); } }
public IHttpActionResult FinshOrder(CsOrder order) { int number = _csOrderBll.FinshOrder(order.OrderId, order.UserId, order.TotalWeight, order.OrderCopies); if (number > 0) { return(Json(new { status = true })); } else { return(Json(new { status = false })); } }
/// <summary> /// 带有事务操作 添加支付订单 /// </summary> /// <param name="order"></param> /// <returns></returns> public int AddOrder(OrderModel order, out string orderNumber) { var number = 0;//实际操作影响行数 using (var conn = (SqlConnection)DataSource.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted)) { try { orderNumber = DateTime.Now.ToString("yyyyMMddHHmmssffff"); //添加订单表 获取订单编号 var _csOrder = new CsOrder(); _csOrder.OrderNumber = orderNumber; _csOrder.UserId = order.userid; _csOrder.TotalMoney = order.totalmoney; _csOrder.DiscountMoney = 0; _csOrder.ActualMoney = order.finalPrice; _csOrder.OrderDate = DateTime.Now; _csOrder.OrderState = 1; _csOrder.OrderAddress = order.orderaddress; _csOrder.SendAddress = order.sendaddress; _csOrder.CargoNumber = 1; _csOrder.OrderCopies = order.totalnumber; _csOrder.TotalWeight = order.totalweight; _csOrder.BillWeight = order.sendweight; _csOrder.ExpressMoney = order.expressmoney; _csOrder.ServiceMoney = order.servicemoney; _csOrder.RowStatus = 1; _csOrder.IsInvoice = order.isInvoice ? 1 : 0; _csOrder.OrderRemarks = order.remarks; var strSql1 = new StringBuilder(); strSql1.Append("insert into CsOrder (OrderNumber,UserId,TotalMoney,DiscountMoney,ActualMoney,OrderDate,OrderState,OrderAddress,"); strSql1.Append("SendAddress,CargoNumber,OrderCopies,TotalWeight,BillWeight,RowStatus,ExpressMoney,ServiceMoney,IsInvoice,OrderRemarks ) values (@OrderNumber,"); strSql1.Append("@UserId,@TotalMoney,@DiscountMoney,@ActualMoney,@OrderDate,@OrderState,@OrderAddress,@SendAddress,@CargoNumber,@OrderCopies,"); strSql1.Append("@TotalWeight,@BillWeight,@RowStatus,@ExpressMoney,@ServiceMoney,@IsInvoice,@OrderRemarks);select @@Identity;"); SqlParameter[] parameter1 = { new SqlParameter("@OrderNumber", SqlDbType.VarChar, 50), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@TotalMoney", SqlDbType.Decimal, 18), new SqlParameter("@DiscountMoney", SqlDbType.Decimal, 18), new SqlParameter("@ActualMoney", SqlDbType.Decimal, 18), new SqlParameter("@OrderDate", SqlDbType.DateTime), new SqlParameter("@OrderState", SqlDbType.Int, 4), new SqlParameter("@OrderAddress", SqlDbType.NVarChar, 500), new SqlParameter("@SendAddress", SqlDbType.VarChar, 5000), new SqlParameter("@CargoNumber", SqlDbType.Int, 4), new SqlParameter("@OrderCopies", SqlDbType.Int, 4), new SqlParameter("@TotalWeight", SqlDbType.Decimal, 18), new SqlParameter("@BillWeight", SqlDbType.Decimal, 18), new SqlParameter("@RowStatus", SqlDbType.TinyInt, 4), new SqlParameter("@ExpressMoney", SqlDbType.Decimal, 18), new SqlParameter("@ServiceMoney", SqlDbType.Decimal, 18), new SqlParameter("@IsInvoice", SqlDbType.Int, 4), new SqlParameter("@OrderRemarks", SqlDbType.Text) }; parameter1[0].Value = _csOrder.OrderNumber; parameter1[1].Value = _csOrder.UserId; parameter1[2].Value = _csOrder.TotalMoney; parameter1[3].Value = _csOrder.DiscountMoney; parameter1[4].Value = _csOrder.ActualMoney; parameter1[5].Value = _csOrder.OrderDate; parameter1[6].Value = _csOrder.OrderState; parameter1[7].Value = _csOrder.OrderAddress; parameter1[8].Value = _csOrder.SendAddress; parameter1[9].Value = _csOrder.CargoNumber; parameter1[10].Value = _csOrder.OrderCopies; parameter1[11].Value = _csOrder.TotalWeight; parameter1[12].Value = _csOrder.BillWeight; parameter1[13].Value = _csOrder.RowStatus; parameter1[14].Value = _csOrder.ExpressMoney; parameter1[15].Value = _csOrder.ServiceMoney; parameter1[16].Value = _csOrder.IsInvoice; parameter1[17].Value = _csOrder.OrderRemarks; object obj = DbClient.ExecuteScalar(conn, trans, strSql1.ToString(), parameter1); if (obj != null) { int orderid = Convert.ToInt32(obj); int totalNumber = 0; //应总共操作记录影响行数 //decimal weight = 0; int carbNumber = 0; //总共购买螃蟹数 //添加购物详细 //购买螃蟹列表 List <CsOrderDetail> detailList = new List <CsOrderDetail>(); foreach (CartItem cart in order.cartFoodList) { CsOrderDetail orderDetail = new CsOrderDetail(); orderDetail.OrderId = orderid; orderDetail.ProductId = cart.id; orderDetail.UnitPrice = cart.price; orderDetail.ProductNumber = cart.num; orderDetail.TotalPrice = (cart.price * cart.weight * 2 * cart.num); orderDetail.ChoseType = 1; //weight += (cart.weight * cart.num); totalNumber++; carbNumber += cart.num; detailList.Add(orderDetail); } //购买可选配件列表 if (order.partNumList.Count > 0) { foreach (CartItem cart in order.partNumList) { if (cart.id == 0) { continue; } CsOrderDetail orderDetail = new CsOrderDetail(); orderDetail.OrderId = orderid; orderDetail.ProductId = cart.id; orderDetail.UnitPrice = cart.price; orderDetail.ProductNumber = cart.id == 10009 ? carbNumber : 1; orderDetail.TotalPrice = (cart.price * cart.num); orderDetail.ChoseType = 2; detailList.Add(orderDetail); totalNumber++; } } //购买必选配件列表 foreach (PartItem part in order.partList) { CsOrderDetail orderDetail = new CsOrderDetail(); orderDetail.OrderId = orderid; orderDetail.ProductId = part.PartId; orderDetail.UnitPrice = part.PartPrice; orderDetail.ProductNumber = part.PartId == 10004 ? carbNumber : 1; orderDetail.TotalPrice = (part.PartPrice * orderDetail.ProductNumber); orderDetail.ChoseType = 2; detailList.Add(orderDetail); totalNumber++; } foreach (CsOrderDetail detail in detailList) { StringBuilder strSql2 = new StringBuilder(); strSql2.Append("insert into CsOrderDetail (OrderId,ProductId,UnitPrice,ProductNumber,TotalPrice,ChoseType )"); strSql2.Append("values(@OrderId,@ProductId,@UnitPrice,@ProductNumber,@TotalPrice,@ChoseType)"); SqlParameter[] parameter2 = { new SqlParameter("@OrderId", SqlDbType.Int, 4), new SqlParameter("@ProductId", SqlDbType.Int, 4), new SqlParameter("@UnitPrice", SqlDbType.Money, 18), new SqlParameter("@ProductNumber", SqlDbType.Int), new SqlParameter("@TotalPrice", SqlDbType.Decimal, 18), new SqlParameter("@ChoseType", SqlDbType.Int, 4) }; parameter2[0].Value = detail.OrderId; parameter2[1].Value = detail.ProductId; parameter2[2].Value = detail.UnitPrice; parameter2[3].Value = detail.ProductNumber; parameter2[4].Value = detail.TotalPrice; parameter2[5].Value = detail.ChoseType; number += DbClient.ExecuteSql(conn, trans, strSql2.ToString(), parameter2); } if (number != totalNumber) { trans.Rollback(); return(0); } else { trans.Commit(); return(orderid); } } else { trans.Rollback(); return(0); } } catch (Exception ex) { LogHelper.Log(ex.ToJson(), "订单添加异常"); trans.Rollback(); orderNumber = ""; return(0); } } } }
/// <summary> /// 根据订单编号获取订单详情 /// </summary> /// <param name="orderId">订单编号</param> /// <returns></returns> public IHttpActionResult GetOrderInfoByOrderId(int id) { CsOrder order = _csOrderBll.GetModel(id); List <CsOrderDetail> orderList = _csOrderDetailBll.GetModelList($" and OrderId={id}"); List <CsProducts> productList = _csProductsBll.GetModelList(""); List <CsParts> partList = _csPartsBll.GetModelList(""); CsPackageBll _cspackageBll = new CsPackageBll(); List <CsPackage> packageList = _cspackageBll.GetModelList(""); //螃蟹列表 var crabList = orderList.Where(x => x.ChoseType == 1).Select(x => new { x.OrderId, x.ProductId, ProductName = productList.FirstOrDefault(y => y.ProductId == x.ProductId).ProductName, ProductType = ((ProductType)productList.FirstOrDefault(y => y.ProductId == x.ProductId).ProductType).ToString(), ProductWeight = (ProductType)productList.FirstOrDefault(y => y.ProductId == x.ProductId).ProductWeight, x.ProductNumber, x.UnitPrice, x.TotalPrice }); //必选配件列表 var partMustList = orderList.Where(x => x.ChoseType == 2 && x.ProductId < 10005 && x.ProductId > 10000).Select(x => new { x.OrderId, x.ProductId, PartName = partList.FirstOrDefault(y => y.PartId == x.ProductId).PartName, PartType = "必选配件", x.ProductNumber, x.UnitPrice, x.TotalPrice }); //可选配件列表 var partOptList = orderList.Where(x => x.ChoseType == 2 && x.ProductId >= 10005).Select(x => new { x.OrderId, x.ProductId, PartName = partList.FirstOrDefault(y => y.PartId == x.ProductId).PartName, PartType = "配件", x.ProductNumber, x.UnitPrice, x.TotalPrice }); //套餐列表 var packList = orderList.Where(x => x.ChoseType == 3).Select(x => new { x.OrderId, x.ProductId, ProductName = packageList.FirstOrDefault(y => y.PackageId == x.ProductId).PackageName, ProductType = ((ProductType)packageList.FirstOrDefault(y => y.PackageId == x.ProductId).PackageType).ToString(), ProductWeight = (ProductType)packageList.FirstOrDefault(y => y.PackageId == x.ProductId).PackageWeight, x.ProductNumber, x.UnitPrice, x.TotalPrice }); return(Json(new { order, crabList, partMustList, partOptList, packList })); }