|
@@ -1,115 +1,116 @@
|
|
|
-<?php
|
|
|
-namespace User\Model;
|
|
|
-use Think\Model;
|
|
|
-use Org\Net\Http;
|
|
|
-
|
|
|
-/**
|
|
|
- * 用户模型
|
|
|
- * @author Superbee
|
|
|
- *
|
|
|
- */
|
|
|
-class UserModel extends Model {
|
|
|
-
|
|
|
- protected $fields = array('id', 'uid', 'diamond', 'nickname', 'coin', 'mobile', 'last_login', 'registertime',
|
|
|
- '_pk' => 'id', '_autoinc' => false);
|
|
|
-
|
|
|
- protected $_validate = array(
|
|
|
- array('nickname', 'require', '昵称不能为空!'), //默认情况下用正则进行验证
|
|
|
- array('mobile', '', '该手机号码已被占用', 0, 'unique', 1), // 新增的时候mobile字段是否唯一
|
|
|
- // 正则验证密码 [需包含字母数字以及@*#中的一种,长度为6-22位]
|
|
|
- array('password', '/^([a-zA-Z0-9@*#]{6,22})$/', '密码格式不正确,请重新输入!', 0),
|
|
|
- array('repassword', 'password', '确认密码不正确', 0, 'confirm'), // 验证确认密码是否和密码一致
|
|
|
- array('mobile', '/^1[34578]/d{9}$/', '手机号码格式不正确', 0), // 正则表达式验证手机号
|
|
|
- );
|
|
|
-
|
|
|
- protected $_auto = array(
|
|
|
- array('password', 'md5', 3, 'function'), // 对password字段在新增和编辑的时候使md5函数处理
|
|
|
- array('regdate', 'time', 1, 'function'), // 对regdate字段在新增的时候写入当前时间戳
|
|
|
- array('regip', 'get_client_ip', 1, 'function'), // 对regip字段在新增的时候写入当前注册ip地址
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
- public function __construct(){
|
|
|
- $this->dbName = "user";
|
|
|
- $this->db = M($this->dbName);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取页码当前信息
|
|
|
- * @param array $where
|
|
|
- * @param int $page
|
|
|
- * @return \Think\mixed
|
|
|
- */
|
|
|
- public function getInfo($page = 0, $where = array()) {
|
|
|
- return $this->db->where($where)->page(0, PAGE_ROW)->select();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取分页信息
|
|
|
- * @param array $where 查询条件
|
|
|
- * @return string
|
|
|
- */
|
|
|
- public function getPages($where = array()) {
|
|
|
- $p = getPages($this->db, $where, PAGE_ROW);
|
|
|
- return $p->show();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据id找到用户
|
|
|
- * @param int $id
|
|
|
- * @return \Think\mixed
|
|
|
- */
|
|
|
- public function getUserById($id) {
|
|
|
- return $this->db->where(array("id" => $id))->find();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 利用UID登陆,如果UID不存在则创建新的用户
|
|
|
- * @param string $uid 登陆唯一码
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function loginByUid($uid){
|
|
|
- $data = array();
|
|
|
- $id = 0;
|
|
|
- $info = $this->db->where(array("uid"=>$uid))->find();
|
|
|
-
|
|
|
- if($info){
|
|
|
- $data['d'] = $info['diamond'];
|
|
|
- $data['c'] = $info['coin'];
|
|
|
- $id = $info['id'];
|
|
|
- }else{
|
|
|
- $data['d'] = 0;
|
|
|
- $data['c'] = 0;
|
|
|
- $id = $this->createUser($uid);
|
|
|
- }
|
|
|
-
|
|
|
- if($id)
|
|
|
- $this->db->where(array('id'=>$id))->save(array('last_login'=>getCurrentTime())); // 更新最后登陆时间
|
|
|
-
|
|
|
- return $data;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建新用户
|
|
|
- * @param string $uid
|
|
|
- */
|
|
|
- private function createUser($uid){
|
|
|
- $data = array('id'=>getId(), 'uid'=>$uid, 'registertime'=>getCurrentTime());
|
|
|
- $this->db->add($data);
|
|
|
- return $data['id'];
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public function update(){
|
|
|
- $data = $this->db->create();
|
|
|
- return $this->db->save($data);
|
|
|
- }
|
|
|
-
|
|
|
- public function add(){
|
|
|
- $data = $this->db->create();
|
|
|
- return $this->db->add($data);
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
+<?php
|
|
|
+namespace User\Model;
|
|
|
+use Think\Model;
|
|
|
+use Org\Net\Http;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户模型
|
|
|
+ * @author Superbee
|
|
|
+ *
|
|
|
+ */
|
|
|
+class UserModel extends Model {
|
|
|
+
|
|
|
+ protected $fields = array('id', 'uid', 'diamond', 'nickname', 'coin', 'mobile', 'last_login', 'registertime',
|
|
|
+ '_pk' => 'id', '_autoinc' => false);
|
|
|
+
|
|
|
+ protected $_validate = array(
|
|
|
+ array('nickname', 'require', '昵称不能为空!'), //默认情况下用正则进行验证
|
|
|
+ array('mobile', '', '该手机号码已被占用', 0, 'unique', 1), // 新增的时候mobile字段是否唯一
|
|
|
+ // 正则验证密码 [需包含字母数字以及@*#中的一种,长度为6-22位]
|
|
|
+ array('password', '/^([a-zA-Z0-9@*#]{6,22})$/', '密码格式不正确,请重新输入!', 0),
|
|
|
+ array('repassword', 'password', '确认密码不正确', 0, 'confirm'), // 验证确认密码是否和密码一致
|
|
|
+ array('mobile', '/^1[34578]/d{9}$/', '手机号码格式不正确', 0), // 正则表达式验证手机号
|
|
|
+ );
|
|
|
+
|
|
|
+ protected $_auto = array(
|
|
|
+ array('password', 'md5', 3, 'function'), // 对password字段在新增和编辑的时候使md5函数处理
|
|
|
+ array('regdate', 'time', 1, 'function'), // 对regdate字段在新增的时候写入当前时间戳
|
|
|
+ array('regip', 'get_client_ip', 1, 'function'), // 对regip字段在新增的时候写入当前注册ip地址
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ public function __construct(){
|
|
|
+ $this->dbName = "user";
|
|
|
+ $this->db = M($this->dbName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取页码当前信息
|
|
|
+ * @param array $where
|
|
|
+ * @param int $page
|
|
|
+ * @return \Think\mixed
|
|
|
+ */
|
|
|
+ public function getInfo($page = 0, $where = array()) {
|
|
|
+ return $this->db->where($where)->page(0, PAGE_ROW)->select();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分页信息
|
|
|
+ * @param array $where 查询条件
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getPages($where = array()) {
|
|
|
+ $p = getPages($this->db, $where, PAGE_ROW);
|
|
|
+ return $p->show();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id找到用户
|
|
|
+ * @param int $id
|
|
|
+ * @return \Think\mixed
|
|
|
+ */
|
|
|
+ public function getUserById($id) {
|
|
|
+ return $this->db->where(array("id" => $id))->find();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 利用UID登陆,如果UID不存在则创建新的用户
|
|
|
+ * @param string $uid 登陆唯一码
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function loginByUid($uid){
|
|
|
+ $data = array();
|
|
|
+ $id = 0;
|
|
|
+ $info = $this->db->where(array("uid"=>$uid))->find();
|
|
|
+ print_r($expression)
|
|
|
+
|
|
|
+ if($info){
|
|
|
+ $data['d'] = $info['diamond'];
|
|
|
+ $data['c'] = $info['coin'];
|
|
|
+ $id = $info['id'];
|
|
|
+ }else{
|
|
|
+ $data['d'] = 0;
|
|
|
+ $data['c'] = 0;
|
|
|
+ $id = $this->createUser($uid);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($id)
|
|
|
+ $this->db->where(array('id'=>$id))->save(array('last_login'=>getCurrentTime())); // 更新最后登陆时间
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建新用户
|
|
|
+ * @param string $uid
|
|
|
+ */
|
|
|
+ private function createUser($uid){
|
|
|
+ $data = array('id'=>getId(), 'uid'=>$uid, 'registertime'=>getCurrentTime());
|
|
|
+ $this->db->add($data);
|
|
|
+ return $data['id'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function update(){
|
|
|
+ $data = $this->db->create();
|
|
|
+ return $this->db->save($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add(){
|
|
|
+ $data = $this->db->create();
|
|
|
+ return $this->db->add($data);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|