/// <summary> /// 计算佣金 /// </summary> public void Operation() { SystemLog.Add("计算佣金" + UsedAgent.ToString()); if (UsedAgent) { AgentMoney(); } //if (UsedAgentArea) // AgentAreaMoney(); //if (UsedAgentProduct) // AgentProductMoney(); }
/// <summary> /// 添加佣金记录 /// </summary> /// <param name="money"></param> /// <param name="user"></param> /// <param name="order"></param> /// <param name="type"></param> /// <param name="status"></param> /// <param name="areaid"></param> /// <param name="productid"></param> /// <param name="productparentid"></param> private void AddMoney(decimal money, Lebi_User user, int type, int areaid, int productid, int productparentid, string productnumber = "") { if (money == 0) { SystemLog.Add("金额:" + money + ",会员:" + user.id + ",订单:" + Order.Code + ""); return; } int IsSpread = 1; if (Order.Supplier_id > 0) { Lebi_Supplier supplier = B_Lebi_Supplier.GetModel(Order.Supplier_id); if (supplier != null) { IsSpread = supplier.IsSpread; } } if (IsSpread == 1) //判断是否开启推广佣金 by lebi.kingdge 2015-04-10 { Lebi_Agent_Money model = new Lebi_Agent_Money(); model.Area_id = areaid; model.Money = money; model.Type_id_AgentMoneyType = type; if (Order.Type_id_OrderType == 212)//退货单 { model.Money = 0 - money; } model.Order_Code = Order.Code; model.Order_id = Order.id; model.Product_id = productid; model.Product_id_parent = productparentid; model.Type_id_AgentMoneyStatus = 381; model.Product_Number = productnumber; model.User_id = user.id; model.User_UserName = user.UserName; model.Supplier_id = Order.Supplier_id; model.DT_id = user.DT_id; B_Lebi_Agent_Money.Add(model); UpdateUserMoney(user, model); } }
/// <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); }