JkController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 JkController : BaseController
  18. {
  19. public JkController(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. return dataList;
  48. }
  49. #endregion
  50. #region 金控-设置押金
  51. [Authorize]
  52. public JsonResult SetDeposit(string value)
  53. {
  54. value = DesDecrypt(value);
  55. JsonData data = JsonMapper.ToObject(value);
  56. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
  57. string SnIds = data["SnIds"].ToString(); //机具Id列表
  58. string check = RedisDbconn.Instance.Get<string>("SetDepositWait:" + UserId);
  59. if (!string.IsNullOrEmpty(check))
  60. {
  61. return Json(new AppResultJson() { Status = "-1", Info = "操作频繁,请稍后再试" });
  62. }
  63. RedisDbconn.Instance.Set("SetDepositWait:" + UserId, SnIds);
  64. RedisDbconn.Instance.SetExpire("SetDepositWait:" + UserId, 120);
  65. string DepositId = data["DepositId"].ToString(); //押金Id
  66. Dictionary<string, object> Obj = new Dictionary<string, object>();
  67. string[] SnIdList = SnIds.Split(',');
  68. foreach (string SnId in SnIdList)
  69. {
  70. int SnIdNum = int.Parse(SnId);
  71. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.UserId == UserId && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  72. if (pos == null)
  73. {
  74. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "已设置押金,请勿重复设置" });
  75. }
  76. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "金控-设置押金-返回报文");
  77. string content = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/SetDeposit?sn=" + pos.PosSn + "&num=" + DepositId); //PublicImportDataService.Instance.SetDeposit(pos.PosSn, decimal.Parse(DepositId));
  78. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "金控-设置押金-返回报文");
  79. if (content == "fail")
  80. {
  81. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "设置失败" });
  82. }
  83. JsonData jsonObj = JsonMapper.ToObject(content);
  84. if (jsonObj["code"].ToString() != "000000")
  85. {
  86. return Json(new AppResultJson() { Status = "-1", Info = jsonObj["message"].ToString() });
  87. }
  88. content = jsonObj["data"].ToString();
  89. content = PublicImportDataService.Instance.Decrypt(content);
  90. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "金控-设置押金-返回报文");
  91. JsonData contentObj = JsonMapper.ToObject(content);
  92. if (contentObj["respCode"].ToString() != "00")
  93. {
  94. return Json(new AppResultJson() { Status = "-1", Info = contentObj["respMsg"].ToString() });
  95. }
  96. var BeforeDeposit = 0;
  97. if (string.IsNullOrEmpty(pos.PrizeParams))
  98. {
  99. if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签")
  100. {
  101. BeforeDeposit = 249;
  102. }
  103. else
  104. {
  105. BeforeDeposit = 299;
  106. }
  107. }
  108. else
  109. {
  110. BeforeDeposit = int.Parse(pos.PrizeParams);
  111. }
  112. decimal amount = decimal.Parse(DepositId);
  113. pos.PrizeParams = amount.ToString("f0");
  114. maindb.SaveChanges();
  115. //设置押金添加记录
  116. PublicFunction.MerchantDepositSet(pos.BrandId, UserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content);
  117. }
  118. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  119. }
  120. #endregion
  121. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  122. /// <summary>
  123. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  124. /// </summary>
  125. /// <param name="value">请求的参数(json字符串)</param>
  126. /// <param name="signField">要签名的字段</param>
  127. /// <returns></returns>
  128. private string CheckSign(string value, string[] signField)
  129. {
  130. JsonData json = JsonMapper.ToObject(value);
  131. Dictionary<string, string> dic = new Dictionary<string, string>();
  132. for (int i = 0; i < signField.Length; i++)
  133. {
  134. dic.Add(signField[i], json[signField[i]].ToString());
  135. }
  136. string sign = json["sign"].ToString(); //客户端签名字符串
  137. return new Sign().sign(dic, sign);
  138. }
  139. #endregion
  140. }
  141. }