User.php
2.43 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
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
/**
* @property $id 主键ID
* @property $user_sn 客户编码
* @property $name 用户名
* @property $email 邮箱
* @property $email_verified_at 邮箱校验时间
* @property $password 密码
* @property $phone 手机号码
* @property $remark 备注
* @property $reg_source 注册来源 1网站 2人工新增
* @property $remember_token 记住登陆token
* @property $account_properties 账号属性,1是个人,2是企业
* @property $status 状态,1是正常,-1是禁用
* @property $company_name 公司名称
* @property $first_name 名字
* @property $sale_id 业务员
* @property $sale_name 业务员名字
* @property $last_name 姓氏
* @property $created_time 创建时间
* @property $update_time 更新时间
*/
class User extends BaseModel
{
use HasDateTimeFormatter;
protected $table = 'users';
public $timestamps = false;
const STATUS_NORMAL = 1;
const STATUS_DISABLE = -1;
const REG_SOURCE_WEB = 1;
const REG_SOURCE_MANUAL = 2;
const ACCOUNT_PROPERTIES_PERSONAL = 1;
const ACCOUNT_PROPERTIES_ENTERPRISE = 2;
//查看权限
public static $ruleViewList = [
self::SEM_USER_VIEW_ALL, //查看所有
self::SEM_USER_VIEW_SUB,//查看下级
];
const SEM_USER_VIEW_ALL = "sem_user_viewAllList";//查看所有
const SEM_USER_VIEW_SUB = "sem_user_viewSubList";//查看下级
public static function insertData($data)
{
return self::insertGetId($data);
}
public static function updateById($id, $update)
{
return self::where("id", $id)->update($update);
}
public static function getInfoByUserId($userId)
{
$res = self::where('id', $userId)->first();
return ($res) ? $res->toArray() : [];
}
// 批量获取用户信息
public static function getInfoByUserIds($userId)
{
return self::whereIn('id', $userId)->get()->keyBy('id')->toArray();
}
public static function getListByIdArr($userIdArr)
{
$res = self::wherein('id', $userIdArr)->get();
return ($res) ? $res->toArray() : [];
}
public static function updateByIdArr($idArr, $update)
{
return self::whereIn("id", $idArr)->update($update);
}
public function user_address()
{
return $this->hasMany(UserAddress::class, 'user_id', 'id');
}
}