Beispiel #1
0
        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", "兑换失败")));
            }
        }
Beispiel #2
0
        public void Ready()
        {
            var id = 0;

            if (!int.TryParse(ServerSerialNo, out id))
            {
                return;
            }

            DealLog = DealLogService.GetById(id);
            if (DealLog == null)
            {
                return;
            }
            if (DealLog.State != DealLogStates.Normal || DealLog.DealType != DealTypes.Deal)
            {
                DealLog = null;
                return;
            }
            var       user      = SecurityHelper.GetCurrentUser().CurrentUser;
            AdminUser adminUser = user as AdminUser;

            if (adminUser != null)
            {
                if (DealLog.SourceShopName != Constants.SystemShopName)
                {
                    DealLog = null;
                    return;
                }
            }
            ShopUser shopUser = user as ShopUser;

            if (shopUser != null)
            {
                var shop = ShopService.GetById(shopUser.ShopId);
                if (DealLog.SourceShopName != shop.Name)
                {
                    DealLog = null;
                    return;
                }
            }
        }
Beispiel #3
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;
                    }
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public void Ready()
        {
            var user = SecurityHelper.GetCurrentUser().CurrentUser;

            // debug
            var       posName   = "";
            AdminUser adminUser = user as AdminUser;

            if (adminUser != null)
            {
                _sourceShopName = Constants.SystemShopName;
                var pos = this.PosEndPointService.GetByCurrentUserId(adminUser.UserId);
                if (pos == null)
                {
                    Error = "请先创建终端,再进行交易!";
                    return;
                }
                posName = pos.Name;
            }
            ShopUser shopUser = user as ShopUser;

            if (shopUser != null)
            {
                var pos = PosEndPointService.Query(new PosEndPointRequest()
                {
                    ShopId = shopUser.ShopId, State = PosEndPointStates.Normal
                }).FirstOrDefault();
                if (pos == null)
                {
                    Error = "请先创建终端,再进行交易!";
                    return;
                }
                posName = pos.Name;
                var shop = ShopService.GetById(shopUser.ShopId);
                _sourceShopName = shop.Name;
                ShopName        = shop.Name;
            }



            // debug end
            IPasswordService passwordService = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType);
            var password = passwordService.Decrypto(Password);

            var dealLog = DealLogService.GetById(Convert.ToInt32(ServerSerialNo));

            ShopName     = dealLog.ShopName;
            Amount       = dealLog.Amount;
            AccountName  = dealLog.AccountName;
            _oldSerialNo = dealLog.SerialNo;
            var account = AccountService.GetByName(AccountName);
            var token   = account == null ? "" : account.AccountToken;

            Response = InnerCall(token, posName, password);

            this.Code      = Response.Code;
            ServerSerialNo = Response.SerialServerNo;
            if (Response.Code == ResponseCode.InvalidatePassword)
            {
                IsRetry = true;
                Error   = ModelHelper.GetBoundText(this, x => x.Code);
            }
            else if (Response.Code != ResponseCode.Success)
            {
                Error = ModelHelper.GetBoundText(this, x => x.Code);
            }
        }
Beispiel #6
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")));
            }
        }
Beispiel #7
0
        public void Query()
        {
            var request = new ShopDealLogRequest();

            if (State != ShopDealLogStates.All)
            {
                request.State = State;
            }
            request.SubmitDateMin = Data.Start;
            request.SubmitDateMax = Data.GetEnd();
            request.AccountName   = AccountName;
            if (Shop != Globals.All)
            {
                request.ShopId = Shop;
            }
            request.SerialNo    = SerialNo;
            request.IsLiquidate = IsLiquidate;
            var user = SecurityHelper.GetCurrentUser().CurrentUser as ShopUser;

            if (user != null)
            {
                request.ShopId = user.ShopId;
            }
            if (AccountShop != Globals.All)
            {
                request.AccountShopId = AccountShop;
            }
            var query = ShopDealLogService.Query(request);

            this.List = query.ToList(this, x => new ListShopDealLog(x));

            var shopIds = List.Select(x => x.InnerObject.ShopId).Distinct();
            var shops   = ShopService.Query(new ShopRequest()
            {
                ShopIds = shopIds.ToArray()
            }).ToList();

            foreach (var log in List)
            {
                var shop = shops.FirstOrDefault(x => x.ShopId == log.InnerObject.ShopId);
                if (shop != null)
                {
                    log.TempShop = shop;
                }
            }

            var dealLogIds = List.Select(x => x.InnerObject.Addin).Distinct();

            var dealLogs = DealLogService.GetByIds(dealLogIds.ToArray()).ToList();

            foreach (var log in List)
            {
                var shop = dealLogs.FirstOrDefault(x => x.DealLogId == log.InnerObject.Addin);
                if (shop != null)
                {
                    log.DealLog = shop;
                }
            }


            //
            var q = (from x in ShopService.Query(new ShopRequest()
            {
                IsBuildIn = false, State = ShopStates.Normal
            })
                     select new IdNamePair {
                Key = x.ShopId, Name = x.FormatedName
            }).ToList();

            q.Insert(0, new IdNamePair {
                Key = Ecard.Models.Shop.Default.ShopId, Name = Ecard.Models.Shop.Default.FormatedName
            });
            this.AccountShop.Bind(q, true);
        }
Beispiel #8
0
        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);
        }