apeblog/app/common/model/Attachment.php

53 lines
1.3 KiB
PHP

<?php
namespace app\common\model;
/**
* Class attachment
* @package app\admin\model\widget
*/
class Attachment extends BaseModel
{
/**
* @param int $cid
* @param string $name
* @param string $path
* @param string $type
* @param string $mime
* @param float $size
* @param int $storage
* @return int|string
*/
public static function addAttachment(int $cid, string $name, string $path, string $type, string $mime, float $size, int $storage)
{
$data = [
'cid' => $cid,
'name' => $name,
'path' => $path,
'type' => $type,
'mime' => $mime,
'size' => $size,
'storage' => $storage,
];
return self::create($data);
}
/**
* 分页显示
* @param array $where
* @return array
*/
public static function pagination(array $where)
{
$model = self::where("type", $where['type']);
if ($where['cid'] != "") $model = $model->where("cid", $where['cid']);
$count = self::count();
$model = $model->order("id desc");
$model = $model->field("id,path");
$data = $model->page((int)$where['page'], (int)$where['limit'])->select();
if ($data) $data = $data->toArray();
return compact("data", "count");
}
}