<?php

namespace App\Services\Views;


use App\Models\Comment;
use App\Models\Setting;

// 评论
class CommentService
{
    public function list($table = 'product', $id, $page = 1, $perPage = 10)
    {
        // 是否开启评论
        $config = Setting::where('lang', 'single')->lists('value', 'name');
        $isOpenComment = $config['open_comment'] ?? 1;

        if ($isOpenComment) {
            $query = Comment::with('member')->where('lang', config('setting.lang'))->where('is_display', 1)->where('model_id', $id)->where('model_type', $table);

            $data = $page == 1 ? $query->paginate($perPage) : $query->limit($perPage)->get();

            return $data;
        }
        return [];
    }
}
