
using New_College.IServices;
using New_College.Model.Models;
using New_College.Services.BASE;
using New_College.IRepository.Base;
using New_College.IRepository.UnitOfWork;
using New_College.Model.ViewModels;
using System.Threading.Tasks;
using New_College.Common;
using New_College.IRepository;
using System.Linq;
using YIJIYI.Core.Common.Helper;
using System;
using New_College.Model;
using New_College.Common.Helper;
using Microsoft.Extensions.Options;
using Essensoft.AspNetCore.Payment.WeChatPay;
using Essensoft.AspNetCore.Payment.Alipay;
using Essensoft.AspNetCore.Payment.WeChatPay.Notify;
using Microsoft.Extensions.Logging;
using Essensoft.AspNetCore.Payment.Alipay.Domain;
using Essensoft.AspNetCore.Payment.Alipay.Request;
using System.Collections.Generic;
using LinqKit;
using System.Collections.Specialized;
using Org.BouncyCastle.Asn1.Ocsp;
using Essensoft.AspNetCore.Payment.WeChatPay.Response;
using Essensoft.AspNetCore.Payment.WeChatPay.Request;
using Microsoft.AspNetCore.Http;

namespace New_College.Services
{
    public class V_OrderInfoServices : BaseServices<V_OrderInfo>, IV_OrderInfoServices
    {
        private readonly IWeChatPayClient _client;
        private readonly IOptions<WeChatPayOptions> _optionsAccessor;
        private readonly IAlipayClient alipayClient;
        private readonly IOptions<AlipayOptions> alipayoptions;

        private readonly IBaseRepository<V_OrderInfo> _dal;
        private readonly IUnitOfWork _unitOfWork;
        private readonly IV_CustomerInfoRepository v_CustomerInfoRepository;
        private readonly IV_VipCardInfoRepository v_VipCardInfoRepository;
        private readonly IV_VipCardTypeRepository v_VipCardTypeRepository;

        private readonly ILogger<V_OrderInfo> logger;

        public int Nums = 10;
        public V_OrderInfoServices(IWeChatPayClient client, IOptions<WeChatPayOptions> optionsAccessor
            , IAlipayClient IAlipayClient, IOptions<AlipayOptions> alipayopt
            , IBaseRepository<V_OrderInfo> dal
            , IUnitOfWork IUnitOfWork
            , IV_CustomerInfoRepository IV_CustomerInfoRepository
            , IV_VipCardInfoRepository IV_VipCardInfoRepository
            , IV_VipCardTypeRepository IV_VipCardTypeRepository
            , ILogger<V_OrderInfo> loggers
            )
        {
            _client = client;
            _optionsAccessor = optionsAccessor;
            alipayClient = IAlipayClient;
            alipayoptions = alipayopt;
            this._dal = dal;
            _unitOfWork = IUnitOfWork;
            v_CustomerInfoRepository = IV_CustomerInfoRepository;
            v_VipCardInfoRepository = IV_VipCardInfoRepository;
            v_VipCardTypeRepository = IV_VipCardTypeRepository;
            logger = loggers;
            base.BaseDal = dal;
        }

        /// <summary>
        /// 下订单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<CreateOrderModel> CreateOrder(UniOrderQuery query)
        {
            var response = new CreateOrderModel();
            string OrderNo = OrderGenerateHelper.GenerateOrderNo("ZY");
            try
            {
                _unitOfWork.BeginTran();
                var customer = await v_CustomerInfoRepository.QueryById(query.StudentId);
                var createtime = TimeUtil.GetCstDateTime();
                var baseResult = await _dal.Add(new V_OrderInfo
                {
                    //out_trade_no = payNum,
                    //PayType = 2,
                    OrderId = OrderNo,
                    CardTypeId = query.CardTypeId,
                    Status = EnumOrderType.payment,
                    CustomerId = customer.Id,
                    Price = query.total_fee,
                    PayPrice = query.total_fee,
                    Name = "志愿好帮手VIP购买",
                    //CardNo = code,
                    //CardId = addcard
                    CreateTime = createtime
                });
                if (baseResult > 0)
                {
                    _unitOfWork.CommitTran();
                    response.OrderId = OrderNo;
                    response.Status = EnumOrderType.payment;
                    response.CreateTime = createtime.ToString("yyyy-MM-dd HH:mm:ss");
                }
            }
            catch (System.Exception)
            {
                _unitOfWork.RollbackTran();
                response.msg = "订单创建失败";
                response.success = false;
                return response;
            }
            return response;
        }

