ctms/ctms-api/controllers/client/v1/ImageController.php
fm453 4b842ebf3d ADD:添加后台管理端接口;
DEL:删除不必要的头部注释;
FIX:修正若干已知错误;
2025-06-30 09:40:13 +08:00

88 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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);
}
}