Esempio n. 1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <MobileSoft.Model.Unified.Tb_User> DataTableToList(DataTable dt)
        {
            List <MobileSoft.Model.Unified.Tb_User> modelList = new List <MobileSoft.Model.Unified.Tb_User>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                MobileSoft.Model.Unified.Tb_User model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model             = new MobileSoft.Model.Unified.Tb_User();
                    model.Id          = dt.Rows[n]["Id"].ToString();
                    model.Name        = dt.Rows[n]["Name"].ToString();
                    model.Mobile      = dt.Rows[n]["Mobile"].ToString();
                    model.Email       = dt.Rows[n]["Email"].ToString();
                    model.QQ          = dt.Rows[n]["QQ"].ToString();
                    model.QQToken     = dt.Rows[n]["QQToken"].ToString();
                    model.WeChatNum   = dt.Rows[n]["WeChatNum"].ToString();
                    model.WeChatToken = dt.Rows[n]["WeChatToken"].ToString();
                    model.NickName    = dt.Rows[n]["NickName"].ToString();
                    model.Pwd         = dt.Rows[n]["Pwd"].ToString();
                    model.UserPic     = dt.Rows[n]["UserPic"].ToString();
                    model.Sex         = Convert.ToInt32(dt.Rows[n]["Sex"]);
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Esempio n. 2
0
        private string RegisterUser_WeiXin_RH(DataRow Row)
        {
            string backstr = "";
            string UserId  = "";

            try
            {
                if (Row.Table.Columns.Contains("OpenId") && !string.IsNullOrEmpty(Row["OpenId"].ToString()))
                {
                    DataTable dTable = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT WeChatToken FROM Tb_User_WeiXin  where WeChatToken='" + Row["OpenId"].ToString() + "'").Tables[0];


                    if (dTable.Rows.Count > 0)
                    {
                        return(JSONHelper.FromString(false, "此用户已存在"));
                    }
                    else
                    {
                        string Pwd = "";
                        if (Row.Table.Columns.Contains("Pwd"))
                        {
                            Pwd = Row["Pwd"].ToString();
                        }
                        if (string.IsNullOrEmpty(Pwd))
                        {
                            return(JSONHelper.FromString(false, "密码不能为空"));
                        }
                        Random ro          = new Random();
                        string Name        = "";
                        string Email       = "";
                        string QQ          = "";
                        string QQToken     = "";
                        string WeChatToken = "";
                        string NickName    = Row["Mobile"].ToString();//游客

                        string UserPic = "";
                        int    Sex     = 1;
                        if (Row.Table.Columns.Contains("Name"))
                        {
                            Name = Row["Name"].ToString();
                        }
                        if (Row.Table.Columns.Contains("Email"))
                        {
                            Email = Row["Email"].ToString();
                        }
                        if (Row.Table.Columns.Contains("QQ"))
                        {
                            QQ = Row["QQ"].ToString();
                        }
                        if (Row.Table.Columns.Contains("QQToken"))
                        {
                            QQToken = Row["QQToken"].ToString();
                        }
                        if (Row.Table.Columns.Contains("WeChatToken"))
                        {
                            WeChatToken = Row["WeChatToken"].ToString();
                        }
                        if (Row.Table.Columns.Contains("NickName") && !string.IsNullOrEmpty(Row["NickName"].ToString()))
                        {
                            NickName = Row["NickName"].ToString();
                        }

                        if (Row.Table.Columns.Contains("UserPic"))
                        {
                            UserPic = Row["UserPic"].ToString();
                        }
                        if (Row.Table.Columns.Contains("Sex"))
                        {
                            Sex = AppGlobal.StrToInt(Row["Sex"].ToString());
                        }
                        MobileSoft.Model.Unified.Tb_User User = new MobileSoft.Model.Unified.Tb_User();
                        User.Id          = Guid.NewGuid().ToString();
                        User.Name        = Name;
                        User.Mobile      = Row["Mobile"].ToString();
                        User.QQ          = QQ;
                        User.QQToken     = QQToken;
                        User.WeChatNum   = WeChatToken;
                        User.WeChatToken = WeChatToken;
                        User.Pwd         = Pwd;
                        User.NickName    = NickName;
                        User.Email       = Email;
                        User.UserPic     = UserPic;
                        User.Sex         = Sex;
                        User.RegDate     = DateTime.Now;
                        //新增用户
                        new MobileSoft.BLL.Unified.Bll_Tb_User().Add(User);
                        UserId = User.Id;
                        //新增openid
                        new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).ExecuteSql("insert into Tb_User_WeiXin(UserId,WeChatToken) values('" + User.Id + "','" + Row["OpenId"] + "')");
                    }
                }
                else
                {
                    return(JSONHelper.FromString(false, "用户名不能为空!"));
                }
            }
            catch (Exception ex)
            {
                backstr = ex.Message;
            }
            if (backstr == "")
            {
                return(JSONHelper.FromString(true, UserId));
            }
            else
            {
                return(JSONHelper.FromString(false, backstr));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 注册用户微信共众号  RegisterUser_WeiXin
        /// </summary>
        /// <param name="Row"></param>
        /// OpenId              必填
        /// <returns></returns>
        private string RegisterUser_WeiXin_hnc(DataRow Row)
        {
            if (!Row.Table.Columns.Contains("OpenId") || string.IsNullOrEmpty(Row["OpenId"].ToString()))
            {
                return(JSONHelper.FromString(false, "请使用微信客户端打开"));
            }
            string OpenId = Row["OpenId"].ToString();
            //微信公众号注册,默认密码为123456
            //针对某些公众号系统不需要设置密码的问题(例如华南城)
            string Pwd;

            if (!Row.Table.Columns.Contains("Pwd") || string.IsNullOrEmpty(Row["Pwd"].ToString()))
            {
                Pwd = "123456";
            }
            else
            {
                Pwd = Row["Pwd"].ToString();
            }
            if (!Row.Table.Columns.Contains("Mobile") || string.IsNullOrEmpty(Row["Mobile"].ToString()))
            {
                return(JSONHelper.FromString(false, "手机号不能为空"));
            }
            string Mobile = Row["Mobile"].ToString();
            //查询系统中是否存在该openid
            DataTable dTable = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT * FROM Tb_User_WeiXin as w JOIN Tb_User as u on w.UserId = u.id  where w.WeChatToken = '" + Row["OpenId"].ToString() + "'").Tables[0];

            if (null != dTable && dTable.Rows.Count > 0)
            {
                //如果系统中已存在该openid,直接返回注册成功
                return(JSONHelper.FromString(true, "注册成功"));
            }
            //默认姓名为空
            string Name = "";
            //默认邮箱为空
            string Email = "";
            //默认QQ为空
            string QQ = "";
            //默认QQ登录为空
            string QQToken = "";
            //默认微信登录为空
            string WeChatToken = "";
            //默认昵称为手机号
            string NickName = Mobile;
            //默认用户头像为空
            string UserPic = "";
            //默认性别为女
            int Sex = 1;

            if (Row.Table.Columns.Contains("Name") && string.IsNullOrEmpty(Row["Name"].ToString()))
            {
                Name = Row["Name"].ToString();
            }
            if (Row.Table.Columns.Contains("Email") && string.IsNullOrEmpty(Row["Email"].ToString()))
            {
                Email = Row["Email"].ToString();
            }
            if (Row.Table.Columns.Contains("QQ") && string.IsNullOrEmpty(Row["QQ"].ToString()))
            {
                QQ = Row["QQ"].ToString();
            }
            if (Row.Table.Columns.Contains("QQToken") && string.IsNullOrEmpty(Row["QQToken"].ToString()))
            {
                QQToken = Row["QQToken"].ToString();
            }
            if (Row.Table.Columns.Contains("WeChatToken") && string.IsNullOrEmpty(Row["WeChatToken"].ToString()))
            {
                WeChatToken = Row["WeChatToken"].ToString();
            }
            if (Row.Table.Columns.Contains("NickName") && !string.IsNullOrEmpty(Row["NickName"].ToString()))
            {
                NickName = Row["NickName"].ToString();
            }

            if (Row.Table.Columns.Contains("UserPic") && !string.IsNullOrEmpty(Row["UserPic"].ToString()))
            {
                UserPic = Row["UserPic"].ToString();
            }
            if (Row.Table.Columns.Contains("Sex") && !string.IsNullOrEmpty(Row["Sex"].ToString()))
            {
                Sex = AppGlobal.StrToInt(Row["Sex"].ToString());
            }
            // 如果不存在该用户才新增,否则只增加绑定关系
            string    UserId;
            DataTable dt = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT * FROM Tb_User WHERE Mobile = '" + Mobile + "'").Tables[0];

            if (null == dt || dt.Rows.Count == 0)
            {
                UserId = Guid.NewGuid().ToString();
                MobileSoft.Model.Unified.Tb_User User = new MobileSoft.Model.Unified.Tb_User();
                User.Id          = UserId;
                User.Name        = Name;
                User.Mobile      = Mobile;
                User.QQ          = QQ;
                User.QQToken     = QQToken;
                User.WeChatNum   = WeChatToken;
                User.WeChatToken = WeChatToken;
                User.Pwd         = Pwd;
                User.NickName    = NickName;
                User.Email       = Email;
                User.UserPic     = UserPic;
                User.Sex         = Sex;
                User.RegDate     = DateTime.Now;
                //新增用户
                new MobileSoft.BLL.Unified.Bll_Tb_User().Add(User);
            }
            else
            {
                UserId = dt.Rows[0]["Id"].ToString();
            }
            //新增openid
            int result = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).ExecuteSql("insert into Tb_User_WeiXin(UserId,WeChatToken) values('" + UserId + "','" + Row["OpenId"] + "')");

            if (result == 0)
            {
                return(JSONHelper.FromString(false, "注册失败,请重试"));
            }
            try
            {
                string erpString = AppGlobal.GetConnectionString("HNC_HM_ConnectionString");
                // 查询业主
                using (IDbConnection conn = new SqlConnection(erpString))
                {
                    IEnumerable <dynamic> resultSet = conn.Query(string.Format(@"SELECT a.CustID,a.CustName,a.CommID,b.RoomID,c.RoomSign FROM Tb_HSPR_Customer as a JOIN Tb_HSPR_CustomerLive AS b ON a.CustID = b.CustID JOIN Tb_HSPR_Room AS c ON b.RoomID = c.RoomID
                        WHERE (b.LiveType=1 OR b.LiveType=2) AND isnull(IsDelLive,0)= 0 AND a.MobilePhone LIKE '%{0}%'", Mobile));

                    // 业主存在,自动绑定房屋
                    if (resultSet.Count() > 0)
                    {
                        foreach (dynamic item in resultSet)
                        {
                            Tb_Community tb_Community = getTbCommunity(item.CommID + "");
                            if (null == tb_Community)
                            {
                                continue;
                            }
                            using (IDbConnection conn2 = new SqlConnection(PubConstant.UnifiedContionString))
                            {
                                conn2.Execute(@"INSERT INTO Tb_User_Relation(Id, UserId, CommunityId, CustId, RoomId, RegDate, CustName, RoomSign, CustMobile)
                                            VALUES(newid(), @UserId, @CommunityId, @CustID, @RoomID, getdate(), @CustName, @RoomSign, @Mobile)",
                                              new { UserId = UserId, CommunityId = tb_Community.Id, CustID = item.CustID, RoomID = item.RoomID, CustName = item.CustName, RoomSign = item.RoomSign, Mobile = Mobile });
                            }
                        }
                        return(JSONHelper.FromString(true, "注册成功,已自动绑定房屋"));
                    }
                    return(JSONHelper.FromString(true, "注册成功"));
                }
            }
            catch (Exception ex)
            {
                return(JSONHelper.FromString(true, "注册成功,但自动绑定失败(" + ex.Message + ")"));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 注册用户微信共众号  RegisterUser_WeiXin
        /// </summary>
        /// <param name="Row"></param>
        /// OpenId              必填
        /// <returns></returns>
        private string RegisterUser_WeiXin(DataRow Row)
        {
            if (!Row.Table.Columns.Contains("OpenId") || string.IsNullOrEmpty(Row["OpenId"].ToString()))
            {
                return(JSONHelper.FromString(false, "请使用微信客户端打开"));
            }
            string OpenId = Row["OpenId"].ToString();
            //微信公众号注册,默认密码为123456
            //针对某些公众号系统不需要设置密码的问题(例如华南城)
            string Pwd;

            if (!Row.Table.Columns.Contains("Pwd") || string.IsNullOrEmpty(Row["Pwd"].ToString()))
            {
                Pwd = "123456";
            }
            else
            {
                Pwd = Row["Pwd"].ToString();
            }
            if (!Row.Table.Columns.Contains("Mobile") || string.IsNullOrEmpty(Row["Mobile"].ToString()))
            {
                return(JSONHelper.FromString(false, "手机号不能为空"));
            }
            string Mobile = Row["Mobile"].ToString();

            //查询系统中是否存在该openid
            DataTable dTable = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT * FROM Tb_User_WeiXin as w JOIN Tb_User as u on w.UserId = u.id  where w.WeChatToken = '" + Row["OpenId"].ToString() + "'").Tables[0];

            if (null != dTable && dTable.Rows.Count > 0)
            {
                //如果系统中已存在该openid,直接返回注册成功
                return(JSONHelper.FromString(true, "注册成功"));
            }
            //默认姓名为空
            string Name = "";
            //默认邮箱为空
            string Email = "";
            //默认QQ为空
            string QQ = "";
            //默认QQ登录为空
            string QQToken = "";
            //默认微信登录为空
            string WeChatToken = "";
            //默认昵称为手机号
            string NickName = Mobile;
            //默认用户头像为空
            string UserPic = "";
            //默认性别为女
            int Sex = 1;

            if (Row.Table.Columns.Contains("Name") && string.IsNullOrEmpty(Row["Name"].ToString()))
            {
                Name = Row["Name"].ToString();
            }
            if (Row.Table.Columns.Contains("Email") && string.IsNullOrEmpty(Row["Email"].ToString()))
            {
                Email = Row["Email"].ToString();
            }
            if (Row.Table.Columns.Contains("QQ") && string.IsNullOrEmpty(Row["QQ"].ToString()))
            {
                QQ = Row["QQ"].ToString();
            }
            if (Row.Table.Columns.Contains("QQToken") && string.IsNullOrEmpty(Row["QQToken"].ToString()))
            {
                QQToken = Row["QQToken"].ToString();
            }
            if (Row.Table.Columns.Contains("WeChatToken") && string.IsNullOrEmpty(Row["WeChatToken"].ToString()))
            {
                WeChatToken = Row["WeChatToken"].ToString();
            }
            if (Row.Table.Columns.Contains("NickName") && !string.IsNullOrEmpty(Row["NickName"].ToString()))
            {
                NickName = Row["NickName"].ToString();
            }

            if (Row.Table.Columns.Contains("UserPic") && !string.IsNullOrEmpty(Row["UserPic"].ToString()))
            {
                UserPic = Row["UserPic"].ToString();
            }
            if (Row.Table.Columns.Contains("Sex") && !string.IsNullOrEmpty(Row["Sex"].ToString()))
            {
                Sex = AppGlobal.StrToInt(Row["Sex"].ToString());
            }
            // 如果不存在该用户才新增,否则只增加绑定关系
            string    UserId;
            DataTable dt = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT * FROM Tb_User WHERE Mobile = '" + Mobile + "'").Tables[0];

            if (null == dt || dt.Rows.Count == 0)
            {
                UserId = Guid.NewGuid().ToString();
                MobileSoft.Model.Unified.Tb_User User = new MobileSoft.Model.Unified.Tb_User();
                User.Id          = UserId;
                User.Name        = Name;
                User.Mobile      = Mobile;
                User.QQ          = QQ;
                User.QQToken     = QQToken;
                User.WeChatNum   = WeChatToken;
                User.WeChatToken = WeChatToken;
                User.Pwd         = Pwd;
                User.NickName    = NickName;
                User.Email       = Email;
                User.UserPic     = UserPic;
                User.Sex         = Sex;
                User.RegDate     = DateTime.Now;
                //新增用户
                new MobileSoft.BLL.Unified.Bll_Tb_User().Add(User);
            }
            else
            {
                UserId = dt.Rows[0]["Id"].ToString();
            }
            //新增openid
            int result = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).ExecuteSql("insert into Tb_User_WeiXin(UserId,WeChatToken) values('" + UserId + "','" + Row["OpenId"] + "')");

            if (result == 0)
            {
                return(JSONHelper.FromString(false, "注册失败,请重试"));
            }
            return(JSONHelper.FromString(true, "注册成功"));
        }
Esempio n. 5
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="Row"></param>
        /// <returns></returns>
        private string RegisterUser(DataRow Row)
        {
            // 鸿坤
            if (HttpContext.Current.Request.Url.Host.Contains("wuyth-test.hongkun.com.cn") || HttpContext.Current.Request.Url.Host.Contains("wyyth-app.hongkun.com.cn"))
            {
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add(new DataColumn("Mobile", typeof(string)));
                dataTable.Columns.Add(new DataColumn("Password", typeof(string)));

                DataRow dataRow = dataTable.NewRow();
                dataRow[0] = Row["Mobile"];
                dataRow[1] = Row["Pwd"];
                return(new Register_th().RegisterUser(dataRow));
            }

            string backstr = "";

            try
            {
                if (Row.Table.Columns.Contains("Mobile") && !string.IsNullOrEmpty(Row["Mobile"].ToString()))
                {
                    DataTable dTable = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT Name FROM Tb_User  where Mobile='" + Row["Mobile"].ToString() + "'").Tables[0];
                    if (dTable.Rows.Count > 0)
                    {
                        return(JSONHelper.FromString(false, "此用户已存在"));
                    }
                    else
                    {
                        string Pwd = "";
                        if (Row.Table.Columns.Contains("Pwd"))
                        {
                            Pwd = Row["Pwd"].ToString();
                        }
                        if (string.IsNullOrEmpty(Pwd))
                        {
                            return(JSONHelper.FromString(false, "密码不能为空"));
                        }
                        Random ro          = new Random();
                        string Name        = "";
                        string Email       = "";
                        string QQ          = "";
                        string QQToken     = "";
                        string WeChatToken = "";
                        string NickName    = Row["Mobile"].ToString();//游客

                        string UserPic = "";
                        int    Sex     = 1;
                        if (Row.Table.Columns.Contains("Name"))
                        {
                            Name = Row["Name"].ToString();
                        }
                        if (Row.Table.Columns.Contains("Email"))
                        {
                            Email = Row["Email"].ToString();
                        }
                        if (Row.Table.Columns.Contains("QQ"))
                        {
                            QQ = Row["QQ"].ToString();
                        }
                        if (Row.Table.Columns.Contains("QQToken"))
                        {
                            QQToken = Row["QQToken"].ToString();
                        }
                        if (Row.Table.Columns.Contains("WeChatToken"))
                        {
                            WeChatToken = Row["WeChatToken"].ToString();
                        }
                        if (Row.Table.Columns.Contains("NickName") && !string.IsNullOrEmpty(Row["NickName"].ToString()))
                        {
                            NickName = Row["NickName"].ToString();
                        }

                        if (Row.Table.Columns.Contains("UserPic"))
                        {
                            UserPic = Row["UserPic"].ToString();
                        }
                        if (Row.Table.Columns.Contains("Sex"))
                        {
                            Sex = AppGlobal.StrToInt(Row["Sex"].ToString());
                        }
                        MobileSoft.Model.Unified.Tb_User User = new MobileSoft.Model.Unified.Tb_User();
                        User.Id          = Guid.NewGuid().ToString();
                        User.Name        = Name;
                        User.Mobile      = Row["Mobile"].ToString();
                        User.QQ          = QQ;
                        User.QQToken     = QQToken;
                        User.WeChatNum   = WeChatToken;
                        User.WeChatToken = WeChatToken;
                        User.Pwd         = Pwd;
                        User.NickName    = NickName ?? User.Mobile;
                        User.Email       = Email;
                        User.UserPic     = UserPic;
                        User.Sex         = Sex;
                        User.RegDate     = DateTime.Now;
                        new MobileSoft.BLL.Unified.Bll_Tb_User().Add(User);
                    }
                }
                else
                {
                    return(JSONHelper.FromString(false, "用户名不能为空!"));
                }
            }
            catch (Exception ex)
            {
                backstr = ex.Message;
            }
            if (backstr == "")
            {
                return(JSONHelper.FromString(true, "注册成功"));
            }
            else
            {
                return(JSONHelper.FromString(false, backstr));
            }
        }
Esempio n. 6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(MobileSoft.Model.Unified.Tb_User model)
 {
     dal.Update(model);
 }
Esempio n. 7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(MobileSoft.Model.Unified.Tb_User model)
 {
     dal.Add(model);
 }
Esempio n. 8
0
        /// <summary>
        /// 邀请用户
        /// </summary>
        private string InviteUser(DataRow row)
        {
            if (!row.Table.Columns.Contains("CommunityId") || string.IsNullOrEmpty(row["CommunityId"].ToString()))
            {
                return(JSONHelper.FromString(false, "缺少CommunityId参数"));
            }
            if (!row.Table.Columns.Contains("UserMobile") || string.IsNullOrEmpty(row["UserMobile"].ToString()))
            {
                return(JSONHelper.FromString(false, "缺少UserMobile参数"));
            }
            if (!row.Table.Columns.Contains("InviteMobile") || string.IsNullOrEmpty(row["InviteMobile"].ToString()))
            {
                return(JSONHelper.FromString(false, "缺少InviteMobile参数"));
            }
            if (!row.Table.Columns.Contains("InviteName") || string.IsNullOrEmpty(row["InviteName"].ToString()))
            {
                return(JSONHelper.FromString(false, "缺少InviteName参数"));
            }
            if (!row.Table.Columns.Contains("InviteType") || string.IsNullOrEmpty(row["InviteType"].ToString()))
            {
                return(JSONHelper.FromString(false, "缺少InviteType参数"));
            }

            var communityId  = row["CommunityId"].AsString();
            var userMobile   = row["UserMobile"].ToString();
            var inviteMobile = row["InviteMobile"].ToString();
            var inviteName   = row["InviteName"].ToString();
            var inviteType   = row["InviteType"].ToString();
            var relationship = UserRoomIdentityCode.Other;

            var roomId     = 0L;
            var relationId = default(string);

            if (row.Table.Columns.Contains("RelationId") && !string.IsNullOrEmpty(row["RelationId"].ToString()))
            {
                relationId = row["RelationId"].ToString();
            }
            if (row.Table.Columns.Contains("RoomID") && !string.IsNullOrEmpty(row["RoomID"].ToString()))
            {
                roomId = AppGlobal.StrToLong(row["RoomID"].ToString());
            }

            if (roomId == 0 && string.IsNullOrEmpty(relationId))
            {
                return(JSONHelper.FromString(false, "未指定绑定房屋"));
            }

            if (inviteType == ((int)UserRoomIdentity.Customer).ToString())
            {
                relationship = UserRoomIdentityCode.Customer2;
            }
            else if (inviteType == ((int)UserRoomIdentity.FamilyMember).ToString())
            {
                relationship = UserRoomIdentityCode.FamilyMember;
            }
            else if (inviteType == ((int)UserRoomIdentity.Tenant).ToString())
            {
                relationship = UserRoomIdentityCode.Tenant;
            }

            //查询小区
            Tb_Community Community = new MobileSoft.BLL.Unified.Bll_Tb_Community().GetModel(communityId);

            //构造链接字符串
            if (Community == null)
            {
                return(JSONHelper.FromString(false, "该小区不存在"));
            }

            string strcon = GetConnectionStringStr(Community);
            string message;

            using (var appConn = new SqlConnection(PubConstant.UnifiedContionString))
            {
                var sql      = @"SELECT CommName FROM Tb_Community WHERE Id=@Id";
                var commName = appConn.Query <string>(sql, new { Id = communityId }).FirstOrDefault();

                if (roomId == 0)
                {
                    sql = @"SELECT CustId,RoomId,RoomSign,CustName FROM Tb_User_Relation WHERE Id=@RelationId";
                }
                else
                {
                    sql = @"SELECT CustId,RoomId,RoomSign,CustName FROM Tb_User_Relation WHERE UserId IN(SELECT Id FROM Tb_User WHERE Mobile=@Mobile)";
                }

                var relationInfo = appConn.Query(sql, new { RelationId = relationId, Mobile = userMobile }).FirstOrDefault();
                if (relationInfo == null)
                {
                    return(JSONHelper.FromString(false, "该房屋所属业主还未注册到业主App"));
                }

                var custId   = AppGlobal.StrToLong(relationInfo.CustId);
                var roomSign = relationInfo.RoomSign?.ToString();
                var custName = relationInfo.CustName?.ToString();

                var holdId = 0L;

                // 判断客户信息是否已经插入到家庭成员表
                using (var erpConn = new SqlConnection(strcon))
                {
                    sql = @"SELECT HoldID FROM Tb_HSPR_Household 
                                WHERE CustID=@CustID AND RoomID=@RoomID 
                                AND (MobilePhone like @MobilePhone OR LinkManTel like @MobilePhone) AND isnull(IsDelete,0)=0";

                    holdId = erpConn.Query <long>(sql, new { CustID = custId, RoomID = roomId, MobilePhone = $"%{inviteMobile}%" }).FirstOrDefault();
                    if (holdId == 0)
                    {
                        // 客户信息插入到家庭成员表
                        var parameters = new DynamicParameters();
                        parameters.Add("@HoldID", 0, DbType.Int64, ParameterDirection.Output);
                        parameters.Add("@CommID", Community.CommID);
                        parameters.Add("@CustID", custId);
                        parameters.Add("@RoomID", roomId);
                        parameters.Add("@Name", inviteName);
                        parameters.Add("@MobilePhone", inviteMobile);
                        parameters.Add("@Relationship", relationship);
                        parameters.Add("@IsDelete", 0);

                        erpConn.Execute("Proc_HSPR_Household_Insert_Phone", parameters, null, null, CommandType.StoredProcedure);

                        // 家庭成员表id
                        holdId = parameters.Get <long>("@HoldID");
                    }
                }

                var userInfo = new MobileSoft.Model.Unified.Tb_User();
                var isAdd    = false;

                // 判断用户是否已经注册
                sql         = "SELECT Id FROM Tb_User WHERE Mobile=@Mobile";
                userInfo.Id = appConn.Query <string>(sql, new { Mobile = inviteMobile }).FirstOrDefault();
                if (userInfo.Id == null)
                {
                    isAdd = true;

                    // 注册用户
                    userInfo.Id       = Guid.NewGuid().ToString();
                    userInfo.Name     = inviteName;
                    userInfo.Mobile   = inviteMobile;
                    userInfo.Pwd      = "123456";
                    userInfo.NickName = inviteMobile;
                    userInfo.Sex      = 1;
                    userInfo.RegDate  = DateTime.Now;
                    new MobileSoft.BLL.Unified.Bll_Tb_User().Add(userInfo);
                }

                // 查询用户是否已经绑定该房屋
                sql = @"SELECT Id FROM Tb_User_Relation WHERE UserId=@UserId AND RoomId=@RoomID";
                var hasBinded = appConn.Query(sql, new { UserId = userInfo.Id, RoomID = roomId }).Count();
                if (hasBinded > 0)
                {
                    // 已经绑定,解锁,更新家庭成员id
                    sql = @"UPDATE Tb_User_Relation SET Locked=0,CustHoldId=@HoldID WHERE UserId=@UserId AND RoomId=@RoomID";
                    appConn.Execute(sql, new { UserId = userInfo.Id, RoomID = roomId, HoldID = holdId });
                }
                else
                {
                    // 未绑定,绑定房屋
                    sql = @"INSERT INTO Tb_User_Relation(Id,UserId,CommunityId,CustId,RoomId,RegDate,CustName,RoomSign,CustMobile,Locked) 
                            VALUES(@Id,@UserId,@CommunityId,@CustId,@RoomId,getdate(),@CustName,@RoomSign,@CustMobile,0)";

                    appConn.Execute(sql, new
                    {
                        Id          = Guid.NewGuid().ToString(),
                        UserId      = userInfo.Id,
                        CommunityId = communityId,
                        CustId      = custId,
                        RoomId      = roomId,
                        CustName    = custName,
                        RoomSign    = roomSign,
                        CustMobile  = userMobile
                    });
                }

                // 短信内容
                if (Community.CorpID == 1975)
                {
                    message = string.Format("\"{0}\"业主{1}为您绑定了编号为:{2}的房屋,关注微信公众号“第一亚太物业”,您可以对该房屋进行报事和缴费等操作。",
                                            commName, custName, roomSign);

                    if (isAdd)
                    {
                        message = string.Format("\"{0}\"业主{1}邀请您关注微信公众号“第一亚太物业”随时掌握房屋、小区信息,您的账号为:{2},初始密码为:123456。",
                                                commName, custName, inviteMobile);
                    }
                }
                else if (Community.CorpID == 1970)
                {
                    message = string.Format("温馨提示:\"{0}\"业主{1}为您绑定了编号为:{2}房屋,您可以对该房屋进行报事和缴费等操作。",
                                            commName, custName, roomSign);
                    if (isAdd)
                    {
                        message = string.Format(@"温馨提示:“{0}”业主{1}邀请您使用泰禾业主App,您的账号为:{2},初始密码为:123456,请及时下载登录泰禾App并修改密码,下载地址:http://t.cn/Rdo20xY",
                                                commName, custName, inviteMobile);
                    }
                }
                else
                {
                    message = string.Format("温馨提示:\"{0}\"业主{1}为您绑定了编号为:{2}的房屋,您可以对该房屋进行报事和缴费等操作。",
                                            commName, custName, roomSign);
                    if (isAdd)
                    {
                        message = string.Format("温馨提示:“{0}”业主{1}为您绑定了编号为:{2}的房屋,您的账号为:{3},初始密码为:123456,您可以对该房屋进行报事和缴费等操作。",
                                                commName, custName, roomSign, inviteMobile);
                    }
                }

                SendShortMessage(inviteMobile, message, out string errorMessage, Community.CorpID);
            }

            return(JSONHelper.FromString(true, "邀请成功"));
        }
Esempio n. 9
0
        /// <summary>
        /// 注册用户
        /// </summary>
        public string RegisterUser(DataRow Row)
        {
            if (!Row.Table.Columns.Contains("Mobile") || string.IsNullOrEmpty(Row["Mobile"].ToString()))
            {
                return(JSONHelper.FromString(false, "缺少Mobile参数"));
            }

            if (!Row.Table.Columns.Contains("Password") || string.IsNullOrEmpty(Row["Password"].ToString()))
            {
                return(JSONHelper.FromString(false, "缺少Password参数"));
            }

            string mobile   = Row["Mobile"].ToString();
            string password = Row["Password"].ToString();

            string backstr    = "注册失败";
            string connString = "";
            string dataSource = "";

            try
            {
                #region App版本判断
                if (HttpContext.Current.Request.Url.Host.Contains("wyerp.tahoecn.com"))
                {
                    // 泰禾正式
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=10.0.102.32;initial catalog=HM_wygl_new_1970;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_1970";
                }

                // 泰禾测试环境
                else if (HttpContext.Current.Request.Url.Host.Contains("test.wyerp.tahoecndemo.com"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=(local);initial catalog=HM_wygl_new_1970;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_1970";
                }

                // 俊发版本
                else if (HttpContext.Current.Request.Url.Host.Contains("120.79.213.157"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=172.18.148.25;initial catalog=HM_wygl_new_1985;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_1985";
                }

                // 海亮版本
                else if (HttpContext.Current.Request.Url.Host.Contains("hlland"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=(local);initial catalog=HM_wygl_new_2021;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_2021";
                }

                // 大发
                else if (HttpContext.Current.Request.Url.Host.Contains("dafa"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=(local);initial catalog=HM_wygl_new_2046;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_2046";
                }

                // 嘉和
                else if (HttpContext.Current.Request.Url.Host.Contains("180.139.137.50"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=192.168.1.42;initial catalog=HM_wygl_new_2046;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_2045";
                }

                // 鸿坤
                else if (HttpContext.Current.Request.Url.Host.Contains("wyyth-app.hongkun.com.cn"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=192.168.0.174;initial catalog=HM_wygl_new_1973;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_1973";
                }

                // 鸿坤测试
                else if (HttpContext.Current.Request.Url.Host.Contains("wuyth-test.hongkun.com.cn"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=192.168.0.236;initial catalog=HM_wygl_new_test;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_test";
                }

                // 金帝物业
                else if (HttpContext.Current.Request.Url.Host.Contains("218.56.176.26"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=218.56.176.27;initial catalog=HM_wygl_new_2091;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_2091";
                }

                // 润达
                else if (HttpContext.Current.Request.Url.Host.Contains("106.46.169.14"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=106.46.169.14;initial catalog=HM_wygl_new_2091;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_2091";
                }

                // 和家
                else if (HttpContext.Current.Request.Url.Host.Contains("47.105.34.12"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=47.104.233.12;initial catalog=Erp_Wygl_6008;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "Erp_Wygl_6008";
                }

                // 丽创
                else if (HttpContext.Current.Request.Url.Host.Contains("14.23.45.58"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=172.16.200.21;initial catalog=HM_wygl_new_1329;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_1329";
                }

                // 珠光
                else if (HttpContext.Current.Request.Url.Host.Contains("ygapp.zgproperty.cn"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=172.16.0.8;initial catalog=HM_wygl_new_1329;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_1329";
                }


                // 中集
                else if (HttpContext.Current.Request.Url.Host.Contains("120.79.228.111"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=120.79.228.111,8433;initial catalog=HM_wygl_new_1953;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "HM_wygl_new_1953";
                }
                //else if (HttpContext.Current.Request.Url.Host.Contains("localhost"))
                //{
                //    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=120.79.228.111,8433;initial catalog=HM_wygl_new_1953;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                //    dataSource = "HM_wygl_new_1953";
                //}


                else if (HttpContext.Current.Request.Url.Host.Contains("47.107.176.138"))
                {
                    connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=47.107.176.138;initial catalog=PMS_Base;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096";
                    dataSource = "PMS_Base";
                }
                #endregion

                if (string.IsNullOrEmpty(connString) || string.IsNullOrEmpty(dataSource))
                {
                    return(JSONHelper.FromString(false, "未配置ERP信息"));
                }

                DataTable dTable = new DbHelperSQLP(PubConstant.UnifiedContionString).Query("SELECT Name FROM Tb_User where Mobile='" + Row["Mobile"].ToString() + "'").Tables[0];
                if (dTable.Rows.Count > 0)
                {
                    return(JSONHelper.FromString(false, "此用户已存在"));
                }

                MobileSoft.Model.Unified.Tb_User User = new MobileSoft.Model.Unified.Tb_User();
                User.Id       = Guid.NewGuid().ToString();
                User.Name     = mobile;
                User.Mobile   = mobile;
                User.Pwd      = password;
                User.NickName = mobile;
                User.Sex      = 1;
                User.RegDate  = DateTime.Now;
                new MobileSoft.BLL.Unified.Bll_Tb_User().Add(User);

                using (var erpConn = new SqlConnection(connString))
                {
                    var holds = new List <long>();

                    // 1、查询客户信息
                    var sql = $@"SELECT CustID FROM Tb_HSPR_Customer 
                                 WHERE (MobilePhone LIKE '%{mobile}%' OR LinkmanTel LIKE '%{mobile}%') AND IsDelete=0";

                    var custId = erpConn.Query <long>(sql, null).FirstOrDefault();
                    if (custId != 0)
                    {
                        sql = @"SELECT a.*, b.CustName,b.MobilePhone,b.CommID,c.RoomSign,c.RoomName  
                                FROM Tb_HSPR_CustomerLive a 
                                LEFT JOIN Tb_HSPR_Customer b ON a.CustID=b.CustID 
                                LEFT JOIN Tb_HSPR_Room c ON a.RoomID=c.RoomID 
                                WHERE a.CustID=@CustID AND a.RoomID>=1 AND isnull(a.IsActive,0)=1 AND isnull(a.IsDelLive,0)=0";

                        // 查询客户拥有的房屋
                        var rooms = erpConn.Query(sql, new { CustID = custId });
                        if (rooms.Count() > 0)
                        {
                            foreach (dynamic roomInfo in rooms)
                            {
                                // 判断客户信息是否已经插入到家庭成员表
                                sql = @"SELECT HoldID FROM Tb_HSPR_Household 
                                        WHERE CustID=@CustID AND RoomID=@RoomID 
                                        AND (MobilePhone like @MobilePhone OR LinkManTel like @MobilePhone) AND isnull(IsDelete,0)=0";

                                var holdId = erpConn.Query <long>(sql, new { CustID = custId, RoomID = roomInfo.RoomID, MobilePhone = $"%{mobile}%" }).FirstOrDefault();
                                if (holdId == 0)
                                {
                                    // 判断客户身份
                                    var identity = "";
                                    if (roomInfo.LiveType == 1)     // 业主
                                    {
                                        identity = UserRoomIdentityCode.Customer2;
                                    }
                                    if (roomInfo.LiveType == 2)     // 租户
                                    {
                                        identity = UserRoomIdentityCode.Tenant;
                                    }

                                    // 客户信息插入到家庭成员表
                                    var parameters = new DynamicParameters();
                                    parameters.Add("@HoldID", 0, DbType.Int64, ParameterDirection.Output);
                                    parameters.Add("@CommID", roomInfo.CommID);
                                    parameters.Add("@CustID", roomInfo.CustID);
                                    parameters.Add("@RoomID", roomInfo.RoomID);
                                    parameters.Add("@Name", roomInfo.CustName);
                                    parameters.Add("@MobilePhone", mobile);
                                    parameters.Add("@Relationship", identity);
                                    parameters.Add("@IsDelete", 0);

                                    erpConn.Execute("Proc_HSPR_Household_Insert_Phone", parameters, null, null, CommandType.StoredProcedure);

                                    // 家庭成员表id
                                    holdId = parameters.Get <long>("@HoldID");
                                }

                                holds.Add(holdId);

                                // 自动绑定房屋
                                using (var appConn = new SqlConnection(PubConstant.UnifiedContionString))
                                {
                                    // 小区是否已经添加App系统
                                    sql = @"SELECT * FROM Tb_Community WHERE CommID=@CommID";
                                    var commInfo = appConn.Query(sql, new { CommID = roomInfo.CommID }).FirstOrDefault();
                                    if (commInfo != null)
                                    {
                                        sql = @"INSERT INTO Tb_User_Relation
                                                    (Id,UserId,CommunityId,CustId,CustHoldId,RoomId,RegDate,CustName,RoomSign,CustMobile)
                                                VALUES(newid(),@UserId,@CommunityId,@CustID,@HoldID,@RoomID,getdate(),@CustName,@RoomSign,@CustMobile)";

                                        appConn.Execute(sql, new
                                        {
                                            UserId      = User.Id,
                                            CommunityId = commInfo.Id,
                                            CustID      = custId,
                                            HoldID      = holdId,
                                            RoomID      = roomInfo.RoomID,
                                            CustName    = roomInfo.CustName,
                                            RoomSign    = (roomInfo.RoomName ?? roomInfo.RoomSign),
                                            CustMobile  = mobile
                                        });
                                    }
                                }
                            }
                        }
                    }

                    // 2、查询家庭成员表
                    sql = @"SELECT a.HoldID,a.CommID,a.CustID,b.CustName,b.MobilePhone AS CustMobile,a.RoomID,c.RoomSign,c.RoomName 
                            FROM Tb_HSPR_Household a 
                            LEFT JOIN Tb_HSPR_Customer b ON a.CustID=b.CustID
                            LEFT JOIN Tb_HSPR_Room c ON a.RoomID=c.RoomID
                            WHERE (a.MobilePhone like @MobilePhone OR a.LinkManTel like @MobilePhone) AND isnull(a.IsDelete,0)=0";

                    if (holds.Count != 0)
                    {
                        sql += $" AND a.HoldID NOT IN({ string.Join(",", holds) })";
                    }

                    var holdsInfo = erpConn.Query(sql, new { MobilePhone = $"%{mobile}%" });
                    if (holdsInfo.Count() > 0)
                    {
                        // 自动绑定房屋
                        using (var appConn = new SqlConnection(PubConstant.UnifiedContionString))
                        {
                            foreach (var holdInfo in holdsInfo)
                            {
                                // 小区是否已经添加App系统
                                sql = @"SELECT * FROM Tb_Community WHERE CommID=@CommID";
                                var commInfo = appConn.Query(sql, new { CommID = holdInfo.CommID }).FirstOrDefault();
                                if (commInfo != null)
                                {
                                    sql = @"INSERT INTO Tb_User_Relation
                                                    (Id,UserId,CommunityId,CustId,CustHoldId,RoomId,RegDate,CustName,RoomSign,CustMobile)
                                                VALUES(newid(),@UserId,@CommunityId,@CustID,@HoldID,@RoomID,getdate(),@CustName,@RoomSign,@CustMobile)";

                                    appConn.Execute(sql, new
                                    {
                                        UserId      = User.Id,
                                        CommunityId = commInfo.Id,
                                        CustID      = custId,
                                        HoldID      = holdInfo.HoldID,
                                        RoomID      = holdInfo.RoomID,
                                        CustName    = holdInfo.CustName,
                                        RoomSign    = (holdInfo.RoomName ?? holdInfo.RoomSign),
                                        CustMobile  = holdInfo.CustMobile
                                    });
                                }
                            }
                        }
                    }

                    return(JSONHelper.FromString(true, "注册成功"));
                }
            }
            catch (Exception ex)
            {
                backstr = ex.Message;
            }

            return(JSONHelper.FromString(false, backstr));
        }