RpcAlbum.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Libraries\RpcClient;
  4. use App\Models\NullModel as Model;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Repositories\EloquentRepository;
  7. use Dcat\Admin\Show;
  8. use JsonRPC\Client;
  9. /*
  10. * RPC调用相册
  11. */
  12. class RpcAlbum extends EloquentRepository
  13. {
  14. /**
  15. * Model.
  16. *
  17. * @var string
  18. */
  19. protected $eloquentClass = Model::class;
  20. public function execute($method, $params = [])
  21. {
  22. return RpcClient::albumExecute($method, $params);
  23. }
  24. /*
  25. * 通过IDS获取相册详情
  26. */
  27. public function getByids($ids)
  28. {
  29. return $this->execute('siteAlbumGetByIds', [
  30. 'ids' => $ids,
  31. ]);
  32. }
  33. /*
  34. * 获取相册列表
  35. */
  36. public function get(Grid\Model|\Dcat\Admin\Grid\Model $model)
  37. {
  38. // 获取当前页数
  39. $currentPage = $model->getCurrentPage();
  40. // 获取每页显示行数
  41. $perPage = $model->getPerPage();
  42. // 获取筛选参数
  43. $filterModel = $model->filter()->input('model', '');
  44. $folder_id = $model->filter()->input('folder_id', '');
  45. $filter = [
  46. 'model' => $filterModel,
  47. 'folder_id' => $folder_id,
  48. ];
  49. $result = $this->execute('siteAlbumPaginate', [
  50. 'filter' => $filter,
  51. 'perPage'=>$perPage,
  52. 'page' => $currentPage,
  53. ]);
  54. $data = $result['data'] ?? [];
  55. return $model->makePaginator(
  56. $data['total'] ?? 0,
  57. $data['data'] ?? [] // 传入数据二维数组
  58. );
  59. }
  60. /*
  61. * 获取相册详情
  62. */
  63. public function detail(Show $show): array
  64. {
  65. // 获取数据主键值
  66. $id = $show->getKey();
  67. $result = $this->execute('siteAlbumGet', [
  68. 'id' => $id,
  69. ]);
  70. $data = $result['data'] ?? [];
  71. return $data;
  72. }
  73. }