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.
68 lines
1.9 KiB
68 lines
1.9 KiB
<?php |
|
|
|
namespace Plugins\Notebook\Service\Admin; |
|
|
|
|
|
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 Plugins\Notebook\Model\Notebook; |
|
use App\Util\EasySearch; |
|
|
|
/** |
|
* Class NotebookService |
|
*/ |
|
class NotebookService extends AbstractAdminService |
|
{ |
|
use StoreServiceTrait, UpdateServiceTrait, DestroyServiceTrait, SwitchServiceTrait; |
|
|
|
public function __construct() |
|
{ |
|
$this->model = new Notebook(); |
|
} |
|
|
|
/** |
|
* @return array |
|
*/ |
|
public function lists(): array |
|
{ |
|
$query = $this->model |
|
->leftJoin('administrators as a1', 'a1.id', '=', 'notebook.administrators_id') |
|
->leftJoin('administrators as a2', 'a2.id', '=', 'notebook.latest_administrators_id') |
|
->select(["notebook.id","notebook.title","notebook.content","a1.name as create_name","a2.name as latest_name","notebook.create_time","notebook.update_time"]); |
|
|
|
return EasySearch::create($query)->getData(); |
|
} |
|
|
|
public function beforeStore(&$data): void |
|
{ |
|
$data['administrators_id'] = AdminAuth::getInfo()->id; |
|
} |
|
|
|
public function beforeWrite(&$data, $id = null): void |
|
{ |
|
$data['latest_administrators_id'] = AdminAuth::getInfo()->id; |
|
} |
|
|
|
/** |
|
* @param int $id |
|
* @param string $update_time |
|
* @return array|null |
|
*/ |
|
public function getLatest(int $id, string $update_time): ?array |
|
{ |
|
$notebook = $this->model->find($id); |
|
|
|
if (strtotime($update_time) < strtotime($notebook->update_time)) { |
|
$data = $notebook->toArray(); |
|
$data['latest_name'] = $notebook->latestAdmin->name; |
|
}else{ |
|
$data = null; |
|
} |
|
|
|
return $data; |
|
} |
|
}
|
|
|