ServiceCenterController.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 ServiceCenterController : BaseController
  18. {
  19. public ServiceCenterController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 商户-常见问题列表
  23. // [Authorize]
  24. public JsonResult List(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = ListDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> ListDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int CategoryId = int.Parse(function.CheckInt(data["CategoryId"].ToString())); //问答类型
  35. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  36. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  37. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  38. List<ServiceCenter> querys = RedisDbconn.Instance.GetList<ServiceCenter>("ServiceCenterList", 1, 1000000);
  39. if (CategoryId > 0)
  40. {
  41. querys = querys.Where(m => m.CategoryId == CategoryId).ToList();
  42. }
  43. if (PageNum == 1)
  44. {
  45. querys = querys.Take(PageSize).ToList();
  46. }
  47. else
  48. {
  49. int skipNum = PageSize * (PageNum - 1);
  50. querys = querys.Skip(skipNum).Take(PageSize).ToList();
  51. }
  52. foreach (ServiceCenter subdata in querys)
  53. {
  54. Dictionary<string, object> curData = new Dictionary<string, object>();
  55. curData.Add("Title", subdata.Title); //标题
  56. curData.Add("Id", subdata.Id); //Id
  57. dataList.Add(curData);
  58. }
  59. return dataList;
  60. }
  61. #endregion
  62. #region 商户-常见问题搜索
  63. [Authorize]
  64. public JsonResult Search(string value)
  65. {
  66. value = DesDecrypt(value);
  67. JsonData data = JsonMapper.ToObject(value);
  68. List<Dictionary<string, object>> dataList = SearchDo(value);
  69. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  70. }
  71. public List<Dictionary<string, object>> SearchDo(string value)
  72. {
  73. JsonData data = JsonMapper.ToObject(value);
  74. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  75. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  76. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  77. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  78. List<ServiceCenter> querys = RedisDbconn.Instance.GetList<ServiceCenter>("ServiceCenterList", 1, 1000000);
  79. if (!string.IsNullOrEmpty(SearchKey))
  80. {
  81. querys = querys.Where(m => m.Title.Contains(SearchKey)).ToList();
  82. }
  83. if (PageNum == 1)
  84. {
  85. querys = querys.Take(PageSize).ToList();
  86. }
  87. else
  88. {
  89. int skipNum = PageSize * (PageNum - 1);
  90. querys = querys.Skip(skipNum).Take(PageSize).ToList();
  91. }
  92. foreach (ServiceCenter subdata in querys)
  93. {
  94. Dictionary<string, object> curData = new Dictionary<string, object>();
  95. curData.Add("Title", subdata.Title); //标题
  96. curData.Add("Id", subdata.Id); //Id
  97. dataList.Add(curData);
  98. }
  99. return dataList;
  100. }
  101. #endregion
  102. #region 商户-常见问题详情
  103. // [Authorize]
  104. public JsonResult Detail(string value)
  105. {
  106. value = DesDecrypt(value);
  107. JsonData data = JsonMapper.ToObject(value);
  108. Dictionary<string, object> Obj = DetailDo(value);
  109. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  110. }
  111. public Dictionary<string, object> DetailDo(string value)
  112. {
  113. JsonData data = JsonMapper.ToObject(value);
  114. Dictionary<string, object> Obj = new Dictionary<string, object>();
  115. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  116. ServiceCenter query = RedisDbconn.Instance.Get<ServiceCenter>("ServiceCenter:" + Id) ?? new ServiceCenter();
  117. Obj.Add("Title", query.Title); //标题
  118. Obj.Add("Content", CheckContentImage(query.Content)); //内容
  119. return Obj;
  120. }
  121. #endregion
  122. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  123. /// <summary>
  124. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  125. /// </summary>
  126. /// <param name="value">请求的参数(json字符串)</param>
  127. /// <param name="signField">要签名的字段</param>
  128. /// <returns></returns>
  129. private string CheckSign(string value, string[] signField)
  130. {
  131. JsonData json = JsonMapper.ToObject(value);
  132. Dictionary<string, string> dic = new Dictionary<string, string>();
  133. for (int i = 0; i < signField.Length; i++)
  134. {
  135. dic.Add(signField[i], json[signField[i]].ToString());
  136. }
  137. string sign = json["sign"].ToString(); //客户端签名字符串
  138. return new Sign().sign(dic, sign);
  139. }
  140. #endregion
  141. }
  142. }