Exemple #1
0
        public IMessageProvider Done()
        {
            this.Ready();
            if (this.ShouldPayAmount < this.Amount)
            {
                AddError(LogTypes.CashDealLogDone, "amountInvalidate", ShouldPayAmount, Amount);
                return(this);
            }
            var serialNo = SerialNoHelper.Create();
            var user     = SecurityHelper.GetCurrentUser().CurrentUser;
            var amount   = Amount;

            using (var tran = TransactionHelper.BeginTransaction())
            {
                // InnerObject.AccountLevel = AccountLevel;
                InnerObject.DealType   = CashDealLogTypes.EmployeeDeposit;
                InnerObject.UserId     = user.UserId;
                InnerObject.OwnerId    = OwnerId;
                InnerObject.Amount     = -amount;
                InnerObject.SubmitTime = DateTime.Now;
                InnerObject.SubmitDate = this.SubmitDate;
                CashDealLogService.Create(InnerObject);
                AddMessage("success", ShouldPayAmount, amount);
                Logger.LogWithSerialNo(LogTypes.CashDealLogDone, serialNo, InnerObject.CashDealLogId /*, InnerObject.DisplayName*/);
                Amount = amount;
                tran.Commit();
                return(this);
            }
        }
Exemple #2
0
        public void Ready()
        {
            LiquidateId = Id;
            _hasError   = true;
            Liquidate   = LiquidateService.GetById(Id);
            State       = ModelHelper.GetBoundText(Liquidate, x => x.State);
            var currentUser = SecurityHelper.GetCurrentUser().CurrentUser;
            var shop        = ShopService.GetById(Liquidate.ShopId);

            var rate = shop.ShopDealLogChargeRate ?? HostSite.ShopDealLogChargeRate;

            RateAmount   = (Liquidate.DealAmount * rate);
            Amount       = (Liquidate.DealAmount - Liquidate.CancelAmount) - RateAmount;
            Formula      = string.Format("({0} - {1}) - {0} * {2}", Liquidate.DealAmount, Liquidate.CancelAmount, rate.ToString("P"));
            DealAmount   = Liquidate.DealAmount;
            CancelAmount = Liquidate.CancelAmount;
            Count        = Liquidate.Count;

            var ids = Liquidate.DealIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToArray();

            Items = new ItemList <ListShopDealLog>(this.ShopDealLogService.GetByIds(ids).Select(x => new ListShopDealLog(x)));

            CashAmount = CashDealLogService.GetSummary(currentUser.UserId);


            var dealways = from x in DealWayService.Query()
                           where new ApplyToModel(x.ApplyTo).EnabledShopDealAccount
                           select new IdNamePair {
                Key = x.DealWayId, Name = x.DisplayName
            };

            this.DealWay.Bind(dealways);
            this.DealWay.IsReadOnly = this.Liquidate.State == LiquidateStates.Done;
            _hasError = false;
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
        protected override int OnReject(ICommand command)
        {
            RechargingCommand c = (RechargingCommand)command;

            if (c.IsCash)
            {
                var user = MembershipService.GetUserById(c.OperatorUserId);
                CashDealLogService.Create(new CashDealLog(-c.Amount, 0, user.UserId, SystemDealLogTypes.Recharge));
            }
            return(base.OnReject(command));
        }
Exemple #5
0
        public void Suspend(int id)
        {
            TransactionHelper.BeginTransaction();
            var serialNo = SerialNoHelper.Create();
            var item     = this.CashDealLogService.GetById(id);

            if (item != null)
            {
                item.State = CashDealLogStates.Invalid;
                CashDealLogService.Update(item);
                Logger.LogWithSerialNo(LogTypes.CashDealLogSuspend, serialNo, item.CashDealLogId, serialNo);
                AddMessage("suspend.success", serialNo);
            }
            TransactionHelper.Commit();
        }
Exemple #6
0
        public IMessageProvider Create()
        {
            var serialNo = SerialNoHelper.Create();
            var user     = SecurityHelper.GetCurrentUser().CurrentUser;

            using (var tran = TransactionHelper.BeginTransaction())
            {
                // InnerObject.AccountLevel = AccountLevel;
                InnerObject.DealType = CashDealLogTypes.EmployeeLoan;
                InnerObject.UserId   = user.UserId;
                InnerObject.OwnerId  = this.Owner;
                CashDealLogService.Create(InnerObject);
                AddMessage("success" /*, InnerObject.DisplayName*/);
                Logger.LogWithSerialNo(LogTypes.CashDealLogCreate, serialNo, InnerObject.CashDealLogId /*, InnerObject.DisplayName*/);
                tran.Commit();
                return(this);
            }
        }
Exemple #7
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));
        }
Exemple #8
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);
            }
        }
Exemple #9
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);
        }
Exemple #10
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));
        }