OutApiController.cs 4.2 KB

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