コード例 #1
0
        /// <summary>
        /// 处理积分奖励逻辑
        /// </summary>
        /// <param name="AgentId">代理商(被推荐人或是产品购买人)</param>
        /// <param name="reType">奖励类型:推荐奖励   购买奖励</param>
        /// <returns></returns>
        public static bool DealRewardScore(string AgentId, RewartType reType, int amount = 1)
        {
            var  configLisg = CommConfigLogic.GetConfigListByCate((int)ConfigCategory.ScoreConfigCate);
            bool result     = true;

            using (DistributionContext context = new DistributionContext())
            {
                var beRecomm = context.t_agent.Find(AgentId);
                var parList  = context.t_agent_relation.Where(c => c.c_child_id == AgentId);
                if (parList.Count() < 1)
                {
                    return(result);
                }
                Agent  recommAg = parList.FirstOrDefault().ParentAgent;
                string RecommId = recommAg.c_id;
                int    firsSc   = 0; //直推奖励
                int    secoSc   = 0; //二代奖励
                string desc     = "";
                if (reType == RewartType.Recommend)
                {
                    desc = "推荐";
                    if (beRecomm.c_agnet_type == (int)AgentType.Fran)//加盟店
                    {
                        firsSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.firstRecomm).FirstOrDefault().c_value);
                        secoSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.secondRecomm).FirstOrDefault().c_value);
                        desc  += "加盟店";
                    }
                    else if (beRecomm.c_agnet_type == (int)AgentType.Exp)//体验店
                    {
                        firsSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.expFirstRecomm).FirstOrDefault().c_value);
                        secoSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.expSecondRecomm).FirstOrDefault().c_value);
                        desc  += "体验店";
                    }
                }
                else
                {
                    if (beRecomm.c_agnet_type == (int)AgentType.Fran)//加盟店
                    {
                        firsSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.firstBuy).FirstOrDefault().c_value);
                        secoSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.secondBuy).FirstOrDefault().c_value);
                        desc  += "加盟店";
                    }
                    else if (beRecomm.c_agnet_type == (int)AgentType.Exp)//体验店
                    {
                        firsSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.expFirstBuy).FirstOrDefault().c_value);
                        secoSc = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.expSecondBuy).FirstOrDefault().c_value);
                        desc  += "体验店";
                    }
                    desc = "购买";
                }

                //1、直推人更新积分
                UpdateAgentScore(RecommId, firsSc * amount, "直推人【" + desc + "】积分奖励", context);

                //2、二代更新积分
                var sec_list = context.t_agent_relation.Where(c => c.c_child_id == RecommId);
                if (sec_list.Count() == 0)//若没有二代则直接返回
                {
                    return(result);
                }
                Agent SeconAgent = sec_list.FirstOrDefault().ParentAgent;
                UpdateAgentScore(SeconAgent.c_id, secoSc * amount, "二代【" + desc + "】积分奖励", context);

                if (beRecomm.c_agnet_type != (int)AgentType.Exp)
                {
                    #region 二代外积分更改逻辑
                    int maxLevel    = GetMaxLevel(AgentId, context);
                    var list_Config = context.t_level_config.Where(f => f.c_level == maxLevel && f.c_is_delete == 0);
                    if (maxLevel == 1 || list_Config.Count() == 0)
                    {
                        return(result);
                    }
                    int rewardScore = (int)list_Config.First().c_recomm_reward;
                    if (reType == RewartType.Purchase)
                    {
                        rewardScore = (int)list_Config.First().c_buy_reward *amount;
                    }

                    if (rewardScore > 0)
                    {
                        var list = context.t_agent_relation.ToList();
                        RewardForCorreLevel(SeconAgent, 1, 1, ref rewardScore, reType, list, context, amount);
                    }
                    if (reType == RewartType.Recommend)
                    {
                        DealProvinceReward(SeconAgent);
                    }

                    #endregion
                }
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// (递归)相应等级奖励相应积分(按照极差制度) 极差制度,上级奖励= 总奖励 - 下级奖励   体验店不进行二代外奖励
        /// </summary>
        /// <param name="ParAgent"></param>
        /// <param name="RewardScore">奖励总积分</param>
        /// <param name="reType">奖励类型</param>
        /// <param name="context"></param>
        private static void RewardForCorreLevel(Agent ParAgent, int beforeMaxLevel, int currentLevel, ref int RewardScore, RewartType reType, List <AgentRelation> allRelationList, DistributionContext context, int amount = 1)
        {
            string desc = "";
            var    list = allRelationList.Where(f => f.c_child_id == ParAgent.c_id);

            if (list.Count() == 0)
            {
                return;
            }
            if (RewardScore <= 0)
            {
                return;
            }
            Agent ag = list.First().ParentAgent;       //上级代理

            if (ag.c_agnet_type != (int)AgentType.Exp) //体验店不进行二代外奖励
            {
                var list_config = context.t_level_config.Where(f => f.c_level == ag.c_levle && f.c_is_delete == 0);
                int needReward  = 0;              //等级奖励
                int cMaxLevel   = beforeMaxLevel; //下级中最高等级
                //极差制度提现,上级奖励= 配置奖励 - 下级最高级奖励
                if (list_config.Count() != 0 && currentLevel < ag.c_levle)
                {
                    if (reType == RewartType.Recommend)//推荐代理商奖励
                    {
                        needReward = (int)list_config.First().c_recomm_reward;
                        if (cMaxLevel > 1)
                        {
                            int cDeduReward = (int)LevelConfigLogic.FindEntity(f => f.c_level == cMaxLevel).c_recomm_reward;
                            needReward -= cDeduReward;
                        }

                        desc = "推荐";
                    }
                    else//购买产品奖励
                    {
                        needReward = (int)list_config.First().c_buy_reward *amount;
                        if (cMaxLevel > 1)
                        {
                            int cDeduReward = (int)LevelConfigLogic.FindEntity(f => f.c_level == cMaxLevel).c_buy_reward *amount;
                            needReward -= cDeduReward;
                        }
                        desc = "购买";
                    }
                }
                needReward = Math.Min(RewardScore, needReward);
                if (needReward != 0)
                {
                    UpdateAgentScore(ag.c_id, needReward, "部门【" + desc + "】积分奖励", context);
                    RewardScore -= needReward;//极差制度,上级奖励= 总奖励 - 下级奖励
                }
            }

            int level = 0;

            if (ag.c_levle != null)
            {
                level = (int)ag.c_levle;
            }
            level          = Math.Max(currentLevel, level);
            beforeMaxLevel = Math.Max(beforeMaxLevel, level);
            RewardForCorreLevel(ag, beforeMaxLevel, level, ref RewardScore, reType, allRelationList, context, amount);
        }