增加erp组织架构
This commit is contained in:
parent
25e3923ad3
commit
c389fec971
105
app/admin/controller/Erp/OrganizationController.php
Normal file
105
app/admin/controller/Erp/OrganizationController.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?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');
|
||||
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' => '删除失败',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -31,6 +31,23 @@ class UserController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户用户
|
||||
* @return Json
|
||||
*/
|
||||
public function getTenantUsers(int $tenantId)
|
||||
{
|
||||
$users = AdminUser::where('delete_time', null)->where('tenant_id', $tenantId)->field('id, account, name, phone, birth, email, qq, sex, group_id, status, last_login_ip, login_count, create_time, update_time')->select()->toArray();
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'list' => $users,
|
||||
'total' => count($users)
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @return Json
|
||||
|
||||
11
app/admin/route/routes/erp.php
Normal file
11
app/admin/route/routes/erp.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
use think\facade\Route;
|
||||
|
||||
// 组织机构管理路由
|
||||
Route::group('erp', function() {
|
||||
Route::get('organization', 'app\admin\controller\Erp\OrganizationController/getOrganization');
|
||||
Route::get('getOrganizationDetail/:id', 'app\admin\controller\Erp\OrganizationController/getOrganizationDetail');
|
||||
Route::post('organization', 'app\admin\controller\Erp\OrganizationController/createOrganization');
|
||||
Route::post('organization/:id', 'app\admin\controller\Erp\OrganizationController/editOrganization');
|
||||
Route::delete('organization/:id', 'app\admin\controller\Erp\OrganizationController/deleteOrganization');
|
||||
});
|
||||
@ -3,6 +3,7 @@ use think\facade\Route;
|
||||
|
||||
// 用户路由
|
||||
Route::get('getAllUsers', 'app\\admin\\controller\\UserController@getAllUsers');
|
||||
Route::get('getTenantUsers/:tenantId', 'app\\admin\\controller\\UserController@getTenantUsers');
|
||||
Route::get('getUserInfo/:id', 'app\\admin\\controller\\UserController@getUserInfo');
|
||||
Route::post('addUser', 'app\\admin\\controller\\UserController@addUser');
|
||||
Route::post('editUser/:id', 'app\\admin\\controller\\UserController@editUser');
|
||||
|
||||
@ -80,6 +80,7 @@ class LoginController extends BaseController
|
||||
'id' => $user['id'],
|
||||
'account' => $user['account'],
|
||||
'name' => $user['name'],
|
||||
'tenant_id' => $user['tenant_id'],
|
||||
'group_id' => $user['group_id']
|
||||
];
|
||||
|
||||
|
||||
45
app/model/Erp/Organization.php
Normal file
45
app/model/Erp/Organization.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: Liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model\Erp;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* 组织机构模型
|
||||
*/
|
||||
class Organization extends Model
|
||||
{
|
||||
// 启用软删除
|
||||
use SoftDelete;
|
||||
|
||||
// 数据库表名
|
||||
protected $name = 'mete_apps_erp_organization';
|
||||
|
||||
// 字段类型转换
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'tenant_id' => 'integer',
|
||||
'org_name' => 'string',
|
||||
'org_code' => 'string',
|
||||
'parent_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'leader_id' => 'integer',
|
||||
'remark' => 'string',
|
||||
'status' => 'integer',
|
||||
'create_time' => 'datetime',
|
||||
'update_time' => 'datetime',
|
||||
'delete_time' => 'datetime',
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user