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