AmountRecordOperateController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. // dic["SourceInfo"] = "";
  120. // if (int.Parse(dic["QueryCount"].ToString()) > 0)
  121. // {
  122. // var Id = int.Parse(dic["QueryCount"].ToString());
  123. // var orderInfo = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Models.Orders();
  124. // var userInfo = db.Users.FirstOrDefault(m => m.Id == orderInfo.UserId) ?? new Models.Users();
  125. // dic["SourceInfo"] = userInfo.MakerCode + "<br />" + userInfo.RealName;
  126. // }
  127. // int OperateType = int.Parse(dic["OperateType"].ToString());
  128. // dic["OperateTypeName"] = "";
  129. // if (OperateType == 1) dic["OperateTypeName"] = "收入";
  130. // if (OperateType == 2) dic["OperateTypeName"] = "支出";
  131. // }
  132. // return Json(obj);
  133. // }
  134. // #endregion
  135. #region 运营中心额度变动明细记录列表v2
  136. /// <summary>
  137. /// 根据条件查询运营中心额度变动明细记录列表v2
  138. /// </summary>
  139. /// <returns></returns>
  140. public IActionResult Index(AmountRecordNew data, string right, int UserId = 0)
  141. {
  142. ViewBag.RightInfo = RightInfo;
  143. ViewBag.right = right;
  144. return View();
  145. }
  146. #endregion
  147. #region 根据条件查询运营中心额度变动明细记录列表v2
  148. /// <summary>
  149. /// 运营中心额度变动明细记录列表v2
  150. /// </summary>
  151. /// <returns></returns>
  152. public JsonResult IndexData(AmountRecordNew data, string MakerCode, string OpCode, string CreateDateData, int page = 1, int limit = 30)
  153. {
  154. Dictionary<string, string> Fields = new Dictionary<string, string>();
  155. string condition = " and Status>-1";
  156. //创客编号
  157. if (!string.IsNullOrEmpty(MakerCode))
  158. {
  159. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Models.Users();
  160. condition += " and UserId=" + user.Id;
  161. }
  162. //运营中心编号
  163. if (!string.IsNullOrEmpty(OpCode))
  164. {
  165. condition += " and UserId in (select UserId from SysAdmin where OpCode='" + OpCode + "')";
  166. }
  167. if (!string.IsNullOrEmpty(CreateDateData))
  168. {
  169. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  170. // string start = datelist[0];
  171. // string end = datelist[1];
  172. // condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  173. var start = Convert.ToDateTime(Convert.ToDateTime(datelist[0]).ToString("yyyy-MM-dd"));
  174. var end = Convert.ToDateTime(Convert.ToDateTime(datelist[1]).ToString("yyyy-MM-dd") + " 23:59:59");
  175. var check = opdb.AmountRecordNew.Any(m => m.CreateDate >= start);
  176. var checks = opdb.AmountRecordNew.Any(m => m.CreateDate <= end);
  177. if (check)
  178. {
  179. var sId = opdb.AmountRecordNew.Where(m => m.CreateDate >= start).Min(m => m.Id);
  180. condition += " and Id >=" + sId;
  181. }
  182. if (checks)
  183. {
  184. var eId = opdb.AmountRecordNew.Where(m => m.CreateDate <= end).Max(m => m.Id);
  185. condition += " and Id <=" + eId;
  186. }
  187. }
  188. else
  189. {
  190. var start = Convert.ToDateTime(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01");
  191. var check = opdb.AmountRecordNew.Any(m => m.CreateDate >= start);
  192. if (check)
  193. {
  194. var minId = opdb.AmountRecordNew.Where(m => m.CreateDate >= start).Min(m => m.Id);
  195. var Info = function.ReadInstance("/WritePage/AmountRecordOperateNew/AmountRecordOperateNew.txt");
  196. if (string.IsNullOrEmpty(Info.ToString()))
  197. {
  198. function.WritePage("/WritePage/AmountRecordOperateNew/", "AmountRecordOperateNew.txt", minId.ToString());
  199. condition += " and Id >=" + minId;
  200. }
  201. else if (minId != int.Parse(Info))
  202. {
  203. function.WritePage("/WritePage/AmountRecordOperateNew/", "AmountRecordOperateNew.txt", minId.ToString());
  204. condition += " and Id >=" + minId;
  205. }
  206. else
  207. {
  208. condition += " and Id >=" + Convert.ToInt32(Info);
  209. }
  210. }
  211. else
  212. {
  213. condition += " and Id =0";
  214. }
  215. }
  216. Dictionary<string, object> obj = new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).IndexData("AmountRecordNew", Fields, "Id desc", "0", page, limit, condition);
  217. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  218. foreach (Dictionary<string, object> dic in diclist)
  219. {
  220. int UserId = int.Parse(dic["UserId"].ToString());
  221. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.UserId == UserId) ?? new SysAdmin();
  222. dic["OpCode"] = sysAdmin.OpCode;
  223. dic["MakerCode"] = sysAdmin.MakerCode;
  224. dic["MakerName"] = sysAdmin.MakerName;
  225. var DataType = int.Parse(dic["DataType"].ToString());//来源类型,区分表(1订单,2机具,3申请记录,4购买运营中心,5预扣款 6兑换大盟主)
  226. var Id = int.Parse(dic["DataId"].ToString());//来源Id,表的主键Id
  227. var SourceInfo = "";
  228. if (DataType > 0 && Id > 0)
  229. {
  230. var SourceUserId = 0;
  231. if (DataType == 1)
  232. {
  233. var orderInfo = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Models.Orders();
  234. SourceUserId = orderInfo.UserId;
  235. }
  236. if (DataType == 2)
  237. {
  238. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new Models.PosMachinesTwo();
  239. SourceUserId = pos.BuyUserId;
  240. }
  241. if (DataType == 3)
  242. {
  243. var storeMachineApply = db.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new Models.StoreMachineApply();
  244. SourceUserId = storeMachineApply.UserId;
  245. }
  246. if (DataType == 4)
  247. {
  248. var sysAdminInfo = opdb.SysAdmin.FirstOrDefault(m => m.Id == Id) ?? new SysAdmin();
  249. SourceUserId = sysAdminInfo.UserId;
  250. }
  251. if (DataType == 5)
  252. {
  253. var toChargeBackRecord = db.ToChargeBackRecord.FirstOrDefault(m => m.Id == Id) ?? new Models.ToChargeBackRecord();
  254. SourceUserId = toChargeBackRecord.UserId;
  255. }
  256. if (DataType == 6)
  257. {
  258. var userExchangeLeaderRecord = db.UserExchangeLeaderRecord.FirstOrDefault(m => m.Id == Id) ?? new Models.UserExchangeLeaderRecord();
  259. SourceUserId = userExchangeLeaderRecord.UserId;
  260. }
  261. var userInfo = db.Users.FirstOrDefault(m => m.Id == SourceUserId) ?? new Models.Users();
  262. SourceInfo = userInfo.MakerCode + "_" + userInfo.RealName;
  263. }
  264. dic["SourceInfo"] = SourceInfo;
  265. int OperateType = int.Parse(dic["OperateType"].ToString());
  266. dic["OperateTypeName"] = "";
  267. if (OperateType == 1) dic["OperateTypeName"] = "收入";
  268. if (OperateType == 2) dic["OperateTypeName"] = "支出";
  269. }
  270. return Json(obj);
  271. }
  272. #endregion
  273. }
  274. }