Пример #1
0
        private XResult <AllotAmountWithdrawApplyRequest> BuildWithdrawRequest(CommonWithdrawRequest request)
        {
            if (request == null)
            {
                return(new XResult <AllotAmountWithdrawApplyRequest>(null, ErrorCode.INVALID_ARGUMENT, new ArgumentNullException(nameof(request))));
            }

            if (!request.IsValid)
            {
                _logger.Error(TraceType.ROUTE.ToString(), CallResultStatus.ERROR.ToString(), $"{this.GetType().FullName}.{nameof(BuildWithdrawRequest)}()", "构造分账提现请求参数", $"快钱盈帐通:参数验证失败:{request.ErrorMessage}");
                return(new XResult <AllotAmountWithdrawApplyRequest>(null, ErrorCode.INVALID_ARGUMENT, new ArgumentException(request.ErrorMessage)));
            }

            var result = new AllotAmountWithdrawApplyRequest()
            {
                OutTradeNo   = request.OutTradeNo,
                PayeeId      = request.PayeeId,
                Amount       = request.Amount,
                SettlePeriod = request.SettlePeriod,
                CustomerFee  = 0,
                MerchantFee  = 0
            };

            return(new XResult <AllotAmountWithdrawApplyRequest>(result));
        }
Пример #2
0
        //private readonly IWithdrawService _withdrawService = null;

        public XResult <AllotAmountWithdrawApplyResponse> Apply(AllotAmountWithdrawApplyRequest request)
        {
            if (request == null)
            {
                return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.INVALID_ARGUMENT, new ArgumentNullException(nameof(request))));
            }

            String service = $"{this.GetType().FullName}.Apply(...)";

            if (!request.IsValid)
            {
                _logger.Trace(TraceType.BLL.ToString(), CallResultStatus.ERROR.ToString(), service, $"{nameof(request)}.IsValid", LogPhase.ACTION, $"快钱盈帐通:{request.ErrorMessage}", request);
                return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.INVALID_ARGUMENT, new ArgumentException(request.ErrorMessage)));
            }

            if (request.Amount < GlobalConfig.X99bill_YZT_WithdrawMinAmount)
            {
                return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.INVALID_ARGUMENT, new ArgumentException($"提现金额至少为{GlobalConfig.X99bill_YZT_WithdrawMinAmount.ToString()}元")));
            }

            var requestHash = $"withdraw:{request.PayeeId}".GetHashCode();

            if (_lockProvider.Exists(requestHash))
            {
                return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.SUBMIT_REPEAT));
            }

            try
            {
                if (!_lockProvider.Lock(requestHash))
                {
                    return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.SUBMIT_REPEAT));
                }

                //检查是否已开户
                if (!_personalSubAccountRepository.Exists(x => x.AppId == request.AppId && x.UID == request.PayeeId))
                {
                    _logger.Trace(TraceType.BLL.ToString(), CallResultStatus.ERROR.ToString(), service, "__CheckPersonalAccountRegisterInfo", LogPhase.ACTION, "该用户尚未开户", request);
                    return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.UN_REGISTERED));
                }

                //检查是否已绑卡
                if (!_withdrawBankCardBindInfoRepository.Exists(x => x.AppId == request.AppId && x.PayeeId == request.PayeeId))
                {
                    _logger.Trace(TraceType.BLL.ToString(), CallResultStatus.ERROR.ToString(), service, "__CheckBankCardBindInfo", LogPhase.ACTION, "该用户尚未绑卡", request);
                    return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.NO_BANKCARD_BOUND));
                }

                var existsOrder = _allotAmountWithdrawOrderRepository.Exists(x => x.OutTradeNo == request.OutTradeNo);
                if (existsOrder)
                {
                    return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.OUT_TRADE_NO_EXISTED));
                }

                var newId            = IDGenerator.GenerateID();
                var newWithdrawOrder = new AllotAmountWithdrawOrder()
                {
                    Id           = newId,
                    AppId        = request.AppId,
                    TradeNo      = newId.ToString(),
                    PayeeId      = request.PayeeId,
                    OutTradeNo   = request.OutTradeNo,
                    Amount       = request.Amount,
                    CustomerFee  = request.CustomerFee,
                    MerchantFee  = request.MerchantFee,
                    SettlePeriod = request.SettlePeriod,
                    Status       = WithdrawOrderStatus.APPLY.ToString(),
                    ApplyTime    = DateTime.Now
                };

                _allotAmountWithdrawOrderRepository.Add(newWithdrawOrder);

                var saveResult = _allotAmountWithdrawOrderRepository.SaveChanges();
                if (!saveResult.Success)
                {
                    _logger.Error(TraceType.BLL.ToString(), CallResultStatus.ERROR.ToString(), service, $"{nameof(_allotAmountWithdrawOrderRepository)}.SaveChanges()", "保存分账提现记录失败", saveResult.FirstException, newWithdrawOrder);
                    return(new XResult <AllotAmountWithdrawApplyResponse>(null, ErrorCode.DB_UPDATE_FAILED, saveResult.FirstException));
                }

                var resp = new AllotAmountWithdrawApplyResponse()
                {
                    PayeeId    = newWithdrawOrder.PayeeId,
                    OutTradeNo = newWithdrawOrder.OutTradeNo,
                    Amount     = newWithdrawOrder.Amount,
                    Status     = CommonStatus.SUCCESS.ToString(),
                    Msg        = $"申请{CommonStatus.SUCCESS.GetDescription()}"
                };

                return(new XResult <AllotAmountWithdrawApplyResponse>(resp));
            }
            finally
            {
                _lockProvider.UnLock(requestHash);
            }
        }