81 lines
1.6 KiB
PHP
81 lines
1.6 KiB
PHP
<?php
|
|
namespace App\Domains\User\Http\Controllers;
|
|
|
|
use App\Core\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Domains\User\Services\UserService;
|
|
|
|
class UserController extends Controller
|
|
{
|
|
protected $request;
|
|
protected $userService;
|
|
|
|
/**
|
|
* 构造函数,自动注入.
|
|
*/
|
|
public function __construct(Request $request, UserService $userService)
|
|
{
|
|
$this->request = $request;
|
|
$this->userService = $userService;
|
|
$this->account = app('dipper')->initAccount();
|
|
}
|
|
|
|
/**
|
|
* 列表.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$conditions = [];
|
|
$conditions['limit'] = $this->request->get('limit', 20);
|
|
|
|
$users = $this->userService->index($conditions);
|
|
|
|
return res($users, '用户列表', 201);
|
|
}
|
|
|
|
/**
|
|
* 创建.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$attributes = $this->request->all();
|
|
|
|
$user = $this->userService->store($attributes);
|
|
|
|
return res($user, '创建成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update($id)
|
|
{
|
|
$attributes = $this->request->all();
|
|
$attributes['id'] = $id;
|
|
|
|
$user = $this->userService->store($attributes);
|
|
|
|
return res($user, '修改成功');
|
|
}
|
|
|
|
/**
|
|
* 删除.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy()
|
|
{
|
|
$ids = $this->request->ids();
|
|
|
|
$this->userService->destroy($ids);
|
|
|
|
return res(true, '删除成功');
|
|
}
|
|
}
|