OutApiController.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. req.Add("CallBackUrl", data["callBackUrl"].ToString());
  37. RedisDbconn.Instance.AddList("ChangePosFeeQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  38. return Json(new AppResultJson() { Status = "1", Info = "" });
  39. }
  40. #endregion
  41. #region 设置费率
  42. [Route("/api/v1/fee/set")]
  43. public JsonResult SetFee()
  44. {
  45. StreamReader sr = new StreamReader(Request.Body);
  46. string requestMes = sr.ReadToEnd();
  47. JsonData data = JsonMapper.ToObject(requestMes);
  48. string PosSn = data["posSn"].ToString();
  49. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  50. if(pos == null)
  51. {
  52. return Json(new AppResultJson() { Status = "-1", Info = "机具号不正确" });
  53. }
  54. int PosId = pos.Id;
  55. int BrandId = int.Parse(data["brandId"].ToString());
  56. decimal FeeRate = decimal.Parse(data["feeRate"].ToString());
  57. int FeeExtra = int.Parse(data["feeExtra"].ToString());
  58. string CallBackUrl = data["callBackUrl"].ToString();
  59. PosMerchantInfo mer = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == PosId) ?? new PosMerchantInfo();
  60. PosMachinesFeeChangeRecord query = maindb.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == PosId && m.Status == 0);
  61. if(query == null)
  62. {
  63. query = maindb.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  64. {
  65. CreateDate = DateTime.Now, //创建时间
  66. PosId = PosId, //机具Id
  67. }).Entity;
  68. maindb.SaveChanges();
  69. }
  70. query.UpdateDate = DateTime.Now; //创建时间
  71. query.Sort = pos.BrandId; //品牌Id
  72. query.UserId = pos.BuyUserId; //创客
  73. query.PosId = PosId; //机具Id
  74. query.PosSn = pos.PosSn;
  75. query.MerNo = mer.MerchantNo;
  76. query.MerchantId = mer.Id;
  77. query.PosUserId = pos.BuyUserId; //机具所属人
  78. query.ChangeFee = FeeRate; //调整费率
  79. maindb.SaveChanges();
  80. int ChangeKind = 0;
  81. if(FeeRate == 0.63M && FeeExtra == 3)
  82. {
  83. ChangeKind = 1;
  84. }
  85. else if(FeeRate == 0.63M && FeeExtra == 0)
  86. {
  87. ChangeKind = 2;
  88. }
  89. else if(FeeRate == 0.6M && FeeExtra == 0)
  90. {
  91. ChangeKind = 3;
  92. }
  93. // PosId:机具Id
  94. // Kind:1或2,1为费率0.63+3,2为费率0.63,3为费率0.6
  95. // OpMan:操作人,app传创客编号,后台传SysUserName
  96. string info = "{\"RecordId\":\"" + query.Id + "\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"" + FeeRate.ToString("f0").TrimEnd('0') + "\",\"Kind\": \"" + ChangeKind + "\",\"OpMan\": \"接口\",\"CallBackUrl\":\"" + CallBackUrl + "\"}";
  97. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  98. return Json(new AppResultJson() { Status = "1", Info = "" });
  99. }
  100. #endregion
  101. }
  102. }