using Castle.ActiveRecord; using NHibernate.Criterion; using System; using System.Data; using System.Data.SqlClient; using System.Text; namespace BizCom { [ActiveRecord("S_User")] public class SUser : ComBase { /// /// /// [PrimaryKey(PrimaryKeyType.Native)] public int ID { get; set; } private string _lgName = ""; /// /// /// [Property] public string lgName { get { return _lgName; } set { _lgName = value; } } private string _nickName = ""; /// ///会员名 /// [Property] public string NickName { get { return _nickName; } set { _nickName = value; } } private string _realName = ""; /// /// /// [Property] public string RealName { get { return _realName; } set { _realName = value; } } private string _mobile = ""; /// ///手机 /// [Property] public string Mobile { get { return _mobile; } set { _mobile = value; } } private string _lgPwd = ""; /// ///密码 /// [Property] public string lgPwd { get { return _lgPwd; } set { _lgPwd = value; } } private string _userPic = ""; /// /// /// [Property] public string UserPic { get { return _userPic; } set { _userPic = value; } } private string _miniopenid = ""; /// /// /// [Property] public string miniopenid { get { return _miniopenid; } set { _miniopenid = value; } } private string _openid = ""; /// /// /// [Property] public string openid { get { return _openid; } set { _openid = value; } } private string _unionid = ""; /// /// /// [Property] public string unionid { get { return _unionid; } set { _unionid = value; } } private int _sex = 0; /// ///性别 /// [Property] public int Sex { get { return _sex; } set { _sex = value; } } private string _loginIP = ""; /// ///登录IP /// [Property] public string LoginIP { get { return _loginIP; } set { _loginIP = value; } } private int _state = 0; /// /// /// [Property] public int State { get { return _state; } set { _state = value; } } private int _expertID = 0; /// /// /// [Property] public int ExpertID { get { return _expertID; } set { _expertID = value; } } /// /// /// [Property] public DateTime? AddTime { get; set; } public static void Del(object id) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("delete from S_User where id=" + id); ExecuteNonQuery(sql.ToString()); } public static SUser GetByWeixin(string unionid) { SUser SUser = FindFirst(Expression.Sql(string.Format("unionid='{0}'", unionid))); return SUser; } public static SUser Get(string uname, string pwd) { return FindFirst(Expression.Sql(string.Format("lgName='{0}' and lgPwd='{1}'", uname, pwd))); } public static SUser GetByWeixinMiniOpenId(string uid, string opid) { SUser SUser = FindFirst(Expression.Sql(string.Format("unionid='{0}' or miniopenid='{1}'", uid, opid))); return SUser; } public static SUser GetByWeixinMiniOpenId(string opid) { SUser SUser = FindFirst(Expression.Sql(string.Format("miniopenid='{0}'", opid))); return SUser; } public static void UserSave(SUser user, string ip, string ticket) { UserSave(user, true, ip, ticket); } public static void UserSave(SUser user, bool isFeed, string ip, string ticket) { user.LoginIP = ip; user.Create(); } public static double GetUserMoney(int userId) { object obj = DbConn.ExecuteScalar("select usermoney from s_user where ID=" + userId); return Convert.ToDouble(obj); } public static string GetOpenId(int userId) { object obj = DbConn.ExecuteScalar("select miniopenid from s_user where ID=" + userId); if (obj != null) return obj.ToString(); return ""; } /// /// 查询是否已经存在当前用户 /// /// /// public static bool CheckExitsUser(string userName) { return CheckExits("UserName", userName); } public static bool CheckExitsNickName(string name) { string sql = "select count(0) from lc_user where username='{0}' or nickname='{0}'"; object result = DbConn.ExecuteScalar(string.Format(sql, name, name)); if (result == null) return false; if (Convert.ToInt32(result) > 0) return true; return false; } public static bool CheckExitsByWhere(string sWhere, string parms) { return Exists(sWhere, parms.Split(',')); } /// /// 查询某个字段值是否存在 /// /// /// /// public static bool CheckExits(string fieldName, string fieldValue) { return Exists(fieldName + "=?", fieldValue); } public static bool CheckUser(string key) { string sql = "select count(0) from lc_user where userName='{0}' or mobile='{0}' or email='{0}'"; object result = DbConn.ExecuteScalar(string.Format(sql, key)); if (result != null && Convert.ToInt32(result) > 0) return true; return false; } public static SUser GetUserBySomeCondition(string user, string mail, string mobile) { user = user == "" ? "$$$" : user; mobile = mobile == "" ? "$$$" : mobile; mail = mail == "" ? "$$$" : mail; return FindFirst(Expression.Sql(string.Format("UserName='{0}' or Mobile='{1}' or Email='{2}'", user, mobile, mail))); } /// /// 找回密码 /// /// /// /// public static SUser GetByUserMail(string user, string email) { //return Exists("Email=? and SecretSignal=?", email, secretSignal); SUser SUser = FindFirst(Expression.And(Expression.Eq("Email", email), Expression.Eq("UserName", user))); return SUser; } public static SUser GetByIdMail(int id, string email) { //return Exists("Email=? and SecretSignal=?", email, secretSignal); SUser SUser = FindFirst(Expression.And(Expression.Eq("Email", email), Expression.Eq("ID", id))); return SUser; } public static SUser GetByMail(string user) { //return Exists("Email=? and SecretSignal=?", email, secretSignal); SUser SUser = FindFirst(Expression.Or(Expression.Eq("Email", user), Expression.Eq("Mobile", user))); return SUser; } public static SUser GetUser(string user) { //return Exists("Email=? and SecretSignal=?", email, secretSignal); SUser SUser = FindFirst(Expression.Or(Expression.Eq("Email", user), Expression.Eq("Mobile", user))); return SUser; } /// /// 查询cookie的票据是否符合 /// /// /// /// public static SUser GetUserByCookie(string userName, string ticket) { //FindFirst(Expression.And(Expression.Eq("UserName", userName), Expression.Eq("Ticket", ticket))); SUser SUser = FindFirst(Expression.Sql(string.Format("(Mobile='{0}' or Email='{0}') and Ticket='{1}'", userName, ticket))); return SUser; } /// /// 查询用户名密码 /// /// /// /// public static SUser GetUserByPassWord(string key, string passWrod) { SUser SUser = FindFirst(Expression.Sql(string.Format("(Mobile='{0}' or Email='{0}') and PassWord='{1}'", key, passWrod))); return SUser; } public static SUser GetUserByUserId(string UserId, string passWrod) { SUser SUser = FindFirst(Expression.Sql(string.Format("ID='{0}'and PassWord='{1}'", UserId, passWrod))); return SUser; } public static SUser GetUserByUserId(string UserId) { SUser SUser = FindFirst(Expression.Sql(string.Format("ID='{0}'", UserId))); return SUser; } public static SUser GetUserByMobile(string mobile) { SUser SUser = FindFirst(Expression.Sql(string.Format("Mobile='{0}'", mobile))); return SUser; } public static void ResetPwd(string userIds) { string sql = "Update Lc_User set PassWord='4kTUiQQOdDM=' where ID in(" + userIds + ")"; DbConn.ExecuteNonQuery(sql); } /// /// 验证手机 /// /// /// /// /// public static string VerifyMobile(int userId, string mobile, string verifyCode) { string errMsg = ""; SqlParameter[] sqlParameter ={ new SqlParameter("@userId", SqlDbType.Int, 4), new SqlParameter("@mobile", SqlDbType.VarChar, 20), new SqlParameter("@verifyCode", SqlDbType.VarChar, 10), new SqlParameter("@errMsg",SqlDbType.VarChar,100)}; sqlParameter[0].Value = userId; sqlParameter[1].Value = mobile; sqlParameter[2].Value = verifyCode; sqlParameter[3].Direction = ParameterDirection.Output; DbConn.ExecuteScalar(CommandType.StoredProcedure, "sp_VerifyMobile", sqlParameter); errMsg = sqlParameter[3].Value.ToString(); return errMsg; } /// /// 发送短信验证 /// /// /// /// /// public static string SendSmsVerify(int userId, string mobile, string verifyCode) { string errMsg = ""; SqlParameter[] sqlParameter ={ new SqlParameter("@userId", SqlDbType.Int, 4), new SqlParameter("@mobile", SqlDbType.VarChar, 20), new SqlParameter("@verifyCode", SqlDbType.VarChar, 10), new SqlParameter("@errMsg",SqlDbType.VarChar,100)}; sqlParameter[0].Value = userId; sqlParameter[1].Value = mobile; sqlParameter[2].Value = verifyCode; sqlParameter[3].Direction = ParameterDirection.Output; DbConn.ExecuteScalar(CommandType.StoredProcedure, "sp_SendSms", sqlParameter); errMsg = sqlParameter[3].Value.ToString(); return errMsg; } /// /// 用户登录 /// /// /// /// public static SUser UserLogin(string key, string passWrod, string ip, string ticket) { SUser SUser = GetUserByPassWord(key, passWrod); //找不到 if (SUser == null) return null; //更改用户登录状态 SUser.LoginIP = ip; //CommonHelper.ClientIP; SUser.Update(); return SUser; } } }