public int Execute(User @operatorUser) { _operatorUser = @operatorUser ?? _operatorUser; _account.Amount += Amount; AccountService.Update(_account); var systemDealLog = new SystemDealLog(SerialNo, _operatorUser) { Amount = Amount, DealType = SystemDealLogTypes.Recharge, HasReceipt = HasReceipt, Addin = _account.AccountId.ToString(), DealWayId = this.HowToDeal }; SystemDealLogService.Create(systemDealLog); DealLog dealLog = CreateDealLog(); dealLog.Addin = systemDealLog.SystemDealLogId; DealLogService.Create(dealLog); if (!string.IsNullOrWhiteSpace(CurrentSite.MessageTemplateOfRecharge)) { if (_owner != null && _accountType.IsSmsRecharge && _owner.IsMobileAvailable) { string message = MessageFormator.FormatTickForRecharging(CurrentSite.MessageTemplateOfRecharge, CurrentSite, HasReceipt, Amount, _dealWay != null?_dealWay.DisplayName:"", dealLog, _account, AccountType, _owner, _operatorUser); SmsHelper.Send(_owner.Mobile, message); } } return(ResponseCode.Success); }
public object Save() { try { var serialNo = SerialNoHelper.Create(); SystemDealLog dealLog = SystemDealLogService.GetById(Id); if (dealLog != null && dealLog.CanCancel(SystemDealLogTypes.Recharge, CurrentSite)) { var account = AccountService.GetById(Convert.ToInt32(dealLog.Addin)); if (account == null || account.State != AccountStates.Normal) { return(new DataAjaxResult(Localize("NoAccount", "会员信息未找到"))); } var passwordService = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType); var password = passwordService.Decrypto(Password); if (User.SaltAndHash(password, account.PasswordSalt) != account.Password) { return(new DataAjaxResult(Localize("error.Password", "密码错误"))); } dealLog.State = SystemDealLogStates.Closed; account.Amount -= dealLog.Amount; var logItem = DealLogService.GetByAddin(dealLog.SystemDealLogId); TransactionHelper.BeginTransaction(); if (logItem != null) { logItem.State = DealLogStates.Cancel; DealLogService.Update(logItem); DealLogService.Create(new DealLog(serialNo) { Account = account, Amount = dealLog.Amount, SubmitTime = DateTime.Now, State = DealLogStates.Normal, DealType = DealTypes.CancelRecharging, Addin = logItem.DealLogId, }); } SystemDealLogService.Update(dealLog); AccountService.Update(account); LogHelper.LogWithSerialNo(LogTypes.SystemDealLogCloseRecharging, serialNo, dealLog.SystemDealLogId, dealLog.SystemDealLogId, account.Name); AddMessage(Localize("CloseRecharging.success"), dealLog.SystemDealLogId); return(TransactionHelper.CommitAndReturn(new SimpleAjaxResult())); } return(new SimpleAjaxResult(Localize("OpenReceipt.failed", "原交易不存在"))); } catch (Exception ex) { Logger.Error(LogTypes.SystemDealLogCloseRecharging, ex); return(new SimpleAjaxResult(ex.Message)); } }
public IMessageProvider Save() { TransactionHelper.BeginTransaction(); var serialNo = SerialNoHelper.Create(); var pointRebate = PointRebateService.GetById(this.PointRebate); if (pointRebate == null) { AddError(LogTypes.AccountRebate, "NoPointRebate"); return(this); } var account = AccountService.GetById(AccountId); if (account == null || account.Point < pointRebate.Point) { AddError(LogTypes.AccountRebate, "NoPointRebate"); return(this); } var accountLevel = AccountLevelPolicyService.Query().FirstOrDefault( x => x.State == AccountLevelPolicyStates.Normal && x.Level == account.AccountLevel && x.AccountTypeId == account.AccountTypeId); var owner = (AccountUser)(_innerObject.OwnerId.HasValue ? this.MembershipService.GetUserById(_innerObject.OwnerId.Value) : null); var pointRebates = PointRebateService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now) && x.Point < account.Point).ToList(); if (pointRebates.Count == 0) { AddError(LogTypes.AccountRebate, "NoPointRebate"); return(this); } if (!pointRebates.Any(x => x.PointRebateId == pointRebate.PointRebateId)) { AddError(LogTypes.AccountRebate, "NoPointRebate"); return(this); } account.Amount += pointRebate.Amount; account.Point -= pointRebate.Point; AccountService.Update(account); var dealLog = new DealLog(serialNo, DealTypes.Rebate, -pointRebate.Amount, -pointRebate.Point, null, null, account, null, pointRebate.PointRebateId); DealLogService.Create(dealLog); SystemDealLogService.Create(new SystemDealLog(serialNo, SecurityHelper.GetCurrentUser()) { Amount = pointRebate.Amount, DealType = SystemDealLogTypes.Rebate, Addin = dealLog.DealLogId.ToString() }); Logger.LogWithSerialNo(LogTypes.AccountRebate, serialNo, account.AccountId, account.Name, pointRebate.DisplayName); PointRebateLogService.Create(new PointRebateLog(serialNo, account, SecurityHelper.GetCurrentUser().CurrentUser, pointRebate)); AddMessage("success", pointRebate.Amount, pointRebate.Point); return(TransactionHelper.CommitAndReturn(this)); }
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", "兑换失败"))); } }
public AccountServiceResponse Save() { var serialNo = SerialNoHelper.Create(); TransactionHelper.BeginTransaction(); var accountName = AccountName.TrimSafty(); var account = AccountService.GetByName(accountName); if (account == null || (account.State != AccountStates.Normal && account.State != AccountStates.Invalid)) { return(new AccountServiceResponse(ResponseCode.NonFoundAccount)); } User owner = null; if (account.OwnerId.HasValue) { owner = MembershipService.GetUserById(account.OwnerId.Value); } var amount = account.Amount; // Ó¦Í˽ð¶î var depositAmount = account.DepositAmount; account.Amount = 0; account.DepositAmount = 0; account.State = AccountStates.Closed; account.LastDealTime = DateTime.Now; account.ExpiredDate = DateTime.Now; account.OwnerId = null; // ÍË¿¨ // var currentUser = SecurityHelper.GetCurrentUser().CurrentUser; var systemDealLog = new SystemDealLog(serialNo, currentUser) { Amount = -amount, DealType = SystemDealLogTypes.CloseCard }; SystemDealLogService.Create(systemDealLog); CashDealLogService.Create(new CashDealLog(systemDealLog.Amount, 0, currentUser.UserId, systemDealLog.DealType)); var dealLog1 = new DealLog(SerialNoHelper.Create()) { DealType = DealTypes.Close, AccountAmount = 0, AccountId = account.AccountId, AccountName = account.Name, Point = 0, Amount = amount, SubmitTime = DateTime.Now, State = DealLogStates.Normal }; DealLogService.Create(dealLog1); // Ѻ½ð // if (depositAmount != 0m) { var dealLog = new SystemDealLog(serialNo, currentUser) { Amount = -depositAmount, DealType = SystemDealLogTypes.CloseDeposit }; SystemDealLogService.Create(dealLog); CashDealLogService.Create(new CashDealLog(dealLog.Amount, 0, currentUser.UserId, dealLog.DealType)); } AccountService.Update(account); if (owner != null) { MembershipService.DeleteUser(owner); } Logger.LogWithSerialNo(LogTypes.AccountClose, serialNo, account.AccountId, accountName); TransactionHelper.Commit(); var response = new MyAccountServiceResponse(ResponseCode.Success, dealLog1, ShopService.GetById(account.ShopId), account, owner) { DepositAmount = depositAmount, Amount = amount }; if (!string.IsNullOrWhiteSpace(CurrentSite.TicketTemplateOfClose)) { var message = MessageFormator.Format(CurrentSite.TicketTemplateOfClose, account); message = MessageFormator.Format(message, amount); message = MessageFormator.Format(message, CurrentSite); message = message.Replace("#deposit-amount#", depositAmount.ToString()); message = message.Replace("#total-amount#", (depositAmount + amount).ToString()); message = MessageFormator.Format(message, owner); response.CodeText = message.FormatForJavascript(); } return(response); }
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"))); } }
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); }