| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- 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<SUser>
- {
- /// <summary>
- ///
- /// </summary>
- [PrimaryKey(PrimaryKeyType.Native)]
- public int ID { get; set; }
- private string _lgName = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string lgName
- {
- get { return _lgName; }
- set { _lgName = value; }
- }
- private string _nickName = "";
- /// <summary>
- ///会员名
- /// </summary>
- [Property]
- public string NickName
- {
- get { return _nickName; }
- set { _nickName = value; }
- }
- private string _realName = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string RealName
- {
- get { return _realName; }
- set { _realName = value; }
- }
- private string _mobile = "";
- /// <summary>
- ///手机
- /// </summary>
- [Property]
- public string Mobile
- {
- get { return _mobile; }
- set { _mobile = value; }
- }
- private string _lgPwd = "";
- /// <summary>
- ///密码
- /// </summary>
- [Property]
- public string lgPwd
- {
- get { return _lgPwd; }
- set { _lgPwd = value; }
- }
- private string _userPic = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string UserPic
- {
- get { return _userPic; }
- set { _userPic = value; }
- }
- private string _miniopenid = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string miniopenid
- {
- get { return _miniopenid; }
- set { _miniopenid = value; }
- }
- private string _openid = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string openid
- {
- get { return _openid; }
- set { _openid = value; }
- }
- private string _unionid = "";
- /// <summary>
- ///
- /// </summary>
- [Property]
- public string unionid
- {
- get { return _unionid; }
- set { _unionid = value; }
- }
- private int _sex = 0;
- /// <summary>
- ///性别
- /// </summary>
- [Property]
- public int Sex
- {
- get { return _sex; }
- set { _sex = value; }
- }
- private string _loginIP = "";
- /// <summary>
- ///登录IP
- /// </summary>
- [Property]
- public string LoginIP
- {
- get { return _loginIP; }
- set { _loginIP = value; }
- }
- private int _state = 0;
- /// <summary>
- ///
- /// </summary>
- [Property]
- public int State
- {
- get { return _state; }
- set { _state = value; }
- }
- private int _expertID = 0;
- /// <summary>
- ///
- /// </summary>
- [Property]
- public int ExpertID
- {
- get { return _expertID; }
- set { _expertID = value; }
- }
- /// <summary>
- ///
- /// </summary>
- [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 "";
- }
- /// <summary>
- /// 查询是否已经存在当前用户
- /// </summary>
- /// <param name="userName"></param>
- /// <returns></returns>
- 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(','));
- }
- /// <summary>
- /// 查询某个字段值是否存在
- /// </summary>
- /// <param name="fieldName"></param>
- /// <param name="fieldValue"></param>
- /// <returns></returns>
- 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)));
- }
- /// <summary>
- /// 找回密码
- /// </summary>
- /// <param name="user"></param>
- /// <param name="email"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 查询cookie的票据是否符合
- /// </summary>
- /// <param name="userName"></param>
- /// <param name="ticket"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 查询用户名密码
- /// </summary>
- /// <param name="key"></param>
- /// <param name="passWrod"></param>
- /// <returns></returns>
- 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);
- }
- /// <summary>
- /// 验证手机
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="mobile"></param>
- /// <param name="verifyCode"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 发送短信验证
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="mobile"></param>
- /// <param name="verifyCode"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 用户登录
- /// </summary>
- /// <param name="key"></param>
- /// <param name="passWrod"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|