        /// <summary>
        /// 订单查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<PageModel<OrderInfoQuery>>> GetOrderInfoByPage(SearchOrderQuery query)
        {
            var wheres = PredicateBuilder.New<V_OrderInfo>();
            wheres = wheres.And(x => x.IsDelete == false);
            //根据卡号查询
            if (!string.IsNullOrWhiteSpace(query.CardNo))
                wheres = wheres.And(x => x.CardNo.Contains(query.CardNo));

            //根据支付状态查询

            //  var status = Enum.Parse(typeof(EnumOrderType), query.Status.ToString());// (EnumOrderType)query.Status;
            if (query.Status > -2)
            {
                var status = (EnumOrderType)query.Status;
                wheres = wheres.And(x => x.Status == status);
            }


            //根据支付方式查询
            if (query.PayType > -1)
            {
                var payType = (EnumPayType)query.PayType;
                wheres = wheres.And(x => x.PayType == payType);
            }
            //根据out_trade_no查询
            if (!string.IsNullOrWhiteSpace(query.out_trade_no))
                wheres = wheres.And(x => x.out_trade_no.Contains(query.out_trade_no));


            //根据电话查询
            if (!string.IsNullOrWhiteSpace(query.Phone))
            {
                var CoustomerId = await v_CustomerInfoRepository.Query(x => x.Phone.Contains(query.Phone));
                var ids = CoustomerId.Select(x => x.Id).ToList();
                if (CoustomerId != null)
                    wheres = wheres.And(x => ids.Contains(x.CustomerId));
            }

            //根据卡片类别查询
            if (query.CardTypeId > 0)
                wheres = wheres.And(x => x.CardTypeId == query.CardTypeId);

            var info = await _dal.QueryPage(wheres, query.PageIndex, query.PageSize);
            if (info.data.Count <= 0)
                return new MessageModel<PageModel<OrderInfoQuery>>()
                {
                    success = false,
                    msg = "获取失败"
                };
            var idsCard = info.data.Select(x => x.CardTypeId).ToList();
            var idsCoustomer = info.data.Select(x => x.CustomerId).ToList();
            var listCard = await v_VipCardTypeRepository.Query(x => idsCard.Contains(x.Id) && x.IsDelete == false);
            var listCoustomer = await v_CustomerInfoRepository.Query(x => idsCoustomer.Contains(x.Id) && x.IsDelete == false);
            PageModel<OrderInfoQuery> pageModel = new PageModel<OrderInfoQuery>() { };
            List<OrderInfoQuery> list = new List<OrderInfoQuery>() { };
            foreach (var item in info.data)
            {
                var CardOne = listCard.Where(x => x.Id == item.CardTypeId).FirstOrDefault();
                if (CardOne == null)
                    continue;
                var CoustomerOne = listCoustomer.Where(x => x.Id == item.CustomerId).FirstOrDefault();
                if (CoustomerOne == null)
                    continue;

                list.Add(new OrderInfoQuery()
                {
                    CardId = item.Id,
                    PayPrice = item.PayPrice,
                    Price = item.Price,
                    CardNo = item.CardNo,
                    CardTypeName = CardOne.Name,
                    OrderId = item.OrderId,
                    CustomerName = CoustomerOne.NickName,
                    Name = item.Name,
                    //支付状态
                    StatusName = item.Status.GetDescription(),
                    out_trade_no = item.out_trade_no,
                    //支付方式
                    PayTypeName = item.PayType.GetDescription(),

                    Phone = CoustomerOne.Phone,
                });
            }
            pageModel.data = list;
            pageModel.dataCount = info.dataCount;
            pageModel.page = info.page;
            pageModel.pageCount = info.pageCount;
            pageModel.PageSize = info.PageSize;
            return new MessageModel<PageModel<OrderInfoQuery>>()
            {
                success = true,
                msg = "获取成功",
                response = pageModel
            };
        }

        //public async Task<MessageModel<>>

