PosFeeWarningRecordController.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 PosFeeWarningRecordController : BaseController
  23. {
  24. public PosFeeWarningRecordController(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(PosFeeWarningRecord 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(PosFeeWarningRecord data, string DoStatus, string CreateDateData, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. string condition = "";
  49. if (!string.IsNullOrEmpty(data.PosSn))
  50. {
  51. condition += " and PosSn like '%" + data.PosSn + "%'";
  52. }
  53. //状态
  54. if (!string.IsNullOrEmpty(DoStatus))
  55. {
  56. condition += " and Status=" + DoStatus;
  57. }
  58. //创建时间
  59. if (!string.IsNullOrEmpty(CreateDateData))
  60. {
  61. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  62. string start = datelist[0];
  63. string end = datelist[1];
  64. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  65. }
  66. List<KqProducts> BrandList = db.KqProducts.ToList();
  67. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosFeeWarningRecord", Fields, "Id desc", "0", page, limit, condition);
  68. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  69. foreach (Dictionary<string, object> dic in diclist)
  70. {
  71. int BrandId = int.Parse(dic["BrandId"].ToString());
  72. KqProducts Brand = BrandList.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  73. dic["BrandName"] = Brand.Name;
  74. //状态
  75. int Status = int.Parse(dic["Status"].ToString());
  76. if (Status == 1) dic["Status"] = "已同步";
  77. if (Status == 0) dic["Status"] = "未同步";
  78. }
  79. return Json(obj);
  80. }
  81. #endregion
  82. #region 同步
  83. /// <summary>
  84. /// 同步
  85. /// </summary>
  86. /// <returns></returns>
  87. public string Sycn(string Id)
  88. {
  89. string[] idlist = Id.Split(new char[] { ',' });
  90. AddSysLog(Id, "PosFeeWarningRecord", "Sycn");
  91. foreach (string subid in idlist)
  92. {
  93. int id = int.Parse(subid);
  94. Dictionary<string, object> Fields = new Dictionary<string, object>();
  95. Fields.Add("Status", 1);
  96. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosFeeWarningRecord", Fields, id);
  97. RedisDbconn.Instance.AddList("FeeRateAlignmentQueue", Id);
  98. }
  99. return "success";
  100. }
  101. #endregion
  102. #region 导入数据
  103. public IActionResult ImportTrade(string right)
  104. {
  105. ViewBag.RightInfo = RightInfo;
  106. ViewBag.right = right;
  107. List<KqProducts> BrandList = db.KqProducts.OrderBy(m => m.Id).ToList();
  108. ViewBag.BrandList = BrandList;
  109. return View();
  110. }
  111. /// <summary>
  112. /// 导入数据
  113. /// </summary>
  114. /// <param name="ExcelData"></param>
  115. [HttpPost]
  116. public string ImportTradePost(string ExcelPath, string BrandId)
  117. {
  118. RedisDbconn.Instance.AddList("ExcelCheckFee", ExcelPath + "#cut#" + BrandId + "#cut#" + SysUserName);
  119. AddSysLog(ExcelPath, "ImportTrade", "ImportTradePost");
  120. return "success";
  121. }
  122. #endregion
  123. #region 导出Excel
  124. /// <summary>
  125. /// 导出Excel
  126. /// </summary>
  127. /// <returns></returns>
  128. public JsonResult ExportExcel(PosFeeWarningRecord data, string UserIdMakerCode, string LeaderLevelSelect, string PosFeeWarningRecordtatusSelect, string LastBuyDateData, string ExpiredDateData, string CreateDateData)
  129. {
  130. Dictionary<string, string> Fields = new Dictionary<string, string>();
  131. string condition = " and Status>-1";
  132. //创客编号
  133. if (!string.IsNullOrEmpty(UserIdMakerCode))
  134. {
  135. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  136. }
  137. //盟主等级
  138. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  139. {
  140. condition += " and LeaderLevel=" + LeaderLevelSelect;
  141. }
  142. //状态
  143. if (!string.IsNullOrEmpty(PosFeeWarningRecordtatusSelect))
  144. {
  145. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  146. if (PosFeeWarningRecordtatusSelect == "0")
  147. {
  148. condition += " and ExpiredDate>'" + time + "'";
  149. }
  150. else
  151. {
  152. condition += " and ExpiredDate<='" + time + "'";
  153. }
  154. }
  155. //首次购买时间
  156. if (!string.IsNullOrEmpty(CreateDateData))
  157. {
  158. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  159. string start = datelist[0];
  160. string end = datelist[1];
  161. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  162. }
  163. //最后购买时间
  164. if (!string.IsNullOrEmpty(LastBuyDateData))
  165. {
  166. string[] datelist = LastBuyDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  167. string start = datelist[0];
  168. string end = datelist[1];
  169. condition += " and LastBuyDate>='" + start + " 00:00:00' and LastBuyDate<='" + end + " 23:59:59'";
  170. }
  171. //盟主到期时间
  172. if (!string.IsNullOrEmpty(ExpiredDateData))
  173. {
  174. string[] datelist = ExpiredDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  175. string start = datelist[0];
  176. string end = datelist[1];
  177. condition += " and ExpiredDate>='" + start + " 00:00:00' and ExpiredDate<='" + end + " 23:59:59'";
  178. }
  179. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosFeeWarningRecord", Fields, "Id desc", "0", 1, 20000, condition, "UserId,LeaderLevel,CreateDate", false);
  180. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  181. foreach (Dictionary<string, object> dic in diclist)
  182. {
  183. //创客
  184. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  185. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  186. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  187. dic["UserIdRealName"] = userid_Users.RealName;
  188. dic.Remove("UserId");
  189. //盟主等级
  190. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  191. if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
  192. if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
  193. if (LeaderLevel == 0) dic["LeaderLevel"] = "";
  194. }
  195. Dictionary<string, object> result = new Dictionary<string, object>();
  196. result.Add("Status", "1");
  197. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  198. result.Add("Obj", diclist);
  199. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  200. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  201. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  202. ReturnFields.Add("LeaderLevel", "盟主等级");
  203. ReturnFields.Add("CreateDate", "创建时间");
  204. result.Add("Fields", ReturnFields);
  205. AddSysLog("0", "PosFeeWarningRecord", "ExportExcel");
  206. return Json(result);
  207. }
  208. #endregion
  209. }
  210. }