LsController.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 LsController : BaseController
  18. {
  19. public LsController(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>("SetLsDepositWait:" + UserId);
  59. if (!string.IsNullOrEmpty(check))
  60. {
  61. return Json(new AppResultJson() { Status = "-1", Info = "操作频繁,请稍后再试" });
  62. }
  63. RedisDbconn.Instance.Set("SetLsDepositWait:" + UserId, SnIds);
  64. RedisDbconn.Instance.SetExpire("SetLsDepositWait:" + 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. string OldId = "", NewId = "";
  77. // string content = PublicImportDataService.Instance.QueryActiveForBrand(int.Parse(DepositId), pos.BrandId);
  78. // JsonData jsonObj = JsonMapper.ToObject(content);
  79. // if (jsonObj["code"].ToString() == "0")
  80. // {
  81. if (DepositId == "100")
  82. {
  83. NewId = "704067039039856640";
  84. }
  85. else if (DepositId == "200")
  86. {
  87. NewId = "709820183485095936";
  88. }
  89. else if (DepositId == "300")
  90. {
  91. NewId = "709820390742437888";
  92. }
  93. // }
  94. string content = PublicImportDataService.Instance.QueryActiveForConfig(pos.PosSn, pos.BrandId);
  95. JsonData jsonObj = JsonMapper.ToObject(content);
  96. if (jsonObj["code"].ToString() == "0")
  97. {
  98. OldId = jsonObj["data"]["posMarket"]["id"].ToString();
  99. }
  100. jsonObj = JsonMapper.ToObject(content);
  101. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + OldId + ":" + NewId, "乐刷-设置押金-返回报文");
  102. content = PublicImportDataService.Instance.SetDepositForLS(pos.PosSn, OldId, NewId, pos.BrandId);
  103. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "乐刷-设置押金-返回报文");
  104. if (content == "fail")
  105. {
  106. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "设置失败" });
  107. }
  108. jsonObj = JsonMapper.ToObject(content);
  109. if (jsonObj["code"].ToString() != "0")
  110. {
  111. return Json(new AppResultJson() { Status = "-1", Info = jsonObj["msg"].ToString() });
  112. }
  113. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "乐刷-设置押金-返回报文");
  114. // JsonData contentObj = JsonMapper.ToObject(content);
  115. // if (contentObj["respCode"].ToString() != "00")
  116. // {
  117. // return Json(new AppResultJson() { Status = "-1", Info = contentObj["respMsg"].ToString() });
  118. // }
  119. var BeforeDeposit = 0;
  120. if (string.IsNullOrEmpty(pos.PrizeParams))
  121. {
  122. if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签")
  123. {
  124. BeforeDeposit = 249;
  125. }
  126. else
  127. {
  128. BeforeDeposit = 299;
  129. }
  130. }
  131. else
  132. {
  133. BeforeDeposit = int.Parse(pos.PrizeParams);
  134. }
  135. decimal amount = decimal.Parse(DepositId);
  136. if (pos.BrandId == 4 || pos.BrandId == 5)
  137. {
  138. amount -= 1;
  139. }
  140. pos.PrizeParams = amount.ToString("f0");
  141. maindb.SaveChanges();
  142. //设置押金添加记录
  143. PublicFunction.MerchantDepositSet(pos.BrandId, UserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content);
  144. }
  145. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  146. }
  147. #endregion
  148. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  149. /// <summary>
  150. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  151. /// </summary>
  152. /// <param name="value">请求的参数(json字符串)</param>
  153. /// <param name="signField">要签名的字段</param>
  154. /// <returns></returns>
  155. private string CheckSign(string value, string[] signField)
  156. {
  157. JsonData json = JsonMapper.ToObject(value);
  158. Dictionary<string, string> dic = new Dictionary<string, string>();
  159. for (int i = 0; i < signField.Length; i++)
  160. {
  161. dic.Add(signField[i], json[signField[i]].ToString());
  162. }
  163. string sign = json["sign"].ToString(); //客户端签名字符串
  164. return new Sign().sign(dic, sign);
  165. }
  166. #endregion
  167. }
  168. }