MerchantParamSetController.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  70. if (string.IsNullOrEmpty(data["IsAll"].ToString()))
  71. {
  72. return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" };
  73. }
  74. if (string.IsNullOrEmpty(data["MinPayMoney"].ToString()))
  75. {
  76. return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" };
  77. }
  78. if (string.IsNullOrEmpty(data["GetPercent"].ToString()))
  79. {
  80. return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" };
  81. }
  82. if (string.IsNullOrEmpty(data["ProfitDays"].ToString()))
  83. {
  84. return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" };
  85. }
  86. if (!function.IsInt(data["ProfitDays"].ToString()))
  87. {
  88. return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" };
  89. }
  90. if (string.IsNullOrEmpty(data["DiviPercent"].ToString()))
  91. {
  92. return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" };
  93. }
  94. if (string.IsNullOrEmpty(data["DiviPersons"].ToString()))
  95. {
  96. return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" };
  97. }
  98. if (!function.IsInt(data["DiviPersons"].ToString()))
  99. {
  100. return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" };
  101. }
  102. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  103. MerchantInfo merchant = maindb.MerchantInfo.FirstOrDefault(m => m.Id == Id);
  104. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + merchant.Mobile);
  105. if (mobilecheck == null)
  106. {
  107. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  108. }
  109. if (mobilecheck.CheckCode != MobileCode)
  110. {
  111. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  112. }
  113. RedisDbconn.Instance.Clear("MobileCodeCheck:" + merchant.Mobile);
  114. Dictionary<string, object> Obj = new Dictionary<string, object>();
  115. MerchantParamSet query = maindb.MerchantParamSet.FirstOrDefault(m => m.Id == Id);
  116. if(query == null)
  117. {
  118. query = maindb.MerchantParamSet.Add(new MerchantParamSet()
  119. {
  120. Id = Id,
  121. CreateDate = DateTime.Now,
  122. }).Entity;
  123. maindb.SaveChanges();
  124. }
  125. query.UpdateDate = DateTime.Now; //修改时间
  126. query.IsAll = IsAll; //是否收全额
  127. query.MinPayMoney = MinPayMoney; //订单参与门槛
  128. query.GetPercent = GetPercent; //商家实收比例
  129. query.ProfitDays = ProfitDays; //分红期限(天)
  130. query.DiviPercent = DiviPercent; //最大分红比例
  131. query.DiviPersons = DiviPersons; //单笔订单分红人数
  132. maindb.SaveChanges();
  133. Obj.Add("UpdateDate", query.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //更新时间
  134. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  135. }
  136. #endregion
  137. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  138. /// <summary>
  139. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  140. /// </summary>
  141. /// <param name="value">请求的参数(json字符串)</param>
  142. /// <param name="signField">要签名的字段</param>
  143. /// <returns></returns>
  144. private string CheckSign(string value, string[] signField)
  145. {
  146. JsonData json = JsonMapper.ToObject(value);
  147. Dictionary<string, string> dic = new Dictionary<string, string>();
  148. for (int i = 0; i < signField.Length; i++)
  149. {
  150. dic.Add(signField[i], json[signField[i]].ToString());
  151. }
  152. string sign = json["sign"].ToString(); //客户端签名字符串
  153. return new Sign().sign(dic, sign);
  154. }
  155. #endregion
  156. }
  157. }