public void Handle(ICommandContext context, CreateBenevolenceTransferCommand command)
        {
            var cashTransfer = new BenevolenceTransfer(
                command.AggregateRootId,
                command.WalletId,
                command.Number,
                new BenevolenceTransferInfo(
                    command.Amount,
                    command.Fee,
                    command.Direction,
                    command.Remark
                    ),
                command.Type,
                command.Status);

            context.Add(cashTransfer);
        }
Example #2
0
        /// <summary>
        /// 接受新的善心记录 更新统计信息
        /// </summary>
        /// <param name="benevolenceTransfer"></param>
        public void AcceptNewBenevolenceTransfer(BenevolenceTransfer benevolenceTransfer)
        {
            if (!_benevolenceTransfers.Add(benevolenceTransfer.Id))
            {
                return;
            }

            var finallyValue = _benevolence;
            //业务逻辑判断
            BenevolenceTransferInfo benevolenceTransferInfo = benevolenceTransfer.GetInfo();
            //统计信息
            var walletStatisticInfo = _walletStatisticInfo;

            if (benevolenceTransferInfo.Direction == WalletDirection.Out)
            {//如果是出账 判断账号余额是否够
                if (_benevolence < benevolenceTransferInfo.Amount)
                {
                    throw new Exception("账户余额不足");
                }
                finallyValue -= benevolenceTransferInfo.Amount;
            }
            else
            {
                //如果是进账 更新统计信息
                if (_walletStatisticInfo.UpdatedOn.Date.Equals(DateTime.Now.Date))
                {
                    //今日非第一个记录
                    walletStatisticInfo.BenevolenceTotal      += benevolenceTransferInfo.Amount;
                    walletStatisticInfo.TodayBenevolenceAdded += benevolenceTransferInfo.Amount;
                    walletStatisticInfo.UpdatedOn              = DateTime.Now;
                }
                else
                {
                    //今日第一个收入
                    walletStatisticInfo.BenevolenceTotal     += benevolenceTransferInfo.Amount;
                    walletStatisticInfo.TodayBenevolenceAdded = benevolenceTransferInfo.Amount;
                    walletStatisticInfo.UpdatedOn             = DateTime.Now;
                }
                finallyValue += benevolenceTransferInfo.Amount;
            }

            ApplyEvent(new NewBenevolenceTransferAcceptedEvent(_userId, benevolenceTransfer.Id, finallyValue, walletStatisticInfo));
        }