Notebook
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
2.3 KiB

<?php
namespace Plugins\Notebook\Service\Admin;
use App\Exception\ApiMessageException;
use App\Service\Admin\AbstractAdminService;
use App\Service\Admin\Traits\DestroyServiceTrait;
use App\Service\Admin\Traits\StoreServiceTrait;
use App\Service\Admin\Traits\UpdateServiceTrait;
use App\Service\Admin\Traits\SwitchServiceTrait;
use App\Util\AdminAuth;
use App\Util\Hy;
use Plugins\Notebook\Model\Notebook;
use Plugins\Notebook\Model\NotebookUser;
use App\Util\EasySearch;
/**
* Class NotebookUserService
*/
class NotebookUserService extends AbstractAdminService
{
use StoreServiceTrait, UpdateServiceTrait, DestroyServiceTrait, SwitchServiceTrait;
public function __construct()
{
$this->model = new NotebookUser();
}
/**
* @return array
*/
public function lists(): array
{
$query = $this->model->join('administrators', 'administrators.id', '=', "notebook_user.administrators_id")
->select([
"notebook_user.id","notebook_user.notebook_id","notebook_user.administrators_id","notebook_user.mode","notebook_user.status","notebook_user.create_time","administrators.name as user"
]);
if (Hy::request()->query('notebook_id')) {
$query->where("notebook_user.notebook_id", Hy::request()->query('notebook_id'));
}
return EasySearch::create($query)->totalCancellations()->getData()['data']->toArray();
}
/**
* @param $data
* @param $id
*
* @return void
* @throws ApiMessageException
*/
public function beforeUpdate(&$data, $id): void
{
if ($this->model->notebook->administrators_id != AdminAuth::getInfo()->id) {
throw new ApiMessageException('对不起,未找到该操作');
}
}
/**
* @param array $ids
*
* @return void
* @throws ApiMessageException
*/
public function beforeDestroy(array $ids): void
{
$data = NotebookUser::whereIn('id', $ids)->pluck('notebook_id');
$notAuth = Notebook::whereIn('id', $data->toArray())
->where('administrators_id', '<>', AdminAuth::getInfo()->id)
->value('id');
if ($notAuth) {
throw new ApiMessageException('对不起,未找到该操作');
}
}
}