Blame view

domain/user/UserRepository.php 1.6 KB
3a892ee0   xu   app-wx(v0.1.0 bui...
1
2
3
4
5
<?php

namespace domain\user;

use domain\user\models\User as UserModel;
afd2f743   xu   app-ht(v0.0.1 bui...
6
use domain\user\models\UserProfile as UserProfileModel;
3a892ee0   xu   app-wx(v0.1.0 bui...
7
8
9
10
11
12
13
14
15
16
17
18
19
20

/**
 * 手机验证码
 */
class UserRepository
{
    /**
     * @param $condition
     * @return static
     */
    public static function findOne($condition)
    {
        return UserModel::findOne($condition);
    }
d11ff394   xu   app-ht(v0.0.1 bui...
21
22
23
24
25
26
27
28
29
30

    /**
     * @param $offset
     * @param $limit
     * @param $map
     * @param string $orderDesc
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function getAdminUserList($offset, $limit, $map, $orderDesc = '')
    {
afd2f743   xu   app-ht(v0.0.1 bui...
31
        $UPT = UserProfileModel::tableName();
d11ff394   xu   app-ht(v0.0.1 bui...
32
33
        $userFind = UserModel::find();
        $userFind->alias('user');
afd2f743   xu   app-ht(v0.0.1 bui...
34
35
        $userFind->select(["user.*","upt.emergency_contact", "upt.emergency_person"]);
        $userFind->leftJoin("{$UPT} as upt", 'upt.user_id = user.id');
d11ff394   xu   app-ht(v0.0.1 bui...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        $userFind->where($map);
        if (empty($orderDesc)) {
            $orderDesc = "user.created_at desc";
        }
        $userFind->orderBy($orderDesc);
        $userFind->offset($offset);
        if ($limit) {
            $userFind->limit($limit);
        }
        $userList = $userFind->asArray()->all();

        return $userList;
    }

    /**
     * 获取总记录数
     * @param $map
     * @return int|string
     */
    public static function getAdminUserListCount($map)
    {
afd2f743   xu   app-ht(v0.0.1 bui...
57
58
59
60
61
        $UPT = UserProfileModel::tableName();
        $userFind = UserModel::find();
        $userFind->alias('user');
        $userFind->leftJoin("{$UPT} as upd", 'upd.user_id = user.id');
        $userFind->where($map);
d11ff394   xu   app-ht(v0.0.1 bui...
62

afd2f743   xu   app-ht(v0.0.1 bui...
63
        return $userFind->count();
d11ff394   xu   app-ht(v0.0.1 bui...
64
    }
3a892ee0   xu   app-wx(v0.1.0 bui...
65
}