Ejemplo n.º 1
0
        public async Task <ResultDto> Add(EmailInput item)
        {
            var result = new ResultDto {
                Message = ""
            };

            try
            {
                var email = _mapper.Map <EmailEntity>(item);
                await _emailDomainService.Add(email);

                await _operatorLogDomainService.AddSuccess(new OperatorLogEntity
                {
                    Type    = OperatorLogType.发送邮件,
                    Content = JsonConvert.SerializeObject(item)
                });

                await Commit();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                await _operatorLogDomainService.AddError(new OperatorLogEntity
                {
                    Type    = OperatorLogType.发送邮件,
                    Content = $"Data={JsonConvert.SerializeObject(item)},ErrorMessage={result.Message}"
                });
                await Commit();
            }
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <Unit> Handle(AgreeFriendCommand command, CancellationToken cancellationToken)
        {
            var playerId   = command.PlayerId;
            var relationId = command.RelationId;
            var player     = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var relation = await _playerDomainService.Get(relationId);

            if (relation == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var playerRelationFrom = await _playerRelationDomainService.Get(x => x.PlayerId == relationId && x.RelationId == playerId && x.Type == PlayerRelationTypeEnum.好友);

            if (playerRelationFrom == null)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】[{relation.Name}]没有申请加你为好友,或者已撤销申请。");

                return(Unit.Value);
            }

            var playerRelationTo = await _playerRelationDomainService.Get(x => x.PlayerId == playerId && x.RelationId == relationId && x.Type == PlayerRelationTypeEnum.好友);

            if (playerRelationTo != null)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】你和[{relation.Name}]已经是好友了。");

                return(Unit.Value);
            }


            playerRelationTo = new PlayerRelationEntity
            {
                PlayerId    = playerId,
                RelationId  = relationId,
                Type        = PlayerRelationTypeEnum.好友,
                CreatedTime = DateTime.Now
            };
            await _playerRelationDomainService.Add(playerRelationTo);

            await _mudProvider.ShowMessage(player.Id, $"【好友】你同意了[{relation.Name}]的好友申请。");

            var content = $"【好友】[{player.Name}]同意了你的申请,你们已成为了好友。";

            await _emailDomainService.Add(new EmailEntity
            {
                ExpiryDate = DateTime.Now.AddDays(30),
                SendDate   = DateTime.Now,
                Title      = $"{player.Name}同意了你的好友申请",
                Content    = content,
                Type       = EmailTypeEnum.系统,
                TypeId     = relation.Id
            });


            await _mudProvider.ShowMessage(relation.Id, content);

            return(Unit.Value);
        }
Ejemplo n.º 3
0
        private async Task Friend(PlayerEntity player, PlayerEntity relation)
        {
            if (await _redisDb.StringGet <int>(string.Format(RedisKey.RefuseFriend, player.Id, relation.Id)) > 0)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】[{relation.Name}]已拒绝你的申请。");

                return;
            }

            //我加对方
            var playerRelationFrom = await _playerRelationDomainService.Get(x => x.PlayerId == player.Id &&
                                                                            x.RelationId == relation.Id &&
                                                                            x.Type == PlayerRelationTypeEnum.好友);

            //对方加我
            var playerRelationTo = await _playerRelationDomainService.Get(x => x.PlayerId == relation.Id &&
                                                                          x.RelationId == player.Id &&
                                                                          x.Type == PlayerRelationTypeEnum.好友);



            if (playerRelationFrom != null && playerRelationTo != null)
            {
                if (playerRelationTo != null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你们已经是好友。");

                    return;
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你已申请加[{relation.Name}]为好友,请等待对方同意。");

                    return;
                }
            }



            if (playerRelationFrom == null)
            {
                if (playerRelationTo == null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你申请加[{relation.Name}]为好友,请等待对方同意。");

                    var content = $"【好友】[{player.Name}]想和你成为好友,到 '社交'->'好友' 界面可以同意或拒绝对方的申请,你也可以直接添加对方为好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}想和你成为好友",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你成功添加[{relation.Name}]为好友。");


                    var content = $"【好友】[{player.Name}]同意了你的申请,你们已成为了好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}同意了你的好友申请",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }


                playerRelationFrom = new PlayerRelationEntity
                {
                    CreatedTime = DateTime.Now,
                    PlayerId    = player.Id,
                    RelationId  = relation.Id,
                    Type        = PlayerRelationTypeEnum.好友
                };
                await _playerRelationDomainService.Add(playerRelationFrom);



                await _queueHandler.SendQueueMessage(new ReceiveEmailQueue(relation.Id));
            }
        }