作者 lyh

gx

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