Browse Source

发现页面-点赞处理

zhaoxinrui 6 years ago
parent
commit
e2a29ba1fd
3 changed files with 68 additions and 10 deletions
  1. 1 1
      app/Api/V1/Controllers/FindsController.php
  2. 65 8
      app/Models/VestPublish.php
  3. 2 1
      config/constants.php

+ 1 - 1
app/Api/V1/Controllers/FindsController.php

@@ -23,7 +23,7 @@ class FindsController extends BaseController
23 23
         //分页
24 24
         $page=$request->has('page')?$request->input('page'):1;
25 25
         //$page=2;//测试数据
26
-        $pageSize=2;
26
+        $pageSize=config('constants.PAGE_SIZE');
27 27
         $totalNum=count($publish_info);
28 28
         $pageInfo=$this->_PAGE($totalNum,$page,$pageSize);
29 29
         return $this->response->array(self::returnValue(['data'=>$publish_info,'pageInfo'=>$pageInfo], 200));

+ 65 - 8
app/Models/VestPublish.php

@@ -12,6 +12,7 @@ class VestPublish extends Model
12 12
     public $timestamps = false;
13 13
     public static function getFindsInfo()
14 14
     {
15
+        $http=config('constants.HOST_URL');
15 16
         $publish_info=DB::table('vest_publish')->where('status',1)->get();
16 17
         if (empty($publish_info)){
17 18
             return [];
@@ -22,33 +23,44 @@ class VestPublish extends Model
22 23
             if ($publish_info[0]['img_or_video']==2){
23 24
                 //视频个数
24 25
                 $publish_info[0]['counts']=1;
25
-                //$publish_infos[]=$publish_info[0];
26
+                //点赞
27
+                $datas=self::thumb_up();
28
+                $publish_info[0]['thumb_up_num']=$datas['thumb_up_num'];
29
+                $publish_info[0]['thumb_up_imgs']=$datas['thumb_up_imgs'];
26 30
             }else{
27 31
                 if (!empty($publish_info[0]['publish_info'])){
28 32
                     $allimgs=unserialize($publish_info[0]['publish_info']);
29 33
                     if (count($allimgs)==1){
30
-                        $http=config('constants.HOST_URL');
31 34
                         unset($publish_info[0]['publish_info']);
32 35
                         $publish_info[0]['publish_info'][]=$http.$allimgs[0];
33 36
                         //图集个数
34 37
                         $publish_info[0]['counts']=1;
35
-                        //$publish_infos[]=$publish_info[0];
38
+                        //点赞
39
+                        $datas=self::thumb_up();
40
+                        $publish_info[0]['thumb_up_num']=$datas['thumb_up_num'];
41
+                        $publish_info[0]['thumb_up_imgs']=$datas['thumb_up_imgs'];
36 42
                     }else{
37 43
                         unset($publish_info[0]['publish_info']);
38 44
                         $publish_info[0]['publish_info']=self::add_http($allimgs);
39 45
                         //图集个数
40 46
                         $publish_info[0]['counts']=count($publish_info[0]['publish_info']);
41
-                        //$publish_infos[]=$publish_info[0];
47
+                        //点赞
48
+                        $datas=self::thumb_up();
49
+                        $publish_info[0]['thumb_up_num']=$datas['thumb_up_num'];
50
+                        $publish_info[0]['thumb_up_imgs']=$datas['thumb_up_imgs'];
42 51
                     }
43 52
                 }
44 53
             }
45
-            //dd($publish_info);
46 54
         }else{
47 55
             foreach ($publish_info as $key=>$info){
48 56
                 //判断是图集还是视频
49 57
                 if ($info['img_or_video']==2){
50 58
                     //视频个数
51 59
                     $info['counts']=1;
60
+                    //点赞
61
+                    $datas=self::thumb_up();
62
+                    $info['thumb_up_num'] =$datas['thumb_up_num'];
63
+                    $info['thumb_up_imgs']=$datas['thumb_up_imgs'];
52 64
                     $publish_info[$key]=$info;
53 65
                 }else{
54 66
                     if (!empty($info['publish_info'])){
@@ -56,28 +68,34 @@ class VestPublish extends Model
56 68
                         if (count($allimgs)==1){
57 69
                             $http=config('constants.HOST_URL');
58 70
                             unset($info['publish_info']);
59
-                            //dd($info);
60 71
                             $info['publish_info'][]=$http.$allimgs[0];
61 72
                             //图集个数
62 73
                             $info['counts']=1;
74
+                            //点赞
75
+                            $datas=self::thumb_up();
76
+                            $info['thumb_up_num'] =$datas['thumb_up_num'];
77
+                            $info['thumb_up_imgs']=$datas['thumb_up_imgs'];
63 78
                             $publish_info[$key]=$info;
64 79
                         }else{
65 80
                             unset($info['publish_info']);
66 81
                             $info['publish_info']=self::add_http($allimgs);
67 82
                             //图集个数
68 83
                             $info['counts']=count($info['publish_info']);
84
+                            //点赞
85
+                            $datas=self::thumb_up();
86
+                            $info['thumb_up_num'] =$datas['thumb_up_num'];
87
+                            $info['thumb_up_imgs']=$datas['thumb_up_imgs'];
69 88
                             $publish_info[$key]=$info;
70 89
                         }
71 90
                     }
72 91
                 }
73 92
             }
74 93
         }
75
-
76 94
         return $publish_info;
77 95
     }
78 96
     /*
79 97
      * 拼接地址
80
-     * */
98
+     */
81 99
     public static function add_http($array){
82 100
         $http=config('constants.HOST_URL');
83 101
         $count = count($array);
@@ -86,4 +104,43 @@ class VestPublish extends Model
86 104
         }
87 105
         return $array;
88 106
     }
107
+    /*
108
+     * 点赞处理
109
+     */
110
+    public static function thumb_up(){
111
+        $http=config('constants.HOST_URL');
112
+        //左下角共显示多少张马甲头像
113
+        $vest_display_num=5;
114
+        //点赞数上限
115
+        $max_thumb_up_num=2000;
116
+
117
+        //已启用的马甲  头像数组
118
+        $vest_imgs=DB::table('vest')->where('status',1)->pluck('img');
119
+        $vest_imgs=json_decode($vest_imgs,true);
120
+        //随机生成图集点赞数
121
+        $thumb_up_num=mt_rand(0,$max_thumb_up_num);
122
+        //$thumb_up_num=0;//测试数据
123
+        //判断点赞数是否为空
124
+        if ($thumb_up_num==0){
125
+            $datas=array('thumb_up_num'=>$thumb_up_num,'thumb_up_imgs'=>[]);
126
+            return $datas;
127
+        }
128
+        if ($thumb_up_num<=$vest_display_num){
129
+            $thumb_up_imgs_keys=array_rand($vest_imgs,$thumb_up_num);
130
+            if($thumb_up_num==1){
131
+                $thumb_up_imgs[]=$http.$vest_imgs[$thumb_up_imgs_keys];
132
+            }else{
133
+                foreach($thumb_up_imgs_keys as $thumb_up_imgs_key){
134
+                    $thumb_up_imgs[]=$http.$vest_imgs[$thumb_up_imgs_key];
135
+                }
136
+            }
137
+        }else{
138
+            $thumb_up_imgs_keys=array_rand($vest_imgs,$vest_display_num);
139
+            foreach($thumb_up_imgs_keys as $thumb_up_imgs_key){
140
+                $thumb_up_imgs[]=$http.$vest_imgs[$thumb_up_imgs_key];
141
+            }
142
+        }
143
+        $datas=array('thumb_up_num'=>$thumb_up_num,'thumb_up_imgs'=>$thumb_up_imgs);
144
+        return $datas;
145
+    }
89 146
 }

+ 2 - 1
config/constants.php

@@ -3,5 +3,6 @@
3 3
 return [
4 4
    //'HOST_URL' => 'http://182.92.118.1:3320',//测试环境
5 5
     'HOST_URL' => 'http://www.menu.dev',//本地
6
-   'SMS_SECRET_KEY' => 'cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL',
6
+    'SMS_SECRET_KEY' => 'cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL',
7
+    'PAGE_SIZE' =>10,
7 8
 ];