Example #1
0
        public void Read(int id)
        {
            var obj = AccountTypeService.GetById(id);

            if (obj.State == AccountTypeStates.Normal)
            {
                InnerObject = obj;
            }
        }
Example #2
0
        public SimpleAjaxResult Save()
        {
            try
            {
                var serialNo = SerialNoHelper.Create();
                TransactionHelper.BeginTransaction();
                var account = AccountService.GetById(Id);
                if (account != null && account.State == AccountStates.Invalid)
                {
                    account.State = AccountStates.Normal;
                    AccountService.Update(account);

                    Logger.LogWithSerialNo(LogTypes.AccountResume, serialNo, Id, account.Name);
                    DataAjaxResult r = new DataAjaxResult();
                    if (!string.IsNullOrWhiteSpace(HostSite.MessageTemplateOfAccountResume))
                    {
                        var owner = account.OwnerId.HasValue ? MembershipService.GetUserById(account.OwnerId.Value) : null;
                        if (owner != null && owner.IsMobileAvailable)
                        {
                            var accountType = AccountTypeService.GetById(account.AccountTypeId);
                            if (accountType != null && accountType.IsSmsResume)
                            {
                                var msg = MessageFormator.Format(HostSite.MessageTemplateOfAccountResume, owner);
                                msg = MessageFormator.Format(msg, account);
                                SmsHelper.Send(owner.Mobile, msg);
                            }
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(HostSite.TicketTemplateOfResumeAccount))
                    {
                        r.Data1 = MessageFormator.FormatTickForResumeAccount(
                            HostSite.TicketTemplateOfResumeAccount,
                            serialNo,
                            HostSite,
                            account,
                            account.OwnerId.HasValue ? MembershipService.GetUserById(account.OwnerId.Value) : null,
                            AccountTypeService.GetById(account.AccountTypeId),
                            SecurityHelper.GetCurrentUser().CurrentUser);
                        PrintTicketService.Create(new PrintTicket(LogTypes.AccountResume, serialNo, r.Data1.ToString(), account));
                    }
                    return(TransactionHelper.CommitAndReturn(r));
                }
                return(new SimpleAjaxResult(Localize("accountNoExisting")));
            }
            catch (System.Exception ex)
            {
                Logger.Error(LogTypes.AccountResume, ex);
                return(new SimpleAjaxResult(ex.Message));
            }
        }
Example #3
0
        public ResultMsg Suspend(int id)
        {
            ResultMsg msg = new ResultMsg();

            try
            {
                Account item = AccountService.GetById(id);
                if (item != null && item.State == States.Normal)
                {
                    item.State = States.Invalid;
                    AccountService.Update(item);


                    Logger.LogWithSerialNo(LogTypes.AccountSuspend, SerialNoHelper.Create(), id, item.Name);
                    if (!string.IsNullOrWhiteSpace(HostSite.MessageTemplateOfAccountSuspend))
                    {
                        var owner = item.OwnerId.HasValue ? MembershipService.GetUserById(item.OwnerId.Value) : null;
                        if (owner != null && owner.IsMobileAvailable)
                        {
                            var accountType = AccountTypeService.GetById(item.AccountTypeId);
                            if (accountType != null && accountType.IsSmsSuspend)
                            {
                                var msgs = MessageFormator.Format(HostSite.MessageTemplateOfAccountSuspend, owner);
                                msgs = MessageFormator.Format(msgs, item);
                                SmsHelper.Send(owner.Mobile, msgs);
                            }
                        }
                    }
                    msg.Code     = 1;
                    msg.CodeText = "停用会员 " + item.Name + " 成功";
                    // AddMessage("suspend.success", item.Name);
                }
                else
                {
                    msg.CodeText = "不好意思,没有找到会员";
                }
                return(msg);
            }
            catch (Exception ex)
            {
                msg.CodeText = "不好意思,系统异常";
                Logger.Error("停用会员", ex);
                return(msg);
            }
        }
Example #4
0
        public void Save()
        {
            var serialNo = SerialNoHelper.Create();
            var item     = AccountTypeService.GetById(AccountTypeId);

            if (item != null)
            {
                item.DisplayName = DisplayName;
                item.Amount      = Amount;
                //item.DepositAmount = DepositAmount;
                item.ExpiredMonths  = ExpiredMonths;
                item.Frequency      = Frequency;
                item.NumberOfPeople = NumberOfPeople;
                item.Describe       = Describe;
                //item.IsRecharging = IsRecharging;
                //item.IsRenew = IsRenew;
                //item.RenewMonths = RenewMonths;
                //item.Point = Point;
                //var isMessageOfDealBefore = item.IsMessageOfDeal;
                //  item.IsMessageOfDeal = IsMessageOfDeal;
                //item.IsPointable = this.IsPointable;
                //item.IsSmsAccountBirthday = IsSmsAccountBirthday;
                //item.IsSmsClose = IsSmsClose;
                //item.IsSmsCode = IsSmsCode;
                //item.IsSmsDeal = IsSmsDeal;
                //item.IsSmsRecharge = IsSmsRecharge;
                //item.IsSmsRenew = IsSmsRenew;
                //item.IsSmsResume = IsSmsResume;
                //item.IsSmsSuspend = IsSmsSuspend;
                //item.IsSmsTransfer = IsSmsTransfer;
                //item.IsSmsChangeName = IsSmsChangeName;
                TransactionHelper.BeginTransaction();
                AccountTypeService.Update(item);
                AddMessage("success", item.DisplayName);

                //if (!IsMessageOfDeal && isMessageOfDealBefore)
                //{
                //    AccountService.DisableMessageOfDeal(item.AccountTypeId);
                //}
                Logger.LogWithSerialNo(LogTypes.AccountTypeEdit, serialNo, item.AccountTypeId, item.DisplayName);
                TransactionHelper.Commit();
                CacheService.Refresh(CacheKeys.PointPolicyKey);
            }
        }
Example #5
0
        private IEnumerable <Account> GetAccounts()
        {
            int         shopId      = this.Shop;
            AccountType accountType = AccountTypeService.GetById(AccountType);

            if (accountType == null)
            {
                yield break;
            }
            Shop shop = ShopService.GetById(shopId);

            for (int i = Start; i <= End; i += Interval)
            {
                string password = IsEmptyPassword ? "" : Password; //RandomHelper.GenerateNumber(6);
                string salt     = RandomHelper.GenerateNumber(8);

                var account = new Account
                {
                    Name          = string.Format(Format, i),
                    Amount        = accountType.Amount,
                    Point         = accountType.Point,
                    State         = AccountStates.Initialized,
                    ExpiredMonths = accountType.ExpiredMonths,
                    InitPassword  = password,
                    PasswordSalt  = salt,
                    AccountTypeId = accountType.AccountTypeId,
                    DepositAmount = accountType.DepositAmount,
                    Frequency     = accountType.Frequency,
                    useScope      = shop != null ? shop.Name : ""
                };
                if (shopId != Globals.All)
                {
                    account.ShopId = shopId;
                }
                account.DistributorId   = Distributor;
                account.AccountToken    = AccountToken ?? RandomHelper.GenerateNumber(8);
                account.Password        = User.SaltAndHash(account.InitPassword, account.PasswordSalt);
                account.IsMessageOfDeal = accountType.IsMessageOfDeal;
                yield return(account);
            }
        }
Example #6
0
        public int Validate()
        {
            if (Amount <= 0)
            {
                return(ResponseCode.InvalidateAmount);
            }

            _account = AccountService.GetByName(AccountName);
            if (_account == null)
            {
                return(ResponseCode.NonFoundAccount);
            }
            if (_account.State != States.Normal)
            {
                return(ResponseCode.AccountStateInvalid);
            }

            if (_account.OwnerId.HasValue)
            {
                _owner = MembershipService.GetUserById(_account.OwnerId.Value) as AccountUser;
            }
            _accountType = AccountTypeService.GetById(_account.AccountTypeId);

            if (AccountType != null && !AccountType.IsRecharging)
            {
                return(ResponseCode.NonRecharging);
            }

            _operatorUser = MembershipService.GetUserById(OperatorUserId);
            if (_operatorUser == null || !(_operatorUser is AdminUser))
            {
                return(ResponseCode.InvalidateUser);
            }

            //_dealWay = DealWayService.GetById(this.HowToDeal);
            //if (_dealWay == null || _dealWay.State != DealWayStates.Normal)
            //    return ResponseCode.InvalidateDealWay;
            return(ResponseCode.Success);
        }
Example #7
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);
        }
