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.
92 lines
2.2 KiB
PHTML
92 lines
2.2 KiB
PHTML
5 years ago
|
<?php
|
||
|
/**
|
||
|
* Created by PhpStorm.
|
||
|
* User: xmy 280564871@qq.com
|
||
|
* Date: 2017/3/28
|
||
|
* Time: 17:51
|
||
|
*/
|
||
|
|
||
|
namespace Mobile\Model;
|
||
|
use Think\Model;
|
||
|
|
||
|
class CommentModel extends Model{
|
||
|
/**
|
||
|
* 构造函数
|
||
|
* @param string $name 模型名称
|
||
|
* @param string $tablePrefix 表前缀
|
||
|
* @param mixed $connection 数据库连接信息
|
||
|
*/
|
||
|
public function __construct($name = '', $tablePrefix = '', $connection = '') {
|
||
|
/* 设置默认的表前缀 */
|
||
|
$this->tablePrefix ='tab_';
|
||
|
/* 执行构造方法 */
|
||
|
parent::__construct($name, $tablePrefix, $connection);
|
||
|
}
|
||
|
|
||
|
protected $_validate = [
|
||
|
// ['comment','255','评论太长',self::MODEL_BOTH,'length']
|
||
|
['comment', '1,255', '评论为1至255个字符', self::VALUE_VALIDATE, 'length', self::MODEL_BOTH],
|
||
|
];
|
||
|
|
||
|
protected $_auto = [
|
||
|
['create_time', 'time', self::MODEL_INSERT],
|
||
|
['status', '0', self::MODEL_BOTH],
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* 添加评论
|
||
|
* @param $account
|
||
|
* @param $game_id
|
||
|
* @param $comment
|
||
|
* @return bool|mixed
|
||
|
* author: xmy 280564871@qq.com
|
||
|
*/
|
||
|
public function add_comment($account,$game_id,$comment){
|
||
|
$data['account'] = $account;
|
||
|
$data['game_id'] = $game_id;
|
||
|
$data['comment'] = $comment;
|
||
|
$data = $this->create($data);
|
||
|
if(empty($data)){
|
||
|
return false;
|
||
|
}
|
||
|
$result = $this->add($data);
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取评论
|
||
|
* @param $game_id
|
||
|
* @param int $p
|
||
|
* @return mixed
|
||
|
* author: xmy 280564871@qq.com
|
||
|
*/
|
||
|
public function getComment($map,$p=0){
|
||
|
$page = intval($p);
|
||
|
$page = $page ? $page : 1; //默认显示第一页数据
|
||
|
$row = 10;
|
||
|
$map['status'] = 1;
|
||
|
$data = $this->field("account,create_time,comment,game_id")->where($map)->order("create_time desc")->page($page,$row)->select();
|
||
|
foreach ($data as $key => $val){
|
||
|
$user = D("User")->getUserInfo($val['account']);
|
||
|
$data[$key]['nickname'] = $user['nickname'];
|
||
|
$data[$key]['head_img'] = $user['head_img'];
|
||
|
}
|
||
|
$result['data'] = $data;
|
||
|
$result['count'] = $this->where($map)->count();
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 评论总数
|
||
|
* @param array $map 条数数组
|
||
|
* @return integer 总数
|
||
|
* @author 鹿文学
|
||
|
*/
|
||
|
public function total($map=array()) {
|
||
|
|
||
|
return $this->where($map)->count();
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|