OutApiController.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.Extensions.Logging;
  4. using Microsoft.Extensions.Options;
  5. using System.Collections.Generic;
  6. using LitJson;
  7. using Library;
  8. using System.Linq;
  9. using System;
  10. using MySystem.MainModels;
  11. using System.IO;
  12. namespace MySystem.Areas.Api.Controllers.v1
  13. {
  14. public class OutApiController : BaseController
  15. {
  16. public OutApiController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  17. {
  18. }
  19. #region 设置服务费
  20. [Route("/api/v1/deposit/set")]
  21. public JsonResult SetDeposit()
  22. {
  23. StreamReader sr = new StreamReader(Request.Body);
  24. string requestMes = sr.ReadToEnd();
  25. JsonData data = JsonMapper.ToObject(requestMes);
  26. Dictionary<string, object> req = new Dictionary<string, object>();
  27. string PosSn = data["posSn"].ToString();
  28. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  29. if(pos == null)
  30. {
  31. return Json(new AppResultJson() { Status = "-1", Info = "机具号不正确" });
  32. }
  33. req.Add("PosSnId", pos.Id);
  34. req.Add("BrandId", data["brandId"].ToString());
  35. req.Add("Deposit", data["deposit"].ToString());
  36. string CallBackUrl = "";
  37. if(requestMes.Contains("\"callBackUrl\""))
  38. {
  39. CallBackUrl = data["callBackUrl"].ToString();
  40. }
  41. req.Add("CallBackUrl", CallBackUrl);
  42. RedisDbconn.Instance.AddList("ChangePosFeeQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  43. return Json(new AppResultJson() { Status = "1", Info = "" });
  44. }
  45. #endregion
  46. #region 设置费率
  47. [Route("/api/v1/fee/set")]
  48. public JsonResult SetFee()
  49. {
  50. StreamReader sr = new StreamReader(Request.Body);
  51. string requestMes = sr.ReadToEnd();
  52. JsonData data = JsonMapper.ToObject(requestMes);
  53. string PosSn = data["posSn"].ToString();
  54. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  55. if(pos == null)
  56. {
  57. return Json(new AppResultJson() { Status = "-1", Info = "机具号不正确" });
  58. }
  59. int PosId = pos.Id;
  60. int BrandId = int.Parse(data["brandId"].ToString());
  61. decimal FeeRate = decimal.Parse(data["feeRate"].ToString());
  62. int FeeExtra = int.Parse(data["feeExtra"].ToString());
  63. string CallBackUrl = "";
  64. if(requestMes.Contains("\"callBackUrl\""))
  65. {
  66. CallBackUrl = data["callBackUrl"].ToString();
  67. }
  68. PosMerchantInfo mer = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == PosId) ?? new PosMerchantInfo();
  69. PosMachinesFeeChangeRecord query = maindb.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == PosId && m.Status == 0);
  70. if(query == null)
  71. {
  72. query = maindb.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  73. {
  74. CreateDate = DateTime.Now, //创建时间
  75. PosId = PosId, //机具Id
  76. }).Entity;
  77. maindb.SaveChanges();
  78. }
  79. query.UpdateDate = DateTime.Now; //创建时间
  80. query.Sort = pos.BrandId; //品牌Id
  81. query.UserId = pos.BuyUserId; //创客
  82. query.PosId = PosId; //机具Id
  83. query.PosSn = pos.PosSn;
  84. query.MerNo = mer.MerchantNo;
  85. query.MerchantId = mer.Id;
  86. query.PosUserId = pos.BuyUserId; //机具所属人
  87. query.ChangeFee = FeeRate; //调整费率
  88. maindb.SaveChanges();
  89. int ChangeKind = 0;
  90. if(FeeRate == 0.63M && FeeExtra == 3)
  91. {
  92. ChangeKind = 1;
  93. }
  94. else if(FeeRate == 0.63M && FeeExtra == 0)
  95. {
  96. ChangeKind = 2;
  97. }
  98. else if(FeeRate == 0.6M && FeeExtra == 0)
  99. {
  100. ChangeKind = 3;
  101. }
  102. // PosId:机具Id
  103. // Kind:1或2,1为费率0.63+3,2为费率0.63,3为费率0.6
  104. // OpMan:操作人,app传创客编号,后台传SysUserName
  105. string info = "{\"RecordId\":\"" + query.Id + "\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"" + FeeRate.ToString("f0").TrimEnd('0') + "\",\"Kind\": \"" + ChangeKind + "\",\"OpMan\": \"接口\",\"CallBackUrl\":\"" + CallBackUrl + "\"}";
  106. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  107. return Json(new AppResultJson() { Status = "1", Info = "" });
  108. }
  109. #endregion
  110. [Route("/api/v1/{c1}/{c2}")]
  111. public JsonResult ToApServer(string c1, string c2)
  112. {
  113. StreamReader sr = new StreamReader(Request.Body);
  114. string requestMes = sr.ReadToEnd();
  115. string url = AppConfig.Base.ApHost + "api/v1/" + c1 + "/" + c2 + "do";
  116. string result = function.PostWebRequest(url, "value=" + requestMes);
  117. return Json(new AppResultJson() { Status = "1", Data = result });
  118. }
  119. }
  120. }