chenlong 2 years ago
parent
commit
6676756ec6
  1. 16
      Controller/Admin/NotebookController.php
  2. 52
      Controller/Admin/NotebookUserController.php
  3. 25
      Service/Admin/NotebookService.php
  4. 36
      Service/Admin/NotebookUserService.php
  5. 10
      View/Admin/Notebook/lists.blade.php

16
Controller/Admin/NotebookController.php

@ -124,4 +124,20 @@ class NotebookController extends AbstractController
return Response::json()->success($data);
}
/**
* 添加协作用户
*
* @return ResponseInterface
*/
#[PostMapping(path: 'add-user')]
public function addUser(): ResponseInterface
{
NotebookService::aop()->addUser(
(int)$this->request->post('notebook_id'),
(array)$this->request->post('user_ids')
);
return Response::json()->success();
}
}

52
Controller/Admin/NotebookUserController.php

@ -0,0 +1,52 @@
<?php
namespace Plugins\Notebook\Controller\Admin;
use App\Exception\ApiMessageException;
use App\Controller\AbstractController;
use Plugins\Notebook\Service\Admin\NotebookUserService;
use App\Middleware\Admin\AuthenticateMiddleware;
use App\Middleware\Admin\PermissionsMiddleware;
use App\Util\Response;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\Validation\Annotation\Scene;
use Psr\Http\Message\ResponseInterface;
/**
* 笔记协作人员控制器
*/
#[Controller(prefix: 'admin/plugins/notebook_user')]
#[Middlewares([AuthenticateMiddleware::class, PermissionsMiddleware::class])]
class NotebookUserController extends AbstractController
{
/**
* 列表数据
*
* @return ResponseInterface
*/
#[GetMapping(path: 'lists-data')]
public function listsData(): ResponseInterface
{
return Response::json()->success(NotebookUserService::aop()->lists());
}
/**
* 更新数据
*
* @return ResponseInterface
* @throws ApiMessageException
*/
#[Scene('update')]
#[PostMapping(path: 'update')]
public function update(): ResponseInterface
{
NotebookUserService::aop()->update($this->request->post());
return Response::json()->success();
}
}

25
Service/Admin/NotebookService.php

@ -12,6 +12,7 @@ use App\Service\Admin\Traits\SwitchServiceTrait;
use App\Util\AdminAuth;
use Plugins\Notebook\Model\Notebook;
use App\Util\EasySearch;
use Plugins\Notebook\Model\NotebookUser;
/**
* Class NotebookService
@ -74,4 +75,28 @@ class NotebookService extends AbstractAdminService
return $data;
}
/**
* @param int $notebook_id
* @param array $userIds
*
* @return void
* @throws ApiMessageException
*/
public function addUser(int $notebook_id, array $userIds): void
{
$data = [];
foreach ($userIds as $user_id) {
$data[] = [
"notebook_id" => $notebook_id,
"administrators_id" => $user_id,
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
];
}
if (!NotebookUser::insert($data)){
throw new ApiMessageException('添加失败');
}
}
}

36
Service/Admin/NotebookUserService.php

@ -0,0 +1,36 @@
<?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 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->select(["notebook_user.id","notebook_user.notebook_id","notebook_user.administrators_id","notebook_user.mode","notebook_user.status","notebook_user.create_time"]);
return EasySearch::create($query)->getData();
}
}

10
View/Admin/Notebook/lists.blade.php

@ -285,6 +285,7 @@
VueInit.methods.addAllowUser = function () {
if (this.waitAddAllowUser.length > 0) {
let isPure = true;
this.waitAddAllowUser.map(v =>{
if (!this.allowUserData.includes(v)) {
this.allowUserData.push(v);
@ -298,6 +299,15 @@
}
}
};
VueInit.methods.addAllowUserRequest = function (waitAddAllowUser){
axios({
url:'',
method:'post',
data:waitAddAllowUser
})
}
VueInit.methods.delAllowUser = function (index) {
this.allowUserData.splice(index, 1);
};

Loading…
Cancel
Save