UserRepository.php
2.75 KB
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
126
<?php
namespace domain\user;
use domain\user\models\User as UserModel;
use yii\base\NotSupportedException;
/**
* Class UserRepository
* @package domain\user
*/
class UserRepository
{
/**
* @param $where
* @param $offset
* @param $limit
* @return array|\yii\db\ActiveRecord[]
*/
static function getPageList($where, $offset, $limit)
{
$userFind = UserModel::find()->alias("m");
if (!empty($where)) {
$userFind->where($where);
}
if ($offset) {
$userFind->offset($offset);
}
if ($limit) {
$userFind->limit($limit);
}
$userFind->andWhere(["is_delete" => 0]);
$userFind->orderBy("m.id desc");
$userFind->asArray();
$dataList = $userFind->all();
return $dataList;
}
/**
* 列表页面分页器数量
* @param string $map
*/
static function getPageCount($map = '')
{
$userFind = UserModel::find()->alias("m");
if (!empty($map)) {
$userFind->where($map);
}
$userFind->andWhere(["is_delete" => 0]);
$pageCount = $userFind->count();
return $pageCount;
}
/**
* @param $id
* @param bool|false $asArr
* @return null|static
*/
static function selectOne($id, $asArr = false)
{
$user = UserModel::findOne($id);
if ($asArr && $user) {
$user = $user->toArray();
}
return $user;
}
/**
* @param $id
* @param bool|false $asArr
* @return null|static
*/
static function selectInfoById($id, $asArr = false)
{
if (empty($id)) {
return $asArr ? [] : null;
}
$user = UserModel::find();
$user->where("id = " . $id);
if ($asArr && $user) {
$user = $user->asArray();
}
$resultData = $user->one();
return $resultData;
}
/**
* @param $condition
* @param bool|false $asArr
* @return null|static
*/
static function findOne($condition)
{
$user = UserModel::findOne($condition);
return $user;
}
/**
* 通过openid查找用户
* @param $openId
* @param bool|false $asArr
* @return null|static
*/
static function findOneByOpenId($openId)
{
$user = UserModel::findOne(["openid" => $openId]);
return $user;
}
/** @inheritdoc */
public static function findIdentity($condition)
{
return UserModel::findByCondition($condition)->one();
}
/** @inheritdoc */
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
}