UserAccountRecordController.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 UserAccountRecordController : BaseController
  18. {
  19. public UserAccountRecordController(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. Dictionary<string, object> Other = new Dictionary<string, object>();
  29. List<Dictionary<string, object>> dataList = ListDo(value, out Other);
  30. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  31. }
  32. public List<Dictionary<string, object>> ListDo(string value, out Dictionary<string, object> Other)
  33. {
  34. JsonData data = JsonMapper.ToObject(value);
  35. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  36. string TradeMonth = data["TradeMonth"].ToString(); //月份
  37. if (TradeMonth.Contains("-"))
  38. {
  39. string day = TradeMonth.Substring(TradeMonth.IndexOf("-") + 1);
  40. if (day.Length == 1)
  41. {
  42. day = "0" + day;
  43. }
  44. TradeMonth = TradeMonth.Substring(0, TradeMonth.IndexOf("-")) + day;
  45. }
  46. string Kind = data["Kind"].ToString(); //类型
  47. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  48. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  49. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  50. DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
  51. DateTime end = start.AddMonths(1);
  52. IQueryable<UserAccountRecord> query = maindb.UserAccountRecord;
  53. List<int> ChangeTypes = new List<int>();
  54. if (Kind == "1")
  55. {
  56. ChangeTypes = PublicFunction.IncomeTypes();
  57. }
  58. else
  59. {
  60. ChangeTypes = PublicFunction.ExpendTypes();
  61. }
  62. query = query.Where(m => m.UserId == UserId && m.CreateDate >= start && m.CreateDate < end && ChangeTypes.Contains(m.ChangeType));
  63. query = query.OrderByDescending(m => m.Id);
  64. if (PageNum == 1)
  65. {
  66. query = query.Take(PageSize);
  67. }
  68. else
  69. {
  70. int skipNum = PageSize * (PageNum - 1);
  71. query = query.Skip(skipNum).Take(PageSize);
  72. }
  73. foreach (var subdata in query.ToList())
  74. {
  75. Dictionary<string, object> curData = new Dictionary<string, object>();
  76. curData.Add("ChangeType", subdata.ChangeType);
  77. curData.Add("ChangeAmount", subdata.ChangeAmount); //变更金额
  78. if (subdata.ProductType == 0)
  79. {
  80. string Note = RelationClass.GetChangeTypeInfo(subdata.ChangeType);
  81. if (subdata.ChangeType == 20 || subdata.ChangeType == 31 || subdata.ChangeType == 63 || subdata.ChangeType == 64 || subdata.ChangeType == 65 || subdata.ChangeType == 66 || subdata.ChangeType == 114 || subdata.ChangeType == 115)
  82. {
  83. Note += "\n" + subdata.Remark;
  84. }
  85. curData.Add("Remark", Note); //账户变动明细备注信息
  86. }
  87. else if (subdata.ProductType == 101)
  88. {
  89. string Note = "助利宝(交易分润)\n" + subdata.Remark;
  90. curData.Add("Remark", Note); //账户变动明细备注信息
  91. }
  92. else
  93. {
  94. string Note = RelationClass.GetKqProductBrandInfo(subdata.ProductType) + "(" + RelationClass.GetChangeTypeInfo(subdata.ChangeType) + ")";
  95. if (subdata.ChangeType == 1)
  96. {
  97. Note += "\n" + subdata.Remark;
  98. }
  99. curData.Add("Remark", Note); //账户变动明细备注信息
  100. }
  101. curData.Add("Id", subdata.Id); //Id
  102. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  103. dataList.Add(curData);
  104. }
  105. Other = new Dictionary<string, object>();
  106. Other.Add("Income", UserAccountDbconn.Instance.GetIncome(UserId, TradeMonth));
  107. Other.Add("Expend", UserAccountDbconn.Instance.GetExpend(UserId, TradeMonth));
  108. return dataList;
  109. }
  110. #endregion
  111. #region 收支明细盟主贮蓄金记录
  112. [Authorize]
  113. public JsonResult Lists(string value)
  114. {
  115. value = DesDecrypt(value);
  116. JsonData data = JsonMapper.ToObject(value);
  117. List<Dictionary<string, object>> dataList = ListsDo(value);
  118. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  119. }
  120. public List<Dictionary<string, object>> ListsDo(string value)
  121. {
  122. JsonData data = JsonMapper.ToObject(value);
  123. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  124. string Kind = data["Kind"].ToString(); //类型
  125. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  126. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  127. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  128. IQueryable<UserAccountRecord> query = maindb.UserAccountRecord;
  129. List<int> ChangeTypes = new List<int>();
  130. if (Kind == "1")
  131. {
  132. ChangeTypes = PublicFunction.IncomeTypes();
  133. }
  134. else
  135. {
  136. ChangeTypes = PublicFunction.ExpendTypes();
  137. }
  138. query = query.Where(m => m.UserId == UserId && ChangeTypes.Contains(m.ChangeType)).OrderByDescending(m => m.CreateDate);
  139. query = query.OrderByDescending(m => m.Id);
  140. if (PageNum == 1)
  141. {
  142. query = query.Take(PageSize);
  143. }
  144. else
  145. {
  146. int skipNum = PageSize * (PageNum - 1);
  147. query = query.Skip(skipNum).Take(PageSize);
  148. }
  149. foreach (var subdata in query.ToList())
  150. {
  151. Dictionary<string, object> curData = new Dictionary<string, object>();
  152. curData.Add("ChangeType", subdata.ChangeType);
  153. curData.Add("ChangeAmount", subdata.ChangeAmount); //变更金额
  154. if (subdata.ProductType == 0)
  155. {
  156. string Note = RelationClass.GetChangeTypeInfo(subdata.ChangeType);
  157. if (subdata.ChangeType == 20 || subdata.ChangeType == 31 || subdata.ChangeType == 63 || subdata.ChangeType == 64 || subdata.ChangeType == 114 || subdata.ChangeType == 115)
  158. {
  159. Note += "\n" + subdata.Remark;
  160. }
  161. curData.Add("Remark", Note); //账户变动明细备注信息
  162. }
  163. else
  164. {
  165. string Note = RelationClass.GetKqProductBrandInfo(subdata.ProductType) + "(" + RelationClass.GetChangeTypeInfo(subdata.ChangeType) + ")";
  166. if (subdata.ChangeType == 1)
  167. {
  168. Note += "\n" + subdata.Remark;
  169. }
  170. curData.Add("Remark", Note); //账户变动明细备注信息
  171. }
  172. curData.Add("Id", subdata.Id); //Id
  173. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  174. dataList.Add(curData);
  175. }
  176. return dataList;
  177. }
  178. #endregion
  179. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  180. /// <summary>
  181. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  182. /// </summary>
  183. /// <param name="value">请求的参数(json字符串)</param>
  184. /// <param name="signField">要签名的字段</param>
  185. /// <returns></returns>
  186. private string CheckSign(string value, string[] signField)
  187. {
  188. JsonData json = JsonMapper.ToObject(value);
  189. Dictionary<string, string> dic = new Dictionary<string, string>();
  190. for (int i = 0; i < signField.Length; i++)
  191. {
  192. dic.Add(signField[i], json[signField[i]].ToString());
  193. }
  194. string sign = json["sign"].ToString(); //客户端签名字符串
  195. return new Sign().sign(dic, sign);
  196. }
  197. #endregion
  198. }
  199. }