public void Add(ApplyJoin ApplyJoin, string code)
        {
            if (code.ToUpper() != Session.GetCheckCode())
            {
                Response.Write("验证码错误");
                return;
            }
            Session.ClearCheckCode();
            ApplyJoin.State    = 1;
            ApplyJoin.AddTime  = DateTime.Now;
            ApplyJoin.AgentId  = BasicUsers.Agent;
            ApplyJoin.AgentAId = BasicUsers.AId;
            SysAgent SysAgent = Entity.SysAgent.FirstOrNew(f => f.Id == BasicUsers.Agent);

            ApplyJoin.AgentName = SysAgent.Name;
            SysAgent TopSysAgent = SysAgent.GetTopAgent(Entity);

            if (TopSysAgent.IsTeiPai == 1)
            {
                ApplyJoin.TiePaiAgentId   = TopSysAgent.Id;
                ApplyJoin.TiePaiAgentName = TopSysAgent.Name;
            }
            Entity.ApplyJoin.AddObject(ApplyJoin);
            Entity.SaveChanges();
            Response.Redirect("Success.html");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新旧版本判断 for IOS:8.0.3/安卓:8.0.6
        /// true:新版 false:旧版
        /// </summary>
        public static bool NewOrOldVersion(SysAgent SysAgent, Equipment Equipment, LokFuEntity Entity)
        {
            //处理贴牌相关
            bool result      = false;
            var  topSysAgent = SysAgent.GetTopAgent(Entity);

            if (!Equipment.SoftVer.IsNullOrEmpty())
            {
                Version v1 = new Version(Equipment.SoftVer);//当前版本
                Version v2 = new Version("1.0");

                if (Equipment.RqType.ToLower() == "apple")
                {
                    //苹果
                    if (topSysAgent.IsTeiPai == 0)//好付
                    {
                        v2 = new Version("8.0.3");
                    }
                    else//贴牌
                    {
                        v2 = new Version("8.0");
                    }
                }
                else if (Equipment.RqType.ToLower() == "android")
                {
                    //安卓
                    if (topSysAgent.IsTeiPai == 0)//好付
                    {
                        v2 = new Version("8.0.6");
                    }
                    else //贴牌
                    {
                        v2 = new Version("8.0.0");
                    }
                }
                if (v1 > v2)
                {
                    result = true;
                }
            }
            return(result);
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[UsersReg]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }

            //JObject pp = (JObject)p;
            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);
            if (Users.UserName.IsNullOrEmpty())
            {
                //
                DataObj.OutError("1000");
                return;
            }
            //手机号码黑名单验证
            if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Users.UserName && UBL.State == 1) != null)
            {
                //提示暂不支持您手机号入网
                DataObj.OutError("2026");
                return;
            }
            //验证是否重复
            Users Old = Entity.Users.FirstOrDefault(n => n.UserName == Users.UserName);

            if (Old != null)
            {
                DataObj.OutError("2005");
                return;
            }

            DateTime Today  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            SysSet   SysSet = Entity.SysSet.FirstOrNew();
            //统计今天已经发送注册验证码次数
            int Times = Entity.SMSCode.Count(n => n.UId == 0 && n.Mobile == Users.UserName && n.CType == 1 && n.AddTime >= Today);

            if (Times >= SysSet.SMSTimes)
            {
                DataObj.OutError("2031");
                return;
            }
            if (Times > 0)   //第一次发送不获取,以节少系统资源
            {
                SMSCode SMSCode = Entity.SMSCode.Where(n => n.UId == 0 && n.Mobile == Users.UserName && n.CType == 1 && n.AddTime >= Today).OrderByDescending(n => n.Id).FirstOrDefault();
                if (SMSCode.AddTime.AddMinutes(1) >= DateTime.Now)   //最后一次发送到现在不足1分钟
                {
                    DataObj.OutError("2032");
                    return;
                }
            }
            //失效之前获取验证码
            IList <SMSCode> List = Entity.SMSCode.Where(n => n.UId == 0 && n.Mobile == Users.UserName && n.CType == 1 && n.State == 1).ToList();

            foreach (var p in List)
            {
                p.State = 0;
            }
            Entity.SaveChanges();

            //生成验证码
            string Code = Utils.RandomSMSCode(4);

            SMSCode SSC = new SMSCode();

            SSC.CType   = 1;
            SSC.UId     = 0;
            SSC.Mobile  = Users.UserName;
            SSC.Code    = Code;
            SSC.AddTime = DateTime.Now;
            SSC.State   = 1;
            Entity.SMSCode.AddObject(SSC);
            Entity.SaveChanges();

            SysAgent SA = Entity.SysAgent.FirstOrNew(n => n.Id == Users.Agent);

            SA = SA.GetTopAgent(Entity);
            //发送验证码
            SSC.SendSMS(SysSet, SA, Entity);

            DataObj.Data = "";
            DataObj.Code = "0000";
            DataObj.OutString();
            //Tools.OutString(ErrInfo.Return("0000"));
        }
