Floder.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use app\model\VrFloder;
  5. use app\model\VrGroup;
  6. use app\model\VrView;
  7. use think\facade\Request;
  8. use app\model\Employee;
  9. class Floder extends Base
  10. {
  11. /**
  12. * 创建文件夹
  13. */
  14. public function saveFloder()
  15. {
  16. $param = Request::only(['pid'=>0,'name'=>'']);
  17. if($param['pid']){
  18. $info = VrFloder::where([['id','=',$param['pid']]])->findOrEmpty();
  19. if($info->isEmpty() || $info->depth==2) return json(['code'=>1,'data'=>'最多支持创建两级文件夹','msg'=>'最多支持创建两级文件夹']);
  20. }
  21. $save = [
  22. 'fld_name'=>$param['name'],
  23. 'createtime'=>time(),
  24. 'create_user'=>$this->employeeId,
  25. 'fld_type'=>1,
  26. 'root_id'=>$this->rootId,
  27. 'rgt'=>0,
  28. 'lft'=>0
  29. ];
  30. if($param['pid']) $save['pid']=$param['pid'];
  31. VrFloder::create($save);
  32. return json(['code'=>0,'data'=>'保存成功','msg'=>'']);
  33. }
  34. /**
  35. * 右侧我的目录文件夹列表
  36. */
  37. public function getFloder()
  38. {
  39. $where[] = ['root_id','=',$this->rootId];
  40. $where[] = ['depth','<',3];
  41. $where[] = ['fld_type','=',1];
  42. $where[] = ['create_user','=',$this->employeeId];
  43. $list = VrFloder::where($where)->order('lft asc')->select()->toArray();
  44. return json(['code'=>0,'data'=>$list,'msg'=>'']);
  45. }
  46. /**
  47. * 作品管理列表
  48. * type= 0全部,1我的
  49. * 基本逻辑 草稿箱中只放草稿 status=0
  50. */
  51. public function getFloderList()
  52. {
  53. $param = Request::only(['type'=>0,'page'=>1,'limit'=>10]);
  54. $where[] = ['root_id','=',$this->rootId];
  55. $where[] = ['depth','=',1];
  56. $where[] = ['fld_type','=',1];
  57. if($param['type']) $where[] = ['create_user','=',$this->employeeId];
  58. // //一级文件夹
  59. $list = VrFloder::withCount(['group'=>function($query){
  60. $query->where([['status','<>',0]]);
  61. }])->where($where)->order('id desc')->field('id,fld_name,createtime,create_user')->select()->toArray();
  62. foreach ($list as $k => $v) {
  63. $list[$k]['createtime'] = date('Y.m.d',strtotime($v['createtime']));
  64. }
  65. // //草稿箱作品数量
  66. $draft = VrGroup::where([['status','=',0],['emp_id','=',$this->employeeId]])->count();
  67. // //未分磊作品列表
  68. $top_id = VrFloder::where([['create_user','=',$this->employeeId],['depth','=',0],['fld_type','=',1]])->value('id') ?: 0;
  69. $unassigned = VrGroup::where([['emp_id','=',$this->employeeId],['floder_id','in',[$top_id,0]],['status','<>',0]])->field('id,pic_path,title,createtime,sid,status')->page((int)$param['page'],(int)$param['limit'])->select()->toArray();
  70. $uncount = VrGroup::where([['emp_id','=',$this->employeeId],['floder_id','in',[$top_id,0]],['status','<>',0]])->count();
  71. foreach ($unassigned as $k1 => $v1) {
  72. $unassigned[$k1]['createtime'] = date('Y.m.d',strtotime($v1['createtime']));
  73. }
  74. //作品总量
  75. $count = VrGroup::where([['emp_id','in',$this->employeeId]])->count();
  76. return json(['code'=>0,'draft'=>$draft,'floder'=>['data'=>$list,'count'=>$count],'unassigned'=>['data'=>$unassigned,'count'=>$uncount]]);
  77. }
  78. /**
  79. * 删除文件夹
  80. * id=0
  81. */
  82. public function delFloder()
  83. {
  84. $param = Request::only(['id'=>0]);
  85. $where = [
  86. ['root_id','=',$this->rootId],
  87. ['create_user','=',$this->employeeId],
  88. ['id','=',$param['id']]
  89. ];
  90. $info = VrFloder::where($where)->findOrEmpty();
  91. if($info->isEmpty()) return json(['code'=>1,'data'=>'删除失败','msg'=>'删除失败']);
  92. $where = [
  93. ['lft','>=',$info->lft],
  94. ['rgt','<=',$info->rgt],
  95. ['create_user','=',$this->employeeId],
  96. ['fld_type','=',1],
  97. ];
  98. //所有子集
  99. $fids = VrFloder::where($where)->column('id');
  100. $group = VrGroup::where([['floder_id','in',$fids],['status','<>',0]])->findOrEmpty();
  101. if(!$group->isEmpty()) return json(['code'=>1,'data'=>'文件夹中含有作品数据,不支持删除','msg'=>'文件夹中含有作品数据,不支持删除']);
  102. VrFloder::where($where)->delete();
  103. //草稿箱中的作品默认0
  104. VrGroup::where([['floder_id','in',$fids],['status','=',0]])->update(['floder_id'=>0]);
  105. return json(['code'=>0,'data'=>'删除成功','msg'=>'']);
  106. }
  107. /**
  108. * 子文件作品列表
  109. */
  110. public function getSonFloderList()
  111. {
  112. $param = Request::only(['pid'=>0,'user_id'=>0]);
  113. $user_id = $param['user_id'] ?: $this->employeeId;
  114. $where = [
  115. ['root_id','=',$this->rootId],
  116. ['create_user','=',$user_id],
  117. ['depth','=',1],
  118. ['id','=',$param['pid']]
  119. ];
  120. $info = VrFloder::where($where)->findOrEmpty();
  121. if($info->isEmpty()) return json(['code'=>1,'data'=>'获取失败','msg'=>'获取失败']);
  122. //子文件夹
  123. $where = [
  124. ['root_id','=',$this->rootId],
  125. ['create_user','=',$user_id],
  126. ['depth','=',2],
  127. ['lft','>',$info->lft],
  128. ['rgt','<',$info->rgt]
  129. ];
  130. $list = VrFloder::withCount(['group'=>function($query){
  131. $query->where([['status','<>',0]]);
  132. }])->where($where)->field('id,fld_name,createtime')->select()->toArray();
  133. $id = [];
  134. foreach ($list as $k => $v) {
  135. $list[$k]['createtime'] = date('Y.m.d',strtotime($v['createtime']));
  136. $id[] = $v['id'];
  137. }
  138. $id = array_merge([(int)$param['pid']],$id);
  139. //作品总量
  140. $all_count = VrGroup::where([['floder_id','in',$id],['status','<>',0]])->count();
  141. return json(['code'=>0,'data'=>$list,'all_count'=>$all_count]);
  142. }
  143. /**
  144. * 编辑文件夹名称
  145. * id=0
  146. */
  147. public function editFloderName()
  148. {
  149. $param = Request::only(['id'=>0,'name'=>'']);
  150. $where = [
  151. ['root_id','=',$this->rootId],
  152. ['create_user','=',$this->employeeId],
  153. ['id','=',$param['id']]
  154. ];
  155. $info = VrFloder::where($where)->findOrEmpty();
  156. if($info->isEmpty()) return json(['code'=>1,'data'=>'编辑失败','msg'=>'编辑失败']);
  157. $info->fld_name = $param['name'];
  158. $info->save();
  159. return json(['code'=>0,'data'=>'保存成功','msg'=>'']);
  160. }
  161. }