<?php
/**
 * JYmusic音乐管理系统 - [幻灯片模型]
 *
 * @version   2.0
 * @author    战神~~巴蒂 [jyuucn@163.com]
 * @license   license: http://jyuu.cn
 * @copyright JYmusic 2014 - 2017
 */
namespace addons\Links\model;

use think\Model;

/**
 * 友情链接模型
 */
class Links extends Model
{
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;
    
    public $fields = [
        [
            'name'  => 'title',
            'title' => '站点名称',
            'type'  => 'text',
        ],
        [
            'name'  => 'link',
            'title' => '链接地址',
            'type'  => 'long_text',
            'remark' => ''
        ],
        [
            'name'  => 'cover_url',
            'title' => '站点logo',
            'type'  => 'image',
            'remark' => '可以为空，也可填写外链地址,'
        ],
        [
            'name'  => 'level',
            'title' => '优先级',
            'type'  => 'num',
            'remark' => '优先级越高排序越往前'
        ]
    ];
    
    protected function getStatusTextAttr($value, $data)
    {
        $status = [-1 => '删除', 0 => '禁用', 1 => '正常'];
        return $status[$data['status']];
    }

    /*展示数据*/
    public function getList($limit = 10, $type = 1)
    {
        $data = $this->where('status = 1')
            ->where('status', 1)
            ->where('type', $type)
            ->field('create_time,status', true)
            ->cache('links_lists_' . $type, 86400, 'limit_cache')
            ->limit($limit)
            ->order('level desc,id desc')
            ->select();
        return $data;
    }
}
