* @version : HUOSDK 8.0 */ namespace huo\controller\comment; use huo\controller\common\Base; use huo\logic\comment\CommentLogic; use huolib\status\CommonStatus; class Comment extends Base { protected $comment_logic; public function __construct(CommentLogic $comment_logic = null) { if (null === $comment_logic) { $this->comment_logic = new CommentLogic(); } else { $this->comment_logic = $comment_logic; } } /** * 获取列表 * * @param array $param * @param string $page * * @return array */ public function getList($param = [], $page) { $_map['table_name'] = $param['type_name']; $_map['object_id'] = $param['object_id']; $_cnt = $this->comment_logic->getCnt($_map); if (empty($_cnt)) { $_data = []; } else { $_order = '-create_time'; $_data = $this->comment_logic->getList($_map, $page, $_order); } $_rdata = [ 'count' => $_cnt, 'list' => $_data, ]; $code = CommonStatus::NO_ERROR; return $this->huoSuccess($code, CommonStatus::getMsg($code), $_rdata); } /** * 添加评论 * * @param array $param * @param int $mem_id * * @return array */ public function addComment($param, $mem_id) { $param['mem_id'] = $mem_id; $_rs = $this->comment_logic->addComment($param); $code = CommonStatus::NO_ERROR; if (!$_rs) { $code = CommonStatus::INNER_ERROR; } return $this->huoSuccess($code, CommonStatus::getMsg($code)); } /** * 获取列表 * * @param int $mem_id 玩家ID * @param string $page * * @return array */ public function getMyGameCommentList($mem_id, $page) { $_map['table_name'] = 'game'; $_map['mem_id'] = $mem_id; $_cnt = $this->comment_logic->getCnt($_map); if (empty($_cnt)) { $_data = []; } else { $_order = '-create_time'; $_data = $this->comment_logic->getListAndGame($_map, $page, $_order); } $_rdata = [ 'count' => $_cnt, 'list' => $_data, ]; $code = CommonStatus::NO_ERROR; return $this->huoSuccess($code, CommonStatus::getMsg($code), $_rdata); } /** * 获取评论数量 * * @param int $mem_id 玩家ID * * @return array */ public function getCnt($mem_id) { $_map['table_name'] = 'game'; $_map['mem_id'] = $mem_id; $_cnt = $this->comment_logic->getCnt($_map); $_rdata = [ 'comment_cnt' => $_cnt, ]; $code = CommonStatus::NO_ERROR; return $this->huoSuccess($code, CommonStatus::getMsg($code), $_rdata); } }