102 lines
3.2 KiB
PHP
102 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use DateTime;
|
|
use think\Config;
|
|
use think\Controller;
|
|
use think\Db;
|
|
use think\exception\ErrorException;
|
|
use think\Request;
|
|
use think\Cache;
|
|
use app\api\controller\Upload;
|
|
|
|
header("Access-Control-Allow-Origin:*");
|
|
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
|
|
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
|
|
|
|
class System extends Common
|
|
{
|
|
public function getImgUrl()
|
|
{
|
|
$dataList = db('system_runtime')
|
|
->where('name', 'in', ['title','login_back', 'login_title', 'logo', 'logo_mini', 'favicon'])
|
|
->select();
|
|
for ($i = 0; $i < count($dataList); $i++) {
|
|
$dataList[$i]['value'] = $dataList[$i]['value'];
|
|
}
|
|
return $this->sendSuccess($dataList);
|
|
}
|
|
|
|
public function getImgUrlByName()
|
|
{
|
|
$param = request()->param();
|
|
$data = db('system_runtime')
|
|
->where('name', $param['name'])
|
|
->find();
|
|
return $this->sendSuccess($data['value']);
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
$title = db('system_runtime')
|
|
->where('name', 'title')
|
|
->find();
|
|
return $this->sendSuccess($title['value']);
|
|
}
|
|
|
|
public function updateTitle()
|
|
{
|
|
$param = request()->param();
|
|
$res = db('system_runtime')
|
|
->where('name', 'title')
|
|
->update($param);
|
|
if ($res) {
|
|
return $this->sendSuccess("更新Title成功");
|
|
} else {
|
|
return $this->sendError(400, "更新Title失败", "更新Title失败");
|
|
}
|
|
}
|
|
|
|
public function uploadImgUrlToDb()
|
|
{
|
|
$param = request()->param();
|
|
$msg = '';
|
|
$oldFile = db('system_runtime')
|
|
->where('name', $param['name'])
|
|
->find();
|
|
$res = db('system_runtime')
|
|
->where('name', $param['name'])
|
|
->update($param);
|
|
if ($res) {
|
|
$msg = "新图片更新成功";
|
|
try {
|
|
$resDelete = unlink(ROOT_PATH . 'public' . $oldFile['value']);
|
|
if (!$resDelete) {
|
|
$msg = "清理上次图标失败";
|
|
}
|
|
} catch (ErrorException $e) {
|
|
$msg = $e->getMessage();
|
|
}
|
|
|
|
if ($param['name'] == 'logo_mini') {
|
|
$oldIco = db('system_runtime')
|
|
->where('name', 'favicon')
|
|
->find();
|
|
try {
|
|
unlink(ROOT_PATH . 'public' . $oldIco['value']);
|
|
}catch (ErrorException $e){
|
|
$msg = $e->getMessage();
|
|
}
|
|
$upload = new Upload();
|
|
$res = $upload->icon($param['value']);
|
|
db('system_runtime')
|
|
->where('name', 'favicon')
|
|
->update(['value' => $res]);
|
|
}
|
|
return $this->sendSuccess($msg);
|
|
} else {
|
|
return $this->sendError(400, "更新" . $param['name'] . "图片失败", "更新" . $param['name'] . "图片失败");
|
|
}
|
|
}
|
|
} |