Ejemplo n.º 1
0
        public SimpleAjaxResult Save()
        {
            if (Amount < 0)
            {
                return(new SimpleAjaxResult(Localize("invalidAmount")));
            }

            try
            {
                var serialNo = SerialNoHelper.Create();
                TransactionHelper.BeginTransaction();
                var prePay = PrePayService.GetById(Id);
                if (prePay != null && prePay.State == PrePayStates.Processing)
                {
                    if (Amount == 0)
                    {
                        Amount = prePay.Amount;
                    }
                    var account = AccountService.GetById(prePay.AccountId);
                    if (account == null)
                    {
                        return(new SimpleAjaxResult(Localize("invalidAccount")));
                    }

                    var rsp = AccountDealService.DonePrePay(new PayRequest(prePay.AccountName, "", prePay.ShopName, Amount, serialNo,
                                                                           account.AccountToken, prePay.ShopName, prePay.ShopName)
                    {
                        IsForce = true
                    });
                    if (rsp.Code != ResponseCode.Success)
                    {
                        return(new SimpleAjaxResult(ModelHelper.GetBoundText(rsp, x => x.Code)));
                    }

                    Logger.LogWithSerialNo(LogTypes.DonePrePayForce, serialNo, Id, account.Name);
                    DataAjaxResult r = new DataAjaxResult();
                    //if (!string.IsNullOrWhiteSpace(HostSite.TicketTemplateOfSuspendAccount))
                    //{
                    //    r.Data1 = MessageFormator.FormatTickForSuspendAccount(HostSite.TicketTemplateOfSuspendAccount, HostSite,
                    //                                                          prePay, SecurityHelper.GetCurrentUser().CurrentUser);
                    //    PrintTicketService.Create(new PrintTicket(LogTypes.AccountSuspend, r.Data1.ToString(), prePay));
                    //}
                    return(TransactionHelper.CommitAndReturn(r));
                }
                return(new SimpleAjaxResult(Localize("invalidDeal")));
            }
            catch (System.Exception ex)
            {
                Logger.Error(LogTypes.DonePrePayForce, ex);
                return(new SimpleAjaxResult(ex.Message));
            }
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 3
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")));
            }
        }