瀏覽代碼

评论优化

qifengquan 1 年之前
父節點
當前提交
bdb0760a57
共有 1 個文件被更改,包括 27 次插入10 次删除
  1. 27 10
      application/api/controller/Index.php

+ 27 - 10
application/api/controller/Index.php

@@ -837,13 +837,13 @@ class Index extends Api
             }
         }else if(input('type') == 2){
             //子级评论
-            if(!input('uid') || !input('uid') || !input('articleid') || !input('content')){
+            if(!input('belong_id') || !input('articleid') || !input('content')){
                 $this->error('参数缺失');
             }else{
                 Db::name('store_article_class')->where('id',input('articleid'))->findOrFail();
                 Db::startTrans();
                 try{
-                    $comment = Db::name('store_article_comment')->insertGetId(['uid' => input('uid'),'zid' => $id, 'articleid' => input('articleid'), 'content' => input('content'),'create_time'=>date('Y-m-d H:i:s')]);
+                    $comment = Db::name('store_article_comment')->insertGetId(['belong_id' => input('belong_id'),'zid' => $id, 'articleid' => input('articleid'), 'content' => input('content'),'create_time'=>date('Y-m-d H:i:s')]);
                     Db::commit();
                     $this->success('评论成功',$comment);
                 } catch (Exception $e) {
@@ -863,17 +863,34 @@ class Index extends Api
         $articleid = input('id');
         if(!$articleid)$this->error('参数缺失');
         $where = [
-            'articleid' => $articleid,
-            'status' => 1,
-            'audit' => 1
+            'c.articleid' => $articleid,
+            'c.status' => 1,
+            'c.audit' => 1
         ];
         if(input('type') == 1){
-            $data = Db::name('store_article_comment')->where($where)->where('zid',0)->paginate($page_num,'',['page'=>$page]);;
+            $data = Db::name('store_article_comment')
+                ->alias('c')
+                ->join('store_member m','c.uid = m.id')
+                ->where($where)
+                ->where('c.zid',0)
+                ->field('c.*,m.id as userid,m.headimg,m.nickname')
+                ->paginate($page_num,'',['page'=>$page])
+                ->toArray();
+            foreach($data['data'] as &$v){
+                    $v['count'] = Db::name('store_article_comment')->alias('c')->where($where)->where('c.zid','<>','0')->where('belong_id',$v['id'])->count();
+                }
             $this->success('请求成功',$data);
-        }else if(input('type') == 2){
-            $uid = input('uid');
-            if(!$uid)$this->error('参数缺失');
-            $data = Db::name('store_article_comment')->where($where)->where('zid','<>','0')->where('uid',$uid)->paginate($page_num,'',['page'=>$page]);;
+        } else if(input('type') == 2){
+            $elong_id = input('belong_id');
+            if(!$elong_id)$this->error('参数缺失');
+            $data = Db::name('store_article_comment')
+                ->alias('c')
+                ->join('store_member m','c.zid = m.id')
+                ->where($where)
+                ->where('c.zid','<>','0')
+                ->where('c.belong_id',$elong_id)
+                ->field('c.*,m.id as userid,m.headimg,m.nickname')
+                ->paginate($page_num,'',['page'=>$page]);;
             $this->success('请求成功',$data);
         }
     }