ActivityInfoController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 ActivityInfoController : BaseController
  18. {
  19. public ActivityInfoController(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 PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  35. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  36. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  37. List<Dictionary<string, object>> query = new ActivityInfoService().List(new List<FieldItem>(), "", PageNum, PageSize);
  38. foreach (Dictionary<string, object> subdata in query)
  39. {
  40. Dictionary<string, object> curData = new Dictionary<string, object>();
  41. curData.Add("ActBanner", DefaultPic(subdata["ActBanner"].ToString())); //活动Banner图片
  42. curData.Add("Id", subdata["Id"].ToString()); //Id
  43. curData.Add("Status", subdata["Status"].ToString()); //Status
  44. dataList.Add(curData);
  45. }
  46. return dataList;
  47. }
  48. #endregion
  49. #region 商户-活动详情
  50. [Authorize]
  51. public JsonResult Detail(string value)
  52. {
  53. value = DesDecrypt(value);
  54. JsonData data = JsonMapper.ToObject(value);
  55. Dictionary<string, object> Obj = DetailDo(value);
  56. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  57. }
  58. public Dictionary<string, object> DetailDo(string value)
  59. {
  60. JsonData data = JsonMapper.ToObject(value);
  61. Dictionary<string, object> Obj = new Dictionary<string, object>();
  62. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  63. ActivityInfo query = new ActivityInfoService().Query(Id);
  64. Obj.Add("ActContent", query.ActContent); //活动详情
  65. return Obj;
  66. }
  67. #endregion
  68. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  69. /// <summary>
  70. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  71. /// </summary>
  72. /// <param name="value">请求的参数(json字符串)</param>
  73. /// <param name="signField">要签名的字段</param>
  74. /// <returns></returns>
  75. private string CheckSign(string value, string[] signField)
  76. {
  77. JsonData json = JsonMapper.ToObject(value);
  78. Dictionary<string, string> dic = new Dictionary<string, string>();
  79. for (int i = 0; i < signField.Length; i++)
  80. {
  81. dic.Add(signField[i], json[signField[i]].ToString());
  82. }
  83. string sign = json["sign"].ToString(); //客户端签名字符串
  84. return new Sign().sign(dic, sign);
  85. }
  86. #endregion
  87. }
  88. }