Example #1
0
        public static Model Info(Lebi_User user)
        {
            BaseConfig bc     = ShopCache.GetBaseConfig();
            Model      m      = new Model();
            decimal    Money  = 0;
            string     money_ = Common.GetValue("select sum(Money) from Lebi_Agent_Money where User_id=" + user.id + " and Type_id_AgentMoneyStatus=382 and datediff(d,Time_add,'" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')>" + bc.CommissionMoneyDays + "");

            decimal.TryParse(money_, out Money);
            int UserCount = 0;

            UserCount = B_Lebi_User.Counts("User_id_parent=" + user.id + "");
            int UserCountmonth = 0;

            UserCountmonth = B_Lebi_User.Counts("User_id_parent=" + user.id + " and (datediff(d,Time_Reg,'" + System.DateTime.Now.Date.AddDays(0 - System.DateTime.Now.Day + 1).ToString("yyyy-MM-dd") + "')<=0 and datediff(d,Time_Reg,'" + System.DateTime.Now + "')>=0)");
            int UserCountday = 0;

            UserCountday = B_Lebi_User.Counts("User_id_parent=" + user.id + " and (datediff(d,Time_Reg,'" + System.DateTime.Now.Date.ToString("yyyy-MM-dd") + "')<=0 and datediff(d,Time_Reg,'" + System.DateTime.Now + "')>=0)");
            decimal Commission1 = 0;
            decimal Commission2 = 0;
            decimal Commission3 = 0;

            decimal.TryParse(bc.Angent1_Commission, out Commission1);
            decimal.TryParse(bc.Angent2_Commission, out Commission2);
            decimal.TryParse(bc.Angent3_Commission, out Commission3);
            if (user.DT_id == 0)
            {
                Lebi_Agent_UserLevel agent_userlevel = B_Lebi_Agent_UserLevel.GetModel("UserLevel_id = " + user.UserLevel_id + "");
                if (agent_userlevel != null)
                {
                    if (agent_userlevel.Angent1_Commission != -1)
                    {
                        Commission1 = agent_userlevel.Angent1_Commission;
                    }
                    if (agent_userlevel.Angent2_Commission != -1)
                    {
                        Commission2 = agent_userlevel.Angent2_Commission;
                    }
                    if (agent_userlevel.Angent3_Commission != -3)
                    {
                        Commission3 = agent_userlevel.Angent3_Commission;
                    }
                }
                Lebi_Agent_User agent_user = B_Lebi_Agent_User.GetModel("User_id = " + user.id + "");
                if (agent_user != null)
                {
                    if (agent_user.Angent1_Commission != -1)
                    {
                        Commission1 = agent_user.Angent1_Commission;
                    }
                    if (agent_user.Angent2_Commission != -1)
                    {
                        Commission2 = agent_user.Angent2_Commission;
                    }
                    if (agent_user.Angent3_Commission != -1)
                    {
                        Commission3 = agent_user.Angent3_Commission;
                    }
                }
            }
            else
            {
                Lebi_DT_Agent dt_agent = B_Lebi_DT_Agent.GetModel("DT_id = " + user.DT_id + "");
                if (dt_agent != null)
                {
                    if (dt_agent.IsUsedAgent == 1)
                    {
                        Commission1 = dt_agent.Angent1_Commission;
                        Commission2 = dt_agent.Angent2_Commission;
                        Commission3 = dt_agent.Angent3_Commission;
                    }
                }
            }
            m.Money          = Money;
            m.UserCount      = UserCount;
            m.UserCountmonth = UserCountmonth;
            m.UserCountday   = UserCountday;
            m.Commission1    = Commission1;
            m.Commission2    = Commission2;
            m.Commission3    = Commission3;
            Lebi_UserLevel userlevel = B_Lebi_UserLevel.GetModel(user.UserLevel_id);

            if (userlevel != null)
            {
                if (userlevel.IsUsedAgent == 0) //关闭注册
                {
                    m.Commission1 = 0;
                    m.Commission2 = 0;
                    m.Commission3 = 0;
                }
            }
            return(m);
        }
Example #2
0
        /// <summary>
        /// 推广佣金
        /// </summary>
        private void AgentMoney()
        {
            //SystemLog.Add("计算佣金orderid" + Order.id + "userid" + OrderUser.User_id_parent);
            SystemLog.Add("推广佣金-开始");
            if (OrderUser.User_id_parent == 0)
            {
                return;
            }
            //string Money_Product_Profit_ = Common.GetValue("select sum((Price - Price_Cost)*(Count-Count_Return)) from Lebi_Order_Product where Order_id = " + Order.id + "");
            string  Money_Product_Profit_ = Common.GetValue("select sum((Price - Price_Cost)*Count) from Lebi_Order_Product where Order_id = " + Order.id + "");
            decimal Money_Product_Profit  = 0;

            decimal.TryParse(Money_Product_Profit_, out Money_Product_Profit);
            if (Order.Type_id_OrderType == 212)
            {
                Money_Product_Profit = 0 - Money_Product_Profit;//zhangshijia  退货时产生负数佣金
            }
            //处理一级代理
            Lebi_User user1 = B_Lebi_User.GetModel(OrderUser.User_id_parent);

            if (user1 == null)
            {
                return;
            }
            decimal       yongjin1        = 0; //1级佣金比例
            decimal       yongjin2        = 0; //2级佣金比例
            decimal       yongjin3        = 0; //3级佣金比例
            Lebi_DT_Agent dt_agent        = B_Lebi_DT_Agent.GetModel(0);
            Lebi_User     DT_User         = new Lebi_User();
            Lebi_DT       dt              = new Lebi_DT();
            int           CommissionLevel = 3;

            if (Order.Supplier_id > 0)
            {
                Lebi_Supplier supplier = B_Lebi_Supplier.GetModel(Order.Supplier_id);
                if (supplier.IsSpread == 0)  //商家未开启
                {
                    SystemLog.Add("推广佣金-商家未开启");
                    return;
                }
            }
            if (Order.DT_id > 0)
            {
                Money_Product_Profit = Order.DT_Money;  //如果是分销商,利润为分销商佣金
                dt_agent             = B_Lebi_DT_Agent.GetModel("DT_id=" + Order.DT_id + "");
                dt = B_Lebi_DT.GetModel(Order.DT_id);
                if (dt != null)
                {
                    CommissionLevel = dt.CommissionLevel;
                }
                DT_User = B_Lebi_User.GetModel(dt.User_id);
                if (dt_agent.IsUsedAgent == 0)  //分销商未开启
                {
                    SystemLog.Add("推广佣金-分销商未开启");
                    return;
                }
                //  Money_Product_Profit = Order.DT_Money; ///zhangshijia注释,未找到DT_Money来源
                //List<Lebi_Order_Product> order_pro = B_Lebi_Order_Product.GetModel(" Order_id = " + Order.id + "");
                //foreach (Lebi_Order_Product op in order_pro)
                //{

                //}
            }
            yongjin1 = GetAngentCommission1(dt_agent, user1);
            decimal money = Money_Product_Profit * yongjin1 / 100;

            if (Order.DT_id > 0)
            {
                if (DT_User.Money < money)
                {
                    SystemLog.Add("推广佣金-分销商[" + DT_User.NickName + "-" + DT_User.id + "]金额不足,一级佣金生成失败");
                    return;
                }
            }
            AddMoney(money, user1, 391, 0, 0, 0);
            //SystemLog.Add("计算佣金" + user1.UserName + money.ToString());
            if (Order.DT_id > 0)
            {
                AddMoney(0 - money, DT_User, 391, 0, 0, 0);
            }
            //处理2级代理
            Lebi_User user2 = B_Lebi_User.GetModel(user1.User_id_parent);

            if (user2 == null)
            {
                user2 = new Lebi_User();
            }
            else
            {
                if (CommissionLevel >= 2)
                {
                    yongjin2 = GetAngentCommission2(dt_agent, user2);
                    money    = Money_Product_Profit * yongjin2 / 100;
                    if (Order.DT_id > 0)
                    {
                        if (DT_User.Money < money)
                        {
                            SystemLog.Add("推广佣金-分销商金额不足,二级佣金生成失败");
                            return;
                        }
                    }
                    AddMoney(money, user2, 391, 0, 0, 0);
                    if (Order.DT_id > 0)
                    {
                        AddMoney(0 - money, DT_User, 391, 0, 0, 0);
                    }
                }
            }
            //处理3级代理
            if (CommissionLevel == 2)
            {
                return;
            }
            Lebi_User user3 = B_Lebi_User.GetModel(user2.User_id_parent);

            if (user3 != null)
            {
                yongjin3 = GetAngentCommission3(dt_agent, user3);
                money    = Money_Product_Profit * yongjin3 / 100;
                if (Order.DT_id > 0)
                {
                    if (DT_User.Money < money)
                    {
                        SystemLog.Add("推广佣金-分销商金额不足,三级佣金生成失败");
                        return;
                    }
                }
                AddMoney(money, user3, 391, 0, 0, 0);
                if (Order.DT_id > 0)
                {
                    AddMoney(0 - money, DT_User, 391, 0, 0, 0);
                }
            }
            ////处理条件佣金,佣金历史达到X时,可获得下线,下下线Y%的佣金
            //decimal Angent_Commission_require = 0;
            //decimal.TryParse(bc.Angent_Commission_require, out Angent_Commission_require);
            //decimal yongjin3 = 0;//条件佣金比例
            //decimal.TryParse(bc.Angent_Commission, out yongjin3);
            //money = Money_Product_Profit * yongjin3 / 100;
            //if (user1.AgentMoney_history > Angent_Commission_require)
            //    AddMoney(money, user1, 395, 0, 0, 0);
            //if (user2.AgentMoney_history > Angent_Commission_require)
            //    AddMoney(money, user2, 395, 0, 0, 0);
        }