Ejemplo n.º 1
0
        public static int GetNotDescDistributorGrades(string ReferralUserId)
        {
            DistributorsInfo     userIdDistributors = GetUserIdDistributors(int.Parse(ReferralUserId));
            decimal              num2 = userIdDistributors.ReferralBlance + userIdDistributors.ReferralRequestBalance;
            DistributorGradeInfo distributorGradeInfo = DistributorGradeBrower.GetDistributorGradeInfo(userIdDistributors.DistriGradeId);

            if ((distributorGradeInfo != null) && (num2 < distributorGradeInfo.CommissionsLimit))
            {
                return(userIdDistributors.DistriGradeId);
            }
            List <DistributorGradeInfo> distributorGrades = new DistributorsDao().GetDistributorGrades() as List <DistributorGradeInfo>;

            foreach (DistributorGradeInfo info3 in from item in distributorGrades
                     orderby item.CommissionsLimit descending
                     select item)
            {
                if (userIdDistributors.DistriGradeId == info3.GradeId)
                {
                    return(0);
                }
                if (info3.CommissionsLimit <= (userIdDistributors.ReferralBlance + userIdDistributors.ReferralRequestBalance))
                {
                    return(info3.GradeId);
                }
            }
            return(0);
        }
Ejemplo n.º 2
0
        public static int GetNotDescDistributorGrades(string ReferralUserId)
        {
            SiteSettings         masterSettings     = SettingsManager.GetMasterSettings(false);
            DistributorsInfo     userIdDistributors = GetUserIdDistributors(int.Parse(ReferralUserId));
            decimal              num2 = userIdDistributors.ReferralBlance + userIdDistributors.ReferralRequestBalance; //用于判断的变量:佣金
            decimal              num3 = userIdDistributors.OrdersTotal;                                                //用于判断的变量:销售额
            DistributorGradeInfo distributorGradeInfo = DistributorGradeBrower.GetDistributorGradeInfo(userIdDistributors.DistriGradeId);

            //增加了升级判断类型:根据分销商的销售价来判断
            switch (masterSettings.DistributorUpgradeType)
            {
            case "byComm":
                //根据分销商的佣金判断
                if ((distributorGradeInfo != null) && (num2 < distributorGradeInfo.CommissionsLimit))
                {
                    return(userIdDistributors.DistriGradeId);
                }
                List <DistributorGradeInfo> distributorGrades = new DistributorsDao().GetDistributorGrades() as List <DistributorGradeInfo>;
                foreach (DistributorGradeInfo info3 in from item in distributorGrades
                         orderby item.CommissionsLimit descending
                         select item)
                {
                    if (userIdDistributors.DistriGradeId == info3.GradeId)
                    {
                        return(0);
                    }
                    if (info3.CommissionsLimit <= (userIdDistributors.ReferralBlance + userIdDistributors.ReferralRequestBalance))
                    {
                        return(info3.GradeId);
                    }
                }
                break;

            case "byOrdersTotal":
                //根据分销商的销售额判断
                if ((distributorGradeInfo != null) && (num3 < distributorGradeInfo.CommissionsLimit))
                {
                    return(userIdDistributors.DistriGradeId);
                }
                List <DistributorGradeInfo> distributorGrades2 = new DistributorsDao().GetDistributorGrades() as List <DistributorGradeInfo>;
                foreach (DistributorGradeInfo info4 in from item in distributorGrades2
                         orderby item.CommissionsLimit descending
                         select item)
                {
                    if (userIdDistributors.DistriGradeId == info4.GradeId)
                    {
                        return(0);
                    }
                    if (info4.CommissionsLimit <= (new DistributorsDao().GetDistributorDirectOrderTotal(userIdDistributors.UserId)))
                    {
                        return(info4.GradeId);
                    }
                }
                break;
            }

            return(0);
        }
        public static string MemberAutoToDistributor(MemberInfo memberinfo)
        {
            Globals.Debuglog("开始自动生成分销商请求", "_DebuglogMemberAutoToDistributor.txt");
            if (memberinfo == null)
            {
                return("用户不存在");
            }
            if (GetDistributorInfo(memberinfo.UserId) != null)
            {
                return("用户已是分销商");
            }
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(true);
            string       stroname       = string.Empty;

            if (string.IsNullOrEmpty(memberinfo.OpenId))
            {
                stroname = Globals.GetStoreNameByUserIDAndName(memberinfo.UserId, memberinfo.UserName, memberinfo.OpenId, masterSettings.SiteName);
            }
            else
            {
                stroname = Globals.GetStoreNameByUserIDAndName(0, memberinfo.UserName, memberinfo.OpenId, masterSettings.SiteName);
                if (IsExiteDistributorsByStoreName(stroname) > 0)
                {
                    stroname = Globals.GetStoreNameByUserIDAndName(memberinfo.UserId, memberinfo.UserName, memberinfo.OpenId, masterSettings.SiteName);
                }
            }
            DistributorsInfo distributors = new DistributorsInfo {
                RequestAccount   = "",
                StoreName        = stroname,
                StoreDescription = masterSettings.ShopIntroduction,
                Logo             = masterSettings.DistributorLogoPic,
                BackImage        = "",
                CellPhone        = memberinfo.CellPhone,
                ReferralUserId   = memberinfo.ReferralUserId,
                UserId           = memberinfo.UserId
            };
            DistributorGradeInfo isDefaultDistributorGradeInfo = DistributorGradeBrower.GetIsDefaultDistributorGradeInfo();

            if (isDefaultDistributorGradeInfo == null)
            {
                return("默认分销商等级未设置");
            }
            distributors.DistriGradeId = isDefaultDistributorGradeInfo.GradeId;
            Globals.Debuglog("开始自动生成分销商请求2", "_DebuglogMemberAutoToDistributor.txt");
            string str3 = AutoAddDistributors(distributors, memberinfo);

            if (str3 == "1")
            {
                Globals.Debuglog(string.Concat(new object[] { "自动生成分销商(", distributors.UserId, ")[", distributors.StoreName, "]" }), "_DebuglogMemberAutoToDistributor.txt");
                return("1");
            }
            Globals.Debuglog("自动生成分销商失败:" + str3, "_DebuglogMemberAutoToDistributor.txt");
            return("0");
        }
