<?php
declare (strict_types = 1);

namespace app\model\system;

use library\basic\BaseModel;
use library\traits\JwtAuthModelTrait;
use library\traits\ModelTrait;
use think\Model;

/**
 * @mixin \think\Model
 */
class Platform  extends BaseModel
{
    use ModelTrait;
    use JwtAuthModelTrait;
    private $platformData;

    /**
     * 根据id查询平台
     * @param $id
     * @param string $field
     * @return mixed
     */
     public function getPlatformId($id,$field = '*') {
         $this->getPlatformData();
         if(!empty($this->platformData)) {
             foreach ($this->platformData as $v) {
                 if ($v['id'] == $id) {
                     return $field == '*' ? $v : $v[$field];
                 }
             }
         }
         return null;
     }

    /**
     * 平台数据
     * @return mixed|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getPlatformData(){
        if(empty($this->platformData))
            $this->platformData = $this->order("seq desc")->select();
        return $this->platformData;
    }
}
