107 lines
2.7 KiB
PHP
107 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\admin\controller\Erp;
|
|
|
|
use app\admin\BaseController;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Db;
|
|
use think\facade\Session;
|
|
use think\response\Json;
|
|
use think\db\exception\DbException;
|
|
use app\model\Erp\Organization;
|
|
use app\model\AdminUser;
|
|
|
|
class OrganizationController extends BaseController
|
|
{
|
|
/**
|
|
* 获取组织机构列表
|
|
*/
|
|
public function getOrganization()
|
|
{
|
|
$list = Organization::where('delete_time', null)->select()->toArray();
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '获取成功',
|
|
'data' => $list
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 获取组织机构详情
|
|
*/
|
|
public function getOrganizationDetail($id)
|
|
{
|
|
$detail = Organization::where('id', $id)->where('delete_time', null)->find()->toArray();
|
|
$detail['leader_name'] = AdminUser::where('id', $detail['leader_id'])->value('name');
|
|
$detail['parent_name'] = Organization::where('id', $detail['parent_id'])->value('org_name');
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '获取成功',
|
|
'data' => $detail
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 创建组织机构
|
|
*/
|
|
public function createOrganization()
|
|
{
|
|
$data = $this->request->post();
|
|
$organization = Organization::create($data);
|
|
if ($organization) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '创建成功',
|
|
'data' => $organization
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 500,
|
|
'msg' => '创建失败',
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 编辑组织机构
|
|
*/
|
|
public function editOrganization($id)
|
|
{
|
|
$data = $this->request->post();
|
|
$organization = Organization::where('id', $id)->update($data);
|
|
if ($organization) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '编辑成功',
|
|
'data' => $organization
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 500,
|
|
'msg' => '编辑失败',
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除组织机构
|
|
*/
|
|
public function deleteOrganization($id)
|
|
{
|
|
$organization = Organization::where('id', $id)->update(['delete_time' => date('Y-m-d H:i:s')]);
|
|
if ($organization) {
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '删除成功',
|
|
]);
|
|
} else {
|
|
return json([
|
|
'code' => 500,
|
|
'msg' => '删除失败',
|
|
]);
|
|
}
|
|
}
|
|
}
|