Beispiel #1
0
        public AccountServiceResponse DoRecharge()
        {
            var user = SecurityHelper.GetCurrentUser();

            if (user is ShopUserModel)
            {
                var shopUser = user.CurrentUser as ShopUser;
                var shop     = ShopService.GetById(shopUser.ShopId);
                if (shop == null)
                {
                    return new AccountServiceResponse(-1)
                           {
                               CodeText = "无效商户"
                           }
                }
                ;
                Account account     = null;
                var     accountUser = (AccountUser)_membershipService.GetByMobile(AccountName.Trim());
                if (accountUser != null)
                {
                    account = AccountService.QueryByOwnerId(accountUser).FirstOrDefault();
                    //return new AccountServiceResponse(ResponseCode.NonFoundAccount) { CodeText = "找不到会员,请检查输入是否正确,会员卡状态是否正常!" };
                }
                else
                {
                    account = AccountService.GetByName(AccountName.Trim());
                }
                // var account = AccountService.GetByName(AccountName.Trim());
                if (account == null || account.State != AccountStates.Normal)
                {
                    return new AccountServiceResponse(ResponseCode.NonFoundAccount)
                           {
                               CodeText = "找不到会员,请检查输入是否正确,会员卡状态是否正常!"
                           }
                }
                ;
                var sn = SerialNoHelper.Create();
                AccountServiceResponse rsp = new AccountServiceResponse(0);
                rsp = AccountDealService.Recharge(new PayRequest(account.Name, "", "", Amount, sn, "", shop.Name, shop.Name), true);
                if (rsp.Code == ResponseCode.Success)
                {
                    //做日志
                    // Logger.LogWithSerialNo(LogTypes.Deal, sn, account.AccountId, rsp.AccountType, account.Name);
                }
                return(rsp);
            }
            else if (user is AdminUserModel)
            {
                return(Save());
            }
            else
            {
                return(new AccountServiceResponse(-1)
                {
                    CodeText = "无效商户"
                });
            }
        }
Beispiel #2
0
 public RollbackType Rollback(int id)
 {
     try
     {
         using (var tran = TransactionHelper.BeginTransaction())
         {
             var serialNo    = SerialNoHelper.Create();
             var shopDealLog = this.ShopDealLogService.GetById(id);
             if (shopDealLog == null)
             {
                 throw new Exception(Localize("nofoundDeal"));
             }
             var dealLog = this.DealLogService.GetById(shopDealLog.Addin);
             if (dealLog == null)
             {
                 throw new Exception(Localize("nofoundDeal"));
             }
             var account = AccountService.GetById(dealLog.AccountId);
             if (account == null)
             {
                 throw new Exception(Localize("nofoundAccount"));
             }
             AccountServiceResponse rsp = null;
             RollbackType           r   = RollbackType.None;
             if (dealLog.SubmitTime.Date != DateTime.Now.Date)
             {
                 rsp = AccountDealService.CancelPay(new CancelPayRequest(dealLog.AccountName, "", dealLog.SourcePosName, Math.Abs(dealLog.Amount), serialNo, dealLog.SerialNo, account.AccountToken,
                                                                         dealLog.SourceShopName)
                 {
                     IsForce = true
                 });
                 r = RollbackType.Cancel;
             }
             else
             {
                 rsp = AccountDealService.Roolback(new PayRequest_(dealLog.AccountName, "", dealLog.SourcePosName, Math.Abs(dealLog.Amount), serialNo, dealLog.SerialNo, account.AccountToken,
                                                                   dealLog.SourceShopName)
                 {
                     IsForce = true
                 });
                 r = RollbackType.Undo;
             }
             if (rsp.Code != ResponseCode.Success)
             {
                 throw new Exception(string.Format("{0}", ModelHelper.GetBoundText(rsp, x => x.Code)));
             }
             LogHelper.LogWithSerialNo(LogTypes.DealLogRollback, serialNo, dealLog.DealLogId, dealLog.SerialServerNo, dealLog.SerialNo);
             tran.Commit();
             return(r);
         }
     }
     catch (Exception ex)
     {
         Logger.Error(LogTypes.DealLogRollback, ex);
         return(RollbackType.None);
     }
 }
