public HttpResponseMessage SearchPartnerList(EnumPartnerType status, EnumBrokerSearchOrderBy orderByAll = EnumBrokerSearchOrderBy.OrderById, bool isDes = true, string name = null, int page = 1, int pageSize = 10)
        {
            var brokerSearchCondition = new BrokerSearchCondition
            {
                Brokername = name,
                Status = status,
                Page = Convert.ToInt32(page),
                PageCount = pageSize,
                OrderBy =orderByAll ,
                isDescending =isDes 
            };
            var partnerList = _brokerService.GetBrokersByCondition(brokerSearchCondition).Select(p => new
            {
                p.Id,
                p.UserId,
                PartnersName = p.WeiXinNumber == null ? "无" : p.WeiXinNumber,
                p.PartnersId,
                BrokerName = p.Brokername,
                Phone = p.Phone,
                Regtime = p.Regtime,
                Agentlevel = p.Agentlevel,
                Headphoto = p.Headphoto,
                status = EnumPartnerType.同意
            });
            var partnerListCount = _brokerService.GetBrokerCount(brokerSearchCondition);
            return PageHelper.toJson(new { List = partnerList, Condition = brokerSearchCondition, totalCount = partnerListCount });

        }
 public HttpResponseMessage GetAdminList([FromBody]BrokerSearchModel brokerSearchModel)
 {
     var condition = new BrokerSearchCondition
     {
         OrderBy = EnumBrokerSearchOrderBy.OrderById
     };
     return PageHelper.toJson(_brokerService.GetBrokersByCondition(condition).ToList());
 }
示例#3
0
        public HttpResponseMessage ForgetPassword([FromBody]ForgetPasswordModel model)
        {
            //判断用户是否存在
            var sech = new BrokerSearchCondition
            {
                OrderBy = EnumBrokerSearchOrderBy.OrderById,
                Phone = model.Phone,
                State=1
            };
            var broker = _brokerService.GetBrokersByCondition(sech).FirstOrDefault();
            if (broker == null) return PageHelper.toJson(PageHelper.ReturnValue(false, "该用户不存在!"));

            #region 首先判断发送到手机的验证码是否正确
            var strDes = EncrypHelper.Decrypt(model.Hidm, "Hos2xNLrgfaYFY2MKuFf3g==");//解密
            string[] str = strDes.Split('$');

            if(str.Count()<2)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!"));
            }

            string source = str[0];//获取验证码
            DateTime date = Convert.ToDateTime(str[1]);//获取发送验证码的时间
            DateTime dateNow = Convert.ToDateTime(DateTime.Now.ToLongTimeString());//获取当前时间
            TimeSpan ts = dateNow.Subtract(date);
            double secMinu = ts.TotalMinutes;//得到发送时间与现在时间的时间间隔分钟数
            if (secMinu > 3) //发送时间与接受时间是否大于3分钟
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "你已超过时间验证,请重新发送验证码!"));
            }
            else
            {
                // source.Split('#')[0] 验证码
                // source.Split('#')[1] 手机号
                if (model.Phone != source.Split('#')[1])//判断手机号是否一致
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!"));
                }

                if (model.Yzm != source.Split('#')[0])//判断验证码是否一致
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!"));
                }
            }


            #endregion

            //判断两次新密码是否一致
            if (model.first_password != model.second_password) return PageHelper.toJson(PageHelper.ReturnValue(true, "密码不一致!"));

            //密码修改
            var user = _userService.FindUser(broker.UserId);
            PasswordHelper.SetPasswordHashed(user, model.first_password);
            _userService.ModifyUser(user);
            return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功!"));
        }
示例#4
0
        public HttpResponseMessage AddBroker([FromBody]BrokerModel brokerModel)
        {
            var validMsg = "";
            if (!brokerModel.ValidateModel(out validMsg))
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误,请重新输入"));
            }

            #region 验证码判断 解密
            var strDes = EncrypHelper.Decrypt(brokerModel.Hidm, "Hos2xNLrgfaYFY2MKuFf3g==");//解密
            string[] str = strDes.Split('$');
            if (str.Count() < 2)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!"));
            }
            string source = str[0];//获取验证码和手机号
            DateTime date = Convert.ToDateTime(str[1]);//获取发送验证码的时间
            DateTime dateNow = Convert.ToDateTime(DateTime.Now.ToLongTimeString());//获取当前时间
            TimeSpan ts = dateNow.Subtract(date);
            double secMinu = ts.TotalMinutes;//得到发送时间与现在时间的时间间隔分钟数
            if (secMinu > 3) //发送时间与接受时间是否大于3分钟
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "你已超过时间验证,请重新发送验证码!"));
            }
            else
            {
                // source.Split('#')[0] 验证码
                // source.Split('#')[1] 手机号
                if (brokerModel.Phone != source.Split('#')[1])//判断手机号是否一致
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!"));
                }

                if (brokerModel.MobileYzm != source.Split('#')[0])//判断验证码是否一致
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!"));
                }
            }

            #endregion

            #region 判断两次密码是否一致
            if (brokerModel.Password != brokerModel.SecondPassword)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号不能为空"));
            }
            #endregion

            #region 判断邀请码是否存在真实  (brokerInfoController 中GetBrokerByInvitationCode方法也同一判断)
            MessageDetailEntity messageDetail = null;
            if (!string.IsNullOrEmpty(brokerModel.inviteCode))
            {

                MessageDetailSearchCondition messageSearchcondition = new MessageDetailSearchCondition
                {
                    InvitationCode = brokerModel.inviteCode,
                    Title = "推荐经纪人"
                };
                messageDetail = _MessageService.GetMessageDetailsByCondition(messageSearchcondition).FirstOrDefault();//判断邀请码是否存在
                if (messageDetail == null)
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "邀请码错误!"));
                }
            }
            #endregion


            #region UC用户创建 杨定鹏 2015年5月28日14:52:48
            var user = _userService.GetUserByName(brokerModel.UserName);
            if(user!=null)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名已经存在"));
            }


            var condition = new BrokerSearchCondition
            {
                OrderBy = EnumBrokerSearchOrderBy.OrderById,
                State = 1,
                Phone = brokerModel.Phone
            };

            //判断user表和Broker表中是否存在用户名
            int user2 = _brokerService.GetBrokerCount(condition);

            if (user2 != 0) return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号已经存在"));

            var brokerRole = _roleService.GetRoleByName("user");

            //User权限缺少时自动添加
            if (brokerRole == null)
            {
                brokerRole = new Role
                {
                    RoleName = "user",
                    RolePermissions = null,
                    Status = RoleStatus.Normal,
                    Description = "刚注册的用户默认归为普通用户user"
                };
            }

            var newUser = new UserBase
            {
                UserName = brokerModel.UserName,
                Password = brokerModel.Password,
                RegTime = DateTime.Now,
                NormalizedName = brokerModel.UserName.ToLower(),
                //注册用户添加权限
                UserRoles = new List<UserRole>(){new UserRole()
                {
                    Role = brokerRole
                }},
                Status = 0
            };

            PasswordHelper.SetPasswordHashed(newUser, brokerModel.Password);

            #endregion

            #region Broker用户创建 杨定鹏 2015年5月28日14:53:32

            var model = new BrokerEntity();
            model.UserId = _userService.InsertUser(newUser).Id;
            model.Brokername = brokerModel.Phone;
            model.Nickname = brokerModel.Nickname;
            model.Phone = brokerModel.Phone;
            model.Totalpoints = 0;
            model.Amount = 0;
            model.Usertype = EnumUserType.普通用户;
            model.Regtime = DateTime.Now;
            model.State = 1;
            model.Adduser = 0;
            model.Addtime = DateTime.Now;
            model.Upuser = 0;
            model.Uptime = DateTime.Now;

            //判断初始等级是否存在,否则创建
            var level = _levelService.GetLevelsByCondition(new LevelSearchCondition { Name = "默认等级" }).FirstOrDefault();
            if (level == null)
            {
                var levelModel = new LevelEntity
                {
                    Name = "默认等级",
                    Describe = "系统默认初始创建",
                    Url = "",
                    Uptime = DateTime.Now,
                    Addtime = DateTime.Now,
                };
                _levelService.Create(levelModel);
            }

            model.Level = level;

            var newBroker = _brokerService.Create(model);



            #endregion

            #region 推荐经纪人
            if (!string.IsNullOrEmpty(brokerModel.inviteCode))
            {
                //添加经纪人
                var entity = new RecommendAgentEntity
                {
                    PresenteebId = newBroker.Id,
                    Qq = newBroker.Qq.ToString(),
                    Agentlevel = newBroker.Agentlevel,
                    Brokername = newBroker.Brokername,
                    Phone = newBroker.Phone,
                    Regtime = DateTime.Now,
                    Broker = _brokerService.GetBrokerById(Convert.ToInt32(messageDetail.InvitationId)),
                    Uptime = DateTime.Now,
                    Addtime = DateTime.Now,
                };

                _recommendagentService.Create(entity);
            }
            #endregion

            return PageHelper.toJson(PageHelper.ReturnValue(true, "注册成功"));
        }
