MerchantParamSetController.cs 9.6 KB

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