PosFeeWarningRecordController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 = " and Status<99";
  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 == 2) dic["Status"] = "已执行";
  96. if (Status == 0) dic["Status"] = "未同步";
  97. if (Status == 99) dic["Status"] = "数据不完整";
  98. if(dic["CreateDate"].ToString() == dic["UpdateDate"].ToString())
  99. {
  100. dic["UpdateDate"] = "";
  101. }
  102. }
  103. return Json(obj);
  104. }
  105. #endregion
  106. #region 同步
  107. /// <summary>
  108. /// 同步
  109. /// </summary>
  110. /// <returns></returns>
  111. public string Sycn(string Id)
  112. {
  113. string[] idlist = Id.Split(new char[] { ',' });
  114. AddSysLog(Id, "PosFeeWarningRecord", "Sycn");
  115. foreach (string subid in idlist)
  116. {
  117. int id = int.Parse(subid);
  118. Dictionary<string, object> Fields = new Dictionary<string, object>();
  119. Fields.Add("Status", 1);
  120. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosFeeWarningRecord", Fields, id);
  121. RedisDbconn.Instance.AddList("FeeRateAlignmentQueue", Id);
  122. }
  123. return "success";
  124. }
  125. #endregion
  126. #region 导入数据
  127. public IActionResult ImportTrade(string right)
  128. {
  129. ViewBag.RightInfo = RightInfo;
  130. ViewBag.right = right;
  131. List<KqProducts> BrandList = db.KqProducts.OrderBy(m => m.Id).ToList();
  132. ViewBag.BrandList = BrandList;
  133. return View();
  134. }
  135. /// <summary>
  136. /// 导入数据
  137. /// </summary>
  138. /// <param name="ExcelData"></param>
  139. [HttpPost]
  140. public string ImportTradePost(string ExcelPath, string BrandId)
  141. {
  142. RedisDbconn.Instance.AddList("ExcelCheckFee", ExcelPath + "#cut#" + BrandId + "#cut#" + SysUserName);
  143. AddSysLog(ExcelPath, "ImportTrade", "ImportTradePost");
  144. return "success";
  145. }
  146. #endregion
  147. #region 导出Excel
  148. /// <summary>
  149. /// 导出Excel
  150. /// </summary>
  151. /// <returns></returns>
  152. public JsonResult ExportExcel(PosFeeWarningRecord data, string UserIdMakerCode, string LeaderLevelSelect, string PosFeeWarningRecordtatusSelect, string LastBuyDateData, string ExpiredDateData, string CreateDateData)
  153. {
  154. Dictionary<string, string> Fields = new Dictionary<string, string>();
  155. string condition = " and Status>-1";
  156. //创客编号
  157. if (!string.IsNullOrEmpty(UserIdMakerCode))
  158. {
  159. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  160. }
  161. //盟主等级
  162. if (!string.IsNullOrEmpty(LeaderLevelSelect))
  163. {
  164. condition += " and LeaderLevel=" + LeaderLevelSelect;
  165. }
  166. //状态
  167. if (!string.IsNullOrEmpty(PosFeeWarningRecordtatusSelect))
  168. {
  169. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  170. if (PosFeeWarningRecordtatusSelect == "0")
  171. {
  172. condition += " and ExpiredDate>'" + time + "'";
  173. }
  174. else
  175. {
  176. condition += " and ExpiredDate<='" + time + "'";
  177. }
  178. }
  179. //首次购买时间
  180. if (!string.IsNullOrEmpty(CreateDateData))
  181. {
  182. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  183. string start = datelist[0];
  184. string end = datelist[1];
  185. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  186. }
  187. //最后购买时间
  188. if (!string.IsNullOrEmpty(LastBuyDateData))
  189. {
  190. string[] datelist = LastBuyDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  191. string start = datelist[0];
  192. string end = datelist[1];
  193. condition += " and LastBuyDate>='" + start + " 00:00:00' and LastBuyDate<='" + end + " 23:59:59'";
  194. }
  195. //盟主到期时间
  196. if (!string.IsNullOrEmpty(ExpiredDateData))
  197. {
  198. string[] datelist = ExpiredDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  199. string start = datelist[0];
  200. string end = datelist[1];
  201. condition += " and ExpiredDate>='" + start + " 00:00:00' and ExpiredDate<='" + end + " 23:59:59'";
  202. }
  203. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosFeeWarningRecord", Fields, "Id desc", "0", 1, 20000, condition, "UserId,LeaderLevel,CreateDate", false);
  204. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  205. foreach (Dictionary<string, object> dic in diclist)
  206. {
  207. //创客
  208. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  209. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  210. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  211. dic["UserIdRealName"] = userid_Users.RealName;
  212. dic.Remove("UserId");
  213. //盟主等级
  214. int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
  215. if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
  216. if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
  217. if (LeaderLevel == 0) dic["LeaderLevel"] = "";
  218. }
  219. Dictionary<string, object> result = new Dictionary<string, object>();
  220. result.Add("Status", "1");
  221. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  222. result.Add("Obj", diclist);
  223. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  224. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  225. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  226. ReturnFields.Add("LeaderLevel", "盟主等级");
  227. ReturnFields.Add("CreateDate", "创建时间");
  228. result.Add("Fields", ReturnFields);
  229. AddSysLog("0", "PosFeeWarningRecord", "ExportExcel");
  230. return Json(result);
  231. }
  232. #endregion
  233. }
  234. }