RpcAlbum.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Distributor\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 $albumFolder = [];
  21. public function __construct($modelOrRelations = [])
  22. {
  23. $this->initModel($modelOrRelations);
  24. $distInfo = DistAdminDistributor::getInfo();
  25. //可查看的相册目录
  26. $albumFolder = empty($distInfo->album_folder) ? [] : json_decode($distInfo->album_folder);
  27. $this->albumFolder = $albumFolder;
  28. }
  29. /*
  30. * 执行RPC调用
  31. */
  32. public function execute($method, $params = [])
  33. {
  34. return RpcClient::albumExecute($method, $params);
  35. }
  36. /*
  37. * 通过IDS获取相册详情
  38. */
  39. public function getByids($ids)
  40. {
  41. return $this->execute('siteAlbumGetByIds', [
  42. 'ids' => $ids,
  43. ]);
  44. }
  45. /*
  46. * 获取相册列表
  47. */
  48. public function get(Grid\Model|\Dcat\Admin\Grid\Model $model)
  49. {
  50. $self = new self();
  51. // 获取当前页数
  52. $currentPage = $model->getCurrentPage();
  53. // 获取每页显示行数
  54. $perPage = $model->getPerPage();
  55. //排序
  56. $sort = $model->getSort();
  57. if (empty($sort) == true || $sort[0] == null) {
  58. $sort = [];
  59. }
  60. // 获取筛选参数
  61. $filterModel = $model->filter()->input('model', '');
  62. $folder_id = $model->filter()->input('folder_id', '');
  63. $filter = [
  64. 'model' => $filterModel,
  65. 'folder_id' => $folder_id,
  66. 'album_folder' => $self->albumFolder,//把查询结果限定在album_folder中
  67. ];
  68. $result = $this->execute('siteAlbumPaginate', [
  69. 'filter' => $filter,
  70. 'sort' => $sort,
  71. 'perPage'=>$perPage,
  72. 'page' => $currentPage,
  73. ]);
  74. $data = $result['data'] ?? [];
  75. return $model->makePaginator(
  76. $data['total'] ?? 0,
  77. $data['data'] ?? [] // 传入数据二维数组
  78. );
  79. }
  80. /*
  81. * 获取相册详情
  82. */
  83. public function detail(Show $show): array
  84. {
  85. // 获取数据主键值
  86. $id = $show->getKey();
  87. $result = $this->execute('siteAlbumGet', [
  88. 'id' => $id,
  89. ]);
  90. $data = $result['data'] ?? [];
  91. return $data;
  92. }
  93. }