<?php
namespace app\store\controller;
use app\store\model\Setting as SettingModel;
use think\Db;
use think\Request;
class Setting extends Controller
{
public function store()
{
return $this->updateEvent('store');
}
public function Cloud()
{
$version = get_version();
$request = Request::instance();
$domain=$request->domain();
$ulr = "https://api.qycompany.cn/index.php?s=/api/api/run/m/tpwe_pc/do/cloud/uniacid/1";
$data = curlPost($ulr,array('version'=>$version['version'],'domain'=>$domain));
$list = json_decode($data,true);
$web_path = WEB_PATH;
$lists = array();
if (!$this->request->isAjax()) {
foreach ($list as $path=>$content){
$new_md5_file = md5_file($web_path.$path);
$filemtime = filemtime($web_path.$path);
if($new_md5_file!=$content['filemd5']){
$r_dir= substr(base_convert(fileperms($web_path.$path), 10, 8), 3);
$lists[$path]=array(
'content'=>$content,
'filemtime'=>date("Y-m-d H:i:s",$filemtime),
'r_dir'=>$r_dir
);
}
}
$version = get_version();
return $this->fetch('cloud', ['list' => $lists,'version'=>$version]);
}
foreach ($list as $path=>$content){
$new_md5_file = md5_file($web_path.$path);
if($new_md5_file!=$content['filemd5']){
if(file_exists($web_path.$path)){
$r_dir= substr(base_convert(fileperms($web_path.$path), 10, 8), 3);
if($r_dir==777){
file_put_contents($web_path.$path, base64_decode($content['content']));
}
}else{
$position = strrpos($web_path.$path,'/');
$paths = substr($web_path.$path,0,$position);
imkdirs($paths);
$fp=@fopen($web_path.$path,"a+");
@fputs($fp,base64_decode($content['content']));
@fclose($fp);
}
}
}
return $this->renderSuccess('升级成功');
}
public function trade()
{
return $this->updateEvent('trade');
}
public function sms()
{
return $this->updateEvent('sms');
}
public function tplMsg()
{
return $this->updateEvent('tplMsg');
}
public function storage()
{
return $this->updateEvent('storage');
}
private function updateEvent($key, $vars = [])
{
if (!$this->request->isAjax()) {
$vars['values'] = SettingModel::getItem($key);
$vars['modules'] = Db::name('modules')->where(array('type'=>6))->select();
return $this->fetch($key, $vars);
}
$model = new SettingModel;
if ($model->edit($key, $this->postData($key))) {
return $this->renderSuccess('操作成功');
}
return $this->renderError($model->getError() ?: '操作失败');
}
}