ProfitRewardRecordController.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 ProfitRewardRecordController : BaseController
  18. {
  19. public ProfitRewardRecordController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 首页-客小爽产品-收益查看-交易分润
  23. [Authorize]
  24. public JsonResult TradeProfitList(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = TradeProfitListDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> TradeProfitListDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int UserId = int.Parse(function.CheckInt(data["UserId"].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. IQueryable<ProfitRecord> query = maindb.ProfitRecord.Where(m => m.UserId == UserId).OrderByDescending(m => m.Id);
  39. if (PageNum == 1)
  40. {
  41. query = query.Take(PageSize);
  42. }
  43. else
  44. {
  45. int skipNum = PageSize * (PageNum - 1);
  46. query = query.Skip(skipNum).Take(PageSize);
  47. }
  48. foreach (var subdata in query.ToList())
  49. {
  50. Dictionary<string, object> curData = new Dictionary<string, object>();
  51. curData.Add("ProfitAmount", subdata.ProfitAmount); //交易分润
  52. curData.Add("ProfitMonth", subdata.SeoTitle.Substring(0, 4) + "年" + subdata.SeoTitle.Substring(4) + "月");
  53. curData.Add("ProfitDate", subdata.CreateDate.Value.ToString("yyyy-MM-dd"));
  54. dataList.Add(curData);
  55. }
  56. return dataList;
  57. }
  58. #endregion
  59. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  60. /// <summary>
  61. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  62. /// </summary>
  63. /// <param name="value">请求的参数(json字符串)</param>
  64. /// <param name="signField">要签名的字段</param>
  65. /// <returns></returns>
  66. private string CheckSign(string value, string[] signField)
  67. {
  68. JsonData json = JsonMapper.ToObject(value);
  69. Dictionary<string, string> dic = new Dictionary<string, string>();
  70. for (int i = 0; i < signField.Length; i++)
  71. {
  72. dic.Add(signField[i], json[signField[i]].ToString());
  73. }
  74. string sign = json["sign"].ToString(); //客户端签名字符串
  75. return new Sign().sign(dic, sign);
  76. }
  77. #endregion
  78. }
  79. }