        /// <summary>
        /// 支付订单回调修改状态
        /// </summary>
        /// <param name="orderNo"></param>
        /// <param name="payType"></param>
        /// <returns></returns>
        public async Task<bool> UpdateOrderStatus(string orderNo, EnumPayType payType, string trade_no)
        {
            bool status = false;
            var orderinfo = await _dal.Query(e => e.OrderId == orderNo);
            if (orderinfo.Any())
            {
                var cardtype = await v_VipCardTypeRepository.QueryById(orderinfo.FirstOrDefault().CardTypeId);
                if (cardtype == null)
                    return false;
                var code = RadomHelper.GetGuid();
                try
                {
                    _unitOfWork.BeginTran();
                    var addcard = await v_VipCardInfoRepository.Add(new V_VipCardInfo()
                    {
                        CardTypeId = cardtype.Id,
                        CardTypeName = cardtype.Name,
                        Code = code,
                        IsBind = 1,
                        Money = orderinfo.FirstOrDefault().PayPrice,
                        Day = cardtype.Day,
                        EndTime = DateTime.Now.AddDays(cardtype.Day)
                    });
                    if (addcard > 0)
                    {
                        var model = orderinfo.FirstOrDefault();
                        model.PayType = payType;
                        model.ModifyTime = TimeUtil.GetCstDateTime();
                        model.Status = EnumOrderType.payoff;
                        model.out_trade_no = trade_no;
                        var cc = await _dal.Update(model);
                        if (cc)
                        {
                            _unitOfWork.CommitTran();
                            status = true;
                        }
                    }
                }
                catch (Exception)
                {
                    _unitOfWork.RollbackTran();
                    return status;
                }
            }
            return status;
        }

        /// <summary>
        /// 唤醒微信H5支付
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<string>> WechatPubPay(WeChatPayQuery query)
        {
            string out_trade_no = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            logger.LogInformation(out_trade_no + "唤醒支付");
            WeChatPayPayRequest viewModel = new WeChatPayPayRequest() { };
            //viewModel.NotifyUrl = string.Format("{0}/api/front/WeixinPay/PayNotify", PayInfoQuery.ApiUrl);
            viewModel.NotifyUrl = string.Format("{0}/api/front/HFivePay/WeChartOrderConfirm", PayInfoQuery.ApiUrl);
            //viewModel.NotifyUrl = string.Format("{0}/api/front/HFivePay/WeChartOrderConfirm?out_trade_no={1}", PayInfoQuery.ApiUrl, out_trade_no);
            viewModel.SpBillCreateIp = PayInfoQuery.CreateIp;
            viewModel.OutTradeNo = out_trade_no;
            viewModel.TotalFee = Convert.ToInt32(query.Money*100);
            viewModel.Body = "壹志愿VIP";
            viewModel.TradeType = "MWEB";

            var response = await WeChatPay.GetMwebUrl(_client, _optionsAccessor, viewModel);
            if (response.ReturnCode == "SUCCESS" && response.ReturnMsg == "OK")
            {
                try
                {
                    //_unitOfWork.BeginTran();
                    var order = await _dal.Add(new V_OrderInfo
                    {
                        out_trade_no = out_trade_no,
                        PayType = EnumPayType.WeiPay,
                        CardTypeId = query.CardTypeId,
                        Status = EnumOrderType.payment,
                        CustomerId = query.CustomerId,
                        Price = query.Money,
                        PayPrice = query.Money,
                        Name = "壹志愿好帮手VIP开通",
                        CardNo = "0",
                        CardId = 0
                    });
                    if (order > 0)
                    {
                        logger.LogInformation(out_trade_no + "唤醒成功");
                        //_unitOfWork.CommitTran();
                        return new MessageModel<string>()
                        {
                            success = true,
                            msg = "成功",
                            response = string.Format("{0}&redirect_url={1}", response.MwebUrl, string.Format("{0}?out_trade_no={1}", string.Format("{0}/api/front/HFivePay/WeChartOrderConfirm", PayInfoQuery.ApiUrl), out_trade_no))
                        };
                    }
                }
                catch (Exception ex)
                {
                    //_unitOfWork.RollbackTran();
                    return new MessageModel<string>() { success = false, msg = "唤醒微信失败，请重试" };
                }


            }
            return new MessageModel<string>() { success = false, msg = "唤醒微信失败，请重试" };
        }

