ActiveRewardController.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.Models.Main;
  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) : base(accessor)
  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. value = value.Replace("null", "\"\"");
  30. JsonData data = JsonMapper.ToObject(value);
  31. List<Dictionary<string, object>> dataList = StatListDo(value);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  33. }
  34. public List<Dictionary<string, object>> StatListDo(string value)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. int UserId = int.Parse(function.CheckInt(data.getItem("UserId").ToString())); //创客
  38. string TradeMonth = data.getItem("TradeMonth").ToString();
  39. int PageSize = int.Parse(function.CheckInt(data.getItem("PageSize").ToString()));
  40. int PageNum = int.Parse(function.CheckInt(data.getItem("PageNum").ToString()));
  41. int Kind = int.Parse(function.CheckInt(data.getItem("Kind").ToString()));
  42. string Date = Kind == 1 ? "%Y%m%d" : "%Y%m";
  43. string TradeMonthCondi = "";
  44. if (Kind == 2)
  45. {
  46. string StartTradeMonth = TradeMonth + "-01 00:00:00";
  47. string EndTradeMonth = DateTime.Parse(StartTradeMonth).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
  48. TradeMonthCondi = " and CreateDate>='" + StartTradeMonth + "' and CreateDate>='" + EndTradeMonth + "'";
  49. }
  50. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  51. string PageCondition = PageSize.ToString();
  52. if (PageNum > 1)
  53. {
  54. int skipNum = PageSize * (PageNum - 1);
  55. PageCondition = skipNum + "," + PageSize;
  56. }
  57. 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);
  58. foreach (DataRow dr in dt.Rows)
  59. {
  60. string subdata = dr[0].ToString();
  61. decimal RewardAmount = decimal.Parse(dr[1].ToString());
  62. Dictionary<string, object> curData = new Dictionary<string, object>();
  63. curData.Add("RewardAmount", RewardAmount); //奖励金额
  64. if (Kind == 1)
  65. {
  66. curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月" + subdata.Substring(6, 2) + "日"); //激活时间
  67. }
  68. else
  69. {
  70. curData.Add("ActDate", subdata.Substring(0, 4) + "年" + subdata.Substring(4, 2) + "月"); //激活时间
  71. }
  72. curData.Add("ActDateValue", subdata); //激活时间值
  73. dataList.Add(curData);
  74. }
  75. return dataList;
  76. }
  77. #endregion
  78. #region 首页-客小爽产品-收益查看-达标奖励-明细
  79. // [Authorize]
  80. public JsonResult StatDetail(string value)
  81. {
  82. value = DesDecrypt(value);
  83. value = value.Replace("null", "\"\"");
  84. JsonData data = JsonMapper.ToObject(value);
  85. List<Dictionary<string, object>> dataList = StatDetailDo(value);
  86. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  87. }
  88. public List<Dictionary<string, object>> StatDetailDo(string value)
  89. {
  90. JsonData data = JsonMapper.ToObject(value);
  91. int UserId = int.Parse(function.CheckInt(data.getItem("UserId").ToString())); //创客
  92. string ActDate = data.getItem("ActDate").ToString(); //激活时间
  93. int PageSize = int.Parse(function.CheckInt(data.getItem("PageSize").ToString()));
  94. int PageNum = int.Parse(function.CheckInt(data.getItem("PageNum").ToString()));
  95. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  96. DateTime start = DateTime.Parse(ActDate + " 00:00:00");
  97. DateTime end = DateTime.Parse(ActDate + " 23:59:59");
  98. IQueryable<ActiveReward> query = maindb.ActiveReward.Where(m => m.UserId == UserId && m.CreateDate >= start && m.CreateDate <= end);
  99. if (PageNum == 1)
  100. {
  101. query = query.Take(PageSize);
  102. }
  103. else
  104. {
  105. int skipNum = PageSize * (PageNum - 1);
  106. query = query.Skip(skipNum).Take(PageSize);
  107. }
  108. foreach (var subdata in query.ToList())
  109. {
  110. Dictionary<string, object> curData = new Dictionary<string, object>();
  111. PosMerchantInfo merchant = PosMerchantInfoDbconn.Instance.Get(subdata.MerchantId) ?? new PosMerchantInfo();
  112. curData.Add("SnNo", subdata.KqSnNo);
  113. curData.Add("MerchantName", merchant.MerchantName); //商户名称
  114. curData.Add("RewardAmount", subdata.RewardAmount); //奖励金额
  115. dataList.Add(curData);
  116. }
  117. return dataList;
  118. }
  119. #endregion
  120. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  121. /// <summary>
  122. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  123. /// </summary>
  124. /// <param name="value">请求的参数(json字符串)</param>
  125. /// <param name="signField">要签名的字段</param>
  126. /// <returns></returns>
  127. private string CheckSign(string value, string[] signField)
  128. {
  129. JsonData json = JsonMapper.ToObject(value);
  130. Dictionary<string, string> dic = new Dictionary<string, string>();
  131. for (int i = 0; i < signField.Length; i++)
  132. {
  133. dic.Add(signField[i], json[signField[i]].ToString());
  134. }
  135. string sign = json["sign"].ToString(); //客户端签名字符串
  136. return new Sign().sign(dic, sign);
  137. }
  138. #endregion
  139. }
  140. }