Treasured.php
16.8 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<?php
namespace app\api\controller;
use dh2y\qrcode\QRcode;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 墨宝档案
* @package app\api\controller
*/
class Treasured extends BaseApi
{
protected $noNeedLogin = '';
protected $noNeedRight = '*';
/**
* 获取墨宝档案尺寸
* @ApiTitle (获取墨宝档案尺寸)
* @ApiMethod (POST)
* @ApiRoute (/api/treasured/getTreasuredSize)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取数据成功",
"time": "1609298080",
"data": [
{
"id": "尺寸id",
"name": "尺寸名称",
"createtime": "2020-12-29 09:18:49"
}
]
})
*/
public function getTreasuredSize(){
$TreasuredSize = model('TreasuredSize')->order('weigh','desc')->field('id,name,createtime')->select();
$this->success('获取数据成功',$TreasuredSize);
}
/**
* 增加墨宝档案
* @ApiTitle (增加墨宝档案)
* @ApiMethod (POST)
* @ApiRoute (/api/treasured/addTreasured)
* @ApiParams (name="url", type="string", required=true, description="你的域名 精确到id 用于二维码生成")
* @ApiParams (name="author", type="string", required=true, description="墨宝作者")
* @ApiParams (name="title", type="string", required=true, description="墨宝标题")
* @ApiParams (name="content", type="string", required=true, description="墨宝内容")
* @ApiParams (name="images", type="string", required=true, description="图片数组{不带域名}")
* @ApiParams (name="production_typeface_id", type="integer", required=true, description="字体ID")
* @ApiParams (name="treasured_size_id", type="integer", required=true, description="尺寸ID")
* @ApiParams (name="production_format_id", type="integer", required=true, description="格式ID")
* @ApiParams (name="status", type="integer", required=true, description="状态:0=待出售,1=已出售,2=非卖品")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "增加墨宝档案成功",
"time": "1609306718",
"data": {
"id": 1,
"user_id": "用户ID",
"avatar": "用户头像",
"nickname": "用户昵称",
"title": "我是文章标题",
"number": "墨宝编号",
"author": "作者",
"images": "墨宝图片",
"content": "墨宝内容",
"production_typeface": "书体名称",
"production_typeface_id": "书体id{用的作品里面的书体}",
"production_format": "格式名称",
"production_format_id": "用的作品里面的格式",
"treasured_size": "尺寸名称",
"treasured_size_id": "尺寸id",
"status": "状态:0=待出售,1=已出售,2=非卖品",
"zan_num": "点赞数量",
"createtime": "2020-12-30 13:38:38",
"updatetime": "2020-12-30 13:38:38",
"deletetime": null,
"message": null
}
})
*/
public function addTreasured(){
//1.验证用户权限
if ($this->auth->authlist == '' || $this->auth->authlist == ','){
$this->error('请您先实名认证');
}
//2.获取数据
$data = $this->get_data_array([
['url','域名不能为空'],
['author','作者名称不能为空'],
['title','作品标题不能为空'],
['content','内容不存在'],
['images','图片必须上传'],
['production_typeface_id','字体ID必须传入'],
['treasured_size_id','尺寸ID必须传入'],
['production_format_id','格式ID必须传入'],
['status','状态必须填写 0=待出售,1=已出售,2=非卖品'],
]);
//3.获取图片数据
$files = str_replace('"','"',$data['images']);
$images = implode(',',json_decode($files,true));
//4.查询数据
$typeface = model('production_typeface')->where('id',$data['production_typeface_id'])->find();
$treasured_size = model('treasured_size')->where('id',$data['treasured_size_id'])->find();
$format = model('production_format')->where('id',$data['production_format_id'])->find();
if (!$typeface || !$treasured_size || !$format){
$this->error('数据不存在');
}
$data['production_typeface'] = $typeface['name'];
$data['treasured_size'] = $treasured_size['name'];
$data['production_format'] = $format['name'];
$data['user_id'] = $this->auth->id;
$data['avatar'] = $this->auth->avatar;
$data['nickname'] = $this->auth->nickname;
$data['images'] = $images;
$data['number'] = time()-mt_rand(1000,9999);
if (isset($data['url'])){
$url = $data['url'];
unset($data['url']);
}
//5.增加墨宝
$treasured = model('treasured')->create($data);
//6.查询数据
$treasured = model('treasured')->where('id',$treasured['id'])->find();
//7.生成二维码及海报
$qr_code_bg = model('config')->where('name','qr_code_bg')->find();
if ($qr_code_bg && !empty($qr_code_bg['value'])){
$code = new QRcode();
$qr_code = $code->png($url.$treasured['id']) //生成二维码
->logo(ROOT_PATH.'public/assets/img/bg.png',4,1.97); //生成logo二维码
if (!empty($this->auth->avatar)){
$qr_code = $qr_code->logo($this->auth->avatar);//生成logo二维码
}
$qr_code = $qr_code->getPath();//获取二维码生成的地址
$qr_code_d = $code->png($url.$treasured['id']) //生成二维码
->logo(ROOT_PATH.'public/assets/img/bg.png',4,1.97); //生成logo二维码
if (!empty($this->auth->avatar)){
$qr_code_d = $qr_code_d->logo($this->auth->avatar);//生成logo二维码
}
$qr_code_d = $qr_code_d->background(550,950,cdnurl($qr_code_bg['value'])) //给二维码加上背景
->getPath();//获取二维码生成的地址
//8.更新数据
$treasured->qr_code = $qr_code;
$treasured->qr_code_d = $qr_code_d;
$treasured->save();
}
//9.返回结果
$this->success('增加墨宝档案成功',$treasured);
}
/**
* 墨宝档案基本信息
* @ApiTitle (墨宝档案基本信息)
* @ApiMethod (POST)
* @ApiRoute (/api/treasured/getJiXin)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "查询数据成功",
"time": "1609651935",
"data": {
"treasured_num": "墨宝档案数量",
"number": "墨宝档案浏览数量"
}
})
*/
public function getJiXin(){
//1.查询墨宝档案数量
$treasured_num = model('treasured')->where('deletetime','<>',null)->count();
//2.查询墨宝档案浏览数量
$number = model('config')->where('name','mobao_num')->find();
//3.返回数据
$this->success('查询数据成功',['treasured_num'=>$treasured_num,'number'=>$number['value']*1]);
}
/**
* 墨宝档案列表
* @ApiTitle (墨宝档案列表)
* @ApiMethod (POST)
* @ApiRoute (/api/treasured/addListTreasured)
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ()
*/
public function addListTreasured(){
//1.获取动态id
$data = $this->get_data_array([
['page','分页次数不能为空'],
['num','分页数量不能为空']
]);
//2.查询数据
$treasured = model('treasured')
->where('deletetime',null)
->order('createtime','desc')
->page($data['page'],$data['num'])
->select();
//3.记录浏览记录
if ($treasured && $data['page'] == 1){
model('config')->where('name','mobao_num')->setInc('value');
}
//4.判断是不是点赞
if ($treasured){
foreach ($treasured as $key => $val){
$treasured[$key]['is_zan'] = 0;
$zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$val['id'])->find();
if ($zan){
$treasured[$key]['is_zan'] = 1;
}
}
}
//5.返回数据
$this->success('查询数据成功',$treasured);
}
/**
* 墨宝档案筛选
* @ApiTitle (墨宝档案筛选)
* @ApiMethod (POST)
* @ApiRoute (/api/treasured/getTreasuredShai)
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
* @ApiParams (name="author", type="string", required=false, description="作者名称")
* @ApiParams (name="start_time", type="integer", required=false, description="开始时间")
* @ApiParams (name="end_time", type="integer", required=false, description="结束时间")
* @ApiParams (name="production_format_id", type="integer", required=false, description="格式ID")
* @ApiParams (name="production_typeface_id", type="integer", required=false, description="字体ID")
* @ApiParams (name="treasured_size_id", type="integer", required=false, description="尺寸ID")
* @ApiParams (name="status", type="integer", required=false, description="状态:0=待出售,1=已出售,2=非卖品")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ()
*/
public function getTreasuredShai(){
//1.获取动态id
$data = $this->get_data_array([
['page','分页次数不能为空'],
['num','分页数量不能为空']
]);
$res = input('param.');
//2.查询数据
$treasured = model('treasured');
if (isset($res['author']) && !empty($res['author'])){
$treasured = $treasured->where('author',$res['author']);
}
if (isset($res['start_time']) && !empty($res['start_time']) && isset($res['end_time']) && !empty($res['end_time'])){
$treasured = $treasured->where('createtime','>',$res['start_time'])->where('createtime','<',$res['end_time']);
}
if (isset($res['production_format_id']) && !empty($res['production_format_id'])){
$treasured = $treasured->where('production_format_id',$res['production_format_id']);
}
if (isset($res['production_typeface_id']) && !empty($res['production_typeface_id'])){
$treasured = $treasured->where('production_typeface_id',$res['production_typeface_id']);
}
if (isset($res['treasured_size_id']) && !empty($res['treasured_size_id'])){
$treasured = $treasured->where('treasured_size_id',$res['treasured_size_id']);
}
if (isset($res['status']) && $res['status'] != ''){
$treasured = $treasured->where('status',$res['status']);
}
$treasured = $treasured->page($data['page'],$data['num'])
->select();
//3.判断是不是点赞
if ($treasured){
foreach ($treasured as $key => $val){
$treasured[$key]['is_zan'] = 0;
$zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$val['id'])->find();
if ($zan){
$treasured[$key]['is_zan'] = 1;
}
}
}
//4.返回数据
$this->success('查询数据成功',$treasured);
}
/**
* 墨宝档案详情
* @ApiTitle (墨宝档案详情)
* @ApiMethod (POST)
* @ApiRoute (/api/treasured/getTreasuredContent)
* @ApiParams (name="id", type="integer", required=true, description="墨宝ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "查询数据成功",
"time": "1609742416",
"data": {
"id": 1,
"user_id": 2,
"avatar": "头像",
"nickname": "署名",
"title": "墨宝标题",
"number": "墨宝编号",
"author": "作者",
"images": "墨宝图片",
"content": "内容",
"production_typeface": "字体",
"production_typeface_id": "字体ID",
"production_format": "格式",
"production_format_id": "格式ID",
"treasured_size": "尺寸名称",
"treasured_size_id": "尺寸ID",
"status": "状态:0=待出售,1=已出售,2=非卖品",
"zan_num": "点赞数量",
"createtime": "2020-12-30 13:38:38",
"qr_code": "二维码",
"qr_code_d": "海报二维码",
"updatetime": "2020-12-30 13:38:38",
"deletetime": "删除时间",
"message": "删除提示",
"is_zan": "是否点赞 0=未点赞,1=已点赞"
}
})
*/
public function getTreasuredContent(){
//1.获取动态id
$id = $this->get_data('id','墨宝档案ID不能为空');
//2.查询数据
$treasured = model('treasured')->where('id',$id)->find();
//3.查询有没有点赞
$treasured['is_zan'] = 0;
$zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$id)->find();
if ($zan){
$treasured['is_zan'] = 1;
}
//4.返回数据
$this->success('查询数据成功',$treasured);
}
/**
* 动态点赞或取消点赞{注意}
* @ApiTitle (动态点赞或取消点赞{注意})
* @ApiMethod (POST)
* @ApiRoute (/api/treasured/setTreasuredZan)
* @ApiParams (name="treasured_id", type="integer", required=true, description="动态内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "查询成功",
"time": "1608886856",
"data": {
"code": "0取消点赞 1=点赞成功",
"msg": "提示"
}
})
*/
public function setTreasuredZan(){
//1.获取数据
$treasured_id = $this->get_data('treasured_id','动态id不能为空');
//2.查询点赞
$treasured_zan = model('treasured_zan')
->where('user_id',$this->auth->id)
->where('treasured_id',$treasured_id)
->find();
if ($treasured_zan){
$treasured_zan->delete();
model('treasured')->where('id',$treasured_id)->setDec('zan_num');
$this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
}
//4.增加点赞
model('treasured_zan')->create(['user_id'=>$this->auth->id,'treasured_id'=>$treasured_id]);
//5.增加点赞数量
model('treasured')->where('id',$treasured_id)->setInc('zan_num');
//6.返回结果
$this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
}
}