Example #8
0
        public AccountServiceResponse Save()
        {
            var serialNo = SerialNoHelper.Create();

            TransactionHelper.BeginTransaction();

            var account = AccountService.GetByName(AccountName);

            if (account == null)
            {
                return(new AccountServiceResponse(ResponseCode.NonFoundAccount));
            }
            if (account.State != AccountStates.Normal)
            {
                return(new AccountServiceResponse(ResponseCode.AccountStateInvalid));
            }
            AccountUser owner = null;

            if (account.OwnerId.HasValue)
            {
                owner = MembershipService.GetUserById(account.OwnerId.Value) as AccountUser;
            }
            var  accountType  = AccountTypeService.GetById(account.AccountTypeId);
            bool isRenew      = false;
            int  renewalMonth = 6;

            if (accountType != null)
            {
                isRenew      = accountType.IsRenew;
                renewalMonth = accountType.RenewMonths;
            }
            if (!isRenew)
            {
                return(new AccountServiceResponse(ResponseCode.NonRenewal));
            }
            var now = DateTime.Now;

            account.ExpiredDate = (now > account.ExpiredDate ? now : account.ExpiredDate).AddMonths(renewalMonth);
            AccountService.Update(account);
            Logger.LogWithSerialNo(LogTypes.AccountRenew, serialNo, account.AccountId, AccountName, accountType.RenewMonths);
            if (!string.IsNullOrWhiteSpace(HostSite.MessageTemplateOfAccountRenew))
            {
                if (owner != null && owner.IsMobileAvailable)
                {
                    if (accountType.IsSmsRenew)
                    {
                        var msg = MessageFormator.Format(HostSite.MessageTemplateOfAccountRenew, owner);
                        msg = MessageFormator.Format(msg, account);
                        SmsHelper.Send(owner.Mobile, msg);
                    }
                }
            }
            var response = new AccountServiceResponse(ResponseCode.Success, null, ShopService.GetById(account.ShopId), account, owner);

            if (!string.IsNullOrWhiteSpace(HostSite.TicketTemplateOfRenewAccount))
            {
                var msg = MessageFormator.FormatTickForRenewAccount(HostSite.TicketTemplateOfRenewAccount, serialNo, HostSite, account, owner, accountType,
                                                                    SecurityHelper.GetCurrentUser().CurrentUser);
                response.CodeText = msg;
                PrintTicketService.Create(new PrintTicket(LogTypes.AccountRenew, serialNo, msg, account));
            }
            return(TransactionHelper.CommitAndReturn(response));
        }
