123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- <?php
- namespace app\api\controller;
- use app\api\controller\Base;
- use think\Db;
- use think\Model;
- class Index extends Base
- {
-
- public function cate(){
- $cate = Db::name('store_goods_cate')->field('id,title')->where('status',1)->where('is_deleted',0)->order('sort','desc')->select();
- $this->success('获取成功',$cate);
- }
-
- public function news_list(){
- $id = input('id');
- $last_id = input('last_id');
- $keyword = input('keyword');
- $page = input('page',1);
- $pageSize = input('page_size',10);
- if($keyword){
- $where = "title like '%".$keyword."%'";
-
- $uid = $this->get_uid();
- if($uid){
- $search_id = Db::name('store_search_keyword')->where('user_id',$uid)->where('type',1)->where('name',$keyword)->value('id');
- if(empty($search_id)){
- Db::name('store_search_keyword')->insert(array('user_id' => $uid, 'name' => $keyword));
- }
- }
- }else{
- $where = "id > 0";
- }
- if($id){
- $where .= " and cate_id = ".$id;
- }
- $field = 'id,title,user_id,image,video,is_top,create_at';
- $list = Db::name('store_goods')->field($field)->where('status',1)->where('is_deleted',0)->where($where)->page($page,$pageSize)->order(['is_top'=>'desc','sort'=>'desc','id'=>'desc'])->select();
-
- $num = 0;
- if($last_id){
- $num = Db::name('store_goods')->field($field)->where('status',1)->where('cate_id',$id)->where('is_deleted',0)->where('id','>',$last_id)->count('id');
- }
-
- $result_last_id = Db::name('store_goods')->field($field)->where('status',1)->where('cate_id',$id)->where('is_deleted',0)->order('id desc')->value('id');
- if($list){
- foreach($list as &$value) {
-
- $value['comment_num'] = Db::name('store_comment')->where('forum_id',$value['id'])->where('type',1)->where('forum_type',1)->count('id');
- $value['image'] = image_path($value['image']);
-
- $media_info = Db::name('store_media')->field('logo,title')->where('id',$value['user_id'])->find();
- $value['media_logo'] = $media_info['logo'];
- $value['media_title'] = $media_info['title'];
- $remain_time = time() - strtotime($value['create_at']);
- $value['duration'] = get_stay_time($remain_time);
- unset($value['user_id']);
- unset($value['create_at']);
- }
- }
- $data = array(
- 'last_id' => $result_last_id?$result_last_id:0,
- 'num' => $num,
- 'list' => $list
- );
- $this->success('获取成功',$data);
- }
-
- public function news_detail(){
- $uid = $this->get_uid();
- $id = input('id');
- if(empty($id)){
- $this->error('参数错误');
- }
- $field = 'id,title,user_id,content,create_at';
- $news_info = Db::name('store_goods')->field($field)->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($news_info)){
- $this->error('新闻信息有误');
- }
-
- $news_info['comment_num'] = Db::name('store_comment')->where('forum_id',$id)->where('type',1)->where('forum_type',1)->count('id');
-
- $news_info['like_num'] = Db::name('store_like')->where('forum_id',$id)->where('type',1)->where('status',1)->count('id');
-
- $news_info['transpond_num'] = Db::name('store_transpond')->where('forum_id',$id)->where('type',1)->where('status',1)->count('id');
- $news_info['is_attention'] = 0;
- $news_info['is_like'] = 0;
- $news_info['is_collect'] = 0;
- if($uid){
-
- $is_attention = Db::name('store_attention')->where('from_user_id',$news_info['user_id'])->where('user_id',$uid)->where('status',1)->count('id');
- if($is_attention){
- $news_info['is_attention'] = 1;
- }
-
- $is_like = Db::name('store_like')->where('forum_id',$id)->where('type',1)->where('user_id',$uid)->where('status',1)->count('id');
- if($is_like){
- $news_info['is_like'] = 1;
- }
-
- $is_collect = Db::name('store_collect')->where('forum_id',$id)->where('type',1)->where('user_id',$uid)->where('status',1)->count('id');
- if($is_collect){
- $news_info['is_collect'] = 1;
- }
- }
-
- $media_info = Db::name('store_media')->field('logo,title')->where('id',$news_info['user_id'])->find();
- $news_info['media_logo'] = $media_info['logo'];
- $news_info['media_title'] = $media_info['title'];
- $remain_time = time() - strtotime($news_info['create_at']);
- $news_info['duration'] = get_stay_time($remain_time);
- unset($news_info['create_at']);
- if($uid && $uid != $news_info['user_id']){
-
- $browse_id = Db::name('store_browse')->where('user_id',$uid)->where('forum_id',$id)->where('type',1)->value('id');
- if(empty($browse_id)){
- $data = array(
- 'user_id' => $uid,
- 'from_user_id' => $news_info['user_id'],
- 'forum_id' => $id,
- 'type' => 1,
- 'status' => 1
- );
- Db::name('store_browse')->insert($data);
- }
- }
- $this->success('获取成功',$news_info);
- }
-
- public function news_comment_list(){
- $id = input('id');
- $page = input('page',1);
- $pageSize = input('page_size',10);
- if(empty($id)){
- $this->error('参数错误');
- }
- $news_info = Db::name('store_goods')->field('id')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($news_info)){
- $this->error('新闻信息有误');
- }
-
- $comment_list = Db::name('store_comment')->field('id,user_id,content,create_time')->where('forum_id',$id)->where('type',1)->where('forum_type',1)->page($page,$pageSize)->order(['id'=>'desc'])->select();
- if($comment_list){
- foreach ($comment_list as $key=>&$value){
- $user_info = Db::name('store_member')->field('name,headimg,privacy_switch')->where('id',$value['user_id'])->find();
-
- $value['user_name'] = $user_info['name'];
- $value['user_headimg'] = $user_info['headimg'];
-
- $value['apply_num'] = Db::name('store_comment')->where('forum_id',$id)->where('type',2)->where('forum_type',1)->where('root_comment_id',$value['id'])->count('id');
- unset($value['user_id']);
- }
- }
- $this->success('获取成功',$comment_list);
- }
-
- public function news_reply_comment_list(){
- $id = input('id');
- $page = input('page',1);
- $pageSize = input('page_size',10);
- if(empty($id)){
- $this->error('参数错误');
- }
-
- $comment_info = Db::name('store_comment')->field('id,user_id,content')->where('id',$id)->where('type',1)->where('forum_type',1)->find();
- if(empty($comment_info)){
- $this->error('评论信息有误');
- }
- $member_info = Db::name('store_member')->field('name,headimg')->where('id',$comment_info['user_id'])->find();
- $comment_info['user_name'] = $member_info['name'];
- $comment_info['user_headimg'] = $member_info['headimg'];
- unset($comment_info['user_id']);
-
- $comment_list = Db::name('store_comment')->field('user_id,content,create_time')->where('root_comment_id',$id)->where('type',2)->page($page,$pageSize)->order(['id'=>'desc'])->select();
- if($comment_list){
- foreach ($comment_list as &$value){
- $user_info = Db::name('store_member')->field('name,headimg')->where('id',$value['user_id'])->find();
- $value['user_name'] = $user_info['name'];
- $value['user_headimg'] = $user_info['headimg'];
- unset($value['user_id']);
- }
- }
- $data = array(
- 'comment' => $comment_info,
- 'list' => $comment_list
- );
- $this->success('获取成功',$data);
- }
-
- public function attention_detail(){
- $user_id = input('user_id');
- if(empty($user_id)){
- $this->error('参数错误');
- }
- $user_type = user_type($user_id);
- if($user_type == 1){
- $user_info = Db::name('store_member')->field('name,headimg')->where('id',$user_id)->find();
- $user_name = $user_info['name'];
- $user_headimg = $user_info['headimg'];
- }else{
- $media_info = Db::name('store_media')->field('logo,title')->where('id',$user_id)->find();
- $user_name = $media_info['title'];
- $user_headimg = $media_info['logo'];
- }
-
- $is_attention = 0;
- $uid = $this->get_uid();
- if($uid){
- $attention_id = Db::name('store_attention')->where('from_user_id',$user_id)->where('user_id',$uid)->where('status',1)->count('id');
- if($attention_id){
- $is_attention = 1;
- }
- }
-
- $like_num = Db::name('store_like')->where('from_user_id',$user_id)->where('status',1)->count('id');
-
- $attention_num = Db::name('store_attention')->where('from_user_id',$user_id)->where('status',1)->count('id');
- $data = array(
- 'user_type' => $user_type,
- 'user_name' => $user_name,
- 'user_headimg' => $user_headimg,
- 'is_attention' => $is_attention,
- 'like_num' => $like_num,
- 'attention_num' => $attention_num
- );
- $this->success('获取成功',$data);
- }
-
- public function attention_news_list(){
- $user_id = input('user_id');
- $page = input('page',1);
- $pageSize = input('page_size',10);
- if(empty($user_id)){
- $this->error('参数错误');
- }
- $user_type = user_type($user_id);
- if($user_type == 1){
- $this->error('发布者身份有误');
- }
- $list = Db::name('store_goods')->field('id,title,image,create_at')->where('status',1)->where('is_deleted',0)->where('user_id',$user_id)->page($page,$pageSize)->order(['is_top'=>'desc','sort'=>'desc','id'=>'desc'])->select();
- if($list){
- foreach($list as &$value) {
-
- $value['comment_num'] = Db::name('store_comment')->where('forum_id',$value['id'])->where('type',1)->where('forum_type',1)->count('id');
- $value['image'] = image_path($value['image'])[0];
- $remain_time = time() - strtotime($value['create_at']);
- $value['duration'] = get_stay_time($remain_time);
- unset($value['create_at']);
- }
- }
- $this->success('获取成功',$list);
- }
- }
|