Exemple #1
0
        /// <summary>
        /// 代理升级
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="money"></param>
        /// <param name="oldAgentLevel"></param>
        /// <returns></returns>
        public bool UpdateAgentLevel(PinAgent agent, int money, int oldAgentLevel, DateTime oldAddTime)
        {
            if (base.Update(agent, "AgentLevel,addTime"))
            {
                TransactionModel  tran = new TransactionModel();
                PinAgentChangeLog pinAgentChangeLog = new PinAgentChangeLog()
                {
                    Aid         = agent.aId,
                    AgentId     = agent.id,
                    ChangeMoney = money,
                    Remark      = $"代理商升级由之前的{oldAgentLevel}等级升级为{agent.AgentLevel},花费{money * 0.01}元",
                    ChangeType  = 1,
                    AddTime     = DateTime.Now
                };
                tran.Add(PinAgentChangeLogBLL.SingleModel.BuildAddSql(pinAgentChangeLog));
                PinGoodsOrder pinOrder = new PinGoodsOrder()
                {
                    money = money
                };
                UpdateIncome(agent, pinOrder, tran);
                PinAgentIncomeLogBLL.SingleModel.AddAgentLog(agent, pinOrder, tran);//插入提成日志
                if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray))
                {
                    agent.addTime    = oldAddTime;
                    agent.AgentLevel = oldAgentLevel;
                    base.Update(agent, "AgentLevel,addTime");
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 代理续费
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="money"></param>
        /// <returns></returns>
        public bool AddAgentTime(PinAgent agent, int money, int timeLength)
        {
            TransactionModel  tran = new TransactionModel();
            PinAgentChangeLog pinAgentChangeLog = new PinAgentChangeLog()
            {
                Aid         = agent.aId,
                AgentId     = agent.id,
                ChangeMoney = money,
                Remark      = $"代理商续费{timeLength}年,花费{money * 0.01}元",
                ChangeType  = 0,
                AddTime     = DateTime.Now
            };

            tran.Add(PinAgentChangeLogBLL.SingleModel.BuildAddSql(pinAgentChangeLog));

            if (agent.IsExpired)
            {
                //如果过期了则当前时间为入驻时间
                agent.addTime   = DateTime.Now;
                agent.AgentTime = timeLength;
                tran.Add(base.BuildUpdateSql(agent, "addTime,AgentTime"));
            }
            else
            {
                agent.AgentTime += timeLength;
                tran.Add(base.BuildUpdateSql(agent, "AgentTime"));
            }



            PinGoodsOrder pinOrder = new PinGoodsOrder()
            {
                money = money
            };

            UpdateIncome(agent, pinOrder, tran);
            PinAgentIncomeLogBLL.SingleModel.AddAgentLog(agent, pinOrder, tran);//插入提成日志
            return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
        }
Exemple #3
0
        /// <summary>
        /// 平台后台-配置代理
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int SetAgent(int aid, int userId, int state, out string msg, int agentMoney = 0)
        {
            int      code  = 0;
            PinAgent agent = null;

            switch (state)
            {
            case 0:    //取消代理
                agent = GetModelByUserId(userId);
                if (agent == null)
                {
                    code = 1;
                    msg  = "操作成功";
                }
                else
                {
                    agent.state = 0;
                    code        = Update(agent, "state") ? 1 : 0;
                    msg         = code == 1 ? "操作成功" : "操作失败";
                }
                break;

            case 1:
                agent = GetModel($"userid={userId}");
                if (agent == null)
                {
                    agent = new PinAgent
                    {
                        aId        = aid,
                        userId     = userId,
                        addTime    = DateTime.Now,
                        state      = 1,
                        AgentLevel = 1,
                        AgentTime  = 1
                    };
                    code = Convert.ToInt32(Add(agent)) > 0 ? 1 : 0;
                    msg  = code == 1 ? "操作成功" : "操作失败";
                }
                else
                {
                    agent.AgentLevel = 1;
                    agent.AgentTime  = 1;
                    agent.addTime    = DateTime.Now;
                    agent.state      = 1;
                    code             = Update(agent, "state,AgentLevel,AgentTime,addTime") ? 1 : 0;
                    msg = code == 1 ? "操作成功" : "操作失败";
                }

                PinGoodsOrder pinOrder = new PinGoodsOrder()
                {
                    money = agentMoney
                };
                TransactionModel  tran = new TransactionModel();
                PinAgentChangeLog pinAgentChangeLog = new PinAgentChangeLog()
                {
                    Aid         = agent.aId,
                    AgentId     = agent.id,
                    ChangeMoney = agentMoney,
                    Remark      = $"成为代理,花费{agentMoney * 0.01}元",
                    ChangeType  = 2,
                    AddTime     = DateTime.Now
                };
                tran.Add(PinAgentChangeLogBLL.SingleModel.BuildAddSql(pinAgentChangeLog));
                UpdateIncome(agent, pinOrder, tran);
                PinAgentIncomeLogBLL.SingleModel.AddAgentLog(agent, pinOrder, tran);    //插入提成日志

                //分提成
                if (!base.ExecuteTransactionDataCorect(tran.sqlArray))
                {
                    agent.state = 0;
                    Update(agent, "state");
                    code = 0;
                    msg  = "代理分成异常";
                }



                break;

            default:
                msg = "参数错误";
                break;
            }
            return(code);
        }