Personal.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\user\controller;
  15. use app\base\BaseController;
  16. use app\user\model\DepartmentChange as DepartmentChange;
  17. use app\user\model\PersonalQuit as PersonalQuit;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Personal extends BaseController
  22. {
  23. //调部门列表
  24. public function change()
  25. {
  26. if (request()->isAjax()) {
  27. $param = get_params();
  28. $tab = isset($param['tab']) ? $param['tab'] : 0;
  29. $uid = $this->uid;
  30. $where=[];
  31. $whereOr=[];
  32. $where[]=['delete_time','=',0];
  33. if($tab == 0){
  34. //全部
  35. $auth = isAuth($uid,'office_admin','conf_1');
  36. if($auth == 0){
  37. $whereOr[] = ['admin_id', '=', $uid];
  38. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  39. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  40. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  41. $dids_a = get_leader_departments($uid);
  42. $dids_b = get_role_departments($uid);
  43. $dids = array_merge($dids_a, $dids_b);
  44. if(!empty($dids)){
  45. $whereOr[] = ['did','in',$dids];
  46. }
  47. }
  48. }
  49. if($tab == 1){
  50. //我创建的
  51. $where[] = ['admin_id', '=', $this->uid];
  52. }
  53. if($tab == 2){
  54. //待我审核的
  55. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  56. }
  57. if($tab == 3){
  58. //我已审核的
  59. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  60. }
  61. if($tab == 4){
  62. //抄送给我的
  63. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  64. }
  65. if (isset($param['check_status']) && $param['check_status'] != "") {
  66. $where[] = ['check_status', '=', $param['check_status']];
  67. }
  68. if (!empty($param['did'])) {
  69. $where[] = ['did', '=',$param['did']];
  70. }
  71. //按时间检索
  72. if (!empty($param['move_time'])) {
  73. $move_time =explode('~', $param['move_time']);
  74. $where[] = ['move_time', 'between', [strtotime(urldecode($move_time[0])),strtotime(urldecode($move_time[1]))]];
  75. }
  76. $model = new DepartmentChange();
  77. $list = $model->datalist($param,$where,$whereOr);
  78. return table_assign(0, '', $list);
  79. } else {
  80. return view();
  81. }
  82. }
  83. //新增&编辑调部门
  84. public function change_add()
  85. {
  86. $param = get_params();
  87. if (request()->isAjax()) {
  88. $param['move_time'] = isset($param['move_time']) ? strtotime($param['move_time']) : 0;
  89. $model = new DepartmentChange();
  90. if ($param['id'] > 0) {
  91. $model->edit($param);
  92. } else {
  93. $uid = $param['uid'];
  94. $map = [];
  95. $map[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',leader_ids)")];
  96. $count = Db::name('Department')->where($map)->count();
  97. if($count>0){
  98. return to_assign(1,'请先撤销该员工的部门负责人头衔再申请');
  99. }
  100. $has = Db::name('DepartmentChange')->where(['uid'=>$param['uid'],'status'=>1,'delete_time'=>0])->count();
  101. if($has>0){
  102. return to_assign(1, "该员工有调动记录未完成,不能重复申请");
  103. }
  104. $param['admin_id'] = $this->uid;
  105. $model->add($param);
  106. }
  107. } else {
  108. $id = isset($param['id']) ? $param['id'] : 0;
  109. $department = set_recursion(get_department());
  110. if ($id > 0) {
  111. $model = new DepartmentChange();
  112. $detail = $model->getById($id);
  113. View::assign('detail', $detail);
  114. }
  115. View::assign('department', $department);
  116. View::assign('id', $id);
  117. if(is_mobile()){
  118. return view('qiye@/approve/add_change');
  119. }
  120. return view();
  121. }
  122. }
  123. //查看调部门申请
  124. public function change_view()
  125. {
  126. $param = get_params();
  127. $model = new DepartmentChange();
  128. $detail = $model->getById($param['id']);
  129. View::assign('detail', $detail);
  130. if(is_mobile()){
  131. return view('qiye@/approve/view_change');
  132. }
  133. return view();
  134. }
  135. //删除调部门申请
  136. public function change_delete()
  137. {
  138. $param = get_params();
  139. $id = $param['id'];
  140. if (request()->isDelete()) {
  141. $model = new DepartmentChange();
  142. $model->delById($id);
  143. } else {
  144. return to_assign(1, "错误的请求");
  145. }
  146. }
  147. //离职
  148. public function leave()
  149. {
  150. $param = get_params();
  151. if (request()->isAjax()) {
  152. $tab = isset($param['tab']) ? $param['tab'] : 0;
  153. $uid = $this->uid;
  154. $where=[];
  155. $whereOr=[];
  156. $where[]=['delete_time','=',0];
  157. if($tab == 0){
  158. //全部
  159. $auth = isAuth($uid,'office_admin','conf_1');
  160. if($auth == 0){
  161. $whereOr[] = ['admin_id', '=', $this->uid];
  162. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  163. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  164. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  165. $dids_a = get_leader_departments($uid);
  166. $dids_b = get_role_departments($uid);
  167. $dids = array_merge($dids_a, $dids_b);
  168. if(!empty($dids)){
  169. $whereOr[] = ['did','in',$dids];
  170. }
  171. }
  172. }
  173. if($tab == 1){
  174. //我创建的
  175. $where[] = ['admin_id', '=', $uid];
  176. }
  177. if($tab == 2){
  178. //待我审核的
  179. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  180. }
  181. if($tab == 3){
  182. //我已审核的
  183. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  184. }
  185. if($tab == 4){
  186. //抄送给我的
  187. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  188. }
  189. if (isset($param['check_status']) && $param['check_status'] != "") {
  190. $where[] = ['check_status', '=', $param['check_status']];
  191. }
  192. if (!empty($param['did'])) {
  193. $where[] = ['did', '=',$param['did']];
  194. }
  195. //按时间检索
  196. if (!empty($param['quit_time'])) {
  197. $quit_time =explode('~', $param['quit_time']);
  198. $where[] = ['quit_time', 'between', [strtotime(urldecode($quit_time[0])),strtotime(urldecode($quit_time[1]))]];
  199. }
  200. $model = new PersonalQuit();
  201. $list = $model->datalist($param,$where,$whereOr);
  202. return table_assign(0, '', $list);
  203. }
  204. else{
  205. return view();
  206. }
  207. }
  208. //添加离职申请
  209. public function leave_add()
  210. {
  211. $param = get_params();
  212. if (request()->isAjax()) {
  213. $param['quit_time'] = isset($param['quit_time']) ? strtotime($param['quit_time']) : 0;
  214. $model = new PersonalQuit();
  215. if ($param['id'] > 0) {
  216. $has = Db::name('PersonalQuit')->where([['uid','=',$param['uid']],['delete_time','=',0],['id','<>',$param['id']]])->count();
  217. if($has>0){
  218. return to_assign(1, "该员工已申请有离职记录,不能重复申请");
  219. }
  220. $detail = $model->edit($param);
  221. } else {
  222. $has = Db::name('PersonalQuit')->where(['uid'=>$param['uid'],'delete_time'=>0])->count();
  223. if($has>0){
  224. return to_assign(1, "该员工已申请有离职记录,不能重复申请");
  225. }
  226. $param['admin_id'] = $this->uid;
  227. $detail = $model->add($param);
  228. }
  229. } else {
  230. $id = isset($param['id']) ? $param['id'] : 0;
  231. $uid = isset($param['uid']) ? $param['uid'] : 0;
  232. $detail=[];
  233. if($uid>0){
  234. $admin = get_admin($uid);
  235. $detail['name'] = $admin['name'];
  236. $detail['did'] = $admin['did'];
  237. $detail['department'] = $admin['department'];
  238. }
  239. if ($id>0) {
  240. $model = new PersonalQuit();
  241. $detail = $model->getById($id);
  242. }
  243. View::assign('id', $id);
  244. View::assign('detail', $detail);
  245. if(is_mobile()){
  246. return view('qiye@/approve/add_leave');
  247. }
  248. return view();
  249. }
  250. }
  251. //查看离职申请
  252. public function leave_view()
  253. {
  254. $param = get_params();
  255. $model = new PersonalQuit();
  256. $detail = $model->getById($param['id']);
  257. View::assign('detail', $detail);
  258. if(is_mobile()){
  259. return view('qiye@/approve/view_leave');
  260. }
  261. return view();
  262. }
  263. //删除离职申请
  264. public function leave_delete()
  265. {
  266. $param = get_params();
  267. $id = $param['id'];
  268. if (request()->isDelete()) {
  269. $model = new PersonalQuit();
  270. $model->delById($id);
  271. } else {
  272. return to_assign(1, "错误的请求");
  273. }
  274. }
  275. }