ServiceCenterController.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. string condition = "";
  39. if (CategoryId > 0)
  40. {
  41. condition += " and CategoryId=" + CategoryId;
  42. }
  43. List<Dictionary<string, object>> querys = new ServiceCenterService().List(new List<FieldItem>(), condition, PageNum, PageSize);
  44. foreach (Dictionary<string, object> subdata in querys)
  45. {
  46. Dictionary<string, object> curData = new Dictionary<string, object>();
  47. curData.Add("Title", subdata["Title"].ToString()); //标题
  48. curData.Add("Id", subdata["Id"].ToString()); //Id
  49. dataList.Add(curData);
  50. }
  51. return dataList;
  52. }
  53. #endregion
  54. #region 商户-常见问题搜索
  55. [Authorize]
  56. public JsonResult Search(string value)
  57. {
  58. value = DesDecrypt(value);
  59. JsonData data = JsonMapper.ToObject(value);
  60. List<Dictionary<string, object>> dataList = SearchDo(value);
  61. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  62. }
  63. public List<Dictionary<string, object>> SearchDo(string value)
  64. {
  65. JsonData data = JsonMapper.ToObject(value);
  66. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  67. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  68. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  69. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  70. string condition = "";
  71. if (!string.IsNullOrEmpty(SearchKey))
  72. {
  73. condition += " and Title like '%" + SearchKey + "%'";
  74. }
  75. List<Dictionary<string, object>> querys = new ServiceCenterService().List(new List<FieldItem>(), condition, PageNum, PageSize);
  76. foreach (Dictionary<string, object> subdata in querys)
  77. {
  78. Dictionary<string, object> curData = new Dictionary<string, object>();
  79. curData.Add("Title", subdata["Title"].ToString()); //标题
  80. curData.Add("Id", subdata["Id"].ToString()); //Id
  81. dataList.Add(curData);
  82. }
  83. return dataList;
  84. }
  85. #endregion
  86. #region 商户-常见问题详情
  87. // [Authorize]
  88. public JsonResult Detail(string value)
  89. {
  90. value = DesDecrypt(value);
  91. JsonData data = JsonMapper.ToObject(value);
  92. Dictionary<string, object> Obj = DetailDo(value);
  93. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  94. }
  95. public Dictionary<string, object> DetailDo(string value)
  96. {
  97. JsonData data = JsonMapper.ToObject(value);
  98. Dictionary<string, object> Obj = new Dictionary<string, object>();
  99. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  100. ServiceCenter query = new ServiceCenterService().Query(Id);
  101. Obj.Add("Title", query.Title); //标题
  102. Obj.Add("Content", CheckContentImage(query.Content)); //内容
  103. return Obj;
  104. }
  105. #endregion
  106. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  107. /// <summary>
  108. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  109. /// </summary>
  110. /// <param name="value">请求的参数(json字符串)</param>
  111. /// <param name="signField">要签名的字段</param>
  112. /// <returns></returns>
  113. private string CheckSign(string value, string[] signField)
  114. {
  115. JsonData json = JsonMapper.ToObject(value);
  116. Dictionary<string, string> dic = new Dictionary<string, string>();
  117. for (int i = 0; i < signField.Length; i++)
  118. {
  119. dic.Add(signField[i], json[signField[i]].ToString());
  120. }
  121. string sign = json["sign"].ToString(); //客户端签名字符串
  122. return new Sign().sign(dic, sign);
  123. }
  124. #endregion
  125. }
  126. }