/// <summary>
        /// 后台取消订单
        /// </summary>
        /// <param name="orderCancel">
        /// 订单取消对象
        /// </param>
        /// <returns>
        /// 操作结果:0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废
        /// </returns>
        public int OrderCancel(Order_Cancel orderCancel)
        {
            /*
             Create Procedure sp_Order_Cancel
                @OrderID int,
                @OrderCancelCauseID int
               ,@EmployeeID int = default
               ,@UserID int =default
               ,@Description nvarchar
               ,@CreateTime datetime
                ,@Result int output
            As
             */

            var paras = new List<SqlParameter>
                            {
                                this.SqlServer.CreateSqlParameter(
                                    "OrderID",
                                    SqlDbType.Int,
                                    orderCancel.OrderID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "OrderCancelCauseID",
                                    SqlDbType.Int,
                                    orderCancel.OrderCancelCauseID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "UserID",
                                    SqlDbType.Int,
                                    orderCancel.UserID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "EmployeeID",
                                    SqlDbType.Int,
                                    orderCancel.EmployeeID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "Description",
                                    SqlDbType.NVarChar,
                                    orderCancel.Description,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "CreateTime",
                                    SqlDbType.DateTime,
                                    DateTime.Now,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "Result",
                                    SqlDbType.Int,
                                    null,
                                    ParameterDirection.Output)
                            };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Order_Cancel", paras, null);
            return (int)paras.Find(p => p.ParameterName == "Result").Value;
        }
 /// <summary>
 /// 后台取消已付款为发货订单
 /// </summary>
 /// <param name="orderCancelCauseId">
 /// 订单编码
 /// </param>
 /// <param name="cancelDescription">
 /// 取消订单备注
 /// </param>
 /// <param name="refund">
 /// 退款对象
 /// </param>
 /// <returns>
 /// 操作结果:0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废,4-订单未付款
 /// </returns>
 public int OrderCancelRefundByBackstage(int orderCancelCauseId, string cancelDescription, Aftersale_Refund refund)
 {
     var orderCancel = new Order_Cancel
                           {
                               OrderID = refund.OrderID,
                               OrderCancelCauseID = orderCancelCauseId,
                               Description = cancelDescription,
                               EmployeeID = refund.EmployeeID
                           };
     return this.orderCancelDA.OrderCancelWithRefundByBackstage(orderCancel, refund);
 }
 /// <summary>
 /// 前台取消未付款未发货订单
 /// </summary>
 /// <param name="orderCancel">
 /// The order cancel.
 /// </param>
 /// <returns>
 /// 操作结果:0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废
 /// </returns>
 public int OrderCancelByFront(Order_Cancel orderCancel)
 {
     var state = new OrderCancelService().OrderCancel(orderCancel);
     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="ono"></param>
        /// <param name="orderCancelCauseID"></param>
        /// <returns></returns>
        public ActionResult Cancel(string ono, int orderCancelCauseID)
        {
            var response = new AjaxResponse();
            //if (orderID < 1 || orderCancelCauseID < 1)
            //{
            //    response.State = -1;
            //    response.Message = "参数错误";
            //    return this.Json(response, JsonRequestBehavior.AllowGet);
            //}

            var order = new OrderService(this.UserSession.UserID, false).QueryByOrderCode(ono);
            if (order == null || order.UserID != this.UserSession.UserID)
            {
                response.State = -1;
                response.Message = "订单编号错误";
                LogUtils.Log(
                    "用户取消订单时订单编号(" + ono + ")错误或者获取对应订单数据为空",
                    "前台取消订单",
                    Category.Error,
                    this.UserSession.SessionId,
                    this.UserSession.UserID,
                    "/Order/Cancel");
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }

            //可取消条件:
            // 1.只有在线支付且未支付
            // 2.订单货到付款且未确认
            if (order.Status != 100 && (order.Status == 0 && order.PaymentMethodID == 0))
            {
                LogUtils.Log(
                    "前台尝试取消不符合取消条件的订单(订单号:" + ono + ")",
                    "前台取消订单",
                    Category.Warn,
                    this.UserSession.SessionId,
                    this.UserSession.UserID,
                    "/Order/Cancel");
                TextLogger.Instance.Log("前台尝试取消不符合取消条件的订单(订单号:" + ono + ",用户名:"+this.UserSession.UserID+")", Category.Warn, null);

                response.State = -1;
                response.Message = "此订单不符合取消条件";
                return this.Json(response);
            }

            try
            {
                var orderCancel = new Order_Cancel
                                      {
                                          OrderID = order.ID,
                                          CreateTime = DateTime.Now,
                                          OrderCancelCauseID = orderCancelCauseID,
                                          UserID = this.UserSession.UserID
                                      };

                int state = new OrderService(this.UserSession.UserID,false).OrderCancelByBackstage(orderCancel);

                // 0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废
                if (state == 0)
                {
                    response.State = 0;
                    response.Message = "订单状态异常";
                }
                else if (state == 1)
                {
                    response.State = 1;
                    response.Message = "订单取消成功";
                }
                else if (state == 2)
                {
                    response.State = 2;
                    response.Message = "已发货,取消订单操作取消";
                }
                else if (state == 3)
                {
                    response.State = 3;
                    response.Message = "订单已取消、已损失或者已作废";
                }
                else if (state == 4)
                {
                    response.State = 4;
                    response.Message = "订单已付款";
                }
                else
                {
                    response.State = 0;
                    response.Message = "订单状态异常";
                }

                LogUtils.Log(
                    "前台尝试取消订单(订单号:" + ono + "),结果:(状态:" + response.State + ";消息:" + response.Message + ")",
                    "前台取消订单",
                    Category.Info,
                    this.UserSession.SessionId,
                    this.UserSession.UserID,
                    "/Order/Cancel");

                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                TextLogger.Instance.Log("订单取消操作发生错误", Category.Error, exception);

                response.State = -2;
                response.Message = exception.Message;
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
        }
        /// <summary>
        /// 后台取消已付款未发货订单
        /// </summary>
        /// <param name="orderCancel">
        /// 订单取消对象
        /// </param>
        /// <param name="refund">
        /// 售后退款对象
        /// </param>
        /// <returns>
        /// 操作结果:0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废,4-订单未付款
        /// </returns>
        public int OrderCancelWithRefundByBackstage(Order_Cancel orderCancel, Aftersale_Refund refund)
        {
            /**
            Create Procedure sp_Order_Cancel_Refund
                @OrderID int,
                @OrderCancelCauseID int,
                @EmployeeID int = default,
                @UserID int =default, --后台操作,则为空
                @CancelDescription ntext=default,
                @RefundMethodID int, --退款方式编号(1:退至虚拟账户,2:人工退款至指定帐号)
                @ActualRefundMoney float, --实际退款金额
                @RefundDescription nvarchar(512)=default,
                @CreateTime datetime,
                @Result int output
            As
             * **/
            var paras = new List<SqlParameter>
                            {
                                this.SqlServer.CreateSqlParameter(
                                    "OrderID",
                                    SqlDbType.Int,
                                    orderCancel.OrderID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "OrderCancelCauseID",
                                    SqlDbType.Int,
                                    orderCancel.OrderCancelCauseID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "EmployeeID",
                                    SqlDbType.Int,
                                    orderCancel.EmployeeID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "CancelDescription",
                                    SqlDbType.NVarChar,
                                    orderCancel.Description,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "RefundMethodID",
                                    SqlDbType.Int,
                                    refund.RefundMethodID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "ActualRefundMoney",
                                    SqlDbType.Float,
                                    refund.ActualRefundMoney,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "RefundDescription",
                                    SqlDbType.NVarChar,
                                    refund.RefundDescription,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "CreateTime",
                                    SqlDbType.DateTime,
                                    DateTime.Now,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "Result",
                                    SqlDbType.Int,
                                    null,
                                    ParameterDirection.Output)
                            };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Order_Cancel_Refund", paras, null);
            return (int)paras.Find(p => p.ParameterName == "Result").Value;
        }
 /// <summary>
 /// 后台取消未发货为付款订单
 /// </summary>
 /// <param name="orderCancel">
 /// 订单取消对象
 /// </param>
 /// <returns>
 /// 操作结果:0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废
 /// </returns>
 public int OrderCancel(Order_Cancel orderCancel)
 {
     return this.orderCancelDA.OrderCancel(orderCancel);
 }