        /// <summary>
        /// 微信订单查询确认  传用户Id
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<bool>> WeChatPayStatus(IdQuery query)
        {
            var orderinfo = await _dal.Query(x => x.CustomerId == query.Id && x.IsDelete == false && x.PayType == EnumPayType.WeiPay);
            if (orderinfo.Count <= 0)
                return new MessageModel<bool>() { success = false, msg = "未查询到用户订单" };
            var result = orderinfo.OrderByDescending(x => x.Id).FirstOrDefault();
            if (result.Status == EnumOrderType.payoff)
            {
                return new MessageModel<bool>() { success = true, msg = "已支付成功" };
            }
            var request = new WeChatPayOrderQueryRequest
            {
                OutTradeNo = result.out_trade_no
            };
            //如果订单状态是
            var response = await _client.ExecuteAsync(request, _optionsAccessor.Value);
            if (response.TradeState == "NOTPAY")
            {
                return new MessageModel<bool>() { success = false, msg = "您还未支付订单，请重新支付" };
            }
            if (response.ReturnCode == "SUCCESS" && response.ReturnMsg == "OK")
            {
                var payresult = await PaySuccess(result);
                if (payresult.success == true)
                {
                    logger.LogInformation("SUCCESS：" + result.out_trade_no);
                    return new MessageModel<bool>() { success = true, msg = "支付成功" };
                }
                else
                {
                    return new MessageModel<bool>() { success = false, msg = "支付成功，业务处理错误，请联系客服" };
                }
            }
            return new MessageModel<bool>() { success = false, msg = "您还未支付订单，请重新支付或联系客服" };
        }

        /// <summary>
        /// 支付宝 订单确认
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<bool>> AliPayStatus(IdQuery query)
        {
            logger.LogInformation("订单确认（支付宝）");
            var orderinfo = await _dal.Query(x => x.CustomerId == query.Id && x.IsDelete == false && x.PayType == EnumPayType.AliPay);
            if (orderinfo.Count <= 0)
                return new MessageModel<bool>() { success = false, msg = "未查询到用户订单" };
            var result = orderinfo.OrderByDescending(x => x.CreateTime).FirstOrDefault();
            if (result.Status == EnumOrderType.payoff)
            {
                return new MessageModel<bool>() { success = true, msg = "已支付成功" };
            }
            else
            {
                return new MessageModel<bool>() { success = false, msg = "未支付，如有疑问请联系客服" };
            }

            //var model = new AlipayTradeWapPayModel
            //{
            //    OutTradeNo = query.out_trade_no,
            //};
            //var req = new AlipayTradeWapPayRequest();
            //req.SetBizModel(model);
            //var response = await alipayClient.PageExecuteAsync(req, alipayoptions.Value);
            //logger.LogInformation(query.out_trade_no + "返回参数" + response.Body);
            ////response.Body
            ////根绝回调的返回  确认是否支付成功  此处还存在问题----------------------------------
            ////if(response.)
            //var payresult = await PaySuccess(result);
            //if (payresult.success == true)
            //{
            //    logger.LogInformation("SUCCESS(支付宝订单确认成功)：" + result.out_trade_no);
            //    return new MessageModel<bool>() { success = true, msg = "支付成功" };
            //}
            //else
            //{
            //    return new MessageModel<bool>() { success = false, msg = "支付成功，业务处理错误，请联系客服" };
            //}
        }

        ///// <summary>
        ///// 微信订单回调确认
        ///// </summary>
        ///// <param name="query"></param>
        ///// <returns></returns>
        //public async Task<MessageModel<string>> WeChartOrderConfirm(XmlQuery query)
        //{
        //    string xmlstr = "";
        //    try
        //    {
        //        var response = XmlSerializeHelper.XMLToObject<WeChatPayOrderResponse>(query.xml);
        //        if (response == null)
        //            return new MessageModel<string>() { success = false, msg = "订单确认失败", response = xmlstr };
        //        var result = (await _dal.Query(x => x.out_trade_no == response.out_trade_no && x.PayType == EnumPayType.WeiPay)).FirstOrDefault();
        //        if (result != null && result.Status == EnumOrderType.payoff)
        //        {
        //            xmlstr = "<xml>< return_code >< ![CDATA[SUCCESS]] ></ return_code >< return_msg >< ![CDATA[OK]] ></return_msg </ xml>";
        //            return new MessageModel<string>() { success = true, msg = "成功", response = xmlstr };
        //        }
        //        if (response.result_code == "SUCCESS")
        //        {
        //            //记录流水
        //            var payresult = await PaySuccess(result);
        //            if (payresult.success == true)
        //            {
        //                xmlstr = "<xml>< return_code >< ![CDATA[SUCCESS]] ></ return_code >< return_msg >< ![CDATA[OK]] ></return_msg </ xml>";
        //                return new MessageModel<string>() { success = true, msg = "成功", response = xmlstr };
        //            }
        //            else
        //            {
        //                payresult.response = xmlstr;
        //                return payresult;
        //            }

