Index.php
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?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);
}
}