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 HkController : BaseController { public HkController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 海科-获取押金列表 [Authorize] public JsonResult GetDepositList(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = GetDepositListDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> GetDepositListDo(string value) { JsonData data = JsonMapper.ToObject(value); List> dataList = new List>(); Dictionary row = new Dictionary(); row.Add("Id", "100"); row.Add("Name", "押99"); dataList.Add(row); row = new Dictionary(); row.Add("Id", "200"); row.Add("Name", "押199"); dataList.Add(row); row = new Dictionary(); row.Add("Id", "300"); row.Add("Name", "押299"); dataList.Add(row); return dataList; } #endregion #region 海科-设置押金 [Authorize] public JsonResult SetDeposit(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); string SnIds = data["SnIds"].ToString(); //机具Id列表 string check = RedisDbconn.Instance.Get("SetHkDepositWait:" + UserId); if (!string.IsNullOrEmpty(check)) { return Json(new AppResultJson() { Status = "-1", Info = "操作频繁,请稍后再试" }); } RedisDbconn.Instance.Set("SetHkDepositWait:" + UserId, SnIds); RedisDbconn.Instance.SetExpire("SetHkDepositWait:" + UserId, 120); string DepositId = data["DepositId"].ToString(); //押金Id Dictionary Obj = new Dictionary(); string[] SnIdList = SnIds.Split(','); foreach (string SnId in SnIdList) { int SnIdNum = int.Parse(SnId); PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.UserId == UserId && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0")); var posMer = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId); if (pos == null) { return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "已设置押金,请勿重复设置" }); } string OldId = "", NewId = ""; if (DepositId == "100") { NewId = pos.BrandId == 8 ? "202207011718129" : "202207011718197"; } else if (DepositId == "200") { NewId = pos.BrandId == 8 ? "747200504467566592" : "747199934126108672"; } else if (DepositId == "300") { NewId = pos.BrandId == 8 ? "747193472108732416" : "747193820156276736"; } string content = PublicImportDataService.Instance.QueryActiveForConfigHK(pos.PosSn, pos.BrandId); JsonData jsonObj = JsonMapper.ToObject(content); if (jsonObj["code"].ToString() == "0") { OldId = jsonObj["data"]["posMarket"]["id"].ToString(); } jsonObj = JsonMapper.ToObject(content); function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + OldId + ":" + NewId, "海科-设置押金-返回报文"); content = PublicImportDataService.Instance.SetDepositForHK(pos.PosSn, OldId, NewId, pos.BrandId); function.WriteLog(DateTime.Now.ToString() + "\n" + content, "海科-设置押金-返回报文"); if (content == "fail") { return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "设置失败" }); } jsonObj = JsonMapper.ToObject(content); if (jsonObj["code"].ToString() != "0") { return Json(new AppResultJson() { Status = "-1", Info = jsonObj["msg"].ToString() }); } decimal amount = decimal.Parse(DepositId); var BeforeDeposit = 0; if (string.IsNullOrEmpty(pos.PrizeParams)) { if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签") { BeforeDeposit = 249; } else { BeforeDeposit = 299; } } else { BeforeDeposit = int.Parse(pos.PrizeParams); } if (pos.BrandId == 8 || pos.BrandId == 9) { amount -= 1; } pos.PrizeParams = amount.ToString("f0"); maindb.SaveChanges(); //设置押金添加记录 PublicFunction.MerchantDepositSet(pos.BrandId, UserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content); } return Json(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 } }