12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\admin\controller\base\org;
- /**
- * @title : 企业部门/组织部门
- * @desc :
- * @Author : Rock
- * @Date : 2022-01-10 09:59:57
- * @LastEditTime: 2024-11-28 14:18:23
- */
- use app\admin\controller\Base;
- use app\common\model\base\org\OrgDepart as OrgDepartModel;
- use app\admin\validate\base\org\OrgDepart as OrgDepartValidate;
- class OrgDepart extends Base
- {
- protected $noNeedAuth = ['getList'];
- protected $noNeedValidate = ['doEdit'];
- protected $orgDepartModel = null;
- public function initialize()
- {
- parent::initialize();
- $this->orgDepartModel = new OrgDepartModel;
- $this->validate = new OrgDepartValidate;
- }
- /**
- * @title: 组织部门列表
- * @param {int} {org_id} {非必填} {部门所属组织}
- * @return array
- * @Author: wangkewei
- * @Date: 2021/5/18 9:53
- */
- public function getList($org_id=0)
- {
- $where = [];
- if(!empty($org_id)){
- $where[] = ['org_id','=',$org_id];
- }else{
- $where[] = ['org_id','=',$this->userinfo['org_id']];
- }
- $list = $this->orgDepartModel->where($where)->with(['org'])->order("sort ASC")->select();
- return res(1,"获取成功",$list);
- }
- /**
- * @title: 组织部门编辑
- * @param array
- * @return array
- * @Author: wangkewei
- * @Date: 2021/5/18 9:55
- */
- public function doEdit()
- {
- $data = $this->request->param();
- if(!empty($data['org_id'])){
- $data['org_id'] = $data['org_id'];
- }else{
- $data['org_id'] = $this->userinfo['org_id'];
- }
- if(empty($data['depart_id'])){
- $maxSort = $this->orgDepartModel->where('org_id',$data['org_id'])->max('sort');
- $data['sort'] = $maxSort + 1;
- $info = $this->orgDepartModel->where('org_id',$data['org_id'])->where('name',$data['name'])->find();
- if(!empty($info)){
- return res(1,"部门已存在");
- }
- }
- try{
- $check = validate(OrgDepartValidate::class)->check($data);
- if(true!==$check){
- return res(2,$check);
- }
- $this->orgDepartModel->replace()->save($data);
- $info = $this->orgDepartModel->getData();
- slog(1,"编辑了组织部门".$data['name']);
- return res(1,"保存成功");
- }catch(Exception $e){
- slog(2,"编辑了组织部门".$data['name']);
- return res(2,"保存失败".$e->getMessage());
- }
- }
- /**
- * @title: 组织部门删除
- * @param {int} {depart_id} {必填} {部门ID}
- * @return array
- * @Author: wangkewei
- * @Date: 2021/5/18 9:55
- */
- public function doDelete(int $depart_id=0)
- {
- $info = $this->orgDepartModel->where("depart_id",$depart_id)->find();
- $info->delete();
- slog(1,"删除了组织部门".$info->name);
- return res(1,"删除成功");
- }
- }
|