Example #1
0
        public void SendMessage()
        {
            List <AccountWithOwner> accounts;

            if (SendToAll == true)
            {
                AccountRequest request = GetAccountRequest();
                accounts = AccountService.QueryAccountWithOwner(request).ToList();
            }
            else
            {
                int[] ids = CheckItems.GetCheckedIds();
                accounts = AccountService.QueryAccountWithOwner(new AccountRequest {
                    Ids = ids
                }).ToList();
            }
            foreach (AccountWithOwner account in accounts)
            {
                string msg = MessageFormator.Format(MessageTemplate, account);
                msg = MessageFormator.Format(msg, HostSite);
                msg = MessageFormator.Format(msg,
                                             new AccountUser
                {
                    DisplayName = account.OwnerDisplayName,
                    Gender      = Genders.Male,
                    Mobile      = account.OwnerMobileNumber
                });
                SmsHelper.Send(account.OwnerMobileNumber, msg);
            }
            AddMessage("发送短信成功!共发送给 {0} 会员", accounts.Count);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        public void Notify(Account account, AccountUser owner, DealLog dealItem)
        {
            try
            {
                var site = _siteService.GetSite();
                if (site != null && !string.IsNullOrWhiteSpace(site.MessageTemplateOfDeal))
                {
                    if (owner != null && owner.IsMobileAvailable)
                    {
                        var text = "";
                        switch (dealItem.DealType)
                        {
                        case DealTypes.Deal:
                            text = site.MessageTemplateOfDeal;
                            break;

                        case DealTypes.Integral:
                            text = site.MessageTemplateOfDeal;
                            break;

                        case DealTypes.Recharging:
                            text = site.MessageTemplateOfRecharge;
                            break;

                        case DealTypes.DonePrePay:
                            text = site.MessageTemplateOfDonePrePay;
                            break;

                        case DealTypes.PrePay:
                            text = site.MessageTemplateOfPrePay;
                            break;

                        default:
                            break;
                        }
                        if (string.IsNullOrWhiteSpace(text))
                        {
                            return;
                        }

                        text = MessageFormator.Format(text, owner);
                        text = MessageFormator.Format(text, dealItem);
                        text = MessageFormator.Format(text, account);
                        text = MessageFormator.Format(text, _site);


                        _smsHelper.Send(owner.Mobile, text);

                        _log.Info("send sms for " + account.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error("send message failed!", ex);
            }
        }
Example #5
0
        public DataAjaxResult Print()
        {
            try
            {
                IPasswordService passwordService = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType);
                var password = passwordService.Decrypto(this.Password);

                if (string.IsNullOrWhiteSpace(this.HostSite.TicketTemplateOfDeal))
                {
                    return(new DataAjaxResult(Localize("nonTemplateOfDeal", "请先设置消费打印模板")));
                }
                var shopDealLog = this.ShopDealLogService.GetById(Id);
                if (shopDealLog == null)
                {
                    return(new DataAjaxResult(Localize("nonShopDealLog", "指定商户交易未找到")));
                }
                var deallog = this.DealLogService.GetById(shopDealLog.Addin);
                if (deallog == null)
                {
                    return(new DataAjaxResult(Localize("nonShopDealLog", "指定会员交易未找到")));
                }
                var account = this.AccountService.GetById(deallog.AccountId);
                if (account == null)
                {
                    return(new DataAjaxResult(Localize("nonAccount", "指定会员未找到")));
                }
                if (User.SaltAndHash(password, account.PasswordSalt) != account.Password)
                {
                    return(new DataAjaxResult(Localize("invalidPassword", "密码错误")));
                }
                var shop = this.ShopService.GetById(deallog.ShopId);
                if (shop == null)
                {
                    return(new DataAjaxResult(Localize("nonShop", "指定商户未找到")));
                }
                var dealWay = this.DealWayService.GetById(shop.DealWayId);
                if (dealWay == null)
                {
                    return(new DataAjaxResult(Localize("nonDealWay", "指定支付渠道未找到")));
                }

                var msg = this.HostSite.TicketTemplateOfDeal.Trim();
                msg = MessageFormator.FormatTickForDeal(msg, HostSite, deallog, account, ShopService.GetById(deallog.ShopId), PosEndPointService.GetById(deallog.SourcePosId), SecurityHelper.GetCurrentUser());
                return(new DataAjaxResult()
                {
                    Data1 = msg
                });
            }
            catch (System.Exception ex)
            {
                return(new DataAjaxResult(ex.Message));
            }
        }
Example #6
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 #7
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 #8
0
        public void Execute()
        {
            if (string.IsNullOrWhiteSpace(_site.MessageTemplateOfBirthDate))
            {
                return;
            }

            var users = GetAccounts();

            foreach (var user in users)
            {
                if (user is AccountUser && user.IsMobileAvailable)
                {
                    var text = MessageFormator.Format(_site.MessageTemplateOfBirthDate, user);
                    _smsHelper.Send(user.Mobile, text);
                }
            }
        }
Example #9
0
        public ActionResult SendSmsCode(string number, string userName)
        {
            var msg          = MessageFormator.Format(_site.MessageTemplateOfIdentity ?? "", _site);
            var randomNumber = RandomHelper.GenerateNumber(6);

            CodeHelper.CreateObject("sms", randomNumber, TimeSpan.FromMinutes(5));
            CodeHelper.CreateObject("sms_mobile", number, TimeSpan.FromMinutes(5));
            try
            {
                msg = msg.Replace("#code#", randomNumber);
                msg = msg.Replace("#username#", userName);
                _smsHelper.Send(number, msg);
                return(Json("验证短信发送成功.", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Error(LogTypes.SendSmsCode, ex);
                return(Json("验证短信发送失败: " + ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Example #10
0
        public void Init(AccountServiceResponse rsp, int dealType)
        {
            Code  = rsp.Code;
            Error = ModelHelper.GetBoundText(this, x => x.Code);
            if (Code == ResponseCode.Success)
            {
                var dealLog = DealLogService.GetById(Convert.ToInt32(rsp.SerialServerNo));
                ShopName       = dealLog.ShopName;
                PosName        = dealLog.SourcePosName;
                AccountName    = dealLog.AccountName;
                Amount         = dealLog.Amount;
                SerialNo       = dealLog.SerialNo;
                ServerSerialNo = dealLog.SerialServerNo;

                if (Code == ResponseCode.Success)
                {
                    var account     = AccountService.GetByName(AccountName);
                    var shop        = ShopService.GetByName(ShopName);
                    var pos         = PosService.GetById(dealLog.SourcePosId);
                    var currentUser = SecurityHelper.GetCurrentUser().CurrentUser;
                    switch (dealType)
                    {
                    case DealTypes.Deal:

                        if (!string.IsNullOrWhiteSpace(HostSite.TicketTemplateOfDeal))
                        {
                            this.Ticket = MessageFormator.FormatTickForDeal(HostSite.TicketTemplateOfDeal, HostSite, dealLog, account, shop, pos, currentUser);
                        }
                        break;

                    case DealTypes.CancelDeal:
                        if (!string.IsNullOrWhiteSpace(HostSite.TicketTemplateOfCancelDeal))
                        {
                            this.Ticket = MessageFormator.FormatTickForDeal(HostSite.TicketTemplateOfCancelDeal, HostSite, dealLog, account, shop, pos, currentUser);
                        }
                        break;
                    }
                }
            }
        }
Example #11
0
        public void NotifyCode(Shop shop, Shop shopTo, ShopDealLog shopDealLog, string shopNameTo)
        {
            try
            {
                var site = _siteService.GetSite();

                if (site != null && !string.IsNullOrWhiteSpace(site.MessageTemplateOfDealCode) && !string.IsNullOrWhiteSpace(shopNameTo) && Regex.IsMatch(shopNameTo, @"^\d{11}$"))
                {
                    var text = site.MessageTemplateOfDealCode;

                    text = MessageFormator.Format(text, shopTo);
                    text = text.Replace("#code#", shopDealLog.Code);

                    _smsHelper.Send(shopNameTo, text);
                    _log.Info("send sms for " + shopNameTo);
                }
            }
            catch (Exception ex)
            {
                _log.Error("send message failed!", ex);
            }
        }
Example #12
0
        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));
        }
Example #13
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 #14
0
        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);
            }
        }
Example #15
0
        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);
        }
Example #16
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 #17
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")));
            }
        }