Compare commits
No commits in common. "99fc99f8ad589af9d2a70e8d716a117b3f3ade09" and "050d1adc0bea7e6430f5e0d4b20053d090028e8d" have entirely different histories.
99fc99f8ad
...
050d1adc0b
@ -187,15 +187,4 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,144 +0,0 @@
|
|||||||
<?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,15 +20,7 @@ class OrganizationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function getOrganization()
|
public function getOrganization()
|
||||||
{
|
{
|
||||||
$tenantId = $this->getTenantId();
|
$list = Organization::where('delete_time', null)->select()->toArray();
|
||||||
if (!$tenantId) {
|
|
||||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$list = Organization::where('delete_time', null)
|
|
||||||
->where('tenant_id', $tenantId)
|
|
||||||
->select()
|
|
||||||
->toArray();
|
|
||||||
return json([
|
return json([
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'msg' => '获取成功',
|
'msg' => '获取成功',
|
||||||
@ -41,16 +33,7 @@ class OrganizationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function getOrganizationDetail($id)
|
public function getOrganizationDetail($id)
|
||||||
{
|
{
|
||||||
$tenantId = $this->getTenantId();
|
$detail = Organization::where('id', $id)->where('delete_time', null)->find()->toArray();
|
||||||
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['leader_name'] = AdminUser::where('id', $detail['leader_id'])->value('name');
|
||||||
$detail['parent_name'] = Organization::where('id', $detail['parent_id'])->value('org_name');
|
$detail['parent_name'] = Organization::where('id', $detail['parent_id'])->value('org_name');
|
||||||
return json([
|
return json([
|
||||||
@ -65,14 +48,7 @@ class OrganizationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function createOrganization()
|
public function createOrganization()
|
||||||
{
|
{
|
||||||
$tenantId = $this->getTenantId();
|
|
||||||
if (!$tenantId) {
|
|
||||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->request->post();
|
$data = $this->request->post();
|
||||||
$data['tenant_id'] = $tenantId;
|
|
||||||
|
|
||||||
$organization = Organization::create($data);
|
$organization = Organization::create($data);
|
||||||
if ($organization) {
|
if ($organization) {
|
||||||
return json([
|
return json([
|
||||||
@ -93,18 +69,9 @@ class OrganizationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function editOrganization($id)
|
public function editOrganization($id)
|
||||||
{
|
{
|
||||||
$tenantId = $this->getTenantId();
|
|
||||||
if (!$tenantId) {
|
|
||||||
return json(['code' => 403, 'msg' => '无法获取租户信息']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->request->post();
|
$data = $this->request->post();
|
||||||
unset($data['tenant_id']); // 不允许修改租户ID
|
$organization = Organization::where('id', $id)->update($data);
|
||||||
|
if ($organization) {
|
||||||
$organization = Organization::where('id', $id)
|
|
||||||
->where('tenant_id', $tenantId)
|
|
||||||
->update($data);
|
|
||||||
if ($organization !== false) {
|
|
||||||
return json([
|
return json([
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'msg' => '编辑成功',
|
'msg' => '编辑成功',
|
||||||
@ -123,14 +90,7 @@ class OrganizationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function deleteOrganization($id)
|
public function deleteOrganization($id)
|
||||||
{
|
{
|
||||||
$tenantId = $this->getTenantId();
|
$organization = Organization::where('id', $id)->update(['delete_time' => date('Y-m-d H:i:s')]);
|
||||||
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) {
|
if ($organization) {
|
||||||
return json([
|
return json([
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
@ -143,50 +103,4 @@ 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,15 +8,4 @@ Route::group('erp', function() {
|
|||||||
Route::post('createOrganization', 'app\admin\controller\Erp\OrganizationController/createOrganization');
|
Route::post('createOrganization', 'app\admin\controller\Erp\OrganizationController/createOrganization');
|
||||||
Route::post('editOrganization/:id', 'app\admin\controller\Erp\OrganizationController/editOrganization');
|
Route::post('editOrganization/:id', 'app\admin\controller\Erp\OrganizationController/editOrganization');
|
||||||
Route::delete('deleteOrganization/:id', 'app\admin\controller\Erp\OrganizationController/deleteOrganization');
|
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');
|
|
||||||
});
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
<?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,7 +35,6 @@ class Organization extends Model
|
|||||||
'sort' => 'integer',
|
'sort' => 'integer',
|
||||||
'leader_id' => 'integer',
|
'leader_id' => 'integer',
|
||||||
'remark' => 'string',
|
'remark' => 'string',
|
||||||
'is_company' => 'integer',
|
|
||||||
'status' => 'integer',
|
'status' => 'integer',
|
||||||
'create_time' => 'datetime',
|
'create_time' => 'datetime',
|
||||||
'update_time' => 'datetime',
|
'update_time' => 'datetime',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user