Netdisk.php 2.89 KB
<?php

namespace addons\qingdong\controller;

use addons\antis\controller\StaffApi;
use app\admin\model\qingdong\file\Category;

class Netdisk extends StaffApi
{

    protected $noNeedLogin = ['*'];


    //文件列表
    public function index(){

        $param = $this->request->param();

        $groupList = (new \addons\qingdong\model\Netdisk())->where('category_id',$param['category_id'])->select();

        $this->success('',$groupList);

    }


    //文件夹列表
    public function listType(){

        $param = $this->request->param();

        $groupList = (new Category())->where('s_id',$param['category_id'])->select();

        $this->success('',$groupList);

    }



    //文件列表
    public function indexType(){

        $param = $this->request->param();

        $groupList = (new Category())->where('s_id', 0)
            ->where(function ($query)use($param){

                if(isset($param['type']) && !empty($param['type'])){
                    if($param['type'] == '2'){
                        $query->where(['type'=>'2','create_id'=>$this->auth->id]);
                    }
                    if($param['type'] == '3'){
                        $query->whereOr(['type'=>'3']);
                    }
                }

            })

            ->select();

        $this->success('',$groupList);
    }


    //创建文件
    public function addNetdisk(){

        $param = $this->request->param();

        $data = [
            'category_id'=>$param['category_id']??'',
            'name'=>$param['name'],
            'file'=>$param['file'],
            'create_id'=>$this->auth->id,

        ];

        $res = (new \addons\qingdong\model\Netdisk())->save($data);

        $this->success('添加成功');
    }


    //创建文件夹
    public function addType(){

        $param = $this->request->param();

        $data = [
            's_id'=>$param['s_id']??'',
            'name'=>$param['name'],
            'type'=>$param['type'],
            'create_id'=>$this->auth->id,

        ];

        $res = (new Category())->save($data);

        $this->success('添加成功');
    }


    public function delNetdisk(){

        $param = $this->request->param();
        $find = (new \addons\qingdong\model\Netdisk())->where('create_id',$this->auth->id)->where('id',$param['id'])->find();

        if(!$find){
            $this->error('未找到该文件');
        }
        $find->delete();
        $this->success('删除成功');
    }


    public function delType(){

        $param = $this->request->param();
        $find = (new Category())->where('create_id',$this->auth->id)->where('id',$param['id'])->find();

        if(!$find){
            $this->error('未找到该文件夹');
        }
        $find->delete();
        $this->success('删除成功');
    }



}