Beispiel #1
0
        public async Task <SignedInfoOutput> Signed()
        {
            var signedPointInfo = _pointQueryService.GetPointInfoByType(PointType.Signed);
            var todaySignedInfo = _pointQueryService.GetTodaySigned(_lotterySession.UserId);

            if (todaySignedInfo != null)
            {
                throw new LotteryException("您今天已经签到,无法重复签到");
            }
            var sinedNotes = $"{DateTime.Now.ToString("yyyy-MM-dd")}日,每日签到";

            await SendCommandAsync(new AddPointRecordCommand(Guid.NewGuid().ToString(), signedPointInfo.Point,
                                                             PointType.Signed, PointOperationType.Increase, sinedNotes, _lotterySession.UserId));

            var signeds = _pointQueryService.GetUserLastSined(_lotterySession.UserId);

            if (signeds != null && signeds.CurrentPeriodEndDate.Date == DateTime.Now.Date && signeds.DurationDays != 0 && signeds.DurationDays % LotteryConstants.ContinuousSignedDays == 0)
            {
                var signAdditionalPointInfo = _pointQueryService.GetPointInfoByType(PointType.SignAdditional);
                var signAdditionalNotes     = $"{DateTime.Now.ToString("yyyy-MM-dd")}日,连续签到五日,获得额外{signAdditionalPointInfo.Point}点积分";
                await SendCommandAsync(new AddPointRecordCommand(Guid.NewGuid().ToString(), signAdditionalPointInfo.Point,
                                                                 PointType.SignAdditional, PointOperationType.Increase, signAdditionalNotes, _lotterySession.UserId));
            }
            Thread.Sleep(200);
            return(await SignedInfo());
        }
Beispiel #2
0
        public async Task <string> CreateUser(UserInfoInput user)
        {
            ValidationResult validationResult = _userInfoInputValidator.Validate(user);

            if (!validationResult.IsValid)
            {
                throw new LotteryDataException(validationResult.Errors.Select(p => p.ErrorMessage).ToList().ToString(";"));
            }

            var validIdentifyCodeOutput = _identifyCodeAppService.ValidIdentifyCode(user.Account, user.IdentifyCode);

            if (validIdentifyCodeOutput.IsOvertime)
            {
                await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, "system"));

                throw new LotteryDataException("验证码超时,请重新获取验证码");
            }
            if (!validIdentifyCodeOutput.IsValid)
            {
                // await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, _lotterySession.UserId));
                throw new LotteryDataException("您输入的验证码错误,请重新输入");
            }

            var accountRegType = AccountHelper.JudgeAccountRegType(user.Account);
            var isReg          = await _userManager.IsExistAccount(user.Account);

            if (isReg)
            {
                await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, "system"));

                throw new LotteryDataException("该账号已经存在");
            }

            var userId = Guid.NewGuid().ToString();

            var userInfoCommand = new AddUserInfoCommand(userId, user.Account,
                                                         EncryptPassword(user.Account, user.Password, accountRegType),
                                                         user.ClientRegistType, accountRegType, 0);
            var commandResult = await SendCommandAsync(userInfoCommand);

            var signedPointInfo = _pointQueryService.GetPointInfoByType(PointType.Register);
            var sinedNotes      = $"{DateTime.Now.ToString("yyyy-MM-dd")}日,注册即送积分";

            await SendCommandAsync(new AddPointRecordCommand(Guid.NewGuid().ToString(), signedPointInfo.Point,
                                                             PointType.Signed, PointOperationType.Increase, sinedNotes, userId));

            if (commandResult.Status != AsyncTaskStatus.Success)
            {
                throw new LotteryDataException("创建用户失败");
            }
            await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account,
                                                                  user.Account));

            return("注册用户成功");
        }