Ejemplo n.º 1
0
        public async Task <WalletAction> RechargeAsync(
            Guid?tenantId,
            Guid userId,
            Guid rechargeProductId,
            int productQuantity,
            string orderId,
            int creditAmount,
            decimal paidAmount,
            string title,
            string description
            )
        {
            using (CurrentTenant.Change(tenantId))
            {
                var coinPurchased = new WalletAction(GuidGenerator.Create(), tenantId, userId, rechargeProductId, productQuantity, orderId, creditAmount, paidAmount);

                await _repository.InsertAsync(coinPurchased);

                // 修改销售数量
                var product = await _productRepository.GetAsync(rechargeProductId);

                product.SetSoldQuantity(product.SoldQuantity + productQuantity);

                // 钱包
                var wallet = await _walletRepository.GetByUserIdAsync(userId);

                wallet.IncBalance(creditAmount);

                // 写日志
                var log = new WalletLog(GuidGenerator.Create(), tenantId, userId, "Recharge", false, creditAmount, wallet.Balance, title, description);
                await _walletLogRepository.InsertAsync(log);

                return(coinPurchased);
            }
        }
Ejemplo n.º 2
0
        public async Task <RechargeProductDto> GetAsync(Guid id)
        {
            var product = await _repository.GetAsync(id);

            return(ObjectMapper.Map <RechargeProduct, RechargeProductDto>(product));
        }