88 lines
3.0 KiB
PHP
88 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace api\controllers\client\v1;
|
|
|
|
use Yii;
|
|
use yii\data\Pagination;
|
|
use yii\web\UploadedFile;
|
|
use yii\helpers\Url;
|
|
use common\models\CAttachment;
|
|
|
|
class ImageController extends Common
|
|
{
|
|
public function beforeAction($action)
|
|
{
|
|
if (!$this->pid) {
|
|
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
|
}
|
|
return parent::beforeAction($action);
|
|
}
|
|
|
|
public function actionIndex()
|
|
{
|
|
$apis = [
|
|
'list'=>'图片列表',
|
|
];
|
|
$this->result('您正使用CMTS-CLIENT图库管理接口!', $apis, 200);
|
|
}
|
|
|
|
public function actionList()
|
|
{
|
|
$siteId =$this->site_id;
|
|
$pid = $this->pid;
|
|
$model = new CAttachment();
|
|
$search = $where = [];
|
|
$where[] = 'and';
|
|
$where[] = ['=','status_code',1];
|
|
$where[] = ['=','type',0];
|
|
$where[] = ['=','siteid',$siteId];
|
|
$where[] = ['=','pid',$pid];
|
|
$post = $this->postdata;
|
|
|
|
$search = $post['search'];
|
|
if ($search) {
|
|
if ($search['create_m']) {
|
|
$start = strtotime($search['create_m']);
|
|
$s = date("Y-m-d H:i:s", $start);
|
|
$ldm = strtotime("last day of ".$s);
|
|
$m = date("Y-m-d", $ldm)." 23:59:59";
|
|
$end = strtotime($m);
|
|
$where[] = ['between','create_at',$start,$end];
|
|
} elseif (!empty($search['create_after']) && !empty($search['create_before'])) {
|
|
$start = strtotime($search['create_after']);
|
|
$end = strtotime($search['create_before']);
|
|
$where[] = ['between','create_at',$start,$end];
|
|
} elseif (!empty($search['create_after'])) {
|
|
$start = strtotime($search['create_after']);
|
|
$where[] = ['>=','create_at',$start];
|
|
} elseif (!empty($search['create_before'])) {
|
|
$end = strtotime($search['create_before']);
|
|
$where[] = ['<=','create_at',$end];
|
|
}
|
|
if ($search['title']) {
|
|
$where[] = ['LIKE','title',$search['title']];
|
|
}
|
|
}
|
|
//分页
|
|
$orderby = ['id' => SORT_DESC];
|
|
$Attachment = new CAttachment();
|
|
$list = $Attachment->getData($model, $where, $orderby);
|
|
$pager = $Attachment->getPagination();
|
|
|
|
//附件网址前缀
|
|
$src = Url::base(true)."/../../upload"; //在网站根目录下使用upload/pics目录;适合使用yii框架主目录入口而非绑定子域名的情形
|
|
if ($_SERVER['DOCUMENT_ROOT'].'/upload' != Yii::getAlias("@upload")) {
|
|
// $src = Url::toRoute(['attach/index','img'=>'']); //换用网络加载转换的方式-反应慢
|
|
$src = Yii::$app->params['attachSrc'].Yii::$app->params['attachDir'];
|
|
}
|
|
|
|
$callback = $_GET['callback'] ?? 'thumb';
|
|
$data = [
|
|
'list'=>$list,
|
|
'pager' => $pager,
|
|
'src'=>$src,
|
|
'callback'=>$callback
|
|
];
|
|
$this->result('', $data, 200);
|
|
}
|
|
} |