📖 File Reader
<?php
namespace app\api\controller;
use app\api\common\Common_config;
use app\BaseController;
use app\api\common\Common_user;
use think\facade\Db;
use think\facade\View;
class Ad extends BaseController
{
protected $page = 1;//默认页数
protected $limit = 20;//默认条数
// 初始化
protected function initialize()
{
$this->page = input('page')?:$this->page;
$this->limit = input('limit')?:$this->limit;
}
/*广告数据*/
public function ad_list()
{
$act_id = input("param.act_id");
if (empty($act_id)){
return $this->error_json("请输入所属类型");
}
$list = db::name("ad")->where("act_id = $act_id and is_show = 1")->order("sort desc")->page($this->page,$this->limit)->select()->toArray();
foreach ($list as $k => $v){
$list[$k]["add_time"] = date("Y-m-d H:i",$v["add_time"]);
}
/*分页数据*/
$count = db::name("ad")->where("act_id = $act_id and is_show = 1")->order("sort desc")->count();
$vue_page = $this->vue_pages($count,$this->limit);
$data = [
'list'=>$list,
'pages'=>$vue_page,
];
return $this->succeed_json("ok",$data);
}
/*广告分类*/
public function ad_act_list()
{
$list = db::name("ad_act")->where("is_show = 1 and is_system = 0")->field("id,name")->order("sort desc")->select()->toArray();
$data = [
'list'=>$list,
];
return $this->succeed_json("ok",$data);
}
/*幻灯片*/
public function lantern_slide()
{
$act_id = input("param.act_id");
$where = 1;
if (!empty($act_id)){
$where .= " and act_id = $act_id";
}
$list = db::name("ad")->where("is_show = 1 and $where")->order("sort desc")->select()->toarray();
$str1 = '';
$str2 = '';
foreach ($list as $k => $v){
$count = $k+1;
if ($k == 0){
$str1 .= '<li class="on">
<font style="vertical-align: inherit;">
<font style="vertical-align: inherit;">'.$count.'</font>
</font>
</li>';
$str2 .= '<li style="display: list-item;"><a href="javascript:;">
<img src="'.$v["img"].'"></a>
</li>';
}else{
$str1 .= '<li class="">
<font style="vertical-align: inherit;">
<font style="vertical-align: inherit;">'.$count.'</font>
</font>
</li>';
$str2 .= '<li style="display: none;"><a href="javascript:;">
<img src="'.$v["img"].'"></a>
</li>';
}
}
$data = [
'str1'=>htmlspecialchars_decode($str1),
'str2'=>htmlspecialchars_decode($str2),
];
return $this->succeed_json("ok",$data);
}
/*上传处理*/
public function file_upload()
{
$type = input("param.type");//是否带域名:1是 0否
$url = '';
if ($type == 1){
$config = Common_config::config("'url'");
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$url = $config["url"] != ''?$config["url"]:$http_type . $_SERVER['HTTP_HOST'];
}
if (!empty($_FILES["imageData"])){
$url .= '/public/uploads/'.$this->upload('imageData');
}else if(!empty($_FILES["videoData"])){
$url .= '/public/uploads/'.$this->upload('videoData');
}
return $this->succeed_json("ok",$url);
}
}