public async Task <IHttpActionResult> PostOrderItemDetail(ChangeOrderItemModel coim) { if (!ModelState.IsValid) { return(BadRequest()); } var order = db.Orders.Where(o => o.Id == coim.OrderId).FirstOrDefault(); if (order == null) { return(NotFound()); } if (order.OrderStatus == OrderStatus.Partion) { return(BadRequest()); } try { OrderItem oi = new OrderItem(); oi.Id = Guid.NewGuid(); oi.ProductId = coim.OrderItem.ProductId; oi.ProductType = coim.OrderItem.ProductType; oi.CertificateDate = coim.OrderItem.CertificateDate; oi.CertificateNum = coim.OrderItem.CertificateNum; oi.CustomerPrice = 0; oi.Describe = coim.OrderItem.Describe; oi.EndDate = coim.OrderItem.EndDate; oi.StartDate = coim.OrderItem.StartDate; oi.TotalPrice = coim.OrderItem.TotalPrice; oi.OrderId = coim.OrderId; oi.Remark = coim.OrderItem.Remark; oi.Quantity = coim.OrderItem.Quantity; oi.Persons = new List <PersonInfo>(); foreach (var item in coim.OrderItem.Persons) { PersonInfo pi = item; oi.Persons.Add(pi); } order.OrderItems.Add(oi); order.OrderItems.First(o => o.Id == coim.OrderItem.Id).State = 1; order.OrderStatus = OrderStatus.Partion; order.Remark += "修改订单信息,重新下单"; db.SaveChanges(); string err = string.Empty; TaskAdapter ta = new TaskAdapter(); var tasks = ta.OrderItem2Task(oi, order.OrderCode, db, ref err); if (string.IsNullOrEmpty(err)) { ta.SendTask2Group(tasks, _changeState.Group); OrderUpdateModel oum = new OrderUpdateModel(); oum.Id = order.Id; oum.State = order.OrderStatus; oum.Remark = order.Remark; _changeState.SendUpdateOrderState(oum); } else { throw new Exception(err); } } catch (Exception) { return(InternalServerError()); } return(Ok()); }
public async Task <IHttpActionResult> PutOrderStatus(Guid id) { string err = string.Empty; try { var order = db.Orders.Include("OrderItems").FirstOrDefault(o => o.Id == id); if (order.OrderStatus != OrderStatus.Partion) { ///取消还未下单的订单 var tasks = db.Tasks.Include(t => t.Personinfos).Where(t => t.OrderCode == order.OrderCode).ToList(); if (tasks.Count > 0) { bool isCancelOrder = true; foreach (var item in tasks) { if (item.State == TaskState.Create || item.State == TaskState.Take || item.State == TaskState.Change) { item.State = TaskState.Canceled; await db.SaveChangesAsync(); _changeState.SendUpdateTaskState(item); } if (item.State == TaskState.Finish) { isCancelOrder = false; TaskOrderModel tom = new TaskOrderModel(); tom.OrderCode = item.OrderCode; tom.OrderItemId = item.OrderItemId; tom.ProductCode = item.ProductCode; tom.ProductFrom = item.ProductFrom; tom.ProductName = item.ProductName; tom.ProductType = item.ProductType; tom.Quantity = item.Quantity; tom.Remark = item.Remark; tom.UsedEndDate = item.UsedEndDate; tom.UsedStartDate = item.UsedStartDate; foreach (var it in item.Personinfos) { tom.Personinfos.Add(it); } tom.State = TaskState.CreateCancel; db.Tasks.Add(tom); await db.SaveChangesAsync(); _changeState.SendUpdateTaskState(tom, true); } } if (isCancelOrder) { order.OrderStatus = OrderStatus.Canceled; order.Remark = order.Remark + "订单取消完成"; } else { order.OrderStatus = OrderStatus.Cancel; } } else { order.OrderStatus = OrderStatus.Canceled; } await db.SaveChangesAsync(); OrderUpdateModel oum = new OrderUpdateModel(); oum.Id = order.Id; oum.State = order.OrderStatus; oum.Remark = order.Remark; _changeState.SendUpdateOrderState(oum); } } catch (Exception) { return(InternalServerError()); } return(Ok()); }
public async Task <IHttpActionResult> PutUpdateTasks(UpdateTaskModel utm) { try { var task = odb.Tasks.Find(utm.Id); if (task == null) { return(NotFound()); } var order = odb.Orders.FirstOrDefault(o => o.OrderCode == task.OrderCode); if (order == null) { return(NotFound()); } task.State = utm.State; if (task.State == TaskState.Take) { task.TakeDate = DateTime.Now; task.TakePerson = User.Identity.GetUserId(); if (order.OrderStatus != OrderStatus.Partion && order.OrderStatus != OrderStatus.Processing) { order.OrderStatus = OrderStatus.Processing; } order.Remark += DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + ":处理订单中\r\n"; } if (task.State == TaskState.Finish) { var tasks = odb.Tasks.Where(o => o.OrderCode == task.OrderCode).ToList(); var d = tasks.Where(t => t.State == TaskState.Create || t.State == TaskState.Take).Count(); task.CompleteDate = DateTime.Now; if (d == 0) { if (tasks.FindAll(ta => ta.State == TaskState.OrderErr).Count > 0) { order.OrderStatus = OrderStatus.DoneWithErr; } else { order.OrderStatus = OrderStatus.Done; } order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + ":完成订单[" + utm.Remark + "]"; } if (d > 0) { order.OrderStatus = OrderStatus.Partion; order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + task.ProductName + "出货成功[" + utm.Remark + "]"; } } if (task.State == TaskState.OrderErr) { var tasks = odb.Tasks.Where(o => o.OrderCode == task.OrderCode).ToList(); var d = tasks.Where(t => t.State == TaskState.Create || t.State == TaskState.Take).Count(); task.CompleteDate = DateTime.Now; if (d == 0) { order.OrderStatus = OrderStatus.DoneWithErr; order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + task.ProductName + ":下单失败[" + utm.Remark + "]"; } if (d > 0) { order.OrderStatus = OrderStatus.Partion; order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + task.ProductName + "出货失败[" + utm.Remark + "]"; } } if (task.State == TaskState.TakeCanceling) { task.TakeDate = DateTime.Now; task.TakePerson = User.Identity.GetUserId(); var tasks = odb.Tasks.Where(o => o.OrderCode == task.OrderCode).ToList(); order.OrderStatus = OrderStatus.Canceling; order.Remark += "\r\n" + task.ProductName + "处理取消"; } if (task.State == TaskState.Canceled) { var tasks = odb.Tasks.Where(o => o.OrderCode == task.OrderCode).ToList(); var d = tasks.Where(t => t.State == TaskState.CreateCancel || t.State == TaskState.TakeCanceling).Count(); task.CompleteDate = DateTime.Now; if (d == 0) { if (tasks.FindAll(ta => ta.State == TaskState.CancelFaild).Count > 0) { order.OrderStatus = OrderStatus.CancelFailed; } else { order.OrderStatus = OrderStatus.Canceled; } order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + ":退单完成[" + utm.Remark + "]"; } if (d > 0) { order.OrderStatus = OrderStatus.Canceling; order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + task.ProductName + "退货完成[" + utm.Remark + "]"; } } if (task.State == TaskState.CancelFaild) { var tasks = odb.Tasks.Where(o => o.OrderCode == task.OrderCode).ToList(); var d = tasks.Where(t => t.State == TaskState.CreateCancel || t.State == TaskState.TakeCanceling).Count(); task.CompleteDate = DateTime.Now; if (d == 0) { order.OrderStatus = OrderStatus.CancelFailed; order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + task.ProductName + ":退单失败[" + utm.Remark + "]"; } if (d > 0) { order.OrderStatus = OrderStatus.Canceling; order.Remark += "\r\n" + DateTime.Now.ToString("yy-MM-dd hh:mm:ss") + task.ProductName + "退单失败[" + utm.Remark + "]"; } } task.TaskRemark = utm.Remark; await odb.SaveChangesAsync(); OrderUpdateModel oum = new OrderUpdateModel(); oum.Id = order.Id; oum.State = order.OrderStatus; oum.Remark = order.Remark; _changeState.SendUpdateTaskState(task); _changeState.SendUpdateOrderState(oum); return(Ok()); } catch (Exception) { return(InternalServerError()); } }