Exemplo n.º 1
0
        public async Task <BaseApiResponse> IncentiveBenevolence([FromBody] IncentiveBenevolenceRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (request.BenevolenceIndex <= 0 || request.BenevolenceIndex >= 1)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "善心指数异常"
                });
            }
            //遍历所有的钱包发送激励指令
            var wallets = _walletQueryService.ListPage();

            if (wallets.Any())
            {
                var totalBenevolenceAmount = wallets.Where(x => x.Benevolence > 1).Sum(x => x.Benevolence);
                //创建激励记录
                await ExecuteCommandAsync(new CreateBenevolenceIndexCommand(
                                              GuidUtil.NewSequentialId(),
                                              request.BenevolenceIndex,
                                              totalBenevolenceAmount
                                              ));

                foreach (var wallet in wallets)
                {
                    if (wallet.Benevolence > 1)
                    {
                        var command = new IncentiveBenevolenceCommand(wallet.Id, request.BenevolenceIndex);
                        await ExecuteCommandAsync(command);
                    }
                }
            }

            return(new BaseApiResponse());
        }
Exemplo n.º 2
0
        public async Task <BaseApiResponse> IncentiveWallet([FromBody] IncentiveWalletRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (request.BenevolenceIndex >= 1 || request.BenevolenceIndex <= 0)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "指出值异常"
                });
            }
            var wallet = _walletQueryService.Info(request.WalletId);

            if (wallet == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没有找到钱包"
                });
            }
            var command = new IncentiveBenevolenceCommand(request.WalletId, request.BenevolenceIndex);
            var result  = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Exemplo n.º 3
0
        public void Incentive()
        {
            var benevolenceIndex = RandomArray.BenevolenceIndex();

            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                //周日两倍激励
                benevolenceIndex = benevolenceIndex * 2;
            }

            //善心指数判断
            if (benevolenceIndex <= 0 || benevolenceIndex >= 1)
            {
                throw new Exception("善心指数异常");
            }

            //遍历所有的钱包发送激励指令
            var wallets = _walletQueryService.ListPage();

            foreach (var wallet in wallets)
            {
                var command = new IncentiveBenevolenceCommand(wallet.Id, benevolenceIndex);
                _commandService.SendAsync(command);
            }
        }
Exemplo n.º 4
0
        public async Task <BaseApiResponse> IncentiveWallet(IncentiveWalletRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (request.BenevolenceIndex >= 1 || request.BenevolenceIndex <= 0)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "指出值异常"
                });
            }
            var wallet = _walletQueryService.Info(request.WalletId);

            if (wallet == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没有找到钱包"
                });
            }
            var command = new IncentiveBenevolenceCommand(request.WalletId, request.BenevolenceIndex);
            var result  = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(), "激励钱包福豆", wallet.Id, "钱包{0},指数:{1}".FormatWith(wallet.OwnerMobile, request.BenevolenceIndex));

            return(new BaseApiResponse());
        }
Exemplo n.º 5
0
        public async Task <BaseApiResponse> IncentiveBenevolence(IncentiveBenevolenceRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (request.BenevolenceIndex <= 0 || request.BenevolenceIndex >= 1)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "善心指数异常"
                });
            }
            //遍历所有的钱包发送激励指令
            var wallets = _walletQueryService.ListPage();

            foreach (var wallet in wallets)
            {
                var command = new IncentiveBenevolenceCommand(wallet.Id, request.BenevolenceIndex);
                await ExecuteCommandAsync(command);
            }

            return(new BaseApiResponse());
        }
Exemplo n.º 6
0
        public void Incentive()
        {
            var benevolenceIndex = RandomArray.BenevolenceIndex();

            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                //周日两倍激励
                benevolenceIndex = benevolenceIndex * 2;
            }

            //善心指数判断
            if (benevolenceIndex <= 0 || benevolenceIndex >= 1)
            {
                throw new Exception("善心指数异常");
            }
            //所有待激励的钱包 福豆>1  钱包未锁定
            var wallets = _walletQueryService.ListPage().Where(x => x.Benevolence > 1 && x.IsFreeze == Common.Enums.Freeze.UnFreeze);

            //遍历所有的钱包发送激励指令
            if (wallets.Any())
            {
                var totalBenevolenceAmount = wallets.Sum(x => x.Benevolence);
                //创建激励记录
                _commandService.SendAsync(new CreateBenevolenceIndexCommand(
                                              GuidUtil.NewSequentialId(),
                                              benevolenceIndex,
                                              totalBenevolenceAmount
                                              ));

                foreach (var wallet in wallets)
                {
                    if (wallet.Benevolence > 1)
                    {
                        var command = new IncentiveBenevolenceCommand(wallet.Id, benevolenceIndex);
                        _commandService.SendAsync(command);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public async Task <BaseApiResponse> IncentiveBenevolence(IncentiveBenevolenceRequest request)
        {
            request.CheckNotNull(nameof(request));
            if (request.BenevolenceIndex <= 0 || request.BenevolenceIndex >= 1)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "善心指数异常"
                });
            }
            //遍历所有的钱包发送激励指令
            var wallets = _walletQueryService.ListPage();

            if (wallets.Any())
            {
                var totalBenevolenceAmount = wallets.Where(x => x.Benevolence > 1).Sum(x => x.Benevolence);
                //创建激励记录
                await ExecuteCommandAsync(new CreateBenevolenceIndexCommand(
                                              GuidUtil.NewSequentialId(),
                                              request.BenevolenceIndex,
                                              totalBenevolenceAmount
                                              ));

                foreach (var wallet in wallets)
                {
                    if (wallet.Benevolence > 1)
                    {
                        var command = new IncentiveBenevolenceCommand(wallet.Id, request.BenevolenceIndex);
                        await ExecuteCommandAsync(command);
                    }
                }
            }
            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(), "激励福豆", Guid.Empty, "指数:{0}".FormatWith(request.BenevolenceIndex));

            return(new BaseApiResponse());
        }
Exemplo n.º 8
0
 public void Handle(ICommandContext context, IncentiveBenevolenceCommand command)
 {
     context.Get <Wallet>(command.AggregateRootId).IncentiveBenevolence(command.BenevolenceIndex);
 }