作者 lyh

gx

... ... @@ -24,21 +24,16 @@ class NewsController extends BaseController
* @method
*/
public function lists(NewsModel $news,NewsCategoryLogic $newsCategoryLogic){
$this->map['project_id'] = $this->user['project_id'];
$this->map = $this->searchParam();
$lists = $news->lists($this->map,$this->page,$this->row,$this->order = 'sort',
['id','category_id','operator_id','status','created_at','updated_at','image','name','sort','url']);
if(!empty($lists['list'])){
if(!empty($lists) && !empty($lists['list'])){
$user = new User();
foreach ($lists['list'] as $k => $v){
if(!empty($v['category_id'])){
$v = $newsCategoryLogic->get_category_name($v);
}
$v['url'] = $this->user['domain'] . RouteMap::getRoute(RouteMap::SOURCE_NEWS, $v['id'], $this->user['project_id']);
if(!empty($v['image'])){
$v['image_link'] = getImageUrl($v['image']);
}
if(!empty($v['operator_id'])){
$v['operator_name'] = (new User())->getName($v['operator_id']);
}
$v = $newsCategoryLogic->get_category_name($v);
$v['url'] = $this->user['domain'] . $v['url'];
$v['image_link'] = getImageUrl($v['image']);
$v['operator_name'] = $user->getName($v['operator_id']);
$lists['list'][$k] = $v;
}
}
... ... @@ -46,6 +41,21 @@ class NewsController extends BaseController
}
/**
* @remark :处理列表返回参数
* @name :handleReturnParam
* @author :lyh
* @method :post
* @time :2023/9/14 10:01
*/
public function searchParam(){
$this->map['project_id'] = $this->user['project_id'];
if(isset($this->map['category_id']) && !empty($this->map['category_id'])){
$this->map['category_id'] = ['like','%'.$this->map['category_id'].'%'];
}
return $this->map;
}
/**
* @remark :根据状态数量
* @name :getStatusNumber
* @author :lyh
... ...
... ... @@ -25,14 +25,16 @@ class NewsCategoryLogic extends BaseLogic
* @method
*/
public function get_category_name($v){
//获取用户已读还是未读
$category_info = $this->model->list([
'id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
$str = '';
foreach ($category_info as $v1){
$str .= $v1['name'].',';
if(!empty($v['category_id'])){
//获取用户已读还是未读
$category_info = $this->model->list([
'id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
$str = '';
foreach ($category_info as $v1){
$str .= $v1['name'].',';
}
$v['category_name'] = trim($str,',');
}
$v['category_name'] = trim($str,',');
return $this->success($v);
}
... ...
... ... @@ -13,4 +13,5 @@ class NewsCategory extends Base
protected $table = 'gl_news_category';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -38,10 +38,14 @@ class User extends Base
* @time :2023/8/8 15:00
*/
public function getName($id){
$info = $this->read(['id'=>$id],['id','name']);
if($info === false){
return '用户不存在';
$name = '';
if(!empty($id)){
$info = $this->read(['id'=>$id],['id','name']);
if($info === false){
return '用户不存在';
}
$name = $info['name'];
}
return $info['name'];
return $name;
}
}
... ...