| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | <?phpnamespace Act\Lib;use Dever;class Comment{    private function table($type) {        if ($type == 3) {            $table = 'act/live_comment';        } else {            $table = 'act/comment';        }        return $table;    }    # 获取评论列表    public function get($id, $type)    {        $where['type'] = $type;        $where['data_id'] = $id;        $table = $this->table($type);        $data = Dever::db($table)->getAll($where);        if ($data) {            foreach ($data as $k => $v) {                $user = Dever::load('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;        $table = $this->table($type);        $info = Dever::db($table)->one($where);        if (!$info) {            Dever::db($table)->insert($where);        }        # 更新评论数        $where = array();        $where['data_id'] = $id;        $where['type'] = $type;        $where['state'] = 1;        $total = Dever::db($table)->total($where);        $table = Dever::config('base')->type_table[$type];        Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));        return true;    }}
 |