Пример #1
0
        public virtual async Task Recharge(long customerId, decimal amount, CusTransactionLog cusTransactionLog, CancellationToken cancellationToken = default)
        {
            await _cusTransactionLogRepo.InsertAsync(cusTransactionLog);

            var regchargeInfo = new CustomerRechargedEto
            {
                Id = customerId
                ,
                Amount = amount
                ,
                TransactionLogId = cusTransactionLog.Id
                ,
                EventSource = nameof(this.Recharge)
            };

            await _capBus.PublishAsync(EbConsts.CustomerRechagered, regchargeInfo);
        }
Пример #2
0
        public async Task Process(CustomerRechargedEto eto)
        {
            try
            {
                _uow.BeginTransaction();

                var transLog = await _cusTranlog.FindAsync(eto.TransactionLogId);

                if (transLog == null || transLog.ExchageStatus == "20")
                {
                    return;
                }

                var finance = await _cusFinanceReop.FindAsync(eto.Id);

                var newBalance = finance.Balance + eto.Amount;

                transLog.ExchageStatus  = "20";
                transLog.ChangingAmount = finance.Balance;
                transLog.ChangedAmount  = newBalance;


                await _cusFinanceReop.UpdateAsync(new CusFinance()
                {
                    Id = finance.Id, Balance = newBalance
                }, t => t.Balance);

                await _cusTranlog.UpdateAsync(transLog, t => t.ExchageStatus, t => t.ChangingAmount, t => t.ChangedAmount);

                _uow.Commit();
            }
            catch (Exception ex)
            {
                _uow.Rollback();
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                _uow.Dispose();
            }
        }