Example #9
0
        public AccountServiceResponse Save()
        {
            var serialNo = SerialNoHelper.Create();

            TransactionHelper.BeginTransaction();
            var newAccount = AccountService.GetByName(AccountName);

            if (newAccount == null || newAccount.State != AccountStates.Ready)
            {
                return(new AccountServiceResponse(ResponseCode.NonFoundAccount));
            }

            var oldAccount = AccountService.GetByName(OldAccountName);

            if (oldAccount == null ||
                (oldAccount.State != AccountStates.Normal && oldAccount.State != AccountStates.Invalid))
            {
                return(new AccountServiceResponse(ResponseCode.NonFoundAccount));
            }
            oldAccount.Remark1      = "Ô­¿¨ºÅ£º" + newAccount.Name;
            oldAccount.Name         = newAccount.Name;
            oldAccount.AccountToken = newAccount.AccountToken;
            oldAccount.Password     = newAccount.Password;
            oldAccount.PasswordSalt = newAccount.PasswordSalt;
            var owner = (AccountUser)(oldAccount.OwnerId.HasValue ? MembershipService.GetUserById(oldAccount.OwnerId.Value) : null);

            Logger.LogWithSerialNo(LogTypes.AccountChangeName, serialNo, oldAccount.AccountId, OldAccountName, AccountName);
            var fee = HostSite.ChangeCardFee;

            if (fee.HasValue)
            {
                SystemDealLogService.Create(new SystemDealLog(serialNo, SecurityHelper.GetCurrentUser().CurrentUser)
                {
                    Addin    = oldAccount.AccountId.ToString(),
                    Amount   = fee.Value,
                    DealType = SystemDealLogTypes.ChangeCard
                });
                oldAccount.ChargingAmount += fee.Value;
                CashDealLogService.Create(new CashDealLog(fee.Value, 0, SecurityHelper.GetCurrentUser().CurrentUser.UserId, CashDealLogTypes.ChangeCard));
            }
            AccountService.Delete(newAccount);

            AccountService.Update(oldAccount);
            var response    = new AccountServiceResponse(ResponseCode.Success, null, ShopService.GetById(oldAccount.ShopId), oldAccount, owner);
            var accountType = AccountTypeService.GetById(oldAccount.AccountTypeId);

            if (!string.IsNullOrWhiteSpace(HostSite.MessageTemplateOfAccountChangeName))
            {
                if (owner != null && owner.IsMobileAvailable)
                {
                    var msg = MessageFormator.Format(HostSite.MessageTemplateOfAccountChangeName, owner);
                    SmsHelper.Send(owner.Mobile, msg);
                }
            }

            if (!string.IsNullOrWhiteSpace(HostSite.TicketTemplateOfChangeAccountName))
            {
                var msg = MessageFormator.FormatTickForChangeAccountName(
                    HostSite.TicketTemplateOfChangeAccountName,
                    HostSite,
                    serialNo,
                    OldAccountName,
                    oldAccount,
                    owner,
                    accountType,
                    SecurityHelper.GetCurrentUser().CurrentUser);
                PrintTicketService.Create(new PrintTicket(LogTypes.AccountChangeName, serialNo, msg, oldAccount));
                response.CodeText = msg;
            }

            return(TransactionHelper.CommitAndReturn(response));
        }
