更新功能

This commit is contained in:
2023-02-23 22:34:00 +08:00
parent 6885382c52
commit 4995c5b6be
18 changed files with 444 additions and 200 deletions

View File

@@ -8,17 +8,73 @@
// +----------------------------------------------------------------------
namespace App\Http\Controllers\Auth;
use Illuminate\Support\Facades\Auth;
use App\Services\Auth\UsersService;
use App\Services\Auth\DepartmentService;
use App\Http\Controllers\Base;
use App\Support\Tree;
use Illuminate\Support\Arr;
class Department extends Base{
/**
* @title 部门数据
*/
public function index(){
/**
* @title 部门数据
*/
public function index(DepartmentService $service){
$data = $service->getDepartmentList(request());
return $this->data;
}
$sortData = Arr::keyBy($data, 'partent_id');
$this->data['data'] = (new Tree())->listToTree($data->toArray(), 'id', 'parent_id', 'children');
return $this->data;
}
/**
* @title 添加部门
*
* @param DepartmentService $service
* @return void
*/
public function add(DepartmentService $service){
try {
$service->createDepartment(request());
$this->data['message'] = '添加成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 修改部门
*
* @param DepartmentService $service
* @return void
*/
public function edit(DepartmentService $service){
try {
$service->updateDepartment(request());
$this->data['message'] = '修改成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 删除部门
*
* @param DepartmentService $service
* @return void
*/
public function delete(DepartmentService $service){
try {
$service->deleteDepartment(request());
$this->data['message'] = '删除成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
}