123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace App\Models;
- use App\Models\Vest;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- class VestPublish extends Model
- {
- protected $table = 'vest_publish';
- public $timestamps = false;
- public static function getFindsInfo()
- {
- $http=config('constants.HOST_URL');
- $publish_info=DB::table('vest_publish')->where('status',1)->get();
- if (empty($publish_info)){
- return [];
- }
- $publish_info=json_decode($publish_info,true);
- if (count($publish_info)==1){
- //判断是图集还是视频
- if ($publish_info[0]['img_or_video']==2){
- //反串行化publish_info
- $publish_info[0]['publish_info']=unserialize($publish_info[0]['publish_info']);
- $publish_info[0]['publish_info'][0]=$http.$publish_info[0]['publish_info'][0];
- //马甲头像
- $publish_info[0]['img']=Vest::get_img_by_id($publish_info[0]['vest_id']);
- //视频个数
- $publish_info[0]['counts']=1;
- //点赞
- $datas=self::thumb_up($publish_info[0]['id']);
- $publish_info[0]['thumb_up_num']=$datas['thumb_up_num'];
- $publish_info[0]['thumb_up_imgs']=$datas['thumb_up_imgs'];
- }else{
- if (!empty($publish_info[0]['publish_info'])){
- $allimgs=unserialize($publish_info[0]['publish_info']);
- if (count($allimgs)==1){
- unset($publish_info[0]['publish_info']);
- $publish_info[0]['publish_info'][]=$http.$allimgs[0];
- //马甲头像
- $publish_info[0]['img']=Vest::get_img_by_id($publish_info[0]['vest_id']);
- //图集个数
- $publish_info[0]['counts']=1;
- //点赞
- $datas=self::thumb_up($publish_info[0]['id']);
- $publish_info[0]['thumb_up_num']=$datas['thumb_up_num'];
- $publish_info[0]['thumb_up_imgs']=$datas['thumb_up_imgs'];
- }else{
- unset($publish_info[0]['publish_info']);
- $publish_info[0]['publish_info']=self::add_http($allimgs);
- //马甲头像
- $publish_info[0]['img']=Vest::get_img_by_id($publish_info[0]['vest_id']);
- //图集个数
- $publish_info[0]['counts']=count($publish_info[0]['publish_info']);
- //点赞
- $datas=self::thumb_up($publish_info[0]['id']);
- $publish_info[0]['thumb_up_num']=$datas['thumb_up_num'];
- $publish_info[0]['thumb_up_imgs']=$datas['thumb_up_imgs'];
- }
- }
- }
- }else{
- foreach ($publish_info as $key=>$info){
- //判断是图集还是视频
- if ($info['img_or_video']==2){
- //反串行化publish_info
- $info['publish_info']=unserialize($info['publish_info']);
- $info['publish_info'][0]=$http.$info['publish_info'][0];
- //马甲头像
- $info['img']=Vest::get_img_by_id($info['vest_id']);
- //视频个数
- $info['counts']=1;
- //点赞
- $datas=self::thumb_up($info['id']);
- $info['thumb_up_num'] =$datas['thumb_up_num'];
- $info['thumb_up_imgs']=$datas['thumb_up_imgs'];
- $publish_info[$key]=$info;
- }else{
- if (!empty($info['publish_info'])){
- $allimgs=unserialize($info['publish_info']);
- if (count($allimgs)==1){
- $http=config('constants.HOST_URL');
- unset($info['publish_info']);
- $info['publish_info'][]=$http.$allimgs[0];
- //马甲头像
- $info['img']=Vest::get_img_by_id($info['vest_id']);
- //图集个数
- $info['counts']=1;
- //点赞
- $datas=self::thumb_up($info['id']);
- $info['thumb_up_num'] =$datas['thumb_up_num'];
- $info['thumb_up_imgs']=$datas['thumb_up_imgs'];
- $publish_info[$key]=$info;
- }else{
- unset($info['publish_info']);
- $info['publish_info']=self::add_http($allimgs);
- //马甲头像
- $info['img']=Vest::get_img_by_id($info['vest_id']);
- //图集个数
- $info['counts']=count($info['publish_info']);
- //点赞
- $datas=self::thumb_up($info['id']);
- $info['thumb_up_num'] =$datas['thumb_up_num'];
- $info['thumb_up_imgs']=$datas['thumb_up_imgs'];
- $publish_info[$key]=$info;
- }
- }
- }
- }
- }
- return $publish_info;
- }
- /*
- * 拼接地址
- */
- public static function add_http($array){
- $http=config('constants.HOST_URL');
- $count = count($array);
- for($i=0;$i<$count;$i++){
- $array[$i] = $http. $array[$i];
- }
- return $array;
- }
- /*
- * 点赞处理
- */
- public static function thumb_up($vest_id){
- $http=config('constants.HOST_URL');
- //左下角共显示多少张马甲头像
- $vest_display_num=5;
- //点赞数上限
- $max_thumb_up_num=2000;
- //已启用的马甲 头像数组
- $vest_imgs=DB::table('vest')->where('status',1)->pluck('img');
- // $user_list=DB::table('collect_vest_publish')->where('status',1)->where('vest_publish_id',$vest_id)->pluck('user_id');
- $user_num=DB::table('collect_vest_publish')->where('status',1)->where('vest_publish_id',$vest_id)->count();
- // $user_img=DB::table('users')->whereIn('id',$user_list)->pluck('headimgurl');
- // $user_img=json_decode(json_encode($user_img),true);
- // $user_img=array_filter($user_img);
- $vest_imgs=json_decode($vest_imgs,true);
- // $vest_imgs=array_merge($user_img,$vest_imgs);
- //随机生成图集点赞数
- $thumb_up_num=intval(abs(crc32($vest_id)/1000000))+($vest_id%3*100)+($vest_id%5*10)+($vest_id%7)+$user_num;
- //$thumb_up_num=0;//测试数据
- //判断点赞数是否为空
- if ($thumb_up_num==0){
- $datas=array('thumb_up_num'=>$thumb_up_num,'thumb_up_imgs'=>[]);
- return $datas;
- }
- if ($thumb_up_num<=$vest_display_num){
- $thumb_up_imgs_keys=array_rand($vest_imgs,$thumb_up_num);
- if($thumb_up_num==1){
- $thumb_up_imgs[]=$http.$vest_imgs[$thumb_up_imgs_keys];
- }else{
- foreach($thumb_up_imgs_keys as $thumb_up_imgs_key){
- $thumb_up_imgs[]=$http.$vest_imgs[$thumb_up_imgs_key];
- }
- }
- }else{
- $thumb_up_imgs_keys=array_rand($vest_imgs,$vest_display_num);
- foreach($thumb_up_imgs_keys as $thumb_up_imgs_key){
- $thumb_up_imgs[]=$http.$vest_imgs[$thumb_up_imgs_key];
- }
- }
- $datas=array('thumb_up_num'=>$thumb_up_num,'thumb_up_imgs'=>$thumb_up_imgs);
- return $datas;
- }
- }
|