コード例 #1
0
        /// <summary>
        /// 省级代理奖励
        /// </summary>
        /// <param name="BeRecommAgent">被推荐代理商</param>
        /// <returns></returns>
        public static bool DealProvinceReward(Agent BeRecommAgent)
        {
            var  configLisg = CommConfigLogic.GetConfigListByCate((int)ConfigCategory.ScoreConfigCate);
            bool result     = true;
            int  ProReward  = Convert.ToInt32(configLisg.Where(t => t.c_key == (int)RewardConfigKey.provinceRecomm).FirstOrDefault().c_value);;

            using (DistributionContext context = new DistributionContext())
            {
                RewardForProvice(BeRecommAgent, ProReward, context);
            }
            return(true);
        }
コード例 #2
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);
        }