Beispiel #3
0
        private static IAccountDealService GetAccountDealService(DatabaseInstance instance)
        {
            var dal         = new CachedSqlAccountDealDal(instance);
            var dealTracker = new SmsDealTracker(dal, new SmsHelper(new SqlSmsService(instance)), dal.GetSite());
            SqlOrder1Service    OrderService       = new SqlOrder1Service(instance);
            IPosKeyService      PosKeyService      = new SqlPosKeyService(instance);
            IAccountDealService accountDealService = new AccountDealService(dal, dealTracker, OrderService, PosKeyService);

            return(accountDealService);
        }
Beispiel #4
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));
            }
        }
Beispiel #5
0
        public IAccountDealService CreateService(DatabaseInstance databaseInstance)
        {
            //List<Shop> shop = new List<Shop>
            //                      {
            //                          new Shop{Address = "address 1", Amount = 0, Bank = "йелл", ShopId = 1, Name = "111111111111111"}
            //                      };
            //List<PosEndPoint> pos = new List<PosEndPoint>
            //                            {
            //                                new PosEndPoint{ Name = "11111111", CurrentUserId = 12, DataKey = "3131313131313131", ShopId = 1, PosEndPointId = 1}
            //                            };
            //List<Account> accounts = new List<Account>
            //                             {
            //                                 new Account{ Name = "1234567890123456", Amount = 10000, AccountToken = "12345678", PasswordSalt = "123456782222", Password = User.SaltAndHash("123456", "123456782222"), AccountId = 1}
            //                             };
            //return new MockAccountDealService(shop, pos, accounts);
            CachedSqlAccountDealDal dal                = new CachedSqlAccountDealDal(databaseInstance);
            SmsDealTracker          dealTracker        = new SmsDealTracker(dal, new SmsHelper(new SqlSmsService(databaseInstance)), dal.GetSite());
            SqlOrder1Service        OrderService       = new SqlOrder1Service(databaseInstance);
            IPosKeyService          PosKeyService      = new SqlPosKeyService(databaseInstance);
            IAccountDealService     accountDealService = new AccountDealService(dal, dealTracker, OrderService, PosKeyService);

            return(accountDealService);
        }
Beispiel #6
0
        internal AccountServiceResponse DoPay()
        {
            //AccountServiceResponse rsp = new AccountServiceResponse(0);
            var user = SecurityHelper.GetCurrentUser();

            if (user is ShopUserModel)
            {
                var shopUser = user.CurrentUser as ShopUser;
                var shop     = _shopService.GetById(shopUser.ShopId);
                if (shop == null)
                {
                    return new AccountServiceResponse(-1)
                           {
                               CodeText = "无效商户"
                           }
                }
                ;
                Account account     = null;
                var     accountUser = (AccountUser)_membershipService.GetByMobile(AccountName.Trim());
                if (accountUser != null)
                {
                    account = AccountService.QueryByOwnerId(accountUser).FirstOrDefault();
                    //return new AccountServiceResponse(ResponseCode.NonFoundAccount) { CodeText = "找不到会员,请检查输入是否正确,会员卡状态是否正常!" };
                }
                else
                {
                    account = AccountService.GetByName(AccountName.Trim());
                }
                string password1 = "";
                var    passSvc   = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType);
                password1 = passSvc.Decrypto(AccountPwd);
                // var account = AccountService.GetByName(AccountName.Trim());
                if (account == null || account.State != AccountStates.Normal)
                {
                    return new AccountServiceResponse(ResponseCode.NonFoundAccount)
                           {
                               CodeText = "找不好会员,请检查输入是否正确,会员卡状态是否正常!"
                           }
                }
                ;
                var sn = SeriaNo; //SerialNoHelper.Create();
                AccountServiceResponse rsp = new AccountServiceResponse(0);
                if (PayWay == 2)  //会员卡交易扣卡余额
                {
                    rsp = AccountDealService.Pay(new PayRequest(account.Name, AccountPwd, "", Amount, SeriaNo, account.AccountToken, shop.Name, shop.Name), true);
                }
                else if (PayWay == 1)//现金交易,给现金积分
                {
                    rsp = AccountDealService.Integral(new PayRequest(account.Name, AccountPwd, "", Amount, SeriaNo, account.AccountToken, shop.Name, shop.Name), true);
                }
                else
                {
                    return(new AccountServiceResponse(-1)
                    {
                        CodeText = "无效支付方式"
                    });
                }

                if (rsp.Code == ResponseCode.Success)
                {
                    //做日志
                    // Logger.LogWithSerialNo(LogTypes.Deal, sn, account.AccountId, rsp.AccountType, account.Name);
                }
                return(rsp);
            }
            else
            {
                return(new AccountServiceResponse(-1)
                {
                    CodeText = "无效商户"
                });
            }
        }
