Compare commits
2 Commits
050d1adc0b
...
99fc99f8ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 99fc99f8ad | |||
| 21480f43b1 |
@ -187,4 +187,15 @@ abstract class BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的 tenant_id
|
||||
*
|
||||
* @return int 租户ID
|
||||
*/
|
||||
protected function getTenantId(): int
|
||||
{
|
||||
$userInfo = $this->getAdminUserInfo();
|
||||
return isset($userInfo['tenant_id']) ? intval($userInfo['tenant_id']) : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
144
app/admin/controller/Erp/EmployeeController.php
Normal file
144
app/admin/controller/Erp/EmployeeController.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?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\Employee;
|
||||
use app\model\AdminUser;
|
||||
|
||||
class EmployeeController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取员工列表
|
||||
*/
|
||||
public function getEmployee()
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$list = Employee::where('delete_time', null)
|
||||
->where('tenant_id', $tenantId)
|
||||
->select()
|
||||
->toArray();
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $list
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取员工详情
|
||||
*/
|
||||
public function getEmployeeDetail($id)
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$detail = Employee::where('id', $id)
|
||||
->where('delete_time', null)
|
||||
->where('tenant_id', $tenantId)
|
||||
->find()
|
||||
->toArray();
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $detail
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建员工
|
||||
*/
|
||||
public function createEmployee()
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$data = $this->request->post();
|
||||
$data['tenant_id'] = $tenantId;
|
||||
|
||||
$employee = Employee::create($data);
|
||||
if ($employee) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '创建成功',
|
||||
'data' => $employee
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '创建失败',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑员工
|
||||
*/
|
||||
public function editEmployee($id)
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$data = $this->request->post();
|
||||
unset($data['tenant_id']); // 不允许修改租户ID
|
||||
|
||||
$employee = Employee::where('id', $id)
|
||||
->where('tenant_id', $tenantId)
|
||||
->update($data);
|
||||
if ($employee !== false) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '编辑成功',
|
||||
'data' => $employee
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '编辑失败',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除员工
|
||||
*/
|
||||
public function deleteEmployee($id)
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$employee = Employee::where('id', $id)
|
||||
->where('tenant_id', $tenantId)
|
||||
->update(['delete_time' => date('Y-m-d H:i:s')]);
|
||||
if ($employee) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '删除成功',
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => '删除失败',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,15 @@ class OrganizationController extends BaseController
|
||||
*/
|
||||
public function getOrganization()
|
||||
{
|
||||
$list = Organization::where('delete_time', null)->select()->toArray();
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$list = Organization::where('delete_time', null)
|
||||
->where('tenant_id', $tenantId)
|
||||
->select()
|
||||
->toArray();
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
@ -33,7 +41,16 @@ class OrganizationController extends BaseController
|
||||
*/
|
||||
public function getOrganizationDetail($id)
|
||||
{
|
||||
$detail = Organization::where('id', $id)->where('delete_time', null)->find()->toArray();
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$detail = Organization::where('id', $id)
|
||||
->where('delete_time', null)
|
||||
->where('tenant_id', $tenantId)
|
||||
->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([
|
||||
@ -48,7 +65,14 @@ class OrganizationController extends BaseController
|
||||
*/
|
||||
public function createOrganization()
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$data = $this->request->post();
|
||||
$data['tenant_id'] = $tenantId;
|
||||
|
||||
$organization = Organization::create($data);
|
||||
if ($organization) {
|
||||
return json([
|
||||
@ -69,9 +93,18 @@ class OrganizationController extends BaseController
|
||||
*/
|
||||
public function editOrganization($id)
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$data = $this->request->post();
|
||||
$organization = Organization::where('id', $id)->update($data);
|
||||
if ($organization) {
|
||||
unset($data['tenant_id']); // 不允许修改租户ID
|
||||
|
||||
$organization = Organization::where('id', $id)
|
||||
->where('tenant_id', $tenantId)
|
||||
->update($data);
|
||||
if ($organization !== false) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '编辑成功',
|
||||
@ -90,7 +123,14 @@ class OrganizationController extends BaseController
|
||||
*/
|
||||
public function deleteOrganization($id)
|
||||
{
|
||||
$organization = Organization::where('id', $id)->update(['delete_time' => date('Y-m-d H:i:s')]);
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$organization = Organization::where('id', $id)
|
||||
->where('tenant_id', $tenantId)
|
||||
->update(['delete_time' => date('Y-m-d H:i:s')]);
|
||||
if ($organization) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
@ -103,4 +143,50 @@ class OrganizationController extends BaseController
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业单位
|
||||
*/
|
||||
public function getCompanys()
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$where = [['delete_time', '=', null], ['is_company', '=', 1], ['tenant_id', '=', $tenantId]];
|
||||
|
||||
$list = Organization::where($where)->select()->toArray();
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $list
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门
|
||||
*/
|
||||
public function getDepartments()
|
||||
{
|
||||
$tenantId = $this->getTenantId();
|
||||
if (!$tenantId) {
|
||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
||||
}
|
||||
|
||||
$parentId = input('parent_id/d', 0);
|
||||
|
||||
$where = [['delete_time', '=', null], ['is_company', '=', 0], ['tenant_id', '=', $tenantId]];
|
||||
|
||||
if ($parentId > 0) {
|
||||
$where[] = ['parent_id', '=', $parentId];
|
||||
}
|
||||
|
||||
$list = Organization::where($where)->select()->toArray();
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $list
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,4 +8,15 @@ Route::group('erp', function() {
|
||||
Route::post('createOrganization', 'app\admin\controller\Erp\OrganizationController/createOrganization');
|
||||
Route::post('editOrganization/:id', 'app\admin\controller\Erp\OrganizationController/editOrganization');
|
||||
Route::delete('deleteOrganization/:id', 'app\admin\controller\Erp\OrganizationController/deleteOrganization');
|
||||
Route::get('getCompanys', 'app\admin\controller\Erp\OrganizationController/getCompanys');
|
||||
Route::get('getDepartments', 'app\admin\controller\Erp\OrganizationController/getDepartments');
|
||||
|
||||
});
|
||||
// 员工管理路由
|
||||
Route::group('erp', function() {
|
||||
Route::get('getEmployee', 'app\admin\controller\Erp\EmployeeController/getEmployee');
|
||||
Route::get('getEmployeeDetail/:id', 'app\admin\controller\Erp\EmployeeController/getEmployeeDetail');
|
||||
Route::post('createEmployee', 'app\admin\controller\Erp\EmployeeController/createEmployee');
|
||||
Route::post('editEmployee/:id', 'app\admin\controller\Erp\EmployeeController/editEmployee');
|
||||
Route::delete('deleteEmployee/:id', 'app\admin\controller\Erp\EmployeeController/deleteEmployee');
|
||||
});
|
||||
51
app/model/Erp/Employee.php
Normal file
51
app/model/Erp/Employee.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?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 Employee extends Model
|
||||
{
|
||||
// 启用软删除
|
||||
use SoftDelete;
|
||||
|
||||
// 数据库表名
|
||||
protected $name = 'mete_apps_erp_employee';
|
||||
|
||||
// 字段类型转换
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'account' => 'string',
|
||||
'password' => 'string',
|
||||
'name' => 'string',
|
||||
'gender' => 'integer',
|
||||
'birthday' => 'date',
|
||||
'affiliate_unit' => 'string',
|
||||
'department' => 'string',
|
||||
'position' => 'string',
|
||||
'nation' => 'string',
|
||||
'phone' => 'string',
|
||||
'wechat' => 'string',
|
||||
'email' => 'string',
|
||||
'home_address' => 'string',
|
||||
'account_status' => 'integer',
|
||||
'create_time' => 'datetime',
|
||||
'update_time' => 'datetime',
|
||||
'delete_time' => 'datetime',
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
@ -35,6 +35,7 @@ class Organization extends Model
|
||||
'sort' => 'integer',
|
||||
'leader_id' => 'integer',
|
||||
'remark' => 'string',
|
||||
'is_company' => 'integer',
|
||||
'status' => 'integer',
|
||||
'create_time' => 'datetime',
|
||||
'update_time' => 'datetime',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user