<?php

namespace app\api\controller\tvuser;

use app\common\controller\Api;
use think\Db;
/**
 * 家庭乐园，使用自动注册的用户
 */
class Family extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    //图片，视频的列表
    public function lists(){
        $ids = Db::name('user')->where('tv_userid',$this->auth->tv_userid)->column('id');//自动注册的用户 和 app注册并绑定盒子的app用户,理论上只需要第二个

        $type = input('type',1);

        $list = Db::name('family')->where('user_id','IN',$ids)->where('type',$type)->order('id desc')->autopage()->select();
        if(!empty($list)){
            foreach($list as $key => &$val){
                $val['media_file'] = localpath_to_netpath($val['media_file']);

                if($val['type'] == 2){
                    $images_url = explode('.', $val['media_file']);
                    unset($images_url[count($images_url) - 1]);
                    $val['thumb_image'] = join('.', $images_url) . '_0.jpg';
                }else{
                    $val['thumb_image'] = $val['media_file'] . '?imageView2/1/w/100/h/100/q/85';
                }

            }
        }

        $this->success(1,$list);
    }


}
