/// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, Sxc_CommissionRecordEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public ActionResult SaveForm(string keyValue, Sxc_CommissionRecordEntity entity)
        {
            var obj = sxc_commissionrecordbll.GetEntity(keyValue);

            if (TryUpdateModel(obj, new string[] { "Memo" }))
            {
                sxc_commissionrecordbll.SaveForm(keyValue, obj);
            }
            //页面未传入全部数据会有外键问题
            //sxc_commissionrecordbll.SaveForm(keyValue, entity);
            return(Success("操作成功。"));
        }
Example #3
0
        public void DistrCommission(IRepository db, Sxc_UserPaymentEntity entity)
        {
            entity.State     = 1;
            entity.DistrTime = DateTime.Now;

            var agent = db.FindEntity <Sxc_AgentEntity>(t => t.ID == entity.UserID);

            //&& agent.IsValid.Value 不需要本身是有效代理
            if (agent.Type == 1)
            {
                if (agent.PID.HasValue)
                {
                    var agent1 = db.FindEntity <Sxc_AgentEntity>(t => t.ID == agent.PID);

                    var per1 = GetZxsPercent(agent1.Level);

                    var amount1 = entity.DistrAmount * per1;

                    entity.Commission += amount1;
                    agent1.Commission += amount1;

                    var record1 = new Sxc_CommissionRecordEntity
                    {
                        AgentID       = agent1.ID,
                        CreateTime    = DateTime.Now,
                        State         = 0,
                        UserPaymentID = entity.ID,
                        Commission    = amount1
                    };

                    db.Insert(record1);
                    db.Update(agent1);

                    if (agent1.PID.HasValue)
                    {
                        var agent2 = db.FindEntity <Sxc_AgentEntity>(t => t.ID == agent1.PID);

                        var per2 = GetZxsPercent(agent2.Level);

                        if (per2 > per1)
                        {
                            per2 = per2 - per1;
                        }
                        else
                        {
                            per2 = 0.05m;
                        }

                        var amount2 = entity.DistrAmount * per2;

                        entity.Commission += amount2;
                        agent2.Commission += amount2;

                        var record2 = new Sxc_CommissionRecordEntity
                        {
                            AgentID       = agent2.ID,
                            CreateTime    = DateTime.Now,
                            State         = 0,
                            UserPaymentID = entity.ID,
                            Commission    = amount2
                        };

                        db.Insert(record2);
                        db.Update(agent2);
                    }
                }
            }

            //&& agent.IsValid.Value
            if (agent.Type == 2)
            {
                if (agent.PID.HasValue)
                {
                    var agent1 = db.FindEntity <Sxc_AgentEntity>(t => t.ID == agent.PID);

                    //var amount1 = GetFzxsCommission(agent1.Level);
                    var amount1 = entity.DistrAmount * GetFzxsCommission(agent1.Level);

                    entity.Commission += amount1;
                    agent1.Commission += amount1;

                    var record1 = new Sxc_CommissionRecordEntity
                    {
                        AgentID       = agent1.ID,
                        CreateTime    = DateTime.Now,
                        State         = 0,
                        UserPaymentID = entity.ID,
                        Commission    = amount1
                    };

                    db.Insert(record1);
                    db.Update(agent1);

                    if (agent1.PID.HasValue)
                    {
                        var agent2 = db.FindEntity <Sxc_AgentEntity>(t => t.ID == agent1.PID);

                        //var amount2 = 1000;
                        var amount2 = entity.DistrAmount * 0.05m;

                        entity.Commission += amount2;
                        agent2.Commission += amount2;

                        var record2 = new Sxc_CommissionRecordEntity
                        {
                            AgentID       = agent2.ID,
                            CreateTime    = DateTime.Now,
                            State         = 0,
                            UserPaymentID = entity.ID,
                            Commission    = amount2
                        };

                        db.Insert(record2);
                        db.Update(agent2);

                        List <Sxc_AgentEntity> SupAgents = new List <Sxc_AgentEntity>();

                        GetSupAgents(db, agent2, SupAgents);

                        foreach (var sup in SupAgents)
                        {
                            //var amountsup = 1000;
                            var amountsup = entity.DistrAmount * 0.05m;

                            entity.Commission += amountsup;
                            sup.Commission    += amountsup;

                            var recordsup = new Sxc_CommissionRecordEntity
                            {
                                AgentID       = sup.ID,
                                CreateTime    = DateTime.Now,
                                State         = 0,
                                UserPaymentID = entity.ID,
                                Commission    = amountsup
                            };

                            db.Insert(recordsup);
                            db.Update(sup);
                        }
                    }
                }
            }
            //直属
            if (agent.Type == 3)
            {
                if (agent.PID.HasValue)
                {
                    var agent1 = db.FindEntity <Sxc_AgentEntity>(t => t.ID == agent.PID);

                    //公司直招
                    if (agent1.Level < 4)
                    {
                        var distrAmount = entity.DistrAmount * 0.3m;
                        var amount1     = distrAmount * GetFzxsCommission(agent1.Level);

                        entity.Commission += amount1;
                        agent1.Commission += amount1;

                        var record1 = new Sxc_CommissionRecordEntity
                        {
                            AgentID       = agent1.ID,
                            CreateTime    = DateTime.Now,
                            State         = 0,
                            UserPaymentID = entity.ID,
                            Commission    = amount1
                        };

                        db.Insert(record1);
                        db.Update(agent1);

                        List <Sxc_AgentEntity> SupAgents = new List <Sxc_AgentEntity>();
                        GetSupAgents(db, agent1, SupAgents);

                        foreach (var sup in SupAgents)
                        {
                            var amountsup = distrAmount * 0.15m;
                            entity.Commission += amountsup;
                            sup.Commission    += amountsup;

                            var recordsup = new Sxc_CommissionRecordEntity
                            {
                                AgentID       = sup.ID,
                                CreateTime    = DateTime.Now,
                                State         = 0,
                                UserPaymentID = entity.ID,
                                Commission    = amountsup
                            };

                            db.Insert(recordsup);
                            db.Update(sup);
                        }
                    }
                    //学员发展
                    //level=4
                    else
                    {
                        var amount1 = entity.DistrAmount * GetFzxsCommission(agent1.Level);

                        entity.Commission += amount1;
                        agent1.Commission += amount1;

                        var record1 = new Sxc_CommissionRecordEntity
                        {
                            AgentID       = agent1.ID,
                            CreateTime    = DateTime.Now,
                            State         = 0,
                            UserPaymentID = entity.ID,
                            Commission    = amount1
                        };

                        db.Insert(record1);
                        db.Update(agent1);

                        if (agent1.PID.HasValue)
                        {
                            var agent2 = db.FindEntity <Sxc_AgentEntity>(t => t.ID == agent1.PID);

                            var amount2 = entity.DistrAmount * 0.05m;

                            entity.Commission += amount2;
                            agent2.Commission += amount2;

                            var record2 = new Sxc_CommissionRecordEntity
                            {
                                AgentID       = agent2.ID,
                                CreateTime    = DateTime.Now,
                                State         = 0,
                                UserPaymentID = entity.ID,
                                Commission    = amount2
                            };

                            db.Insert(record2);
                            db.Update(agent2);
                        }
                    }
                }
            }

            entity.FinalAmount = entity.Amount - entity.Commission;
        }