LisController.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class LisController : BaseController
  18. {
  19. public LisController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 立刷-获取押金列表
  23. [Authorize]
  24. public JsonResult GetDepositList(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = GetDepositListDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> GetDepositListDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  35. Dictionary<string, object> row = new Dictionary<string, object>();
  36. row.Add("Id", "0");
  37. row.Add("Name", "押0");
  38. dataList.Add(row);
  39. row = new Dictionary<string, object>();
  40. row.Add("Id", "99");
  41. row.Add("Name", "押99");
  42. dataList.Add(row);
  43. row = new Dictionary<string, object>();
  44. row.Add("Id", "199");
  45. row.Add("Name", "押199");
  46. dataList.Add(row);
  47. row = new Dictionary<string, object>();
  48. row.Add("Id", "249");
  49. row.Add("Name", "押249");
  50. dataList.Add(row);
  51. return dataList;
  52. }
  53. #endregion
  54. #region 立刷-设置押金
  55. [Authorize]
  56. public JsonResult SetDeposit(string value)
  57. {
  58. value = DesDecrypt(value);
  59. JsonData data = JsonMapper.ToObject(value);
  60. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
  61. string SnIds = data["SnIds"].ToString(); //机具Id列表
  62. string check = RedisDbconn.Instance.Get<string>("SetLisDepositWait:" + UserId);
  63. if (!string.IsNullOrEmpty(check))
  64. {
  65. return Json(new AppResultJson() { Status = "-1", Info = "操作频繁,请稍后再试" });
  66. }
  67. RedisDbconn.Instance.Set("SetLisDepositWait:" + UserId, SnIds);
  68. RedisDbconn.Instance.SetExpire("SetLisDepositWait:" + UserId, 120);
  69. string DepositId = data["DepositId"].ToString(); //押金Id
  70. Dictionary<string, object> Obj = new Dictionary<string, object>();
  71. string[] SnIdList = SnIds.Split(',');
  72. foreach (string SnId in SnIdList)
  73. {
  74. int SnIdNum = int.Parse(SnId);
  75. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.UserId == UserId && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  76. if (pos == null)
  77. {
  78. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "已设置押金,请勿重复设置" });
  79. }
  80. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "立刷-设置押金-返回报文");
  81. string content = PublicImportDataService.Instance.SetLiSDeposit(pos.PosSn, int.Parse(DepositId));
  82. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "立刷-设置押金-返回报文");
  83. JsonData jsonObj = JsonMapper.ToObject(content);
  84. if (jsonObj["ret_code"].ToString() != "00")
  85. {
  86. return Json(new AppResultJson() { Status = "-1", Info = jsonObj["ret_msg"].ToString() });
  87. }
  88. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "立刷-设置押金-返回报文");
  89. var BeforeDeposit = 0;
  90. if (string.IsNullOrEmpty(pos.PrizeParams))
  91. {
  92. if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签")
  93. {
  94. BeforeDeposit = 249;
  95. }
  96. else
  97. {
  98. BeforeDeposit = 299;
  99. }
  100. }
  101. else
  102. {
  103. BeforeDeposit = int.Parse(pos.PrizeParams);
  104. }
  105. pos.PrizeParams = DepositId;
  106. maindb.SaveChanges();
  107. //设置押金添加记录
  108. PublicFunction.MerchantDepositSet(pos.BrandId, UserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content);
  109. }
  110. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  111. }
  112. #endregion
  113. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  114. /// <summary>
  115. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  116. /// </summary>
  117. /// <param name="value">请求的参数(json字符串)</param>
  118. /// <param name="signField">要签名的字段</param>
  119. /// <returns></returns>
  120. private string CheckSign(string value, string[] signField)
  121. {
  122. JsonData json = JsonMapper.ToObject(value);
  123. Dictionary<string, string> dic = new Dictionary<string, string>();
  124. for (int i = 0; i < signField.Length; i++)
  125. {
  126. dic.Add(signField[i], json[signField[i]].ToString());
  127. }
  128. string sign = json["sign"].ToString(); //客户端签名字符串
  129. return new Sign().sign(dic, sign);
  130. }
  131. #endregion
  132. }
  133. }