PosFeeWarningRecordController.cs 11 KB

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