Exemplo n.º 1
0
 /// <summary>
 /// 订单取消回调
 /// </summary>
 /// <param name="result"></param>
 public static void CancelOrderCallback(OrderCancelResultCallBack result)
 {
     try
     {
         Guid orderId;
         Guid.TryParse(result.orderId, out orderId);
         LogHelper.Debug("进入 YXOrderHelper.CancelOrderCallback,Input:" + JsonConvert.SerializeObject(result));
         OrderSV.UnLockOrder(orderId);
         if (result.cancelStatus == 0)
         {
             var optResult = OrderHelper.RejectOrderRefund(orderId, result.rejectReason);
             if (optResult.ResultCode != 0)
             {
                 LogHelper.Error("YXOrderHelper.CancelOrderCallback 取消订单失败,RejectOrderRefund返回:" + JsonConvert.SerializeObject(optResult));
             }
         }
         else if (result.cancelStatus == 1)
         {
             var optResult = OrderHelper.ApproveCancelOrder(orderId);
             if (optResult.ResultCode != 0)
             {
                 LogHelper.Error("YXOrderHelper.CancelOrderCallback 取消订单失败,ApproveCancelOrder返回:" + JsonConvert.SerializeObject(optResult));
             }
         }
         else
         {
             LogHelper.Error("YXOrderHelper.CancelOrderCallback 取消订单失败,严选回调为待客服审核:" + JsonConvert.SerializeObject(result));
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("YXOrderHelper.CancelOrderCallback 异常,Input:" + JsonConvert.SerializeObject(result), ex);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 第三方电商订单取消审核结果回调
        /// </summary>
        /// <param name="result"></param>
        public static ThirdResponse CancelOrderCallback(string resultJsonStr)
        {
            LogHelper.Debug("ThirdECommerceOrderHelper.CancelOrderCallback第三方电商订单取消审核结果回调,Input:" + resultJsonStr);
            if (string.IsNullOrEmpty(resultJsonStr))
            {
                return new ThirdResponse {
                           Code = 10200, Msg = "缺少参数orderCancelResult"
                }
            }
            ;
            var result = new ThirdResponse {
                Code = 200, Msg = "ok"
            };

            try
            {
                var cancelResult = JsonConvert.DeserializeObject <ThirdOrderCancelResultCallBack>(resultJsonStr);

                if (cancelResult == null)
                {
                    return new ThirdResponse {
                               Code = 10201, Msg = "非法参数orderCancelResult"
                    }
                }
                ;
                Guid     orderId;
                DateTime auditTime;
                Guid.TryParse(cancelResult.OrderId, out orderId);
                DateTime.TryParse(cancelResult.AuditTime, out auditTime);
                if (orderId == Guid.Empty)
                {
                    return new ThirdResponse {
                               Code = 10202, Msg = "非法参数OrderId"
                    }
                }
                ;
                if (!new List <int> {
                    0, 1
                }.Contains(cancelResult.CancelStatus))
                {
                    return new ThirdResponse {
                               Code = 10203, Msg = "非法参数CancelStatus"
                    }
                }
                ;
                if (cancelResult.CancelStatus == 0 && string.IsNullOrEmpty(cancelResult.RejectReason))
                {
                    return new ThirdResponse {
                               Code = 10204, Msg = "非法参数RejectReason"
                    }
                }
                ;
                if (auditTime == DateTime.MinValue)
                {
                    return new ThirdResponse {
                               Code = 10205, Msg = "非法参数CancelStatus"
                    }
                }
                ;
                #region 判断是否第三方电商订单及获取订单信息
                var order = ThirdECOrder.ObjectSet().FirstOrDefault(o => o.OrderId == orderId);
                if (order == null)
                {
                    return new ThirdResponse {
                               Code = 10206, Msg = "未找到此订单"
                    }
                }
                ;
                if (order.CancelCallBackTime.HasValue)
                {
                    return(result);
                }
                #endregion
                #region 处理退款
                var errorMessage = string.Empty;
                OrderSV.UnLockOrder(orderId);
                if (cancelResult.CancelStatus == 0)
                {
                    var optResult = OrderHelper.RejectOrderRefund(orderId, cancelResult.RejectReason);
                    if (optResult.ResultCode != 0)
                    {
                        errorMessage = optResult.Message;
                        LogHelper.Error("ThirdECommerceOrderHelper.CancelOrderCallback 取消订单失败,RejectOrderRefund返回:" + JsonConvert.SerializeObject(optResult));
                        result = new ThirdResponse {
                            Code = 10207, Msg = "内部异常"
                        };
                    }
                    else
                    {
                        order.StateName          = "不允许取消";
                        order.CancelCallBackTime = auditTime;
                        order.StateDesc          = "订单取消审核结果回调:不允许取消," + cancelResult.RejectReason;
                    }
                }
                else
                {
                    order.StateName = "允许取消";
                    var optResult = OrderHelper.ApproveCancelOrder(orderId);
                    if (optResult.ResultCode != 0)
                    {
                        errorMessage = optResult.Message;
                        LogHelper.Error("ThirdECommerceOrderHelper.CancelOrderCallback 取消订单失败,ApproveCancelOrder返回:" + JsonConvert.SerializeObject(optResult));
                        result = new ThirdResponse {
                            Code = 10208, Msg = "内部异常"
                        };
                    }
                    else
                    {
                        order.StateName          = "允许取消";
                        order.CancelCallBackTime = auditTime;
                        order.StateDesc          = "订单取消审核结果回调:允许取消";
                    }
                }
                #endregion
                #region 保存ThirdECOrderJournal
                var thirdOrderJournal = new ThirdECOrderJournal
                {
                    Id          = Guid.NewGuid(),
                    OrderId     = order.OrderId,
                    OrderCode   = order.OrderCode,
                    SubTime     = DateTime.Now,
                    SubId       = order.SubId,
                    Name        = "取消订单审核结果回调",
                    Details     = result.Successed ? order.StateDesc : errorMessage,
                    Json        = resultJsonStr,
                    EntityState = EntityState.Added
                };
                ContextFactory.CurrentThreadContext.SaveObject(thirdOrderJournal);
                #endregion
                int count = ContextFactory.CurrentThreadContext.SaveChanges();
                if (count == 0)
                {
                    LogHelper.Error(string.Format("ThirdECommerceOrderHelper.CancelOrderCallback第三方电商订单取消审核结果回调数据保存失败,入参:{0}", resultJsonStr));
                    return(new ThirdResponse {
                        Code = 10209, Msg = "内部异常"
                    });
                }
            }
            catch (JsonReaderException ex)
            {
                LogHelper.Error("ThirdECommerceOrderHelper.CancelOrderCallback第三方电商订单取消审核结果回调反序列化异常,Input:" + resultJsonStr, ex);
                return(new ThirdResponse <ThirdOrderCancelResult> {
                    Msg = "反序列化异常"
                });
            }
            catch (Exception ex)
            {
                LogHelper.Error("ThirdECommerceOrderHelper.CancelOrderCallback第三方电商订单取消审核结果回调异常,Input:" + resultJsonStr, ex);
                return(new ThirdResponse {
                    Code = 10210, Msg = "内部异常"
                });
            }
            return(result);
        }