123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\Distributor\Repositories;
- use App\Libraries\RpcClient;
- use App\Models\NullModel as Model;
- use Dcat\Admin\Form;
- use Dcat\Admin\Repositories\EloquentRepository;
- use Dcat\Admin\Show;
- use JsonRPC\Client;
- /*
- * RPC调用相册
- */
- class RpcAlbum extends EloquentRepository
- {
- /**
- * Model.
- *
- * @var string
- */
- protected $eloquentClass = Model::class;
- public $albumFolder = [];
- public function __construct($modelOrRelations = [])
- {
- $this->initModel($modelOrRelations);
- $distInfo = DistAdminDistributor::getInfo();
- //可查看的相册目录
- $albumFolder = empty($distInfo->album_folder) ? [] : json_decode($distInfo->album_folder);
- $this->albumFolder = $albumFolder;
- }
- /*
- * 执行RPC调用
- */
- public function execute($method, $params = [])
- {
- return RpcClient::albumExecute($method, $params);
- }
- /*
- * 通过IDS获取相册详情
- */
- public function getByids($ids)
- {
- return $this->execute('siteAlbumGetByIds', [
- 'ids' => $ids,
- ]);
- }
- /*
- * 获取相册列表
- */
- public function get(Grid\Model|\Dcat\Admin\Grid\Model $model)
- {
- $self = new self();
- // 获取当前页数
- $currentPage = $model->getCurrentPage();
- // 获取每页显示行数
- $perPage = $model->getPerPage();
- //排序
- $sort = $model->getSort();
- if (empty($sort) == true || $sort[0] == null) {
- $sort = [];
- }
- // 获取筛选参数
- $filterModel = $model->filter()->input('model', '');
- $folder_id = $model->filter()->input('folder_id', '');
- $filter = [
- 'model' => $filterModel,
- 'folder_id' => $folder_id,
- 'album_folder' => $self->albumFolder,//把查询结果限定在album_folder中
- ];
- $result = $this->execute('siteAlbumPaginate', [
- 'filter' => $filter,
- 'sort' => $sort,
- 'perPage'=>$perPage,
- 'page' => $currentPage,
- ]);
- $data = $result['data'] ?? [];
- return $model->makePaginator(
- $data['total'] ?? 0,
- $data['data'] ?? [] // 传入数据二维数组
- );
- }
- /*
- * 获取相册详情
- */
- public function detail(Show $show): array
- {
- // 获取数据主键值
- $id = $show->getKey();
- $result = $this->execute('siteAlbumGet', [
- 'id' => $id,
- ]);
- $data = $result['data'] ?? [];
- return $data;
- }
- }
|