示例#5
0
        public HttpResponseMessage CheckMobile([FromBody]UserModel model)
        {
            if (!string.IsNullOrEmpty(model.Phone) )
            {
                //1 先判断手机号是否存在
                var condition = new BrokerSearchCondition
                {
                    State = 1,
                    Phone = model.Phone
                };
                //判断Broker表中是否存在手机号
                int brokerCount = _brokerService.GetBrokerCount(condition);
                if (brokerCount != 0)
                {
                    //存在 

                    return PageHelper.toJson(PageHelper.ReturnValue(true, "yes"));
                }
                else //不存在  就进行注册
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "no"));

                }
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "请填写手机号和密码"));
        }
示例#6
0
        public HttpResponseMessage ExternalLoginOrAdd([FromBody]UserModel model)
        {
            if(!string.IsNullOrEmpty( model.Phone)  && !string.IsNullOrEmpty( model.Password))
            {
                //1 先判断手机号是否存在
                var condition = new BrokerSearchCondition
                {                   
                    State = 1,
                    Phone = model.Phone
                };
                //判断Broker表中是否存在手机号
                int brokerCount = _brokerService.GetBrokerCount(condition);
                if (brokerCount != 0)
                {
                    //存在  就进行登录

                    #region 登录

                    BrokerEntity broker = _brokerService.GetBrokersByCondition(condition).FirstOrDefault();
                    if (broker == null)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号或密码错误"));
                    }
                 
                    var user = _userService.FindUser(broker.UserId);
                    if (user == null)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名或密码错误"));
                    }
                    if (!PasswordHelper.ValidatePasswordHashed(user, model.Password))
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名或密码错误")); 
                    }
                    _authenticationService.SignIn(user, model.Remember);

                    return PageHelper.toJson(PageHelper.ReturnValue(true, "ok"));

                    #endregion 
                }
                else //不存在  就进行注册
                {

                    #region UC用户创建 杨定鹏 2015年5月28日14:52:48
                                     
                    var brokerRole = _roleService.GetRoleByName("user");

                    //User权限缺少时自动添加
                    if (brokerRole == null)
                    {
                        brokerRole = new Role
                        {
                            RoleName = "user",
                            RolePermissions = null,
                            Status = RoleStatus.Normal,
                            Description = "刚注册的用户默认归为普通用户user"
                        };
                    }

                    var newUser = new UserBase
                    {
                        UserName = model.Phone,
                        Password = model.Password,
                        RegTime = DateTime.Now,
                        NormalizedName = model.Phone,
                        //注册用户添加权限
                        UserRoles = new List<UserRole>(){new UserRole()
                       {
                         Role = brokerRole
                       }},
                        Status = 0
                    };

                    PasswordHelper.SetPasswordHashed(newUser, model.Password);

                    #endregion

                    #region Broker用户创建 杨定鹏 2015年5月28日14:53:32

                    var models = new BrokerEntity();
                    models.UserId = _userService.InsertUser(newUser).Id;
                    models.Brokername = model.Phone;
                    models.Nickname = model.Phone;
                    models.Phone = model.Phone;
                    models.Totalpoints = 0;
                    models.Amount = 0;
                    models.Usertype = EnumUserType.普通用户;
                    models.Regtime = DateTime.Now;
                    models.State = 1;
                    models.Adduser = 0;
                    models.Addtime = DateTime.Now;
                    models.Upuser = 0;
                    models.Uptime = DateTime.Now;

                    //判断初始等级是否存在,否则创建
                    var level = _levelService.GetLevelsByCondition(new LevelSearchCondition { Name = "默认等级" }).FirstOrDefault();
                    if (level == null)
                    {
                        var levelModel = new LevelEntity
                        {
                            Name = "默认等级",
                            Describe = "系统默认初始创建",
                            Url = "",
                            Uptime = DateTime.Now,
                            Addtime = DateTime.Now,
                        };
                        _levelService.Create(levelModel);
                    }
                    models.Level = level;
                    var newBroker = _brokerService.Create(models);
                    #endregion
                  
                    return PageHelper.toJson(PageHelper.ReturnValue(true, "ok"));

                }                          
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "请填写手机号和密码"));
        }
