Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CommentModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'idUser' => $this->idUser, 'idProduct' => $this->idProduct, 'date' => $this->date, 'mark' => $this->mark]);
     $query->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public static function getUserCommentToProduct($productId, $userId)
 {
     $comments = \Yii::$app->cache->get('comments_product_' . $productId);
     if ($comments === false) {
         $comments = CommentModel::find()->where(['idProduct' => $productId])->all();
         \Yii::$app->cache->add('comments_product_' . $productId, $comments);
     }
     foreach ($comments as $comment) {
         if ($comment->idUser == $userId) {
             return $comment;
         }
     }
     return null;
 }
Exemplo n.º 3
0
 public function actionCheckcomment()
 {
     $request = Yii::$app->request;
     // if(!$request->isAjax) return false;
     $id = intval($request->get('buff_id'));
     $filed_arr = ['id', 'buff_id', 'user_id', 'content', 'save_time' => 'time', 'nick_name' => 'username'];
     $data_thumb = CommentModel::find()->joinWith('business_customer')->where(['buff_id' => $id])->all();
     // var_dump($data_thumb);
     foreach ($data_thumb as $k => $v) {
         $data_comment[$k] = $this->_checkAjaxInfo($v, $filed_arr);
         $data_id[$k] = $data_comment[$k]['id'];
     }
     //获取评论相关的回复信息
     $data_reply = array();
     $data_reply_thumb = ReplyModel::find()->joinWith('business_customer')->where(['comment_id' => $data_id])->all();
     if (!$data_reply_thumb) {
         return json_encode('暂无评论');
     }
     $filed_arr = ['id', 'comment_id' => 'com_id', 'user_id', 'content', 'p_user_id', 'p_reply_id', 'save_time', 'nick_name' => 'username'];
     foreach ($data_reply_thumb as $v) {
         $data_reply[] = $this->_checkAjaxInfo($v, $filed_arr);
     }
     $comment_info = $this->_CheckCommentInfo($data_comment, $data_reply);
 }