PosCouponExchangeRecordController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class PosCouponExchangeRecordController : BaseController
  23. {
  24. public PosCouponExchangeRecordController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 电签券兑换记录列表
  29. /// <summary>
  30. /// 根据条件查询电签券兑换记录列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(PosCouponExchangeRecord data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询电签券兑换记录列表
  41. /// <summary>
  42. /// 电签券兑换记录列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(PosCouponExchangeRecord data, string UserIdMakerCode, string CreateDateData, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. string condition = "";
  49. //来源创客编号
  50. if (!string.IsNullOrEmpty(UserIdMakerCode))
  51. {
  52. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  53. }
  54. if (!string.IsNullOrEmpty(CreateDateData))
  55. {
  56. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  57. string start = datelist[0];
  58. string end = datelist[1];
  59. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  60. }
  61. //来源券码
  62. if (!string.IsNullOrEmpty(data.SourceCoupons))
  63. {
  64. condition += " and SourceCoupons like '%" + data.SourceCoupons + "%'";
  65. }
  66. //兑换券码
  67. if (!string.IsNullOrEmpty(data.ToCoupons))
  68. {
  69. condition += " and ToCoupons like '%" + data.ToCoupons + "%'";
  70. }
  71. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosCouponExchangeRecord", Fields, "Id desc", "0", page, limit, condition);
  72. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  73. foreach (Dictionary<string, object> dic in diclist)
  74. {
  75. //来源创客
  76. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  77. Users Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  78. dic["UserIdMakerCode"] = Users.MakerCode;
  79. dic["UserIdRealName"] = Users.RealName;
  80. dic.Remove("UserId");
  81. }
  82. return Json(obj);
  83. }
  84. #endregion
  85. #region 导出Excel
  86. /// <summary>
  87. /// 导出Excel
  88. /// </summary>
  89. /// <returns></returns>
  90. public JsonResult ExportExcel(PosCouponExchangeRecord data, string UserIdMakerCode, string CreateDateData)
  91. {
  92. Dictionary<string, string> Fields = new Dictionary<string, string>();
  93. string condition = "";
  94. //来源创客编号
  95. if (!string.IsNullOrEmpty(UserIdMakerCode))
  96. {
  97. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  98. }
  99. if (!string.IsNullOrEmpty(CreateDateData))
  100. {
  101. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  102. string start = datelist[0];
  103. string end = datelist[1];
  104. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  105. }
  106. //来源券码
  107. if (!string.IsNullOrEmpty(data.SourceCoupons))
  108. {
  109. condition += " and SourceCoupons like '%" + data.SourceCoupons + "%'";
  110. }
  111. //兑换券码
  112. if (!string.IsNullOrEmpty(data.ToCoupons))
  113. {
  114. condition += " and ToCoupons like '%" + data.ToCoupons + "%'";
  115. }
  116. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosCouponExchangeRecord", Fields, "Id desc", "0", 1, 20000, condition, "FromUserId,ToUserId,OrderNo,BeforeStock,BeforeTotal,BeforeOut,AfterStock,AfterTotal,AfterOut,ChangeCount,ChangeKind", false);
  117. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  118. foreach (Dictionary<string, object> dic in diclist)
  119. {
  120. //来源创客
  121. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  122. Users Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  123. dic["UserIdMakerCode"] = Users.MakerCode;
  124. dic["UserIdRealName"] = Users.RealName;
  125. dic.Remove("UserId");
  126. }
  127. Dictionary<string, object> result = new Dictionary<string, object>();
  128. result.Add("Status", "1");
  129. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  130. result.Add("Obj", diclist);
  131. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  132. ReturnFields.Add("UserIdMakerCode", "来源创客编号");
  133. ReturnFields.Add("UserIdRealName", "来源创客真实姓名");
  134. ReturnFields.Add("SourceCount", "来源券数量");
  135. ReturnFields.Add("ToCount", "兑换券数量");
  136. ReturnFields.Add("SourceCoupons", "来源券");
  137. ReturnFields.Add("ToCoupons", "兑换券");
  138. result.Add("Fields", ReturnFields);
  139. AddSysLog("0", "PosCouponExchangeRecord", "ExportExcel");
  140. return Json(result);
  141. }
  142. #endregion
  143. }
  144. }