Ejemplo n.º 4
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[UsersGetPayPass]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            //JObject pp = (JObject)p;

            //身份证号,手机号(登录帐户),邮箱
            //CardId,UserName,Email

            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);
            if (Users.UserName.IsNullOrEmpty() || Users.CardId.IsNullOrEmpty() || Users.TrueName.IsNullOrEmpty() || Users.CardNum.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            ////手机号码黑名单验证
            //if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Users.UserName && UBL.State == 1) != null)
            //{
            //    //提示暂不支持您手机号入网
            //    DataObj.OutError("2026");
            //    return;
            //}
            //if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Users.CardId && UBL.State == 2) != null)
            //{
            //    //提示暂不支持您手机号入网
            //    DataObj.OutError("2027");
            //    return;
            //}
            Users BaseUsers = Entity.Users.Where(n => n.UserName == Users.UserName).FirstOrDefault();

            if (BaseUsers == null)//用户不存在
            {
                DataObj.OutError("2001");
                return;
            }
            if (BaseUsers.State != 1)
            {
                DataObj.OutError("2003");
                return;
            }
            if (BaseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (BaseUsers.MiBao != 1)
            {
                DataObj.OutError("2008");
                return;
            }

            //实名信息验证,支付密码密段是实名认证的
            if (Users.TrueName != BaseUsers.TrueName)
            {
                DataObj.OutError("2011");
                return;
            }
            if (Users.CardId != BaseUsers.CardId)
            {
                DataObj.OutError("2012");
                return;
            }

            //int BankNum = Entity.UserCard.Count(n => n.UId == BaseUsers.Id);
            //BaseUsers.BankNum = BankNum;

            IList <UserCard> UserCardList = Entity.UserCard.Where(n => n.UId == BaseUsers.Id && n.State == 1).ToList();

            if (UserCardList.Count() == 0)
            {
                DataObj.OutError("2099");
                return;
            }
            else
            {
                UserCard UserCard = UserCardList.FirstOrDefault(n => n.UId == BaseUsers.Id && n.Card == Users.CardNum);
                if (UserCard == null)
                {
                    DataObj.OutError("2013");
                    return;
                }
            }

            DateTime Today  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            SysSet   SysSet = Entity.SysSet.FirstOrNew();

            if (SysSet.AuthType != 3 && SysSet.AuthType != 1)
            {
                DataObj.OutError("2061");//----------------
                return;
            }
            //统计今天已经发送注册验证码次数
            int Times = Entity.SMSCode.Count(n => n.UId == BaseUsers.Id && n.Mobile == BaseUsers.UserName && n.CType == 3 && n.AddTime >= Today);

            if (Times >= SysSet.SMSTimes)
            {
                DataObj.OutError("2031");
                return;
            }
            if (Times > 0)
            { //第一次发送不获取,以节少系统资源
                SMSCode SMSCode = Entity.SMSCode.Where(n => n.UId == BaseUsers.Id && n.Mobile == BaseUsers.UserName && n.CType == 3 && n.AddTime >= Today).OrderByDescending(n => n.Id).FirstOrDefault();
                if (SMSCode.AddTime.AddMinutes(1) >= DateTime.Now)
                { //最后一次发送到现在不足1分钟
                    DataObj.OutError("2032");
                    return;
                }
            }
            //失效之前获取验证码
            IList <SMSCode> List = Entity.SMSCode.Where(n => n.UId == BaseUsers.Id && n.Mobile == BaseUsers.UserName && n.CType == 3 && n.State == 1).ToList();

            foreach (var p in List)
            {
                p.State = 0;
            }
            Entity.SaveChanges();

            //生成验证码
            string Code = Utils.RandomSMSCode(6);

            SMSCode SSC = new SMSCode();

            SSC.CType   = 3;
            SSC.UId     = BaseUsers.Id;
            SSC.Mobile  = BaseUsers.UserName;
            SSC.Code    = Code;
            SSC.AddTime = DateTime.Now;
            SSC.State   = 1;
            Entity.SMSCode.AddObject(SSC);
            Entity.SaveChanges();

            SysAgent SA = Entity.SysAgent.FirstOrNew(n => n.Id == BaseUsers.Agent);

            SA = SA.GetTopAgent(Entity);
            //发送验证码
            SSC.SendSMS(SysSet, SA, Entity);

            //BaseUsers.Cols = "BankNum";
            //DataObj.Data = BaseUsers.OutJson();
            DataObj.Data = "";
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[UsersInfo]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            //JObject pp = (JObject)p;
            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);
            if (Users.Token.IsNullOrEmpty())
            {
                //
                DataObj.OutError("1000");
                return;
            }

            Users = Entity.Users.FirstOrDefault(n => n.Token == Users.Token);
            if (Users == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (Users.State != 1)
            {
                DataObj.OutError("2003");
                return;
            }
            //===========================================================
            if (!Equipment.SoftVer.IsNullOrEmpty())
            {
                Version  v1       = new Version(Equipment.SoftVer);//当前版本
                Version  v2       = new Version("1.0");
                SysAgent SysAgent = new SysAgent();
                bool     IsTeiPai = false;
                //--------------------------------------------------------
                //判断是否是贴牌
                if (!Users.Id.IsNullOrEmpty())
                {
                    SysAgent = Entity.SysAgent.FirstOrDefault(n => n.Id == Users.Agent && n.State == 1);
                    if (SysAgent != null)
                    {
                        SysAgent = SysAgent.GetTopAgent(Entity);
                        if (SysAgent != null)
                        {
                            if (SysAgent.IsTeiPai == 1)
                            {
                                IsTeiPai = true;
                            }
                        }
                    }
                }
                //--------------------------------------------------------
                if (Equipment.RqType.ToLower() == "apple")
                {
                    //苹果
                    if (!IsTeiPai)//好付
                    {
                        v2 = new Version("8.0.1");
                    }
                    else//贴牌
                    {
                        v2 = new Version("6.0.0");
                    }
                }
                else if (Equipment.RqType.ToLower() == "android")
                {
                    //安卓
                    if (!IsTeiPai)//好付
                    {
                        v2 = new Version("8.0.2");
                    }
                    else //贴牌
                    {
                        v2 = new Version("6.0.0");
                    }
                }
                if (v1 >= v2)
                {
                    if (Users.IfCanIn == 0)
                    {
                        //已经是最新版
                        Users.IfCanIn = 1;
                        Users.AutoBao = 0;
                        Entity.SaveChanges();
                    }
                }
            }
            //===========================================================
            Users.AgentTel = "";

            string CashName = "UsersAgentTel" + Users.Agent.ToString();

            if (HasCache)
            {
                Users.AgentTel = CacheBuilder.EntityCache.Get(CashName, null) as string;
            }
            if (Users.AgentTel.IsNullOrEmpty())
            {
                if (!Users.Agent.IsNullOrEmpty())
                {
                    SysAgent SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == Users.Agent);
                    Users.AgentTel = SysAgent.Tel;
                }
                if (Users.AgentTel.IsNullOrEmpty())
                {
                    SysSet SysSet = Entity.SysSet.FirstOrNew();
                    Users.AgentTel = SysSet.Tel;
                }
                if (HasCache && !Users.AgentTel.IsNullOrEmpty())
                {
                    CacheBuilder.EntityCache.Remove(CashName, null);
                    CacheBuilder.EntityCache.Add(CashName, Users.AgentTel, DateTime.Now.AddMinutes(60), null);
                }
            }

            if (Users.Pic.IsNullOrEmpty())
            {
                Users.Pic = "none.png";
            }
            Users.Pic      = Utils.ImageUrl("UsersPic", Users.Pic, AppImgPath);
            Users.CardPic  = Utils.ImageUrl("Users", Users.CardPic, AppImgPath);
            Users.CardFace = Utils.ImageUrl("Users", Users.CardFace, AppImgPath);
            Users.CardBack = Utils.ImageUrl("Users", Users.CardBack, AppImgPath);

            int BankNum = Entity.UserCard.Count(n => n.UId == Users.Id && n.State == 1 && n.Type == 1);

            Users.BankNum = BankNum;


            CashName = "UsersMsgCount" + Users.Id.ToString();
            string count = string.Empty;

            if (HasCache)
            {
                count = CacheBuilder.EntityCache.Get(CashName, null) as string;
            }
            if (count == string.Empty || count == null)
            {
                string uid   = string.Format(",{0},", Users.Id);
                int    Count = Entity.MsgUser.Count(n => (n.UId == Users.Id && n.State == 1) || (n.UId == 0 && !n.ReadUsers.Contains(uid) && !n.DeleteUsers.Contains(uid) && n.AddTime > Users.AddTime && (n.SendUsers.Contains(uid) || n.SendUsers == null || n.SendUsers == "") && n.State > 0));
                Users.MsgCount = Count;
                count          = Count.ToString();
                if (HasCache)
                {
                    CacheBuilder.EntityCache.Remove(CashName, null);
                    CacheBuilder.EntityCache.Add(CashName, count, DateTime.Now.AddMinutes(6), null);
                }
            }
            else
            {
                Users.MsgCount = Int32.Parse(count);
            }

            //AutoCashBank,AutoBank
            CashName = "UsersAutoBank" + Users.Id.ToString();
            string AutoBank = string.Empty;

            if (!Users.AutoCashBank.IsNullOrEmpty() && Users.AutoCash == 1)
            {
                if (HasCache)
                {
                    AutoBank = CacheBuilder.EntityCache.Get(CashName, null) as string;
                }
                if (AutoBank.IsNullOrEmpty())
                {
                    UserCard UserCard = Entity.UserCard.FirstOrDefault(n => n.Id == Users.AutoCashBank && n.UId == Users.Id && n.State == 1);
                    if (UserCard != null)
                    {
                        AutoBank = UserCard.Card;
                        if (HasCache)
                        {
                            CacheBuilder.EntityCache.Remove(CashName, null);
                            CacheBuilder.EntityCache.Add(CashName, AutoBank, DateTime.Now.AddMinutes(1), null);
                        }
                    }
                }
            }
            Users.AutoBank = AutoBank;

            if (Users.Amount < 0)
            {
                Users.Amount = 0;
            }
            //输出格式化钱
            Users.Amount = Users.Amount.Floor();
            Users.Frozen = Users.Frozen.Floor();

            var BaoConfig = Entity.BaoConfig.FirstOrNew();

            Users.GetCost = BaoConfig.GetCost;
            Users.YearPer = BaoConfig.YearPer;

            if (Users.CardPic.IsNullOrEmpty() && Users.CardType == 1)
            {
                Users.IsAnewUpImg = 1;
            }
            SysMoneySet SysMoneySet = Entity.SysMoneySet.FirstOrNew();

            Users.VipPrice = SysMoneySet.VipPrice;
            //Users.Cols = "Id,UserName,NeekName,TrueName,Mobile,QQ,Email,Address,Amount,Frozen,CardId,Pic,CardStae,CardFace,CardBack,CardPic,MiBao,CardNum";
            Users.Cols   = "Id,UserName,NeekName,TrueName,Mobile,QQ,Email,Address,Amount,Frozen,CardId,Pic,CardStae,CardFace,CardBack,CardPic,MiBao,Token,CardNum,CardRemark,BankNum,MsgCount,AgentTel,YYOpenState,InTypeMobile,InTypePC,T0Times,T1Times,AutoBao,AutoCash,AutoCashMoney,AutoCashBank,AutoBank,GetCost,YearPer,YAmount,AllRec,LastRec,IsAnewUpImg,IsVip,VipPrice";
            DataObj.Data = Users.OutJson();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
Ejemplo n.º 6
0
        public void GetCode(string UserName, string tuCode, int Agent = 0)
        {
            if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == UserName && UBL.State == 1) != null)
            {
                Response.Write("6");
                return;
            }
            if (tuCode.IsNullOrEmpty())
            {
                Response.Write("4");
                return;
            }
            if (tuCode.ToUpper() != Session.GetCheckCode())
            {
                Response.Write("4");
                return;
            }
            Session.ClearCheckCode();
            if (UserName.IsNullOrEmpty())
            {
                return;
            }
            //验证是否重复
            Users Old = Entity.Users.FirstOrDefault(n => n.UserName == UserName);

            if (Old != null)
            {
                Response.Write("1");
                return;
            }
            DateTime Today  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            SysSet   SysSet = Entity.SysSet.FirstOrNew();
            //统计今天已经发送注册验证码次数
            int Times = Entity.SMSCode.Count(n => n.UId == 0 && n.Mobile == UserName && n.CType == 1 && n.AddTime >= Today);

            if (Times >= SysSet.SMSTimes)
            {
                Response.Write("2");
                return;
            }
            if (Times > 0)
            { //第一次发送不获取,以节少系统资源
                SMSCode SMSCode = Entity.SMSCode.Where(n => n.UId == 0 && n.Mobile == UserName && n.CType == 1 && n.AddTime >= Today).OrderByDescending(n => n.Id).FirstOrDefault();
                if (SMSCode.AddTime.AddMinutes(1) >= DateTime.Now)
                { //最后一次发送到现在不足1分钟
                    Response.Write("3");
                    return;
                }
            }
            //失效之前获取验证码
            IList <SMSCode> List = Entity.SMSCode.Where(n => n.UId == 0 && n.Mobile == UserName && n.CType == 1 && n.State == 1).ToList();

            foreach (var p in List)
            {
                p.State = 0;
            }
            Entity.SaveChanges();
            //生成验证码
            string  Code = Utils.RandomSMSCode(4);
            SMSCode SSC  = new SMSCode();

            SSC.CType   = 1;
            SSC.UId     = 0;
            SSC.Mobile  = UserName;
            SSC.Code    = Code;
            SSC.AddTime = DateTime.Now;
            SSC.State   = 1;
            Entity.SMSCode.AddObject(SSC);
            Entity.SaveChanges();

            SysAgent SA = Entity.SysAgent.FirstOrNew(n => n.Id == Agent);

            SA = SA.GetTopAgent(Entity);
            //发送验证码
            SSC.SendSMS(SysSet, SA, Entity);

            Response.Write("OK");
        }
