TaoLer/app/admin/controller/Set.php

136 lines
3.1 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;
2020-01-01 13:17:19 +08:00
class Set extends AdminController
{
protected function initialize()
{
parent::initialize();
2020-04-02 23:41:48 +08:00
}
//网站设置显示
public function index()
{
$mailserver = MailServer::find(1);
$sysInfo = Db::name('system')->find(1);
$syscy = $this->cyCheck($sysInfo['base_url'],$sysInfo['domain']);
2020-05-10 18:52:02 +08:00
$template = Files::getDirName('../view');
View::assign(['sysInfo'=>$sysInfo,'syscy'=>$syscy,'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::isAjax()){
$data = Request::param();
2020-01-08 17:37:41 +08:00
unset($data['file']);
//$system = System::find(1);
//$result = $system->allowField(['webname','webtitle','domain','keywords','descript','copyright','blackname'])->save($data);
2020-03-13 22:59:38 +08:00
$result = Db::name('system')->cache('system')->where('id', 1)->update($data);
2020-01-01 13:17:19 +08:00
if($result){
return json(['code'=>0,'msg'=>'更新成功']);
} else {
return json(['code'=>-1,'msg'=>'更新失败']);
}
}
}
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'=>'更新失败']);
}
}
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
//上传logo
public function upload()
{
$file = request()->file('file');
try {
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg'])
->check(array($file));
$savename = \think\facade\Filesystem::disk('public')->putFile('logo',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){
$name_path =str_replace('\\',"/",$upload.'/'.$savename);
$result = Db::name('system')->where('id', 1)->update(['logo'=>$name_path]);
if($result){
$res = ['code'=>0,'msg'=>'上传logo成功'];
} else {
$res = ['code'=>1,'msg'=>'上传错误'];
}
}
return json($res);
}
}