KdbController.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 KdbController : BaseController
  18. {
  19. public KdbController(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();
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> GetDepositListDo()
  32. {
  33. // JsonData data = JsonMapper.ToObject(value);
  34. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  35. string content = RedisDbconn.Instance.Get<string>("KdbDepositList");
  36. if (string.IsNullOrEmpty(content))
  37. {
  38. content = PublicImportDataService.Instance.GetPolicyList();
  39. JsonData tops = JsonMapper.ToObject(content);
  40. if (tops.Count > 0)
  41. {
  42. content = PublicImportDataService.Instance.GetDepositList(tops[0]["id"].ToString());
  43. }
  44. RedisDbconn.Instance.Set("KdbDepositList", content);
  45. RedisDbconn.Instance.SetExpire("KdbDepositList", function.get_Random(1800, 5400));
  46. }
  47. JsonData list = JsonMapper.ToObject(content);
  48. for (int i = 0; i < list.Count; i++)
  49. {
  50. JsonData item = list[i];
  51. Dictionary<string, object> row = new Dictionary<string, object>();
  52. row.Add("Id", item["depositId"].ToString());
  53. string depositName = item["depositName"].ToString();
  54. if (depositName.Contains("返"))
  55. {
  56. depositName = depositName.Split(new string[] { "返" }, StringSplitOptions.None)[0];
  57. }
  58. if(depositName != "押0")
  59. {
  60. row.Add("Name", depositName);
  61. dataList.Add(row);
  62. }
  63. }
  64. return dataList;
  65. }
  66. #endregion
  67. #region 开店宝-设置押金
  68. [Authorize]
  69. public JsonResult SetDeposit(string value)
  70. {
  71. value = DesDecrypt(value);
  72. JsonData data = JsonMapper.ToObject(value);
  73. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
  74. string SnIds = data["SnIds"].ToString(); //机具Id列表
  75. string DepositId = data["DepositId"].ToString(); //押金Id
  76. Dictionary<string, object> Obj = new Dictionary<string, object>();
  77. string[] SnIdList = SnIds.Split(',');
  78. foreach (string SnId in SnIdList)
  79. {
  80. int SnIdNum = int.Parse(SnId);
  81. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.UserId == UserId && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  82. if (pos == null)
  83. {
  84. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "已设置押金,请勿重复设置" });
  85. }
  86. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "开店宝-设置押金-返回报文");
  87. string content = PublicImportDataService.Instance.ModifyDeposit(pos.PosSn, DepositId);
  88. if (content == "fail")
  89. {
  90. return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "设置失败" });
  91. }
  92. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "开店宝-设置押金-返回报文");
  93. var BeforeDeposit = 0;
  94. if (string.IsNullOrEmpty(pos.PrizeParams))
  95. {
  96. if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签")
  97. {
  98. BeforeDeposit = 249;
  99. }
  100. else
  101. {
  102. BeforeDeposit = 299;
  103. }
  104. }
  105. else
  106. {
  107. BeforeDeposit = int.Parse(pos.PrizeParams);
  108. }
  109. decimal amount = decimal.Parse(PublicImportDataService.Instance.GetDepositAmount(DepositId));
  110. pos.PrizeParams = amount.ToString("f0");
  111. maindb.SaveChanges();
  112. //设置押金添加记录
  113. PublicFunction.MerchantDepositSet(pos.BrandId, UserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content);
  114. }
  115. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  116. }
  117. #endregion
  118. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  119. /// <summary>
  120. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  121. /// </summary>
  122. /// <param name="value">请求的参数(json字符串)</param>
  123. /// <param name="signField">要签名的字段</param>
  124. /// <returns></returns>
  125. private string CheckSign(string value, string[] signField)
  126. {
  127. JsonData json = JsonMapper.ToObject(value);
  128. Dictionary<string, string> dic = new Dictionary<string, string>();
  129. for (int i = 0; i < signField.Length; i++)
  130. {
  131. dic.Add(signField[i], json[signField[i]].ToString());
  132. }
  133. string sign = json["sign"].ToString(); //客户端签名字符串
  134. return new Sign().sign(dic, sign);
  135. }
  136. #endregion
  137. }
  138. }