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 PosMachinesFeeChangeRecordController : BaseController { public PosMachinesFeeChangeRecordController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 降扣-申请调低机具费率 [Authorize] public JsonResult ApplyPost(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = ApplyPostDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson ApplyPostDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客 int PosId = int.Parse(function.CheckInt(data["PosId"].ToString())); //机具Id decimal ChangeFee = decimal.Parse(function.CheckNum(data["ChangeFee"].ToString())); //调整费率 Dictionary Obj = new Dictionary(); var user = maindb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users(); var pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId) ?? new PosMachinesTwo(); var mer = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo(); string Name = mer.MerchantName; if (mer.BrandId == 2) { if (Name.Contains("-")) { Name = Name.Split('-')[1]; } else if (Name.Contains("_")) { Name = Name.Split('_')[1]; } } var brand = maindb.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts(); RedisDbconn.Instance.GetLock("CheckApplyPostId:" + PosId); var poschannge = maindb.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == PosId && m.UserId == UserId && m.Status != -1); if (poschannge != null) { RedisDbconn.Instance.ReleaseLock("CheckApplyPostId:" + PosId); return new AppResultJson() { Status = "-1", Info = "已经申请过了,请勿重复申请!", Data = Obj }; } else { PosMachinesFeeChangeRecord query = new PosMachinesFeeChangeRecord(); query = maindb.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord() { CreateDate = DateTime.Now, //创建时间 Sort = pos.BrandId, //品牌Id UserId = UserId, //创客 PosId = PosId, //机具Id PosSn = pos.PosSn, MerNo = mer.MerchantNo, MerchantId = mer.Id, PosUserId = pos.BuyUserId, //机具所属人 ChangeFee = ChangeFee, //调整费率 }).Entity; maindb.SaveChanges(); // PosId:机具Id // Kind:1或2,1为费率0.63,2为费率0.6 // OpMan:操作人,app传创客编号,后台传SysUserName string info = "{\"RecordId\":\"" + query.Id + "\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"" + 0.6 + "\",\"Kind\": \"2\",\"OpMan\": \"" + user.MakerCode + "\"}"; RedisDbconn.Instance.AddList("SetDepositQueue", info); string snhtml = "
"; snhtml += "
商户姓名:" + Name + "
"; snhtml += "
机具品牌:" + brand.Name + "
"; snhtml += "
SN:" + pos.PosSn + "
"; snhtml += "
当前费率:0.63%
"; snhtml += "
变更费率:0.6%
"; snhtml += "
变更时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "
"; snhtml += "
"; RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal() { UserId = UserId, //创客 Title = "商户费率变更通知", //标题 Content = "
您的商户刷卡交易费率正在审核中!
" + snhtml, //内容 Summary = "您的商户刷卡交易费率正在审核中!", CreateDate = DateTime.Now, })); } 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 } }