Index.php 4.0 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle    (APP启动页)
     * @ApiSummary  (APP启动页)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/flash)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "image": //启动页图片,
    }
    })
     */
    public function flash()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('flash')->where('id',1)->field('image')->find();
        $data['image'] = $qiniu.$data['image'];
        $this->success('success',$data);

    }


    /**
     * @ApiTitle    (我的文件夹)
     * @ApiSummary  (我的文件夹)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/index)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "times": //时间,
    "info": [
    {
    "id":           //文件夹id,
    "user_id":      //用户id,
    "folder_name":  //文件夹名称,
    "pid":          //父级文件夹id,
    "is_open":      //是否公开1公开2私密
    "is_up":        //1上架2下架
    "createtime":   //创建时间,
    "updatetime":   //修改时间
    }
    ]
    }
    })
     */
    public function index()
    {
        $user_id = $this->auth->id;
        //登录的身份下
        if(!empty($user_id)){
            $data = Db::name('folder')->field('updatetime',true)->where('user_id',$user_id)->where('pid',0)->order('is_up asc')->select();
            foreach ($data as &$v){
                $v['nowtime'] = date('Y-m-d',$v['createtime']);
                $v['createtime'] = date('m-d',$v['createtime']);
            }

            $times = array_values(array_unique(array_column($data,'createtime')));
            rsort($times);
            //将数据放到对应的时间分段
            $arr = [];
            foreach ($times as $t_k=> $t_v){
                $arr[$t_k]['times'] = $t_v;
                $k = 0;
                foreach ($data as $value){
                    $k+=0;
                    if($t_v == $value['createtime']){
                        $arr[$t_k]['info'][$k] = $value;
                        $k++;
                    }
                }
            }
            $this->success('success',$arr);
        }else{
            $arr = [];
            $this->success('success',$arr);
        }
    }

    /**
     * @ApiTitle    (文件列表)
     * @ApiSummary  (文件列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/folderlist)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "times": //时间,
    "info": [
    {
    "id":           //文件夹id,
    "user_id":      //用户id,
    "folder_name":  //文件夹名称,
    "pid":          //父级文件夹id,
    "createtime":   //创建时间,
    "updatetime":   //修改时间
    }
    ]
    }
    })
     */
    public function folderlist()
    {
        $user_id = $this->auth->id;
        $data = Db::name('savemes')
            ->where('user_id',$user_id)
            ->order('is_up asc,type asc')
            ->select();
        foreach ($data as &$v){
            $v['createtime'] = date('m-d',$v['createtime']);
        }

        $times = array_values(array_unique(array_column($data,'createtime')));
        //将数据放到对应的时间分段
        $arr = [];
        foreach ($times as $t_k=> $t_v){
            $arr[$t_k]['times'] = $t_v;
            $k = 0;
            foreach ($data as $value){
                $k+=0;
                if($t_v == $value['createtime']){
                    $arr[$t_k]['info'][$k] = $value;
                    $k++;
                }
            }
        }
        $this->success('success',$arr);

    }




}