73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
namespace app\api\lists\user;
|
|
|
|
use app\api\lists\BaseApiDataLists;
|
|
use app\common\enum\YesNoEnum;
|
|
use app\common\model\user\UserNotice;
|
|
use app\common\model\setting\Language;
|
|
use app\common\service\{FileService,UtilsService};
|
|
|
|
/**
|
|
* 用户消息列表
|
|
* Class UserNoticeLists
|
|
* @package app\api\lists\user
|
|
*/
|
|
class UserNoticeLists extends BaseApiDataLists
|
|
{
|
|
|
|
/**
|
|
* @notes 获取用户消息列表
|
|
* @return array
|
|
*@author bd
|
|
* @date 2024/01/31 14:07
|
|
*/
|
|
public function lists(): array
|
|
{
|
|
|
|
$field = 'id,title,content,read,langs,create_time';
|
|
$lists = UserNotice::field($field)
|
|
->where(['user_id' => $this->userId])
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->order(['create_time' => 'desc','id' => 'desc'])
|
|
->select()
|
|
->toArray();
|
|
|
|
//查询语言
|
|
$timeFormat = 'Y-m-d H:i:s';
|
|
$language = Language::where(['symbol' => $this->params['lang']])->findOrEmpty();
|
|
if (!$language->isEmpty()) {
|
|
$timeFormat = $language['time_format'];
|
|
}
|
|
|
|
foreach ($lists as &$item) {
|
|
$item['create_time'] = date($timeFormat, strtotime($item['create_time']));
|
|
//多语言替换
|
|
$data = UtilsService::get_langs_data($item['langs'],$this->params['lang']);
|
|
$data_title = '';
|
|
$data_content = '';
|
|
|
|
if(count($data) > 0){
|
|
$data_title = $data['title'];
|
|
$data_content = $data['content'];
|
|
}
|
|
|
|
$item['title'] = get_file_domain($data_title);
|
|
$item['content'] = get_file_domain($data_content);
|
|
unset($item['langs']);
|
|
}
|
|
|
|
return $lists;
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取用户消息数量
|
|
* @return int
|
|
* @author bd
|
|
* @date 2024/01/31 14:07
|
|
*/
|
|
public function count(): int
|
|
{
|
|
return UserNotice::where(['user_id' => $this->userId])->count();
|
|
}
|
|
} |