using System; using Castle.ActiveRecord; using System.Text; using System.Data.SqlClient; using System.Data; using NHibernate.Criterion; namespace BizCom { [ActiveRecord("S_User")] public class SUser : ComBase { /// /// 内部编号 /// [PrimaryKey(PrimaryKeyType.Native)] public int ID { get; set; } private string _userCode=""; /// ///会员编号 /// [Property] public string UserCode { get{ return _userCode; } set{ _userCode=value; } } private string _userName=""; /// ///会员名 /// [Property] public string UserName { get{ return _userName; } set{ _userName=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 _userPic=""; /// /// /// [Property] public string UserPic { get{ return _userPic; } set{ _userPic=value; } } private string _email=""; /// ///邮箱 /// [Property] public string Email { get{ return _email; } set{ _email=value; } } private string _mobile=""; /// ///手机 /// [Property] public string Mobile { get{ return _mobile; } set{ _mobile=value; } } private string _passWord=""; /// ///密码 /// [Property] public string PassWord { get{ return _passWord; } set{ _passWord=value; } } private string _regionCode=""; /// ///所属地区编号 /// [Property] public string RegionCode { get{ return _regionCode; } set{ _regionCode=value; } } private int _sex=0; /// ///性别 /// [Property] public int Sex { get{ return _sex; } set{ _sex=value; } } /// ///注册时间 /// [Property] public DateTime? RegisterTime { get; set; } /// ///上一次登陆时间 /// [Property] public DateTime? PreTime { get; set; } /// ///最后一次登录时间 /// [Property] public DateTime? LastTime { get; set; } private string _loginIP=""; /// ///登录IP /// [Property] public string LoginIP { get{ return _loginIP; } set{ _loginIP=value; } } private string _ticket=""; /// ///登录票根 /// [Property] public string Ticket { get{ return _ticket; } set{ _ticket=value; } } private int _userCoins=0; /// /// /// [Property] public int UserCoins { get{ return _userCoins; } set{ _userCoins=value; } } private int _userPoints=0; /// ///会员积分 /// [Property] public int UserPoints { get{ return _userPoints; } set{ _userPoints=value; } } private double _userMoney=0; /// /// /// [Property] public double UserMoney { get{ return _userMoney; } set{ _userMoney=value; } } private bool _isFreeze=false; /// ///是否冻结 /// [Property] public bool IsFreeze { get{ return _isFreeze; } set{ _isFreeze=value; } } private int _schoolID = 0; /// ///关联学校 /// [Property] public int SchoolID { get { return _schoolID; } set { _schoolID = value; } } private bool _isVerify = false; /// ///是否手机验证 /// [Property] public bool IsVerify { get { return _isVerify; } set { _isVerify = value; } } private string _rKey = ""; /// /// /// [Property] public string RKey { get { return _rKey; } set { _rKey = value; } } private string _major = ""; /// /// /// [Property] public string Major { get { return _major; } set { _major = value; } } private string _qQ = ""; /// /// /// [Property] public string QQ { get { return _qQ; } set { _qQ = value; } } private string _weiXin = ""; /// /// /// [Property] public string WeiXin { get { return _weiXin; } set { _weiXin = 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 string _studentNo = ""; /// /// /// [Property] public string StudentNo { get { return _studentNo; } set { _studentNo = value; } } private string _miniopenid = ""; /// /// /// [Property] public string miniopenid { get { return _miniopenid; } set { _miniopenid = value; } } private string _ptTags = ""; /// ///+ /// [Property] public string ptTags { get { return _ptTags; } set { _ptTags = value; } } private string _soTags = ""; /// /// /// [Property] public string soTags { get { return _soTags; } set { _soTags = value; } } private int _userType = 0; /// /// /// [Property] public int UserType { get { return _userType; } set { _userType = value; } } private int _bc = 0; /// ///违约次数 /// [Property] public int bc { get { return _bc; } set { _bc = value; } } /// /// /// [Property] public DateTime? bctime { get; set; } private int _isremind = 0; /// /// /// [Property] public int isremind { get { return _isremind; } set { _isremind = value; } } private double _putMoney = 0; /// /// /// [Property] public double PutMoney { get { return _putMoney; } set { _putMoney = value; } } private double _earnMoney = 0; /// /// /// [Property] public double EarnMoney { get { return _earnMoney; } set { _earnMoney = value; } } private int _inviteId = 0; /// /// /// [Property] public int inviteId { get { return _inviteId; } set { _inviteId = value; } } private string _grade = ""; /// /// /// [Property] public string Grade { get { return _grade; } set { _grade = value; } } private string _faculties = ""; /// /// /// [Property] public string Faculties { get { return _faculties; } set { _faculties = value; } } private string _className = ""; /// /// /// [Property] public string ClassName { get { return _className; } set { _className = value; } } private int _addressId = 0; /// /// /// [Property] public int addressId { get { return _addressId; } set { _addressId = value; } } 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.RegisterTime = DateTime.Now; user.LoginIP = ip; user.Ticket = ticket; 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.Ticket = ticket;// CommonHelper.GetLoginTicket(SUser.UserName, SUser.LoginIP); SUser.LastTime = DateTime.Now; SUser.Update(); return SUser; } } }