123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- declare(strict_types=1);
- namespace app\mobile\controller;
- use app\model\VrFloder;
- use app\model\VrGroup;
- use app\model\VrView;
- use think\facade\Request;
- use app\model\Employee;
- class Floder extends Base
- {
- /**
- * 创建文件夹
- */
- public function saveFloder()
- {
- $param = Request::only(['pid'=>0,'name'=>'']);
- if($param['pid']){
- $info = VrFloder::where([['id','=',$param['pid']]])->findOrEmpty();
- if($info->isEmpty() || $info->depth==2) return json(['code'=>1,'data'=>'最多支持创建两级文件夹','msg'=>'最多支持创建两级文件夹']);
- }
- $save = [
- 'fld_name'=>$param['name'],
- 'createtime'=>time(),
- 'create_user'=>$this->employeeId,
- 'fld_type'=>1,
- 'root_id'=>$this->rootId,
- 'rgt'=>0,
- 'lft'=>0
- ];
- if($param['pid']) $save['pid']=$param['pid'];
- VrFloder::create($save);
- return json(['code'=>0,'data'=>'保存成功','msg'=>'']);
- }
- /**
- * 右侧我的目录文件夹列表
- */
- public function getFloder()
- {
- $where[] = ['root_id','=',$this->rootId];
- $where[] = ['depth','<',3];
- $where[] = ['fld_type','=',1];
- $where[] = ['create_user','=',$this->employeeId];
- $list = VrFloder::where($where)->order('lft asc')->select()->toArray();
- return json(['code'=>0,'data'=>$list,'msg'=>'']);
- }
- /**
- * 作品管理列表
- * type= 0全部,1我的
- * 基本逻辑 草稿箱中只放草稿 status=0
- */
- public function getFloderList()
- {
- $param = Request::only(['type'=>0,'page'=>1,'limit'=>10]);
- $where[] = ['root_id','=',$this->rootId];
- $where[] = ['depth','=',1];
- $where[] = ['fld_type','=',1];
- if($param['type']) $where[] = ['create_user','=',$this->employeeId];
- // //一级文件夹
- $list = VrFloder::withCount(['group'=>function($query){
- $query->where([['status','<>',0]]);
- }])->where($where)->order('id desc')->field('id,fld_name,createtime,create_user')->select()->toArray();
- foreach ($list as $k => $v) {
- $list[$k]['createtime'] = date('Y.m.d',strtotime($v['createtime']));
- }
- // //草稿箱作品数量
- $draft = VrGroup::where([['status','=',0],['emp_id','=',$this->employeeId]])->count();
- // //未分磊作品列表
- $top_id = VrFloder::where([['create_user','=',$this->employeeId],['depth','=',0],['fld_type','=',1]])->value('id') ?: 0;
- $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();
- $uncount = VrGroup::where([['emp_id','=',$this->employeeId],['floder_id','in',[$top_id,0]],['status','<>',0]])->count();
- foreach ($unassigned as $k1 => $v1) {
- $unassigned[$k1]['createtime'] = date('Y.m.d',strtotime($v1['createtime']));
- }
- //作品总量
- $count = VrGroup::where([['emp_id','in',$this->employeeId]])->count();
- return json(['code'=>0,'draft'=>$draft,'floder'=>['data'=>$list,'count'=>$count],'unassigned'=>['data'=>$unassigned,'count'=>$uncount]]);
- }
- /**
- * 删除文件夹
- * id=0
- */
- public function delFloder()
- {
- $param = Request::only(['id'=>0]);
- $where = [
- ['root_id','=',$this->rootId],
- ['create_user','=',$this->employeeId],
- ['id','=',$param['id']]
- ];
- $info = VrFloder::where($where)->findOrEmpty();
- if($info->isEmpty()) return json(['code'=>1,'data'=>'删除失败','msg'=>'删除失败']);
- $where = [
- ['lft','>=',$info->lft],
- ['rgt','<=',$info->rgt],
- ['create_user','=',$this->employeeId],
- ['fld_type','=',1],
- ];
- //所有子集
- $fids = VrFloder::where($where)->column('id');
- $group = VrGroup::where([['floder_id','in',$fids],['status','<>',0]])->findOrEmpty();
- if(!$group->isEmpty()) return json(['code'=>1,'data'=>'文件夹中含有作品数据,不支持删除','msg'=>'文件夹中含有作品数据,不支持删除']);
- VrFloder::where($where)->delete();
- //草稿箱中的作品默认0
- VrGroup::where([['floder_id','in',$fids],['status','=',0]])->update(['floder_id'=>0]);
- return json(['code'=>0,'data'=>'删除成功','msg'=>'']);
- }
- /**
- * 子文件作品列表
- */
- public function getSonFloderList()
- {
- $param = Request::only(['pid'=>0,'user_id'=>0]);
- $user_id = $param['user_id'] ?: $this->employeeId;
- $where = [
- ['root_id','=',$this->rootId],
- ['create_user','=',$user_id],
- ['depth','=',1],
- ['id','=',$param['pid']]
- ];
- $info = VrFloder::where($where)->findOrEmpty();
- if($info->isEmpty()) return json(['code'=>1,'data'=>'获取失败','msg'=>'获取失败']);
- //子文件夹
- $where = [
- ['root_id','=',$this->rootId],
- ['create_user','=',$user_id],
- ['depth','=',2],
- ['lft','>',$info->lft],
- ['rgt','<',$info->rgt]
- ];
- $list = VrFloder::withCount(['group'=>function($query){
- $query->where([['status','<>',0]]);
- }])->where($where)->field('id,fld_name,createtime')->select()->toArray();
- $id = [];
- foreach ($list as $k => $v) {
- $list[$k]['createtime'] = date('Y.m.d',strtotime($v['createtime']));
- $id[] = $v['id'];
- }
- $id = array_merge([(int)$param['pid']],$id);
- //作品总量
- $all_count = VrGroup::where([['floder_id','in',$id],['status','<>',0]])->count();
- return json(['code'=>0,'data'=>$list,'all_count'=>$all_count]);
- }
- /**
- * 编辑文件夹名称
- * id=0
- */
- public function editFloderName()
- {
- $param = Request::only(['id'=>0,'name'=>'']);
- $where = [
- ['root_id','=',$this->rootId],
- ['create_user','=',$this->employeeId],
- ['id','=',$param['id']]
- ];
- $info = VrFloder::where($where)->findOrEmpty();
- if($info->isEmpty()) return json(['code'=>1,'data'=>'编辑失败','msg'=>'编辑失败']);
- $info->fld_name = $param['name'];
- $info->save();
- return json(['code'=>0,'data'=>'保存成功','msg'=>'']);
- }
- }
-
|