        //        }
        //        return new MessageModel<string>() { success = false, msg = "失败", response = xmlstr };
        //    }
        //    catch (Exception ex)
        //    {
        //        return new MessageModel<string>() { success = false, msg = "失败", response = xmlstr };
        //    }
        //}

        /// <summary>
        /// 支付成功后操作
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<string>> PaySuccess(V_OrderInfo query)
        {
            //生成一个卡号
            //修改订单状态
            try
            {
                var cardinfo = (await v_VipCardInfoRepository.QuerySql("SELECT Code FROM `V_VipCardInfo` where IsDelete=0")).Select(x => x.Code).ToList();

                var code = GetNumbers(cardinfo, Nums);

                if (string.IsNullOrWhiteSpace(code))
                {
                    logger.LogWarning("用户Id" + query.CustomerId + "的用户，支付成功，卡号生成失败，请联系客服");
                    return new MessageModel<string>() { success = false, msg = "支付成功，卡号生成失败，请联系客服" };
                }

                var cardtype = await v_VipCardTypeRepository.QueryById(query.CardTypeId);
                if (cardtype == null)
                {
                    logger.LogWarning("用户Id" + query.CustomerId + "的用户，支付成功，卡类型有误，请联系客服");
                    return new MessageModel<string>() { success = false, msg = "支付成功，卡类型有误，请联系客服" };
                }

                _unitOfWork.BeginTran();
                var cardadd = await v_VipCardInfoRepository.Add(new V_VipCardInfo()
                {
                    CardTypeId = cardtype.Id,
                    CardTypeName = cardtype.Name,
                    Code = code,
                    IsBind = 1,
                    Money = query.PayPrice,
                    Day = cardtype.Day,
                    EndTime = DateTime.Now.AddDays(cardtype.Day)
                });
                if (cardadd > 0)
                {
                    query.Status = EnumOrderType.payoff;
                    query.CardNo = code;
                    query.CardId = cardadd;
                    var updateorder = await _dal.Update(query);
                    if (updateorder)
                    {
                        //修改用户信息
                        var customerinfo = await v_CustomerInfoRepository.QueryById(query.CustomerId);
                        if (customerinfo == null)
                        {
                            _unitOfWork.RollbackTran();
                            logger.LogWarning("用户Id" + query.CustomerId + "的用户，支付成功，会员卡创建成功，用户信息不存在");
                            return new MessageModel<string>() { success = false, msg = "支付成功，会员卡创建成功，用户信息不存在" };
                        }
                        customerinfo.IsVIP = true;
                        customerinfo.VipCode = code;
                        var updateinfo = await v_CustomerInfoRepository.Update(customerinfo);
                        if (updateinfo)
                        {
                            _unitOfWork.CommitTran();
                            return new MessageModel<string>() { success = true, msg = "成功" };
                        }
                        else
                        {
                            logger.LogWarning("用户Id" + query.CustomerId + "的用户，支付成功，会员卡创建成功，用户信息修改失败");
                            _unitOfWork.RollbackTran();
                            return new MessageModel<string>() { success = false, msg = "支付成功，会员卡创建成功，用户信息修改失败" };
                        }
                    }
                    logger.LogWarning("用户Id" + query.CustomerId + "的用户，支付成功，订单修改失败，请联系客服");
                    return new MessageModel<string>() { success = false, msg = "支付成功，订单修改失败，请联系客服" };
                }
                logger.LogWarning("用户Id" + query.CustomerId + "的用户，支付成功，订单修改失败，请联系客服");
                return new MessageModel<string>() { success = false, msg = "支付成功，会员卡创建失败，请联系客服" };
            }
            catch (Exception)
            {
                _unitOfWork.RollbackTran();
                logger.LogWarning("用户Id" + query.CustomerId + "的用户，支付成功，订单修改失败，请联系客服");
                return new MessageModel<string>() { success = false, msg = "支付成功，订单修改失败，请联系客服" };
            }
        }