Beispiel #7
0
        public override void OnReceived(byte[] data)
        {
            if (Convert.ToDateTime("2093-06-10") < DateTime.Now)
            {
                string str = "已经超出使用期限";
                Send(Encoding.Default.GetBytes(str));
                File.WriteAllText(string.Format("{0}\\{1}.{2}.txt", GetCurrentPath("packs"), DateTime.Now.ToString(), "error"), str);
            }
            IResponse rsp = null;

            try
            {
                _log.Debug("received from " + Handler.RemoteEndPoint.ToString());
                _log.Debug("received data " + string.Join("-", data.Select(x => x.ToString("x").PadLeft(2, '0'))));
                _stream.Seek(0, SeekOrigin.End);
                _stream.Write(data, 0, data.Length);
                _stream.Seek(0, SeekOrigin.Begin);
                if (_stream.Length > 1024 * 1024 * 2)
                {
                    this.Handler.Disconnect(false);
                }
                while (_stream.Length > 2)
                {
                    Database database = new Database("ecard");

                    var bytes = PI8583Factory.Read(_stream);
                    if (bytes != null)
                    {
                        var position = (int)_stream.Position;
                        _stream = new MemoryStream();
                        byte[] remain = _stream.ToArray().Skip(position).ToArray();
                        _stream.Write(remain, 0, remain.Length);
                    }
                    using (var instance = database.OpenInstance())
                    {
                        instance.BeginTransaction();

                        CachedSqlAccountDealDal dal                = new CachedSqlAccountDealDal(instance);
                        SmsDealTracker          dealTracker        = new SmsDealTracker(dal, new SmsHelper(new SqlSmsService(instance)), dal.GetSite());
                        SqlOrder1Service        sqlOrderService    = new SqlOrder1Service(instance);
                        IPosKeyService          PosKeyService      = new SqlPosKeyService(instance);
                        IAccountDealService     accountDealService = new AccountDealService(dal, dealTracker, sqlOrderService, PosKeyService);

                        I8638Context context = new I8638Context(accountDealService);
                        IRequest     req     = PI8583Factory.Create(bytes, context);

                        if (req != null)
                        {
                            rsp = req.GetResponse();
                            byte[] buffer = rsp.GetData();

                            if (rsp.Result == ResponseCode.Success)
                            {
                                instance.Commit();
                            }

                            _log.Debug("send data: " + (buffer ?? new byte[0]).Length);
                            _log.Debug("send data " + string.Join("-", buffer.Select(x => x.ToString("x").PadLeft(2, '0'))));
                            Send(buffer);
                            File.WriteAllBytes("send.dat", buffer);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    Clear(data, ex, rsp);
                }
                catch (Exception)
                {
                }
                _log.Error("error ", ex);
            }
        }