<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class ResourceModel extends Model
{
    protected $connection=false;
    protected $table='resource';
    public $timestamps = false;

    public function GetResourceInfoById($resourceId, $Redis=''){
        if(empty($resourceId)) return false;
        if(empty($Redis)) $Redis=new RedisModel();
        $data=json_decode($Redis->hget('Self_SelfGoodsSource',$resourceId),true);
        if(!empty($data['url'])) return $data['url'];

        //需要更新redis
        if(empty($this->connection)) $this->connection='self';
        $data = $this->where('id', '=', $resourceId)->select('url')->first();
        if(!$data) return false;
        $data=$data->toArray();
        $Redis->hset('Self_SelfGoodsSource',$resourceId,json_encode($data));
        return $data['url'];
    }
}