/// <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="user"> /// 用户对象 /// </param> public void AddUserInfo(User user) { if (user != null) { var userService = new UserService(); var userReceiceAddressService = new UserReceiveAddressService(); SqlTransaction sqlTransact = null; try { var userId = userService.AddUser(user, out sqlTransact); var userReceiveAddress = new User_RecieveAddress { UserID = userId, CountyID = user.CountyID, Address = user.Address, Consignee = user.Name, Mobile = user.Mobile, Tel = user.Tel, IsDefault = true, CreateTime = DateTime.Now }; userReceiceAddressService.Add(userReceiveAddress, sqlTransact); sqlTransact.Commit(); user.ID = userId; } catch { if (sqlTransact != null) { sqlTransact.Rollback(); } throw; } } }
public Order EditOrderInfo( Order order, List<Order_Product> orderProducts, Order_Invoice orderInvoice, User_RecieveAddress userRecieveAddress) { SqlTransaction transaction = null; var orignalOrder = this.QueryById(order.ID); //int rowCount, pageCount; if (orignalOrder == null) { throw new ArgumentException("订单获取错误"); } try { orignalOrder.CpsID = order.CpsID; orignalOrder.DeliveryCost = order.DeliveryCost; orignalOrder.Description = order.Description; orignalOrder.IsRequireInvoice = order.IsRequireInvoice; new UserReceiveAddressService().Modify(userRecieveAddress, out transaction); new OrderProductService().ModifyOrderProductByOrderID(orderProducts, orignalOrder.CpsID, order.ID, transaction); if (order.IsRequireInvoice) { orderInvoice.OrderID = order.ID; if (orderInvoice.ID > 0) { new OrderInvoiceService().Modify(orderInvoice, transaction); } else { new OrderInvoiceService().Add(orderInvoice, transaction); } } foreach (var orderProduct in orderProducts) { order.TotalMoney += orderProduct.TransactPrice * orderProduct.Quantity; } order.TotalIntegral = (int)order.TotalMoney; orignalOrder.TotalIntegral = order.TotalIntegral; orignalOrder.TotalMoney = order.TotalMoney; this.Edit(orignalOrder, transaction); transaction.Commit(); } catch (Exception ex) { if (transaction != null) { transaction.Rollback(); } LogUtils.Log( string.Format( "确认订单是修改订单信息出错,订单编码{0},操作人ID:{1},错误信息:{2},堆栈信息:{3}", order.ID, this.userID, ex.Message, ex.StackTrace), "确认订单--服务层", Category.Fatal); throw; } return orignalOrder; }
/// <summary> /// 保存用户地址的修改 /// </summary> /// <param name="id">主键编号</param> /// <param name="consignee">用户名</param> /// <param name="address">地址</param> /// <param name="mobile">手机号码</param> /// <param name="Isdefault">是否默认</param> /// <param name="email">邮箱</param> /// <param name="zipCode">区号</param> /// <param name="countryId">地区标识</param> /// <param name="tel"></param> /// <returns></returns> public ActionResult SaveModifyAddress(int id, string consignee, string address, string mobile, bool Isdefault, string email, string zipCode, int countryId, string tel) { try { if (id == -1) { var receAddress = new User_RecieveAddress() { UserID = this.GetUserID(), Consignee = consignee, Address = address, Mobile = mobile, IsDefault = Isdefault, Email = email, ZipCode = zipCode, CountyID = countryId, Tel = tel }; var recevid = new UserReceiveAddressService().Add(receAddress, null); if (recevid > 0) { return Json(new AjaxResponse { State = 1, Message = "添加成功", Data = recevid }); } } else { var receAddress = new User_RecieveAddress() { UserID = this.GetUserID(), Consignee = consignee, Address = address, Mobile = mobile, IsDefault = Isdefault, Email = email, ZipCode = zipCode, CountyID = countryId, ID = id, Tel = tel }; var recevid = new UserReceiveAddressService().UpdateAddresss(receAddress); if (recevid > 0) { return Json(new AjaxResponse(1, "修改成功")); } } } catch (Exception exception) { throw new Exception(exception.Message); } return Json(""); }