Index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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\disk\controller;
  15. use app\base\BaseController;
  16. use app\disk\model\Disk as DiskModel;
  17. use app\disk\validate\DiskValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Index extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new DiskModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $pid = isset($param['pid']) ? $param['pid'] : 0;
  40. $where=[];
  41. $where[]=['admin_id','=',$this->uid];
  42. $where[]=['delete_time','=',0];
  43. $where[]=['group_id','=',0];
  44. if (!empty($param['keywords'])) {
  45. $where[] = ['name', 'like', '%' . $param['keywords'] . '%'];
  46. }
  47. if (!empty($param['is_star'])) {
  48. $where[]=['types','<',2];
  49. $where[]=['is_star','=',1];
  50. }
  51. if (!empty($param['ext'])) {
  52. $where[] = ['file_ext', 'in',$param['ext']];
  53. }
  54. if (!empty($param['is_star']) || !empty($param['ext'])) {
  55. }
  56. else{
  57. $where[]=['pid','=',$pid];
  58. }
  59. $list = $this->model->datalist($param,$where);
  60. $folder = get_pfolder($pid);
  61. return table_assign(0, '', $list,$folder);
  62. }
  63. else{
  64. return view();
  65. }
  66. }
  67. /**
  68. * 分享列表
  69. */
  70. public function sharelist()
  71. {
  72. $param = get_params();
  73. if (request()->isAjax()) {
  74. $pid = isset($param['pid']) ? $param['pid'] : 0;
  75. $group_id = isset($param['group_id']) ? $param['group_id'] : 0;
  76. $where=[];
  77. $where[]=['delete_time','=',0];
  78. $where[]=['group_id','=',$group_id];
  79. if (!empty($param['keywords'])) {
  80. $where[] = ['name', 'like', '%' . $param['keywords'] . '%'];
  81. }
  82. if (!empty($param['is_star'])) {
  83. if($pid>0){
  84. $where[]=['pid','=',$pid];
  85. }
  86. else{
  87. $where[]=['is_star','=',1];
  88. }
  89. }
  90. if (!empty($param['ext'])) {
  91. $where[] = ['file_ext', 'in',$param['ext']];
  92. }
  93. if (!empty($param['is_star']) || !empty($param['ext'])) {
  94. }
  95. else{
  96. $where[]=['pid','=',$pid];
  97. }
  98. $list = $this->model->datalist($param,$where);
  99. $folder = get_pfolder($param['pid']);
  100. return table_assign(0, '', $list,$folder);
  101. }
  102. else{
  103. return view();
  104. }
  105. }
  106. /**
  107. * 回收站列表
  108. */
  109. public function clearlist()
  110. {
  111. $param = get_params();
  112. if (request()->isAjax()) {
  113. $pid = isset($param['pid']) ? $param['pid'] : 0;
  114. $where=[];
  115. $where[]=['admin_id','=',$this->uid];
  116. $where[]=['clear_time','=',0];
  117. if($pid>0){
  118. $where[]=['pid','=',$pid];
  119. }
  120. else{
  121. $where[]=['delete_time','>',0];
  122. }
  123. if (!empty($param['ext'])) {
  124. $where[] = ['file_ext', 'in',$param['ext']];
  125. }
  126. if (!empty($param['keywords'])) {
  127. $where[] = ['name', 'like', '%' . $param['keywords'] . '%'];
  128. }
  129. $list = $this->model->datalist($param,$where);
  130. $folder = get_pfolder($param['pid']);
  131. return table_assign(0, '', $list,$folder);
  132. }
  133. else{
  134. return view();
  135. }
  136. }
  137. //添加&编辑
  138. public function add_group()
  139. {
  140. if (request()->isAjax()) {
  141. $param = get_params();
  142. if($param['title'] == '全部' || $param['title']=='未共享空间'){
  143. return to_assign(1, '该共享空间名称已经存在');
  144. }
  145. if (!empty($param['id']) && $param['id'] > 0) {
  146. $uid=$this->uid;
  147. $detail = Db::name('DiskGroup')->where('id',$param['id'])->find();
  148. if($uid==1 || $detail['admin_id'] == $uid){
  149. $count = Db::name('DiskGroup')->where([['id','<>',$param['id']],['delete_time','=',0],['title','=',$param['title']]])->count();
  150. if ($count > 0) {
  151. return to_assign(1, '该共享空间名称已经被其他员工占用');
  152. }
  153. $param['update_time'] = time();
  154. $res = Db::name('DiskGroup')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
  155. if($res!=false){
  156. add_log('edit', $param['id'], $param);
  157. return to_assign(0,'编辑成功',$param['id']);
  158. }else{
  159. return to_assign(1,'操作失败');
  160. }
  161. }else{
  162. return to_assign(1,'只要超级管理员和创建人才有权限操作');
  163. }
  164. } else {
  165. $param['admin_id'] = $this->uid;
  166. $param['create_time'] = time();
  167. $count = Db::name('DiskGroup')->where([['delete_time','=',0],['title','=',$param['title']]])->count();
  168. if ($count > 0) {
  169. return to_assign(1, '该共享空间名称已经被其他员工占用');
  170. }
  171. $gid = Db::name('DiskGroup')->strict(false)->field(true)->insertGetId($param);
  172. if($gid!=false){
  173. add_log('add', $gid, $param);
  174. return to_assign(0,'添加成功',$gid);
  175. }else{
  176. return to_assign(1,'操作失败');
  177. }
  178. }
  179. }
  180. }
  181. //删除
  182. public function del_group()
  183. {
  184. if (request()->isDelete()) {
  185. $id = get_params("id");
  186. $uid=$this->uid;
  187. $detail = Db::name('DiskGroup')->where('id',$id)->find();
  188. if($uid==1 || $detail['admin_id'] == $uid){
  189. $count = Db::name('Disk')->where(["group_id" => $id,'delete_time'=>0])->count();
  190. if ($count > 0) {
  191. return to_assign(1, "该共享空间还存在文件,请去除文件或者转移文件后再删除");
  192. }
  193. if (Db::name('DiskGroup')->delete($id) !== false) {
  194. add_log('delete', $id, []);
  195. return to_assign(0, "删除成功");
  196. } else {
  197. return to_assign(1, "删除失败");
  198. }
  199. }else{
  200. return to_assign(1,'只要超级管理员和创建人才有权限操作');
  201. }
  202. } else {
  203. return to_assign(1, "错误的请求");
  204. }
  205. }
  206. /**
  207. * 新增上传文件
  208. */
  209. public function add_upload()
  210. {
  211. $param = get_params();
  212. if (request()->isAjax()) {
  213. try {
  214. validate(DiskValidate::class)->scene('add')->check($param);
  215. } catch (ValidateException $e) {
  216. // 验证失败 输出错误信息
  217. return to_assign(1, $e->getError());
  218. }
  219. $param['admin_id'] = $this->uid;
  220. $param['did'] = $this->did;
  221. $this->model->add($param);
  222. }
  223. }
  224. /**
  225. * 新增文件夹
  226. */
  227. public function add_folder()
  228. {
  229. $param = get_params();
  230. if (request()->isAjax()) {
  231. try {
  232. validate(DiskValidate::class)->scene('add')->check($param);
  233. } catch (ValidateException $e) {
  234. // 验证失败 输出错误信息
  235. return to_assign(1, $e->getError());
  236. }
  237. $param['types'] = 2;
  238. $param['admin_id'] = $this->uid;
  239. $param['did'] = $this->did;
  240. $this->model->add($param);
  241. }
  242. }
  243. public function add_article()
  244. {
  245. $param = get_params();
  246. if (request()->isAjax()) {
  247. if (!empty($param['id']) && $param['id'] > 0) {
  248. $param['update_time'] = time();
  249. $res = Db::name('Article')->strict(false)->field(true)->update($param);
  250. if ($res !== false) {
  251. add_log('edit', $param['id'], $param);
  252. $disk['id'] = $param['disk_id'];
  253. $disk['name'] = $param['name'];
  254. $disk['update_time'] = $param['update_time'];
  255. $this->model->edit($disk);
  256. } else {
  257. return to_assign(1, "操作失败");
  258. }
  259. } else {
  260. $param['admin_id'] = $this->uid;
  261. $param['create_time'] = time();
  262. $aid = Db::name('Article')->strict(false)->field(true)->insertGetId($param);
  263. if ($aid !== false) {
  264. add_log('add', $aid, $param);
  265. $param['action_id'] = $aid;
  266. $param['types'] = 1;
  267. $param['ext'] = 'article';
  268. $param['did'] = $this->did;
  269. $this->model->add($param);
  270. } else {
  271. return to_assign(1, "操作失败");
  272. }
  273. }
  274. }else{
  275. $id = isset($param['id']) ? $param['id'] : 0;
  276. $pid = isset($param['pid']) ? $param['pid'] : 0;
  277. $group_id = isset($param['group_id']) ? $param['group_id'] : 0;
  278. if ($id>0) {
  279. $file = $this->model->getById($id);
  280. $detail = Db::name('Article')->find($file['action_id']);
  281. if($detail['file_ids'] !=''){
  282. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  283. $detail['file_array'] = $file_array;
  284. }
  285. $detail['disk_id'] = $id;
  286. View::assign('detail', $detail);
  287. return view('edit_article');
  288. }
  289. View::assign('pid', $pid);
  290. View::assign('group_id', $group_id);
  291. return view();
  292. }
  293. }
  294. //查看在线文档
  295. public function view_article()
  296. {
  297. $param = get_params();
  298. $id = isset($param['id']) ? $param['id'] : 0;
  299. if ($id>0) {
  300. $file = $this->model->getById($id);
  301. $detail = Db::name('Article')->find($file['action_id']);
  302. $detail['admin_name'] = Db::name('Admin')->where('id',$detail['admin_id'])->value('name');
  303. if($detail['file_ids'] !=''){
  304. $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  305. $detail['file_array'] = $file_array;
  306. }
  307. View::assign('detail', $detail);
  308. }
  309. return view();
  310. }
  311. /**
  312. * 新增文件夹
  313. */
  314. public function rename()
  315. {
  316. $param = get_params();
  317. if (request()->isAjax()) {
  318. $uid=$this->uid;
  319. $detail = Db::name('Disk')->where('id',$param['id'])->find();
  320. if($uid==1 || $detail['admin_id'] == $uid){
  321. try {
  322. validate(DiskValidate::class)->scene('edit')->check($param);
  323. } catch (ValidateException $e) {
  324. // 验证失败 输出错误信息
  325. return to_assign(1, $e->getError());
  326. }
  327. $this->model->edit($param);
  328. }else{
  329. return to_assign(1,'只要超级管理员和创建人才有权限操作');
  330. }
  331. }
  332. }
  333. /**
  334. * 查看
  335. */
  336. public function view($id)
  337. {
  338. $detail = $this->model->getById($id);
  339. if (!empty($detail)) {
  340. View::assign('detail', $detail);
  341. return view();
  342. }
  343. else{
  344. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  345. }
  346. }
  347. /**
  348. * 删除
  349. */
  350. public function del()
  351. {
  352. $param = get_params();
  353. if (request()->isDelete()) {
  354. $ids = $param["ids"];
  355. $idArray = explode(',', strval($ids));
  356. $list = [];
  357. foreach ($idArray as $key => $val) {
  358. $file = Db::name('Disk')->find($val);
  359. if($file['admin_id'] != $this->uid && $this->uid>1){
  360. return to_assign(1, "删除失败,【".$file['name']."】不是你上传的文件");
  361. break;
  362. }
  363. $count = Db::name('Disk')->where(['pid'=>$val,'delete_time'=>0])->count();
  364. if($count>0){
  365. return to_assign(1, "删除失败,请先清空【".$file['name']."】里面的文件");
  366. break;
  367. }
  368. $list[] = [
  369. 'id' => $val,
  370. 'delete_time' => time()
  371. ];
  372. }
  373. if(!empty($list)){
  374. $model = new DiskModel();
  375. foreach ($list as $item) {
  376. $model->update($item);
  377. }
  378. return to_assign();
  379. }
  380. else{
  381. return to_assign(1, "操作失败");
  382. }
  383. } else {
  384. return to_assign(1, "错误的请求");
  385. }
  386. }
  387. /**
  388. * 恢复
  389. */
  390. public function back()
  391. {
  392. $param = get_params();
  393. if (request()->isAjax()) {
  394. $ids = $param["ids"];
  395. $idArray = explode(',', strval($ids));
  396. $list = [];
  397. foreach ($idArray as $key => $val) {
  398. $list[] = [
  399. 'id' => $val,
  400. 'delete_time' => 0
  401. ];
  402. }
  403. if(!empty($list)){
  404. $model = new DiskModel();
  405. foreach ($list as $item) {
  406. $model->update($item);
  407. }
  408. return to_assign();
  409. }
  410. else{
  411. return to_assign(1, "操作失败");
  412. }
  413. } else {
  414. return to_assign(1, "错误的请求");
  415. }
  416. }
  417. /**
  418. * 清除
  419. */
  420. public function clear()
  421. {
  422. $param = get_params();
  423. if (request()->isAjax()) {
  424. $ids = $param["ids"];
  425. $idArray = explode(',', strval($ids));
  426. $list = [];
  427. foreach ($idArray as $key => $val) {
  428. $list[] = [
  429. 'id' => $val,
  430. 'clear_time' => time()
  431. ];
  432. }
  433. if(!empty($list)){
  434. $model = new DiskModel();
  435. foreach ($list as $item) {
  436. $model->update($item);
  437. }
  438. return to_assign();
  439. }
  440. else{
  441. return to_assign(1, "操作失败");
  442. }
  443. } else {
  444. return to_assign(1, "错误的请求");
  445. }
  446. }
  447. //查找父文件的所有父ids
  448. public function get_pidsa($id)
  449. {
  450. $pid = Db::name('Disk')->where('id',$id)->value('pid');
  451. if($pid==0){
  452. return [];
  453. }
  454. else{
  455. $pids=$this->get_pids($pid);
  456. $pids[] = $pid;
  457. return $pids;
  458. }
  459. return [];
  460. }
  461. //while方法
  462. public function get_pids($categoryId)
  463. {
  464. $parentIds = [];
  465. while ($categoryId > 0) {
  466. $category = Db::name('Disk')->where('id',$categoryId)->find();
  467. if ($category && $category['pid'] > 0) {
  468. $parentIds[] = $category['id'];
  469. $categoryId = $category['pid'];
  470. } else {
  471. break;
  472. }
  473. }
  474. return $parentIds;
  475. }
  476. /**
  477. * 移动
  478. */
  479. public function move()
  480. {
  481. $param = get_params();
  482. if (request()->isAjax()) {
  483. $ids = $param["ids"];
  484. $pid = $param["pid"];
  485. $pids = $this->get_pids($pid);
  486. $idArray = explode(',', strval($ids));
  487. $list = [];
  488. foreach ($idArray as $key => $val) {
  489. if(in_array($val,$pids) || $val==$pid){
  490. $file = Db::name('Disk')->find($val);
  491. return to_assign(1, "移动失败,【".$file['name']."】不能移动到文件夹本身或其子目录");
  492. break;
  493. }
  494. $list[] = [
  495. 'id' => $val,
  496. 'pid' => $pid,
  497. 'update_time' => time()
  498. ];
  499. }
  500. if(!empty($list)){
  501. $model = new DiskModel();
  502. foreach ($list as $item) {
  503. $model->update($item);
  504. }
  505. return to_assign();
  506. }
  507. else{
  508. return to_assign(1, "转移失败");
  509. }
  510. }else{
  511. $pid = isset($param['pid']) ? $param['pid']: 0 ;
  512. $group_id = isset($param['group_id']) ? $param['group_id']: 0 ;
  513. $path = get_pfolder($pid);
  514. $folder = Db::name('Disk')->where(['pid'=>$pid,'group_id'=>$group_id,'types'=>2,'delete_time'=>0])->order('id desc')->select()->toArray();
  515. $pfolder = '全部文件';
  516. if($pid>0){
  517. $pfolder = Db::name('Disk')->where(['id'=>$pid])->value('name');
  518. }
  519. View::assign('pid', $pid);
  520. View::assign('pfolder', $pfolder);
  521. View::assign('path', $path);
  522. View::assign('folder', $folder);
  523. View::assign('group_id', $group_id);
  524. return view();
  525. }
  526. }
  527. /**
  528. * 标星
  529. */
  530. public function star()
  531. {
  532. $param = get_params();
  533. if (request()->isAjax()) {
  534. $ids = $param["ids"];
  535. $idArray = explode(',', strval($ids));
  536. $list = [];
  537. foreach ($idArray as $key => $val) {
  538. $list[] = [
  539. 'id' => $val,
  540. 'is_star' => 1,
  541. 'update_time' => time()
  542. ];
  543. }
  544. if(!empty($list)){
  545. $model = new DiskModel();
  546. foreach ($list as $item) {
  547. $model->update($item);
  548. }
  549. return to_assign();
  550. }
  551. else{
  552. return to_assign(1, "操作失败");
  553. }
  554. }
  555. }
  556. /**
  557. * 取消标星
  558. */
  559. public function unstar()
  560. {
  561. $param = get_params();
  562. if (request()->isAjax()) {
  563. $ids = $param["ids"];
  564. $idArray = explode(',', strval($ids));
  565. $list = [];
  566. foreach ($idArray as $key => $val) {
  567. $list[] = [
  568. 'id' => $val,
  569. 'is_star' => 0,
  570. 'update_time' => time()
  571. ];
  572. }
  573. if(!empty($list)){
  574. $model = new DiskModel();
  575. foreach ($list as $item) {
  576. $model->update($item);
  577. }
  578. return to_assign();
  579. }
  580. else{
  581. return to_assign(1, "操作失败");
  582. }
  583. }
  584. }
  585. }