StoreHouseAmountRecordController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 StoreHouseAmountRecordController : BaseController
  18. {
  19. public StoreHouseAmountRecordController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 创客-首页-仓库管理-申请机具-调低临时额度
  23. [Authorize]
  24. public JsonResult DownAmount(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. AppResultJson result = DownAmountDo(value);
  29. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  30. }
  31. public AppResultJson DownAmountDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
  35. int Amount = int.Parse(function.CheckInt(data["Amount"].ToString())); //操作金额
  36. int ReductQuotaBalance = int.Parse(function.CheckInt(data["ReductQuotaBalance"].ToString())); //操作金额
  37. Dictionary<string, object> Obj = new Dictionary<string, object>();
  38. string check = RedisDbconn.Instance.Get<string>("DownAmount:" + UserId);
  39. if (!string.IsNullOrEmpty(check))
  40. {
  41. return new AppResultJson() { Status = "-1", Info = "操作频繁,请一分钟后再试", Data = Obj };
  42. }
  43. RedisDbconn.Instance.Set("DownAmount:" + UserId, "1");
  44. RedisDbconn.Instance.SetExpire("DownAmount:" + UserId, 60);
  45. var userAccount = maindb.UserAccount.FirstOrDefault(m => m.UserId == UserId);
  46. if (Amount > 0)
  47. {
  48. if (userAccount.ValidAmount >= userAccount.TempAmount && Amount <= userAccount.TempAmount)
  49. {
  50. string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + Amount + "\",\"PayMode\":\"1\"}}";
  51. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  52. }
  53. else if (userAccount.ValidAmount < userAccount.TempAmount && Amount <= userAccount.ValidAmount)
  54. {
  55. string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + Amount + "\",\"PayMode\":\"1\"}}";
  56. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  57. }
  58. else
  59. {
  60. return new AppResultJson() { Status = "-1", Info = "调低的临时额度大于您的可调低临时额度,请重新选择", Data = Obj };
  61. }
  62. }
  63. if (ReductQuotaBalance > 0)
  64. {
  65. if (userAccount.ValidAmount >= userAccount.TempAmountForBalance && ReductQuotaBalance <= userAccount.TempAmountForBalance)
  66. {
  67. string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + ReductQuotaBalance + "\",\"PayMode\":\"3\"}}";
  68. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  69. }
  70. else if (userAccount.ValidAmount < userAccount.TempAmountForBalance && ReductQuotaBalance <= userAccount.ValidAmount)
  71. {
  72. string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + ReductQuotaBalance + "\",\"PayMode\":\"3\"}}";
  73. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  74. }
  75. else
  76. {
  77. return new AppResultJson() { Status = "-1", Info = "调低的临时额度大于您的可调低临时额度,请重新选择", Data = Obj };
  78. }
  79. }
  80. return new AppResultJson() { Status = "1", Info = "调整成功,金额将返还至您的创客余额", Data = Obj };
  81. }
  82. #endregion
  83. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  84. /// <summary>
  85. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  86. /// </summary>
  87. /// <param name="value">请求的参数(json字符串)</param>
  88. /// <param name="signField">要签名的字段</param>
  89. /// <returns></returns>
  90. private string CheckSign(string value, string[] signField)
  91. {
  92. JsonData json = JsonMapper.ToObject(value);
  93. Dictionary<string, string> dic = new Dictionary<string, string>();
  94. for (int i = 0; i < signField.Length; i++)
  95. {
  96. dic.Add(signField[i], json[signField[i]].ToString());
  97. }
  98. string sign = json["sign"].ToString(); //客户端签名字符串
  99. return new Sign().sign(dic, sign);
  100. }
  101. #endregion
  102. }
  103. }