PosMachinesFeeChangeRecordController.cs 22 KB

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