Esempio n. 1
0
        public void Query()
        {
            if (string.IsNullOrWhiteSpace(this.AccountName))
            {
                var query = PointGiftService.Query().Where(x => x.State == PointGiftStates.Normal);


                List         = BuildQuery(query).ToList(this, x => x);
                CurrentPoint = 0;
            }
            else
            {
                var account = AccountService.GetByName(AccountName);
                if (account != null)
                {
                    AccountUser owner = null;
                    if (account.OwnerId.HasValue)
                    {
                        owner = (AccountUser)MembershipService.GetUserById(account.OwnerId.Value);
                    }
                    CurrentPoint = account.Point;
                    var accountLevel = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == account.AccountLevel && account.AccountTypeId == x.AccountTypeId);

                    var query = PointGiftService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now));

                    List = BuildQuery(query).ToList(this, x => x);
                }
                else
                {
                    ErrorMessage = Localize("nofoundAccount", string.Format("ÕÊ»§ {0} δÕÒµ½", AccountName));
                    List         = new PageOfList <PointGift>(this.OrderBy, this.PageSize);
                }
            }
        }
Esempio n. 2
0
 public IEnumerable <ValidationError> Validate()
 {
     if (AccountLevelPolicyService.Query().Any(x => x.Level == Level && x.State == AccountLevelPolicyStates.Normal && x.AccountTypeId == this.AccountType))
     {
         yield return(new ValidationError("Level", string.Format(Localize("messages.duplicationLevel"), Level)));
     }
 }
Esempio n. 3
0
        public void Ready()
        {
            var accountLevel =
                AccountLevelPolicyService.Query().FirstOrDefault(
                    x => x.State == AccountLevelPolicyStates.Normal && x.Level == _innerObject.AccountLevel && x.AccountTypeId == _innerObject.AccountTypeId);

            var owner  = (AccountUser)(_innerObject.OwnerId.HasValue ? this.MembershipService.GetUserById(_innerObject.OwnerId.Value) : null);
            var levels = PointRebateService.Query().Where(x => x.IsFor(_innerObject, owner, accountLevel, DateTime.Now) && x.Point < _innerObject.Point)
                         .Select(x => new IdNamePair()
            {
                Key = x.PointRebateId, Name = x.DisplayName
            });

            PointRebate.Bind(levels);
        }
Esempio n. 4
0
        public object Save()
        {
            var serialNo = SerialNoHelper.Create();

            try
            {
                var account = AccountService.GetByName(AccountName);
                if (account == null || account.State != AccountStates.Normal)
                {
                    return(new DataAjaxResult(string.Format(Localize("NoAccount", "会员卡号 {0} 未找到"), AccountName)));
                }
                var passwordService = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType);
                var password        = passwordService.Decrypto(Password);
                var accountLevel    = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == account.AccountLevel && account.AccountTypeId == x.AccountTypeId);

                var owner = (AccountUser)(account.OwnerId.HasValue ? MembershipService.GetUserById(account.OwnerId.Value) : null);
                var gift  = PointGiftService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now)).FirstOrDefault(x => x.PointGiftId == GiftId);
                if (gift == null)
                {
                    return(new DataAjaxResult(Localize("NoGift", "礼品未找到")));
                }

                if (gift.Point > account.Point)
                {
                    return(new DataAjaxResult(Localize("NoEnoughPoint", "积分不足")));
                }
                if (User.SaltAndHash(password, account.PasswordSalt) != account.Password)
                {
                    return(new DataAjaxResult(Localize("error.Password", "密码错误")));
                }

                account.Point -= gift.Point;
                TransactionHelper.BeginTransaction();
                AccountService.Update(account);
                DealLogService.Create(new DealLog(serialNo, DealTypes.Gift, 0, -gift.Point, null, null, account, null, gift.PointGiftId));

                Logger.LogWithSerialNo(LogTypes.AccountDoGift, serialNo, account.AccountId, account.Name, gift.DisplayName);
                return(TransactionHelper.CommitAndReturn(new DataAjaxResult()));
            }
            catch (System.Exception ex)
            {
                Logger.Error(LogTypes.AccountDoGift, ex);

                return(new DataAjaxResult(Localize("Error", "兑换失败")));
            }
        }
Esempio n. 5
0
        public void Resume(int id)
        {
            var item = AccountLevelPolicyService.GetById(id);

            if (item != null && item.State == AccountLevelPolicyStates.Invalid)
            {
                if (AccountLevelPolicyService.Query().Any(x => x.State == AccountLevelPolicyStates.Normal && x.Level == item.Level && x.AccountTypeId == item.AccountTypeId))
                {
                    AddError("resume.fail", item.Level, item.DisplayName);
                }
                else
                {
                    item.State = AccountLevelPolicyStates.Normal;
                    AccountLevelPolicyService.Update(item);
                    Logger.LogWithSerialNo(LogTypes.AccountLevelResume, SerialNoHelper.Create(), item.Level, item.DisplayName);
                    AddMessage("resume.success", item.Level, item.DisplayName);
                }
            }
        }
