123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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<BaseController> logger, IOptions<Setting> 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<string, object> Obj = new Dictionary<string, object>();
- 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 = "<div style='margin-bottom: .48rem;'>";
- snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
- snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
- snhtml += "<div class='f16'>SN:" + pos.PosSn + "</div>";
- snhtml += "<div class='f16'>当前费率:0.63%</div>";
- snhtml += "<div class='f16'>变更费率:0.6%</div>";
- snhtml += "<div class='f16'>变更时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</div></div>";
- snhtml += "</div>";
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = UserId, //创客
- Title = "商户费率变更通知", //标题
- Content = "<div class='f16' style='margin-bottom: .72rem'>您的商户刷卡交易费率正在审核中!</div>" + snhtml, //内容
- Summary = "您的商户刷卡交易费率正在审核中!",
- CreateDate = DateTime.Now,
- }));
- }
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- 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
- }
- }
|