using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; namespace MySystem.Areas.Api.Controllers.v1 { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class MerchantParamSetController : BaseController { public MerchantParamSetController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 商户-商户活动参数 [Authorize] public JsonResult Detail(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); Dictionary Obj = DetailDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj }); } public Dictionary DetailDo(string value) { JsonData data = JsonMapper.ToObject(value); Dictionary Obj = new Dictionary(); int Id = int.Parse(function.CheckInt(data["Id"].ToString())); MerchantParamSet query = MerchantParamSetDbconn.Instance.Get(Id); if (query == null) { query = new MerchantParamSet(); query.IsAll = 1; } Obj.Add("IsAll", query.IsAll); //是否收全额 Obj.Add("MinPayMoney", query.MinPayMoney); //订单参与门槛 Obj.Add("GetPercent", query.GetPercent); //商家实收比例 Obj.Add("ProfitDays", query.ProfitDays); //分红期限(天) Obj.Add("DiviPercent", query.DiviPercent); //最大分红比例 Obj.Add("DiviPersons", query.DiviPersons); //单笔订单分红人数 return Obj; } #endregion #region 商户-活动配置 [Authorize] public JsonResult Set(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = SetDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson SetDo(string value) { JsonData data = JsonMapper.ToObject(value); int IsAll = int.Parse(function.CheckInt(data["IsAll"].ToString())); //是否收全额 decimal MinPayMoney = decimal.Parse(function.CheckNum(data["MinPayMoney"].ToString())); //订单参与门槛 decimal GetPercent = decimal.Parse(function.CheckNum(data["GetPercent"].ToString())); //商家实收比例 int ProfitDays = int.Parse(function.CheckInt(data["ProfitDays"].ToString())); //分红期限(天) decimal DiviPercent = decimal.Parse(function.CheckNum(data["DiviPercent"].ToString())); //最大分红比例 int DiviPersons = int.Parse(function.CheckInt(data["DiviPersons"].ToString())); //单笔订单分红人数 string MobileCode = data["MobileCode"].ToString(); //短信验证码 if (string.IsNullOrEmpty(data["IsAll"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" }; } if (string.IsNullOrEmpty(data["MinPayMoney"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" }; } if (string.IsNullOrEmpty(data["GetPercent"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" }; } if (string.IsNullOrEmpty(data["ProfitDays"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" }; } if (!function.IsInt(data["ProfitDays"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" }; } if (string.IsNullOrEmpty(data["DiviPercent"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" }; } if (string.IsNullOrEmpty(data["DiviPersons"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" }; } if (!function.IsInt(data["DiviPersons"].ToString())) { return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" }; } int Id = int.Parse(function.CheckInt(data["Id"].ToString())); MerchantInfo merchant = maindb.MerchantInfo.FirstOrDefault(m => m.Id == Id); if (merchant.Id > 0 && merchant.IsAct == 0) { return new AppResultJson() { Status = "-1", Info = "商户尚未激活,不能开启活动配置活动参数" }; } MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get("MobileCodeCheck:" + merchant.Mobile); if (mobilecheck == null) { return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" }; } if (mobilecheck.CheckCode != MobileCode) { return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" }; } RedisDbconn.Instance.Clear("MobileCodeCheck:" + merchant.Mobile); Dictionary Obj = new Dictionary(); MerchantParamSet query = maindb.MerchantParamSet.FirstOrDefault(m => m.Id == Id); if (query == null) { query = maindb.MerchantParamSet.Add(new MerchantParamSet() { Id = Id, CreateDate = DateTime.Now, }).Entity; maindb.SaveChanges(); } var merchantParamSetRecord = maindb.MerchantParamSetRecord.Add(new MerchantParamSetRecord() { // Status = status, //活动状态(1 使用中 -1 已失效 0 已关闭) CreateDate = DateTime.Now, MerchantId = Id, BeforeDiviPersons = query.DiviPersons, BeforeDiviPercent = query.DiviPercent, BeforeProfitDays = query.ProfitDays, BeforeGetPercent = query.GetPercent, BeforeMinPayMoney = query.MinPayMoney, BeforeIsAll = query.IsAll, AfterDiviPersons = DiviPersons, AfterDiviPercent = DiviPercent, AfterProfitDays = ProfitDays, AfterGetPercent = GetPercent, AfterMinPayMoney = MinPayMoney, AfterIsAll = IsAll, }).Entity; maindb.SaveChanges(); query.UpdateDate = DateTime.Now; //修改时间 query.IsAll = IsAll; //是否收全额 query.MinPayMoney = MinPayMoney; //订单参与门槛 query.GetPercent = GetPercent; //商家实收比例 query.ProfitDays = ProfitDays; //分红期限(天) query.DiviPercent = DiviPercent; //最大分红比例 query.DiviPersons = DiviPersons; //单笔订单分红人数 query.Version = merchantParamSetRecord.Id; maindb.SaveChanges(); Obj.Add("UpdateDate", query.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //更新时间 return new AppResultJson() { Status = "1", Info = "", Data = Obj }; } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }