2023-01-18 17:10:33 +08:00
< ? php
namespace app\api\controller ;
use app\api\BaseController ;
use app\api\middleware\Auth ;
use think\facade\Db ;
/**
* 个人新鲜事接口 .
*/
class Personal extends BaseController
{
/**
* 控制器中间件 [ 不需要鉴权 ]
* @ var array
*/
protected $middleware = [
Auth :: class => [ 'except' => [ 'getdetails' , 'getpinglun' , 'getalllist' ] ]
];
/**
* 获取评论列表
*
* @ ApiTitle ( 获取评论列表 )
* @ ApiSummary ( 获取评论列表 )
* @ ApiMethod ( GET )
* @ ApiRoute ( / api / Personal / getCommentList )
* @ ApiHeaders ( name = token , type = string , required = true , description = " 请求的Token " )
* @ ApiParams ( name = " title " , type = " integer " , required = fasle , description = " 标题 " )
* @ ApiParams ( name = " page " , type = " string " , required = true , description = " 页数 " )
* @ ApiParams ( name = " limit " , type = " string " , required = true , description = " 每页条数 " )
* @ ApiReturnParams ( name = " code " , type = " integer " , required = true , sample = " 0 " )
* @ ApiReturnParams ( name = " msg " , type = " string " , required = true , sample = " 返回成功 " )
* @ ApiReturnParams ( name = " data " , type = " object " , sample = " { 'user_id':'int','user_name':'string','profile': { 'email':'string','age':'integer'}} " , description = " 扩展数据返回 " )
* @ ApiReturn ({
* 'code' : '1' ,
* 'msg' : '返回成功'
* })
*/
public function getCommentList ()
{
$user_id = JWT_UID ;
//根据个人村id进行查询
if ( JWT_UID ) {
$find = Db :: table ( 'fa_szxc_information_useraddress' ) -> where ( 'user_id' , JWT_UID ) -> find ();
if ( $find ) {
if ( $find [ 'auth_range' ] == 1 ) {
$where [] = $map [] = $map2 [] = $whe2 [] = [ 'village' , '=' , $find [ 'village_id' ]];
$whe [] = [ 'a.village' , '=' , $find [ 'village_id' ]];
} elseif ( $find [ 'auth_range' ] == 2 ) {
$where [] = $map [] = $map2 [] = $whe2 [] = [ 'township' , '=' , $find [ 'street_id' ]];
$whe [] = [ 'a.township' , '=' , $find [ 'street_id' ]];
} elseif ( $find [ 'auth_range' ] == 3 ) {
$where [] = $map [] = $map2 [] = $whe2 [] = [ 'county' , '=' , $find [ 'area_id' ]];
$whe [] = [ 'a.county' , '=' , $find [ 'area_id' ]];
}
}
}
// $www['village_id'] = $village_id;
// $user_id_arr = UserAddress::where($www)->column('user_id');
// $where[] = ['user_id', 'in', $user_id_arr];
$where [] = [ 'status' , 'in' , '0,1' ];
// 获取本人发布所有评论总数
$total1 = Db :: table ( 'fa_szxc_personal_news_comment' ) -> where ( $where ) -> count ();
$total2 = Db :: table ( 'fa_article_comment' ) -> where ( $where ) -> count ();
$total = $total1 + $total2 ;
// 获取当月发布总数
$monthday = get_month_begin_end ();
$map [] = $map2 [] = [ 'status' , 'in' , '0,1' ];
$map [] = [ 'createtime' , 'between' , [ $monthday [ 'beginThismonth' ], $monthday [ 'endThismonth' ]]];
$map2 [] = [ 'add_time' , 'between' , [ $monthday [ 'beginThismonth' ], $monthday [ 'endThismonth' ]]];
$month1 = Db :: table ( 'fa_szxc_personal_news_comment' ) -> where ( $map ) -> count ();
$month2 = Db :: table ( 'fa_article_comment' ) -> where ( $map2 ) -> count ();
$month = $month1 + $month2 ;
// 获取评论列表
$title = $this -> request -> get ( 'keyword' );
if ( $title ) {
$whe [] = [ 'a.content' , 'like' , '%' . $title . '%' ];
$whe2 [] = [ 'content' , 'like' , '%' . $title . '%' ];
}
$whe [] = [ 'a.status' , '=' , 0 ];
$page = $this -> request -> get ( 'page' , 1 );
$limit = $this -> request -> get ( 'limit' , 10 );
2023-01-30 10:02:23 +08:00
$list = Db :: table ( 'fa_szxc_personal_news_comment' ) -> alias ( 'a' ) -> join ([ 'fa_szxc_personal_news' => 'b' ], 'a.personal_news_id=b.id' ) -> where ( $whe ) -> field ( 'a.id,a.content,a.createtime,a.user_id,b.user_id as uid' ) -> select () -> toArray ();
2023-01-18 17:10:33 +08:00
if ( $list ) {
foreach ( $list as $key => $value ) {
$list [ $key ][ 'createtime' ] = date ( 'Y-m-d' , $value [ 'createtime' ]);
$list [ $key ][ 'news_author' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $value [ 'uid' ]) -> value ( 'name' );
$list [ $key ][ 'username' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $value [ 'user_id' ]) -> value ( 'name' );
$list [ $key ][ 'avatar' ] = Db :: table ( 'fa_user' ) -> where ( 'id' , $value [ 'user_id' ]) -> value ( 'avatar' );
$list [ $key ][ 'type' ] = 'friends' ;
}
}
$whe2 [] = [ 'status' , '=' , 0 ];
$list2 = Db :: table ( 'fa_article_comment' ) -> where ( $whe2 ) -> field ( 'id,content,add_time,vote_id' ) -> select () -> toArray ();
if ( $list2 ) {
foreach ( $list2 as $key => $value ) {
$uid = Db :: table ( 'fa_article' ) -> where ( 'id' , $value [ 'vote_id' ]) -> value ( 'user_id' );
$list2 [ $key ][ 'createtime' ] = substr ( $value [ 'add_time' ], 0 , 10 );
$list2 [ $key ][ 'news_author' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $uid ) -> value ( 'name' );
$list2 [ $key ][ 'username' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $uid ) -> value ( 'name' );
$list2 [ $key ][ 'avatar' ] = Db :: table ( 'fa_user' ) -> where ( 'id' , $uid ) -> value ( 'avatar' );
$list2 [ $key ][ 'type' ] = 'article' ;
}
}
$list = array_merge ( $list , $list2 );
// dump($list);die;
$return [ 'total_num' ] = $total ;
$return [ 'now_num' ] = $month ;
$return [ 'data' ] = $list ;
$this -> apiSuccess ( '获取成功' , $return , 1 );
}
/**
* 一键审核
*
* @ ApiTitle ( 一键审核 )
* @ ApiSummary ( 一键审核 )
* @ ApiMethod ( GET )
* @ ApiRoute ( / api / Personal / oneCAlickAudit )
* @ ApiHeaders ( name = token , type = string , required = true , description = " 请求的Token " )
* @ ApiReturnParams ( name = " code " , type = " integer " , required = true , sample = " 0 " )
* @ ApiReturnParams ( name = " msg " , type = " string " , required = true , sample = " 返回成功 " )
* @ ApiReturnParams ( name = " data " , type = " object " , sample = " { 'user_id':'int','user_name':'string','profile': { 'email':'string','age':'integer'}} " , description = " 扩展数据返回 " )
* @ ApiReturn ({
* 'code' : '1' ,
* 'msg' : '返回成功'
* })
*/
public function oneCAlickAudit ()
{
$user_id = JWT_UID ;
//根据个人村id进行查询
if ( JWT_UID ) {
$find = Db :: table ( 'fa_szxc_information_useraddress' ) -> where ( 'user_id' , JWT_UID ) -> find ();
if ( $find ) {
if ( $find [ 'auth_range' ] == 1 ) {
$where [] = [ 'village' , '=' , $find [ 'village_id' ]];
} elseif ( $find [ 'auth_range' ] == 2 ) {
$where [] = [ 'township' , '=' , $find [ 'street_id' ]];
} elseif ( $find [ 'auth_range' ] == 3 ) {
$where [] = [ 'county' , '=' , $find [ 'area_id' ]];
}
}
}
$where [] = [ 'status' , '=' , 0 ];
$data [ 'status' ] = $data2 [ 'status' ] = 1 ;
$data [ 'updatetime' ] = time ();
// Db::startTrans();
// try {
Db :: table ( 'fa_szxc_personal_news_comment' ) -> where ( $where ) -> update ( $data );
Db :: table ( 'fa_article_comment' ) -> where ( $where ) -> update ( $data2 );
Db :: commit ();
$this -> apiSuccess ( '一键审核成功' );
// } catch (\Exception $e) {
// $this->apiSuccess('一键审核成功');
// }
}
/**
* 删除评论
*
* @ ApiTitle ( 删除评论 )
* @ ApiSummary ( 删除评论 )
* @ ApiMethod ( GET )
* @ ApiRoute ( / api / Personal / delComment )
* @ ApiHeaders ( name = token , type = string , required = true , description = " 请求的Token " )
* @ ApiReturnParams ( name = " code " , type = " integer " , required = true , sample = " 0 " )
* @ ApiReturnParams ( name = " msg " , type = " string " , required = true , sample = " 返回成功 " )
* @ ApiReturnParams ( name = " data " , type = " object " , sample = " { 'user_id':'int','user_name':'string','profile': { 'email':'string','age':'integer'}} " , description = " 扩展数据返回 " )
* @ ApiReturn ({
* 'code' : '1' ,
* 'msg' : '返回成功'
* })
*/
public function delComment ()
{
$id = $this -> request -> get ( 'id' );
$type = $this -> request -> get ( 'type' );
if ( empty ( $id ) || empty ( $type )) {
$this -> apiError ( '缺少参数' );
}
if ( $type == 'friends' ) { //朋友圈
$where [ 'id' ] = $id ;
$where [ 'status' ] = 0 ;
$res = Db :: table ( 'fa_szxc_personal_news_comment' ) -> where ( $where ) -> delete ();
if ( $res ) {
$this -> apiSuccess ( '删除成功' , $res , 1 );
} else {
$this -> apiError ( '删除失败' );
}
}
if ( $type == 'article' ) { //文章
$where [ 'id' ] = $id ;
$where [ 'status' ] = 0 ;
$res = Db :: table ( 'fa_article_comment' ) -> where ( $where ) -> delete ();
if ( $res ) {
$this -> apiSuccess ( '删除成功' , $res , 1 );
} else {
$this -> apiError ( '删除失败' );
}
}
}
/**
* 添加编辑个人新鲜事
*
* @ ApiTitle ( 添加编辑个人新鲜事 )
* @ ApiSummary ( 添加编辑个人新鲜事 )
* @ ApiMethod ( POST )
* @ ApiRoute ( / api / Personal / addOrEditNews )
* @ ApiHeaders ( name = token , type = string , required = true , description = " 请求的Token " )
* @ ApiParams ( name = " id " , type = " integer " , required = false , description = " 公告ID " )
* @ ApiParams ( name = " title " , type = " integer " , required = false , description = " 标题 " )
* @ ApiParams ( name = " content " , type = " integer " , required = false , description = " 内容 " )
* @ ApiParams ( name = " release_time " , type = " integer " , required = false , description = " 发布时间 " )
* @ ApiReturnParams ( name = " code " , type = " integer " , required = true , sample = " 0 " )
* @ ApiReturnParams ( name = " msg " , type = " string " , required = true , sample = " 返回成功 " )
* @ ApiReturnParams ( name = " data " , type = " object " , sample = " { 'user_id':'int','user_name':'string','profile': { 'email':'string','age':'integer'}} " , description = " 扩展数据返回 " )
* @ ApiReturn ({
* 'code' : '1' ,
* 'msg' : '返回成功'
* })
*/
public function addOrEditNews ()
{
$post = $this -> request -> post ();
$time = time ();
$useraddress = Db :: table ( 'fa_szxc_information_useraddress' ) -> where ( 'user_id' , JWT_UID ) -> where ( 'status' , 1 ) -> find ();
$data = [];
if ( $useraddress ) {
$data [ 'county' ] = $post [ 'county' ] = $useraddress [ 'area_id' ];
$data [ 'township' ] = $post [ 'township' ] = $useraddress [ 'street_id' ];
$data [ 'village' ] = $post [ 'village' ] = $useraddress [ 'village_id' ];
}
if ( isset ( $post [ 'topic_id' ]) && ! empty ( $post [ 'topic_id' ])){
$post [ 'category_id' ] = $post [ 'topic_id' ];
}
if ( empty ( $post [ 'category_id' ])){
$this -> apiError ( '请选择分类' );
}
// 公告ID
$id = $this -> request -> post ( 'id' );
if ( $id ) { //编辑
$map [ 'id' ] = $id ;
$is_have = Db :: table ( 'fa_szxc_personal_news' ) -> where ( $map ) -> find ();
if ( $is_have ) {
$data [ 'title' ] = $post [ 'title' ];
$data [ 'content' ] = $post [ 'content' ];
$data [ 'images' ] = $post [ 'images' ];
$data [ 'video' ] = $post [ 'video' ];
$data [ 'updatetime' ] = $time ;
$result = Db :: table ( 'fa_szxc_personal_news' ) -> where ( $map ) -> update ( $data );
if ( $result ) {
$this -> apiSuccess ( '发布成功' , null , 1 );
} else {
$this -> apiError ( '发布失败' );
}
} else {
$this -> apiError ( '未找到该说说' );
}
} else { //添加
$post [ 'createtime' ] = $time ;
$post [ 'user_id' ] = JWT_UID ;
$res = Db :: table ( 'fa_szxc_personal_news' ) -> strict ( false ) -> insert ( $post );
if ( $res ) {
$this -> apiSuccess ( '发布成功' , $res , 1 );
} else {
$this -> apiError ( '发布失败' );
}
}
}
/**
* 评论个人新鲜事
*
* @ ApiTitle ( 评论个人新鲜事 )
* @ ApiSummary ( 评论个人新鲜事 )
* @ ApiMethod ( POST )
* @ ApiRoute ( / api / Personal / newsComment )
* @ ApiHeaders ( name = token , type = string , required = true , description = " 请求的Token " )
* @ ApiParams ( name = " personal_news_id " , type = " integer " , required = true , description = " 新鲜事ID " )
* @ ApiParams ( name = " content " , type = " integer " , required = true , description = " 评论内容 " )
* @ ApiReturnParams ( name = " code " , type = " integer " , required = true , sample = " 0 " )
* @ ApiReturnParams ( name = " msg " , type = " string " , required = true , sample = " 返回成功 " )
* @ ApiReturnParams ( name = " data " , type = " object " , sample = " { 'user_id':'int','user_name':'string','profile': { 'email':'string','age':'integer'}} " , description = " 扩展数据返回 " )
* @ ApiReturn ({
* 'code' : '1' ,
* 'msg' : '返回成功'
* })
*/
public function newsComment ()
{
$post = $this -> request -> post ();
if ( ! $post [ 'personal_news_id' ]) {
$this -> apiError ( '缺少参数' );
}
$where [ 'id' ] = $post [ 'personal_news_id' ];
$news = Db :: table ( 'fa_szxc_personal_news' ) -> where ( $where ) -> find ();
if ( ! $news ) {
$this -> apiError ( '参数错误' );
}
if ( empty ( $post [ 'content' ])){
$this -> apiError ( '请输入评论内容' );
}
$useraddress = Db :: table ( 'fa_szxc_information_useraddress' ) -> where ( 'user_id' , JWT_UID ) -> where ( 'status' , 1 ) -> find ();
$data = [];
if ( $useraddress ) {
$post [ 'county' ] = $useraddress [ 'area_id' ];
$post [ 'township' ] = $useraddress [ 'street_id' ];
$post [ 'village' ] = $useraddress [ 'village_id' ];
}
$time = time ();
$post [ 'createtime' ] = $time ;
$post [ 'user_id' ] = JWT_UID ;
$res = Db :: table ( 'fa_szxc_personal_news_comment' ) -> strict ( false ) -> insert ( $post );
if ( $res ) {
$this -> apiSuccess ( '操作成功' , $res , 1 );
} else {
$this -> apiError ( '发布失败' );
}
}
// 获取说说详情
public function getdetails ( $id )
{
if ( empty ( $id )) {
$this -> apiError ( '缺少参数' );
}
$where [] = [ 'id' , '=' , $id ];
$news = Db :: table ( 'fa_szxc_personal_news' ) -> where ( $where ) -> find ();
if ( $news ) {
// 增加阅读数
// $ip = 'personal_news-details-' . $this->request->ip() . '-' . $id;
// $ip_cache = Cache::get($ip);
// if (empty($ip_cache)) {
// Cache::set($ip, $ip, 3600 * 24);
$map [] = [ 'id' , '=' , $id ];
Db :: table ( 'fa_szxc_personal_news' ) -> where ( $map ) -> inc ( 'view' , '1' ) -> update ();
// }
if ( $news [ 'images' ]) {
$news [ 'images' ] = json_decode ( $news [ 'images' ]);
}
$news [ 'view_time' ] = date ( " Y-m-d " , $news [ 'createtime' ]);
$news [ 'nickname' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $news [ 'user_id' ]) -> value ( 'name' );
$news [ 'avatar' ] = Db :: table ( 'fa_user' ) -> where ( 'id' , $news [ 'user_id' ]) -> value ( 'avatar' );
$this -> apiSuccess ( '获取成功' , $news );
} else {
$this -> apiError ( '获取失败' );
}
}
// 说说详情获取评论
public function getpinglun ()
{
$id = $this -> request -> get ( 'id' );
if ( empty ( $id )) {
$this -> apiError ( '缺少参数' );
}
$where [] = [ 'personal_news_id' , '=' , $id ];
$where [] = [ 'status' , '=' , 1 ];
$news = Db :: table ( 'fa_szxc_personal_news_comment' )
-> withAttr ( 'user_type_info' , function ( $value , $data ){
$political_outlook = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $data [ 'user_id' ]) -> value ( 'political_outlook' );
if ( $political_outlook ){
return Db :: table ( 'fa_category' ) -> where ( 'id' , $political_outlook ) -> value ( 'name' );
} else {
return '群众' ;
}
})
-> withAttr ( 'nickname' , function ( $value , $data ){
return Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $data [ 'user_id' ]) -> value ( 'name' );
})
-> withAttr ( 'avatar' , function ( $value , $data ){
return Db :: table ( 'fa_user' ) -> where ( 'id' , $data [ 'user_id' ]) -> value ( 'avatar' );
})
-> withAttr ( 'createtime' , function ( $value , $data ){
return date ( " Y-m-d " , $data [ 'createtime' ]);
})
-> where ( $where ) -> field ( 'id,user_id,content,createtime' ) -> select () -> toArray ();
$this -> apiSuccess ( '获取成功' , $news );
}
// 根据分类获取朋友圈列表
public function getlist ( $page = 1 , $county = 0 , $township = 0 , $village = 0 ){
$category_id = $this -> request -> get ( 'category_id' );
if ( empty ( $category_id )){
$this -> apiError ( '缺少参数' );
}
$address = Db :: table ( 'fa_szxc_information_useraddress' ) -> where ( 'user_id' , JWT_UID ) -> find ();
if ( $address ){
$where [] = [ 'county' , '=' , $address [ 'area_id' ]];
$where [] = [ 'township' , '=' , $address [ 'street_id' ]];
$where [] = [ 'village' , '=' , $address [ 'village_id' ]];
}
// if ($county != 0) {
// $where[] = ['county', '=', $county];
// }
// if ($township != 0) {
// $where[] = ['township', '=', $township];
// }
// if ($village != 0) {
//
// }
// 获取对应下级分类
$category_id_arr = Db :: table ( 'fa_category' ) -> where ( 'pid' , $category_id ) -> whereOr ( 'id' , $category_id ) -> column ( 'id' );
$where [] = [ 'category_id' , 'in' , $category_id_arr ];
$list = Db :: table ( 'fa_szxc_personal_news' )
-> withAttr ( 'user_info' , function ( $value , $data ) {
$user = Db :: table ( 'fa_user' ) -> where ( 'id' , $data [ 'user_id' ]) -> field ( 'nickname,avatar' ) -> find ();
$user [ 'name' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $data [ 'user_id' ]) -> value ( 'name' );
return $user ;
})
-> withAttr ( 'image' , function ( $value , $data ) {
if ( $data [ 'image' ] != '' ) {
return json_decode ( $data [ 'image' ], true );
}
})
-> withAttr ( 'article_comment' , function ( $value , $data ) {
return Db :: table ( 'fa_szxc_personal_news_comment' ) -> where ([[ 'personal_news_id' , '=' , $data [ 'id' ]],[ 'status' , '=' , 1 ]]) -> count ();
})
-> withAttr ( 'article_type' , function ( $value , $data ) {
return Db :: table ( 'fa_category' ) -> where ( 'id' , $data [ 'category_id' ]) -> value ( 'name' );
})
-> withAttr ( 'view_time' , function ( $value , $data ) {
return date ( 'Y-m-d H:i:s' , $value );
})
-> where ( $where )
-> field ( 'id,id as personal_news_id,content as title,user_id,view,createtime as view_time,images as image,video,category_id' )
-> limit ( 10 ) -> order ( 'id desc' ) -> page ( $page ) -> select () -> toArray ();
$this -> apiSuccess ( 'ok' , [ 'list' => $list ]);
}
//获取当前区域朋友圈列表
public function getlists ( $page = 1 ){
$address = Db :: table ( 'fa_szxc_information_useraddress' ) -> where ( 'user_id' , JWT_UID ) -> find ();
if ( $address ){
$where [] = [ 'county' , '=' , $address [ 'area_id' ]];
$where [] = [ 'township' , '=' , $address [ 'street_id' ]];
$where [] = [ 'village' , '=' , $address [ 'village_id' ]];
}
$list = Db :: table ( 'fa_szxc_personal_news' )
-> withAttr ( 'user_info' , function ( $value , $data ) {
$user = Db :: table ( 'fa_user' ) -> where ( 'id' , $data [ 'user_id' ]) -> field ( 'nickname,avatar' ) -> find ();
$user [ 'name' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $data [ 'user_id' ]) -> value ( 'name' );
return $user ;
})
-> withAttr ( 'image' , function ( $value , $data ) {
if ( $data [ 'image' ] != '' ) {
return json_decode ( $data [ 'image' ], true );
}
})
-> withAttr ( 'article_comment' , function ( $value , $data ) {
return Db :: table ( 'fa_szxc_personal_news_comment' ) -> where ([[ 'personal_news_id' , '=' , $data [ 'id' ]],[ 'status' , '=' , 1 ]]) -> count ();
})
-> withAttr ( 'article_type' , function ( $value , $data ) {
return Db :: table ( 'fa_category' ) -> where ( 'id' , $data [ 'category_id' ]) -> value ( 'name' );
})
-> withAttr ( 'view_time' , function ( $value , $data ) {
return date ( 'Y-m-d H:i:s' , $value );
})
-> where ( $where )
-> field ( 'id,id as personal_news_id,content as title,user_id,view,createtime as view_time,images as image,video,category_id' )
-> limit ( 10 ) -> order ( 'id desc' ) -> page ( $page ) -> select () -> toArray ();
$this -> apiSuccess ( 'ok' , [ 'list' => $list ]);
}
//获取所有朋友圈列表
public function getalllist ( $page = 1 ){
// $address = Db::table('fa_szxc_information_useraddress')->where('user_id',JWT_UID)->find();
// if($address){
// $where[] = ['county', '=', $address['area_id']];
// $where[] = ['township', '=', $address['street_id']];
// $where[] = ['village', '=', $address['village_id']];
// }
$list = Db :: table ( 'fa_szxc_personal_news' )
-> withAttr ( 'user_info' , function ( $value , $data ) {
$user = Db :: table ( 'fa_user' ) -> where ( 'id' , $data [ 'user_id' ]) -> field ( 'nickname,avatar' ) -> find ();
$user [ 'name' ] = Db :: table ( 'fa_szxc_information_usermsg' ) -> where ( 'user_id' , $data [ 'user_id' ]) -> value ( 'name' );
return $user ;
})
-> withAttr ( 'image' , function ( $value , $data ) {
if ( $data [ 'image' ] != '' ) {
return json_decode ( $data [ 'image' ], true );
}
})
-> withAttr ( 'article_comment' , function ( $value , $data ) {
return Db :: table ( 'fa_szxc_personal_news_comment' ) -> where ([[ 'personal_news_id' , '=' , $data [ 'id' ]],[ 'status' , '=' , 1 ]]) -> count ();
})
-> withAttr ( 'article_type' , function ( $value , $data ) {
return Db :: table ( 'fa_category' ) -> where ( 'id' , $data [ 'category_id' ]) -> value ( 'name' );
})
-> withAttr ( 'view_time' , function ( $value , $data ) {
return date ( 'Y-m-d H:i:s' , $value );
})
-> field ( 'id,id as personal_news_id,content as title,user_id,view,createtime as view_time,images as image,video,category_id' )
-> limit ( 10 ) -> order ( 'id desc' ) -> page ( $page ) -> select () -> toArray ();
$this -> apiSuccess ( 'ok' , [ 'list' => $list ]);
}
}