123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace Act\Lib;
- use Dever;
- class Comment
- {
- # 获取评论列表
- public function get($id, $type)
- {
- $where['type'] = $type;
- $where['data_id'] = $id;
- $data = Dever::db('act/comment')->getAll($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $user = Dever::db('passport/api')->info($v['uid']);
- $data[$k]['username'] = $user['username'];
- $data[$k]['avatar'] = $user['avatar'];
- }
- }
- return $data;
- }
- # 发表评论
- public function submit($uid, $id, $type, $content)
- {
- $where['uid'] = $uid;
- $where['data_id'] = $id;
- $where['type'] = $type;
- $where['content'] = $content;
- $info = Dever::db('act/comment')->one($where);
- if (!$info) {
- Dever::db('act/comment')->insert($where);
- }
- # 更新评论数
- $where = array();
- $where['data_id'] = $id;
- $where['type'] = $type;
- $total = Dever::db('act/comment')->total($where);
- $table = Dever::config('base')->type_table[$type];
- Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
- return true;
- }
- }
|