Ejemplo n.º 1
0
    /// <summary>
    /// 处理充值
    /// </summary>
    /// <param name="eventDto"></param>
    /// <param name="tracker"></param>
    /// <returns></returns>
    public async Task <AppSrvResult> ProcessRechargingAsync(CustomerRechargedEvent eventDto, IMessageTracker tracker)
    {
        var customerId       = eventDto.Data.CustomerId;
        var amount           = eventDto.Data.Amount;
        var transactionLogId = eventDto.Data.TransactionLogId;

        var transLog = await _cusTransactionLogRepo.FindAsync(transactionLogId, noTracking : false);

        if (transLog is null)
        {
            return(AppSrvResult());
        }

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

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

        finance.Balance = newBalance;
        await _cusFinaceRepo.UpdateAsync(finance);

        transLog.ExchageStatus  = ExchageStatusEnum.Finished;
        transLog.ChangingAmount = originalBalance;
        transLog.ChangedAmount  = newBalance;
        await _cusTransactionLogRepo.UpdateAsync(transLog);

        await tracker?.MarkAsProcessedAsync(eventDto);

        return(AppSrvResult());
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 标记订单状态
    /// </summary>
    /// <param name="eventDto"></param>
    /// <param name="tracker"></param>
    /// <returns></returns>
    public async Task MarkCreatedStatusAsync(WarehouseQtyBlockedEvent eventDto, IMessageTracker tracker)
    {
        var order = await _orderRepo.GetAsync(eventDto.Data.OrderId);

        order.MarkCreatedStatus(eventDto.Data.IsSuccess, eventDto.Data.Remark);

        await _orderRepo.UpdateAsync(order);

        await tracker?.MarkAsProcessedAsync(eventDto);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 锁定库存
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task BlockQtyAsync(OrderCreatedEvent eventDto, IMessageTracker tracker)
    {
        var blockQtyProductsInfo = eventDto.Data.Products.ToDictionary(x => x.ProductId, x => x.Qty);
        var warehouses           = await _warehouseRepo.Where(x => blockQtyProductsInfo.Keys.Contains(x.ProductId.Value), noTracking : false).ToListAsync();

        var products = await _productRepo.Where(x => blockQtyProductsInfo.Keys.Contains(x.Id)).ToListAsync();

        var result = await _warehouseManager.BlockQtyAsync(eventDto.Data.OrderId, blockQtyProductsInfo, warehouses, products);

        //库存都符合锁定条件才能批量更新数据库
        if (result)
        {
            await _warehouseRepo.UpdateRangeAsync(warehouses);

            await tracker?.MarkAsProcessedAsync(eventDto);
        }
    }
Ejemplo n.º 4
0
 public static async Task MarkAsProcessedAsync <T>(this IMessageTracker tracker, Events.EventEntity <T> eventDto)
     where T : class
 {
     await tracker.MarkAsProcessedAsync(eventDto.Id, eventDto.EventTarget);
 }