Example #10
0
 public void Read(int id)
 {
     this.SetInnerObject(AccountTypeService.GetById(id));
 }
Example #11
0
        public SimpleAjaxResult Save()
        {
            try
            {
                var serialNo = SerialNoHelper.Create();
                if (Amount < 0)
                {
                    return(new SimpleAjaxResult(Localize("invalidAmount")));
                }
                TransactionHelper.BeginTransaction();
                var account1 = AccountService.GetByName(AccountName);
                if (account1 == null || (account1.State != AccountStates.Normal && account1.State != AccountStates.Invalid))
                {
                    return(new SimpleAjaxResult(string.Format(Localize("accountNonFound"), AccountName)));
                }
                var account2 = AccountService.GetByName(AccountNameTo);
                if (account2 == null || (account2.State != AccountStates.Normal && account2.State != AccountStates.Invalid))
                {
                    return(new SimpleAjaxResult(string.Format(Localize("accountNonFound"), AccountNameTo)));
                }

                var accountType = AccountTypeService.GetById(account1.AccountTypeId);
                if (accountType == null || !accountType.IsRecharging)
                {
                    return(new SimpleAjaxResult(string.Format(Localize("accountCannotRecharging"), AccountName)));
                }
                accountType = AccountTypeService.GetById(account2.AccountTypeId);
                if (accountType == null || !accountType.IsRecharging)
                {
                    return(new SimpleAjaxResult(string.Format(Localize("accountCannotRecharging"), AccountNameTo)));
                }
                if (Amount == 0)
                {
                    Amount = account1.Amount;
                }

                if (account1.Amount < Amount)
                {
                    return(new SimpleAjaxResult(Localize("invalidAmount")));
                }

                var passSvc  = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType);
                var password = passSvc.Decrypto(Password);
                if (User.SaltAndHash(password, account1.PasswordSalt) != account1.Password)
                {
                    return(new SimpleAjaxResult(Localize("invalidPassword", "ÃÜÂë´íÎó")));
                }
                account1.Amount -= Amount;
                account2.Amount += Amount;
                AccountService.Update(account1);
                AccountService.Update(account2);

                // transfer in
                DealLog dealLog = new DealLog(serialNo);
                dealLog.Account  = account1;
                dealLog.Addin    = account1.AccountId;
                dealLog.Amount   = Amount;
                dealLog.DealType = DealTypes.TransferOut;
                DealLogService.Create(dealLog);

                // transfer out
                dealLog          = new DealLog(serialNo);
                dealLog.Account  = account2;
                dealLog.Addin    = account2.AccountId;
                dealLog.Amount   = -Amount;
                dealLog.DealType = DealTypes.TransferIn;
                DealLogService.Create(dealLog);

                Logger.LogWithSerialNo(LogTypes.AccountTransfer, serialNo, account1.AccountId, account1.Name, account2.Name, Amount);
                var r = new DataAjaxResult();
                if (!string.IsNullOrWhiteSpace(HostSite.TicketTemplateOfTransfer))
                {
                    r.Data1 = MessageFormator.FormatTickForTransfer(HostSite.TicketTemplateOfTransfer, serialNo,
                                                                    account1,
                                                                    account1.OwnerId.HasValue ? MembershipService.GetUserById(account1.OwnerId.Value) : null,
                                                                    AccountTypeService.GetById(account1.AccountTypeId),
                                                                    account2,
                                                                    account2.OwnerId.HasValue ? MembershipService.GetUserById(account2.OwnerId.Value) : null,
                                                                    AccountTypeService.GetById(account2.AccountTypeId),
                                                                    SecurityHelper.GetCurrentUser().CurrentUser
                                                                    );
                    PrintTicketService.Create(new PrintTicket(LogTypes.AccountTransfer, serialNo, r.Data1.ToString(), account1));
                }
                return(TransactionHelper.CommitAndReturn(r));
            }
            catch (System.Exception ex)
            {
                Logger.Error(LogTypes.AccountTransfer, ex);

                return(new SimpleAjaxResult(Localize("SystemError")));
            }
        }