示例#7
0
        public HttpResponseMessage IndexLogin([FromBody]UserModel model)
        {
            BrokerSearchCondition brokerSearchcon = new BrokerSearchCondition
            {
                State = 1,
                Phone = model.UserName
            };
            BrokerEntity broker = _brokerService.GetBrokersByCondition(brokerSearchcon).FirstOrDefault();
            if (broker == null)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号或密码错误"));
            }
            // var user = _userService.GetUserByName(model.UserName);

            var user = _userService.FindUser(broker.UserId);
            if (user == null)
                return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名或密码错误"));
            if (!PasswordHelper.ValidatePasswordHashed(user, model.Password))
                return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名或密码错误"));
            _authenticationService.SignIn(user, model.Remember);
            return PageHelper.toJson(PageHelper.ReturnValue(true, "登陆成功", new
            {
                user.Id,
                Roles = user.UserRoles.Select(r => new { r.Role.RoleName }).ToArray(),
                user.UserName
            }));
        }
 public HttpResponseMessage SecretaryList()
 {
     var condition = new BrokerSearchCondition
     {
         OrderBy = EnumBrokerSearchOrderBy.OrderById,
         UserType = EnumUserType.场秘,
         State=1
     };
     var list = _brokerService.GetBrokersByCondition(condition).Select(a => new
     {
         a.Id,
         a.Brokername,
         a.Phone
     }).ToList();
     return PageHelper.toJson(list);
 }
        public HttpResponseMessage AddBroker([FromBody]BrokerModel brokerModel)
        {
            if (string.IsNullOrEmpty(brokerModel.UserName)) return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名不能为空"));
            if (string.IsNullOrEmpty(brokerModel.Password)) return PageHelper.toJson(PageHelper.ReturnValue(false, "密码不能为空"));
            if (string.IsNullOrEmpty(brokerModel.Phone)) return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号不能为空"));
            // 创建推荐用户
            var condition = new BrokerSearchCondition
            {
                OrderBy = EnumBrokerSearchOrderBy.OrderById,
                Phone = brokerModel.Phone
            };
            //判断user表和Broker表中是否存在用户名
            int user2 = _brokerService.GetBrokerCount(condition);

            if (user2 != 0) return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名已经存在"));

            //检测规则表中是否存在权限,不存在则添加
            var role = "broker";
            switch (brokerModel.UserType)
            {
                case EnumUserType.经纪人:
                    role = "broker";
                    break;
                case EnumUserType.商家:
                    role = "merchant";
                    break;
                case EnumUserType.场秘:
                    role = "secretary";
                    break;
                case EnumUserType.带客人员:
                    role = "waiter";
                    break;
                case EnumUserType.普通用户:
                    role = "user";
                    break;
                case EnumUserType.管理员:
                    role = "admin";
                    break;
                case EnumUserType.财务:
                    role = "accountant";
                    break;
            }

            var brokerRole = _roleService.GetRoleByName(role);

            //User权限缺少时自动添加
            if (brokerRole == null)
            {
                brokerRole = new Role
                {
                    RoleName = role,
                    RolePermissions = null,
                    Status = RoleStatus.Normal,
                    Description = "后台添加新权限类别:" + role
                };
            }

            var newUser = new UserBase
            {
                UserName = brokerModel.UserName,
                Password = brokerModel.Password,
                RegTime = DateTime.Now,
                NormalizedName = brokerModel.UserName.ToLower(),
                //注册用户添加权限
                UserRoles = new List<UserRole>(){new UserRole()
                {
                    Role = brokerRole
                }},
                Status = 0
            };
            PasswordHelper.SetPasswordHashed(newUser, brokerModel.Password);
            var model = new BrokerEntity();
            model.UserId = _userService.InsertUser(newUser).Id;
            model.Brokername = brokerModel.UserName;
            model.Phone = brokerModel.Phone;
            model.Totalpoints = 0;
            model.Amount = 0;
            model.Usertype = brokerModel.UserType;
            model.Regtime = DateTime.Now;
            model.State = 1;
            model.Adduser = 0;
            model.Addtime = DateTime.Now;
            model.Upuser = 0;
            model.Uptime = DateTime.Now;

            //判断初始等级是否存在,否则创建
            var level = _levelService.GetLevelsByCondition(new LevelSearchCondition { Name = "默认等级" }).FirstOrDefault();
            if (level == null)
            {
                var levelModel = new LevelEntity
                {
                    Name = "默认等级",
                    Describe = "系统默认初始创建",
                    Url = "",
                    Uptime = DateTime.Now,
                    Addtime = DateTime.Now,
                };
                _levelService.Create(levelModel);
            }
            model.Level = level;
            _brokerService.Create(model);
            return PageHelper.toJson(PageHelper.ReturnValue(true, "注册成功"));
        }
        public HttpResponseMessage UpdateBroker([FromBody] BrokerModel broker)
        {
            if (broker != null && !string.IsNullOrEmpty(broker.Id.ToString()) && PageHelper.ValidateNumber(broker.Id.ToString()))
            {
                var brokerModel = _brokerService.GetBrokerById(broker.Id);
                brokerModel.Headphoto = broker.Headphoto;
                brokerModel.Nickname = broker.Nickname;
                brokerModel.Phone = broker.Phone;
                brokerModel.Sfz = broker.Sfz;
                brokerModel.Email = broker.Email;
                brokerModel.Realname = broker.Realname;
                brokerModel.Sexy = broker.Sexy;
                brokerModel.WeiXinNumber = broker.WeiXinNumber;//by  yangyue  2015/7/16

                #region 转职经纪人 杨定鹏 2015年6月11日17:29:58
                //填写身份证,邮箱,和真实姓名后就能转职经纪人
                if (!string.IsNullOrEmpty(broker.Email) && !string.IsNullOrEmpty(broker.Sfz) &&
                    !string.IsNullOrEmpty(broker.Realname))
                {
                    //权限变更
                    var brokerRole = _roleService.GetRoleByName("broker");
                    //User权限缺少时自动添加
                    if (brokerRole == null)
                    {
                        brokerRole = new Role
                        {
                            RoleName = "broker",
                            RolePermissions = null,
                            Status = RoleStatus.Normal,
                            Description = "user用户转职为broker"
                        };
                    }

                    var user = _userService.FindUser(brokerModel.UserId);
                    user.UserRoles.First().Role = brokerRole;

                    //更新用户权限
                    if (_userService.ModifyUser(user))
                    {
                        //更新broker表记录
                        brokerModel.Usertype = EnumUserType.经纪人;
                        _brokerService.Update(brokerModel);
                        //return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功!"));
                    }


                }
                #endregion


                #region 邀请码逻辑 by yangyue  2015/7/16
                
                var even = new EventSearchCondition //判断该活动是否开启
                {
                    EventContent ="完善经纪人资料活动",
                    State = true
                };
                if (_eventService.GetEventCount(even) > 0)
                {
                    #region  邀请码活动 by yangyue  2015/7/16

                    InviteCodeSearchCondition icodeseCon = new InviteCodeSearchCondition
                    {
                        NumUser = brokerModel.Id,
                        State = 1
                    };
                    //判断有无使用过邀请码
                    if (_inviteCodeService.GetInviteCodeByCount(icodeseCon) <= 0)//没使用过邀请码
                    {
                        //邀请码不为空
                        if (!string.IsNullOrEmpty(broker.code))
                        {
                            var levelCon = new LevelSearchCondition
                            {
                                Name = "白银"
                            };
                            var level = _levelService.GetLevelsByCondition(levelCon).FirstOrDefault();

                            #region  白银逻辑

                            BrokerSearchCondition bsearchModel = new BrokerSearchCondition
                            {
                                Levels = level

                            };
                            //1判断白银等级人数是否《=3000 
                            if (_brokerService.GetBrokerCount(bsearchModel) <= 3000)
                            {
                                var invite = new InviteCodeSearchCondition
                                {

                                    Number = broker.code,
                                    State = 0
                                };
                                var con = _inviteCodeService.GetInviteCodeByCondition(invite).FirstOrDefault();//查询邀请码是否存在并且未使用
                                var eventcon = new EventOrderSearchCondition //判断该经济人有无参与活动 等于0是没参与 等于1是参与过

                                {
                                    Brokers = _brokerService.GetBrokerById(brokerModel.Id)
                                };
                                var num = _eventOrderService.GetEventOrderCount(eventcon);//查询活动订单表有无该经纪人

                                if (con != null && num == 0) //存在 未使用  并且该经纪人未参与过活动
                                {
                                    //using (TransactionScope tsCope = new TransactionScope(TransactionScopeOption.RequiresNew))
                                    //{
                                    #region 添加到活动订单 经纪人账户表 AgentBill表 修改经纪人等级 生成3个邀请码  并发送到手机

                                    var eve = new EventSearchCondition
                                    {
                                        EventContent = "完善经纪人资料活动"
                                    };
                                   var coneve= _eventService.GetEventByCondition(eve).FirstOrDefault();
                                    //添加活动订单信息
                                    EventOrderEntity emodel = new EventOrderEntity();
                                    emodel.AcDetail = "完整经济人资料奖励30元";
                                    emodel.Addtime = DateTime.Now;
                                    emodel.MoneyCount = 30;
                                    emodel.Broker = brokerModel;
                                    emodel.Event = coneve;
                                    _eventOrderService.Create(emodel);

                                    //添加到经纪人账户表brokeraccount
                                    BrokeAccountEntity brokeraccountmodel = new BrokeAccountEntity();
                                    brokeraccountmodel.MoneyDesc = "完整经济人资料奖励30元";
                                    brokeraccountmodel.Balancenum = 30;
                                    brokeraccountmodel.Adduser = brokerModel.Id;
                                    brokeraccountmodel.Addtime = DateTime.Now;
                                    brokeraccountmodel.Upuser = brokerModel.Id;
                                    brokeraccountmodel.Uptime = DateTime.Now;
                                    brokeraccountmodel.Broker = brokerModel;
                                    brokeraccountmodel.Type = 2;
                                    brokeraccountmodel.State = 0;
                                    _brokerAccountService.Create(brokeraccountmodel);



                                    //添加记录到AgentBill表

                                    AgentBillEntity abmmodel = new AgentBillEntity();
                                    abmmodel.AgentId = brokerModel.Id;
                                    abmmodel.Agentname = brokerModel.Brokername;
                                    abmmodel.LandagentId = 1;
                                    abmmodel.Amount = 30;
                                    abmmodel.Isinvoice = false;
                                    abmmodel.Checkoutdate = DateTime.Now;
                                    abmmodel.Addtime = DateTime.Now;
                                    abmmodel.Updtime = DateTime.Now;
                                    abmmodel.EventOrderId = emodel.Id;
                                    _agentBillService.Create(abmmodel);

                                    //    tsCope.Complete();
                                    //}

                                    //      using (TransactionScope tsCope = new TransactionScope(TransactionScopeOption.RequiresNew))
                                    //{

                                    //修改邀请码表信息
                                    con.NumUser = brokerModel.Id;
                                    con.UseTime = DateTime.Now;
                                    con.State = 1;
                                    _inviteCodeService.Update(con);

                                    //更新等级
                                    brokerModel.Level = level;


                                    brokerModel.Amount += 30;
                                    _brokerService.Update(brokerModel);
                                    //    tsCope.Complete();
                                    //}

                                    //并且生成3个邀请码发送到手机端口 并插入库中
                                    string randmNums = string.Empty;
                                    for (int i = 0; i < 3; i++)
                                    {
                                        string rans = GenerateRandomNumber(6);
                                        randmNums += rans + ",";

                                        InviteCodeEntity inviteCode = new InviteCodeEntity();
                                        inviteCode.CreatTime = DateTime.Now;
                                        inviteCode.Number = rans;
                                        inviteCode.UseTime = DateTime.Now;
                                        inviteCode.State = 0;
                                        inviteCode.Broker = brokerModel;
                                        _inviteCodeService.Create(inviteCode);
                                    }
                                    SMSHelper.Sending(brokerModel.Phone, "恭喜您完善个人信息,奖励您三个邀请码:" + randmNums + "赶快邀请小伙伴们,惊喜等你哟!" + "【优客惠】");
                                    #endregion


                                }
                                else //不存在 或已被使用
                                {
                                    #region 邀请码不存在 或已被使用 就转为青铜逻辑


                                    #region 青铜逻辑

                                    var levelConn = new LevelSearchCondition
                                    {
                                        Name = "青铜"
                                    };
                                    var qlevel = _levelService.GetLevelsByCondition(levelConn).FirstOrDefault();

                                    BrokerSearchCondition qbsearchModel = new BrokerSearchCondition
                                    {
                                        Levels = qlevel

                                    };

                                    // 1判断青铜是否《=1000                             
                                    if (_brokerService.GetBrokerCount(qbsearchModel) <= 1000)
                                    {
                                        var qinvite = new InviteCodeSearchCondition
                                        {

                                            Number = broker.code,
                                            State = 0
                                        };
                                        var qcon = _inviteCodeService.GetInviteCodeByCondition(qinvite).FirstOrDefault();
                                        //查询邀请码是否存在并且未使用
                                        var eventcon1 = new EventOrderSearchCondition //判断该经济人有无参与活动 等于0是没参与 等于1是参与过

                                        {
                                            Brokers = _brokerService.GetBrokerById(brokerModel.Id)
                                        };
                                        var num1 = _eventOrderService.GetEventOrderCount(eventcon1); //查询活动订单表有无该经纪人
                                        if (qcon != null && num1 == 0)
                                        {
                                            var eve = new EventSearchCondition
                                            {
                                                EventContent = "完善经纪人资料活动"
                                            };
                                            var coneve = _eventService.GetEventByCondition(eve).FirstOrDefault();
                                            //using (TransactionScope tsCope = new TransactionScope(TransactionScopeOption.RequiresNew))
                                            //{
                                            EventOrderEntity emodel = new EventOrderEntity();
                                            emodel.AcDetail = "完整经济人资料无邀请码奖励20元";
                                            emodel.Addtime = DateTime.Now;
                                            emodel.MoneyCount = 20;
                                            emodel.Broker = brokerModel;
                                            emodel.Event = coneve;
                                            _eventOrderService.Create(emodel);

                                            //添加到经纪人账户表
                                            BrokeAccountEntity brokeraccountmodel = new BrokeAccountEntity();
                                            brokeraccountmodel.MoneyDesc = "完整经济人资料奖励20元";
                                            brokeraccountmodel.Balancenum = 20;
                                            brokeraccountmodel.Adduser = brokerModel.Id;
                                            brokeraccountmodel.Addtime = DateTime.Now;
                                            brokeraccountmodel.Upuser = brokerModel.Id;
                                            brokeraccountmodel.Uptime = DateTime.Now;
                                            brokeraccountmodel.Broker = brokerModel;
                                            brokeraccountmodel.Type = 2;
                                            brokeraccountmodel.State = 0;
                                            _brokerAccountService.Create(brokeraccountmodel);


                                            //添加记录到AgentBill表

                                            AgentBillEntity abmmodel = new AgentBillEntity();
                                            abmmodel.AgentId = brokerModel.Id;
                                            abmmodel.Agentname = brokerModel.Brokername;
                                            abmmodel.LandagentId = 1;
                                            abmmodel.Amount = 20;
                                            abmmodel.Isinvoice = false;
                                            abmmodel.Checkoutdate = DateTime.Now;
                                            abmmodel.Addtime = DateTime.Now;
                                            abmmodel.Updtime = DateTime.Now;
                                            abmmodel.EventOrderId = emodel.Id;
                                            _agentBillService.Create(abmmodel);

                                            brokerModel.Level = qlevel;
                                            brokerModel.Amount += 20;
                                            _brokerService.Update(brokerModel);
                                            //给20元钱 等级设为青铜 
                                            //    tsCope.Complete();
                                            //}
                                        }
                                        else
                                        {
                                            if (_brokerService.Update(brokerModel) != null)
                                            {
                                                //等级设为青铜
                                                brokerModel.Level = qlevel;
                                                _brokerService.Update(brokerModel);
                                                return PageHelper.toJson(PageHelper.ReturnValue(true, "邀请码输入错误!"));
                                            }
                                        }

                                    #endregion

                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                if (_brokerService.Update(brokerModel) != null)
                                {
                                    //白银人数超过3000 等级设为白银
                                    brokerModel.Level = level;
                                    _brokerService.Update(brokerModel);
                                }
                            }

                            #endregion
                        }
                        else//邀请码没有填写  没有参与过活动 给20元钱 等级设为青铜
                        {
                            #region 没有填写邀请码 给20元钱 等级设为青铜
                            var levelConn = new LevelSearchCondition
                            {
                                Name = "青铜"
                            };
                            var qlevel = _levelService.GetLevelsByCondition(levelConn).FirstOrDefault(); //等级为青铜
                            //判断青铜是否《=1000 
                            BrokerSearchCondition qbsearchModel = new BrokerSearchCondition
                            {
                                Levels = qlevel

                            };
                            var eventcon = new EventOrderSearchCondition //判断该经济人有无参与活动 等于0是没参与 等于1是参与过

                            {
                                Brokers = _brokerService.GetBrokerById(brokerModel.Id)
                            };
                            var num = _eventOrderService.GetEventOrderCount(eventcon);
                            //Brokers
                            if (_brokerService.GetBrokerCount(qbsearchModel) <= 1000 && num == 0) //判断青铜是否《=1000  
                            {
                                //青铜等级人数《=1000 给20元钱 等级设为青铜
                                //using (TransactionScope tsCope = new TransactionScope(TransactionScopeOption.RequiresNew))
                                //{
                                //添加到活动订单表

                                var eve = new EventSearchCondition
                                {
                                    EventContent = "完善经纪人资料活动"
                                };
                                var coneve = _eventService.GetEventByCondition(eve).FirstOrDefault();
                                EventOrderEntity emodel = new EventOrderEntity();
                                emodel.AcDetail = "完整经济人资料无邀请码奖励20元";
                                emodel.Addtime = DateTime.Now;
                                emodel.MoneyCount = 20;
                                emodel.Event = coneve;
                                emodel.Broker = brokerModel;
                                _eventOrderService.Create(emodel);

                                //添加到经纪人账户表
                                BrokeAccountEntity brokeraccountmodel = new BrokeAccountEntity();
                                brokeraccountmodel.MoneyDesc = "完整经济人资料奖励20元";
                                brokeraccountmodel.Balancenum = 20;
                                brokeraccountmodel.Adduser = brokerModel.Id;
                                brokeraccountmodel.Addtime = DateTime.Now;
                                brokeraccountmodel.Upuser = brokerModel.Id;
                                brokeraccountmodel.Uptime = DateTime.Now;
                                brokeraccountmodel.Broker = brokerModel;
                                brokeraccountmodel.Type = 2;
                                brokeraccountmodel.State = 0;
                                _brokerAccountService.Create(brokeraccountmodel);


                                //添加记录到AgentBill表

                                AgentBillEntity abmmodel = new AgentBillEntity();
                                abmmodel.AgentId = brokerModel.Id;
                                abmmodel.Agentname = brokerModel.Brokername;
                                abmmodel.LandagentId = 1;
                                abmmodel.Amount = 20;
                                abmmodel.Isinvoice = false;
                                abmmodel.Checkoutdate = DateTime.Now;
                                abmmodel.Addtime = DateTime.Now;
                                abmmodel.Updtime = DateTime.Now;
                                abmmodel.EventOrderId = emodel.Id;
                                _agentBillService.Create(abmmodel);


                                brokerModel.Level = qlevel;
                                brokerModel.Amount += 20;
                                _brokerService.Update(brokerModel);
                                //    tsCope.Complete();
                                //}

                            }
                            else
                            {
                                if (_brokerService.Update(brokerModel) != null)
                                {
                                    //青铜人数已经超过1000人 则等级直接设为青铜
                                    brokerModel.Level = qlevel;
                                    _brokerService.Update(brokerModel);
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion
                }
                else
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(true, "该活动已经下架!"));
                }
                

                #endregion
               

                try
                {
                    if (_brokerService.Update(brokerModel) != null)
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功!"));
                    }
                }
                catch
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "数据更新失败!"));
                }


            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误!"));

        }
        public HttpResponseMessage SearchBrokers( EnumUserType userType,EnumBrokerSearchOrderBy orderByAll = EnumBrokerSearchOrderBy .OrderById, bool isDes = true,string phone = null, string name = null, int page = 1, int pageSize = 10, int state = 2)
        {
            //var phones = new int[1];

            var brokerSearchCondition = new BrokerSearchCondition
            {
                Brokername = name,
                Phone1 = phone,
                Page = Convert.ToInt32(page),
                PageCount = 10,
                UserType = userType,
                State = state,
                OrderBy = orderByAll,
                isDescending =isDes 

            };

            var brokersList = _brokerService.GetBrokersByCondition(brokerSearchCondition).Select(p => new
            {
                p.Id,
                p.Nickname,
                p.Brokername,
                p.Realname,
                p.Phone,
                p.Sfz,
                p.Amount,
                p.Agentlevel,
                p.Regtime,
                p.Headphoto,
                p.State,
                p.Usertype,
                btnVisibleDel = true,
                btnVisibleCan = true,
                btnname = "注销",
                btncolor = "",
                backcolor = ""
            }).ToList().Select(b => new
            {
                b.Id,
                b.Nickname,
                b.Brokername,
                b.Realname,
                b.Phone,
                b.Sfz,
                b.Amount,
                b.Agentlevel,
                Regtime = b.Regtime.ToString("yyyy-MM-dd"),
                b.Headphoto,
                b.State,
                b.Usertype,
                btnVisibleDel = true,
                btnVisibleCan = true
            });
            var brokerListCount = _brokerService.GetBrokerCount(brokerSearchCondition);
            return PageHelper.toJson(new { List = brokersList, Condition = brokerSearchCondition, totalCount = brokerListCount });
        }
        public HttpResponseMessage SearchPartnerList1(int PartnersId)
        {
            if (PartnersId > 0)
            {
                var brokerSearchCondition = new BrokerSearchCondition
                {

                    PartnersId = PartnersId
                };
                var partnerList = _brokerService.GetBrokersByCondition(brokerSearchCondition).Select(p => new
                {
                    p.Id,
                    p.UserId,
                    PartnersName = p.WeiXinNumber,
                    p.PartnersId,
                    BrokerName = p.Brokername,
                    Nickname = p.Nickname,
                    Phone = p.Phone,
                    Regtime = p.Regtime,
                    Agentlevel = p.Agentlevel,
                    Headphoto = p.Headphoto,
                    Sfz = p.Sfz,
                    Amount = p.Amount,
                    status = EnumPartnerType.同意
                }).ToList().Select(p => new
                {
                    p.Id,
                    p.UserId,
                    p.PartnersName,
                    p.PartnersId,
                    BrokerName = p.BrokerName,
                    Nickname = p.Nickname,
                    Phone = p.Phone,
                    Regtime = p.Regtime.ToString("yyyy-MM-dd"),
                    Agentlevel = p.Agentlevel,
                    Headphoto = p.Headphoto,
                    Sfz = p.Sfz,
                    Amount = p.Amount,
                    status = EnumPartnerType.同意
                });
                var partnerListCount = _brokerService.GetBrokerCount(brokerSearchCondition);
                return PageHelper.toJson(new { List = partnerList, Condition = brokerSearchCondition, totalCount = partnerListCount });
            }
            else { return null; }

        }
        public HttpResponseMessage AddPartnerList([FromBody] PartnerListEntity partnerList)
        {
            var sech = new BrokerSearchCondition
            {
                Phone = partnerList.Phone,
                State=1
            };
            var user = (UserBase)_workContext.CurrentUser;
            if (user != null)
            {
                var broker = _brokerService.GetBrokerByUserId(user.Id);//获取当前用户
                if (broker != null)
                {
                    var getbroker = _brokerService.GetBrokersByCondition(sech).FirstOrDefault();//通过手机号查询经纪人
                    if (getbroker != null)
                    {
                        //判断是否是本身
                        if (broker.Id == getbroker.Id)
                        {
                            return PageHelper.toJson(PageHelper.ReturnValue(false, "对不起,不能添加本身"));
                        }
                        //判断要添加的这个经纪人是否有上家
                        if (getbroker.PartnersId == null || getbroker.PartnersId == 0)//查询他的上家是否存在
                        {
                            //1 添加到partnerList表中  

                            var entity = new PartnerListEntity();
                            entity.PartnerId = getbroker.Id;     //添加的下家
                            entity.Brokername = getbroker.Brokername;
                            entity.Phone = getbroker.Phone;
                            entity.Agentlevel = getbroker.Level.Name;
                            entity.Regtime = getbroker.Regtime;

                            entity.Adduser = broker.Id;
                            entity.Addtime = DateTime.Now;
                            entity.Upuser = broker.Id;
                            entity.Uptime = DateTime.Now;
                            entity.Broker = broker;
                            entity.Status = EnumPartnerType.默认;
                            //判断当前用户的合伙人个数是否》=3

                            PartnerListSearchCondition plsearCon = new PartnerListSearchCondition
                            {
                                Brokers = broker,
                                Status = EnumPartnerType.同意
                            };
                            if (_partnerlistService.GetPartnerListCount(plsearCon) >= 3)
                            {
                                return PageHelper.toJson(PageHelper.ReturnValue(true, "对不起,您的合伙人数已满 不能添加"));
                            }

                            if (_partnerlistService.Create(entity) != null)
                            {

                                return PageHelper.toJson(PageHelper.ReturnValue(true, "邀请成功!等待对方同意"));

                            }
                            else
                            {
                                return PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新失败!请与客服联系"));
                            }


                        }
                        else
                        {
                            return PageHelper.toJson(PageHelper.ReturnValue(false, "该用户已经是别人的合伙人了!"));

                        }


                    }
                    else
                    {
                        return PageHelper.toJson(PageHelper.ReturnValue(false, "该经纪人不存在"));
                    }
                }
            }
            return PageHelper.toJson(PageHelper.ReturnValue(false, "对不起,请登录"));






            //var list = _brokerService.GetBrokersByCondition(sech).FirstOrDefault();//通过手机号查询经纪人
            //if (list != null)
            //{
            //    if (list.PartnersId != 0)//查询他的上家是否存在
            //    {
            //        if (partnerList != null)
            //        {
            //            var entity = new PartnerListEntity();
            //            entity.PartnerId = list.Id;     //添加的下家
            //            entity.Phone = partnerList.Phone;

            //            if (list.Id == _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id).Id)
            //            {
            //                return PageHelper.toJson(PageHelper.ReturnValue(false, "不能添加自身!"));
            //            }

            //            //上家的属性
            //                 entity.Agentlevel = _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id).Level.Name;
            //                 entity.Brokername = _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id).Brokername;

            //                 entity.Regtime = DateTime.Now;
            //                 entity.Broker = _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id);

            //                 entity.Upuser = _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id).Id;
            //                 entity.Uptime = DateTime.Now;
            //                 entity.Adduser = _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id).Id;
            //                 entity.Addtime = DateTime.Now;
            //                 entity.Status = EnumPartnerType.默认;

            //            try
            //            {
            //                if (_partnerlistService.Create(entity) != null)
            //                {
            //                    return PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!等待对方同意"));
            //                }
            //            }
            //            catch
            //            {
            //                return PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!"));
            //            }
            //        }
            //        return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误!"));
            //    }
            //    return PageHelper.toJson(PageHelper.ReturnValue(false, "该用户已经是别人的合伙人了!"));
            //}
            //return PageHelper.toJson(PageHelper.ReturnValue(false, "该用户不存在"));


        }
示例#14
0
        public IQueryable<BrokerEntity> GetBrokersByCondition(BrokerSearchCondition condition)
        {
            var query = _brokerRepository.Table;
            try
            {
                if (condition.RegtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Regtime >= condition.RegtimeBegin.Value);
                }
                if (condition.RegtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Regtime < condition.RegtimeEnd.Value);
                }
                if (condition.AddtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Addtime >= condition.AddtimeBegin.Value);
                }
                if (condition.AddtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
                }
                if (condition.UptimeBegin.HasValue)
                {
                    query = query.Where(q => q.Uptime >= condition.UptimeBegin.Value);
                }
                if (condition.UptimeEnd.HasValue)
                {
                    query = query.Where(q => q.Uptime < condition.UptimeEnd.Value);
                }
                if (condition.Amount.HasValue)
                {
                    query = query.Where(q => q.Amount == condition.Amount.Value);
                }
                if (condition.Delflag.HasValue)
                {
                    query = query.Where(q => q.State == condition.Delflag.Value);
                }
                if (!string.IsNullOrEmpty(condition.Brokername))
                {
                    query = query.Where(q => q.Brokername.Contains(condition.Brokername));
                }
                if (!string.IsNullOrEmpty(condition.Nickname))
                {
                    query = query.Where(q => q.Nickname.Contains(condition.Nickname));
                }
                if (!string.IsNullOrEmpty(condition.Realname))
                {
                    query = query.Where(q => q.Realname.Contains(condition.Realname));
                }
                if (!string.IsNullOrEmpty(condition.Sfz))
                {
                    query = query.Where(q => q.Sfz.Contains(condition.Sfz));
                }
                if (!string.IsNullOrEmpty(condition.Sexy))
                {
                    query = query.Where(q => q.Sexy.Contains(condition.Sexy));
                }
                if (!string.IsNullOrEmpty(condition.Phone))
                {
                    query = query.Where(q => q.Phone==condition.Phone);
                }
                if (!string.IsNullOrEmpty(condition.Phone1))
                {
                    query = query.Where(q => q.Phone .Contains (condition.Phone1));
                }
                if (!string.IsNullOrEmpty(condition.Email))
                {
                    query = query.Where(q => q.Email.Contains(condition.Email));
                }
                if (!string.IsNullOrEmpty(condition.Headphoto))
                {
                    query = query.Where(q => q.Headphoto.Contains(condition.Headphoto));
                }
                if (!string.IsNullOrEmpty(condition.Agentlevel))
                {
                    query = query.Where(q => q.Agentlevel.Contains(condition.Agentlevel));
                }
                if (!string.IsNullOrEmpty(condition.Address))
                {
                    query = query.Where(q => q.Address.Contains(condition.Address));
                }
                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                if (condition.PartnersId >0)
                {
                    query = query.Where(q => condition .PartnersId ==q.Id);
                }
                if (condition.Levels != null )
                {
                    query = query.Where(q =>q.Level== condition.Levels);
                }
                if (condition.UserIds != null && condition.UserIds.Any())
                {
                    query = query.Where(q => condition.UserIds.Contains(q.UserId));
                }

                if (condition.Qqs != null && condition.Qqs.Any())
                {
                    query = query.Where(q => condition.Qqs.Contains(q.Qq));
                }
                if (condition.Zips != null && condition.Zips.Any())
                {
                    query = query.Where(q => condition.Zips.Contains(q.Zip));
                }
                if (condition.Totalpointss != null && condition.Totalpointss.Any())
                {
                    query = query.Where(q => condition.Totalpointss.Contains(q.Totalpoints));
                }
                if (condition.Addusers != null && condition.Addusers.Any())
                {
                    query = query.Where(q => condition.Addusers.Contains(q.Adduser));
                }
                if (condition.State!=2)
                {
                    query = query.Where(q => q.State == condition.State);
                }
                if (condition.Upusers != null && condition.Upusers.Any())
                {
                    query = query.Where(q => condition.Upusers.Contains(q.Upuser));
                }
                if (condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy.Value)
                    {
                        case EnumBrokerSearchOrderBy.OrderById:
                            query = condition.isDescending ? query.OrderByDescending(q => q.Id) : query.OrderBy(q => q.Id);
                            break;
                        case EnumBrokerSearchOrderBy.OrderByBrokername :
                            query = condition.isDescending ? query.OrderByDescending(q => q.Brokername ) : query.OrderBy(q => q.Brokername);
                            break;
                        case EnumBrokerSearchOrderBy.OrderByUserType:
                            query = condition.isDescending ? query.OrderByDescending(q => q.Usertype ) : query.OrderBy(q => q.Usertype);
                            break;
                        case EnumBrokerSearchOrderBy.OrderByUserRegtime :
                            query = condition.isDescending ? query.OrderByDescending(q => q.Regtime ) : query.OrderBy(q => q.Regtime);
                            break;
                        case EnumBrokerSearchOrderBy.OrderByPartnersName :
                            query = condition.isDescending ? query.OrderByDescending(q => q.PartnersName) : query.OrderBy(q => q.PartnersName);
                            break; 
                    }

                }
                else
                {
                    query = query.OrderBy(q => q.Id);
                }

                if (condition.UserType.HasValue)
                {
                    query = query.Where(c => c.Usertype == condition.UserType);
                }
                else
                {
                   // query = query.OrderBy(q => q.Usertype);
                }

                if (condition.Page.HasValue && condition.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1) * condition.PageCount.Value).Take(condition.PageCount.Value);
                }
                return query;
            }
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return null;
            }
        }
