public ServiceResult <PrePayExistedOrderOM> PrePayExistedOrder(PrePayExistedOrderIM im) { return(new ServiceResult <PrePayExistedOrderOM> { Data = new OrderComponent().PrePayExistedOrder(this.GetUser(), im) }); }
public PrePayExistedOrderOM PrePayExistedOrder(UserAccount user, PrePayExistedOrderIM im) { var orderno = im.OrderNo; var order = RedisHelper.Get <RedisOrderDTO>($"fiiipos:order:{orderno}"); if (order == null) { throw im.Type == PrePayExistedOrderIMType.ScanCode ? new CommonException(ReasonCode.INVALID_QRCODE, MessageResources.InvalidQRCode) : new CommonException(ReasonCode.GENERAL_ERROR, MessageResources.OrderNotFound); } //if (order.ExpiredTime < DateTime.UtcNow) // throw new ApplicationException(Resources.订单已过期); //if (order.Status != OrderStatus.Pending) // throw new ApplicationException(Resources.订单已完成或者已退款); if (order.UserId != Guid.Empty) { if (order.UserId != user.Id) { throw new ApplicationException(MessageResources.AccountNotMatch); } } if (new OrderDAC().GetByOrderNo(orderno) != null) { throw new ApplicationException(MessageResources.OrderComplated); } var userWallet = new UserWalletDAC().GetByAccountId(user.Id, order.CryptoId) ?? new UserWallet { Balance = 0, FrozenBalance = 0 }; var coin = new CryptocurrencyDAC().GetById(order.CryptoId); var exchangeRate = GetExchangeRate(order.CountryId, order.FiatCurrency, coin); decimal fiatTotalAmount = (order.FiatAmount * (1 + order.Markup)).ToSpecificDecimal(4); decimal cryptoAmount = (fiatTotalAmount / exchangeRate).ToSpecificDecimal(coin.DecimalPlace); return(new PrePayExistedOrderOM { Amount = cryptoAmount.ToString(coin.DecimalPlace), Currency = coin.Code, MerchantName = new MerchantAccountDAC().GetById(order.MerchantGuid).MerchantName, Balance = userWallet.Balance.ToString(coin.DecimalPlace), CoinId = order.CryptoId }); }