Ejemplo n.º 4
0
        //点睛教育需求:返佣同时得积分
        public static bool UpdateDistributorPoints(OrderInfo order)
        {
            bool flag = false;

            //代理商的积分
            DistributorsInfo currentDistributor    = GetDistributorInfo(order.ReferralUserId);                 //当前1级分销商分销信息
            DistributorsInfo currentAgent          = GetDistributorInfo(currentDistributor.AgentPath.ToInt()); //当前代理商分销信息
            MemberInfo       distributorLevel1Info = MemberProcessor.GetMember(currentDistributor.UserId);     //当前1级分销商用户信息
            MemberInfo       agentInfo             = MemberProcessor.GetMember(currentAgent.UserId);           //当前代理商用户信息

            //获取一级返佣和代理商返佣
            decimal commision = 0m;

            foreach (LineItemInfo info in order.LineItems.Values)
            {
                commision += info.ItemsCommission;
            }

            //一级分销商可得的积分
            int pointLevel1        = Convert.ToInt32(commision / 20);
            int agentCommisionRate = Convert.ToInt32(DistributorGradeBrower.GetAgentGradeInfo(currentAgent.AgentGradeId).FirstCommissionRise);//当前代理商的分佣百分比
            //当前代理商可得的积分
            int pointAgent = Convert.ToInt32((order.GetTotal() / 100 * agentCommisionRate) / 20);

            //判断该用户是否关注了公众号,如果没有关注,则积分给代理商.
            if (!(distributorLevel1Info != null && WxSubscribe(distributorLevel1Info.OpenId)))
            {
                pointAgent = pointAgent + pointLevel1;
            }


            //给1级分销商增加积分
            MemberDao dao4 = new MemberDao();

            distributorLevel1Info.Points = distributorLevel1Info.Points + pointLevel1;
            PointDetailInfo pointDistributorLevel1 = new PointDetailInfo
            {
                OrderId   = order.OrderId,
                UserId    = order.ReferralUserId,
                TradeDate = DateTime.Now,
                TradeType = PointTradeType.Bounty,
                Increased = pointLevel1,
                Points    = distributorLevel1Info.Points
            };

            if ((pointDistributorLevel1.Points > 0x7fffffff) || (pointDistributorLevel1.Points < 0))
            {
                pointDistributorLevel1.Points = 0x7fffffff;
            }
            PointDetailDao dao5 = new PointDetailDao();

            dao5.AddPointDetail(pointDistributorLevel1);
            dao4.Update(distributorLevel1Info);

            //给代理商增加积分

            MemberDao dao6 = new MemberDao();

            agentInfo.Points = agentInfo.Points + pointAgent;
            PointDetailInfo pointAgentInfo = new PointDetailInfo
            {
                OrderId   = order.OrderId,
                UserId    = order.ReferralUserId,
                TradeDate = DateTime.Now,
                TradeType = PointTradeType.Bounty,
                Increased = pointAgent,
                Points    = agentInfo.Points
            };

            if ((pointAgentInfo.Points > 0x7fffffff) || (pointAgentInfo.Points < 0))
            {
                pointAgentInfo.Points = 0x7fffffff;
            }
            PointDetailDao dao7 = new PointDetailDao();

            dao5.AddPointDetail(pointAgentInfo);
            dao4.Update(agentInfo);

            return(flag);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// jinhb,20150820,更新三级返佣金额,加入了无限代理佣金算法
        /// </summary>
        public static bool UpdateCalculationCommission(OrderInfo order)
        {
            DistributorsInfo userIdDistributors = GetUserIdDistributors(order.ReferralUserId);

            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
            bool         flag           = false;

            if (userIdDistributors != null)
            {
                bool isAgent1 = (userIdDistributors.IsAgent == 1) ? true : false;
                bool isAgent2 = false;
                bool isAgent3 = false;
                if (!masterSettings.EnableCommission)                    //未启用三级返佣
                {
                    if (userIdDistributors.ReferralStatus == 0)          //状态正常
                    {
                        flag = setCommission(order, userIdDistributors); //设置分销商佣金(仅更新直接销售的分销商返佣)
                    }
                }
                else//启用了三级返佣
                {
                    if (userIdDistributors.ReferralStatus == 0)
                    {
                        flag = setCommission(order, userIdDistributors);//更新直接销售的分销商返佣
                    }
                    if (!string.IsNullOrEmpty(userIdDistributors.ReferralPath))
                    {
                        ArrayList commTatalList  = new ArrayList();
                        decimal   num            = 0M;
                        ArrayList userIdList     = new ArrayList();
                        string    referralUserId = order.ReferralUserId.ToString();
                        string    orderId        = order.OrderId;
                        ArrayList orderTotalList = new ArrayList();
                        decimal   num2           = 0M;
                        ArrayList gradeIdList    = new ArrayList();
                        string[]  strArray       = userIdDistributors.ReferralPath.Split(new char[] { '|' });
                        if (strArray.Length == 1)
                        {
                            #region  一级返佣
                            DistributorsInfo info2 = GetUserIdDistributors(int.Parse(strArray[0]));
                            isAgent2 = (info2.IsAgent == 1) ? true : false;
                            if (info2.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo info3 in order.LineItems.Values)
                                {
                                    if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += info3.SecondItemsCommission;
                                        num2 += info3.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num);
                                orderTotalList.Add(num2);
                                userIdList.Add(info2.UserId);
                            }
                            #endregion  一级返佣
                        }
                        if (strArray.Length == 2)
                        {
                            #region  一级、上二级返佣
                            DistributorsInfo info4 = GetUserIdDistributors(int.Parse(strArray[0]));
                            isAgent3 = (info4.IsAgent == 1) ? true : false;
                            if (info4.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo info3 in order.LineItems.Values)
                                {
                                    if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += info3.ThirdItemsCommission;
                                        num2 += info3.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num);
                                orderTotalList.Add(num2);
                                userIdList.Add(info4.UserId);
                            }
                            DistributorsInfo info5 = GetUserIdDistributors(int.Parse(strArray[1]));
                            isAgent2 = (info5.IsAgent == 1) ? true : false;
                            num      = 0M;
                            num2     = 0M;
                            if (info5.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo info3 in order.LineItems.Values)
                                {
                                    if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += info3.SecondItemsCommission;
                                        num2 += info3.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num);
                                orderTotalList.Add(num2);
                                userIdList.Add(info5.UserId);
                            }
                            #endregion  一级、上二级返佣

                            //三级向上存在代理时进行设置
                            if (!string.IsNullOrEmpty(info4.AgentPath))
                            {
                                System.Data.DataView defaultViewAgent = DistributorGradeBrower.GetAllAgentGrade().DefaultView;      //当前系统中所有代理商等级
                                #region 设置无限代理返佣

                                string[] arrayAgentPath = info4.AgentPath.Split(new char[] { '|' });
                                foreach (string strAgentPat in arrayAgentPath)
                                {
                                    DistributorsInfo infoAgent = GetUserIdDistributors(int.Parse(strAgentPat));
                                    if (infoAgent.IsAgent != 1 || infoAgent.ReferralStatus == 1)
                                    {
                                        continue;
                                    }
                                    defaultViewAgent.RowFilter = " AgentGradeId=" + infoAgent.AgentGradeId;
                                    if (defaultViewAgent.Count == 0)
                                    {
                                        continue;
                                    }
                                    num  = 0M;
                                    num2 = 0M;
                                    foreach (LineItemInfo info in order.LineItems.Values)
                                    {
                                        if (info.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                        {
                                            if (!SettingsManager.GetMasterSettings(false).EnableProfit)
                                            {
                                                num += decimal.Parse(defaultViewAgent[0]["FirstCommissionRise"].ToString()) / 100m * info.GetSubTotal();
                                            }
                                            else
                                            {
                                                num += decimal.Parse(defaultViewAgent[0]["FirstCommissionRise"].ToString()) / 100m * info.GetSubTotalProfit();
                                            }

                                            num2 += info.GetSubTotal();
                                        }
                                    }
                                    commTatalList.Add(num);
                                    orderTotalList.Add(num2);
                                    userIdList.Add(infoAgent.UserId);
                                }

                                #endregion 设置无限代理返佣
                            }
                        }

                        //点睛教育:收到佣金的同时,收到5/100的积分


                        flag = new DistributorsDao().UpdateTwoCalculationCommission(userIdList, referralUserId, orderId, orderTotalList, commTatalList);
                        for (int i = 0; i < userIdList.Count; i++)
                        {
                            int notDescDistributorGrades = GetNotDescDistributorGrades(userIdList[i].ToString());
                            gradeIdList.Add(notDescDistributorGrades);
                        }
                        flag = new DistributorsDao().UpdateGradeId(gradeIdList, userIdList);
                    }
                }
                RemoveDistributorCache(userIdDistributors.UserId);
            }


            //额外10%的比例给服务门店
            if (order.RedPagerID > 0)    //如果选中了门店
            {
                #region 迪蔓门店服务费10%
                ArrayList commTatalList  = new ArrayList();
                ArrayList userIdList     = new ArrayList();
                string    referralUserId = order.ReferralUserId.ToString();
                string    orderId        = order.OrderId;
                ArrayList orderTotalList = new ArrayList();
                decimal   num            = 0M;
                decimal   num2           = 0M;
                foreach (LineItemInfo info in order.LineItems.Values)
                {
                    if (info.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                    {
                        if (!SettingsManager.GetMasterSettings(false).EnableProfit)
                        {
                            num += decimal.Parse("10") / 100m * info.GetSubTotal();
                        }
                        else
                        {
                            num += decimal.Parse("10") / 100m * info.GetSubTotalProfit();
                        }

                        num2 += info.GetSubTotal();
                    }
                }
                commTatalList.Add(num);
                orderTotalList.Add(num2);
                userIdList.Add(order.RedPagerID);
                flag = new DistributorsDao().UpdateTwoCalculationCommission(userIdList, referralUserId, orderId, orderTotalList, commTatalList);
                #endregion
            }


            OrderRedPagerBrower.CreateOrderRedPager(order.OrderId, order.GetTotal(), order.UserId);
            return(flag);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// jinhb,20150820,更新三级返佣金额,加入了无限代理佣金算法
        /// </summary>
        public static bool UpdateCalculationCommission(OrderInfo order)
        {
            DistributorsInfo userIdDistributors = GetUserIdDistributors(order.ReferralUserId);

            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
            bool         flag           = false;

            if (userIdDistributors != null)
            {
                bool isAgent1 = (userIdDistributors.IsAgent == 1) ? true : false;
                bool isAgent2 = false;
                bool isAgent3 = false;
                if (!masterSettings.EnableCommission)                    //未启用三级返佣
                {
                    if (userIdDistributors.ReferralStatus == 0)          //状态正常
                    {
                        flag = setCommission(order, userIdDistributors); //设置分销商佣金(仅更新直接销售的分销商返佣)
                    }
                }
                else//启用了三级返佣
                {
                    if (userIdDistributors.ReferralStatus == 0)
                    {
                        flag = setCommission(order, userIdDistributors);//更新直接销售的分销商返佣
                    }
                    if (!string.IsNullOrEmpty(userIdDistributors.ReferralPath))
                    {
                        ArrayList commTatalList  = new ArrayList();
                        decimal   num            = 0M;
                        ArrayList userIdList     = new ArrayList();
                        string    referralUserId = order.ReferralUserId.ToString();
                        string    orderId        = order.OrderId;
                        ArrayList orderTotalList = new ArrayList();
                        decimal   num2           = 0M;
                        ArrayList gradeIdList    = new ArrayList();
                        string[]  strArray       = userIdDistributors.ReferralPath.Split(new char[] { '|' });
                        if (strArray.Length == 1)
                        {
                            #region  一级返佣
                            DistributorsInfo info2 = GetUserIdDistributors(int.Parse(strArray[0]));
                            isAgent2 = (info2.IsAgent == 1) ? true : false;
                            if (info2.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo info3 in order.LineItems.Values)
                                {
                                    if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += info3.SecondItemsCommission;
                                        num2 += info3.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num);
                                orderTotalList.Add(num2);
                                userIdList.Add(info2.UserId);
                            }
                            #endregion  一级返佣
                        }
                        if (strArray.Length == 2)
                        {
                            #region  一级、上二级返佣
                            DistributorsInfo info4 = GetUserIdDistributors(int.Parse(strArray[0]));
                            isAgent3 = (info4.IsAgent == 1) ? true : false;
                            if (info4.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo info3 in order.LineItems.Values)
                                {
                                    if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += info3.ThirdItemsCommission;
                                        num2 += info3.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num);
                                orderTotalList.Add(num2);
                                userIdList.Add(info4.UserId);
                            }
                            DistributorsInfo info5 = GetUserIdDistributors(int.Parse(strArray[1]));
                            isAgent2 = (info5.IsAgent == 1) ? true : false;
                            num      = 0M;
                            num2     = 0M;
                            if (info5.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo info3 in order.LineItems.Values)
                                {
                                    if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += info3.SecondItemsCommission;
                                        num2 += info3.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num);
                                orderTotalList.Add(num2);
                                userIdList.Add(info5.UserId);
                            }
                            #endregion  一级、上二级返佣

                            //三级向上存在代理时进行设置
                            if (!string.IsNullOrEmpty(info4.AgentPath) && CustomConfigHelper.Instance.SelectServerAgent == false)
                            {
                                /*20160424,by 迪蔓。后期服务门店类时可通用
                                 * 1.消费者购买时可选择服务门店(天使,下拉框列表)
                                 * 1.1如果服务门店选择无,则按正常三级返佣(三级之外的不参与返佣,如无限级代理)
                                 * 1.2如果选择了服务门店,正常三级返佣不变(同1.1规则),额外10%的比例给服务门店(同时支持天使的返佣)
                                 * 1.3店铺订单,列表中额外查出服务订单
                                 */

                                System.Data.DataView defaultViewAgent = DistributorGradeBrower.GetAllAgentGrade().DefaultView;      //当前系统中所有代理商等级
                                #region 设置无限代理返佣

                                string[] arrayAgentPath = info4.AgentPath.Split(new char[] { '|' });
                                foreach (string strAgentPat in arrayAgentPath)
                                {
                                    DistributorsInfo infoAgent = GetUserIdDistributors(int.Parse(strAgentPat));
                                    if (infoAgent.IsAgent != 1 || infoAgent.ReferralStatus == 1)
                                    {
                                        continue;
                                    }
                                    defaultViewAgent.RowFilter = " AgentGradeId=" + infoAgent.AgentGradeId;
                                    if (defaultViewAgent.Count == 0)
                                    {
                                        continue;
                                    }
                                    num  = 0M;
                                    num2 = 0M;
                                    foreach (LineItemInfo info in order.LineItems.Values)
                                    {
                                        if (info.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                        {
                                            if (!SettingsManager.GetMasterSettings(false).EnableProfit)
                                            {
                                                num += decimal.Parse(defaultViewAgent[0]["FirstCommissionRise"].ToString()) / 100m * info.GetSubTotal();
                                            }
                                            else
                                            {
                                                num += decimal.Parse(defaultViewAgent[0]["FirstCommissionRise"].ToString()) / 100m * info.GetSubTotalProfit();
                                            }

                                            num2 += info.GetSubTotal();
                                        }
                                    }
                                    commTatalList.Add(num);
                                    orderTotalList.Add(num2);
                                    userIdList.Add(infoAgent.UserId);

                                    //齐品汇的代理商特殊返佣算法,此处为代理商在三级分佣之外时的情况:实际返佣=商品售价-出货折扣-三级返佣
                                    if (CustomConfigHelper.Instance.IsQipinhui)
                                    {
                                        decimal num_new = 0m;
                                        foreach (LineItemInfo info in order.LineItems.Values)
                                        {
                                            if (info.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                            {
                                                int    categoryId  = int.Parse(info.MainCategoryPath.TrimEnd('|')); //分类id
                                                string specialName = "";                                            //当前代理商的名字
                                                specialName = DistributorGradeBrower.GetAgentGradeInfo(infoAgent.AgentGradeId).AgentGradeName;

                                                //通过分类id和代理商名字获取特殊的分佣比例
                                                decimal currentRate     = Convert.ToDecimal(CatalogHelper.GetSpecialCategoryRent(categoryId, specialName));
                                                string  noCommOpenids   = CustomConfigHelper.Instance.NoCommOpenids != "" ? CustomConfigHelper.Instance.NoCommOpenids.ToLower() : "";      //先获取不参加返佣的4个openid
                                                decimal currentSubTotal = CatalogHelper.isSpecialRateExist(categoryId) ? info.GetSubTotal() * currentRate : info.GetSubTotalByCostPrice(); //根据当前分类id判断当前是用特殊比例计算还是使用成本价计算

                                                if (infoAgent.OpenId != null && noCommOpenids.IndexOf(infoAgent.OpenId.ToLower()) >= 0)
                                                {
                                                    num_new = 0;
                                                }
                                                else
                                                {
                                                    num_new = info.GetSubTotal() - currentSubTotal - (info.ItemsCommission + info.SecondItemsCommission + info.ThirdItemsCommission);
                                                }

                                                /*if (infoAgent.OpenId != null)
                                                 *  num_new = noCommOpenids.IndexOf(infoAgent.OpenId.ToLower()) >= 0 ? 0 : (info.GetSubTotal() - currentSubTotal - (info.ItemsCommission + info.SecondItemsCommission + info.ThirdItemsCommission));
                                                 * else
                                                 * {
                                                 *  num_new = info.GetSubTotal() - currentSubTotal - (info.ItemsCommission + info.SecondItemsCommission + info.ThirdItemsCommission);
                                                 * }
                                                 */
                                            }
                                        }


                                        commTatalList[commTatalList.Count - 1] = num_new;
                                        break;
                                    }
                                }

                                #endregion 设置无限代理返佣
                            }

                            #region 迪蔓,只返一次无限级
                            if (CustomConfigHelper.Instance.SelectServerAgent)
                            {
                                if (isAgent1 == false && isAgent2 == false && isAgent3 == false)
                                {
                                    //三级之外存在店铺时,向上找最近的代理商
                                    while (!string.IsNullOrEmpty(info4.ReferralPath))
                                    {
                                        string[] arrayReferralPath = info4.ReferralPath.Split(new char[] { '|' });
                                        info4 = GetUserIdDistributors(int.Parse(arrayReferralPath[arrayReferralPath.Length - 1]));
                                        if (info4.IsAgent == 1)
                                        {
                                            System.Data.DataView defaultViewAgent = DistributorGradeBrower.GetAllAgentGrade().DefaultView;  //当前系统中所有代理商等级
                                            defaultViewAgent.RowFilter = " AgentGradeId=" + info4.AgentGradeId;
                                            if (defaultViewAgent.Count == 0)
                                            {
                                                break;
                                            }
                                            num  = 0M;
                                            num2 = 0M;
                                            foreach (LineItemInfo info in order.LineItems.Values)
                                            {
                                                if (info.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                                {
                                                    if (!SettingsManager.GetMasterSettings(false).EnableProfit)
                                                    {
                                                        num += decimal.Parse(defaultViewAgent[0]["FirstCommissionRise"].ToString()) / 100m * info.GetSubTotal();
                                                    }
                                                    else
                                                    {
                                                        num += decimal.Parse(defaultViewAgent[0]["FirstCommissionRise"].ToString()) / 100m * info.GetSubTotalProfit();
                                                    }

                                                    num2 += info.GetSubTotal();
                                                }
                                            }
                                            commTatalList.Add(num);
                                            orderTotalList.Add(num2);
                                            userIdList.Add(info4.UserId);//添加无限级代理商佣金
                                            break;
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                        #region 51跟单特殊处理,如果是分销商在自己店铺购买商品,三级佣金往上推一层(直接佣金为0推至第四级佣金)
                        if (CustomConfigHelper.Instance.Is51gendan && order.UserId == order.ReferralUserId)
                        {
                            commTatalList  = new ArrayList();
                            userIdList     = new ArrayList();
                            orderTotalList = new ArrayList();
                            num            = 0m; num2 = 0m;
                            //获取第四级分销商id
                            string[]         strArrayNew = userIdDistributors.ReferralPath.Split(new char[] { '|' });
                            DistributorsInfo user4       = new DistributorsInfo();
                            if (strArrayNew.Length == 2)
                            {
                                user4 = GetUserIdDistributors(GetUserIdDistributors(strArrayNew[0].ToInt()).ReferralUserId);//第四级的分销商为当前分销商的第三级的上一级分销商
                            }


                            //一级返佣为0
                            DistributorsInfo user1 = GetUserIdDistributors(order.ReferralUserId);
                            if (user1.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo item1 in order.LineItems.Values)
                                {
                                    if (item1.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += 0;//一级不加返佣
                                        num2 += item1.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num); num    = 0m;
                                orderTotalList.Add(num2); num2 = 0m;
                                userIdList.Add(user1.UserId);
                            }
                            //一共有二级的返佣处理
                            if (strArrayNew.Length == 1)
                            {
                                DistributorsInfo user2 = GetUserIdDistributors(int.Parse(strArray[0]));
                                if (user2.ReferralStatus == 0)
                                {
                                    foreach (LineItemInfo item2 in order.LineItems.Values)
                                    {
                                        if (item2.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                        {
                                            num  += item2.ItemsCommission;
                                            num2 += item2.GetSubTotal();
                                        }
                                    }
                                    commTatalList.Add(num);
                                    orderTotalList.Add(num2);
                                    userIdList.Add(user2.UserId);
                                }
                            }
                            //一共有三级的返佣处理
                            if (strArray.Length == 2)
                            {
                                DistributorsInfo user2 = GetUserIdDistributors(int.Parse(strArrayNew[0]));
                                if (user2.ReferralStatus == 0)
                                {
                                    foreach (LineItemInfo item2 in order.LineItems.Values)
                                    {
                                        if (item2.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                        {
                                            num  += item2.SecondItemsCommission;
                                            num2 += item2.GetSubTotal();
                                        }
                                    }
                                    commTatalList.Add(num); num    = 0M;
                                    orderTotalList.Add(num2); num2 = 0M;
                                    userIdList.Add(user2.UserId);
                                }
                                DistributorsInfo user3 = GetUserIdDistributors(int.Parse(strArrayNew[1]));
                                if (user3.ReferralStatus == 0)
                                {
                                    foreach (LineItemInfo item3 in order.LineItems.Values)
                                    {
                                        if (item3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                        {
                                            num  += item3.ItemsCommission;
                                            num2 += item3.GetSubTotal();
                                        }
                                    }
                                    commTatalList.Add(num); num    = 0m;
                                    orderTotalList.Add(num2); num2 = 0m;
                                    userIdList.Add(user3.UserId);
                                }
                            }
                            //四级返佣
                            if (user4 != null && user4.ReferralStatus == 0)
                            {
                                foreach (LineItemInfo item4 in order.LineItems.Values)
                                {
                                    if (item4.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                    {
                                        num  += item4.ThirdItemsCommission;
                                        num2 += item4.GetSubTotal();
                                    }
                                }
                                commTatalList.Add(num);
                                orderTotalList.Add(num2);
                                userIdList.Add(user4.UserId);
                            }
                        }
                        #endregion

                        flag = new DistributorsDao().UpdateTwoCalculationCommission(userIdList, referralUserId, orderId, orderTotalList, commTatalList);
                        for (int i = 0; i < userIdList.Count; i++)
                        {
                            int notDescDistributorGrades = GetNotDescDistributorGrades(userIdList[i].ToString());
                            gradeIdList.Add(notDescDistributorGrades);
                        }
                        flag = new DistributorsDao().UpdateGradeId(gradeIdList, userIdList);
                    }
                }
                RemoveDistributorCache(userIdDistributors.UserId);
            }


            //额外10%的比例给服务门店
            if (order.RedPagerID > 0)    //如果选中了门店
            {
                #region 迪蔓门店服务费10%
                ArrayList commTatalList  = new ArrayList();
                ArrayList userIdList     = new ArrayList();
                string    referralUserId = order.ReferralUserId.ToString();
                string    orderId        = order.OrderId;
                ArrayList orderTotalList = new ArrayList();
                decimal   num            = 0M;
                decimal   num2           = 0M;
                foreach (LineItemInfo info in order.LineItems.Values)
                {
                    if (info.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                    {
                        if (!SettingsManager.GetMasterSettings(false).EnableProfit)
                        {
                            num += decimal.Parse("10") / 100m * info.GetSubTotal();
                        }
                        else
                        {
                            num += decimal.Parse("10") / 100m * info.GetSubTotalProfit();
                        }

                        num2 += info.GetSubTotal();
                    }
                }
                commTatalList.Add(num);
                orderTotalList.Add(num2);
                userIdList.Add(order.RedPagerID);
                flag = new DistributorsDao().UpdateTwoCalculationCommission(userIdList, referralUserId, orderId, orderTotalList, commTatalList);
                #endregion
            }


            OrderRedPagerBrower.CreateOrderRedPager(order.OrderId, order.GetTotal(), order.UserId);
            return(flag);
        }
Ejemplo n.º 7
0
        public static void DistributorGradeChange(DistributorsInfo distributor, string orderid, int newDistributorGradeid)
        {
            DistributorGradeInfo distributorGradeInfo = DistributorGradeBrower.GetDistributorGradeInfo(newDistributorGradeid);

            if (distributorGradeInfo != null && distributorGradeInfo.AddCommission > 0m)
            {
                try
                {
                    MemberInfo member = MemberProcessor.GetMember(distributor.UserId, true);
                    Messenger.SendWeiXinMsg_DistributorGradeChange(member, distributorGradeInfo.Name);
                }
                catch
                {
                }
                SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                if (masterSettings.IsAddCommission == 1)
                {
                    try
                    {
                        DateTime t  = DateTime.Parse(masterSettings.AddCommissionStartTime);
                        DateTime t2 = DateTime.Parse(masterSettings.AddCommissionEndTime).AddDays(1.0);
                        if (DateTime.Now > t && DateTime.Now < t2)
                        {
                            decimal num = distributor.ReferralRequestBalance + distributor.ReferralBlance;
                            DistributorGradeCommissionInfo distributorGradeCommissionInfo = new DistributorGradeCommissionInfo();
                            distributorGradeCommissionInfo.UserId             = distributor.UserId;
                            distributorGradeCommissionInfo.Commission         = distributorGradeInfo.AddCommission;
                            distributorGradeCommissionInfo.PubTime            = DateTime.Now;
                            distributorGradeCommissionInfo.OperAdmin          = "system";
                            distributorGradeCommissionInfo.Memo               = "升级奖励";
                            distributorGradeCommissionInfo.OrderID            = orderid;
                            distributorGradeCommissionInfo.OldCommissionTotal = num;
                            if (!string.IsNullOrEmpty(distributorGradeCommissionInfo.OrderID))
                            {
                                distributorGradeCommissionInfo.ReferralUserId = new OrderDao().GetOrderReferralUserId(distributorGradeCommissionInfo.OrderID);
                            }
                            else
                            {
                                distributorGradeCommissionInfo.OrderID = "U" + DistributorsBrower.GenerateOrderId();
                            }
                            distributorGradeCommissionInfo.CommType = 3;
                            if (distributorGradeCommissionInfo.ReferralUserId == 0)
                            {
                                distributorGradeCommissionInfo.ReferralUserId = distributorGradeCommissionInfo.UserId;
                                distributorGradeCommissionInfo.CommType       = 4;
                            }
                            DistributorGradeCommissionBrower.AddCommission(distributorGradeCommissionInfo);
                            NoticeInfo noticeInfo = new NoticeInfo();
                            noticeInfo.Title = "恭喜分销商获得升级奖励佣金¥" + distributorGradeInfo.AddCommission.ToString("F2");
                            StringBuilder stringBuilder = new StringBuilder();
                            stringBuilder.Append(string.Concat(new string[]
                            {
                                "<p class='textlist'>恭喜<span style='color:#3D9BDF;'>",
                                distributor.StoreName,
                                "</span>自动升级为<span style='color:red;'>",
                                distributorGradeInfo.Name,
                                "</span>分销商",
                                (num > 0m) ? ("(累计获得佣金" + num.ToString("F2") + "元)") : "",
                                ",系统额外奖励佣金",
                                distributorGradeInfo.AddCommission.ToString("F2"),
                                "元!</p>"
                            }));
                            stringBuilder.Append(string.Concat(new string[]
                            {
                                "<p class='textlist'>自",
                                t.ToString("yyyy年MM月dd日"),
                                "至",
                                t2.ToString("yyyy年MM月dd日"),
                                ",分销商等级提升将获得系统奖励的额外佣金。</p>"
                            }));
                            stringBuilder.Append("<table class='table table-bordered' style='text-align: center;'><thead><tr class='firstRow'><th style='text-align:center;'>等级名称</th><th style='text-align:center;'>需要佣金</th><th style='text-align:center;'>奖励佣金</th></tr></thead><tbody>");
                            System.Data.DataTable allDistributorGrade = DistributorGradeBrower.GetAllDistributorGrade();
                            int count = allDistributorGrade.Rows.Count;
                            for (int i = 0; i < count; i++)
                            {
                                stringBuilder.Append(string.Concat(new string[]
                                {
                                    "<tr><td>",
                                    allDistributorGrade.Rows[i]["Name"].ToString(),
                                    "</td><td>¥",
                                    decimal.Parse(allDistributorGrade.Rows[i]["CommissionsLimit"].ToString()).ToString("F2"),
                                    "</td><td>¥",
                                    decimal.Parse(allDistributorGrade.Rows[i]["AddCommission"].ToString()).ToString("F2"),
                                    "</td></tr>"
                                }));
                            }
                            stringBuilder.Append("</tbody></table>");
                            noticeInfo.Memo     = stringBuilder.ToString();
                            noticeInfo.Author   = "system";
                            noticeInfo.AddTime  = DateTime.Now;
                            noticeInfo.IsPub    = 1;
                            noticeInfo.PubTime  = new DateTime?(DateTime.Now);
                            noticeInfo.SendType = 0;
                            noticeInfo.SendTo   = 0;
                            NoticeBrowser.SaveNotice(noticeInfo);
                        }
                    }
                    catch (Exception ex)
                    {
                        Globals.Debuglog("升级奖励异常" + ex.Message, "_Debuglog.txt");
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static void DistributorGradeChange(DistributorsInfo distributor, string orderid, int newDistributorGradeid)
        {
            DistributorGradeInfo distributorGradeInfo = DistributorGradeBrower.GetDistributorGradeInfo(newDistributorGradeid);

            if ((distributorGradeInfo != null) && (distributorGradeInfo.AddCommission > 0M))
            {
                try
                {
                    Messenger.SendWeiXinMsg_DistributorGradeChange(MemberProcessor.GetMember(distributor.UserId, true), distributorGradeInfo.Name);
                }
                catch
                {
                }
                SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                if (masterSettings.IsAddCommission == 1)
                {
                    try
                    {
                        DateTime time  = DateTime.Parse(masterSettings.AddCommissionStartTime);
                        DateTime time2 = DateTime.Parse(masterSettings.AddCommissionEndTime).AddDays(1.0);
                        if ((DateTime.Now > time) && (DateTime.Now < time2))
                        {
                            decimal num = distributor.ReferralRequestBalance + distributor.ReferralBlance;
                            DistributorGradeCommissionInfo info = new DistributorGradeCommissionInfo {
                                UserId             = distributor.UserId,
                                Commission         = distributorGradeInfo.AddCommission,
                                PubTime            = DateTime.Now,
                                OperAdmin          = "system",
                                Memo               = "升级奖励",
                                OrderID            = orderid,
                                OldCommissionTotal = num
                            };
                            if (!string.IsNullOrEmpty(info.OrderID))
                            {
                                info.ReferralUserId = new OrderDao().GetOrderReferralUserId(info.OrderID);
                            }
                            else
                            {
                                info.OrderID = "U" + GenerateOrderId();
                            }
                            info.CommType = 3;
                            if (info.ReferralUserId == 0)
                            {
                                info.ReferralUserId = info.UserId;
                                info.CommType       = 4;
                            }
                            DistributorGradeCommissionBrower.AddCommission(info);
                            NoticeInfo info4 = new NoticeInfo {
                                Title = "恭喜分销商获得升级奖励佣金¥" + distributorGradeInfo.AddCommission.ToString("F2")
                            };
                            StringBuilder builder = new StringBuilder();
                            builder.Append("<p class='textlist'>恭喜<span style='color:#3D9BDF;'>" + distributor.StoreName + "</span>自动升级为<span style='color:red;'>" + distributorGradeInfo.Name + "</span>分销商" + ((num > 0M) ? ("(累计获得佣金" + num.ToString("F2") + "元)") : "") + ",系统额外奖励佣金" + distributorGradeInfo.AddCommission.ToString("F2") + "元!</p>");
                            builder.Append("<p class='textlist'>自" + time.ToString("yyyy年MM月dd日") + "至" + time2.ToString("yyyy年MM月dd日") + ",分销商等级提升将获得系统奖励的额外佣金。</p>");
                            builder.Append("<table class='table table-bordered' style='text-align: center;'><thead><tr class='firstRow'><th style='text-align:center;'>等级名称</th><th style='text-align:center;'>需要佣金</th><th style='text-align:center;'>奖励佣金</th></tr></thead><tbody>");
                            DataTable allDistributorGrade = DistributorGradeBrower.GetAllDistributorGrade();
                            int       count = allDistributorGrade.Rows.Count;
                            for (int i = 0; i < count; i++)
                            {
                                builder.Append("<tr><td>" + allDistributorGrade.Rows[i]["Name"].ToString() + "</td><td>¥" + decimal.Parse(allDistributorGrade.Rows[i]["CommissionsLimit"].ToString()).ToString("F2") + "</td><td>¥" + decimal.Parse(allDistributorGrade.Rows[i]["AddCommission"].ToString()).ToString("F2") + "</td></tr>");
                            }
                            builder.Append("</tbody></table>");
                            info4.Memo     = builder.ToString();
                            info4.Author   = "system";
                            info4.AddTime  = DateTime.Now;
                            info4.IsPub    = 1;
                            info4.PubTime  = new DateTime?(DateTime.Now);
                            info4.SendType = 0;
                            info4.SendTo   = 0;
                            NoticeBrowser.SaveNotice(info4);
                        }
                    }
                    catch (Exception exception)
                    {
                        Globals.Debuglog("升级奖励异常" + exception.Message, "_Debuglog.txt");
                    }
                }
            }
        }