ActiveRewardController.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using Microsoft.AspNetCore.Authorization;
  10. using System.Web;
  11. using MySystem.MainModels;
  12. using LitJson;
  13. using Library;
  14. namespace MySystem.Areas.Api.Controllers.v1.pos
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/[controller]/[action]")]
  18. public class ActiveRewardController : BaseController
  19. {
  20. public ActiveRewardController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  23. }
  24. #region 首页-客小爽产品-收益查看-达标奖励
  25. [Authorize]
  26. public JsonResult StatList(string value)
  27. {
  28. value = DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. List<Dictionary<string, object>> dataList = StatListDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  32. }
  33. public List<Dictionary<string, object>> StatListDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  37. string TradeMonth = data["TradeMonth"].ToString();
  38. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  39. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  40. int Kind = int.Parse(function.CheckInt(data["Kind"].ToString()));
  41. string Date = Kind == 1 ? "%Y%m%d" : "%Y%m";
  42. string TradeMonthCondi = "";
  43. if(Kind == 2)
  44. {
  45. string StartTradeMonth = TradeMonth + "-01 00:00:00";
  46. string EndTradeMonth = DateTime.Parse(StartTradeMonth).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
  47. TradeMonthCondi = " and CreateDate>='" + StartTradeMonth + "' and CreateDate>='" + EndTradeMonth + "'";
  48. }
  49. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  50. string PageCondition = PageSize.ToString();
  51. if (PageNum > 1)
  52. {
  53. int skipNum = PageSize * (PageNum - 1);
  54. PageCondition = skipNum + "," + PageSize;
  55. }
  56. DataTable dt = CustomerSqlConn.dtable("select DATE_FORMAT(CreateDate,'" + Date + "'),sum(RewardAmount) from ActiveReward where UserId=" + UserId + TradeMonthCondi + " group by DATE_FORMAT(CreateDate,'" + Date + "') order by DATE_FORMAT(CreateDate,'" + Date + "') desc limit " + PageCondition, AppConfig.Base.SqlConnStr);
  57. foreach (DataRow dr in dt.Rows)
  58. {
  59. string subdata = dr[0].ToString();
  60. decimal RewardAmount = decimal.Parse(dr[1].ToString());
  61. Dictionary<string, object> curData = new Dictionary<string, object>();
  62. curData.Add("RewardAmount", RewardAmount); //奖励金额
  63. if (Kind == 1)
  64. {
  65. curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月" + subdata.Substring(6, 2) + "日"); //激活时间
  66. }
  67. else
  68. {
  69. curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月"); //激活时间
  70. }
  71. curData.Add("ActDateValue", subdata); //激活时间值
  72. dataList.Add(curData);
  73. }
  74. return dataList;
  75. }
  76. #endregion
  77. #region 首页-客小爽产品-收益查看-达标奖励-明细
  78. [Authorize]
  79. public JsonResult StatDetail(string value)
  80. {
  81. value = DesDecrypt(value);
  82. JsonData data = JsonMapper.ToObject(value);
  83. List<Dictionary<string, object>> dataList = StatDetailDo(value);
  84. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  85. }
  86. public List<Dictionary<string, object>> StatDetailDo(string value)
  87. {
  88. JsonData data = JsonMapper.ToObject(value);
  89. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  90. string ActDate = data["ActDate"].ToString(); //激活时间
  91. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  92. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  93. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  94. DateTime start = DateTime.Parse(ActDate + " 00:00:00");
  95. DateTime end = DateTime.Parse(ActDate + " 23:59:59");
  96. IQueryable<ActiveReward> query = maindb.ActiveReward.Where(m => m.UserId == UserId && m.CreateDate >= start && m.CreateDate <= end);
  97. if (PageNum == 1)
  98. {
  99. query = query.Take(PageSize);
  100. }
  101. else
  102. {
  103. int skipNum = PageSize * (PageNum - 1);
  104. query = query.Skip(skipNum).Take(PageSize);
  105. }
  106. foreach (var subdata in query.ToList())
  107. {
  108. Dictionary<string, object> curData = new Dictionary<string, object>();
  109. PosMerchantInfo merchant = PosMerchantInfoDbconn.Instance.Get(subdata.MerchantId) ?? new PosMerchantInfo();
  110. curData.Add("SnNo", subdata.KqSnNo);
  111. curData.Add("MerchantName", merchant.MerchantName); //商户名称
  112. curData.Add("RewardAmount", subdata.RewardAmount); //奖励金额
  113. dataList.Add(curData);
  114. }
  115. return dataList;
  116. }
  117. #endregion
  118. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  119. /// <summary>
  120. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  121. /// </summary>
  122. /// <param name="value">请求的参数(json字符串)</param>
  123. /// <param name="signField">要签名的字段</param>
  124. /// <returns></returns>
  125. private string CheckSign(string value, string[] signField)
  126. {
  127. JsonData json = JsonMapper.ToObject(value);
  128. Dictionary<string, string> dic = new Dictionary<string, string>();
  129. for (int i = 0; i < signField.Length; i++)
  130. {
  131. dic.Add(signField[i], json[signField[i]].ToString());
  132. }
  133. string sign = json["sign"].ToString(); //客户端签名字符串
  134. return new Sign().sign(dic, sign);
  135. }
  136. #endregion
  137. }
  138. }