示例#15
0
 public int GetBrokerCount(BrokerSearchCondition condition)
 {
     var query = _brokerRepository.Table;
     try
     {
         if (condition.RegtimeBegin.HasValue)
         {
             query = query.Where(q => q.Regtime >= condition.RegtimeBegin.Value);
         }
         if (condition.RegtimeEnd.HasValue)
         {
             query = query.Where(q => q.Regtime < condition.RegtimeEnd.Value);
         }
         if (condition.AddtimeBegin.HasValue)
         {
             query = query.Where(q => q.Addtime >= condition.AddtimeBegin.Value);
         }
         if (condition.AddtimeEnd.HasValue)
         {
             query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
         }
         if (condition.State != 2)
         {
             query = query.Where(q => condition.State == q.State);
         }
         if (condition.UptimeBegin.HasValue)
         {
             query = query.Where(q => q.Uptime >= condition.UptimeBegin.Value);
         }
         if (condition.UptimeEnd.HasValue)
         {
             query = query.Where(q => q.Uptime < condition.UptimeEnd.Value);
         }
         if (condition.Amount.HasValue)
         {
             query = query.Where(q => q.Amount == condition.Amount.Value);
         }
         if (condition.Delflag.HasValue)
         {
             query = query.Where(q => q.State == condition.Delflag.Value);
         }
         if (!string.IsNullOrEmpty(condition.Brokername))
         {
             query = query.Where(q => q.Brokername.Contains(condition.Brokername));
         }
         if (!string.IsNullOrEmpty(condition.Nickname))
         {
             query = query.Where(q => q.Nickname.Contains(condition.Nickname));
         }
         if (!string.IsNullOrEmpty(condition.Realname))
         {
             query = query.Where(q => q.Realname.Contains(condition.Realname));
         }
         if (!string.IsNullOrEmpty(condition.Sfz))
         {
             query = query.Where(q => q.Sfz.Contains(condition.Sfz));
         }
         if (!string.IsNullOrEmpty(condition.Sexy))
         {
             query = query.Where(q => q.Sexy.Contains(condition.Sexy));
         }
         if (!string.IsNullOrEmpty(condition.Phone))
         {
             query = query.Where(q => q.Phone==condition.Phone);
         }
         if (!string.IsNullOrEmpty(condition.Phone1))
         {
             query = query.Where(q => q.Phone.Contains(condition.Phone1));
         }
         if (!string.IsNullOrEmpty(condition.Headphoto))
         {
             query = query.Where(q => q.Headphoto.Contains(condition.Headphoto));
         }
         if (!string.IsNullOrEmpty(condition.Agentlevel))
         {
             query = query.Where(q => q.Agentlevel.Contains(condition.Agentlevel));
         }
         if (condition.UserType.HasValue)
         {
             query = query.Where(c => c.Usertype == condition.UserType);
         }
         if (!string.IsNullOrEmpty(condition.Address))
         {
             query = query.Where(q => q.Address.Contains(condition.Address));
         }
         if (condition.Ids != null && condition.Ids.Any())
         {
             query = query.Where(q => condition.Ids.Contains(q.Id));
         }
         if (condition.Levels != null)
         {
             query = query.Where(q =>q.Level== condition.Levels);
         }
         if (condition.UserIds != null && condition.UserIds.Any())
         {
             query = query.Where(q => condition.UserIds.Contains(q.UserId));
         }
         if (condition.Qqs != null && condition.Qqs.Any())
         {
             query = query.Where(q => condition.Qqs.Contains(q.Qq));
         }
         if (condition.Zips != null && condition.Zips.Any())
         {
             query = query.Where(q => condition.Zips.Contains(q.Zip));
         }
         if (condition.Totalpointss != null && condition.Totalpointss.Any())
         {
             query = query.Where(q => condition.Totalpointss.Contains(q.Totalpoints));
         }
         if (condition.Addusers != null && condition.Addusers.Any())
         {
             query = query.Where(q => condition.Addusers.Contains(q.Adduser));
         }
         if (condition.Upusers != null && condition.Upusers.Any())
         {
             query = query.Where(q => condition.Upusers.Contains(q.Upuser));
         }
         return query.Count();
     }
     catch (Exception e)
     {
         _log.Error(e, "数据库操作出错");
         return -1;
     }
 }