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); }
private void SendMessage(SystemDealLog dealLog) { if (string.IsNullOrWhiteSpace(CurrentSite.MessageTemplateOfOpenReceipt)) { return; } int accountId = Convert.ToInt32(dealLog.Addin); Account account = AccountService.GetById(accountId); if (account.OwnerId == null || !account.IsMessageOfDeal) { return; } var user = MembershipService.GetUserById(account.OwnerId.Value) as AccountUser; if (user == null || !user.IsMobileAvailable) { return; } string msg = MessageFormator.Format(CurrentSite.MessageTemplateOfOpenReceipt, user); msg = MessageFormator.Format(msg, account); msg = MessageFormator.Format(msg, CurrentSite); SmsHelper.Send(user.Mobile, msg); }
public object OpenReceipt(int id) { try { SystemDealLog dealLog = SystemDealLogService.GetById(id); if (dealLog != null && !dealLog.HasReceipt && dealLog.DealType == SystemDealLogTypes.Recharge && dealLog.Amount > 0 && dealLog.State == SystemDealLogStates.Normal) { dealLog.HasReceipt = true; TransactionHelper.BeginTransaction(); SystemDealLogService.Update(dealLog); LogHelper.LogWithSerialNo(LogTypes.SystemDealLogOpenReceipt, SerialNoHelper.Create(), dealLog.SystemDealLogId, dealLog.SerialNo); AddMessage(Localize("OpenReceipt.success"), dealLog.SystemDealLogId); SendMessage(dealLog); return(TransactionHelper.CommitAndReturn(new SimpleAjaxResult())); } return(new SimpleAjaxResult(Localize("OpenReceipt.failed", "原交易不存在"))); } catch (Exception ex) { Logger.Error(LogTypes.SystemDealLogOpenReceipt, ex); return(new SimpleAjaxResult(ex.Message)); } }
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 void Execute(User currentUser) { var serialNo = SerialNoHelper.Create(); using (var tran = TransactionHelper.BeginTransaction()) { var liquidate = this.LiquidateService.GetById(LiquidateId); if (liquidate == null || liquidate.State != LiquidateStates.Processing) { throw new Exception("没有找到相关的清算记录"); } liquidate.State = LiquidateStates.Done; LiquidateService.Update(liquidate); var shop = ShopService.GetById(ShopId); var rate = shop.ShopDealLogChargeRate ?? HostSite.ShopDealLogChargeRate; var rateAmount = (liquidate.DealAmount * rate); var amount = liquidate.DealAmount - liquidate.CancelAmount; var systemDealLog = new SystemDealLog(serialNo, currentUser) { Addin = liquidate.LiquidateId.ToString(), Amount = -amount, DealType = SystemDealLogTypes.ShopDealLogDone, DealWayId = DealWayId, }; SystemDealLogService.Create(systemDealLog); shop.Amount -= amount; var shopDealLog = new ShopDealLog(serialNo, DealTypes.ShopDealLogDone, -amount, null, null, null, shop, systemDealLog.SystemDealLogId); ShopDealLogService.Create(shopDealLog); systemDealLog = new SystemDealLog(serialNo, currentUser) { Addin = liquidate.LiquidateId.ToString(), Amount = rateAmount, DealType = SystemDealLogTypes.ShopDealLogCharging, DealWayId = DealWayId, }; SystemDealLogService.Create(systemDealLog); shop.RechargingAmount += rateAmount; shopDealLog = new ShopDealLog(serialNo, DealTypes.ShopDealLogDone, rateAmount, null, null, null, shop, systemDealLog.SystemDealLogId); ShopDealLogService.Create(shopDealLog); var dealWay = DealWayService.GetById(this.DealWayId); if (dealWay.IsCash) { CashDealLogService.Create(new CashDealLog(amount - rateAmount, currentUser.UserId, currentUser.UserId, CashDealLogTypes.ShopDealLogDone)); } ShopService.Update(shop); tran.Commit(); } }
public void Create(SystemDealLog item) { lock (SiteAccount.Locker) { //if (!_databaseInstance.InTransaction) // throw new Exception("SystemDealLog have to run in transaction"); //_databaseInstance.ExecuteNonQuery("update siteaccounts set amount = amount + @amount", // new { amount = item.Amount }); //var siteAccount = _databaseInstance.Query<SiteAccount>("select * from siteaccounts", null).FirstOrDefault(); //if (siteAccount == null) // throw new Exception("siteaccounts table changed, please check it"); //item.SiteAmount = siteAccount.Amount ; item.SystemDealLogId = _databaseInstance.Insert(item, TableName); } }
public AccountServiceResponse Save() { var serialNo = SerialNoHelper.Create(); string password1 = ""; string password2 = ""; var passSvc = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType); passSvc.Decrypto(Password, PasswordConfirm, out password1, out password2); if (!string.IsNullOrEmpty(password1) || !string.IsNullOrEmpty(password2)) { if (password1 != password2) { return(new OpenAccountServiceResponse(ResponseCode.SystemError) { CodeText = "两次密码输入不一致" }); } } string accountName = AccountName.TrimSafty(); var operatorUser = SecurityHelper.GetCurrentUser().CurrentUser; //try //{ // if (CodeHelper.GetObject<string>("sms") != Code || CodeHelper.GetObject<string>("sms_mobile") != Mobile) // { // Mobile = ""; // } //} //catch //{ //} if (!string.IsNullOrWhiteSpace(Mobile)) { User u = MembershipService.GetByMobile(Mobile); if (u != null) { return(new AccountServiceResponse(-1) { CodeText = "手机号已绑定" }); } } var command = new OpenAccountCommand(serialNo, accountName, password1, DisplayName, BirthDate, IsActived, HowToDeal, Identify, Remark1, operatorUser.UserId, SaleId, Gender, Mobile); UnityContainer.BuildUp(command); int code = command.Validate(); if (code != ResponseCode.Success) { return(new AccountServiceResponse(code)); } TransactionHelper.BeginTransaction(); command.Execute(operatorUser); decimal?saleFee = 0m; if (command.AccountType != null) { saleFee = HostSite.SaleCardFee; // 手续费 // if (saleFee != null && saleFee.Value != 0m) { var account = AccountService.GetByName(accountName); account.ChargingAmount += saleFee.Value; AccountService.Update(account); var d = DealWayService.Query().FirstOrDefault(x => x.State == DealWayStates.Normal); var systemDealLog = new SystemDealLog(serialNo, operatorUser) { Amount = saleFee.Value, DealWayId = (d == null ? 0 : d.DealWayId), DealType = SystemDealLogTypes.SaldCardFee, Addin = account.AccountId.ToString() }; SystemDealLogService.Create(systemDealLog); if (d.IsCash) { CashDealLogService.Create(new CashDealLog(systemDealLog.Amount, 0, operatorUser.UserId, systemDealLog.DealType)); } } } // sale Id // var accountShop = ShopService.GetById(command.Account.ShopId); Logger.LogWithSerialNo(LogTypes.AccountOpen, serialNo, command.Account.AccountId, command.Account.Name); var r = new OpenAccountServiceResponse(ResponseCode.Success, command.DealLog, accountShop, command.Account, command.Owner) { SaleFee = saleFee == null ? 0m : saleFee.Value, DepositAmount = command.Account.DepositAmount }; if (command.AccountType != null) { r.AccountType = command.AccountType.DisplayName; } if (!string.IsNullOrEmpty(this.HostSite.TicketTemplateOfOpen)) { var dealLog = command.DealLog; var msg = this.HostSite.TicketTemplateOfOpen; msg = MessageFormator.FormatForOperator(msg, SecurityHelper.GetCurrentUser()); msg = MessageFormator.Format(msg, dealLog); msg = MessageFormator.FormatHowToDeal(msg, command.DealWay.DisplayName); msg = MessageFormator.Format(msg, command.DealLog); msg = MessageFormator.Format(msg, command.AccountType); msg = MessageFormator.Format(msg, command.Owner); msg = MessageFormator.Format(msg, HostSite); r.CodeText = msg; PrintTicketService.Create(new PrintTicket(LogTypes.AccountOpen, serialNo, msg, command.Account)); } return(TransactionHelper.CommitAndReturn(r)); }
public void Delete(SystemDealLog item) { _databaseInstance.Delete(item, TableName); }
public ResultMsg Open(int id, DealWay dealWay) { ResultMsg msgResult = new ResultMsg(); try { User operatorUser = SecurityHelper.GetCurrentUser().CurrentUser; using (Transaction tran = TransactionHelper.BeginTransaction()) { string serialNo = SerialNoHelper.Create(); Account account = AccountService.GetById(id); if (account.State != AccountStates.Ready) { msgResult.CodeText = "不好意思,会员状态不对"; } var command = new OpenAccountCommand(serialNo, account.Name, null, null, null, true, dealWay.DealWayId, null, "批量开卡", operatorUser.UserId, 0, Genders.Male, null); UnityContainer.BuildUp(command); int code = command.Validate(); if (code != ResponseCode.Success) { msgResult.CodeText = "不好意思,验证失败"; } command.Execute(operatorUser); decimal?saleFee = 0m; if (command.AccountType != null) { saleFee = HostSite.SaleCardFee; // 手续费 // if (saleFee != null && saleFee.Value != 0m) { account.ChargingAmount += saleFee.Value; AccountService.Update(account); DealWay d = DealWayService.Query().FirstOrDefault(x => x.State == States.Normal); var systemDealLog = new SystemDealLog(serialNo, operatorUser) { Amount = saleFee.Value, DealWayId = (d == null ? 0 : d.DealWayId), DealType = SystemDealLogTypes.SaldCardFee, Addin = account.AccountId.ToString() }; SystemDealLogService.Create(systemDealLog); if (d.IsCash) { CashDealLogService.Create(new CashDealLog(systemDealLog.Amount, 0, operatorUser.UserId, systemDealLog.DealType)); } } } // sale Id // Logger.LogWithSerialNo(LogTypes.AccountOpen, serialNo, command.Account.AccountId, command.Account.Name); if (!string.IsNullOrEmpty(HostSite.TicketTemplateOfOpen)) { DealLog dealLog = command.DealLog; string msg = HostSite.TicketTemplateOfOpen; msg = MessageFormator.FormatForOperator(msg, SecurityHelper.GetCurrentUser()); msg = MessageFormator.Format(msg, dealLog); msg = MessageFormator.FormatHowToDeal(msg, command.DealWay.DisplayName); msg = MessageFormator.Format(msg, command.DealLog); msg = MessageFormator.Format(msg, command.AccountType); msg = MessageFormator.Format(msg, command.Owner); msg = MessageFormator.Format(msg, HostSite); PrintTicketService.Create(new PrintTicket(LogTypes.AccountOpen, serialNo, msg, command.Account)); } tran.Commit(); msgResult.Code = 1; msgResult.CodeText = "会员建卡 " + account.Name + " 成功"; return(msgResult); } } catch (Exception ex) { msgResult.CodeText = "不好意思,系统异常"; Logger.Error("批量发放会员卡", ex); return(msgResult); } }
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 ListSystemDealLog(SystemDealLog innerObject) { _innerObject = innerObject; }
public ListSystemDealLog() { _innerObject = new SystemDealLog(); }
void IAccountDealDal.SystemDealLogSave(SystemDealLog item) { throw new NotImplementedException(); }
public int SystemDealLogSave(SystemDealLog item) { return(_databaseInstance.Insert(item, "SystemDealLogs")); }
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); }