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