Ejemplo n.º 7
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[UsersReg_2_0]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            //JObject pp = (JObject)p;
            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);
            if (Users.Mobile.IsNullOrEmpty())
            {
                //
                DataObj.OutError("1000");
                return;
            }

            //验证是否重复
            Users Old = Entity.Users.FirstOrDefault(n => n.Mobile == Users.Mobile);

            if (Old != null)
            {
                DataObj.OutError("2005");
                return;
            }
            //手机号码黑名单验证
            if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Users.Mobile && UBL.State == 1) != null)
            {
                //提示暂不支持该手机号入网
                DataObj.OutError("2035");
                return;
            }
            Users baseUsers = null;

            if (Users.Token.IndexOf("Print|") == -1)
            {
                baseUsers = Entity.Users.FirstOrDefault(n => n.Token == Users.Token);
            }
            else
            {
                baseUsers = Entity.Users.FirstOrDefault(n => n.PrintToken == Users.Token);
            }
            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (baseUsers.MiBao != 1)//未设置支付密码
            {
                //DataObj.OutError("2008");
                //return;
            }

            int IntervalCountAll = Entity.Users.Count(o => o.MyPId == baseUsers.Id && o.ShareType == 4);//统计所有邀请人数

            if (IntervalCountAll > 20)
            {
                //20人以上,验证其认证通过率
                int IntervalCountRZ = Entity.Users.Count(o => o.MyPId == baseUsers.Id && o.ShareType == 4 && o.CardStae == 2);//统计所有邀请并认证人数
                if (IntervalCountRZ * 10 < IntervalCountAll)
                {
                    DataObj.OutError("2102");
                    return;
                }
            }

            SysSet   SysSet        = this.Entity.SysSet.FirstOrNew();
            DateTime IntervalTime  = DateTime.Now.AddSeconds(0 - SysSet.YaoQingIntervalTime);
            int      IntervalCount = this.Entity.Users.Where(o => o.MyPId == baseUsers.Id && o.ShareType == 4 && o.AddTime > IntervalTime).Count();

            if (IntervalCount >= SysSet.YaoQingIntervalNumber)
            {
                DataObj.OutError("2101");
                return;
            }

            //邀请注册
            Users inviteUsers = new Users();

            inviteUsers.UserName = Users.Mobile;
            inviteUsers.Mobile   = Users.Mobile;
            inviteUsers.Agent    = baseUsers.Agent;
            inviteUsers.AId      = baseUsers.AId;
            inviteUsers.MyPId    = baseUsers.Id;

            inviteUsers.ShareType  = 4;
            inviteUsers.RegAddress = "短信邀请";
            inviteUsers.X          = "0";
            inviteUsers.Y          = "0";

            string PassWord = Utils.GetCode();

            inviteUsers.PassWord = PassWord.GetMD5();

            inviteUsers.MobileState = 2;
            inviteUsers.EmailState  = 0;
            inviteUsers.CardStae    = 0;
            inviteUsers.State       = 0;
            inviteUsers.Amount      = 0;
            inviteUsers.Frozen      = 0;
            inviteUsers.AddTime     = DateTime.Now;
            inviteUsers.PayPwd      = "";

            Entity.Users.AddObject(inviteUsers);

            //=======================================
            UserTrack UserTrack = new UserTrack();

            UserTrack.ENo        = string.Empty;
            UserTrack.OPType     = "邀请注册";
            UserTrack.IfYY       = string.Empty;
            UserTrack.EqMobile   = string.Empty;
            UserTrack.SysVer     = string.Empty;
            UserTrack.SoftVer    = string.Empty;
            UserTrack.SignalType = string.Empty;
            UserTrack.GPSAddress = string.Empty;
            UserTrack.GPSX       = "0";
            UserTrack.GPSY       = "0";
            Users.SeavGPSLog(UserTrack, Entity);
            //=======================================

            //自动开通
            //IList<PayConfig> PCList = Entity.PayConfig.Where(n => n.State == 1).ToList();
            //foreach (var PC in PCList)
            //{
            //    UserPay UserPay = new UserPay();
            //    UserPay.UId = inviteUsers.Id;
            //    UserPay.PId = PC.Id;
            //    UserPay.Cost = (double)PC.CostUser;
            //    Entity.UserPay.AddObject(UserPay);
            //}

            SysAgent SysAgent = Entity.SysAgent.FirstOrDefault(n => n.Id == inviteUsers.Agent && n.State == 1);

            if (SysAgent == null)
            {
                SysAgent          = Entity.SysAgent.FirstOrDefault(n => n.Id == 1 && n.State == 1);
                inviteUsers.Agent = SysAgent.Id;
                inviteUsers.AId   = SysAgent.AdminId.GetValueOrDefault();
            }
            //使用代理配置
            IList <UserPayAgent> UPAList = Entity.UserPayAgent.Where(n => n.AId == SysAgent.Id).OrderBy(n => n.PId).ToList();

            foreach (var p in UPAList)
            {
                UserPay UserPay = new UserPay();
                UserPay.UId  = inviteUsers.Id;
                UserPay.PId  = p.PId;
                UserPay.Cost = p.Cost;
                Entity.UserPay.AddObject(UserPay);
            }

            SysSet Sys = Entity.SysSet.FirstOrDefault();

            //inviteUsers.Cash0 = Sys.Cash0;
            //inviteUsers.ECash0 = Sys.ECash0;
            //inviteUsers.Cash1 = Sys.Cash1;
            //inviteUsers.ECash1 = Sys.ECash1;
            //使用代理配置
            inviteUsers.Cash0  = SysAgent.Cash0;
            inviteUsers.Cash1  = SysAgent.Cash1;
            inviteUsers.ECash0 = SysAgent.ECash0;
            inviteUsers.ECash1 = SysAgent.ECash1;

            inviteUsers.State = 1;
            Entity.SaveChanges();
            //自动开通End

            //开通后发送短信
            string NoteDownload = "https://fir.im/he3q";
            string CompanyName  = Sys.Name;
            //查询根代理
            //var CurrentAgent = this.Entity.SysAgent.FirstOrNew(o => o.Id == baseUsers.Agent);//当前代理
            //if (CurrentAgent.Tier == 1)
            //{
            //    if (CurrentAgent.IsTeiPai == 1) {
            //        CompanyName = CurrentAgent.APPName;
            //        NoteDownload = CurrentAgent.NoteDownload.IsNullOrEmpty() ? NoteDownload : CurrentAgent.NoteDownload;
            //    }
            //}
            //else
            //{
            //    var TreeAgent = CurrentAgent.GetAgentsById(Entity);
            //    SysAgent RootAgent = TreeAgent.FirstOrDefault(o => o.Tier == 1);
            //    if (RootAgent.IsTeiPai == 1)
            //    {
            //        CompanyName = RootAgent.APPName;
            //        NoteDownload = RootAgent.NoteDownload.IsNullOrEmpty() ? NoteDownload : RootAgent.NoteDownload;
            //    }
            //}

            //根代理
            //string SendText = "{2}邀请您使用{3},您的账号{0}已开通,登陆密码{1},登陆后请修改登陆密码和尽快实名认证!APP下载地址{4}。";
            //SendText = string.Format(SendText, inviteUsers.UserName, PassWord, baseUsers.Mobile, CompanyName, NoteDownload);
            string SendText = "您的账号{0}已开通,登陆密码{1},登录后请修改登录密码和尽快实名认证!APP下载地址{2}。";

            SendText = string.Format(SendText, inviteUsers.UserName, PassWord, NoteDownload);
            SMSLog SMSLog = new SMSLog();

            SMSLog.SendText = SendText;
            SMSLog.Mobile   = inviteUsers.UserName;
            SMSLog.UId      = baseUsers.Id;

            SysSet ss = new SysSet();

            ss.SMSEnd = Sys.SMSEnd;
            SysAgent SA = Entity.SysAgent.FirstOrNew(n => n.Id == baseUsers.Agent);

            SA = SA.GetTopAgent(Entity);
            SMSLog.SendSMS(ss, SA, Entity);

            //邀请注册end
            DataObj.Data = "";
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        public void OpenOrBindUser(int id, string PowerID = "")
        {
            SysAgent SysAgent = Entity.SysAgent.FirstOrDefault(n => n.Id == id);

            if (!SysAgent.MyUId.IsNullOrEmpty())
            {
                //已绑定
                return;
            }
            SysAdmin SysAdmin = new SysAdmin();
            SysSet   ss       = new SysSet();

            ss.SMSEnd = BasicSet.SMSEnd;
            SysAgent SA = SysAgent.GetTopAgent(Entity);

            if (SA.IsTeiPai == 1)
            {
                if (!SA.MsgExt.IsNullOrEmpty())
                {
                    ss.SMSEnd = SA.MsgExt;
                }
            }
            if (SysAgent.AdminId.IsNullOrEmpty())
            {
                //未绑定管理员
                SysAdmin = Entity.SysAdmin.Where(n => n.UserName == SysAgent.LinkMobile).OrderBy(n => n.Id).FirstOrDefault();
                if (SysAdmin == null)
                {
                    //获取是否开通过管理员
                    SysAdmin = Entity.SysAdmin.Where(n => n.AgentId == SysAgent.Id).FirstOrDefault();
                    if (SysAdmin == null)
                    {
                        //开通管理员帐号
                        SysAdmin            = new SysAdmin();
                        SysAdmin.UserName   = SysAgent.LinkMobile;
                        SysAdmin.TrueName   = SysAgent.Linker;
                        SysAdmin.Mobile     = SysAgent.LinkMobile;
                        SysAdmin.Email      = "";
                        SysAdmin.State      = SysAgent.State;
                        SysAdmin.LoginTimes = 0;
                        SysAdmin.AddTime    = DateTime.Now;
                        SysAdmin.AgentId    = SysAgent.Id;
                        SysAdmin.PowerID    = PowerID;
                        string PassWord = Utils.GetCode();
                        SysAdmin.PassWord = PassWord.GetAdminMD5();
                        Entity.SysAdmin.AddObject(SysAdmin);
                        Entity.SaveChanges();
                        SysAgent.AdminId = SysAdmin.Id;
                        Entity.SaveChanges();
                        if (SysAgent.AdminId.IsNullOrEmpty())
                        { //绑定第一个管理员
                            SysAgent.AdminId = SysAdmin.Id;
                        }
                        Entity.SaveChanges();
                        //开通后发送短信
                        string SendText = "您的服务商管理账户已经开通,帐号:{0},密码:{1}。";
                        SendText = string.Format(SendText, SysAdmin.UserName, PassWord);
                        this.SendSMS(SendText, SysAdmin.Mobile, ss);
                    }
                }
                if (SysAdmin.AgentId.IsNullOrEmpty())
                {
                    //所属手机号是管理员
                    return;
                }
                if (SysAdmin.AgentId != SysAgent.Id)
                {
                    //手机号所属于管理员不属于本代理商
                    return;
                }
                SysAgent.AdminId = SysAdmin.Id;
                Entity.SaveChanges();
            }
            Users Users = Entity.Users.FirstOrDefault(n => n.UserName == SysAgent.LinkMobile);

            if (Users == null)
            {
                //注册用户
                Users          = new Users();
                Users.UserName = SysAgent.LinkMobile;
                Users.Mobile   = SysAgent.LinkMobile;
                string PassWord = Utils.GetCode();
                Users.PassWord    = PassWord.GetMD5();
                Users.RegAddress  = "后台自动开通";
                Users.X           = "0";
                Users.Y           = "0";
                Users.MobileState = 2;
                Users.EmailState  = 0;
                Users.CardStae    = 0;
                Users.State       = 0;
                Users.Amount      = 0;
                Users.Frozen      = 0;
                Users.AddTime     = DateTime.Now;
                Users.PayPwd      = "";
                Users.Agent       = SysAgent.Id;//默认指定
                Users.SAId        = SysAgent.Id;
                //Users.SALevel = SysAgent.Levels;
                Users.AId = SysAdmin.Id;//默认指定
                Entity.Users.AddObject(Users);
                Entity.SaveChanges();
                //=======================================
                UserTrack UserTrack = new UserTrack();
                UserTrack.ENo        = string.Empty;
                UserTrack.OPType     = "一级代理开通";
                UserTrack.IfYY       = string.Empty;
                UserTrack.EqMobile   = string.Empty;
                UserTrack.SysVer     = string.Empty;
                UserTrack.SoftVer    = string.Empty;
                UserTrack.SignalType = string.Empty;
                UserTrack.GPSAddress = string.Empty;
                UserTrack.GPSX       = "0";
                UserTrack.GPSY       = "0";
                Users.SeavGPSLog(UserTrack, Entity);
                //=======================================
                SysAgent.MyUId = Users.Id;
                Entity.SaveChanges();

                //自动开通
                //IList<PayConfig> PCList = Entity.PayConfig.Where(n => n.State == 1).ToList();
                //foreach (var PC in PCList)
                //{
                //    UserPay UserPay = new UserPay();
                //    UserPay.UId = Users.Id;
                //    UserPay.PId = PC.Id;
                //    UserPay.Cost = (double)PC.CostUser;
                //    Entity.UserPay.AddObject(UserPay);
                //}

                //使用代理配置
                IList <UserPayAgent> UPAList = Entity.UserPayAgent.Where(n => n.AId == SysAgent.Id).OrderBy(n => n.PId).ToList();
                foreach (var p in UPAList)
                {
                    UserPay UserPay = new UserPay();
                    UserPay.UId  = Users.Id;
                    UserPay.PId  = p.PId;
                    UserPay.Cost = p.Cost;
                    Entity.UserPay.AddObject(UserPay);
                }

                //SysSet Sys = Entity.SysSet.FirstOrDefault();
                //Users.Cash0 = Sys.Cash0;
                //Users.ECash0 = Sys.ECash0;
                //Users.Cash1 = Sys.Cash1;
                //Users.ECash1 = Sys.ECash1;

                //使用代理配置
                Users.Cash0  = SysAgent.Cash0;
                Users.Cash1  = SysAgent.Cash1;
                Users.ECash0 = SysAgent.ECash0;
                Users.ECash1 = SysAgent.ECash1;

                Users.State = 1;
                Entity.SaveChanges();
                //自动开通End
                //开通后发送短信
                string SendText = "您的钱包账户已经开通,帐号:{0},密码:{1}。";
                SendText = string.Format(SendText, Users.UserName, PassWord);
                this.SendSMS(SendText, Users.UserName, ss);
            }
            else
            {
                SysAgent.MyUId = Users.Id;
                //钱包帐户所属于代理商改成自己,避免推广用户属于原代理商
                Users.Agent = SysAgent.Id; //默认指定
                Users.SAId  = SysAgent.Id;
                Users.AId   = SysAdmin.Id; //默认指定
                Users.MyPId = 0;
                Entity.SaveChanges();
                string SendText = "您的钱包账户“{0}”,绑定成为{1}的结算帐户。";
                SendText = string.Format(SendText, Users.UserName, SysAgent.Name);
                this.SendSMS(SendText, Users.UserName, ss);
            }
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[MsgNotice]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            MsgNotice MsgNotice = new MsgNotice();

            MsgNotice = JsonToObject.ConvertJsonToModel(MsgNotice, json);

            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == MsgNotice.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            //if (baseUsers.CardStae != 2)//未实名认证
            //{
            //    DataObj.OutError("2006");
            //    return;
            //}
            //if (baseUsers.MiBao != 1)//未设置支付密码
            //{
            //    DataObj.OutError("2008");
            //    return;
            //}

            //下次改版让手机端传AgentId,这让有点伤性能,然后删除这条备注
            SysAgent SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == baseUsers.Agent);

            SysAgent = SysAgent.GetTopAgent(Entity);

            EFPagingInfo <MsgNotice> p = new EFPagingInfo <MsgNotice>();

            if (!MsgNotice.Pg.IsNullOrEmpty())
            {
                p.PageIndex = MsgNotice.Pg;
            }
            if (!MsgNotice.Pgs.IsNullOrEmpty())
            {
                p.PageSize = MsgNotice.Pgs;
            }

            p.SqlWhere.Add(f => f.NType == 0 || f.NType == 3);
            p.SqlWhere.Add(f => f.State == 1 && f.AddTime > baseUsers.AddTime);
            int AgentId = 999999999;

            if (SysAgent.IsTeiPai == 1)
            {
                AgentId = SysAgent.Id;
            }
            p.SqlWhere.Add(f => f.AgentId == 0 || f.AgentId == AgentId);

            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <MsgNotice> List = Entity.Selects <MsgNotice>(p);

            //处理以读未读
            string UserId = string.Format("|{0}|", baseUsers.Id);

            foreach (var pp in List)
            {
                pp.State = (byte)(pp.ReadUsers != null && pp.ReadUsers.IndexOf(UserId) == -1 ? 1 : 2);
                if (pp.Info != null)
                {
                    pp.Info = Utils.RemoveHtml(pp.Info);
                    pp.Info = pp.Info.Replace("	", "");
                }
            }
            IList <MsgNotice> iList = List.ToList();
            StringBuilder     sb    = new StringBuilder("");

            sb.Append("{");
            sb.Append(List.PageToString());
            sb.Append(",");
            sb.Append(iList.EntityToString());
            sb.Append("}");
            DataObj.Data = sb.ToString();
            DataObj.Code = "0000";
            DataObj.OutString();
        }