MerchantParamSetController.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. if (merchant.Id > 0 && merchant.IsAct == 0)
  105. {
  106. return new AppResultJson() { Status = "-1", Info = "商户尚未激活,不能开启活动配置活动参数" };
  107. }
  108. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + merchant.Mobile);
  109. if (mobilecheck == null)
  110. {
  111. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  112. }
  113. if (mobilecheck.CheckCode != MobileCode)
  114. {
  115. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  116. }
  117. RedisDbconn.Instance.Clear("MobileCodeCheck:" + merchant.Mobile);
  118. Dictionary<string, object> Obj = new Dictionary<string, object>();
  119. MerchantParamSet query = maindb.MerchantParamSet.FirstOrDefault(m => m.Id == Id);
  120. if (query == null)
  121. {
  122. query = maindb.MerchantParamSet.Add(new MerchantParamSet()
  123. {
  124. Id = Id,
  125. CreateDate = DateTime.Now,
  126. }).Entity;
  127. maindb.SaveChanges();
  128. }
  129. var merchantParamSetRecord = maindb.MerchantParamSetRecord.Add(new MerchantParamSetRecord()
  130. {
  131. // Status = status, //活动状态(1 使用中 -1 已失效 0 已关闭)
  132. CreateDate = DateTime.Now,
  133. MerchantId = Id,
  134. BeforeDiviPersons = query.DiviPersons,
  135. BeforeDiviPercent = query.DiviPercent,
  136. BeforeProfitDays = query.ProfitDays,
  137. BeforeGetPercent = query.GetPercent,
  138. BeforeMinPayMoney = query.MinPayMoney,
  139. BeforeIsAll = query.IsAll,
  140. AfterDiviPersons = DiviPersons,
  141. AfterDiviPercent = DiviPercent,
  142. AfterProfitDays = ProfitDays,
  143. AfterGetPercent = GetPercent,
  144. AfterMinPayMoney = MinPayMoney,
  145. AfterIsAll = IsAll,
  146. }).Entity;
  147. maindb.SaveChanges();
  148. query.UpdateDate = DateTime.Now; //修改时间
  149. query.IsAll = IsAll; //是否收全额
  150. query.MinPayMoney = MinPayMoney; //订单参与门槛
  151. query.GetPercent = GetPercent; //商家实收比例
  152. query.ProfitDays = ProfitDays; //分红期限(天)
  153. query.DiviPercent = DiviPercent; //最大分红比例
  154. query.DiviPersons = DiviPersons; //单笔订单分红人数
  155. query.Version = merchantParamSetRecord.Id;
  156. maindb.SaveChanges();
  157. Obj.Add("UpdateDate", query.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //更新时间
  158. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  159. }
  160. #endregion
  161. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  162. /// <summary>
  163. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  164. /// </summary>
  165. /// <param name="value">请求的参数(json字符串)</param>
  166. /// <param name="signField">要签名的字段</param>
  167. /// <returns></returns>
  168. private string CheckSign(string value, string[] signField)
  169. {
  170. JsonData json = JsonMapper.ToObject(value);
  171. Dictionary<string, string> dic = new Dictionary<string, string>();
  172. for (int i = 0; i < signField.Length; i++)
  173. {
  174. dic.Add(signField[i], json[signField[i]].ToString());
  175. }
  176. string sign = json["sign"].ToString(); //客户端签名字符串
  177. return new Sign().sign(dic, sign);
  178. }
  179. #endregion
  180. }
  181. }