MerchantParamSetController.cs 9.0 KB

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