PosFeeWarningRecordController.cs 11 KB

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