PosMachinesFeeChangeRecordController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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 PosMachinesFeeChangeRecordController : BaseController
  23. {
  24. public PosMachinesFeeChangeRecordController(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(PosMachinesFeeChangeRecord 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(PosMachinesFeeChangeRecord data, string UserIdMakerCode, string StatusSelect, string UserIdRealName, string PosUserIdMakerCode, string PosUserIdRealName, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("PosSn", "1"); //机具SN
  50. Fields.Add("MerNo", "1"); //商户号
  51. Fields.Add("Sort", "0"); //品牌
  52. string condition = " and Status>=-1";
  53. //创客创客编号
  54. if (!string.IsNullOrEmpty(UserIdMakerCode))
  55. {
  56. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  57. }
  58. //创客真实姓名
  59. if (!string.IsNullOrEmpty(UserIdRealName))
  60. {
  61. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  62. }
  63. //机具所属人创客编号
  64. if (!string.IsNullOrEmpty(PosUserIdMakerCode))
  65. {
  66. condition += " and PosUserId in (select PosUserId from UsersForMakerCode where MakerCode='" + PosUserIdMakerCode + "')";
  67. }
  68. //机具所属人真实姓名
  69. if (!string.IsNullOrEmpty(PosUserIdRealName))
  70. {
  71. condition += " and PosUserId in (select PosUserId from UsersForRealName where RealName='" + PosUserIdRealName + "')";
  72. }
  73. //品牌
  74. if (data.Sort == 0)
  75. {
  76. condition += " and Sort = 1";
  77. }
  78. if (data.Sort != 0)
  79. {
  80. condition += " and Sort = " + data.Sort;
  81. }
  82. if (data.Status > 0)
  83. {
  84. if(data.Status == 2) data.Status = 0;
  85. if(data.Status == 3) data.Status = -1;
  86. condition += " and Status = " + data.Status;
  87. }
  88. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesFeeChangeRecord", Fields, "Id desc", "0", page, limit, condition);
  89. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  90. foreach (Dictionary<string, object> dic in diclist)
  91. {
  92. //创客
  93. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  94. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  95. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  96. dic["UserIdRealName"] = userid_Users.RealName;
  97. dic.Remove("UserId");
  98. //机具所属人
  99. int PosUserId = int.Parse(function.CheckInt(dic["PosUserId"].ToString()));
  100. Users posuserid_Users = db.Users.FirstOrDefault(m => m.Id == PosUserId) ?? new Users();
  101. dic["PosUserIdMakerCode"] = posuserid_Users.MakerCode;
  102. dic["PosUserIdRealName"] = posuserid_Users.RealName;
  103. dic.Remove("PosUserId");
  104. //状态
  105. int Status = int.Parse(function.CheckInt(dic["Status"].ToString()));
  106. if (Status == 0) dic["Status"] = "处理中";
  107. if (Status == 1) dic["Status"] = "成功";
  108. if (Status == -1) dic["Status"] = "失败";
  109. //产品类型
  110. dic["Sort"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["Sort"].ToString()));
  111. }
  112. return Json(obj);
  113. }
  114. #endregion
  115. #region 增加机具费率调整申请
  116. /// <summary>
  117. /// 增加或修改机具费率调整申请信息
  118. /// </summary>
  119. /// <returns></returns>
  120. public IActionResult Add(string right)
  121. {
  122. ViewBag.RightInfo = RightInfo;
  123. ViewBag.right = right;
  124. return View();
  125. }
  126. #endregion
  127. #region 增加机具费率调整申请
  128. /// <summary>
  129. /// 增加或修改机具费率调整申请信息
  130. /// </summary>
  131. /// <returns></returns>
  132. [HttpPost]
  133. public string Add(PosMachinesFeeChangeRecord data)
  134. {
  135. Dictionary<string, object> Fields = new Dictionary<string, object>();
  136. Fields.Add("UserId", data.UserId); //创客
  137. Fields.Add("ChangeFee", data.ChangeFee); //调整费率
  138. Fields.Add("PosSn", data.PosSn); //机具SN
  139. Fields.Add("MerNo", data.MerNo); //商户号
  140. Fields.Add("PosUserId", data.PosUserId); //机具所属人
  141. Fields.Add("SeoTitle", data.SeoTitle);
  142. Fields.Add("SeoKeyword", data.SeoKeyword);
  143. Fields.Add("SeoDescription", data.SeoDescription);
  144. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMachinesFeeChangeRecord", Fields, 0);
  145. AddSysLog(data.Id.ToString(), "PosMachinesFeeChangeRecord", "add");
  146. db.SaveChanges();
  147. return "success";
  148. }
  149. #endregion
  150. #region 修改机具费率调整申请
  151. /// <summary>
  152. /// 增加或修改机具费率调整申请信息
  153. /// </summary>
  154. /// <returns></returns>
  155. public IActionResult Edit(string right, int Id = 0)
  156. {
  157. ViewBag.RightInfo = RightInfo;
  158. ViewBag.right = right;
  159. PosMachinesFeeChangeRecord editData = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesFeeChangeRecord();
  160. ViewBag.data = editData;
  161. return View();
  162. }
  163. #endregion
  164. #region 修改机具费率调整申请
  165. /// <summary>
  166. /// 增加或修改机具费率调整申请信息
  167. /// </summary>
  168. /// <returns></returns>
  169. [HttpPost]
  170. public string Edit(PosMachinesFeeChangeRecord data)
  171. {
  172. Dictionary<string, object> Fields = new Dictionary<string, object>();
  173. Fields.Add("UserId", data.UserId); //创客
  174. Fields.Add("ChangeFee", data.ChangeFee); //调整费率
  175. Fields.Add("PosSn", data.PosSn); //机具SN
  176. Fields.Add("MerNo", data.MerNo); //商户号
  177. Fields.Add("PosUserId", data.PosUserId); //机具所属人
  178. Fields.Add("SeoTitle", data.SeoTitle);
  179. Fields.Add("SeoKeyword", data.SeoKeyword);
  180. Fields.Add("SeoDescription", data.SeoDescription);
  181. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesFeeChangeRecord", Fields, data.Id);
  182. AddSysLog(data.Id.ToString(), "PosMachinesFeeChangeRecord", "update");
  183. db.SaveChanges();
  184. return "success";
  185. }
  186. #endregion
  187. #region 删除机具费率调整申请信息
  188. /// <summary>
  189. /// 删除机具费率调整申请信息
  190. /// </summary>
  191. /// <returns></returns>
  192. public string Delete(string Id)
  193. {
  194. string[] idlist = Id.Split(new char[] { ',' });
  195. AddSysLog(Id, "PosMachinesFeeChangeRecord", "del");
  196. foreach (string subid in idlist)
  197. {
  198. int id = int.Parse(subid);
  199. Dictionary<string, object> Fields = new Dictionary<string, object>();
  200. Fields.Add("Status", -1);
  201. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesFeeChangeRecord", Fields, id);
  202. }
  203. db.SaveChanges();
  204. return "success";
  205. }
  206. #endregion
  207. #region 开启
  208. /// <summary>
  209. /// 开启
  210. /// </summary>
  211. /// <returns></returns>
  212. public string Open(string Id)
  213. {
  214. string[] idlist = Id.Split(new char[] { ',' });
  215. AddSysLog(Id, "PosMachinesFeeChangeRecord", "open");
  216. foreach (string subid in idlist)
  217. {
  218. int id = int.Parse(subid);
  219. Dictionary<string, object> Fields = new Dictionary<string, object>();
  220. Fields.Add("Status", 1);
  221. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesFeeChangeRecord", Fields, id);
  222. }
  223. db.SaveChanges();
  224. return "success";
  225. }
  226. #endregion
  227. #region 关闭
  228. /// <summary>
  229. /// 关闭
  230. /// </summary>
  231. /// <returns></returns>
  232. public string Close(string Id)
  233. {
  234. string[] idlist = Id.Split(new char[] { ',' });
  235. AddSysLog(Id, "PosMachinesFeeChangeRecord", "close");
  236. foreach (string subid in idlist)
  237. {
  238. int id = int.Parse(subid);
  239. Dictionary<string, object> Fields = new Dictionary<string, object>();
  240. Fields.Add("Status", 0);
  241. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesFeeChangeRecord", Fields, id);
  242. }
  243. db.SaveChanges();
  244. return "success";
  245. }
  246. #endregion
  247. #region 排序
  248. /// <summary>
  249. /// 排序
  250. /// </summary>
  251. /// <param name="Id"></param>
  252. public string Sort(int Id, int Sort)
  253. {
  254. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMachinesFeeChangeRecord", Sort, Id);
  255. AddSysLog(Id.ToString(), "PosMachinesFeeChangeRecord", "sort");
  256. return "success";
  257. }
  258. #endregion
  259. #region 导入费率调整结果
  260. /// <summary>
  261. /// 导入费率调整结果
  262. /// </summary>
  263. /// <param name="ExcelData"></param>
  264. public string ImportEnd(string ExcelData)
  265. {
  266. ExcelData = HttpUtility.UrlDecode(ExcelData);
  267. JsonData list = JsonMapper.ToObject(ExcelData);
  268. List<int> dnposIds = new List<int>();
  269. string userIds = "";
  270. string warning = "";
  271. for (int i = 1; i < list.Count; i++)
  272. {
  273. JsonData dr = list[i];
  274. string PosNo = dr[0].ToString(); // 机具Sn
  275. var Amount = double.Parse(dr[1].ToString()); // 调整费率
  276. int Kind = int.Parse(dr[2].ToString()); // 1 调升 2 调低
  277. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosNo) ?? new PosMachinesTwo();
  278. if (pos.UpFeeFlag == 1)
  279. {
  280. if (Kind != 2 || Amount != 0.6)
  281. {
  282. warning += PosNo + ",该机具调低费率数值或类型不正确,请检查好后全部重新导入";
  283. }
  284. else
  285. {
  286. if (Kind == 2 && Amount == 0.6)
  287. {
  288. pos.DownFeeFlag = 1;
  289. pos.DownFeeDate = DateTime.Now;
  290. pos.DownFeeMan = SysUserName + "_" + SysRealName;
  291. var poschange = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == pos.Id);
  292. poschange.Status = 1;
  293. db.SaveChanges();
  294. dnposIds.Add(pos.Id);
  295. }
  296. if (!userIds.Contains(pos.BuyUserId.ToString()))
  297. {
  298. userIds += pos.BuyUserId + ",";
  299. }
  300. }
  301. }
  302. else
  303. {
  304. warning += PosNo + ",该机具不符合调低条件,请检查好后全部重新导入";
  305. }
  306. }
  307. if (!string.IsNullOrEmpty(warning))
  308. {
  309. return "waning |" + warning;
  310. }
  311. string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  312. int times = lists.ToList().Count;
  313. if (dnposIds.Count > 0)
  314. {
  315. //调降
  316. for (int i = 0; i < times; i++)
  317. {
  318. var UserId = lists[i];
  319. var posInfo = db.PosMachinesTwo.Where(m => dnposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  320. string snhtml = "<div style='margin-bottom: .48rem;'>";
  321. foreach (var items in posInfo)
  322. {
  323. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  324. string Name = mer.MerchantName;
  325. if (mer.BrandId == 2)
  326. {
  327. if (Name.Contains("-"))
  328. {
  329. Name = Name.Split('-')[1];
  330. }
  331. else if (Name.Contains("_"))
  332. {
  333. Name = Name.Split('_')[1];
  334. }
  335. }
  336. var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  337. snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  338. snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  339. snhtml += "<div class='f16'>SN:" + items.PosSn + "</div>";
  340. snhtml += "<div class='f16'>当前费率:0.6%</div>";
  341. snhtml += "<div class='f16'>费率调整时间:" + items.DownFeeDate + "</div></div>";
  342. }
  343. snhtml += "</div>";
  344. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  345. {
  346. UserId = Convert.ToInt32(UserId), //创客
  347. Title = "商户费率变更通知", //标题
  348. Content = "<div class='f16' style='margin-bottom: .72rem'>您的商户刷卡交易费率已变更成功!</div>" + snhtml, //内容
  349. Summary = "您的商户刷卡交易费率已变更成功!",
  350. CreateDate = DateTime.Now,
  351. }));
  352. }
  353. }
  354. AddSysLog("0", "PosMachinesTwoChange", "ImportEnd");
  355. return "success";
  356. }
  357. #endregion
  358. #region 导入数据
  359. /// <summary>
  360. /// 导入数据
  361. /// </summary>
  362. /// <param name="ExcelData"></param>
  363. public string Import(string ExcelData)
  364. {
  365. ExcelData = HttpUtility.UrlDecode(ExcelData);
  366. JsonData list = JsonMapper.ToObject(ExcelData);
  367. for (int i = 1; i < list.Count; i++)
  368. {
  369. JsonData dr = list[i];
  370. db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  371. {
  372. CreateDate = DateTime.Now,
  373. UpdateDate = DateTime.Now,
  374. });
  375. db.SaveChanges();
  376. }
  377. AddSysLog("0", "PosMachinesFeeChangeRecord", "Import");
  378. return "success";
  379. }
  380. #endregion
  381. #region 导出Excel
  382. /// <summary>
  383. /// 导出Excel
  384. /// </summary>
  385. /// <returns></returns>
  386. public JsonResult ExportExcel(PosMachinesFeeChangeRecord data, string UserIdMakerCode, string UserIdRealName, string PosUserIdMakerCode, string PosUserIdRealName)
  387. {
  388. Dictionary<string, string> Fields = new Dictionary<string, string>();
  389. Fields.Add("CreateDate", "3"); //时间
  390. Fields.Add("PosSn", "1"); //机具SN
  391. Fields.Add("MerNo", "1"); //商户号
  392. Fields.Add("Sort", "0"); //品牌
  393. string condition = " and Status>-1 and Sort = " + data.Sort + "";
  394. //创客创客编号
  395. if (!string.IsNullOrEmpty(UserIdMakerCode))
  396. {
  397. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  398. }
  399. //创客真实姓名
  400. if (!string.IsNullOrEmpty(UserIdRealName))
  401. {
  402. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  403. }
  404. //机具所属人创客编号
  405. if (!string.IsNullOrEmpty(PosUserIdMakerCode))
  406. {
  407. condition += " and PosUserId in (select PosUserId from UsersForMakerCode where MakerCode='" + PosUserIdMakerCode + "')";
  408. }
  409. //机具所属人真实姓名
  410. if (!string.IsNullOrEmpty(PosUserIdRealName))
  411. {
  412. condition += " and PosUserId in (select PosUserId from UsersForRealName where RealName='" + PosUserIdRealName + "')";
  413. }
  414. if (data.Status > 0)
  415. {
  416. if(data.Status == 2) data.Status = 0;
  417. if(data.Status == 3) data.Status = -1;
  418. condition += " and Status = " + data.Status;
  419. }
  420. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesFeeChangeRecord", Fields, "Id desc", "0", 1, 20000, condition, "PosSn,ChangeFee", false);
  421. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  422. foreach (Dictionary<string, object> dic in diclist)
  423. {
  424. // //创客
  425. // int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  426. // Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  427. // dic["UserIdMakerCode"] = userid_Users.MakerCode;
  428. // dic["UserIdRealName"] = userid_Users.RealName;
  429. // dic.Remove("UserId");
  430. // //机具所属人
  431. // int PosUserId = int.Parse(function.CheckInt(dic["PosUserId"].ToString()));
  432. // Users posuserid_Users = db.Users.FirstOrDefault(m => m.Id == PosUserId) ?? new Users();
  433. // dic["PosUserIdMakerCode"] = posuserid_Users.MakerCode;
  434. // dic["PosUserIdRealName"] = posuserid_Users.RealName;
  435. // dic.Remove("PosUserId");
  436. var PosSn = dic["PosSn"].ToString();
  437. var ChangeFee = function.CheckNum(dic["ChangeFee"].ToString());
  438. dic.Add("Kind", "2");
  439. }
  440. Dictionary<string, object> result = new Dictionary<string, object>();
  441. result.Add("Status", "1");
  442. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  443. result.Add("Obj", diclist);
  444. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  445. // ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  446. // ReturnFields.Add("UserIdRealName", "创客真实姓名");
  447. // ReturnFields.Add("ChangeFee", "调整费率");
  448. ReturnFields.Add("PosSn", "机具SN");
  449. ReturnFields.Add("ChangeFee", "调整费率");
  450. ReturnFields.Add("Kind", "调整类型(2-调降)");
  451. result.Add("Fields", ReturnFields);
  452. AddSysLog("0", "PosMachinesFeeChangeRecord", "ExportExcel");
  453. return Json(result);
  454. }
  455. #endregion
  456. }
  457. }