微信微网开发,社区论坛开发,电子商务,电子商城,摇电视,h5网页等制定开发

价值咨询

我们与时代并进,不断吸取新鲜理念

新闻详情

微信商城-详情API-打开后端文件

微信商城-打开后端文件:Addons\News\Controller\ApiController.class.php


实现News/Api/getNewsDetail接口

增加getNewsDetail方法


/*

* 获取新闻详情

*/

function getNewsDetail() {

$mMap ['news_id'] = $cMap ['news_id'] = $map ['id'] = $newsId = I ( 'news_id', 0, 'intval' );

// 设置阅读数、和行为记录

$cMap ['uid'] = $uid = $this->mid;

$this->_set_user_act ( $newsId, $uid, 0 );

$data = M ( 'news' )->field ( 'id,title,intro,content,author,cTime,close_comment' )->where ( $map )->find ();

$data = empty ( $data ) ? [ ] : $data;

// 获取是否收藏

$cMap ['type'] = 1;

$collect = M ( 'news_user_act' )->where ( $cMap )->find ();

$data ['has_collect'] = empty ( $collect ) ? 0 : 1;

// 获取我的评论点赞

$likes = M ( 'news_comment_like' )->where ( array (

'uid' => $this->mid 

) )->getFields ( 'comment_id' );

// 获取所有评论

$allComment = M ( 'news_comment' )->where ( $mMap )->getFields ( 'id,uid' );

foreach ( $allComment as $k => $v ) {

$user = getUserInfo ( $v );

$userArr [$k] ['nickname'] = $user ['nickname'] ? $user ['nickname'] : '游客';

$userArr [$k] ['headimgurl'] = $user ['headimgurl'];

}

// 获取评论列表

$lcount = 10; // 首页显示$lcount-1 条评论

$comment = M ( 'news_comment' )->where ( $mMap )->order ( 'id desc' )->limit ( $lcount )->select ();

foreach ( $comment as &$cc ) {

// $user = getUserInfo($cc['uid']);

$cc ['nickname'] = $userArr [$cc ['id']] ['nickname'];

$cc ['headimgurl'] = $userArr [$cc ['id']] ['headimgurl'];

$cc ['cTime'] = time_format ( $cc ['cTime'] );

$cc ['has_like'] = intval ( in_array ( $cc ['id'], $likes ) ); // 用户有没点赞标识

$cc ['is_mine'] = $uid == $cc ['uid'] ? 1 : 0;

unset ( $cc ['token'] );

unset ( $cc ['uid'] );

}

foreach ( $comment as &$co ) {

if ($co ['to_cid'] > 0) {

$co ['to_nickname'] = $userArr [$co ['to_cid']] ['nickname'];

}

}

$comment = empty ( $comment ) ? [ ] : $comment;

if (count ( $comment ) < $lcount) {

// 没有更多内容

$data ['comment_lastid'] = 0;

} else {

$data ['comment_lastid'] = $comment [$lcount - 1] ['id'];

unset ( $comment [$lcount - 1] );

}

// $data['myuid']=$uid;

$data ['comment_lists'] = $comment;

// dump($comment);die;

// 获取广告

$data ['ad_lists'] = $this->_get_ad ( 1, $this->mid );

echo api_return ( 0, $data );

}

以上由可以微信商城开发的圆梦云整理发布。