示例#1
0
        /// <summary>
        /// 充值
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <AppSrvResult <SimpleDto <string> > > RechargeAsync(long id, CustomerRechargeDto input)
        {
            var customer = await _customerRepo.FindAsync(id);

            if (customer == null)
            {
                return(Problem(HttpStatusCode.NotFound, "不存在该账号"));
            }

            var cusTransactionLog = new CustomerTransactionLog()
            {
                Id = IdGenerater.GetNextId(IdGenerater.DatacenterId, IdGenerater.WorkerId)
                ,
                CustomerId = customer.Id
                ,
                Account = customer.Account
                ,
                ExchangeType = ExchangeTypeEnum.Recharge
                ,
                Remark = ""
                ,
                Amount = input.Amount
                ,
                ExchageStatus = ExchageStatusEnum.Processing
            };

            await _cusManagerService.RechargeAsync(cusTransactionLog);

            return(new SimpleDto <string>(cusTransactionLog.Id.ToString()));
        }
示例#2
0
        /// <summary>
        /// 充值
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <AppSrvResult <SimpleDto <string> > > RechargeAsync(long id, CustomerRechargeDto input)
        {
            var customer = await _customerRepo.FindAsync(id);

            if (customer == null)
            {
                return(Problem(HttpStatusCode.NotFound, "不存在该账号"));
            }

            var cusTransactionLog = new CustomerTransactionLog()
            {
                Id            = IdGenerater.GetNextId(),
                CustomerId    = customer.Id,
                Account       = customer.Account,
                ExchangeType  = ExchangeTypeEnum.Recharge,
                Remark        = "",
                Amount        = input.Amount,
                ExchageStatus = ExchageStatusEnum.Processing
            };

            await _cusTransactionLogRepo.InsertAsync(cusTransactionLog);

            //发布充值事件
            var eventId   = IdGenerater.GetNextId();
            var eventData = new CustomerRechargedEvent.EventData()
            {
                CustomerId = cusTransactionLog.CustomerId, TransactionLogId = cusTransactionLog.Id, Amount = cusTransactionLog.Amount
            };
            var eventSource = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;
            await _eventPublisher.PublishAsync(new CustomerRechargedEvent(eventId, eventData, eventSource));

            return(new SimpleDto <string>(cusTransactionLog.Id.ToString()));
        }
示例#3
0
        public virtual async Task RechargeAsync(CustomerTransactionLog cusTransactionLog, CancellationToken cancellationToken = default)
        {
            await _cusTransactionLogRepo.InsertAsync(cusTransactionLog);

            //发布充值事件
            var eventId   = IdGenerater.GetNextId(IdGenerater.DatacenterId, IdGenerater.WorkerId);
            var eventData = new CustomerRechargedEvent.EventData()
            {
                CustomerId = cusTransactionLog.CustomerId, TransactionLogId = cusTransactionLog.Id, Amount = cusTransactionLog.Amount
            };
            var eventSource = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName;
            await _eventPublisher.PublishAsync(new CustomerRechargedEvent(eventId, eventData, eventSource));
        }
示例#4
0
        public virtual async Task ProcessPayingAsync(long transactionLogId, long customerId, decimal amount)
        {
            bool paidResult = false;

            var transLog = await _cusTransactionLogRepo.FindAsync(transactionLogId);

            if (transLog != null)
            {
                return;
            }

            var account = await _cusRepo.FetchAsync(x => x.Account, x => x.Id == customerId);

            var finance = await _cusFinaceRepo.FindAsync(customerId, noTracking : false);

            var originalBalance = finance.Balance;
            var newBalance      = originalBalance - amount;

            if (newBalance >= 0)
            {
                finance.Balance = newBalance;
                await _cusFinaceRepo.UpdateAsync(finance);

                transLog = new CustomerTransactionLog
                {
                    Id = transactionLogId
                    ,
                    CustomerId = customerId
                    ,
                    Account = account
                    ,
                    ChangingAmount = originalBalance
                    ,
                    Amount = 0 - amount
                    ,
                    ChangedAmount = newBalance
                    ,
                    ExchangeType = ExchangeTypeEnum.Order
                    ,
                    ExchageStatus = ExchageStatusEnum.Finished
                };

                await _cusTransactionLogRepo.InsertAsync(transLog);

                paidResult = true;
            }

            //_eventPublisher.PublishAsync()
        }