91 lines
2.0 KiB
PHP
91 lines
2.0 KiB
PHP
<?php
|
|
namespace App\Domains\Account\Http\Controllers;
|
|
|
|
use App\Core\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Domains\Account\Services\AccountService;
|
|
|
|
class AccountController extends Controller
|
|
{
|
|
protected $request;
|
|
protected $accountService;
|
|
|
|
/**
|
|
* 构造函数,自动注入.
|
|
*/
|
|
public function __construct(Request $request, AccountService $accountService)
|
|
{
|
|
$this->request = $request;
|
|
$this->accountService = $accountService;
|
|
}
|
|
|
|
/**
|
|
* 列表.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$conditions = [];
|
|
$conditions['limit'] = $this->request->get('limit', 20);
|
|
|
|
// if (!$this->request->user()->can('api.accounts.root')) {
|
|
// $conditions['parent_id'] = $this->request->user()->id;
|
|
// }
|
|
|
|
$conditions['role_id'] = $this->request->get('role_id');
|
|
|
|
$accounts = $this->accountService->index($conditions);
|
|
|
|
return res($accounts, '账号列表', 201);
|
|
}
|
|
|
|
|
|
/**
|
|
* 创建.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$attributes = $this->request->all();
|
|
|
|
// if (!$this->request->user()->can('api.accounts.root')) {
|
|
// $attributes['parent_id'] = $this->account->id;
|
|
// }
|
|
|
|
$account = $this->accountService->store($attributes);
|
|
|
|
return res($account, '创建成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update($id)
|
|
{
|
|
$attributes = $this->request->all();
|
|
$attributes['id'] = $id;
|
|
|
|
$account = $this->accountService->store($attributes);
|
|
|
|
return res($account, '修改成功');
|
|
}
|
|
|
|
/**
|
|
* 删除.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy()
|
|
{
|
|
$ids = $this->request->ids();
|
|
|
|
$this->accountService->destroy($ids);
|
|
|
|
return res(true, '删除成功');
|
|
}
|
|
}
|