UserRankWhiteController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class UserRankWhiteController : BaseController
  18. {
  19. public UserRankWhiteController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 创客-首页-我的创客-创客当前职级信息
  23. [Authorize]
  24. public JsonResult Detail(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. int UserId = int.Parse(function.CheckInt(data["Id"].ToString())); //用户
  29. Dictionary<string, object> Obj = new Dictionary<string, object>();
  30. UserRankWhite query = maindb.UserRankWhite.FirstOrDefault(m => m.Id == UserId);
  31. if (query != null)
  32. {
  33. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //调整时间
  34. Obj.Add("ExpiredDate", query.UpdateDate == null ? "" : query.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //到期时间
  35. if (query.UpdateDate < DateTime.Now)
  36. {
  37. return Json(new AppResultJson() { Status = "-1", Info = "", Data = Obj });
  38. }
  39. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  40. }
  41. return Json(new AppResultJson() { Status = "-1", Info = "", Data = Obj });
  42. }
  43. #endregion
  44. #region 创客-首页-我的创客-设置职级
  45. [Authorize]
  46. public JsonResult SetLevel(string value)
  47. {
  48. value = DesDecrypt(value);
  49. JsonData data = JsonMapper.ToObject(value);
  50. AppResultJson result = SetLevelDo(value);
  51. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  52. }
  53. public AppResultJson SetLevelDo(string value)
  54. {
  55. JsonData data = JsonMapper.ToObject(value);
  56. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //用户
  57. int UserLevel = int.Parse(function.CheckInt(data["UserLevel"].ToString())); //职级
  58. string ExpireDate = data["ExpireDate"].ToString(); //到期时间
  59. DateTime time = DateTime.Parse(ExpireDate + "-01 00:00:00").AddMonths(1);
  60. Dictionary<string, object> Obj = new Dictionary<string, object>();
  61. UserRankWhite query = maindb.UserRankWhite.FirstOrDefault(m => m.Id == UserId);
  62. if (query == null)
  63. {
  64. query = maindb.UserRankWhite.Add(new UserRankWhite()
  65. {
  66. CreateDate = DateTime.Now, //设置时间
  67. UpdateDate = time, //过期时间
  68. Rank = UserLevel,
  69. UserId = UserId, //用户
  70. Id = UserId,
  71. }).Entity;
  72. }
  73. else
  74. {
  75. query.CreateDate = DateTime.Now; //设置时间
  76. query.UpdateDate = time; //过期时间
  77. query.Rank = UserLevel;
  78. }
  79. maindb.SaveChanges();
  80. Obj.Add("Id", query.Id); //Id
  81. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  82. }
  83. #endregion
  84. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  85. /// <summary>
  86. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  87. /// </summary>
  88. /// <param name="value">请求的参数(json字符串)</param>
  89. /// <param name="signField">要签名的字段</param>
  90. /// <returns></returns>
  91. private string CheckSign(string value, string[] signField)
  92. {
  93. JsonData json = JsonMapper.ToObject(value);
  94. Dictionary<string, string> dic = new Dictionary<string, string>();
  95. for (int i = 0; i < signField.Length; i++)
  96. {
  97. dic.Add(signField[i], json[signField[i]].ToString());
  98. }
  99. string sign = json["sign"].ToString(); //客户端签名字符串
  100. return new Sign().sign(dic, sign);
  101. }
  102. #endregion
  103. }
  104. }