using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; namespace MySystem.Areas.Api.Controllers.v1 { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class StoreHouseAmountRecordController : BaseController { public StoreHouseAmountRecordController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 创客-首页-仓库管理-申请机具-调低临时额度 [Authorize] public JsonResult DownAmount(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = DownAmountDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson DownAmountDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id int Amount = int.Parse(function.CheckInt(data["Amount"].ToString())); //操作金额 int ReductQuotaBalance = int.Parse(function.CheckInt(data["ReductQuotaBalance"].ToString())); //操作金额 Dictionary Obj = new Dictionary(); string check = RedisDbconn.Instance.Get("DownAmount:" + UserId); if (!string.IsNullOrEmpty(check)) { return new AppResultJson() { Status = "-1", Info = "操作频繁,请一分钟后再试", Data = Obj }; } RedisDbconn.Instance.Set("DownAmount:" + UserId, "1"); RedisDbconn.Instance.SetExpire("DownAmount:" + UserId, 60); var userAccount = maindb.UserAccount.FirstOrDefault(m => m.UserId == UserId); if (Amount > 0) { if (userAccount.ValidAmount >= userAccount.TempAmount && Amount <= userAccount.TempAmount) { string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + Amount + "\",\"PayMode\":\"1\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); } else if (userAccount.ValidAmount < userAccount.TempAmount && Amount <= userAccount.ValidAmount) { string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + Amount + "\",\"PayMode\":\"1\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); } else { return new AppResultJson() { Status = "-1", Info = "调低的临时额度大于您的可调低临时额度,请重新选择", Data = Obj }; } } if (ReductQuotaBalance > 0) { if (userAccount.ValidAmount >= userAccount.TempAmountForBalance && ReductQuotaBalance <= userAccount.TempAmountForBalance) { string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + ReductQuotaBalance + "\",\"PayMode\":\"3\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); } else if (userAccount.ValidAmount < userAccount.TempAmountForBalance && ReductQuotaBalance <= userAccount.ValidAmount) { string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + UserId + "\",\"Amount\":\"" + ReductQuotaBalance + "\",\"PayMode\":\"3\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); } else { return new AppResultJson() { Status = "-1", Info = "调低的临时额度大于您的可调低临时额度,请重新选择", Data = Obj }; } } return new AppResultJson() { Status = "1", Info = "调整成功,金额将返还至您的创客余额", Data = Obj }; } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }