Production.php
37.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
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
<?php
namespace app\api\controller;
use EasyWeChat\Factory;
use think\Db;
use think\Exception;
/**
* 作品相关
* @package app\api\controller
*/
class Production extends BaseApi
{
protected $noNeedLogin = '';
protected $noNeedRight = '*';
/**
* 获取作品朝代
*/
public function getDynasty(){
$dynasty = model('production_dynasty')->order('weigh','desc')->field('id,name,createtime')->select();
$this->success('查询成功',$dynasty);
}
/**
* 获取作品格式
*/
public function getFormat(){
$forma = model('production_format')->order('weigh','desc')->field('id,name,createtime')->select();
$this->success('查询成功',$forma);
}
/**
* 获取作品字体
*/
public function getTypeface(){
$typeface = model('production_typeface')->order('weigh','desc')->field('id,name,createtime')->select();
$this->success('查询成功',$typeface);
}
/**
* 增加作品
* @ApiTitle (增加作品)
* @ApiMethod (POST)
* @ApiRoute (/api/production/addProduction)
* @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="typeface_id", type="integer", required=true, description="字体ID")
* @ApiParams (name="dynasty_id", type="integer", required=true, description="朝代ID")
* @ApiParams (name="format_id", type="integer", required=true, description="格式ID")
* @ApiParams (name="width", type="integer", required=true, description="宽度")
* @ApiParams (name="height", 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": "1609213602",
"data": {
"title": "作品标题",
"content": "作品内容",
"images": "作品图片",
"typeface_id": "字体ID",
"dynasty_id": "朝代ID",
"format_id": "格式ID",
"width": "宽度",
"height": "高度",
"typeface": "字体",
"dynasty": "朝代",
"format": "格式",
"user_id": "用户ID",
"avatar": "头像",
"nickname": "署名",
"fenxiang_num": "分享数量",
"zan_num": "点赞数量",
"ping_num": "点赞数量",
"price_num": "打赏总数",
"shoucang_num": "收藏数量",
"createtime": "2020-12-29 11:46:43",
"updatetime": "2020-12-29 11:46:43",
"id": "2"
}
})
*/
public function addProduction(){
//1.验证用户权限
if ($this->auth->authlist == '' || $this->auth->authlist == ','){
$this->error('请您先实名认证');
}
//2.获取数据
$data = $this->get_data_array([
['title','作品标题不能为空'],
['content','内容不存在'],
['images','图片必须上传'],
['typeface_id','字体ID必须传入'],
['dynasty_id','朝代ID必须传入'],
['format_id','格式ID必须传入'],
['width','宽度'],
['height','高度'],
]);
//3.获取图片数据
//$files = str_replace('"','"',$data['images']);
//$images = implode(',',json_decode($files,true));
//4.查询数据
$typeface = model('production_typeface')->where('id',$data['typeface_id'])->find();
$dynasty = model('production_dynasty')->where('id',$data['dynasty_id'])->find();
$format = model('production_format')->where('id',$data['format_id'])->find();
if (!$typeface || !$dynasty || !$format){
$this->error('数据不存在');
}
$data['typeface'] = $typeface['name'];
$data['dynasty'] = $dynasty['name'];
$data['format'] = $format['name'];
$data['user_id'] = $this->auth->id;
$data['avatar'] = $this->auth->avatar;
$data['nickname'] = $this->auth->nickname;
//5.增加作品
$production = model('production')->create($data);
//6.查询数据
$production = model('production')->where('id',$production['id'])->find();
//7.返回结果
$this->success('增加作品成功',$production);
}
/**
* 获取作品列表
* @ApiTitle (获取作品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/production/ProductionList)
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
* @ApiParams (name="status", type="integer", required=true, description="1=最热,2=最新作品,3=书体筛选")
* @ApiParams (name="production_typeface_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": "1609213602",
"data": {
"title": "作品标题",
"content": "作品内容",
"images": "作品图片",
"typeface_id": "字体ID",
"dynasty_id": "朝代ID",
"format_id": "格式ID",
"width": "宽度",
"height": "高度",
"typeface": "字体",
"dynasty": "朝代",
"format": "格式",
"user_id": "用户ID",
"avatar": "头像",
"nickname": "署名",
"fenxiang_num": "分享数量",
"zan_num": "点赞数量",
"ping_num": "点赞数量",
"price_num": "打赏总数",
"shoucang_num": "收藏数量",
"is_zan":"判断是否点赞 0=未点赞,1=已经点赞",
"createtime": "2020-12-29 11:46:43",
"updatetime": "2020-12-29 11:46:43",
"id": "2"
}
})
*/
public function ProductionList(){
//1.获取数据
$data = $this->get_data_array([
['page','分页次数不能为空'],
['num','分页数量不能为空'],
['status','状态必须填写'],
]);
//2.获取列表数据
if ($data['status'] == 1){
//最热
$Pro_list = model('production')
->where('deletetime',null)
->with(['user'])
->order('zan_num','desc')
->page($data['page'],$data['num'])
->select();
}else if ($data['status'] == 2){
//最新作品
$Pro_list = model('production')
->where('deletetime',null)
->with(['user'])
->order('createtime','desc')
->page($data['page'],$data['num'])
->select();
}else if ($data['status'] == 3){
$typeface_id = $this->get_data('production_typeface_id','字体ID不能为空');
//最新作品
$Pro_list = model('production')
->where('deletetime',null)
->with(['user'])
->where('typeface_id',$typeface_id)
->order('createtime','desc')
->page($data['page'],$data['num'])
->select();
}
//3.判断是不是好友
$user_id = $this->auth->id;
if (!empty($Pro_list)){
foreach ($Pro_list as $key => $val){
//1.查询是否点赞
$attention = model('production_zan')->where('user_id',$user_id)->where('production_id',$val['id'])->find();
$attention?$Pro_list[$key]['is_zan'] = 1:$Pro_list[$key]['is_zan'] = 0;
}
}
$this->success('查询数据成功',$Pro_list);
}
/**
* 获取作品详情
* @ApiTitle (获取作品详情)
* @ApiMethod (POST)
* @ApiRoute (/api/production/ProductionContent)
* @ApiParams (name="production_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": "1609213602",
"data": {
"title": "作品标题",
"content": "作品内容",
"images": "作品图片",
"typeface_id": "字体ID",
"dynasty_id": "朝代ID",
"format_id": "格式ID",
"width": "宽度",
"height": "高度",
"typeface": "字体",
"dynasty": "朝代",
"format": "格式",
"user_id": "用户ID",
"avatar": "头像",
"nickname": "署名",
"fenxiang_num": "分享数量",
"zan_num": "点赞数量",
"ping_num": "点赞数量",
"price_num": "打赏总数",
"shoucang_num": "收藏数量",
"is_zan":"判断是否点赞 0=未点赞,1=已经点赞",
"is_collect":"判断是否收藏 0=未收藏,1=已收藏",
"createtime": "2020-12-29 11:46:43",
"updatetime": "2020-12-29 11:46:43",
"id": "2"
}
})
*/
public function ProductionContent(){
//1.获取数据
$data = $this->get_data_array([
['production_id','作品id不能为空'],
]);
//2.获取作品详情
$production = model('production')->where('id',$data['production_id'])->find();
if (!$production){
$this->error('您的作品不存在');
}
//3.查询是否点赞
$attention = model('production_zan')->where('user_id',$this->auth->id)->where('production_id',$production['id'])->find();
$attention?$production['is_zan'] = 1:$production['is_zan'] = 0;
//4.查询是否收藏
$production_collect = model('production_collect')->where('user_id',$this->auth->id)->where('production_id',$production['id'])->find();
$production_collect?$production['is_collect'] = 1:$production['is_collect'] = 0;
$this->success('查询数据成功',$production);
}
/**
* 作品点赞或取消点赞{注意}
* @ApiTitle (作品点赞或取消点赞{注意})
* @ApiMethod (POST)
* @ApiRoute (/api/production/setProductionZan)
* @ApiParams (name="production_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": "1608886856",
"data": {
"code": "0取消点赞 1=点赞成功",
"msg": "提示"
}
})
*/
public function setProductionZan(){
//1.获取数据
$production_id = $this->get_data('production_id','作品id不能为空');
//2.查询作品数据
$production = model('production')->where('id',$production_id)->find();
//3.查询点赞
$production_zan = model('production_zan')
->where('user_id',$this->auth->id)
->where('production_id',$production_id)
->find();
if ($production_zan){
$production_zan->delete();
$production->zan_num -= 1;
$production->save();
$this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
}
//4.增加点赞
model('production_zan')->create(['user_id'=>$this->auth->id,'production_id'=>$production_id]);
//5.增加点赞数量
$production->zan_num += 1;
$production->save();
//6.返回结果
$this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
}
/**
* 作品收藏或取消收藏
* @ApiTitle (作品收藏或取消收藏)
* @ApiMethod (POST)
* @ApiRoute (/api/production/setProductionCollect)
* @ApiParams (name="production_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": "1608886856",
"data": {
"code": "0取消收藏 1=收藏成功",
"msg": "提示"
}
})
*/
public function setProductionCollect(){
//1.获取数据
$production_id = $this->get_data('production_id','作品id不能为空');
//2.查询作品数据
$production = model('production')->where('id',$production_id)->find();
//3.查询点赞
$production_collect = model('production_collect')
->where('user_id',$this->auth->id)
->where('production_id',$production_id)
->find();
if ($production_collect){
$production_collect->delete();
$production->shoucang_num -= 1;
$production->save();
$this->success('查询成功',['code'=>0,'msg'=>'取消收藏成功']);
}
//4.增加点赞
model('production_collect')->create(['user_id'=>$this->auth->id,'production_id'=>$production_id]);
//5.增加点赞数量
$production->shoucang_num += 1;
$production->save();
//6.返回结果
$this->success('查询成功',['code'=>1,'msg'=>'收藏成功']);
}
/**
* 获取作品评论列表
* @ApiTitle (获取作品评论列表)
* @ApiMethod (POST)
* @ApiRoute (/api/production/getComment)
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
* @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 ({
"code": 1,
"msg": "查询成功",
"time": "1608890670",
"data": [
{
"id": 2,
"production_id": "作品id",
"user_id": "用户id",
"content": "评论内容",
"pid": "0一级评论 不是0是父级评论id",
"zan_num": "点赞数量",
"createtime": "2020-12-25 17:53:07",
"updatetime": "2020-12-25 17:53:07",
"deletetime": null,
"message": null,
"is_zan": "是否点赞 0未点赞 1点赞",
"son_num":"子评论数量",
"user": "用户信息参考首页列表注释",
"str_time": "发布时间"
}
]
})
*/
public function getComment(){
Db::startTrans();
try {
//1.获取作品id
$data = $this->get_data_array([
['production_id','作品id不能为空'],
['page','分页次数不能为空'],
['num','分页数量不能为空']
]);
//2.获取一级评论
$production_comment = model('production_comment')
->with(['user'])
->where('production_id',$data['production_id'])
->where('pid',0)
->order('createtime','desc')
->order('deletetime',null)
->page($data['page'],$data['num'])
->select();
//3.循环父级评论
foreach ($production_comment as $key => $val){
//3.1 判断用户有没有点赞
$is_zan = model('production_comment_zan')
->where('user_id',$this->auth->id)
->where('production_comment_id',$val['id'])
->find();
$production_comment[$key]['is_zan'] = 1;
if (!$is_zan){
$production_comment[$key]['is_zan'] = 0;
}
//3.2 获取子评论数量
$production_comment[$key]['son_num'] = model('production_comment')
->where('pid',$val['id'])
->count();
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
//4.返回数据
$this->success('查询成功',$production_comment);
}
/**
* 发布评论
* @ApiTitle (发布评论)
* @ApiMethod (POST)
* @ApiRoute (/api/production/setComment)
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
* @ApiParams (name="content", type="integer", required=true, description="评论内容")
* @ApiParams (name="pid", 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 ( )
*/
public function setComment(){
Db::startTrans();
try {
//1.获取作品id
$data= $this->get_data_array([
['production_id','作品id不能为空'],
['content','评论内容'],
]);
//2.发布评论
$pid = empty(input('param.pid'))?0:input('param.pid');
$data['pid'] = $pid;
$data['user_id'] = $this->auth->id;
$data['zan_num'] = 0;
$res = model('production_comment')->create($data);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
//3.发布成功
$this->success('发布评论成功',$res);
}
/**
* 根据父级评论获取子评论
* @ApiTitle (根据父级评论获取子评论)
* @ApiMethod (POST)
* @ApiRoute (/api/production/getTwoComment)
* @ApiParams (name="production_comment_id", type="integer", required=true, description="作品评论id")
* @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 ({
"code": 1,
"msg": "获取评论成功",
"time": "1608892708",
"data": [
{
"id": 2,
"production_id": "作品ID",
"user_id": "用户ID",
"content": "评论内容",
"pid": "父级id 注意:第一次返回的第一个数据是父级数据 第二次不会返回",
"zan_num": "点赞数量",
"createtime": "2020-12-25 17:53:07",
"updatetime": "2020-12-25 17:53:07",
"deletetime": null,
"message": null,
"is_zan": "是否点赞",
"is_this": "是不是自己发布的评论 1=是,0=不是",
"user": "用户信息 参考首页列表注释",
"str_time": "时间"
}
]
})
*/
public function getTwoComment(){
Db::startTrans();
try {
//1.获取作品id
$data= $this->get_data_array([
['production_comment_id','作品评论id不能为空'],
['page','分页次数不能为空'],
['num','分页数量不能为空']
]);
//2.发布评论
$father_production_comment = model('production_comment')
->with(['user'])
->where('id',$data['production_comment_id'])
->find();
if (!$father_production_comment){
$this->error('您的父级评论不存在');
}
//3.判断是不是第一次 如果是第一次添加进去父级评论
$array = [];
if ($data['page'] == 1){
$array[] = $father_production_comment;
}
//4.查询子级数据
$son_production_somment_array = model('production_comment')
->with(['user'])
->where('pid',$father_production_comment['id'])
->order('createtime','desc')
->page($data['page'],$data['num'])
->select();
foreach ($son_production_somment_array as $val){
$array[] = $val;
}
//5.循环查询是否点赞
foreach ($array as $key => $val){
//3.1 判断用户有没有点赞
$is_zan = model('production_comment_zan')
->where('user_id',$this->auth->id)
->where('production_comment_id',$val['id'])
->find();
$array[$key]['is_zan'] = 1;
if (!$is_zan){
$array[$key]['is_zan'] = 0;
}
//3.2判断是不是自己发布的评论
$array[$key]['is_this'] = 0;
if ($val['user_id'] == $this->auth->id){
$array[$key]['is_this'] = 1;
}
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
//3.发布成功
$this->success('获取评论成功',$array);
}
/**
* 作品评论点赞或取消点赞{注意}
* @ApiTitle (作品评论点赞或取消点赞{注意})
* @ApiMethod (POST)
* @ApiRoute (/api/production/setProductionCommentZan)
* @ApiParams (name="production_comment_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 setProductionCommentZan(){
//1.获取数据
$production_comment_id = $this->get_data('production_comment_id','作品评论id不能为空');
//2.查询作品数据
$production_comment = model('production_comment')->where('id',$production_comment_id)->find();
//3.查询点赞
$production_comment_zan = model('production_comment_zan')
->where('user_id',$this->auth->id)
->where('production_comment_id',$production_comment_id)
->find();
if ($production_comment_zan){
$production_comment_zan->delete();
$production_comment->zan_num -= 1;
$production_comment->save();
$this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
}
//4.增加点赞
model('production_comment_zan')->create(['user_id'=>$this->auth->id,'production_comment_id'=>$production_comment_id]);
//5.增加点赞数量
$production_comment->zan_num += 1;
$production_comment->save();
//6.返回结果
$this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
}
/**
* 举报作品
* @ApiTitle (举报作品)
* @ApiMethod (POST)
* @ApiRoute (/api/production/setProductionReport)
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
* @ApiParams (name="report_type_id", type="integer", required=true, description="举报类型ID")
* @ApiParams (name="content", 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": "1609236276",
"data": {
"production_id": "1",
"report_type_id": "1",
"content": "瓦达",
"user_id": 2,
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eo0mGhWdZVZMqyNCg4CWn7Xyplya5eEF1UUnFlOcF4vvZ9IibfWGocjiatViaP9b4JtosbuP9NibhlEWw/132",
"nickname": "珍惜自己的名字",
"username": "u2",
"mobile": "",
"status": 0,
"report_type_name": "违法违禁",
"createtime": "2020-12-29 18:04:36",
"updatetime": "2020-12-29 18:04:36",
"id": "2"
}
})
*/
public function setProductionReport(){
try {
//1.获取作品id
$data= $this->get_data_array([
['production_id','作品ID不能为空'],
['report_type_id','举报类型ID不能为空'],
['content','举报内容不能为空'],
]);
//2.查询举报内容
$production_report = model('production_report')
->where('user_id',$this->auth->id)
->where('production_id',$data['production_id'])
->where('report_type_id',$data['report_type_id'])
->where('status',0)
->find();
if ($production_report){
$this->error('您已经举报该作品,请等待管理员审核!');
}
//3.查询举报类型
$data['user_id'] = $this->auth->id;
$data['avatar'] = $this->auth->avatar;
$data['nickname'] = $this->auth->nickname;
$data['username'] = $this->auth->username;
$data['mobile'] = $this->auth->mobile;
$data['status'] = 0;
$data['report_type_name'] = model('report_type')->where('id',$data['report_type_id'])->find()['name']??'';
$res = model('production_report')->create($data);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
//3.发布成功
$this->success('举报成功',$res);
}
/**
* 举报评论
* @ApiTitle (举报评论)
* @ApiMethod (POST)
* @ApiRoute (/api/production/setProductionCommentReport)
* @ApiParams (name="production_comment_id", type="integer", required=true, description="评论id")
* @ApiParams (name="report_type_id", type="integer", required=true, description="举报类型ID")
* @ApiParams (name="content", 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 setProductionCommentReport(){
try {
//1.获取作品id
$data= $this->get_data_array([
['production_comment_id','评论ID不能为空'],
['report_type_id','举报类型ID不能为空'],
['content','举报内容不能为空'],
]);
//2.查询举报内容
$production_report = model('production_comment_report')
->where('user_id',$this->auth->id)
->where('production_comment_id',$data['production_comment_id'])
->where('report_type_id',$data['report_type_id'])
->where('status',0)
->find();
if ($production_report){
$this->error('您已经举报该评论,请等待管理员审核!');
}
//3.查询举报类型
$data['user_id'] = $this->auth->id;
$data['avatar'] = $this->auth->avatar;
$data['nickname'] = $this->auth->nickname;
$data['username'] = $this->auth->username;
$data['mobile'] = $this->auth->mobile;
$data['status'] = 0;
$data['report_type_name'] = model('report_type')->where('id',$data['report_type_id'])->find()['name']??'';
$res = model('production_comment_report')->create($data);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
//3.发布成功
$this->success('举报成功',$res);
}
/**
* 送给作品礼物
* @ApiTitle (送给作品礼物)
* @ApiMethod (POST)
* @ApiRoute (/api/production/giveGift)
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
* @ApiParams (name="gift_id", type="integer", required=true, description="礼物id")
* @ApiParams (name="price", type="integer", required=true, description="价格")
* @ApiParams (name="status", type="integer", required=true, description="是否是自定义价格:0=不是{需要填写gift_id},1=是{需要填写金额}")
* @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": "1608963789",
"data": ""
*/
public function giveGift(){
//1.获取数据
$data = $this->get_data_array([
['production_id','您的作品ID不能为空'],
['status','您的自定义价格字段不能为空']
]);
//2.查询作品
$production = model('production')->where('id',$data['production_id'])->find();
if (!$production)$this->error('您的作品不存在,请您检查production_id');
//3.判断不是自定义价格
if ($data['status'] == 0){
//3.1 查询礼物
$production_gift = model('gift')->where('id',$this->get_data('gift_id','礼物id不能为空'))->find();
if (!$production_gift)$this->error('未查询到相关礼物,请您检查gift_id');
//3.2 查询礼物订单
$is_order = model('production_gift_order')
->where('production_id',$production['id'])
->where('gift_id',$production_gift['id'])
->where('is_custom',0)
->where('status',0)
->where('price',$production_gift['price'])
->find();
if (!$is_order){
$a_data = [
'number'=>time()+rand(111111,999999),
'production_id'=>$production['id'],
'production_user_id'=>$production['user_id'],
'user_id'=>$this->auth->id,
'avatar'=>$this->auth->avatar,
'nickname'=>$this->auth->nickname,
'username'=>$this->auth->username,
'mobile'=>$this->auth->mobile,
'price'=>$production_gift['price'],
'status'=>0,
'is_custom'=>0,
'gift_id'=>$production_gift['id'],
'gift_name'=>$production_gift['name'],
];
$is_order = model('production_gift_order')->create($a_data);
}
}
//4.判断是自定义价格
if ($data['status'] == 1){
//4.1 查询礼物
$production_gift = $this->get_data('price','价格不能为空');
//4.2 查询礼物订单
$is_order = model('production_gift_order')
->where('production_id',$production['id'])
->where('is_custom',1)
->where('status',0)
->where('price',$production_gift['price'])
->find();
if (!$is_order){
$a_data = [
'number'=>time()+rand(111111,999999),
'production_id'=>$production['id'],
'production_user_id'=>$production['user_id'],
'user_id'=>$this->auth->id,
'avatar'=>$this->auth->avatar,
'nickname'=>$this->auth->nickname,
'username'=>$this->auth->username,
'mobile'=>$this->auth->mobile,
'price'=>$production_gift['price'],
'status'=>0,
'is_custom'=>0,
];
$is_order = model('production_gift_order')->create($a_data);
}
}
//------------ 支付 -------------
//5.获取配置信息
$config = config('EasyWeChat');
$app = Factory::payment($config);
//6.查询用户的第三方登录信息
$fa_third = Db::name('third')->where('user_id',$this->auth->id)->find();
if (!$fa_third)$this->error('第三方授权数据不存在');
//3.统一下单接口
$result = $app->order->unify([
'body' => '送出礼物',
'out_trade_no' => $is_order['number'],
//'total_fee' => $order['price'] * 100,
'total_fee' => 1,
'notify_url' =>this_url().'/api/production/setWechatGiftNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
'openid' => $fa_third['openid'],
]);
//4.判断返回结果
if ($result['result_code'] == 'SUCCESS' && $result['return_code'] == 'SUCCESS') {
$prepayId = $result['prepay_id'];
$jssdk = $app->jssdk;
$config = $jssdk->sdkConfig($prepayId);
$this->success('获取支付成功',$config);
} else {
$this->error('失败',$result);
}
$list = model('production_gift')->order('weigh','desc')->limit(7)->select();
//2.返回数据
$this->success('获取数据成功',$list);
}
/**
* 支付礼物回调
* @ApiMethod (POST)
* @ApiRoute (/api/production/setWechatGiftNotify)
* @ApiReturn ()
*/
public function setWechatNotify(){
$config = config('EasyWeChat');
$app = Factory::payment($config);
$response = $app->handlePaidNotify(function ($message, $fail) {
//将礼物进行支付
$order = model('production_gift_order')->where('number',$message['out_trade_no'])->find();
if (!$order)$fail('订单不存在');
if ($order['status'] == 1)$fail('您的订单已经支付');
$order->status = 1;
$order->save();
//查询用户和动态
$user = model('user')->where('id',$order['user_id'])->find();
$production = model('production')->where('id',$order['production_id'])->find();
//给礼物用户一个通知
if ($user){
$str = empty($order['gift_id'])?'自定义礼物':$order['gift_name'];
$message = [
'user_id'=>$order['production_user_id'],
'in_user_id'=>$user['id'],
'avatar'=>$user['avatar'],
'nickname'=>$user['nickname'],
'title'=>$production['title'],
'brief'=>'用户:'.$this->auth->nickname.' 送给您的作品一个:'.$str,
'status'=>3,
'is_stu'=>2,
'key_id'=>$production['id'],
];
model('message')->create($message);
}
});
$response->send(); // Laravel 里请使用:return $response;
}
}