87 lines
1.7 KiB
PHP
87 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use app\admin\library\Auth;
|
|
use think\Model;
|
|
|
|
|
|
class Message extends Model
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// 表名
|
|
protected $name = 'message';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'datetime';
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'create_time';
|
|
protected $updateTime = 'update_time';
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'type_text'
|
|
];
|
|
|
|
|
|
|
|
public function getTypeList()
|
|
{
|
|
return ['1' => __('Type 1'), '2' => __('Type 2')];
|
|
}
|
|
|
|
|
|
public function getTypeTextAttr($value, $data)
|
|
{
|
|
$value = $value ?: ($data['type'] ?? '');
|
|
$list = $this->getTypeList();
|
|
return $list[$value] ?? '';
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 管理员权限
|
|
* @param $query
|
|
* @param Auth $auth
|
|
* @param string $auth_admin_id
|
|
* @return mixed
|
|
*/
|
|
public function scopeAuth($query, Auth $auth, string $admin_id_field='to_id'){
|
|
|
|
if(!$auth->isSuperAdmin()){
|
|
$query->where($admin_id_field,$auth->id);
|
|
}
|
|
return $query;
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 地域权限
|
|
* @param $query
|
|
* @param Auth $auth
|
|
* @param string $area_id_field
|
|
* @return mixed
|
|
*/
|
|
public function scopeAreaauth($query,Auth $auth,string $area_id_field='area_id'){
|
|
if(!$auth->isSuperAdmin()){
|
|
$areaIds = array_unique(array_filter(explode(',',trim($auth->area_ids))));
|
|
if(!in_array('*',$areaIds)){
|
|
$query->whereIn($area_id_field,$areaIds);
|
|
}
|
|
}
|
|
return $query;
|
|
}
|
|
|
|
}
|