public static async Task <Result> AddOrder(OnLineOrderParent OrderParent) { return(await Task.Run(() => { return AddConcurrenOrder(OrderParent); })); }
/// <summary> /// 订单申请售后 /// </summary> /// <param name="OrederId"></param> /// <param name="Type"></param> /// <param name="Content"></param> /// <returns></returns> public bool OrderServiceApply(string OrederId, ServiceTypeEnum Type, string Content) { OnLineOrderParent order = _db.Queryable <OnLineOrderParent>().First(a => a.OrderID == OrederId); if (order != null && order.OrderState == OrderStateEnum.Completed) { ServiceRecord sr = new ServiceRecord { Content = Content, CustomerID = order.CustomerID, Type = Type, OrderID = OrederId }; if (_db.Insertable(sr).ExecuteCommand() > 0) { order.IsDelete = true; switch (Type) { case ServiceTypeEnum.Exchange: order.OrderState = OrderStateEnum.ApplyExchange; break; case ServiceTypeEnum.Refund: order.OrderState = OrderStateEnum.ApplyRefund; break; default: order.OrderState = OrderStateEnum.ApplyReturns; break; } if (_db.Updateable(order).ExecuteCommand() > 0) { //发送通知 switch (Type) { case ServiceTypeEnum.Exchange: return(SendMessage(order.CustomerID, order.OrderID, MessageTypeEnum.ApplyExchange)); case ServiceTypeEnum.Refund: return(SendMessage(order.CustomerID, order.OrderID, MessageTypeEnum.ApplyRefund)); default: return(SendMessage(order.CustomerID, order.OrderID, MessageTypeEnum.ApplyReturns)); } } else { throw new Exception("删除订单异常!"); } } else { throw new Exception("添加售后记录订单异常!"); } } else { throw new Exception("查无订单或订单状态异常!"); } }
/// <summary> /// 订单确认(支付) /// </summary> /// <param name="OrderId">订单编号</param> /// <param name="TransactionId">交易编号</param> /// <returns></returns> public bool OrderPay(string OrderId, string TransactionId) { if (string.IsNullOrEmpty(OrderId) || string.IsNullOrEmpty(TransactionId)) { throw new Exception("订单编号或交易编号不能为空!"); } OnLineOrderParent order = _db.Queryable <OnLineOrderParent>().First(a => a.OrderID == OrderId); if (order != null && order.OrderState == OrderStateEnum.WaitPayment) { order.OrderState = OrderStateEnum.WaitShipment; order.PayTime = DateTime.Now; try { if (_db.Updateable(order).ExecuteCommand() > 0) { TransactionRecord tr = new TransactionRecord { OrderID = OrderId, TotalPrice = order.TotalPrice, TransactionID = TransactionId, Type = PaymentTypeEnum.WeChatPayment }; if (_db.Insertable(tr).ExecuteCommand() > 0) { ChangeCustomerSign(order.CustomerID, SignEnum.购买商品50点积分); return(SendMessage(order.CustomerID, order.OrderID, MessageTypeEnum.Confirm)); } else { throw new Exception("添加交易日志异常!"); } } else { throw new Exception("更新订单异常!"); } } catch (Exception) { throw; } } else { throw new Exception("查无订单或订单状态异常!"); } }
static Result AddConcurrenOrder(OnLineOrderParent OrderParent) { var result = new Result(); if (_ConcurrenOrders.Count >= 300) { result.IsSuccessful = false; result.ReasonDescription = "已超过最大并发数"; return(result); } else { _ConcurrenOrders.Push(OrderParent); } return(result); }
/// <summary> /// 取消订单(非物理删除) /// </summary> /// <param name="OrderId"></param> /// <param name="IsDelete">是否删除</param> /// <returns></returns> public bool OrderCancel(string OrderId, bool IsDelete = false) { if (string.IsNullOrWhiteSpace(OrderId)) { throw new Exception("订单号为空!"); } OrderId = OrderId.ToUpper(); OnLineOrderParent order = _db.Queryable <OnLineOrderParent>().First(a => a.OrderID.Equals(OrderId) & a.IsDelete == false); if (order == null) { throw new Exception("订单信息为空,请检查!"); } var type = order.OrderState; order.OrderState = OrderStateEnum.Canceled; order.IsDelete = IsDelete; try { _db.Ado.BeginTran(); if (_db.Updateable(order).ExecuteCommand() > 0) { //发送通知 if (SendMessage(order.CustomerID, order.OrderID, MessageTypeEnum.Cancel)) { _db.Ado.CommitTran(); return(true); } _db.Ado.RollbackTran(); return(false); } else { _db.Ado.RollbackTran(); throw new Exception("删除订单异常!"); } } catch (Exception) { _db.Ado.RollbackTran(); throw; } }
/// <summary> /// 完成订单(确认收货) /// </summary> /// <param name="OrederId"></param> /// <returns></returns> public bool OrderComplete(string OrederId) { OnLineOrderParent order = _db.Queryable <OnLineOrderParent>().First(a => a.OrderID == OrederId); if (order != null && order.OrderState == OrderStateEnum.WaitDelivery) { order.OrderState = OrderStateEnum.WaitShipment; order.PayTime = DateTime.Now; if (_db.Updateable(order).ExecuteCommand() > 0) { return(true); } else { throw new Exception("更新订单异常!"); } } else { throw new Exception("查无订单或订单状态异常!"); } }
/// <summary> /// 创建订单 /// </summary> /// <param name="shopCart"></param> /// <returns></returns> public bool OrderCreate(ShopCart shopCart) { if (shopCart == null) { throw new Exception("购物车为空!"); } int detailCount = 0; //主表数据 OnLineOrderParent order = new OnLineOrderParent { DeliveryAddressID = shopCart.Address.Id, OrderID = shopCart.OrderId, OrderState = shopCart.OrderState, PayTime = shopCart.PayTime, PaymentType = shopCart.PaymentType, CustomerRemarks = shopCart.CustomerRemarks, CustomerID = shopCart.CustomerID, TotalPrice = shopCart.TotalPrice }; if (shopCart.ProductList.Count == 1) { if (shopCart.ProductList.Find(a => 1 == 1).Number == 1) { order.OrderType = OrderTypeEnum.单条单数; } else { order.OrderType = OrderTypeEnum.单条多件; } } else { order.OrderType = OrderTypeEnum.多条; } order.IsDelete = false; try { //开启事务 _db.Ado.BeginTran(); if (_db.Insertable(order).ExecuteCommand() > 0) { //明细数据 foreach (var Product in shopCart.ProductList) { OnLineOrderDetail orderDetail = new OnLineOrderDetail { OrderID = shopCart.OrderId, ProductID = Product.ProductID, Number = Product.Number }; if (_db.Insertable(orderDetail).ExecuteCommand() > 0) { detailCount++; } } //判断是否全部提交成功 if (detailCount == shopCart.ProductList.Count) { //提交事务 _db.Ado.CommitTran(); return(true); } else { //回滚事务 _db.Ado.RollbackTran(); throw new Exception("创建订单异常!"); } } else { //回滚事务 _db.Ado.RollbackTran(); throw new Exception("创建订单异常!"); } } catch (Exception ex) { //回滚事务 _db.Ado.RollbackTran(); throw ex; } }