Example #12
0
        public ShowPay ShowPay()
        {
            var item = new ShowPay();

            item.SeriaNo = SerialNoHelper.Create();
            //var user = (AccountUser)_membershipService.GetByMobile(AccountName.Trim());
            //if (user == null)
            //{
            //    item.Code = -1;
            //    item.CodeText = "手机号码不存在";
            //    return item;
            //}
            //var account = AccountService.QueryByOwnerId(user).FirstOrDefault();
            //var rsp = new AccountServiceResponse(-1, null, null);
            // var account = AccountService.GetByName(AccountName.Trim());
            if (string.IsNullOrWhiteSpace(AccountName))
            {
                item.Code     = -1;
                item.CodeText = "找不到会员,请检查输入是否正确,会员卡状态是否正常!";
                return(item);
            }
            Account account = null;
            var     user    = (AccountUser)_membershipService.GetByMobile(AccountName.Trim());

            if (user != null)
            {
                account = AccountService.QueryByOwnerId(user).FirstOrDefault();
                //return new AccountServiceResponse(ResponseCode.NonFoundAccount) { CodeText = "找不到会员,请检查输入是否正确,会员卡状态是否正常!" };
            }
            else
            {
                account = AccountService.GetByName(AccountName.Trim());
            }
            string password1 = "";
            var    passSvc   = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType);

            password1 = passSvc.Decrypto(AccountPwd.Trim());
            // var account = AccountService.GetByName(AccountName);
            if (account == null || account.State != AccountStates.Normal)
            {
                item.Code     = -1;
                item.CodeText = "找不到会员,请检查输入是否正确,会员卡状态是否正常!";
                return(item);
            }
            if (User.SaltAndHash(password1, account.PasswordSalt) != account.Password)
            {
                item.Code     = -1;
                item.CodeText = "密码错误";
                return(item);
            }

            //return new AccountServiceResponse(ResponseCode.NonFoundAccount) { CodeText = "找不好会员,请检查输入是否正确,会员卡状态是否正常!" };

            var accountType = AccountTypeService.GetById(account.AccountTypeId);

            if (accountType == null)
            {
                item.Code     = -1;
                item.CodeText = "账户不存在";
                return(item);
            }
            AccountUser owner = _accountDealDal.GetUserById(account);

            if (owner != null)
            {
                item.OwnerDisplayName = owner.DisplayName;
            }
            var PointAmount = GetPoint(Amount, account, owner, accountType);

            //switch (PayWay)
            //{
            //    case 1:
            //        item.PayWay = "现金支付";
            //        break;
            //    case 2:
            //        item.PayWay="会员卡支付";
            //        break;
            //}
            item.AccountName     = account.Name;
            item.Amount          = account.Amount;
            item.Point           = account.Point;
            item.OldAmount       = Amount;
            item.AccountTypeName = accountType.DisplayName;
            item.DealAmount      = PointAmount.Amount;
            item.PayPoint        = PointAmount.Point;
            item.Rebate          = PointAmount.DiscountRate;
            item.ExpiredDate     = account.ExpiredDate.ToString();
            //return new AccountServiceResponse(ResponseCode.NonFoundAccount);
            //根据卡类型选择返回内容
            //switch (accountType.BaseType)
            //{
            //    case AccountBaseTypes.MeteringPay:
            //        item.AccountName = account.Name;
            //        item.Amount = account.Amount;
            //        item.Point = account.Point;
            //        var rebateAmount = Amount; //GetRebate(account, accountType);//折扣后金额
            //        var point = GetPoint(rebateAmount, account, accountType);//获得积分
            //        item.DealAmount = 0;
            //        item.PayPoint = 0;
            //        item.Rebate = 0;
            //        item.AccountTypeName = accountType.DisplayName;
            //        item.MeteringPayCount = account.MeteringPayCount;
            //        item.ExpiredDate = account.ExpiredDate.ToString();
            //        item.Code = 0;
            //        item.CodeText = "交易成功";
            //        break;//计次卡
            //    case AccountBaseTypes.Point:
            //        item.AccountName = account.Name;
            //        item.OldAmount = Amount;
            //        item.Amount = account.Amount;
            //        item.Point = account.Point;
            //        item.AccountTypeName = accountType.DisplayName;
            //        item.DealAmount = GetRebate(account, accountType);//折扣后金额
            //        item.PayPoint = GetPoint(item.DealAmount, account, accountType);//获得积分
            //        item.Rebate = accountType.Rebate;
            //        item.ExpiredDate = account.ExpiredDate.ToString();
            //        item.Code = 0;
            //        item.CodeText = "交易成功";
            //        break;//积分&折扣
            //    case AccountBaseTypes.AmountPay:
            //        item.AccountName = account.Name;
            //        item.OldAmount = Amount;
            //        item.Amount = account.Amount;
            //        item.Point = account.Point;
            //        item.AccountTypeName = accountType.DisplayName;
            //        item.DealAmount = GetRebate(account, accountType);//折扣后金额
            //        item.PayPoint = GetPoint(item.DealAmount, account, accountType);//获得积分
            //        item.Rebate = accountType.Rebate;
            //        item.ExpiredDate = account.ExpiredDate.ToString();
            //        item.Code = 0;
            //        item.CodeText = "交易成功";

            //        break;//储值卡
            //    default: return null;
            //        break;
            //}
            return(item);
        }