HkController.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 HkController : BaseController
  18. {
  19. public HkController(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", "100");
  37. row.Add("Name", "押99");
  38. dataList.Add(row);
  39. row = new Dictionary<string, object>();
  40. row.Add("Id", "200");
  41. row.Add("Name", "押199");
  42. dataList.Add(row);
  43. row = new Dictionary<string, object>();
  44. row.Add("Id", "300");
  45. row.Add("Name", "押299");
  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>("SetHkDepositWait:" + UserId);
  59. if (!string.IsNullOrEmpty(check))
  60. {
  61. return Json(new AppResultJson() { Status = "-1", Info = "操作频繁,请稍后再试" });
  62. }
  63. RedisDbconn.Instance.Set("SetHkDepositWait:" + UserId, SnIds);
  64. RedisDbconn.Instance.SetExpire("SetHkDepositWait:" + 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. var posMer = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  73. if (pos == null)
  74. {
  75. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "已设置押金,请勿重复设置" });
  76. }
  77. string OldId = "", NewId = "";
  78. if (DepositId == "100")
  79. {
  80. NewId = pos.BrandId == 8 ? "202207011718129" : "202207011718197";
  81. }
  82. else if (DepositId == "200")
  83. {
  84. NewId = pos.BrandId == 8 ? "747200504467566592" : "747199934126108672";
  85. }
  86. else if (DepositId == "300")
  87. {
  88. NewId = pos.BrandId == 8 ? "747193472108732416" : "747193820156276736";
  89. }
  90. string content = PublicImportDataService.Instance.QueryActiveForConfigHK(pos.PosSn, pos.BrandId);
  91. JsonData jsonObj = JsonMapper.ToObject(content);
  92. if (jsonObj["code"].ToString() == "0")
  93. {
  94. OldId = jsonObj["data"]["posMarket"]["id"].ToString();
  95. }
  96. jsonObj = JsonMapper.ToObject(content);
  97. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + OldId + ":" + NewId, "海科-设置押金-返回报文");
  98. content = PublicImportDataService.Instance.SetDepositForHK(pos.PosSn, OldId, NewId, pos.BrandId);
  99. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "海科-设置押金-返回报文");
  100. if (content == "fail")
  101. {
  102. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "设置失败" });
  103. }
  104. jsonObj = JsonMapper.ToObject(content);
  105. if (jsonObj["code"].ToString() != "0")
  106. {
  107. return Json(new AppResultJson() { Status = "-1", Info = jsonObj["msg"].ToString() });
  108. }
  109. decimal amount = decimal.Parse(DepositId);
  110. var BeforeDeposit = 0;
  111. if (string.IsNullOrEmpty(pos.PrizeParams))
  112. {
  113. if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签")
  114. {
  115. BeforeDeposit = 249;
  116. }
  117. else
  118. {
  119. BeforeDeposit = 299;
  120. }
  121. }
  122. else
  123. {
  124. BeforeDeposit = int.Parse(pos.PrizeParams);
  125. }
  126. if (pos.BrandId == 8 || pos.BrandId == 9)
  127. {
  128. amount -= 1;
  129. }
  130. pos.PrizeParams = amount.ToString("f0");
  131. maindb.SaveChanges();
  132. //设置押金添加记录
  133. PublicFunction.MerchantDepositSet(pos.BrandId, UserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content);
  134. }
  135. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  136. }
  137. #endregion
  138. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  139. /// <summary>
  140. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  141. /// </summary>
  142. /// <param name="value">请求的参数(json字符串)</param>
  143. /// <param name="signField">要签名的字段</param>
  144. /// <returns></returns>
  145. private string CheckSign(string value, string[] signField)
  146. {
  147. JsonData json = JsonMapper.ToObject(value);
  148. Dictionary<string, string> dic = new Dictionary<string, string>();
  149. for (int i = 0; i < signField.Length; i++)
  150. {
  151. dic.Add(signField[i], json[signField[i]].ToString());
  152. }
  153. string sign = json["sign"].ToString(); //客户端签名字符串
  154. return new Sign().sign(dic, sign);
  155. }
  156. #endregion
  157. }
  158. }