/// <summary> /// 账号充值 /// </summary> /// <param name="accountID">充值账号</param> /// <param name="quantity">充值数</param> /// <param name="operatorAccount">操作人</param> /// <returns></returns> public RPCResult AccountPrepaid(string accountID, uint quantity, string operatorAccount) { try { if (string.IsNullOrEmpty(accountID)) { LogHelper.LogWarn("SMSService", "SMSService.AccountPrepaid", "充值账号为空"); return(new RPCResult(false, "充值账号不能为空!")); } Account account = AccountDB.GetAccount(accountID);//AccountServer.Instance.GetAccount(accountID); if (account == null) { LogHelper.LogWarn("SMSService", "SMSService.AccountPrepaid", "充值账号不存在"); return(new RPCResult(false, "账号不存在")); } if (account.SMSNumber + (int)quantity < 0 && quantity > 10000000) { return(new RPCResult(false, "充值金额太大")); } if (AccountDB.AccountPrepaid(account.AccountID, (int)quantity)) { PrepaidRecordDB.Add(operatorAccount, accountID, quantity); return(new RPCResult(true, "充值成功")); } LogHelper.LogWarn("SMSService", "SMSService.AccountPrepaid", "充值数据库操作失败"); return(new RPCResult(false, "充值失败")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.AccountPrepaid", ex.ToString()); return(new RPCResult(false, "充值失败")); } }
public void AccountTest() { Account account = new Account() { AccountID = guid.ToString(), SMSNumber = 10 }; var b = AccountDB.CreateAccount(account); Assert.IsTrue(b); b = AccountDB.AccountPrepaid(account.AccountID, 10); Assert.IsTrue(b); int c = AccountDB.GetSMSNumberByAccount(account.AccountID); Assert.AreEqual(20, c); var a = AccountDB.GetAccount(account.AccountID); Assert.IsNotNull(a); Assert.AreEqual(a.AccountID, account.AccountID); Assert.AreEqual(a.SMSNumber, 20); b = AccountDB.DeductAccountSMSCharge(account.AccountID, 10); Assert.IsTrue(b); c = AccountDB.GetSMSNumberByAccount(account.AccountID); Assert.AreEqual(10, c); b = AccountDB.ReAccountSMSCharge(account.AccountID, 10); Assert.IsTrue(b); c = AccountDB.GetSMSNumberByAccount(account.AccountID); Assert.AreEqual(20, c); var accs = AccountDB.GetAccounts(); Assert.IsNotNull(accs); Assert.IsTrue(accs.Count > 0); b = AccountDB.DelAccount(account.AccountID); Assert.IsTrue(b); }