-
Notifications
You must be signed in to change notification settings - Fork 8
/
UserInfoRecordClass.php
125 lines (108 loc) · 2.18 KB
/
UserInfoRecordClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* 用户信息记录类
*
* 这个类主要是记录关注用户信息,方便进行和用户相关的
* 功能的扩展.
*
*
* @category UserInfoRecord
* @author Tairy <tairyguo@gmail.com>
* @copyright 2014 Tairy
* @version 0.0.1
*
*/
//{{{ UserInfoRecord
class UserInfoRecord{
// {{{ properties
/**
* 连接mongodb数据库对象
*
* @var MongoClient
* @access private
*
*/
private $mongo;
/**
* 选择操作数据库对象
*
* @var MongoClient
* @access private
*
*/
private $db;
// }}}
//{{{ __construct()
/**
* 构造函数
*
* @param void
* @access public
*
*/
function __construct(){
$this -> mongo = new MongoClient();
$this -> db = $this -> mongo -> selectDB("weichatuserinfo");
}
// }}}
// {{{ recordUserInfo($wx_id)
/**
*
* 记录用户微信id
*
* @param string $wx_id 用户微信id
* @access public
*
*/
public function recordUserInfo($wx_id){
$wx_id = (string)$wx_id;
$conllection = $this -> db -> userinfo;
if(!$this -> hasUserRecord($wx_id)){
$userId = time();
$userinfo = array(
"wx_id" => $wx_id,
"user_id" => $userId
);
$conllection -> insert($userinfo);
}
return $userId;
}
// }}}
// {{{ hasUserRecord($wx_id)
/**
*
* 查询某个用户是否存在
*
* @param string $wx_id 用户微信id
* @access public
* @return 存在返回true 不存在返回 false
*
* */
public function hasUserRecord($wx_id){
$wx_id = (string)$wx_id;
$collection = $this -> db -> userinfo;
$cursor = $collection -> findOne(array('wx_id' => $wx_id));
if(empty($cursor)){
return false;
}else{
return true;
}
}
// }}}
public function getUseridByWxid($wx_id){
$wx_id = (string)$wx_id;
$collection = $this -> db -> userinfo;
$userinfo = $collection -> findOne(array('wx_id' => $wx_id));
return $userinfo['user_id'];
}
public function getHomeTemp($wx_id){
$wx_id = (string)$wx_id;
$collection = $this -> db -> userinfo;
$userinfo = $collection -> findOne(array('wx_id' => $wx_id));
if(empty($userinfo['home_temp'])){
return "未绑定温度测试设备";
}
return $userinfo['home_temp'];
}
}
// }}}