User.php
1.23 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
<?php
namespace domain\user;
use Yii;
use domain\user\models\User as UserModel;
/**
* 维修厂
*/
class User
{
const STATUS_APPROVE = 1; //审核通过
const STATUS_REVIEWING = 2; //审核中
const STATUS_REJECT = 3; //审核拒绝
/**
* @param $data
* @return null|object
* @throws \yii\base\InvalidConfigException
*/
static function create($data)
{
if (empty($data)) {
return null;
}
$classData = [
'class' => UserModel::className()
];
foreach($data as $k => $v) {
$classData[$k] = $v;
}
$userModel = Yii::createObject($classData);
if($userModel->save()) {
return $userModel;
} else {
return null;
}
}
/**
* @param string $index
* @return array|string
*/
static function getStatusLabels($index = '')
{
$arr = [
self::STATUS_APPROVE => '审核通过',
self::STATUS_REVIEWING => '审核中',
];
if ('' === $index) {
return $arr;
}
if (isset($arr[$index])) {
return $arr[$index];
} else {
return '';
}
}
}