MerchantParamSetController.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class MerchantParamSetController : BaseController
  18. {
  19. public MerchantParamSetController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 商户-商户活动参数
  23. [Authorize]
  24. public JsonResult Detail(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. Dictionary<string, object> Obj = DetailDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  30. }
  31. public Dictionary<string, object> DetailDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. Dictionary<string, object> Obj = new Dictionary<string, object>();
  35. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  36. MerchantParamSet query = MerchantParamSetDbconn.Instance.Get(Id);
  37. if (query == null)
  38. {
  39. query = new MerchantParamSet();
  40. query.IsAll = 1;
  41. }
  42. Obj.Add("IsAll", query.IsAll); //是否收全额
  43. Obj.Add("MinPayMoney", query.MinPayMoney); //订单参与门槛
  44. Obj.Add("GetPercent", query.GetPercent); //商家实收比例
  45. Obj.Add("ProfitDays", query.ProfitDays); //分红期限(天)
  46. Obj.Add("DiviPercent", query.DiviPercent); //最大分红比例
  47. Obj.Add("DiviPersons", query.DiviPersons); //单笔订单分红人数
  48. return Obj;
  49. }
  50. #endregion
  51. #region 商户-活动配置
  52. [Authorize]
  53. public JsonResult Set(string value)
  54. {
  55. value = DesDecrypt(value);
  56. JsonData data = JsonMapper.ToObject(value);
  57. AppResultJson result = SetDo(value);
  58. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  59. }
  60. public AppResultJson SetDo(string value)
  61. {
  62. JsonData data = JsonMapper.ToObject(value);
  63. int IsAll = int.Parse(function.CheckInt(data["IsAll"].ToString())); //是否收全额
  64. decimal MinPayMoney = decimal.Parse(function.CheckNum(data["MinPayMoney"].ToString())); //订单参与门槛
  65. decimal GetPercent = decimal.Parse(function.CheckNum(data["GetPercent"].ToString())); //商家实收比例
  66. int ProfitDays = int.Parse(function.CheckInt(data["ProfitDays"].ToString())); //分红期限(天)
  67. decimal DiviPercent = decimal.Parse(function.CheckNum(data["DiviPercent"].ToString())); //最大分红比例
  68. int DiviPersons = int.Parse(function.CheckInt(data["DiviPersons"].ToString())); //单笔订单分红人数
  69. if (string.IsNullOrEmpty(data["IsAll"].ToString()))
  70. {
  71. return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" };
  72. }
  73. if (string.IsNullOrEmpty(data["MinPayMoney"].ToString()))
  74. {
  75. return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" };
  76. }
  77. if (string.IsNullOrEmpty(data["GetPercent"].ToString()))
  78. {
  79. return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" };
  80. }
  81. if (string.IsNullOrEmpty(data["ProfitDays"].ToString()))
  82. {
  83. return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" };
  84. }
  85. if (!function.IsInt(data["ProfitDays"].ToString()))
  86. {
  87. return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" };
  88. }
  89. if (string.IsNullOrEmpty(data["DiviPercent"].ToString()))
  90. {
  91. return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" };
  92. }
  93. if (string.IsNullOrEmpty(data["DiviPersons"].ToString()))
  94. {
  95. return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" };
  96. }
  97. if (!function.IsInt(data["DiviPersons"].ToString()))
  98. {
  99. return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" };
  100. }
  101. Dictionary<string, object> Obj = new Dictionary<string, object>();
  102. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  103. MerchantParamSet query = maindb.MerchantParamSet.FirstOrDefault(m => m.Id == Id);
  104. if(query == null)
  105. {
  106. query = maindb.MerchantParamSet.Add(new MerchantParamSet()
  107. {
  108. Id = Id,
  109. CreateDate = DateTime.Now,
  110. }).Entity;
  111. maindb.SaveChanges();
  112. }
  113. query.UpdateDate = DateTime.Now; //修改时间
  114. query.IsAll = IsAll; //是否收全额
  115. query.MinPayMoney = MinPayMoney; //订单参与门槛
  116. query.GetPercent = GetPercent; //商家实收比例
  117. query.ProfitDays = ProfitDays; //分红期限(天)
  118. query.DiviPercent = DiviPercent; //最大分红比例
  119. query.DiviPersons = DiviPersons; //单笔订单分红人数
  120. maindb.SaveChanges();
  121. Obj.Add("UpdateDate", query.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //更新时间
  122. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  123. }
  124. #endregion
  125. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  126. /// <summary>
  127. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  128. /// </summary>
  129. /// <param name="value">请求的参数(json字符串)</param>
  130. /// <param name="signField">要签名的字段</param>
  131. /// <returns></returns>
  132. private string CheckSign(string value, string[] signField)
  133. {
  134. JsonData json = JsonMapper.ToObject(value);
  135. Dictionary<string, string> dic = new Dictionary<string, string>();
  136. for (int i = 0; i < signField.Length; i++)
  137. {
  138. dic.Add(signField[i], json[signField[i]].ToString());
  139. }
  140. string sign = json["sign"].ToString(); //客户端签名字符串
  141. return new Sign().sign(dic, sign);
  142. }
  143. #endregion
  144. }
  145. }