AccountService.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Lottomat.Application.Entity;
  2. using Lottomat.Application.IService;
  3. using Lottomat.Data;
  4. using Lottomat.Data.Repository;
  5. using Lottomat.Util;
  6. using Lottomat.Util.Extension;
  7. using System;
  8. using System.Data.Common;
  9. using System.Linq;
  10. using Lottomat.Application.Code;
  11. using Lottomat.Utils.Date;
  12. using Lottomat.Utils.Web;
  13. namespace Lottomat.Application.Service
  14. {
  15. /// <summary>
  16. /// 版 本
  17. /// Copyright (c) 2016-2017
  18. /// 创建人:赵轶
  19. /// 日 期:2016.05.11 16:23
  20. /// 描 述:注册账户
  21. /// </summary>
  22. public class AccountService : RepositoryFactory<AccountEntity>, IAccountService
  23. {
  24. /// <summary>
  25. /// 登录验证
  26. /// </summary>
  27. /// <param name="mobileCode">用户名</param>
  28. /// <param name="password">密码</param>
  29. /// <returns></returns>
  30. public AccountEntity CheckLogin(string mobileCode, string password)
  31. {
  32. var expression = LinqExtensions.True<AccountEntity>();
  33. expression = expression.And(t => t.MobileCode == mobileCode);
  34. expression = expression.And(t => t.DeleteMark == (int)DeleteMarkEnum.NotDelete);
  35. return this.BaseRepository("AccountDb").FindEntity(expression);
  36. }
  37. /// <summary>
  38. /// 获取验证码
  39. /// </summary>
  40. /// <param name="mobileCode">手机号码</param>
  41. /// <returns>返回6位数验证码</returns>
  42. public string GetSecurityCode(string mobileCode)
  43. {
  44. if (!this.BaseRepository("AccountDb").IQueryable(t => t.MobileCode == mobileCode).Any())
  45. {
  46. //验证每个IP 不能获取超过5次
  47. if (this.BaseRepository("AccountDb").IQueryable(t => t.IPAddress == NetHelper.Ip).Count() >= 5)
  48. {
  49. throw new Exception("获取验证码失败。");
  50. }
  51. AccountEntity accountEntity = new AccountEntity
  52. {
  53. AccountId = CommonHelper.GetGuid().ToString(),
  54. MobileCode = mobileCode,
  55. SecurityCode = CommonHelper.RndNum(6),
  56. IPAddress = NetHelper.Ip,
  57. CreateDate = DateTimeHelper.Now,
  58. EnabledMark = -1
  59. };
  60. this.BaseRepository("AccountDb").Insert(accountEntity);
  61. return accountEntity.SecurityCode;
  62. }
  63. else
  64. {
  65. throw new Exception("手机号已被注册过了。");
  66. }
  67. }
  68. /// <summary>
  69. /// 注册账户
  70. /// </summary>
  71. /// <param name="accountEntity">实体对象</param>
  72. public void Register(AccountEntity accountEntity)
  73. {
  74. var data = this.BaseRepository("AccountDb").FindEntity(t => t.MobileCode == accountEntity.MobileCode);
  75. if (data == null && data.SecurityCode == accountEntity.SecurityCode)
  76. {
  77. throw new Exception("短信验证码不正确。");
  78. }
  79. if (data.RegisterTime != null)
  80. {
  81. throw new Exception("手机号已被注册过了。");
  82. }
  83. accountEntity.AccountId = data.AccountId;
  84. accountEntity.RegisterTime = DateTimeHelper.Now;
  85. accountEntity.ExpireTime = DateTimeHelper.Now.AddMonths(1);
  86. accountEntity.DeleteMark = (int)DeleteMarkEnum.NotDelete;
  87. accountEntity.EnabledMark = 1;
  88. this.BaseRepository("AccountDb").Update(accountEntity);
  89. }
  90. /// <summary>
  91. /// 登录限制
  92. /// </summary>
  93. /// <param name="platform">平台(苹果、安卓、PC浏览器)</param>
  94. /// <param name="account">账户</param>
  95. /// <param name="iPAddress">IP地址</param>
  96. /// <param name="iPAddressName">IP所在城市</param>
  97. public void LoginLimit(string platform, string account, string iPAddress, string iPAddressName)
  98. {
  99. //调用存储过程
  100. DbParameter[] parameter =
  101. {
  102. DbParameters.CreateDbParameter("@IPAddress",iPAddress),
  103. DbParameters.CreateDbParameter("@IPAddressName",iPAddressName),
  104. DbParameters.CreateDbParameter("@Account",account),
  105. DbParameters.CreateDbParameter("@Platform",platform),
  106. };
  107. int IsOk = this.BaseRepository("AccountDb").ExecuteByProc("PROC_verify_IPAddress", parameter);
  108. }
  109. }
  110. }