83 lines
1.6 KiB
PHP
83 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use Hyperf\Database\Model\Builder;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $remark
|
|
* @property int $status
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class AdminRole extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'admin_role';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
protected array $guarded = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['id' => 'integer', 'status' => 'integer'];
|
|
|
|
const CREATED_AT = 'create_time';
|
|
|
|
const UPDATED_AT = 'update_time';
|
|
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return Builder|\Hyperf\Database\Model\Model|object|null
|
|
*/
|
|
public function getInfoById(int $id)
|
|
{
|
|
return $this->where('id', $id)->first();
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return Builder|\Hyperf\Database\Model\Model|object|null
|
|
*/
|
|
public function getInfoByName(string $name)
|
|
{
|
|
return $this->where('name', $name)->first();
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 获取批量数据
|
|
* @param $ids
|
|
* @return array
|
|
*/
|
|
public function getDataByIds($ids)
|
|
{
|
|
$data = $this->whereIn('id', $ids)->get();
|
|
if (empty($data)){
|
|
return [];
|
|
}
|
|
|
|
$res = [];
|
|
foreach ($data->toArray() as $one)
|
|
{
|
|
$res[$one['id']] = $one;
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
}
|