public ActionResult PayOrdersNow(string Remark) { #region 生成订单 string ids = Request["ids"].TrimEnd(','); Business.Sys_Flower Sys_Flower = new Business.Sys_Flower(); Business.Sys_OrdersManaage Sys_OrdersManaage = new Business.Sys_OrdersManaage(); string[] idarry = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string FlowerNum = Request["FlowerNums"]; string[] FlowerNumarry = FlowerNum.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string ConsigneAaddress = Request["DetailedAddress"]; string ConsigneeName = Request["ConsigneeName"]; string ConsigneePhone = Request["ConsigneePhone"]; //唯一的订单 Model.Orders Orders = new Model.Orders(); Orders.UsersId = int.Parse(userid); Orders.CreateTime = DateTime.Now; Orders.OrdersState = 1; Orders.OrderId = Utility.ChangeText.OrderIdCreate(); Orders.GoodsSum = int.Parse(Request["goodnum"]);// 总件数 Orders.ConsigneeName = ConsigneeName; Orders.ConsigneePhone = ConsigneePhone; Orders.ConsigneAaddress = ConsigneAaddress; //详情列表 List <Model.OrdersDetails> OrdersDetailsList = new List <Model.OrdersDetails>(); for (int j = 0; j < idarry.Length; j++) { //每一种花 Model.Flower Flower = Sys_Flower.GetFlower(idarry[j]); Orders.SellingPrice += Flower.FlowerSalesPrice * int.Parse(FlowerNumarry[j]); Orders.CostPrice += Flower.FlowerCostPrice * int.Parse(FlowerNumarry[j]); //每种花对应的数量 for (int i = 0; i < int.Parse(FlowerNumarry[j]); i++) { Model.OrdersDetails OrdersDetails = new Model.OrdersDetails(); OrdersDetails.OrderId = Orders.OrderId; OrdersDetails.FlowerNumber = Flower.FlowerNumber; OrdersDetails.FlowerWatchName = Flower.FlowerWatchName; OrdersDetails.FlowerWatchPhoto = Flower.FlowerWatchPhoto; OrdersDetails.SellingPrice = Flower.FlowerSalesPrice; OrdersDetails.SellingNum = 1; OrdersDetails.CostPrice = Flower.FlowerCostPrice; OrdersDetailsList.Add(OrdersDetails); } } Model.OrdersLog OrdersLog = new Model.OrdersLog(); OrdersLog.OrdersId = Orders.OrderId; OrdersLog.OrdersState = 1; OrdersLog.UserName = Utility.ChangeText.GetUserName(); OrdersLog.Remark = Remark; OrdersLog.Time = DateTime.Now; #endregion Sys_OrdersManaage.TransactionAddOrders(Orders, OrdersDetailsList, OrdersLog); //return Redirect("/WxPay/Index?OrdersId=" + Orders.OrderId + "&PayTotal=" + Orders.SellingPrice); return(Json(new { OrdersId = Orders.OrderId, PayTotal = Orders.SellingPrice }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 记录订单日志 /// </summary> /// <param name="OrdersLog"></param> /// <returns></returns> public bool InsertOrderLog(Model.OrdersLog OrdersLog) { const string sql = @"INSERT INTO OrdersLog(OrdersId,UserName,OrdersState,Remark) VALUES(@OrdersId,@UserName,@OrdersState,@Remark)"; return(Factory.DBHelper.ExecSQL(SQLConString, sql.ToString(), new DynamicParameters(new { OrdersLog.OrdersId, OrdersLog.UserName, OrdersLog.OrdersState, OrdersLog.Remark, }))); }
public ActionResult CreateOrders() { string GoodsId = Request["GoodsId"]; Business.Sys_Flower Sys_Flower = new Business.Sys_Flower(); Model.Flower Flower = Sys_Flower.GetFlowerByFlowerNumber(GoodsId); //判断库存是否足够商品 if (Flower.FlowerStock < Convert.ToInt32(Request["FlowerStock"])) { ViewData["success"] = "抱歉,库存不足"; return(View()); } Model.Orders Orders = new Model.Orders(); Orders.OrderId = Utility.ChangeText.GenerateOutTradeNo(); Orders.OrdersState = 1; Orders.SellingPrice = Flower.FlowerSalesPrice * Convert.ToInt32(Request["FlowerStock"]); Orders.CostPrice = Flower.FlowerCostPrice * Convert.ToInt32(Request["FlowerStock"]); Orders.ConsigneAaddress = Request["ConsigneAaddress"]; Orders.ConsigneeName = Request["ConsigneeName"]; Orders.GoodsSum = Convert.ToInt32(Request["FlowerStock"]); Orders.ConsigneePhone = Request["ConsigneePhone"]; List <Model.OrdersDetails> OrdersDetailsList = new List <Model.OrdersDetails> (); for (int i = 0; i < Convert.ToInt32(Request["FlowerStock"]); i++) { Model.OrdersDetails OrdersDetails = new Model.OrdersDetails(); OrdersDetails.OrderId = Orders.OrderId; OrdersDetails.SellingPrice = Flower.FlowerSalesPrice; OrdersDetails.FlowerNumber = Flower.FlowerNumber; OrdersDetails.CostPrice = Flower.FlowerCostPrice; OrdersDetails.FlowerWatchPhoto = Flower.FlowerWatchPhoto; OrdersDetails.SellingNum = 1; OrdersDetails.FlowerWatchName = Flower.FlowerWatchName; OrdersDetailsList.Add(OrdersDetails); } Model.OrdersLog OrdersLog = new Model.OrdersLog(); OrdersLog.OrdersId = Orders.OrderId; OrdersLog.OrdersState = 1; OrdersLog.UserName = Utility.ChangeText.GetUserName(); Business.Sys_OrdersManaage Sys_OrdersManaage = new Business.Sys_OrdersManaage(); if (!Sys_OrdersManaage.InsertOrders(Orders, OrdersDetailsList, OrdersLog)) { ViewData["success"] = "下单失败,请联系管理员"; return(View()); } return(RedirectToAction("", "")); }
public ActionResult SetOrderStateInfo() { string OrderState = Request["OrdersState"]; string OrdersId = Request["OrdersId"]; Business.Sys_OrdersManaage Sys_OrdersManaage = new Business.Sys_OrdersManaage(); Sys_OrdersManaage.SetOrderState(OrdersId, OrderState); Model.OrdersLog OrdersLog = new Model.OrdersLog() { OrdersId = OrdersId, OrdersState = Convert.ToInt32(OrderState), Time = DateTime.Now, UserName = Utility.ChangeText.GetUserName(), }; Sys_OrdersManaage.InsertOrderLog(OrdersLog); return(Content("1")); }
/// <summary> /// 事务批量执行SQL语句 /// </summary> /// <param name="SQLList">SQL集合</param> /// <param name="SqlParameterList">参数集合</param> /// <returns></returns> public bool TransactionAddOrders(Model.Orders orders, List <Model.OrdersDetails> ordersDetailList, Model.OrdersLog ordersLog) { using (SqlConnection conn = new SqlConnection(SQLConString)) { conn.Open(); SqlTransaction tr = conn.BeginTransaction();//声明事务 SqlCommand comm = new SqlCommand(); comm.Connection = conn; //指定给SqlCommand事务 comm.Transaction = tr; try { #region order //遍历Hashtable数据,每次遍历执行SqlCommand const string sql = @"insert into Orders (OrderId,SellingPrice,CostPrice,profit,UsersId,ConsigneeName,ConsigneePhone,ConsigneAaddress,OrdersState,GoodsSum) values(@OrderId,@SellingPrice,@CostPrice,@profit,@UsersId,@ConsigneeName,@ConsigneePhone,@ConsigneAaddress,@OrdersState,@GoodsSum)"; string cmdText = sql; SqlParameter[] pars = new SqlParameter[] { new SqlParameter("@OrderId", orders.OrderId), new SqlParameter("@SellingPrice", orders.SellingPrice), new SqlParameter("@CostPrice", orders.CostPrice), new SqlParameter("@profit", orders.profit), new SqlParameter("@UsersId", orders.UsersId), new SqlParameter("@ConsigneeName", orders.ConsigneeName), new SqlParameter("@ConsigneePhone", orders.ConsigneePhone), new SqlParameter("@ConsigneAaddress", orders.ConsigneAaddress), new SqlParameter("@OrdersState", orders.OrdersState), new SqlParameter("@GoodsSum", orders.GoodsSum), }; //指定执行语句 comm.CommandText = cmdText; //有参数则进行添加 if (pars != null) { comm.Parameters.AddRange(pars); } //执行 comm.ExecuteNonQuery(); //使用后清空参数,为下次使用 comm.Parameters.Clear(); #endregion #region OrdersLog //遍历Hashtable数据,每次遍历执行SqlCommand const string OrdersLog = @"insert into OrdersLog(OrdersId,UserName,OrdersState,Remark) values(@OrdersId,@UserName,@OrdersState,@Remark)"; SqlParameter[] parsl = new SqlParameter[] { new SqlParameter("@OrdersId", ordersLog.OrdersId), new SqlParameter("@UserName", ordersLog.UserName), new SqlParameter("@OrdersState", ordersLog.OrdersState), new SqlParameter("@Remark", ordersLog.Remark), }; //指定执行语句 comm.CommandText = OrdersLog; //有参数则进行添加 if (parsl != null) { comm.Parameters.AddRange(parsl); } //执行 comm.ExecuteNonQuery(); //使用后清空参数,为下次使用 comm.Parameters.Clear(); #endregion #region detail foreach (Model.OrdersDetails item in ordersDetailList) { const string OrdersDetail = @"insert into OrdersDetails(OrderId,FlowerWatchName,FlowerWatchPhoto,FlowerNumber, SellingPrice,CostPrice,profit,SellingNum) values(@OrderId,@FlowerWatchName,@FlowerWatchPhoto,@FlowerNumber,@SellingPrice, @CostPrice,@profit,@SellingNum)"; SqlParameter[] parsd = new SqlParameter[] { new SqlParameter("@OrderId", item.OrderId), new SqlParameter("@FlowerWatchName", item.FlowerWatchName), new SqlParameter("@FlowerWatchPhoto", item.FlowerWatchPhoto), new SqlParameter("@SellingPrice", item.SellingPrice), new SqlParameter("@FlowerNumber", item.FlowerNumber == null ? "":item.FlowerNumber), new SqlParameter("@CostPrice", item.CostPrice), new SqlParameter("@profit", item.profit), new SqlParameter("@SellingNum", item.SellingNum), }; //指定执行语句 comm.CommandText = OrdersDetail; //有参数则进行添加 if (pars != null) { foreach (SqlParameter par in parsd) { comm.Parameters.Add(par); } } //执行 comm.ExecuteNonQuery(); //使用后清空参数,为下次使用 comm.Parameters.Clear(); } #endregion //不出意外事务提前,返回True tr.Commit(); return(true); } catch (Exception ex) { //出意外事务回滚,返回Fasle tr.Rollback(); return(false); } } }
/// <summary> /// 非事务订单 /// </summary> /// <returns></returns> public bool InsertOrders(Model.Orders orders, List <Model.OrdersDetails> ordersDetailList, Model.OrdersLog ordersLog) { const string sql = @"insert into Orders (OrderId,SellingPrice,CostPrice,profit,UsersId,ConsigneeName,ConsigneePhone,ConsigneAaddress,OrdersState,GoodsSum) values(@OrderId,@SellingPrice,@CostPrice,@profit,@UsersId,@ConsigneeName,@ConsigneePhone,@ConsigneAaddress,@OrdersState,@GoodsSum)"; Factory.DBHelper.ExecSQL(SQLConString, sql.ToString(), new DynamicParameters(new { orders.OrderId, orders.SellingPrice, orders.CostPrice, orders.profit, orders.UsersId, orders.ConsigneeName, orders.ConsigneePhone, orders.ConsigneAaddress, orders.OrdersState, orders.GoodsSum, })); const string OrdersLog = @"insert into OrdersLog(OrdersId,UserName,OrdersState,Remark) values(@OrdersId,@UserName,@OrdersState,@Remark)"; Factory.DBHelper.ExecSQL(SQLConString, OrdersLog.ToString(), new DynamicParameters(new { ordersLog.OrdersId, ordersLog.UserName, ordersLog.OrdersState, ordersLog.Remark, })); // foreach (Model.OrdersDetails item in ordersDetailList) { const string OrdersDetail = @"insert into OrdersDetails(OrderId,FlowerWatchName,FlowerWatchPhoto,FlowerNumber, SellingPrice,CostPrice,profit,SellingNum) values(@OrderId,@FlowerWatchName,@FlowerWatchPhoto,@FlowerNumber,@SellingPrice, @CostPrice,@profit,@SellingNum)"; Factory.DBHelper.ExecSQL(SQLConString, OrdersDetail.ToString(), new DynamicParameters(new { item.OrderId, item.FlowerWatchName, item.FlowerWatchPhoto, item.FlowerNumber, item.SellingPrice, item.CostPrice, item.profit, item.SellingNum, })); } return(true); }