Esempio n. 6
0
        public int Validate()
        {
            _account = AccountService.GetByName(AccountName);

            if (_account == null || (_account.State != AccountStates.Ready && _account.State != AccountStates.Saled))
            {
                return(ResponseCode.NonFoundAccount);
            }

            _operator = MembershipService.GetUserById(OperatorUserId) as AdminUser;
            if (_operator == null)
            {
                return(ResponseCode.InvalidateUser);
            }
            _dealWay = DealWayService.GetById(DealWayId);

            _accountType  = AccountTypeService.GetById(_account.AccountTypeId);
            _accountLevel = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == 0 && x.State == States.Normal && x.AccountTypeId == _account.AccountTypeId);

            _dealLog = new DealLog(SerialNo, DealTypes.Open, -_account.Amount, 0, null, null, _account, null, 0);

            // 用户
            if (!string.IsNullOrEmpty(UserDisplayName))
            {
                _owner              = new AccountUser();
                _owner.DisplayName  = UserDisplayName;
                _owner.IdentityCard = Identify;
                _owner.BirthDate    = BirthDate;
                _owner.Mobile       = Mobile;
                if (!string.IsNullOrWhiteSpace(Mobile))
                {
                    _owner.IsMobileAvailable = true;
                }
                _owner.Gender = Gender;
            }

            return(ResponseCode.Success);
        }
Esempio n. 7
0
        public void Query()
        {
            var query = this.PointPolicyService.Query();

            if (State != States.All)
            {
                query = query.Where(x => x.State == State);
            }
            if (!string.IsNullOrWhiteSpace(DisplayName))
            {
                query = query.Where(x => x.DisplayName.ToLower().Contains(DisplayName.ToLower()));
            }

            List = query.ToList(this, x => new ListPointPolicy(x));
            var levels = AccountLevelPolicyService.Query().ToList();

            foreach (var pointPolicy in List)
            {
                var      ids   = (pointPolicy.InnerObject.AccountLevels ?? "").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                string[] names = levels.Where(x => ids.Contains(x.AccountLevelPolicyId.ToString())).Select(x => x.DisplayName).ToArray();
                pointPolicy.AccountLevelName = string.Join(",", names);
            }
        }
Esempio n. 8
0
        public int Execute(User user)
        {
            if (_dealWay == null)
            {
                _dealWay = new DealWay()
                {
                    IsCash = false
                }
            }
            ;
            user = user ?? OperatorUser;
            if (!string.IsNullOrWhiteSpace(Password))
            {
                _account.SetPassword(Password);
            }
            _account.State        = IsActived ? States.Normal : States.Invalid;
            _account.ExpiredDate  = DateTime.Now.AddMonths(_account.ExpiredMonths).Date;
            _account.LastDealTime = DateTime.Now;
            _account.OpenTime     = DateTime.Now;
            _account.Remark1      = Remark1;


            // 售卡
            //
            var systemDealLog = new SystemDealLog(SerialNo, _operator)
            {
                Amount = _account.Amount, DealWayId = DealWayId, DealType = SystemDealLogTypes.SaldCard, Addin = _account.AccountId.ToString()
            };

            SystemDealLogService.Create(systemDealLog);

            if (_dealWay.IsCash)
            {
                CashDealLogService.Create(new CashDealLog(systemDealLog.Amount, 0, user.UserId, systemDealLog.DealType));
            }

            // 押金
            //
            if (_account.DepositAmount != 0m)
            {
                systemDealLog = new SystemDealLog(SerialNo, _operator)
                {
                    Amount = _account.DepositAmount, DealWayId = DealWayId, DealType = SystemDealLogTypes.Deposit, Addin = _account.AccountId.ToString()
                };
                SystemDealLogService.Create(systemDealLog);
                if (_dealWay.IsCash)
                {
                    CashDealLogService.Create(new CashDealLog(systemDealLog.Amount, 0, user.UserId, systemDealLog.DealType));
                }
            }

            AccountLevelPolicy accountLevel = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == 0 && x.State == States.Normal && x.AccountTypeId == _account.AccountTypeId && _account.TotalPoint >= x.TotalPointStart);

            if (accountLevel != null)
            {
                _account.AccountLevelName = accountLevel.DisplayName;
                _account.AccountLevel     = accountLevel.Level;
            }


            // 用户
            //if (_owner != null)
            //{
            //    _owner.Name = Guid.NewGuid().ToString("N");
            //    var roles = MembershipService.QueryRoles(new RoleRequest() { Name = RoleNames.Account }).ToList();
            //    MembershipService.CreateUser(_owner);
            //    MembershipService.AssignRoles(_owner, roles.Select(x => x.RoleId).ToArray());
            //    _account.OwnerId = _owner.UserId;
            //}

            // sale Id
            //
            if (SaleId > 0)
            {
                var sale = MembershipService.GetUserById(SaleId) as AdminUser;
                if (sale != null && sale.IsSale == true)
                {
                    _account.SalerId = sale.UserId;
                }
            }

            DealLogService.Create(_dealLog);
            AccountService.Update(_account);

            return(ResponseCode.Success);
        }