1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Eddy <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace App\Repository\Admin; |
7
|
|
|
|
8
|
|
|
use App\Model\Admin\Comment; |
9
|
|
|
use App\Repository\Searchable; |
10
|
|
|
|
11
|
|
|
class CommentRepository |
12
|
|
|
{ |
13
|
|
|
use Searchable; |
14
|
|
|
|
15
|
|
|
public static function list($perPage, $condition = []) |
16
|
|
|
{ |
17
|
|
|
$data = Comment::query() |
18
|
|
|
->where(function ($query) use ($condition) { |
19
|
|
|
Searchable::buildQuery($query, $condition); |
20
|
|
|
}) |
21
|
|
|
->with('entity:id,name') |
22
|
|
|
->with('user:id,name') |
23
|
|
|
->orderBy('id', 'desc') |
24
|
|
|
->paginate($perPage); |
25
|
|
|
$data->transform(function ($item) { |
26
|
|
|
xssFilter($item); |
27
|
|
|
$item->editUrl = route('admin::comment.edit', ['id' => $item->id]); |
28
|
|
|
$item->deleteUrl = route('admin::comment.delete', ['id' => $item->id]); |
29
|
|
|
$item->entityName = !is_null($item->entity) ? $item->entity->name : '未知'; |
30
|
|
|
$item->userName = !is_null($item->user) ? $item->user->name : '未知'; |
31
|
|
|
$item->contentEditUrl = route('admin::content.edit', [$item->entity_id, $item->content_id]); |
32
|
|
|
$item->vistUrl = route('web::content', [$item->entity_id, $item->content_id]); |
33
|
|
|
$item->replyUrl = route('admin::comment.index', ['rid' => $item->id, 'entity_id' => $item->entity_id]); |
34
|
|
|
return $item; |
35
|
|
|
}); |
36
|
|
|
|
37
|
|
|
return [ |
38
|
|
|
'code' => 0, |
39
|
|
|
'msg' => '', |
40
|
|
|
'count' => $data->total(), |
41
|
|
|
'data' => $data->items(), |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function add($data) |
46
|
|
|
{ |
47
|
|
|
return Comment::query()->create($data); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function update($id, $data) |
51
|
|
|
{ |
52
|
|
|
return Comment::query()->where('id', $id)->update($data); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public static function find($id) |
56
|
|
|
{ |
57
|
|
|
return Comment::query()->find($id); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public static function delete($id) |
61
|
|
|
{ |
62
|
|
|
return Comment::destroy($id); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public static function hasChildren($id) |
66
|
|
|
{ |
67
|
|
|
return Comment::query()->where('rid', $id)->orWhere('pid', $id)->first(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|