MerchantParamSetController.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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.Models.Main;
  11. using LitJson;
  12. using Library;
  13. using MySystem.Service.Main;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/[controller]/[action]")]
  18. public class MerchantParamSetController : BaseController
  19. {
  20. public MerchantParamSetController(IHttpContextAccessor accessor) : base(accessor)
  21. {
  22. }
  23. #region 商户-商户活动参数
  24. // [Authorize]
  25. public JsonResult Detail(string value)
  26. {
  27. value = DesDecrypt(value);
  28. value = value.Replace("null", "\"\"");
  29. JsonData data = JsonMapper.ToObject(value);
  30. Dictionary<string, object> Obj = DetailDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  32. }
  33. public Dictionary<string, object> DetailDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. Dictionary<string, object> Obj = new Dictionary<string, object>();
  37. int Id = int.Parse(function.CheckInt(data.getItem("Id").ToString()));
  38. MerchantParamSet query = MerchantParamSetDbconn.Instance.Get(Id);
  39. if (query == null)
  40. {
  41. query = new MerchantParamSet();
  42. query.IsAll = 1;
  43. }
  44. Obj.Add("IsAll", query.IsAll); //是否收全额
  45. Obj.Add("MinPayMoney", query.MinPayMoney); //订单参与门槛
  46. Obj.Add("GetPercent", query.GetPercent); //商家实收比例
  47. Obj.Add("ProfitDays", query.ProfitDays); //分红期限(天)
  48. Obj.Add("DiviPercent", query.DiviPercent); //最大分红比例
  49. Obj.Add("DiviPersons", query.DiviPersons); //单笔订单分红人数
  50. return Obj;
  51. }
  52. #endregion
  53. #region 商户-活动配置
  54. // [Authorize]
  55. public JsonResult Set(string value)
  56. {
  57. value = DesDecrypt(value);
  58. value = value.Replace("null", "\"\"");
  59. JsonData data = JsonMapper.ToObject(value);
  60. AppResultJson result = SetDo(value);
  61. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  62. }
  63. public AppResultJson SetDo(string value)
  64. {
  65. JsonData data = JsonMapper.ToObject(value);
  66. int IsAll = int.Parse(function.CheckInt(data.getItem("IsAll").ToString())); //是否收全额
  67. decimal MinPayMoney = decimal.Parse(function.CheckNum(data.getItem("MinPayMoney").ToString())); //订单参与门槛
  68. decimal GetPercent = decimal.Parse(function.CheckNum(data.getItem("GetPercent").ToString())); //商家实收比例
  69. int ProfitDays = int.Parse(function.CheckInt(data.getItem("ProfitDays").ToString())); //分红期限(天)
  70. decimal DiviPercent = decimal.Parse(function.CheckNum(data.getItem("DiviPercent").ToString())); //最大分红比例
  71. int DiviPersons = int.Parse(function.CheckInt(data.getItem("DiviPersons").ToString())); //单笔订单分红人数
  72. string MobileCode = data.getItem("MobileCode").ToString(); //短信验证码
  73. if (string.IsNullOrEmpty(data["IsAll"].ToString()))
  74. {
  75. return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" };
  76. }
  77. if (string.IsNullOrEmpty(data["MinPayMoney"].ToString()))
  78. {
  79. return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" };
  80. }
  81. if (string.IsNullOrEmpty(data["GetPercent"].ToString()))
  82. {
  83. return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" };
  84. }
  85. if (string.IsNullOrEmpty(data["ProfitDays"].ToString()))
  86. {
  87. return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" };
  88. }
  89. if (!function.IsInt(data["ProfitDays"].ToString()))
  90. {
  91. return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" };
  92. }
  93. if (string.IsNullOrEmpty(data["DiviPercent"].ToString()))
  94. {
  95. return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" };
  96. }
  97. if (string.IsNullOrEmpty(data["DiviPersons"].ToString()))
  98. {
  99. return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" };
  100. }
  101. if (!function.IsInt(data["DiviPersons"].ToString()))
  102. {
  103. return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" };
  104. }
  105. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  106. MerchantInfo merchant = maindb.MerchantInfo.FirstOrDefault(m => m.Id == Id);
  107. if (merchant.Id > 0 && merchant.IsAct == 0)
  108. {
  109. return new AppResultJson() { Status = "-1", Info = "商户尚未激活,不能开启活动配置活动参数" };
  110. }
  111. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + merchant.Mobile);
  112. if (mobilecheck == null)
  113. {
  114. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  115. }
  116. if (mobilecheck.CheckCode != MobileCode)
  117. {
  118. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  119. }
  120. RedisDbconn.Instance.Clear("MobileCodeCheck:" + merchant.Mobile);
  121. Dictionary<string, object> Obj = new Dictionary<string, object>();
  122. MerchantParamSet query = maindb.MerchantParamSet.FirstOrDefault(m => m.Id == Id);
  123. if (query == null)
  124. {
  125. query = maindb.MerchantParamSet.Add(new MerchantParamSet()
  126. {
  127. Id = Id,
  128. CreateDate = DateTime.Now,
  129. }).Entity;
  130. maindb.SaveChanges();
  131. }
  132. var merchantParamSetRecord = maindb.MerchantParamSetRecord.Add(new MerchantParamSetRecord()
  133. {
  134. // Status = status, //活动状态(1 使用中 -1 已失效 0 已关闭)
  135. CreateDate = DateTime.Now,
  136. MerchantId = Id,
  137. BeforeDiviPersons = query.DiviPersons,
  138. BeforeDiviPercent = query.DiviPercent,
  139. BeforeProfitDays = query.ProfitDays,
  140. BeforeGetPercent = query.GetPercent,
  141. BeforeMinPayMoney = query.MinPayMoney,
  142. BeforeIsAll = query.IsAll,
  143. AfterDiviPersons = DiviPersons,
  144. AfterDiviPercent = DiviPercent,
  145. AfterProfitDays = ProfitDays,
  146. AfterGetPercent = GetPercent,
  147. AfterMinPayMoney = MinPayMoney,
  148. AfterIsAll = IsAll,
  149. }).Entity;
  150. maindb.SaveChanges();
  151. query.UpdateDate = DateTime.Now; //修改时间
  152. query.IsAll = IsAll; //是否收全额
  153. query.MinPayMoney = MinPayMoney; //订单参与门槛
  154. query.GetPercent = GetPercent; //商家实收比例
  155. query.ProfitDays = ProfitDays; //分红期限(天)
  156. query.DiviPercent = DiviPercent; //最大分红比例
  157. query.DiviPersons = DiviPersons; //单笔订单分红人数
  158. query.Version = merchantParamSetRecord.Id;
  159. maindb.SaveChanges();
  160. Obj.Add("UpdateDate", query.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //更新时间
  161. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  162. }
  163. #endregion
  164. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  165. /// <summary>
  166. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  167. /// </summary>
  168. /// <param name="value">请求的参数(json字符串)</param>
  169. /// <param name="signField">要签名的字段</param>
  170. /// <returns></returns>
  171. private string CheckSign(string value, string[] signField)
  172. {
  173. JsonData json = JsonMapper.ToObject(value);
  174. Dictionary<string, string> dic = new Dictionary<string, string>();
  175. for (int i = 0; i < signField.Length; i++)
  176. {
  177. dic.Add(signField[i], json[signField[i]].ToString());
  178. }
  179. string sign = json["sign"].ToString(); //客户端签名字符串
  180. return new Sign().sign(dic, sign);
  181. }
  182. #endregion
  183. }
  184. }