AmountRecordOperateController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * 创客账户变动记录
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Data;
  10. using System.Threading.Tasks;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.Extensions.Logging;
  14. using Microsoft.Extensions.Options;
  15. using MySystem.OpModels;
  16. using Library;
  17. using LitJson;
  18. using MySystemLib;
  19. namespace MySystem.Areas.Admin.Controllers
  20. {
  21. [Area("Admin")]
  22. [Route("Admin/[controller]/[action]")]
  23. public class AmountRecordOperateController : BaseController
  24. {
  25. public AmountRecordOperateController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  26. {
  27. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  28. }
  29. #region 运营中心额度变动明细记录列表
  30. /// <summary>
  31. /// 根据条件查询运营中心额度变动明细记录列表
  32. /// </summary>
  33. /// <returns></returns>
  34. public IActionResult Index(AmountRecord data, string right, int UserId = 0)
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询运营中心额度变动明细记录列表
  42. /// <summary>
  43. /// 运营中心额度变动明细记录列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(AmountRecord data, string MakerCode, string OpCode, string CreateDateData, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. string condition = " and Status>-1";
  50. //创客编号
  51. if (!string.IsNullOrEmpty(MakerCode))
  52. {
  53. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Models.Users();
  54. condition += " and UserId=" + user.Id;
  55. }
  56. //运营中心编号
  57. if (!string.IsNullOrEmpty(OpCode))
  58. {
  59. condition += " and UserId in (select UserId from SysAdmin where OpCode='" + OpCode + "')";
  60. }
  61. if (!string.IsNullOrEmpty(CreateDateData))
  62. {
  63. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  64. // string start = datelist[0];
  65. // string end = datelist[1];
  66. // condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  67. var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  68. var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  69. var check = opdb.AmountRecord.Any(m => m.CreateDate >= start);
  70. var checks = opdb.AmountRecord.Any(m => m.CreateDate <= end);
  71. if (check)
  72. {
  73. var sId = opdb.AmountRecord.Where(m => m.CreateDate >= start).Min(m => m.Id);
  74. condition += " and Id >=" + sId;
  75. }
  76. if (checks)
  77. {
  78. var eId = opdb.AmountRecord.Where(m => m.CreateDate <= end).Max(m => m.Id);
  79. condition += " and Id <=" + eId;
  80. }
  81. }
  82. else
  83. {
  84. var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  85. var check = opdb.AmountRecord.Any(m => m.CreateDate >= start);
  86. if (check)
  87. {
  88. var minId = opdb.AmountRecord.Where(m => m.CreateDate >= start).Min(m => m.Id);
  89. var Info = function.ReadInstance("/WritePage/AmountRecordOperate/AmountRecordOperate.txt");
  90. if (string.IsNullOrEmpty(Info.ToString()))
  91. {
  92. function.WritePage("/WritePage/AmountRecordOperate/", "AmountRecordOperate.txt", minId.ToString());
  93. condition += " and Id >=" + minId;
  94. }
  95. else if (minId != int.Parse(Info))
  96. {
  97. function.WritePage("/WritePage/AmountRecordOperate/", "AmountRecordOperate.txt", minId.ToString());
  98. condition += " and Id >=" + minId;
  99. }
  100. else
  101. {
  102. condition += " and Id >=" + Convert.ToInt32(Info);
  103. }
  104. }
  105. else
  106. {
  107. condition += " and Id =0";
  108. }
  109. }
  110. Dictionary<string, object> obj = new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).IndexData("AmountRecord", Fields, "Id desc", "0", page, limit, condition);
  111. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  112. foreach (Dictionary<string, object> dic in diclist)
  113. {
  114. int UserId = int.Parse(dic["UserId"].ToString());
  115. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.UserId == UserId) ?? new SysAdmin();
  116. dic["OpCode"] = sysAdmin.OpCode;
  117. dic["MakerCode"] = sysAdmin.MakerCode;
  118. dic["MakerName"] = sysAdmin.MakerName;
  119. int OperateType = int.Parse(dic["OperateType"].ToString());
  120. dic["OperateTypeName"] = "";
  121. if (OperateType == 1) dic["OperateTypeName"] = "收入";
  122. if (OperateType == 2) dic["OperateTypeName"] = "支出";
  123. }
  124. return Json(obj);
  125. }
  126. #endregion
  127. }
  128. }