Пример #1
0
        public void AcceptNewShopCashTransfer(ShopCashTransfer shopCashTransfer)
        {
            var finallyValue = _shopCash;
            //业务逻辑判断
            ShopCashTransferInfo shopCashTransferInfo = shopCashTransfer.GetInfo();
            //统计信息
            var walletStatisticInfo = _walletStatisticInfo;

            if (shopCashTransferInfo.Direction == WalletDirection.Out)
            {
                if (_isFreeze)
                {
                    throw new Exception("钱包冻结,无法出账");
                }
                //如果是出账 判断账号余额是否够
                if (_shopCash < shopCashTransferInfo.Amount)
                {
                    throw new Exception("账户余额不足");
                }
                finallyValue -= shopCashTransferInfo.Amount;
            }
            else
            {
                //进账
                finallyValue += shopCashTransferInfo.Amount;
            }
            finallyValue = Math.Round(finallyValue, 2);
            //新的记录接受后,发出新记录接受的事件
            ApplyEvent(new NewShopCashTransferAcceptedEvent(_userId, shopCashTransfer.Id, finallyValue, walletStatisticInfo));
        }
        public void Handle(ICommandContext context, CreateShopCashTransferCommand command)
        {
            var cashTransfer = new ShopCashTransfer(
                command.AggregateRootId,
                command.WalletId,
                command.Number,
                new ShopCashTransferInfo(command.Amount,
                                         command.Fee,
                                         command.Direction,
                                         command.Remark),
                command.Type,
                command.Status);

            context.Add(cashTransfer);
        }