        /// <summary>
        /// 生成卡号 失败直接继续生成
        /// </summary>
        /// <param name="cardinfo"></param>
        /// <param name="Nums"></param>
        /// <returns></returns>
        public string GetNumbers(List<string> cardinfo, int Nums)
        {
            var code = "";
            for (int i = 0; i < 100; i++)
            {
                var newcode = GenerateCardNumberHelper.GenerateCardNumber("888", Nums);
                cardinfo.Add(newcode);
                var isUnique = cardinfo.GroupBy(x => x).All(g => g.Count() == 1);
                if (isUnique)
                {
                    code = newcode;
                    break;
                }
                else
                {
                    Nums += 1;
                    GetNumbers(cardinfo, Nums);
                }
            }
            return code;
        }

        /// <summary>
        /// 支付宝H5支付
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<AliOrderResult>> AliH5Pay(WeChatPayQuery query)
        {
            logger.LogInformation("唤醒支付宝" + query.CustomerId);
            AliOrderResult aliOrder = new AliOrderResult();
            try
            {
                string out_trade_no = query.CustomerId + "1" + DateTime.Now.ToString("yyyyMMddHHmmssfff");

                AlipayTradeWapPayQuery viewMode = new AlipayTradeWapPayQuery() { };
                string NotifyUrl = string.Format("{0}/api/front/HFivePay/AliOrderConfirm", PayInfoQuery.ApiUrl);
                //生成订单
                //或者失败
                var model = new AlipayTradeWapPayModel
                {
                    Body = "壹志愿VIP",
                    Subject = "壹志愿VIP",
                    TotalAmount = query.Money.ToString(),
                    OutTradeNo = out_trade_no,
                    ProductCode = "QUICK_WAP_WAY",
                    TimeoutExpress = "90m"
                };
                var req = new AlipayTradeWapPayRequest();
                req.SetBizModel(model);
                req.SetNotifyUrl(NotifyUrl);
                req.SetReturnUrl("https://payment.yrtsedu.cn/alipay.html");
                var response = await alipayClient.PageExecuteAsync(req, alipayoptions.Value);
                if (response == null)
                {
                    logger.LogInformation("唤醒失败" + out_trade_no);
                    return new MessageModel<AliOrderResult>() { success = false, msg = "支付宝唤醒失败" };
                }
                logger.LogInformation("唤醒成功" + out_trade_no);
                //_unitOfWork.BeginTran();
                var order = await _dal.Add(new V_OrderInfo
                {
                    out_trade_no = out_trade_no,
                    PayType = EnumPayType.AliPay,
                    CardTypeId = query.CardTypeId,
                    Status = EnumOrderType.payment,
                    CustomerId = query.CustomerId,
                    Price = query.Money,
                    PayPrice = query.Money,
                    Name = "壹志愿好帮手VIP开通",
                    CardNo = "0",
                    CardId = 0
                });
                if (order > 0)
                {
                    logger.LogInformation(out_trade_no + "唤醒成功");
                    //_unitOfWork.CommitTran();
                    return new MessageModel<AliOrderResult>()
                    {
                        //?payType='alipay'&&success=true&&customerId=" + query.CustomerId + "&&out_trade_no=" + out_trade_no
                        success = true,
                        msg = "获取成功",
                        response = new AliOrderResult()
                        {
                            Body = response.Body,
                            CustomerId = query.CustomerId,
                            out_trade_no = out_trade_no,
                            PayType = "alipay",
                            Success = true
                        }
                    };
                }
                return new MessageModel<AliOrderResult>() { success = false, msg = "订单添加失败" };
            }
            catch (Exception ex)
            {
                //_unitOfWork.RollbackTran();
                logger.LogInformation("唤醒异常" + ex.ToString());
                return new MessageModel<AliOrderResult>() { success = false, msg = "支付宝唤醒失败" };
            }
        }


    }
}