/// <summary> /// 后台取消已付款未发货订单 /// </summary> /// <param name="orderCancelCauseID"> /// 订单取消原因编码 /// </param> /// <param name="cancelDescription"> /// 订单取消备注 /// </param> /// <param name="refund"> /// 取消对象 /// </param> /// <returns> /// 操作状态 /// </returns> public int OrderCancelRefundByBackstage( int orderCancelCauseID, string cancelDescription, Aftersale_Refund refund) { var state = new OrderCancelService().OrderCancelRefundByBackstage( orderCancelCauseID, cancelDescription, refund); if (state == 1) { // 取消成功时,写订单修改日志 try { var orderStatusLogService = new OrderStatusLogService(); orderStatusLogService.Insert( new Order_Status_Log { EmployeeID = refund.EmployeeID, OrderID = refund.OrderID, Remark = cancelDescription, Status = 6 }, null); } catch (Exception exception) { TextLogger.Instance.Log( string.Format("后台取消订单--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", refund.OrderID, refund.EmployeeID), Category.Error, exception); } } return state; }
/// <summary> /// 后台取消未付款未发货订单 /// </summary> /// <param name="orderCancel"> /// The order cancel. /// </param> /// <returns> /// 操作结果:0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废 /// </returns> public int OrderCancelByBackstage(Order_Cancel orderCancel) { var state = new OrderCancelService().OrderCancel(orderCancel); if (state == 1) { // 取消成功时,写订单修改日志 try { var orderStatusLogService = new OrderStatusLogService(); orderStatusLogService.Insert( new Order_Status_Log { EmployeeID = orderCancel.EmployeeID, OrderID = orderCancel.OrderID, Remark = orderCancel.Description, Status = 6 }, null); } catch (Exception exception) { TextLogger.Instance.Log( string.Format("后台取消订单--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", orderCancel.OrderID, orderCancel.EmployeeID), Category.Error, exception); } } return state; }
/// <summary> /// 修改订单客服备注信息 /// </summary> /// <param name="orderID"> /// 订单编码 /// </param> /// <param name="description"> /// 客服备注信息 /// </param> public void ModifyOrderDescription(int orderID, string description) { this.orderDA.UpdateDescription(orderID, description); // 写订单修改日志 try { var orderStatusLogService = new OrderStatusLogService(); orderStatusLogService.Insert( new Order_Status_Log { EmployeeID = this.userID, OrderID = orderID, Remark = description, Status = this.orderDA.SelectByID(orderID).Status }, null); } catch (Exception exception) { TextLogger.Instance.Log( string.Format("后台--修改订单备注信息--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", orderID, this.userID), Category.Error, exception); } }
/// <summary> /// 确认订单 /// </summary> /// <param name="order"> /// 订单对象 /// </param> /// <param name="orderProducts"> /// 订单商品列表 /// </param> /// <param name="orderInvoice"> /// 订单发票 /// </param> /// <param name="userRecieveAddress"> /// 用户收货地址信息 /// </param> public void ManualConfirmOrder( Order order, List<Order_Product> orderProducts, Order_Invoice orderInvoice, User_RecieveAddress userRecieveAddress) { //todo: 订单数据需要从数据库取一次 /************ * 一、修改订单 * 1. 修改收货人信息。 * 2. 修改订单商品信息 * 3. 修改订单发票信息 * 4. 修改订单信息 * 二、确认订单 * 1.推送到ERP系统 * 2.修改订单为确认状态 * ***********/ SqlTransaction transaction = null; var orderProductService = new OrderProductService(); Order orignalOrder = this.EditOrderInfo(order, orderProducts, orderInvoice, userRecieveAddress); switch (orignalOrder.Status) { case 100: throw new Exception("此订单处于等待支付状态,不允许确认。"); case 1: throw new Exception("此订单已确认,请不要重复操作!"); case 2: throw new Exception("此订单已发货"); case 3: throw new Exception("此订单已签收"); case 4: case 6: case 8: throw new Exception("此订单已取消"); case 5: throw new Exception("此订单已损失"); case 0: //确认订单 try { Order_Payment payment = null; if (order.PaymentStatus == 1) { payment = new OrderPaymentService().QueryByOrderID(order.ID); } orderProducts = orderProductService.QueryByOrderId(order.ID); this.orderDA.SqlServer.BeginTransaction(); transaction = this.orderDA.SqlServer.Transaction; this.ConfirmByUpdateOrder(orignalOrder, transaction, payment, orderProducts); new OrderStatusTrackingService().Add( new Order_Status_Tracking { OrderID = order.ID, EmployeeID = isBackage ? this.userID : 0, Remark = "订单已经确认,等待出库", Status = 1, // 已确认的订单状态为码 1 UserID = order.UserID }, transaction); transaction.Commit(); } catch (Exception exception) { if (transaction != null) { transaction.Rollback(); } LogUtils.Log( string.Format( "确认订单出错,订单编码{0},操作人ID:{1},错误信息:{2},内部错误:{3},堆栈信息:{4}", order.ID, this.userID, exception.Message, exception.InnerException, exception.StackTrace), "确认订单--服务层", Category.Fatal); throw; } // 写订单修改日志 try { var orderStatusLogService = new OrderStatusLogService(); orderStatusLogService.Insert( new Order_Status_Log { EmployeeID = this.userID, OrderID = order.ID, Remark = order.Description, Status = 1 }, null); } catch (Exception exception) { TextLogger.Instance.Log( string.Format("后台订单确认--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", order.ID, this.userID), Category.Error, exception); } break; default: throw new Exception("订单状态异常。"); } }
/// <summary> /// 添加订单 /// </summary> /// <param name="order"> /// 订单兑现 /// </param> /// <param name="orderProducts"> /// 订单商品列表 /// </param> /// <param name="invoice"> /// 发票信息 /// </param> /// <param name="Coupons">赠送的优惠券信息</param> /// <param name="promotes">订单促销信息</param> /// <returns> /// 已添加订单的编码 /// </returns> public int Add(Order order, List<Order_Product> orderProducts, Order_Invoice invoice, List<Gift_Coupon> Coupons = null, List<Order_Product_Promote> promotes = null) { // 1.添加订单 // 2.添加订单商品 // 3.添加发票(若有) var orderProductService = new OrderProductService(); SqlTransaction transaction = null; int orderId; try { if (order.TotalMoney == 0) //如果0,则认为是前端的订单,需要从新计算金额,不能享受到优惠和促销 { double totalMoney = 0; foreach (var orderProduct in orderProducts) { totalMoney += orderProduct.TransactPrice * orderProduct.Quantity; } order.TotalMoney = totalMoney; order.DeliveryCost = totalMoney >= 100 ? 0 : 10; // todo: 读取数据库配置,设置运费。 } order.TotalIntegral = (int)order.TotalMoney / 1; orderId = this.orderDA.Insert(order, out transaction); order.ID = orderId; orderProductService.BatchAddOrderProduct(orderProducts, order.CpsID, orderId, transaction); if (invoice != null) { invoice.OrderID = orderId; invoice.InvoiceCost = order.TotalMoney; new OrderInvoiceService().Add(invoice, transaction); } //赠送优惠券 if (Coupons != null && Coupons.Count > 0) { foreach (var giftCoupon in Coupons) { switch (giftCoupon.CouponType) { case 0: //默认新方法的券状态为2,未激活 new CouponCashBindingService().Add(orderId, giftCoupon.CouponID, this.userID, "购物赠券", 2, transaction); break; case 1: //默认新方法的券状态为2,未激活 new CouponDecreaseBindingService().Add(orderId, giftCoupon.CouponID, this.userID, "购物赠券", 2, transaction); break; } } } if (promotes != null && promotes.Count > 0) { foreach (var promote in promotes) { promote.OrderID = orderId; } var rowCount = new OrderProductPromoteService().BatchAdd(promotes, transaction); if (rowCount < 1) { LogUtils.Log("添加订单(订单号:" + order.OrderCode + ")时添加的订单商品促销信息数为:" + rowCount, "添加订单服务层", Category.Info); } } string remark; if (order.PaymentMethodID == 1||order.PaymentMethodID == 2) { remark = "添加订单成功,等待确认"; } else { remark = order.PaymentStatus == 0 ? "添加订单成功,等待付款" : "添加订单成功,等待确认"; } new OrderStatusTrackingService().Add( new Order_Status_Tracking { OrderID = orderId, EmployeeID = isBackage? this.userID:0, Remark = remark, Status = 0, UserID = order.UserID }, transaction); transaction.Commit(); } catch (Exception) { if (transaction != null) { transaction.Rollback(); } throw; } // 写订单修改日志 try { var orderStatusLogService = new OrderStatusLogService(); orderStatusLogService.Insert( new Order_Status_Log { EmployeeID = isBackage? this.userID:0, // 若是后台,则填写操作员工编码 OrderID = orderId, Remark = order.Description, Status = 0 }, null); } catch (Exception exception) { TextLogger.Instance.Log( string.Format("后台添加订单--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", order.ID, this.userID), Category.Error, exception); } return orderId; }
/// <summary> /// 设置订单为废单 /// </summary> /// <param name="orderId"> /// 订单编码 /// </param> /// <param name="reason"> /// 废单原因 /// </param> public void SetInvalidByGJW(int orderId, string reason) { SqlTransaction transaction = null; try { this.orderDA.UpdateStatus(orderId, 8, reason, out transaction); this.orderDA.RecoverProductsInventory(orderId, transaction); new OrderStatusTrackingService().Add( new Order_Status_Tracking { OrderID = orderId, EmployeeID = isBackage? this.userID:0, Remark = "订单作废,原因:"+reason, Status = 8 }, transaction); transaction.Commit(); } catch (Exception) { if (transaction != null) { transaction.Rollback(); } throw; } // 写订单修改日志 try { var orderStatusLogService = new OrderStatusLogService(); orderStatusLogService.Insert( new Order_Status_Log { EmployeeID = this.userID, OrderID = orderId, Remark = reason, Status = 8 }, null); } catch (Exception exception) { TextLogger.Instance.Log( string.Format("后台设为废单--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", orderId, this.userID), Category.Error, exception); } }