链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 lines
1.4 KiB

<?php
namespace App\Models\v3;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = 'lanzu_user';
protected $dateFormat = 'U';
public static $_GENDER = ['保密','男','女'];
public static $_STATUS = [0=>'禁用',1=>'正常'];
protected $appends = [
'gender_text',
'status_text'
];
public function getGenderTextAttribute($value)
{
$value = $value ? $value : $this->gender;
return isset(self::$_GENDER[$value]) ? self::$_GENDER[$value] : '';
}
public function getStatusTextAttribute($value)
{
$value = $value ? $value : $this->status;
return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
}
/**
* 获取单个用户信息
* @param int $id
* @param string $field
* @return object
*/
public static function getUserInfo($id,$field = '*')
{
return self::select($field)->find($id);
}
/**
* 获取用户数组
* id为键,name为值
* @return array
*/
public static function getUserArray()
{
$list = self::select('id','nick_name')
->where('status',1)
->whereNull('deleted_at')
->get();
$array = [];
if(count($list) > 0){
foreach ($list as $value) {
$array[$value->id] = $value->nick_name;
}
}
return $array;
}
}