public ApiResult <RewardRuleOutput> Save([FromBody] RewardRuleOutput model) { if (!this.IsFormValid()) { return(ApiResult.Failure <RewardRuleOutput>(this.FormInvalidReason())); } model.UserId = AutoModel.UserId; var result = Resolve <IRewardRuleAdminService>().Save(model); return(ToResult <RewardRuleOutput>(result)); }
public Tuple <ServiceResult, RewardRuleOutput> GetEditView(Guid moduleId, ObjectId id) { #region 安全验证 var taskModuleAttribute = Resolve <ITaskQueueService>().GetTaskModuleAttribute(moduleId); if (taskModuleAttribute == null) { return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.FailedWithMessage("类型不存在,请确定Id是否输入正确"), null)); } #endregion 安全验证 var view = new RewardRuleOutput { AutoForm = AutoFormMapping.Convert(taskModuleAttribute.ConfigurationType.FullName), Base = new RewardEditOutputBase { Name = taskModuleAttribute.Name, Title = taskModuleAttribute.Name, Intro = taskModuleAttribute.Intro, Summary = $"{taskModuleAttribute.Name}的简要说明" }, ModuleId = moduleId }; IList <AssetsRule> ruleItems = new List <AssetsRule>(); var rule = new AssetsRule { MoneyTypeId = Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid(), Ratio = 0.8m }; ruleItems.Add(rule); var moneyType = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>().FirstOrDefault(r => r.Id != Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid() && r.Status == Status.Normal); rule = new AssetsRule { MoneyTypeId = moneyType.Id, Ratio = 0.2m }; ruleItems.Add(rule); view.RuleItems = ruleItems; return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.Success, view)); }
/// <summary> /// 保存 /// </summary> /// <param name="view"></param> /// <returns></returns> public ServiceResult Save(RewardRuleOutput view) { var moduleAttribute = Resolve <IRuleModuleService>().GetRuleAttribute(view.ModuleId); if (moduleAttribute == null) { return(ServiceResult.Failure("模块不存在")); } #region 登录用户验证 var loginUser = Resolve <IUserService>().GetUserDetail(view.UserId); if (loginUser == null) { return(ServiceResult.Failure("用户不存在")); } if (!Resolve <IUserService>().IsAdmin(loginUser.Id)) { return(ServiceResult.Failure("您不是管理员无权操作")); } if (loginUser.Status != Status.Normal) { return(ServiceResult.Failure("您的账户不正常,不能进行资产操作")); } if (view.PayPassword.ToMd5HashString() != loginUser.Detail.PayPassword) { // return ServiceResult.Failure("支付密码不正确"); } #endregion 登录用户验证 #region 资产范围验证 if (view.AssetsRules == null) { return(ServiceResult.Failure("资产分配比例必须设置,请在资产分配中设置.")); } foreach (var rule in view.AssetsRules) { if (rule.MoneyTypeId.IsGuidNullOrEmpty()) { return(ServiceResult.Failure("货币类型不能为空")); } } if (view.AssetsRules.Sum(e => e.Ratio) != 1) { return(ServiceResult.Failure("资产分配比例总和不等于1,请在资产分配中设置分润比例.")); } if (view.Base == null) { return(ServiceResult.Failure("基础设置不能为空")); } if (view.Base.TemplateRule == null) { return(ServiceResult.Failure("模板设置不能为空")); } if (view.UserRang == null) { return(ServiceResult.Failure("用户范围不能为空")); } #endregion 资产范围验证 if (view.Value.IsNotNullOrEmpty()) { var type = Resolve <IRuleModuleService>().GetRuleType(view.ModuleId); // 转换为模块配置,保证数据的准确性 var moduleConfig = view.Value.ToObject(type); view.Value = moduleConfig.ToJsons(); } var find = GetSingle(r => r.Id == view.Id); if (find == null) { find = view.MapTo <RewardRule>(); find.UpdateTime = DateTime.Now; if (!Add(find)) { return(ServiceResult.Failure("添加失败")); } } else { find = view.MapTo <RewardRule>(); find.UpdateTime = DateTime.Now; if (!Update(find)) { return(ServiceResult.Failure("编辑失败")); } } return(ServiceResult.Success); }
/// <summary> /// 获取视图 /// </summary> /// <param name="moduleId"></param> /// <param name="id"></param> /// <returns></returns> public Tuple <ServiceResult, RewardRuleOutput> GetEditView(Guid moduleId, ObjectId id) { #region 安全验证 RewardRule find = null; if (!id.IsObjectIdNullOrEmpty()) { find = Resolve <IRewardRuleAdminService>().GetSingle(id); moduleId = find.ModuleId; } if (!id.IsObjectIdNullOrEmpty()) { } var taskModuleAttribute = Resolve <IRuleModuleService>().GetRuleAttribute(moduleId); if (taskModuleAttribute == null) { return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.Failure("类型不存在,请确定Id是否输入正确"), null)); } #endregion 安全验证 var view = new RewardRuleOutput { ModuleConfig = new RewardRuleOutputModuleConfig { Title = taskModuleAttribute.Name, Intro = taskModuleAttribute.Intro, } }; if (find == null) { // 添加视图 view.Base = new RewardRuleBase { Name = taskModuleAttribute.Name, Summary = $"{taskModuleAttribute.Name}的简要说明" }; // 配置资产 IList <RewardRuleAssetsRule> ruleItems = new List <RewardRuleAssetsRule>(); var rule = new RewardRuleAssetsRule { MoneyTypeId = Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid(), Ratio = 0.8m }; ruleItems.Add(rule); var moneyType = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>().FirstOrDefault(r => r.Id != Currency.Cny.GetCustomAttr <FieldAttribute>().GuidId.ToGuid() && r.Status == Status.Normal); rule = new RewardRuleAssetsRule { MoneyTypeId = moneyType.Id, Ratio = 0.2m }; ruleItems.Add(rule); view.AssetsRules = ruleItems; } else { // 编辑视图 view = find.MapTo <RewardRuleOutput>(); } view.ModuleId = moduleId; object moduleConfig = Resolve <IRuleModuleService>().GetConfigValue(moduleId, view.Value); view.AutoForm = AutoFormMapping.Convert(moduleConfig); view.Value = string.Empty; return(new Tuple <ServiceResult, RewardRuleOutput>(ServiceResult.Success, view)); }
public ServiceResult Save(RewardRuleOutput rewardRuleOutput) { throw new NotImplementedException(); }