15 changed files with 691 additions and 199 deletions
@ -0,0 +1,116 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\adminapi\controller\personnel; |
||||
|
|
||||
|
use core\base\BaseAdminController; |
||||
|
use app\service\admin\personnel\PersonnelService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 人力资源-人员控制器 |
||||
|
* Class Personnel |
||||
|
* @package app\adminapi\controller\personnel |
||||
|
*/ |
||||
|
class Personnel extends BaseAdminController |
||||
|
{ |
||||
|
/** |
||||
|
* 获取人力资源-人员列表 |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function lists(){ |
||||
|
$data = $this->request->params([ |
||||
|
["name",""], |
||||
|
["gender",""], |
||||
|
["phone",""], |
||||
|
["address",""], |
||||
|
["education",""], |
||||
|
["employee_number",""], |
||||
|
["status",""], |
||||
|
["create_time",""] |
||||
|
]); |
||||
|
return success((new PersonnelService())->getPage($data)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 人力资源-人员详情 |
||||
|
* @param int $id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function info(int $id){ |
||||
|
return success((new PersonnelService())->getInfo($id)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加人力资源-人员 |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function add(){ |
||||
|
$data = $this->request->params([ |
||||
|
["name",""], |
||||
|
["gender",0], |
||||
|
["phone",""], |
||||
|
["head_img",""], |
||||
|
["address",""], |
||||
|
["native_place",""], |
||||
|
["education",""], |
||||
|
["profile",""], |
||||
|
["emergency_contact_phone",""], |
||||
|
["id_card_front",""], |
||||
|
["id_card_back",""], |
||||
|
["status",0], |
||||
|
["is_sys_user",0], |
||||
|
|
||||
|
]); |
||||
|
$this->validate($data, 'app\validate\personnel\Personnel.add'); |
||||
|
$id = (new PersonnelService())->add($data); |
||||
|
return success('ADD_SUCCESS', ['id' => $id]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 人力资源-人员编辑 |
||||
|
* @param $id 人力资源-人员id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function edit(int $id){ |
||||
|
$data = $this->request->params([ |
||||
|
["name",""], |
||||
|
["gender",0], |
||||
|
["phone",""], |
||||
|
["head_img",""], |
||||
|
["address",""], |
||||
|
["native_place",""], |
||||
|
["education",""], |
||||
|
["profile",""], |
||||
|
["emergency_contact_phone",""], |
||||
|
["id_card_front",""], |
||||
|
["id_card_back",""], |
||||
|
["status",0], |
||||
|
["is_sys_user",0], |
||||
|
|
||||
|
]); |
||||
|
$this->validate($data, 'app\validate\personnel\Personnel.edit'); |
||||
|
(new PersonnelService())->edit($id, $data); |
||||
|
return success('EDIT_SUCCESS'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 人力资源-人员删除 |
||||
|
* @param $id 人力资源-人员id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function del(int $id){ |
||||
|
(new PersonnelService())->del($id); |
||||
|
return success('DELETE_SUCCESS'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
use think\facade\Route; |
||||
|
|
||||
|
use app\adminapi\middleware\AdminCheckRole; |
||||
|
use app\adminapi\middleware\AdminCheckToken; |
||||
|
use app\adminapi\middleware\AdminLog; |
||||
|
// USER_CODE_BEGIN -- personnel |
||||
|
|
||||
|
Route::group('personnel', function () { |
||||
|
|
||||
|
//人力资源-人员列表 |
||||
|
Route::get('personnel', 'personnel.Personnel/lists'); |
||||
|
//人力资源-人员详情 |
||||
|
Route::get('personnel/:id', 'personnel.Personnel/info'); |
||||
|
//添加人力资源-人员 |
||||
|
Route::post('personnel', 'personnel.Personnel/add'); |
||||
|
//编辑人力资源-人员 |
||||
|
Route::put('personnel/:id', 'personnel.Personnel/edit'); |
||||
|
//删除人力资源-人员 |
||||
|
Route::delete('personnel/:id', 'personnel.Personnel/del'); |
||||
|
|
||||
|
})->middleware([ |
||||
|
AdminCheckToken::class, |
||||
|
AdminCheckRole::class, |
||||
|
AdminLog::class |
||||
|
]); |
||||
|
// USER_CODE_END -- personnel |
||||
@ -0,0 +1,159 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\model\personnel; |
||||
|
|
||||
|
use core\base\BaseModel; |
||||
|
use think\model\concern\SoftDelete; |
||||
|
use think\model\relation\HasMany; |
||||
|
use think\model\relation\HasOne; |
||||
|
|
||||
|
/** |
||||
|
* 人力资源-人员模型 |
||||
|
* Class Personnel |
||||
|
* @package app\model\personnel |
||||
|
*/ |
||||
|
class Personnel extends BaseModel |
||||
|
{ |
||||
|
|
||||
|
use SoftDelete; |
||||
|
|
||||
|
/** |
||||
|
* 数据表主键 |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $pk = 'id'; |
||||
|
|
||||
|
/** |
||||
|
* 模型名称 |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $name = 'personnel'; |
||||
|
|
||||
|
/** |
||||
|
* 定义软删除标记字段. |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $deleteTime = 'delete_time'; |
||||
|
|
||||
|
/** |
||||
|
* 定义软删除字段的默认值. |
||||
|
* @var int |
||||
|
*/ |
||||
|
protected $defaultSoftDelete = 0; |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员姓名 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchNameAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("name", "like", "%".$value."%"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员性别 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchGenderAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("gender", $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员电话 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchPhoneAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("phone", $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员家庭住址 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchAddressAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("address", $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员学历 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchEducationAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("education", $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员员工编号 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchEmployeeNumberAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("employee_number", $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员员工状态 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchStatusAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("status", $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 搜索器:人力资源-人员创建时间 |
||||
|
* @param $value |
||||
|
* @param $data |
||||
|
*/ |
||||
|
public function searchCreateTimeAttr($query, $value, $data) |
||||
|
{ |
||||
|
if ($value) { |
||||
|
$query->where("create_time", $value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
public function sys_user() |
||||
|
{ |
||||
|
return $this->hasOne(\app\model\sys\SysUser::class, 'uid', 'sys_user_id'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,151 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\service\admin\personnel; |
||||
|
|
||||
|
use app\dict\sys\UserDict; |
||||
|
use app\model\personnel\Personnel; |
||||
|
|
||||
|
use app\model\sys\SysUser; |
||||
|
use app\service\admin\user\UserService; |
||||
|
use core\base\BaseAdminService; |
||||
|
use think\facade\Db; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 人力资源-人员服务层 |
||||
|
* Class PersonnelService |
||||
|
* @package app\service\admin\personnel |
||||
|
*/ |
||||
|
class PersonnelService extends BaseAdminService |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
$this->model = new Personnel(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取人力资源-人员列表 |
||||
|
* @param array $where |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getPage(array $where = []) |
||||
|
{ |
||||
|
$field = 'id,name,head_img,gender,birthday,phone,address,native_place,education,profile,emergency_contact_phone,id_card_front,id_card_back,employee_number,status,is_sys_user,sys_user_id,create_time,update_time,delete_time'; |
||||
|
$order = 'create_time desc'; |
||||
|
|
||||
|
$search_model = $this->model->withSearch(["name", "gender", "phone", "address", "education", "employee_number", "status", "create_time"], $where)->field($field)->order($order); |
||||
|
$list = $this->pageQuery($search_model); |
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取人力资源-人员信息 |
||||
|
* @param int $id |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getInfo(int $id) |
||||
|
{ |
||||
|
$field = 'id,name,gender,head_img,birthday,phone,address,native_place,education,profile,emergency_contact_phone,id_card_front,id_card_back,employee_number,status,is_sys_user,sys_user_id,create_time,update_time,delete_time'; |
||||
|
|
||||
|
$info = $this->model->field($field)->where([['id', "=", $id]])->findOrEmpty()->toArray(); |
||||
|
$info['gender'] = strval($info['gender']); |
||||
|
$info['status'] = strval($info['status']); |
||||
|
$info['is_sys_user'] = strval($info['is_sys_user']); |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加人力资源-人员 |
||||
|
* @param array $data |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function add(array $data) |
||||
|
{ |
||||
|
$status = $this->model->where('phone', $data['phone'])->value('id'); |
||||
|
if ($status) { |
||||
|
throw new \Exception('手机号已存在'); |
||||
|
} |
||||
|
try { |
||||
|
Db::startTrans(); |
||||
|
if ($data['is_sys_user'] === '1') { |
||||
|
$uid = (new UserService())->addUser([ |
||||
|
'username' => $data['phone'], |
||||
|
'password' => $data['phone'], |
||||
|
'real_name' => $data['name'], |
||||
|
'head_img' => $data['head_img'], |
||||
|
'status' => UserDict::ON, |
||||
|
'role_ids' => [] |
||||
|
]); |
||||
|
$data['sys_user_id'] = $uid; |
||||
|
} |
||||
|
$res = $this->model->create($data); |
||||
|
Db::commit(); |
||||
|
return $res->id; |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
throw new \Exception($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 人力资源-人员编辑 |
||||
|
* @param int $id |
||||
|
* @param array $data |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function edit(int $id, array $data) |
||||
|
{ |
||||
|
|
||||
|
$status = $this->model->where('phone', $data['phone'])->value('id'); |
||||
|
if ($status && $status != $id) { |
||||
|
throw new \Exception('手机号已存在'); |
||||
|
} |
||||
|
try { |
||||
|
Db::startTrans(); |
||||
|
if ($data['is_sys_user'] === '1') { |
||||
|
$uid = (new SysUser())->where(['username' => $data['phone']])->value('uid'); |
||||
|
if (!$uid) { |
||||
|
$uid = (new UserService())->addUser([ |
||||
|
'username' => $data['phone'], |
||||
|
'password' => $data['phone'], |
||||
|
'real_name' => $data['name'], |
||||
|
'head_img' => $data['head_img'], |
||||
|
'status' => UserDict::ON, |
||||
|
'role_ids' => [] |
||||
|
]); |
||||
|
$data['sys_user_id'] = $uid; |
||||
|
} |
||||
|
} |
||||
|
$this->model->where([['id', '=', $id]])->update($data); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
throw new \Exception($e->getMessage()); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除人力资源-人员 |
||||
|
* @param int $id |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function del(int $id) |
||||
|
{ |
||||
|
$model = $this->model->where([['id', '=', $id]])->find(); |
||||
|
$res = $model->delete(); |
||||
|
return $res; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\validate\personnel; |
||||
|
use core\base\BaseValidate; |
||||
|
/** |
||||
|
* 人力资源-人员验证器 |
||||
|
* Class Personnel |
||||
|
* @package addon\app\validate\personnel |
||||
|
*/ |
||||
|
class Personnel extends BaseValidate |
||||
|
{ |
||||
|
|
||||
|
protected $rule = [ |
||||
|
'name' => 'require', |
||||
|
'phone' => 'require|mobile', |
||||
|
'emergency_contact_phone' => 'mobile', |
||||
|
'status' => 'require', |
||||
|
'is_sys_user' => 'require', |
||||
|
]; |
||||
|
|
||||
|
protected $message = [ |
||||
|
'name.require' => ['common_validate.require', ['name']], |
||||
|
'phone.require' => ['common_validate.require', ['phone']], |
||||
|
'phone.mobile' => ['common_validate.mobile', ['phone']], |
||||
|
'emergency_contact_phone.mobile' => ['common_validate.mobile', ['emergency_contact_phone']], |
||||
|
'status.require' => ['common_validate.require', ['status']], |
||||
|
'is_sys_user.require' => ['common_validate.require', ['is_sys_user']], |
||||
|
]; |
||||
|
|
||||
|
protected $scene = [ |
||||
|
"add" => ['name', 'gender', 'phone', 'address', 'native_place', 'education', 'profile', 'emergency_contact_phone', 'id_card_front', 'id_card_back', 'status', 'is_sys_user'], |
||||
|
"edit" => ['name', 'gender', 'phone', 'address', 'native_place', 'education', 'profile', 'emergency_contact_phone', 'id_card_front', 'id_card_back', 'status', 'is_sys_user'] |
||||
|
]; |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue