Beispiel #1
0
        private static bool Refund(OnlineOrder model, string certpath)
        {
            IOnlineOrder factory       = OnlineOrderFactory.GetFactory();
            bool         refundResult  = false;
            string       refundOrderId = IdGenerator.Instance.GetId().ToString();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    refundResult = factory.RefundSuccess(model.OrderID, refundOrderId, dbOperator);
                    if (!refundResult)
                    {
                        throw new MyException("更改订单为退款成功时失败");
                    }
                    switch (model.PaymentChannel)
                    {
                    case PaymentChannel.WeiXinPay: {
                        string refundAmount = ((int)(model.Amount * 100)).ToString();
                        refundResult = PaymentServices.Refund(model.CompanyID, model.SerialNumber, model.OrderID.ToString(), refundAmount, refundAmount, refundOrderId, certpath);
                        TxtLogServices.WriteTxtLogEx("OnlineOrderServices", string.Format("方法名:{0},操作类型:{1},订单编号:{2},备注:{3} {4}", "Refund", "订单退款处理", model.OrderID, model.SerialNumber.ToString(), (model.Amount / 100).ToString("F2"), refundOrderId));
                        if (!refundResult)
                        {
                            throw new MyException("微信退款失败");
                        }
                        break;
                    }

                    case PaymentChannel.AliPay:
                    {
                        refundResult = AliPayApiServices.RefundRequest(model.CompanyID, model.OrderID.ToString(), model.SerialNumber.ToString(), model.Amount.ToString("F2"), "车场网络异常", refundOrderId);
                        TxtLogServices.WriteTxtLogEx("OnlineOrderServices", string.Format("方法名:{0},操作类型:{1},订单编号:{2},备注:{3} {4}", "Refund", "订单退款处理", model.OrderID, model.SerialNumber.ToString(), (model.Amount / 100).ToString("F2"), refundOrderId));
                        if (!refundResult)
                        {
                            throw new MyException("支付宝退款失败");
                        }
                        break;
                    }

                    default: throw new MyException("退款渠道不正确");
                    }
                    dbOperator.CommitTransaction();
                    TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "方法名:{0},操作类型:{1},订单编号:{2},备注:{3}", "Refund", "订单退款处理", model.OrderID, "退款成功");
                }
                catch (Exception ex)
                {
                    refundResult = false;
                    dbOperator.RollbackTransaction();
                    ExceptionsServices.AddExceptionToDbAndTxt("OnlineOrderServices", string.Format("订单退款失败,订单编号{0},描述:{1}", model.OrderID, ex.Message), ex, LogFrom.WeiXin);
                }
                if (!refundResult)
                {
                    factory.RefundFail(model.OrderID);
                }
                if (model.PaymentChannel == PaymentChannel.WeiXinPay)
                {
                    if (!refundResult)
                    {
                        switch (model.OrderType)
                        {
                        case OnlineOrderType.PkBitBooking: {
                            TemplateMessageServices.SendBookingBitNoRefundFail(model.CompanyID, model.OrderID.ToString(), "车场网络异常", model.Amount, model.PayAccount);
                            break;
                        }

                        case OnlineOrderType.SellerRecharge: {
                            TemplateMessageServices.SendSellerRechargeRefundFail(model.CompanyID, model.OrderID.ToString(), "车场网络异常", model.Amount, model.PayAccount);
                            break;
                        }

                        default: {
                            TemplateMessageServices.SendParkingRefundFail(model.CompanyID, model.OrderID.ToString(), "车场网络异常", model.Amount, model.PayAccount);
                            break;
                        }
                        }
                    }
                    else
                    {
                        string message = string.IsNullOrWhiteSpace(model.Remark) ? "车场网络异常" : model.Remark;
                        switch (model.OrderType)
                        {
                        case OnlineOrderType.PkBitBooking:
                        {
                            TemplateMessageServices.SendBookingBitNoRefundSuccess(model.CompanyID, model.OrderID.ToString(), message, model.Amount, model.PayAccount);
                            break;
                        }

                        case OnlineOrderType.SellerRecharge:
                        {
                            TemplateMessageServices.SendSellerRechargeRefundSuccess(model.CompanyID, model.OrderID.ToString(), message, model.Amount, model.PayAccount);
                            break;
                        }

                        default:
                        {
                            TemplateMessageServices.SendParkingRefundSuccess(model.CompanyID, model.OrderID.ToString(), message, model.Amount, model.PayAccount);
                            break;
                        }
                        }
                    }
                }
            }
            return(refundResult);
        }