You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.0 KiB
PHP

<?php
/**
* 评论控制器
* Created by PhpStorm.
* User: xmy 280564871@qq.com
* Date: 2017/3/28
* Time: 16:53
*/
namespace App\Controller;
class CommentController extends BaseController{
/**
* 添加评论
* @param $comment 评论
* @param $game_id
* @param $token
* author: xmy 280564871@qq.com
*/
public function add_comment($comment,$game_id,$token){
$this->auth($token);
if(mb_strlen($comment,'UTF8')>255){
$this->set_message(1036,"评论最多可以输入255个字符");
}
$model = D("Comment");
$result = $model->add_comment(USER_ACCOUNT,$game_id,$comment);
if($result !== false){
$this->set_message(200,"添加成功");
}else{
$this->set_message(1036,$model->getError());
}
}
/**
* 获取评论
* @param $game_id
* @param int $p
* author: xmy 280564871@qq.com
*/
public function get_comment($game_id,$p=1){
$model = D("Comment");
$map['game_id'] = $game_id;
$data = $model->getComment($map,$p);
if(empty($data)){
$this->set_message(1037,"暂无评论");
}else{
$this->set_message(200,"成功",$data);
}
}
/**
* 我的评论
* @param $token
* @param int $p
* author: xmy 280564871@qq.com
*/
public function my_comment($token,$p=1,$game_name=""){
$this->auth($token);
if(!empty($game_name)){
$game = D("Game")->where(['game_name'=>['like',"%".$game_name."%"]])->select();
$map['game_id'] = ['in',array_column($game,"id")];
}
$model = D("Comment");
$map['account'] = USER_ACCOUNT;
$data = $model->getComment($map,$p);
if(empty($data['data'])){
$this->set_message(1037,"暂无评论");
}else{
$this->set_message(200,"成功",$data);
}
}
/**
* 我的评论
* @param $token
* @param int $p
* author: xmy 280564871@qq.com
*/
public function my_comment_all($token,$p=1,$game_name=""){
$this->auth($token);
$model = D("Comment");
$map['account'] = USER_ACCOUNT;
$data = $model->getCommentall($map,$p);
if(empty($data['data'])){
$this->set_message(1037,"暂无评论");
}else{
$this->set_message(200,"成功",$data);
}
}
}