AmountRecordOperateController.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. condition += " and UserId in (select UserId from SysAdmin where MakerCode='" + MakerCode + "')";
  54. }
  55. //运营中心编号
  56. if (!string.IsNullOrEmpty(OpCode))
  57. {
  58. condition += " and UserId in (select UserId from SysAdmin where OpCode='" + OpCode + "')";
  59. }
  60. if (!string.IsNullOrEmpty(CreateDateData))
  61. {
  62. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  63. // string start = datelist[0];
  64. // string end = datelist[1];
  65. // condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  66. var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  67. var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  68. var check = opdb.AmountRecord.Any(m => m.CreateDate >= start);
  69. var checks = opdb.AmountRecord.Any(m => m.CreateDate <= end);
  70. if (check)
  71. {
  72. var sId = opdb.AmountRecord.Where(m => m.CreateDate >= start).Min(m => m.Id);
  73. condition += " and Id >=" + sId;
  74. }
  75. if (checks)
  76. {
  77. var eId = opdb.AmountRecord.Where(m => m.CreateDate <= end).Max(m => m.Id);
  78. condition += " and Id <=" + eId;
  79. }
  80. }
  81. else
  82. {
  83. var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  84. var check = opdb.AmountRecord.Any(m => m.CreateDate >= start);
  85. if (check)
  86. {
  87. var minId = opdb.AmountRecord.Where(m => m.CreateDate >= start).Min(m => m.Id);
  88. var Info = function.ReadInstance("/WritePage/AmountRecordOperate/AmountRecordOperate.txt");
  89. if (string.IsNullOrEmpty(Info.ToString()))
  90. {
  91. function.WritePage("/WritePage/AmountRecordOperate/", "AmountRecordOperate.txt", minId.ToString());
  92. condition += " and Id >=" + minId;
  93. }
  94. else
  95. {
  96. condition += " and Id >=" + Convert.ToInt32(Info);
  97. }
  98. }
  99. else
  100. {
  101. condition += " and Id =0";
  102. }
  103. }
  104. Dictionary<string, object> obj = new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).IndexData("AmountRecord", Fields, "Id desc", "0", page, limit, condition);
  105. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  106. foreach (Dictionary<string, object> dic in diclist)
  107. {
  108. int UserId = int.Parse(dic["UserId"].ToString());
  109. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.UserId == UserId) ?? new SysAdmin();
  110. dic["OpCode"] = sysAdmin.OpCode;
  111. dic["MakerCode"] = sysAdmin.MakerCode;
  112. dic["MakerName"] = sysAdmin.MakerName;
  113. int OperateType = int.Parse(dic["OperateType"].ToString());
  114. dic["OperateTypeName"] = "";
  115. if (OperateType == 1) dic["OperateTypeName"] = "收入";
  116. if (OperateType == 2) dic["OperateTypeName"] = "支出";
  117. }
  118. return Json(obj);
  119. }
  120. #endregion
  121. }
  122. }