Merge pull request 'zhangwei' (#6) from zhangwei into dev
Reviewed-on: #6
This commit is contained in:
commit
b5a6624471
@ -18,6 +18,7 @@ use app\adminapi\controller\BaseAdminController;
|
|||||||
use app\adminapi\lists\dept\DeptLists;
|
use app\adminapi\lists\dept\DeptLists;
|
||||||
use app\adminapi\logic\dept\DeptLogic;
|
use app\adminapi\logic\dept\DeptLogic;
|
||||||
use app\adminapi\validate\dept\DeptValidate;
|
use app\adminapi\validate\dept\DeptValidate;
|
||||||
|
use app\common\model\dept\Dept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门管理控制器
|
* 部门管理控制器
|
||||||
@ -78,8 +79,8 @@ class DeptController extends BaseAdminController
|
|||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$params = (new DeptValidate())->post()->goCheck('delete');
|
$params = (new DeptValidate())->post()->goCheck('delete');
|
||||||
DeptLogic::delete($params);
|
$result = DeptLogic::delete($params);
|
||||||
return $this->success('删除成功', [], 1, 1);
|
return $result ? $this->success('删除成功', [], 1, 1) : $this->fail(DeptLogic::getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -95,4 +96,15 @@ class DeptController extends BaseAdminController
|
|||||||
$result = DeptLogic::detail($params);
|
$result = DeptLogic::detail($params);
|
||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//某个组织下面的部门
|
||||||
|
public function listToOrg(): \think\response\Json
|
||||||
|
{
|
||||||
|
$params = $this->request->get(['org_id']);
|
||||||
|
if(empty($params['org_id'])){
|
||||||
|
return $this->fail('参数错误');
|
||||||
|
}
|
||||||
|
$data = Dept::field('id,name,leader,mobile,status')->where('org_id',$params['org_id'])->select()->toArray();
|
||||||
|
return $this->success('请求成功',$data);
|
||||||
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ use app\adminapi\controller\BaseAdminController;
|
|||||||
use app\adminapi\lists\dept\JobsLists;
|
use app\adminapi\lists\dept\JobsLists;
|
||||||
use app\adminapi\logic\dept\JobsLogic;
|
use app\adminapi\logic\dept\JobsLogic;
|
||||||
use app\adminapi\validate\dept\JobsValidate;
|
use app\adminapi\validate\dept\JobsValidate;
|
||||||
|
use app\common\model\dept\Jobs;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,22 +98,16 @@ class JobsController extends BaseAdminController
|
|||||||
$result = JobsLogic::detail($params);
|
$result = JobsLogic::detail($params);
|
||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//某个部门下面的岗位
|
||||||
/**
|
public function listToDept(): \think\response\Json
|
||||||
* @notes 获取岗位数据
|
{
|
||||||
* @return \think\response\Json
|
$params = $this->request->get(['dept_id']);
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
if(empty($params['dept_id'])){
|
||||||
* @throws \think\db\exception\DbException
|
return $this->fail('参数错误');
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
}
|
||||||
* @author 段誉
|
$data = Jobs::field('id,name,status,sort,create_time')->where('dept_id',$params['dept_id'])->select()->toArray();
|
||||||
* @date 2022/10/13 10:31
|
return $this->success('请求成功',$data);
|
||||||
*/
|
}
|
||||||
public function all()
|
|
||||||
{
|
|
||||||
$result = JobsLogic::getAllData();
|
|
||||||
return $this->data($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ use app\adminapi\controller\BaseAdminController;
|
|||||||
use app\adminapi\lists\dept\OrgsLists;
|
use app\adminapi\lists\dept\OrgsLists;
|
||||||
use app\adminapi\logic\dept\OrgsLogic;
|
use app\adminapi\logic\dept\OrgsLogic;
|
||||||
use app\adminapi\validate\dept\OrgsValidate;
|
use app\adminapi\validate\dept\OrgsValidate;
|
||||||
|
use app\common\model\dept\Orgs;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,8 +87,8 @@ class OrgsController extends BaseAdminController
|
|||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$params = (new OrgsValidate())->post()->goCheck('delete');
|
$params = (new OrgsValidate())->post()->goCheck('delete');
|
||||||
OrgsLogic::delete($params);
|
$result = OrgsLogic::delete($params);
|
||||||
return $this->success('删除成功', [], 1, 1);
|
return $result ? $this->success('删除成功', [], 1, 1) : $this->fail(OrgsLogic::getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,5 +105,10 @@ class OrgsController extends BaseAdminController
|
|||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取所有组织
|
||||||
|
public function getAll(): \think\response\Json
|
||||||
|
{
|
||||||
|
$data = Orgs::field('id,name,master,status,create_time')->select();
|
||||||
|
return $this->success('请求成功',$data->toArray());
|
||||||
|
}
|
||||||
}
|
}
|
@ -39,7 +39,7 @@
|
|||||||
$where[] = ['org_id','in',$orgs];
|
$where[] = ['org_id','in',$orgs];
|
||||||
}
|
}
|
||||||
return Dept::where($this->searchWhere)->where($where)
|
return Dept::where($this->searchWhere)->where($where)
|
||||||
->field('id,name,org_id,leader,mobile,status,sort')
|
->field('id,name,org_id,leader,mobile,status,sort,create_time')
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||||
->select()->each(function($item){
|
->select()->each(function($item){
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
namespace app\adminapi\lists\dept;
|
namespace app\adminapi\lists\dept;
|
||||||
|
|
||||||
use app\adminapi\lists\BaseAdminDataLists;
|
use app\adminapi\lists\BaseAdminDataLists;
|
||||||
use app\common\lists\ListsExcelInterface;
|
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\dept\Dept;
|
||||||
use app\common\model\dept\Jobs;
|
use app\common\model\dept\Jobs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +24,7 @@ use app\common\model\dept\Jobs;
|
|||||||
* Class JobsLists
|
* Class JobsLists
|
||||||
* @package app\adminapi\lists\dept
|
* @package app\adminapi\lists\dept
|
||||||
*/
|
*/
|
||||||
class JobsLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
|
class JobsLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,8 +36,8 @@ class JobsLists extends BaseAdminDataLists implements ListsSearchInterface,Lists
|
|||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'%like%' => ['name'],
|
'%like%' => ['name','dept_name'],
|
||||||
'=' => ['code', 'status']
|
'=' => ['status']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,14 +50,21 @@ class JobsLists extends BaseAdminDataLists implements ListsSearchInterface,Lists
|
|||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
$lists = Jobs::where($this->searchWhere)
|
$params = $this->request->param();
|
||||||
->append(['status_desc'])
|
$where = [];
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
if(isset($params['dept_name']) && $params['dept_name'] != ''){
|
||||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
$deps = Dept::where('name','like','%'.$params['dept_name'].'%')->column('id');
|
||||||
->select()
|
$where[] = ['dept_id','in',$deps];
|
||||||
->toArray();
|
}
|
||||||
|
return Jobs::where($this->searchWhere)->where($where)->field('id,dept_id,name,status,sort,create_time')
|
||||||
return $lists;
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
|
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||||
|
->select()->each(function($item){
|
||||||
|
$dept = Dept::where('id',$item['dept_id'])->findOrEmpty();
|
||||||
|
$item['dept_name'] = $dept->isEmpty() ? '' : $dept['name'];
|
||||||
|
return $item;
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,37 +76,13 @@ class JobsLists extends BaseAdminDataLists implements ListsSearchInterface,Lists
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
return Jobs::where($this->searchWhere)->count();
|
$params = $this->request->param();
|
||||||
}
|
$where = [];
|
||||||
|
if(isset($params['dept_name']) && $params['dept_name'] != ''){
|
||||||
|
$deps = Dept::where('name','like','%'.$params['dept_name'].'%')->column('id');
|
||||||
/**
|
$where[] = ['dept_id','in',$deps];
|
||||||
* @notes 导出文件名
|
}
|
||||||
* @return string
|
return Jobs::where($this->searchWhere)->where($where)->count();
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/11/24 16:17
|
|
||||||
*/
|
|
||||||
public function setFileName(): string
|
|
||||||
{
|
|
||||||
return '岗位列表';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 导出字段
|
|
||||||
* @return string[]
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/11/24 16:17
|
|
||||||
*/
|
|
||||||
public function setExcelFields(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'code' => '岗位编码',
|
|
||||||
'name' => '岗位名称',
|
|
||||||
'remark' => '备注',
|
|
||||||
'status_desc' => '状态',
|
|
||||||
'create_time' => '添加时间',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -56,7 +56,7 @@ class OrgsLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return Orgs::where($this->searchWhere)
|
return Orgs::where($this->searchWhere)
|
||||||
->field(['id', 'name', 'master', 'status'])
|
->field(['id', 'name', 'master', 'status','create_time'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()
|
->select()
|
||||||
|
@ -83,9 +83,12 @@ class DeptLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function delete(array $params)
|
public static function delete(array $params)
|
||||||
{
|
{
|
||||||
$jobs = Jobs::where('dept_id',$params['id'])->column('id');
|
$jobs = Jobs::where('dept_id',$params['id'])->findOrEmpty();
|
||||||
Jobs::destroy($jobs);
|
if(!$jobs->isEmpty()){
|
||||||
Dept::destroy($params['id']);
|
self::setError('当前部门下存在岗位数据,不能删除');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Dept::destroy($params['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ class DeptLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
public static function detail($params): array
|
||||||
{
|
{
|
||||||
$dept = Dept::field('id,name,org_id,leader,mobile,status,sort')->where('id',$params['id'])->findOrEmpty();
|
$dept = Dept::field('id,name,org_id,leader,mobile,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
|
||||||
if($dept->isEmpty()){
|
if($dept->isEmpty()){
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ namespace app\adminapi\logic\dept;
|
|||||||
use app\common\enum\YesNoEnum;
|
use app\common\enum\YesNoEnum;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\model\article\Article;
|
use app\common\model\article\Article;
|
||||||
|
use app\common\model\dept\Dept;
|
||||||
use app\common\model\dept\Jobs;
|
use app\common\model\dept\Jobs;
|
||||||
use app\common\service\FileService;
|
use app\common\service\FileService;
|
||||||
|
|
||||||
@ -39,11 +40,10 @@ class JobsLogic extends BaseLogic
|
|||||||
public static function add(array $params)
|
public static function add(array $params)
|
||||||
{
|
{
|
||||||
Jobs::create([
|
Jobs::create([
|
||||||
|
'dept_id' => $params['dept_id'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'code' => $params['code'],
|
|
||||||
'sort' => $params['sort'] ?? 0,
|
'sort' => $params['sort'] ?? 0,
|
||||||
'status' => $params['status'],
|
'status' => $params['status'],
|
||||||
'remark' => $params['remark'] ?? '',
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +60,10 @@ class JobsLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
Jobs::update([
|
Jobs::update([
|
||||||
'id' => $params['id'],
|
'id' => $params['id'],
|
||||||
|
'dept_id' => $params['dept_id'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'code' => $params['code'],
|
|
||||||
'sort' => $params['sort'] ?? 0,
|
'sort' => $params['sort'] ?? 0,
|
||||||
'status' => $params['status'],
|
'status' => $params['status'],
|
||||||
'remark' => $params['remark'] ?? '',
|
|
||||||
]);
|
]);
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -95,25 +94,13 @@ class JobsLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params) : array
|
public static function detail($params) : array
|
||||||
{
|
{
|
||||||
return Jobs::findOrEmpty($params['id'])->toArray();
|
$jobs = Jobs::field('id,dept_id,name,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
|
||||||
}
|
if($jobs->isEmpty()){
|
||||||
|
return [];
|
||||||
|
}
|
||||||
/**
|
$dept = Dept::where('id',$jobs['dept_id'])->findOrEmpty();
|
||||||
* @notes 岗位数据
|
$jobs['dept_name'] = $dept->isEmpty() ? '' : $dept['name'];
|
||||||
* @return array
|
return $jobs->toArray();
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/10/13 10:30
|
|
||||||
*/
|
|
||||||
public static function getAllData()
|
|
||||||
{
|
|
||||||
return Jobs::where(['status' => YesNoEnum::YES])
|
|
||||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
|
||||||
->select()
|
|
||||||
->toArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -15,6 +15,7 @@
|
|||||||
namespace app\adminapi\logic\dept;
|
namespace app\adminapi\logic\dept;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\dept\Dept;
|
||||||
use app\common\model\dept\Orgs;
|
use app\common\model\dept\Orgs;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -92,6 +93,12 @@ class OrgsLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function delete(array $params): bool
|
public static function delete(array $params): bool
|
||||||
{
|
{
|
||||||
|
//判断组织下面是否有部门
|
||||||
|
$dept = Dept::where('org_id',$params['id'])->findOrEmpty();
|
||||||
|
if(!$dept->isEmpty()){
|
||||||
|
self::setError('当前组织下存在部门,不能删除');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return Orgs::destroy($params['id']);
|
return Orgs::destroy($params['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +112,6 @@ class OrgsLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
public static function detail($params): array
|
||||||
{
|
{
|
||||||
return Orgs::findOrEmpty($params['id'])->toArray();
|
return Orgs::field('id,name,master,status,create_time')->findOrEmpty($params['id'])->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,7 +32,7 @@ class DeptValidate extends BaseValidate
|
|||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require|checkDept',
|
'id' => 'require|checkDept',
|
||||||
'org_id' => 'require|checkOrg',
|
'org_id' => 'require|checkOrg',
|
||||||
'name' => 'require|checkUnique|length:1,30',
|
'name' => 'require|length:1,30',
|
||||||
'leader' => 'require',
|
'leader' => 'require',
|
||||||
'mobile' => 'require|mobile',
|
'mobile' => 'require|mobile',
|
||||||
'status' => 'require|in:0,1',
|
'status' => 'require|in:0,1',
|
||||||
@ -62,7 +62,7 @@ class DeptValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->remove('id', true);
|
return $this->remove('id', true)->append('name','checkUniqueByAdd');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class DeptValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
return $this->only(['id','org_id','name','leader','mobile','status']);
|
return $this->only(['id','org_id','name','leader','mobile','status'])->append('name','checkUniqueByEdit');;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -102,15 +102,23 @@ class DeptValidate extends BaseValidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
//验证唯一
|
//验证唯一
|
||||||
public function checkUnique($value,$rule,$data): bool|string
|
public function checkUniqueByAdd($value,$rule,$data): bool|string
|
||||||
{
|
{
|
||||||
if(!empty($data['id'])) return true;
|
|
||||||
$dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->findOrEmpty();
|
$dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->findOrEmpty();
|
||||||
if(!$dep->isEmpty()){
|
if(!$dep->isEmpty()){
|
||||||
return '部门已存在';
|
return '部门已存在';
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkUniqueByEdit($value,$rule,$data): bool|string
|
||||||
|
{
|
||||||
|
$dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->where('id','<>',$data['id'])->findOrEmpty();
|
||||||
|
if(!$dep->isEmpty()){
|
||||||
|
return '部门已存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//校验组织
|
//校验组织
|
||||||
public function checkOrg($value): bool|string
|
public function checkOrg($value): bool|string
|
||||||
|
@ -17,6 +17,7 @@ namespace app\adminapi\validate\dept;
|
|||||||
|
|
||||||
use app\common\model\auth\Admin;
|
use app\common\model\auth\Admin;
|
||||||
use app\common\model\auth\AdminJobs;
|
use app\common\model\auth\AdminJobs;
|
||||||
|
use app\common\model\dept\Dept;
|
||||||
use app\common\model\dept\Jobs;
|
use app\common\model\dept\Jobs;
|
||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
@ -31,22 +32,20 @@ class JobsValidate extends BaseValidate
|
|||||||
{
|
{
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require|checkJobs',
|
'id' => 'require|checkJobs',
|
||||||
'name' => 'require|unique:'.Jobs::class.'|length:1,50',
|
'dept_id' => 'require|checkDept',
|
||||||
'code' => 'require|unique:'.Jobs::class,
|
'name' => 'require|length:1,50',
|
||||||
'status' => 'require|in:0,1',
|
'status' => 'require|in:0,1',
|
||||||
'sort' => 'egt:0',
|
'sort' => 'egt:0',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
'id.require' => '参数缺失',
|
'id.require' => '参数缺失',
|
||||||
|
'dept_id.require' => '请选择部门',
|
||||||
'name.require' => '请填写岗位名称',
|
'name.require' => '请填写岗位名称',
|
||||||
'name.length' => '岗位名称长度须在1-50位字符',
|
'name.length' => '岗位名称长度须在1-50位字符',
|
||||||
'name.unique' => '岗位名称已存在',
|
'status.require' => '请选择岗位状态',
|
||||||
'code.require' => '请填写岗位编码',
|
'status.in' => '岗位状态值错误',
|
||||||
'code.unique' => '岗位编码已存在',
|
|
||||||
'sort.egt' => '排序值不正确',
|
'sort.egt' => '排序值不正确',
|
||||||
'status.require' => '请选择岗位状态',
|
|
||||||
'status.in' => '岗位状态值错误',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ class JobsValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->remove('id', true);
|
return $this->remove('id', true)->append('name','checkUniqueByAdd');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -76,6 +75,7 @@ class JobsValidate extends BaseValidate
|
|||||||
|
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
|
return $this->append('name','checkUniqueByEdit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -87,8 +87,18 @@ class JobsValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneDelete()
|
public function sceneDelete()
|
||||||
{
|
{
|
||||||
return $this->only(['id'])->append('id', 'checkAbleDetele');
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//验证部门
|
||||||
|
public function checkDept($value): bool|string
|
||||||
|
{
|
||||||
|
$dept = Dept::findOrEmpty($value);
|
||||||
|
if ($dept->isEmpty()) {
|
||||||
|
return '部门不存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,22 +116,25 @@ class JobsValidate extends BaseValidate
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//验证唯一
|
||||||
/**
|
public function checkUniqueByAdd($value,$rule,$data): bool|string
|
||||||
* @notes 校验能否删除
|
{
|
||||||
* @param $value
|
$jobs = Jobs::where('dept_id',$data['dept_id'])->where('name',$data['name'])->findOrEmpty();
|
||||||
* @return bool|string
|
if(!$jobs->isEmpty()){
|
||||||
* @author 段誉
|
return '岗位已存在';
|
||||||
* @date 2022/5/26 14:22
|
}
|
||||||
*/
|
return true;
|
||||||
public function checkAbleDetele($value)
|
}
|
||||||
{
|
|
||||||
$check = AdminJobs::where(['jobs_id' => $value])->findOrEmpty();
|
public function checkUniqueByEdit($value,$rule,$data): bool|string
|
||||||
if (!$check->isEmpty()) {
|
{
|
||||||
return '已关联管理员,暂不可删除';
|
$jobs = Jobs::where('dept_id',$data['dept_id'])->where('name',$data['name'])->where('id','<>',$data['id'])->findOrEmpty();
|
||||||
}
|
if(!$jobs->isEmpty()){
|
||||||
return true;
|
return '岗位已存在';
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -15,6 +15,7 @@
|
|||||||
namespace app\adminapi\validate\dept;
|
namespace app\adminapi\validate\dept;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\dept\Orgs;
|
||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ class OrgsValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->only(['name','master','status']);
|
return $this->only(['name','master','status'])->append('name','checkUniqueByAdd');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ class OrgsValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
return $this->only(['id','name','master','status']);
|
return $this->only(['id','name','master','status'])->append('name','checkUniqueByEdit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,5 +97,24 @@ class OrgsValidate extends BaseValidate
|
|||||||
{
|
{
|
||||||
return $this->only(['id']);
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//验证唯一
|
||||||
|
public function checkUniqueByAdd($value,$rule,$data): bool|string
|
||||||
|
{
|
||||||
|
$org = Orgs::where('name',$data['name'])->findOrEmpty();
|
||||||
|
if(!$org->isEmpty()){
|
||||||
|
return '组织已存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkUniqueByEdit($value,$rule,$data): bool|string
|
||||||
|
{
|
||||||
|
$org = Orgs::where('name',$data['name'])->where('id','<>',$data['id'])->findOrEmpty();
|
||||||
|
if(!$org->isEmpty()){
|
||||||
|
return '组织已存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -28,17 +28,10 @@ class Jobs extends BaseModel
|
|||||||
use SoftDelete;
|
use SoftDelete;
|
||||||
|
|
||||||
protected $deleteTime = 'delete_time';
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
/**
|
public function getStatusAttr($value): string
|
||||||
* @notes 状态描述
|
{
|
||||||
* @param $value
|
$status = [1=>'禁用',0=>'正常'];
|
||||||
* @param $data
|
return $status[$value];
|
||||||
* @return string
|
}
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/5/25 18:03
|
|
||||||
*/
|
|
||||||
public function getStatusDescAttr($value, $data)
|
|
||||||
{
|
|
||||||
return $data['status'] ? '正常' : '停用';
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user