TaoLer/app/admin/controller/Set.php

114 lines
2.6 KiB
PHP
Raw Normal View History

2020-01-01 13:17:19 +08:00
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\admin\model\System;
use app\admin\model\MailServer;
use think\facade\Config;
use think\exception\ValidateException;
2020-05-10 18:52:02 +08:00
use taoler\com\Files;
2020-05-22 21:10:01 +08:00
use taoler\com\Api;
2021-07-22 10:54:03 +08:00
use app\common\lib\SetConf;
2020-01-01 13:17:19 +08:00
class Set extends AdminController
{
protected function initialize()
{
parent::initialize();
2021-07-07 17:40:43 +08:00
$this->sysInfo = $this->getSystem();
2020-04-02 23:41:48 +08:00
}
//网站设置显示
public function index()
{
$mailserver = MailServer::find(1);
2020-05-10 18:52:02 +08:00
$template = Files::getDirName('../view');
2021-07-16 17:42:07 +08:00
View::assign(['sysInfo'=>$this->sysInfo,'mailserver'=>$mailserver,'template'=>$template]);
2020-04-02 23:41:48 +08:00
return View::fetch('set/system/website');
2020-01-01 13:17:19 +08:00
}
2020-04-02 23:41:48 +08:00
//网站设置
2020-01-01 13:17:19 +08:00
public function website()
{
if(Request::isPost()){
2021-07-16 17:42:07 +08:00
$data = Request::only(['webname','domain','template','cache','upsize','uptype','blackname','webtitle','keywords','descript','icp','showlist','copyright']);
2021-07-07 17:40:43 +08:00
$system = new System();
2021-07-16 17:42:07 +08:00
$result = $system->sets($data,$this->sysInfo['clevel']);
2021-07-07 17:40:43 +08:00
if($result == 1){
2020-01-01 13:17:19 +08:00
return json(['code'=>0,'msg'=>'更新成功']);
} else {
2021-07-07 17:40:43 +08:00
return json(['code'=>-1,'msg'=>$result]);
2020-01-01 13:17:19 +08:00
}
}
}
2020-03-29 19:57:18 +08:00
//综合设置
public function server()
{
2020-04-02 23:41:48 +08:00
return View::fetch('set/system/server');
2020-03-29 19:57:18 +08:00
}
2020-01-01 13:17:19 +08:00
2020-03-29 19:57:18 +08:00
/**邮箱设置
* parem $id
2020-01-01 13:17:19 +08:00
*/
public function email()
{
$mailserver = MailServer::find(1);
//邮箱配置
if(Request::isAjax()){
2020-04-02 23:41:48 +08:00
$data = Request::only(['host','port','mail','nickname','password']);
2020-01-01 13:17:19 +08:00
$res = $mailserver->save($data);
if($res){
return json(['code'=>0,'msg'=>'更新成功']);
} else {
return json(['code'=>-1,'msg'=>'更新失败']);
}
}
}
2021-07-22 10:54:03 +08:00
/**配置设置
* parem $id
*/
public function config()
{
$conf = Config::get('taoler.config');
if(Request::isPost()){
$data = Request::param();
foreach($conf as $c=>$f){
if(array_key_exists($c,$data)){
$conf[$c] = (int) $data[$c];
}else{
$conf[$c] = 0;
}
}
$setConf = new SetConf;
$value = [
'config'=>$conf
];
$upRes = $setConf->setConfig('taoler',$value);
return $upRes;
}
}
2020-01-01 13:17:19 +08:00
//上传logo
public function upload()
{
$uploads = new \app\common\lib\Uploads();
$upRes = $uploads->put('file','logo',2000,'image','uniqid');
$logoJson = $upRes->getData();
if($logoJson['status'] == 0){
$result = Db::name('system')->where('id', 1)->update(['logo'=>$logoJson['url']]);
2020-01-01 13:17:19 +08:00
if($result){
$res = ['code'=>0,'msg'=>'上传logo成功'];
} else {
$res = ['code'=>1,'msg'=>'上传错误'];
}
}
return json($res);
}
}