/// <summary> /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var userMap = Service <IUserMapService>().GetParentMapFromCache(ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } IList <ITaskResult> resultList = new List <ITaskResult>(); // 获取最大极差比例 //分期 return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
public ExecuteResult Update() { try { if (_taskActuator == null) { return(ExecuteResult.Cancel("task actuator is null.")); } if (_taskManager == null) { return(ExecuteResult.Cancel("task manager is null.")); } if (ModuleId == Guid.Empty) { return(ExecuteResult.Cancel("module is is empty, return.")); } if (!_taskManager.ContainsModuleId(ModuleId)) { return(ExecuteResult.Fail($"module with id {ModuleId} not found.")); } // 注释可能出现出错 // _taskActuator.ExecuteTaskAndUpdateResults(ModuleId, Parameter); return(ExecuteResult.Success()); } catch (Exception e) { return(ExecuteResult.Error(e)); } }
public ExecuteResult Update() { try { if (typeof(T) == typeof(TaskQueueParameter)) { if (QueueId < 1) { return(ExecuteResult.Cancel("QueueId is empty.")); } Ioc.Resolve <ITaskQueueService>().Handle(QueueId); return(ExecuteResult.Success()); } if (Parameter == null) { return(ExecuteResult.Cancel("parameter is null.")); } Ioc.Resolve <ITaskQueueService>() .Add(UserId, ModuleId, Type, ExecutionTime, MaxExecutionTimes, Parameter); return(ExecuteResult.Success()); } catch (Exception e) { return(ExecuteResult.Error(e)); } }
/// <summary> /// 检查分润订单用户的类型与等级,检查分润用户 /// </summary> public virtual ExecuteResult <ITaskResult[]> CheckOrderUserTypeAndGrade() { //检查分润订单用户类型 if (Configuration.OrderUser.IsLimitOrderUserType) { if (!Configuration.OrderUser.OrderUserTypeId.IsGuidNullOrEmpty()) { if (Configuration.OrderUser.OrderUserTypeId == Guid.Parse("71BE65E6-3A64-414D-972E-1A3D4A365000")) //如果是会员,检查会员等级 { if (Configuration.OrderUser.IsLimitOrderUserGrade) { if (Configuration.OrderUser.OrderUserGradeId != ShareOrderUser.GradeId) { return(ExecuteResult <ITaskResult[]> .Cancel( $"user with id {ShareOrder.UserId} not match UserGradeid:{Configuration.OrderUser.OrderUserTypeId}, exit module")); //会员等级不符合grade要求,直接退出 } } } } else { return(ExecuteResult <ITaskResult[]> .Cancel("OrderUserTypeId is null")); //userTypeId 为空 } } return(ExecuteResult <ITaskResult[]> .Success()); }
/// <summary> /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var userMap = Resolve <IUserMapService>().GetParentMapFromCache(ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } IList <ITaskResult> resultList = new List <ITaskResult>(); // 获取最大极差比例 var maxRate = Configuration.TeamRangeRateItems.Max(r => r.MaxRate); for (var i = 0; i < TeamLevel; i++) { if (map.Count < i + 1) { break; } var item = map[i]; base.GetShareUser(item.UserId, out var shareUser); //从基类获取分润用户 var shareGrade = Resolve <IGradeService>().GetGrade(shareUser.GradeId); if (shareGrade == null) { continue; } var userRule = Configuration.TeamRangeRateItems.FirstOrDefault(r => r.GradeId == shareGrade.Id); if (userRule == null) { continue; } //当前分润用户最大极差 var shareUserRate = userRule.MaxRate; //剩余极差比例 var ratio = maxRate - shareUserRate; if (ratio <= 0) { continue; } var shareAmount = ratio * BaseFenRunAmount; // 极差分润 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); } //分期 return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
/// <summary> /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> /// <returns>ExecuteResult<ITaskResult[]>.</returns> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(baseResult); } IList <ITaskResult> resultList = new List <ITaskResult>(); // 开始计算自身返利 base.GetShareUser(ShareOrder.UserId, out var shareUser); //从基类获取分润用户 var ratio = Convert.ToDecimal(Ratios[0]); var shareAmount = BaseFenRunAmount * ratio; //分润金额 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); //构建分润参数 // 开始计算管理分红 var userMap = Resolve <IUserMapService>().GetParentMapFromCache(shareUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } for (var i = 0; i < map.Count; i++) { // 如果大于团队层数 if (i + 1 > Configuration.TeamLevel) { break; } var item = map[i]; GetShareUser(item.UserId, out shareUser); //从基类获取分润用户 if (shareUser == null) { continue; } // 每上一级50% var itemRatio = Math.Pow(Convert.ToDouble(Configuration.ManagerRatio), Convert.ToDouble(i + 1)) .ToDecimal() * ratio; if (itemRatio <= 0) { continue; } shareAmount = BaseFenRunAmount * itemRatio; //分润金额 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); //构建分润参数 } return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
/// <summary> /// 检查分润订单用户的类型与等级,检查分润用户 /// </summary> public virtual ExecuteResult <ITaskResult[]> CheckOrderUserTypeAndGrade() { //检查分润订单用户类型 if (Configuration.OrderUser.IsLimitOrderUserType) { if (!Configuration.OrderUser.OrderUserTypeId.IsGuidNullOrEmpty()) { if (Configuration.OrderUser.OrderUserTypeId == Guid.Parse("71BE65E6-3A64-414D-972E-1A3D4A365000")) { //如果是会员,检查会员等级 if (Configuration.OrderUser.IsLimitOrderUserGrade) { if (Configuration.OrderUser.OrderUserGradeId != ShareOrderUser.GradeId) { return(ExecuteResult <ITaskResult[]> .Cancel($"user with id {ShareOrder.UserId} not match UserGradeid:{Configuration.OrderUser.OrderUserTypeId}, exit module")); //会员等级不符合grade要求,直接退出 } } } else { ////检查用户类型 //var userType = Alabo.Helpers.Ioc.Resolve<IUserTypeService>().GetSingle(ShareOrderUser.Id, Configuration.OrderUser.OrderUserTypeId); //if (userType == null) { // return ExecuteResult<ITaskResult[]>.Cancel($"user with id {ShareOrder.UserId} has not userType:{Configuration.OrderUser.OrderUserTypeId}, exit module"); //该会员不存在该类型的用户类型 //} else { // //检查用户类型等级 // if (Configuration.OrderUser.IsLimitOrderUserGrade) { // if (Configuration.OrderUser.OrderUserGradeId != userType.GradeId) { // return ExecuteResult<ITaskResult[]>.Cancel($"userType with UserId {ShareOrder.UserId} not match UserTypeGradeid:{Configuration.OrderUser.OrderUserTypeId}, exit module"); //会员等级不符合grade要求,直接退出 // } // } //} } } else { return(ExecuteResult <ITaskResult[]> .Cancel($"OrderUserTypeId is null")); //userTypeId 为空 } } return(ExecuteResult <ITaskResult[]> .Success()); }
public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("基础验证未通过" + baseResult.Message)); } var userMap = Resolve <IUserMapService>().GetParentMapFromCache(base.ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var ww = Configuration.DistriRatio; IList <ITaskResult> resultList = new List <ITaskResult>(); for (var i = 0; i < Ratios.Count; i++) { if (map.Count < i + 1) { break; } var item = map[i]; base.GetShareUser(item.UserId, out var shareUser); //从基类获取分润用户 if (shareUser == null) { continue; } var ratio = Convert.ToDecimal(Ratios[i]); var shareAmount = BaseFenRunAmount * ratio; //分润金额 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); //构建分润参数 } return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
/// <summary> /// 检查分润会员,得到收益的会员 /// 可以在插入数据看的时候,检查 /// </summary> /// <param name="userId">会员Id</param> /// <param name="shareUser">The share 会员.</param> public virtual ExecuteResult <ITaskResult[]> GetShareUser(long userId, out User shareUser) { shareUser = null; var _shareUser = Ioc.Resolve <IUserService>().GetSingle(userId); if (_shareUser == null) { return(ExecuteResult <ITaskResult[]> .Cancel($"the shareuser is null.with userid {userId}")); } //检查分润会员的状态 if (_shareUser.Status != Status.Normal) { return(ExecuteResult <ITaskResult[]> .Fail($"the shareuser status is not normal .with userid {userId}")); } //检查分润订单用户类型 if (Configuration.ShareUser.IsLimitShareUserType) { if (!Configuration.ShareUser.ShareUserTypeId.IsGuidNullOrEmpty()) { if (Configuration.ShareUser.ShareUserTypeId == Guid.Parse("71BE65E6-3A64-414D-972E-1A3D4A365000")) { //如果是会员,检查会员等级 if (Configuration.ShareUser.IsLimitShareUserGrade) { if (Configuration.ShareUser.ShareUserGradeId != _shareUser.GradeId) { return(ExecuteResult <ITaskResult[]> .Fail( $"user with id {userId} not match UserGradeid:{Configuration.ShareUser.ShareUserTypeId}, exit module")); //会员等级不符合grade要求,直接退出 } } } } else { return(ExecuteResult <ITaskResult[]> .Fail("ShareUserTypeId is null")); //userTypeId 为空 } } shareUser = _shareUser; return(ExecuteResult <ITaskResult[]> .Success()); }
/// <summary> /// 开始执行分润 /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> /// <returns>ExecuteResult<ITaskResult[]>.</returns> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel(baseResult.Message)); } //TODO 2019年9月24日 城市代理商分润 //// 如果触发方式是订单类型,用户触发和其他触发后续支出 //long? cityRegionId = 0; // 城市区域代理Id //// 20190603: TriggerType.Order || TriggerType.Other //if (base.Configuration.TriggerType == TriggerType.Order // || base.Configuration.TriggerType == TriggerType.Other) { // var order = Resolve<IOrderService>().GetSingle(ShareOrder.EntityId); // if (order == null) { // return ExecuteResult<ITaskResult[]>.Cancel("未找到订单"); // } // var region = new Region(); // 区域 // // 按收货地址 // if (base.Configuration.AddressLockType == AddressLockType.OrderAddress) { // var userAddress = Resolve<IUserAddressService>().GetSingle(r => r.Id == order.AddressId.ToObjectId()); // var regStr = userAddress.RegionId.ToString(); // if (regStr.Length >= 4) { // cityRegionId = regStr.Substring(0, 4).ToInt64(); // } // } // // 按备案地址 // if (base.Configuration.AddressLockType == AddressLockType.UserInfoAddress) { // var orderUser = Resolve<IUserService>().GetUserDetail(order.UserId); // cityRegionId = Resolve<IRegionService>().GetCityId((orderUser.Detail?.RegionId).ConvertToLong()); // } // // 按发货人地址分润 // if (base.Configuration.AddressLockType == AddressLockType.DeliveryUserAddress) { // var orderUserDetail = Resolve<IUserDetailService>().GetSingle(r => r.UserId == order.DeliverUserId); // if (orderUserDetail != null) { // cityRegionId = Resolve<IRegionService>().GetCityId(orderUserDetail.RegionId) // .ConvertToLong(); // } // } //} //// 获取城市代理 //IList<ITaskResult> resultList = new List<ITaskResult>(); ////var cityUserType = Resolve<IUserTypeService>().GetSingle(r => r.UserTypeId == UserTypeEnum.City.GetFieldId() && r.EntityId == cityRegionId); //var cityUserType = Resolve<ICityService>().GetSingle(r => r.RegionId == cityRegionId); //if (cityUserType == null) { // return ExecuteResult<ITaskResult[]>.Cancel("该区域的城市代理未找到"); //} //// 推荐关系 一二代 //var maps = new List<ParentMap> { // new ParentMap { // ParentLevel = 1, // UserId = cityUserType.UserId // } //}; //if (cityUserType.ParentUserId != 0) { // maps.Add(new ParentMap { // ParentLevel = 2, // UserId = cityUserType.ParentUserId // }); //} //// 城市代理分润 //for (var i = 0; i < Ratios.Count; i++) { // if (maps.Count < i + 1) { // break; // } // var item = maps[i]; // base.GetShareUser(item.UserId, out var shareUser);//从基类获取分润用户 // if (shareUser == null) { // continue; // } // var ratio = Convert.ToDecimal(Ratios[i]); // var shareAmount = BaseFenRunAmount * ratio;//分润金额 // CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList);//构建分润参数 //} // return ExecuteResult<ITaskResult[]>.Success(resultList.ToArray()); return(null); }
/// <summary> /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var userMap = Resolve <IUserMapService>().GetParentMapFromCache(ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } IList <ITaskResult> resultList = new List <ITaskResult>(); // foreach (var teamRangCultivateItem in Configuration.TeamRangCultivateItems) // { var maxRatio = 0.36m; var a = 0; var longAmount = 0.0m; var useRatio = 0.0m; var level = 0; for (var i = 0; i < TeamLevel;) { if (useRatio >= maxRatio) { break; } if (a >= 6) { break; } if (map.Count < i + 1) { break; } //var item = map[i]; //var grade = Resolve<IGradeService>().GetGrade(teamRangCultivateItem.GradeId); //base.GetShareUser(item.UserId, out var shareUser); var item = map[i]; base.GetShareUser(item.UserId, out var shareUser); //从基类获取分润用户 var grade = Resolve <IGradeService>().GetGrade(shareUser.GradeId); var shareUserRule = Configuration.TeamRangCultivateItems.FirstOrDefault(r => r.GradeId == grade.Id); if (shareUserRule == null) { continue; } var sumAmount = shareUserRule.FristAmount + shareUserRule.SecondAmount; if (grade == null) { continue; } //if (grade == null) //{ // break; //} if (longAmount < sumAmount) { var ratio = shareUserRule.FristAmount - useRatio; i = i + 1; level = 0; longAmount = sumAmount; var intro = $"{grade.Name}一代"; var shareAmount = BaseFenRunAmount * ratio; if (shareAmount > 0) { CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList, intro); a = a + 1; useRatio += ratio; } } else { i = i + 1; level++; if (longAmount == sumAmount) { if (level == 1) { var intro = $"{grade.Name}二代"; var shareAmount = BaseFenRunAmount * shareUserRule.SecondAmount; if (shareAmount > 0) { CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList, intro); a = a + 1; useRatio = useRatio + shareUserRule.SecondAmount; } } if (level >= 2) { continue; } } } } // } return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
/// <summary> /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var mapList = new List <ParentMap>(); var userMap = Resolve <IUserMapService>().GetParentMapFromCache(ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } IList <ITaskResult> resultList = new List <ITaskResult>(); long lvKey = 0; //用于判断级差 long userIdKey = 0; //第一个营业部userID要记录 var iKey = false; var firLv = false; foreach (var teamRangCultivateItem in Configuration.TeamRangCultivateItems) { // 将自己加上去 var parentMap = new ParentMap { UserId = ShareOrderUser.Id, ParentLevel = 0 }; map = map.AddBefore(parentMap).ToList(); for (var i = 0; i < TeamLevel; i++) { var level = 0; var tempLv = 0; if (map.Count < i + 1) { break; } var item = map[i]; var grade = Resolve <IGradeService>().GetGrade(teamRangCultivateItem.GradeId); if (grade == null) { break; } var gradeList = Resolve <IAutoConfigService>().GetList <UserGradeConfig>(); base.GetShareUser(item.UserId, out var shareUser); var shareGradeContribute = gradeList.FirstOrDefault(u => u.Id == shareUser.GradeId).Contribute; //如果是营业部 则不再判断其他等级 if (shareGradeContribute >= 500000) { level = 4; iKey = true; if (i == 0) { userIdKey = shareUser.Id; } } if (shareGradeContribute >= 500000) { level = 4; } if (shareGradeContribute >= 100000 && shareGradeContribute < 500000) { level = 3; } if (shareGradeContribute >= 10000 && shareGradeContribute < 100000) { level = 2; } if (shareGradeContribute >= 0 && shareGradeContribute < 10000) { level = 1; } if (i == 0) { lvKey = level; //获得下单人等级 } if (level < lvKey) { continue; } if (i >= 4) { break; } #region 区分判断 var tempContribute = gradeList.FirstOrDefault(u => u.Id == teamRangCultivateItem.GradeId).Contribute; if (tempContribute >= 500000) { tempLv = 4; } if (tempContribute >= 100000 && tempContribute < 500000) { tempLv = 3; } if (tempContribute >= 10000 && tempContribute < 100000) { tempLv = 2; } if (tempContribute >= 0 && tempContribute < 10000) { tempLv = 1; } #endregion 区分判断 if (level == tempLv) { if (userIdKey == shareUser.Id && i != 0) { continue; } if (level == 0) { continue; } var mapSingle = mapList.FirstOrDefault(u => u.UserId == level); if (mapSingle == null) { var temp = new ParentMap { UserId = level, ParentLevel = 1 //计算该等级出现次数 }; //如果第一个加入的值为营业厅 则不判断其他 if (mapList.Count() == 0 && level == 4) { iKey = true; } //如果等级小于报单人 则跳过 if (lvKey <= level) { mapList.Add(temp); } continue; } else { var num = mapList.FirstOrDefault(u => u.UserId == level).ParentLevel; mapList.Remove(mapSingle); var temp = new ParentMap { UserId = level, ParentLevel = num + 1 //用于计算该等级出现次数 }; mapList.Add(temp); mapSingle.ParentLevel = num + 1; } var gradeName = Resolve <IGradeService>().GetGrade(shareUser.GradeId); if (mapSingle.ParentLevel == 2) { if (lvKey > mapSingle.UserId) { continue; } lvKey = mapSingle.UserId; var intro = $"{gradeName.Name}育成一代"; var shareAmount = BaseFenRunAmount * teamRangCultivateItem.FristAmount; if (shareAmount > 0) { CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList, intro); } } if (mapSingle.ParentLevel == 3 && mapSingle.UserId == 4) { var intro = $"{gradeName.Name}育成二代"; var shareAmount = BaseFenRunAmount * teamRangCultivateItem.SecondAmount; if (shareAmount > 0) { CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList, intro); } break; } if (mapSingle.ParentLevel >= 3) { break; } } } } return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
/// <summary> /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var userMap = Resolve <IUserMapService>().GetParentMapFromCache(ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } IList <ITaskResult> resultList = new List <ITaskResult>(); //检查分润比例 var distriRatio = Configuration.DistriRatio.Split(','); // 以结构A->B->C->D,D下单为列子 for (var i = 0; i < distriRatio.Count(); i++) { if (map.Count < i + 1 || i > 2) { break; } //当前级别奖励 var ratio = distriRatio[i].ConvertToDecimal(); var levelRadio = ratio; if (ratio <= 0) { continue; } var item = map[i]; var shareGuids = new List <Guid>(); // 已分配的等级,极差分配中,同一等级只能分配一次 base.GetShareUser(item.UserId, out var shareUser); //从基类获取分润用户 ExecuteLevelAmount(resultList, shareUser, i + 1, parameter, ref levelRadio, ref shareGuids); if (levelRadio > 0 && i < 2) { // 第一层分配有剩,开始第二层分配 base.GetShareUser(shareUser.ParentId, out shareUser); //从基类获取分润用户 if (shareUser.GradeId == Guid.Parse("cc873faa-749b-449b-b85a-c7d26f626feb")) { ExecuteLevelAmount(resultList, shareUser, i + 1, parameter, ref levelRadio, ref shareGuids); } if (levelRadio > 0 && i < 1) { // 第二层分配有剩,开始第三层分配 base.GetShareUser(shareUser.ParentId, out shareUser); //从基类获取分润用户 if (shareUser.GradeId == Guid.Parse("cc873faa-749b-449b-b85a-c7d26f626feb")) { ExecuteLevelAmount(resultList, shareUser, i + 1, parameter, ref levelRadio, ref shareGuids); } } } } //分期 return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("基础验证未通过" + baseResult.Message)); } IList <ITaskResult> resultList = new List <ITaskResult>(); // 检查关系图 var userRelationshipConfigs = Resolve <IAutoConfigService>().GetList <UserRelationshipIndexConfig>(); var config = userRelationshipConfigs.FirstOrDefault(r => r.IsEnable && r.Id == Configuration.ConfigId); if (config == null) { return(ExecuteResult <ITaskResult[]> .Cancel("关系图配置不存在")); } // 查找分润订单用户的,关系图索引 var userRelationshipIndex = Resolve <IRelationshipIndexService>() .GetSingle(r => r.ConfigId == config.Id && r.UserId == ShareOrder.UserId); if (userRelationshipIndex == null) { return(ExecuteResult <ITaskResult[]> .Cancel("触发用户关系图索引不存在")); } // 根据关系索引获取分润用户 base.GetShareUser(userRelationshipIndex.ParentId, out var shareUser); //从基类获取分润用户 if (shareUser == null) { return(ExecuteResult <ITaskResult[]> .Cancel("分润用户不符合条件或不存在")); } // 一级分润比例 if (Ratios.Count > 0) { var ratio = Convert.ToDecimal(Ratios[0]); var shareAmount = BaseFenRunAmount * ratio; //分润金额 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); // 二级分润比例 if (Ratios.Count > 1) { // 二级关系图索引 var user = shareUser; userRelationshipIndex = Resolve <IRelationshipIndexService>() .GetSingle(r => r.ConfigId == config.Id && r.UserId == user.Id); if (userRelationshipIndex == null) { return(ExecuteResult <ITaskResult[]> .Cancel("二级用户关系图索引不存在")); } // 根据关系索引获取二级分润用户 base.GetShareUser(userRelationshipIndex.ParentId, out shareUser); if (shareUser == null) { return(ExecuteResult <ITaskResult[]> .Cancel("二级分润用户不符合条件或不存在")); } ratio = Convert.ToDecimal(Ratios[1]); shareAmount = BaseFenRunAmount * ratio; CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); } } return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("基础验证未通过" + baseResult.Message)); } var userMap = Resolve <IUserMapService>().GetParentMapFromCache(ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var parentUserIds = map.OrderBy(r => r.ParentLevel).Select(r => r.UserId).ToList(); if (Configuration.IsAllowUserSelf) { parentUserIds = parentUserIds.AddBefore(ShareOrderUser.Id).ToList(); } if (Configuration.UserGradeId.IsGuidNullOrEmpty()) { return(ExecuteResult <ITaskResult[]> .Cancel("会员等级设置错误")); } var allUserGradeIds = Resolve <IGradeService>().GetUserGradeList().Select(r => r.Id); var allGrades = Resolve <IGradeService>().GetUserGradeList(); var configGrade = allGrades.FirstOrDefault(r => r.Id == Configuration.UserGradeId); if (configGrade == null) { return(ExecuteResult <ITaskResult[]> .Cancel("会员等级不存在,不是有效的会员等级")); } allGrades = allGrades.Where(r => r.Contribute >= configGrade.Contribute).ToList(); // 获取高等级的 var shareUsersList = Resolve <IUserService>().GetList(parentUserIds).ToList(); if (!shareUsersList.Any()) { return(ExecuteResult <ITaskResult[]> .Cancel("符合条件的会员不存在")); } var shareUsersListIds = shareUsersList.Select(r => r.Id).ToList(); var allGradeIds = allGrades.Select(r => r.Id).ToList(); IList <ITaskResult> resultList = new List <ITaskResult>(); foreach (var parentId in parentUserIds) { if (shareUsersListIds.Contains(parentId)) { base.GetShareUser(parentId, out var shareUser); //从基类获取分润用户 if (shareUser != null) // 符合等级条件 { if (allGradeIds.Contains(shareUser.GradeId)) { var shareAmount = BaseFenRunAmount * Ratios[0].ToDecimal(); //绩效奖励 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); break; } } } } return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }
/// <summary> /// Executes the specified parameter. /// </summary> /// <param name="parameter">参数</param> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { if (Configuration == null) { return(ExecuteResult <ITaskResult[]> .Fail("configuration is null.")); } //进行参数判断 if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } //判断通用交易订单 if (!parameter.TryGetValue("ShareOrderId", out long shareOrderId)) { return(ExecuteResult <ITaskResult[]> .Fail("分润订单ShareOrderId未找到.")); } var shareOrder = Ioc.Resolve <IShareOrderService>().GetSingle(r => r.Id == shareOrderId); if (shareOrder == null) { return(ExecuteResult <ITaskResult[]> .Fail($"分润订单为空,shareorder with id {shareOrderId} is null.")); } if (shareOrder.Status != ShareOrderStatus.Pending) { return(ExecuteResult <ITaskResult[]> .Fail("分润订单状态不是代理状态,不触发分润.")); } if (shareOrder.Amount <= 0) { return(ExecuteResult <ITaskResult[]> .Fail("分润订单金额小于0,shareorder with amount is less than zero")); } if (Configuration.PriceLimitType == PriceLimitType.OrderPrice) { if (shareOrder.Amount > Configuration.BaseRule.MaxAmount && Configuration.BaseRule.MaxAmount > 0) { return(ExecuteResult <ITaskResult[]> .Fail( $"分润订单金额{shareOrder.Amount} > 最大触发金额{Configuration.BaseRule.MinimumAmount}, 退出模块")); } if (shareOrder.Amount < Configuration.BaseRule.MinimumAmount && Configuration.BaseRule.MinimumAmount > 0 ) { return(ExecuteResult <ITaskResult[]> .Fail( $"分润订单金额{shareOrder.Amount} <= 最小触发金额{Configuration.BaseRule.MinimumAmount}, 退出模块")); } } ShareOrder = shareOrder; //判断交易用户 var user = Ioc.Resolve <IUserService>().GetSingle(shareOrder.UserId); if (user == null) { return(ExecuteResult <ITaskResult[]> .Fail( $"shareorder with id {shareOrderId} ,shareorder user is null.")); } ShareOrderUser = user; //检查分润用户 var gradeResult = CheckOrderUserTypeAndGrade(); if (gradeResult.Status != ResultStatus.Success) { return(gradeResult); } //检查分润比例 var distriRatio = Configuration.DistriRatio.Split(','); if (distriRatio == null || distriRatio.Length == 0) { return(ExecuteResult <ITaskResult[]> .Cancel("模块需要设置分润比例但未设置.")); } Ratios = distriRatio.ToList(); return(ExecuteResult <ITaskResult[]> .Success()); }
/// <summary> /// 对module配置与参数进行基础验证,子类重写后需要显式调用并判定返回值,如返回值不为Success,则不再执行子类后续逻辑 /// </summary> /// <param name="parameter">参数</param> public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(baseResult); } if (parameter.TryGetValue(TriggerTypeKey, out int triggerType)) { TriggerType = (TriggerType)triggerType; if (Configuration.TriggerType != TriggerType) //触发类型与配置的触发类型不一致,直接退出 { return(ExecuteResult <ITaskResult[]> .Cancel( $"模块实际触发类型{triggerType}与模块设置的触发类型{Configuration.TriggerType}不一致,退出模块.")); } } else { TriggerType = Configuration.TriggerType; } // 触发类型为会员注册 if (TriggerType == TriggerType.UserReg) { parameter.TryGetValue(FenRunAmountKey, out decimal amount); BaseFenRunAmount = amount; if (BaseFenRunAmount <= 0) { return(ExecuteResult <ITaskResult[]> .Cancel($"分润基数价格获取为0. BaseFenRunAmount={BaseFenRunAmount}")); } } // 触发类型为会员升级 if (TriggerType == TriggerType.UserUpgrade) { parameter.TryGetValue(FenRunAmountKey, out decimal amount); BaseFenRunAmount = amount; if (BaseFenRunAmount <= 0) { return(ExecuteResult <ITaskResult[]> .Cancel( $"分润基数价格获取为0. BaseFenRunAmount={BaseFenRunAmount},会员Id为{ShareOrder.UserId}")); } } // TODO 2019年9月24日 触发类型为商城购物 if (TriggerType == TriggerType.Order) { ////获取价格基数 //if (parameter.TryGetValue("OrderId", out long orderId)) { // // 获取符合条件的商品 价格依赖范围 所有商品 按所属商品线选择 按所属商城选择 // var effectiveOrderProductListAll = GetEffectiveOrderProduct(orderId); // if (effectiveOrderProductListAll == null || effectiveOrderProductListAll.Count == 0) { // return ExecuteResult<ITaskResult[]>.Cancel($"没有符合的产品可分润,退出模块."); // } // var effectiveOrderProductList = new List<OrderProduct>(); // // 商品单价限制 // if (Configuration.PriceLimitType == PriceLimitType.ProductPrice) { // foreach (var productItem in effectiveOrderProductListAll) { // if (productItem.Amount > Configuration.BaseRule.MaxAmount && Configuration.BaseRule.MaxAmount > 0) { // continue; // } // if (productItem.Amount < Configuration.BaseRule.MinimumAmount && Configuration.BaseRule.MinimumAmount > 0) { // continue; // } // effectiveOrderProductList.Add(productItem); // } // } else { // effectiveOrderProductList = effectiveOrderProductListAll; // } // //如果价格模式为销售价,则触发金额为有效的商品实际售价之和 // if (Configuration.ProductRule.AmountType == PriceType.Price) { // // 根据实际支付方式获取价格 (PaymentAmount为人民币支付的价格) // BaseFenRunAmount = effectiveOrderProductList.Sum(e => e.PaymentAmount); // } // //如果价格模式为分润价,则触发金额为有效的商品分润价之和 // if (Configuration.ProductRule.AmountType == PriceType.FenRun) { // BaseFenRunAmount = effectiveOrderProductList.Sum(e => e.FenRunAmount); // } // //如果价格模式为商品数 :有效商品数量之和 // if (Configuration.ProductRule.AmountType == PriceType.ProductNum) { // BaseFenRunAmount = effectiveOrderProductList.Sum(e => e.Count); // } // //如果价格模式为商品数 :有效商品数量之和 // if (Configuration.ProductRule.AmountType == PriceType.OrderNum) { // BaseFenRunAmount = 1; // } // //如果价格模式为服务费 // if (Configuration.ProductRule.AmountType == PriceType.OrderFeeAmount) { // BaseFenRunAmount = effectiveOrderProductList.Sum(e => e.OrderProductExtension?.OrderAmount?.FeeAmount).ConvertToDecimal(); // } //} //OrderId = orderId; //if (BaseFenRunAmount <= 0) { // return ExecuteResult<ITaskResult[]>.Cancel($"分润基数价格获取为0. BaseFenRunAmount={BaseFenRunAmount},订单id为{OrderId}"); //} } // 触发类型为内部连锁 if (TriggerType == TriggerType.Chain) { if (!parameter.TryGetValue(DefaultAmountKey, out decimal amount)) { amount = 0; } BaseFenRunAmount = amount; } // 触发类型为其他、提现、充值,订单金额为ShareOrder的Amount if (TriggerType == TriggerType.Other || TriggerType == TriggerType.WithDraw || TriggerType == TriggerType.Recharge) { parameter.TryGetValue(FenRunAmountKey, out decimal amount); BaseFenRunAmount = amount; if (BaseFenRunAmount <= 0) { return(ExecuteResult <ITaskResult[]> .Cancel($"分润基数价格获取为0. BaseFenRunAmount={BaseFenRunAmount}")); } } if (!parameter.TryGetValue("ShareOrderId", out long shareOrderId)) { return(ExecuteResult <ITaskResult[]> .Fail("分润订单ShareOrderId未找到.")); } // 线程停止3s中,重新读取数据库,保证ShardeOdeer状态正确,不重复触发 //Thread.Sleep(TimeSpan.FromSeconds(3)); var shareOrder = Resolve <IShareOrderService>().GetSingleNative(shareOrderId); if (shareOrder == null) { return(ExecuteResult <ITaskResult[]> .Fail("分润订单未找到.")); } // TODO 2019年9月24日 重构 商城模式 //if (shareOrder.Status != ShareOrderStatus.Pending) { // return ExecuteResult<ITaskResult[]>.Fail("分润订单原生查询,状态不正常."); //} var teamConfig = Resolve <IAutoConfigService>().GetValue <TeamConfig>(); TeamLevel = teamConfig.TeamLevel; return(ExecuteResult <ITaskResult[]> .Success()); }
public override ExecuteResult <ITaskResult[]> Execute(TaskParameter parameter) { var baseResult = base.Execute(parameter); if (baseResult.Status != ResultStatus.Success) { return(ExecuteResult <ITaskResult[]> .Cancel("基础验证未通过" + baseResult.Message)); } var userMap = Resolve <IUserMapService>().GetParentMapFromCache(ShareOrderUser.Id); var map = userMap.ParentMap.DeserializeJson <List <ParentMap> >(); if (map == null) { return(ExecuteResult <ITaskResult[]> .Cancel("未找到触发会员的Parent Map.")); } var parentUserIds = map.OrderBy(r => r.ParentLevel).Select(r => r.UserId); if (Configuration.UserGradeId.IsGuidNullOrEmpty()) { return(ExecuteResult <ITaskResult[]> .Cancel("会员等级设置错误")); } var allUserGradeIds = Resolve <IGradeService>().GetUserGradeList().Select(r => r.Id); if (!allUserGradeIds.Contains(Configuration.UserGradeId)) { return(ExecuteResult <ITaskResult[]> .Cancel("会员等级不存在,不是有效的会员等级")); } var shareUsersList = Resolve <IUserService>() .GetList(r => r.GradeId == Configuration.UserGradeId && parentUserIds.Contains(r.Id)).ToList(); if (!shareUsersList.Any()) { return(ExecuteResult <ITaskResult[]> .Cancel("符合条件的会员不存在")); } var shareUsersListIds = shareUsersList.Select(r => r.Id).ToList(); var count = 0; IList <ITaskResult> resultList = new List <ITaskResult>(); foreach (var parentId in parentUserIds) { if (shareUsersListIds.Contains(parentId)) { base.GetShareUser(parentId, out var shareUser); //从基类获取分润用户 if (shareUser == null) { continue; } count++; //基础分润 if (count == 1) { var shareAmount = BaseFenRunAmount * Configuration.BaseRatio; //基础分润 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); } //培育分润 if (count == 2) { var shareAmount = BaseFenRunAmount * Configuration.CultivateRatio; //培育分润 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); //构建分润参数 } //培育分润 if (count == 3) { var shareAmount = BaseFenRunAmount * Configuration.CultivateTwoRatio; //培育分润 CreateResultList(shareAmount, ShareOrderUser, shareUser, parameter, Configuration, resultList); //构建分润参数 } } if (count >= 3) { break; } } return(ExecuteResult <ITaskResult[]> .Success(resultList.ToArray())); }