123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /**
- * CommentLogic.php UTF-8
- *
- *
- * @date : 2017/11/24 16:20
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\comment;
- use huo\model\comment\CommentModel;
- use huo\model\common\CommonModel;
- class CommentLogic extends CommonModel {
- /**
- * 获取评论列表
- *
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getList($where = [], $page = '1,10', $order = '') {
- $_map = $where;
- $_order = $this->orderFilter($order);
- $_datas = CommentModel::where($_map)->page($page)->order($_order)->select();
- if (empty($_datas)) {
- return null;
- }
- $_list = [];
- foreach ($_datas as $_data) {
- $_comment = null;
- $_comment['id'] = $_data['id'];
- $_comment['parent_id'] = $_data['parent_id'];
- $_comment['mem_id'] = $_data['mem_id'];
- $_comment['icon'] = $_data['mem']['avatar'];
- $_comment['to_mem_id'] = $_data['to_mem_id'];
- $_comment['object_id'] = $_data['object_id'];
- $_comment['create_time'] = $_data['create_time'];
- $_comment['full_name'] = $_data['mem']['nickname'];
- $_comment['path'] = null;
- $_comment['url'] = '';
- $_comment['content'] = $_data['content'];
- $_list[] = $_comment;
- }
- return $_list;
- }
- /**
- * 获取数量
- *
- * @param array $where
- *
- * @return int|string
- */
- public function getCnt($where = []) {
- $_map = $where;
- $_cnt = CommentModel::where($_map)->count();
- return $_cnt;
- }
- /**
- * 添加评论
- *
- * @param array $data
- *
- * @return bool
- */
- public function addComment($data = []) {
- $_data['parent_id'] = $this->getVal($data, 'parent_id', 0);
- $_data['mem_id'] = $this->getVal($data, 'mem_id', 0);
- $_data['to_mem_id'] = $this->getVal($data, 'to_mem_id', 0);
- $_data['object_id'] = $this->getVal($data, 'object_id', 0);
- $_data['table_name'] = $this->getVal($data, 'table_name', 'game');
- $_data['content'] = $this->getVal($data, 'content');
- $_rs = CommentModel::setComment($_data);
- if ($_rs) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 获取评论列表
- *
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getListAndGame($where = [], $page = '1,10', $order = '') {
- $_map = $where;
- $_order = $this->orderFilter($order);
- $_datas = CommentModel::with('game')->where($_map)->page($page)->order($_order)->select();
- if (empty($_datas)) {
- return null;
- }
- $_list = [];
- foreach ($_datas as $_data) {
- $_comment = null;
- $_comment['comment_id'] = $_data['id'];
- $_comment['game_id'] = $_data['object_id'];
- $_comment['gamename'] = isset($_data['game']['name']) ? $_data['game']['name'] : '';
- $_comment['icon'] = isset($_data['game']['icon']) ? $_data['game']['icon'] : '';
- $_comment['create_time'] = $_data['create_time'];
- $_comment['content'] = $_data['content'];
- $_list[] = $_comment;
- }
- return $_list;
- }
- }
|