PHP後台評論的實現

來源:互聯網
上載者:User
這篇文章主要介紹了關於PHP後台評論的實現,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

/**    * 添加評論    * content 評論內容    * addtime 評論時間    * uid  評論作品    */   public  function padd(){       $param=input('param.');       $param['pid']=session('tid');       if(empty($param['uid'])){           return json(['code'=>2,'message'=>'uid不可為空']);       }$data=db('comments')->insertGetId(['uid'=>$param['uid'],'content'=>$param['content'],'addtime'=>$param['addtime'],'pid'=>$param['pid']]);       if($data){           return json(['code'=>1,'message'=>'評論成功']);       }else{           return json(['code'=>2,'message'=>'評論失敗']);       }   }/**    * 評論展示    * uid   comments表    * page  頁數    * num   條數    */   public function comment(){       $param=input('param.');       $param['pid']=session('tid');//使用者id       if(empty($param['page'])){           $param['page']=1;       }if(empty($param['num'])){           $param['num']=5;       }       if(empty($param['uid'])){           return json(['code'=>2,'message'=>'uid不可為空']);       }$data=db('comments')->where('uid',$param['uid'])->page($param['page'],$param['num'])->select();$commentslike=db('commentslike');       $people=db('people');       foreach ($data as $k=>$value) {           //查看評論點贊表的狀態           $state=$commentslike->where(['pid'=>$param['pid'],'uid'=>$param['uid'],'cid'=>$value['data']])->value('state');           if(empty($state)){               $state = '還未點贊';           }           $data[$k]['state']=$state;//擷取評論人的手機號           $people=$people->where('id',$value['pid'])->value('tel');           $data[$k]['tel']=$people;           //把二級評論添加到數組資料中           if($value['rpid'] !== 0){               // $r_pid = $commentslike->where(['id'=>$value['rpid']])->value('pid');               $r_tel = $people->where('id',$value['rpid'])->value('tel');               $data[$k]['r_tel'] = $r_tel;           }else{               $data[$k]['r_tel'] = '';           }}       return json(['code'=>1,'data'=>$data]);   }/**    * 評論點贊    * uid  作品id    */   public function commentslike(){      $param=input('param.');      $param['pid']=session::get('tid');if(empty($param['uid'])){           return json(['code'=>2,'message'=>'uid不可為空']);       }       //判斷該作品有沒有評論      $comments=db('comments')->where('uid',$param['uid'])->select();      if(!empty($comments)){           //判斷他有沒有點贊           $data=db('commentslike')->where(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id']])->find();           if(empty($data)){               $like=db('commentslike')->insertGetId(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id'],$param['state']=>'點贊']);               if($like){                   return json(['code'=>1,'message'=>'點贊成功']);               }else{                   return json(['code'=>1,'message'=>'點贊失敗']);               }           }else{               if($data['state']=='取消點贊'){                   $like=db('commentslike')->where(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id']])->update([$param['state']=>'點贊']);               }elseif($data['state']=='點贊'){                   $like=db('commentslike')->where(['uid'=>$param['uid'],'pid'=>$param['pid'],'cid'=>$comments['id']])->update([$param['state']=>'取消點贊']);               }           }}else{           return json(['code'=>2,'message'=>'此作品還未評論']);      }   }/**    * 回複評論    * uid 作品id    * content  回複內容    * cid   這條評論的id    * uid 作品id  pid 評論人id      */   public function reply(){       $param['pid'] = session('tid');       $param = input('param.');       //被評論的id     $param['cid']       $data = db('comments')->where(['id'=>$param['rid']])->find();       if($data['rid'] !== 0){           $param['rid'] = $data['rid'];//被回複人的pid.       }       $param['rid'] = $data['id'];//被回複人的pid.$param['rpid'] = $data['pid'];//評論內容  $param['content']        //作品id  $param['uid']       $param['addtime'] = date('Y-m-d H:i:s');       $id = db('comments')->insertGetId(['uid'=>$param['uid'],'content'=>$param['content'],'addtime'=>$param['addtime'],'pid'=>$param['pid'],'rid'=>$param['rid']]);       if($id){           return json(['code'=>1,'messgae'=>'回複成功']);       }else{           return json(['code'=>2,'message'=>'回複失敗']);       }   }   /**    * 查看二級評論    * uid 作品id    * rid   這條評論的id    */   public function GetRCommtens($value='')   {       $data = db('comments')->where(['rid'=>$param['rid']])->select();   }

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.