1. 程式人生 > 其它 >齊博x1伺服器效能太差,調整系統升級每次校驗的檔案數

齊博x1伺服器效能太差,調整系統升級每次校驗的檔案數

系統升級需要校驗本地的檔案是否被修改過,系統預設每次檢驗1千個檔案,一般來說需要分四到五頁來處理,如下圖所示。

如果你的伺服器效能太差的話,就需要手工把數值調小。把下面的程式碼複製出來。進入後臺資料庫管理工具那裡執行一下,匯入資料庫。然後就可以在後臺核心設定那裡修改數值

INSERT INTO `qb_config` (`id`, `type`, `title`, `c_key`, `c_value`, `form_type`, `options`, `ifsys`, `htmlcode`, `c_descrip`, `list`, `sys_id`) VALUES(0, 1, '系統升級每次核對檔案數', 'sys_update_filenum', '10', 'number', '', 1, '', '留空則預設是1000,如果你的空間效能太差,就手工調為50甚至10', 0, 0);

匯入資料庫後,需要在下面那裡做設定,如下圖

把數值相應調小,測試看看能否正常升級。

複製下面的程式碼修改兩個檔案後,將會實現如下圖的效果.

要實現分頁檢驗檔案的話,需要修改兩個檔案.

複製下面的程式碼替換\application\admin\controller\Upgrade.php中的內容

<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\common\model\Module;
use app\common\model\Plugin;
use app\common\model\Hook_plugin;
use app\common\model\Market as MarketModel;
use app\common\model\Timedtask AS TaskModel;

class Upgrade extends AdminBase
{
    public function _initialize(){
        parent::_initialize();
        if(config('client_upgrade_edition')==''){
            config('client_upgrade_edition',RUNTIME_PATH . '/client_upgrade_edition.php');
        }
    }
    
    public function index()
    {
        $this->clean_cache();
        $array = @include(config('client_upgrade_edition'));
        $this->assign('upgrade',$array);
        return $this->fetch('index');
    }
    
    /**
     * 清除相關快取
     */
    protected function clean_cache(){
        cache('timed_task',null);
        cache('cache_modules_config',null);
        cache('cache_plugins_config',null);
        cache('hook_plugins',null);
    }
    
    /**
     * 更新升級日誌
     * @param string $upgrade_edition
     * @return boolean|string
     */
    private function writelog($upgrade_edition=''){
        $data = $this->request->post();
        if($data['m']){
            $array = modules_config();
            foreach ($array AS $rs){
                $de = $data['m'][$rs['keywords']];
                if($de){
                    $vs = $de['time']."\t".$de['md5'];
                    Module::update(['id'=>$rs['id'],'version'=>$vs]);
                }
            }
        }
        if($data['p']){
            $array = plugins_config();
            foreach ($array AS $rs){
                $de = $data['p'][$rs['keywords']];
                if($de){
                    $vs = $de['time']."\t".$de['md5'];
                    Plugin::update(['id'=>$rs['id'],'version'=>$vs]);
                }
            }
        }
        if($data['h']){
            $array = cache('hook_plugins');
            foreach ($array AS $rs){
                $de = $data['h'][$rs['version_id']];
                if($de){
                    $vs = $de['time']."\t".$de['md5'];
                    Hook_plugin::update(['id'=>$rs['id'],'version'=>$vs]);
                }
            }
        }
        if($data['t']){
            $array = cache('timed_task');
            foreach ($array AS $rs){
                $de = $data['t'][$rs['version_id']];
                if($de){
                    $vs = $de['time']."\t".$de['md5'];
                    TaskModel::update(['id'=>$rs['id'],'version'=>$vs]);
                }
            }
        }
        $this->upgrade_mark($data['admin_style'],'admin_style');
        $this->upgrade_mark($data['index_style'],'index_style');
        $this->upgrade_mark($data['member_style'],'member_style');
        $this->upgrade_mark($data['qun_style'],'qun_style');
        $this->upgrade_mark($data['haibao_style'],'haibao_style');
        $this->upgrade_mark($data['model_style'],'model_style');
        $this->upgrade_mark($data['packet'],'packet');
        
        $this->clean_cache();
        if( file_put_contents(config('client_upgrade_edition'), '<?php return ["md5"=>"'.$upgrade_edition.'","time"=>"'.date('Y-m-d H:i').'",];') ){
            return true;
        }else{
            return '許可權不足,日誌寫入失敗';
        }
    }
    
    /**
     * 應用市場,比如風格更新升級日誌
     * @param array $data
     * @param string $type 比如admin_style index_style member_style
     */
    private function upgrade_mark($data=[],$type=''){
        if($data){
            $array = MarketModel::get_list(['type'=>$type]);
            foreach ($array AS $rs){
                $de = $data[$rs['version_id']];
                if($de){
                    $vs = $de['time']."\t".$de['md5'];
                    MarketModel::update(['id'=>$rs['id'],'version'=>$vs]);
                }
            }
        }
    }
    
    /**
     * 更新前,先備份一下檔案
     * @param string $filename
     */
    private function bakfile($filename=''){
        $bakpath = RUNTIME_PATH.'bakfile/';
        if(!is_dir($bakpath)){
            mkdir($bakpath);
        }
        $new_name = $bakpath.date('Y_m_d-H_i--').str_replace(['/','\\'], '--', $filename);
        copy(ROOT_PATH.$filename,$new_name);
    }
    
    /**
     * 升級資料庫
     * @param string $filename
     */
    private function up_sql($filename=''){
        if(preg_match('/\/upgrade\/([\w]+)\.sql$/', $filename)){
            //if(preg_match('/^\/application\/common\/upgrade\/([\w]+)\.sql/', $filename)){
            into_sql(ROOT_PATH.$filename,true,0);
        }
    }
    
    /**
     * 執行更多複雜的邏輯性的升級
     * @param string $filename
     */
    private function up_run($filename=''){
        if(preg_match('/^\/application\/common\/upgrade\/([\w]+)\.php$/', $filename)){
            $classname = "app\\common\\upgrade\\".ucfirst(substr(basename($filename), 0,-4));
        }elseif(  preg_match('/(application|plugins)\/([\w]+)\/upgrade\/([\w]+)\.php$/',$filename,$array) ){     //實際已包含了上面的
            $m_p = $array[1]=='application'?'app':'plugins';
            $model = $array[2];
            $file = $array[3];
            $classname = "$m_p\\$model\\upgrade\\".ucfirst($file);
        }else{
            return;
        }
        if( class_exists($classname) && method_exists($classname, 'up') ){
            $obj = new $classname;
            try {
                $obj->up();
            } catch(\Exception $e) {
                //echo $e;
            }
        }
    }
    
    
    /**
     * 正式執行開始升級,一個一個的檔案升級替換
     */
    public function sysup($filename='',$upgrade_edition=''){
        if($upgrade_edition){  //升級完畢,寫入升級資訊日誌
            $result = $this->writelog($upgrade_edition);
            if( $result===true ){
                return $this->ok_js([],'升級成功');
            }else{
                return $this->err_js($result);
            }
        }
        list($filename,$id) = explode(',',$filename);
        if($filename==''){
            return $this->err_js('檔案不存在!');
        }
        
        $str = $this->get_server_file($filename,$id);
        if($str){
            $filename = $this->format_filename($filename); //針對模組或外掛的升級做替換處理
            $this->bakfile($filename);
            makepath(dirname(ROOT_PATH.$filename));    //檢查並生成目錄
            if( file_put_contents(ROOT_PATH.$filename, $str) ){
                $this->up_sql($filename);
                $this->up_run($filename);
                return $this->ok_js([],'檔案升級成功');
            }else{
                return $this->err_js('目錄許可權不足,檔案寫入失敗');
            }
        }else{
            return $this->err_js('獲取雲端資料失敗,請確認伺服器DNS是否正常,能否訪問外網?');
        }
    }
    
    /**
     * 升級前,可以檢視任何一個檔案的原始碼
     * @param string $filename
     */
    public function view_file($filename='',$id=0,$oldfile=''){
        
        $str = $this->get_server_file($filename,$id);
        
        if ( preg_match("/(\.jpg|\.png|\.jpeg|\.gif)$/i", $filename) ) {
            //header('Content-type:image/'.substr($filename,strripos($filename,'.')+1));echo $str;
            if (is_file(ROOT_PATH.$oldfile)) {
                echo "<img style='max-width:200px;' src='".request()->domain().'/'.$oldfile."'><br>";
            }
            $temp_file = "uploads/images/temp.".substr($filename,strripos($filename,'.')+1);
            file_put_contents(PUBLIC_PATH.$temp_file, $str);
            echo "<br><br><img style='max-width:200px;' src='".tempdir($temp_file)."?".time()."'>";
            exit;
        }
        
        $this->assign('new_code',str_replace(['<','>'], ['&lt;','&gt;'], $str));
        $this->assign('old_code', str_replace(['<','>'], ['&lt;','&gt;'], file_get_contents(str_replace('//', '/', ROOT_PATH.$oldfile)) ) );
        
        return $this->fetch();
    }
    
    /**
     * 針對要升級的模組與外掛的檔名特別處理, 替換後,// 雙斜槓開頭的檔案就是外掛或模組升級的檔案
     * @param string $filename
     * @return string|mixed
     */
    protected function format_filename($filename=''){
        if(strstr($filename,'/../../')){
            $filename = str_replace(['/../../template/','/../../plugin/','/../../hook/'], '/../../', $filename);
            $filename = preg_replace('/^\/..\/..\/([\w]+)/','/',$filename);
        }
        return $filename;
    }
    
    /**
     * 核對需要升級檔案,展示出來給使用者挑選哪些不想升級
     * 這裡的升級檔案列表,即有系統的,也有頻道外掛與風格的
     * @param string $upgrade_edition
     * @param string $page 分頁檢驗需要升級的檔案.一次處理的話,有的伺服器可能吃不消
     * @return string|mixed
     */
    public function check_files($upgrade_edition='',$page=0,$rows=1000){
        if ($this->webdb['sys_update_filenum']>0) {
            $rows = $this->webdb['sys_update_filenum'];
        }
        set_time_limit(0); //防止超時
        $array = $this->getfile($page);
        if(empty($array)){
            $str = http_curl("https://x1.php168.com/appstore/upgrade/get_version.html?id=46");
            if (!strstr($str,'md5')) {
                return $this->err_js('你的伺服器無法訪問齊博官網,請檢查你的伺服器DNS是否配置正確,或者是否設定了防火牆不能訪問外網');
            }
            return $this->err_js('獲取雲端檔案列表資料失敗,請晚點再償試');
        }
        $totalpage = ceil(count($array)/$rows);
        if (!$page) {
            set_cookie('need_update',0);
            return $this->ok_js($totalpage);
        }
        $data = [];
        $min = ($page-1)*$rows;
        for($i=$min;$i<$min+$rows;$i++){
            $rs = $array[$i];
            if (!$rs) {
                break;
            }
//         }
//         foreach($array AS $rs){
            $showfile = $this->format_filename($rs['file']);
            $file = ROOT_PATH.$showfile;
            if (is_file($file.'.lock') && file_get_contents($file.'.lock')=='hide') {
                continue;   //使用者不想升級的檔案,也不想提示升級
            }
            $ispic = false;
            $change = false;
            $md5_size = '';
            if (!is_file($file)) {
                $change = true;
            }elseif( ($md5_size=md5_file($file)) != $rs['md5'] ){
                $change = true;
                if ( preg_match("/(\.jpg|\.png|\.jpeg|\.gif)$/i", $file) ) {
                    $ispic = true;
                }elseif ( check_bom($file,true) ) {
                    file_put_contents($file, check_bom($file));
                    if (md5_file($file)==$rs['md5']) {
                        $change = false;
                    }//elseif(preg_match("/(\/|\\\)upgrade(\/|\\\)([\w]+)(\.sql|\.php)$/i", $file)){
                    //$change = false;
                    //}
                }
            }
            if($change){                
                $data[]=[
                    'file'=>$rs['file'],
                    'showfile'=>$showfile,
                    'md5'=>$md5_size,
                    'id'=>$rs['id'],
                    'islock'=>(is_file($file.'.lock')||(is_file($file)&&preg_match("/(\/|\\\)upgrade(\/|\\\)([\w]+)(\.sql|\.php)$/i", $file)))?1:0,
                    'ctime'=>is_file($file)?date('Y-m-d H:i',filemtime($file)):'缺失的檔案',
                    'time'=>date('Y-m-d H:i',$rs['time']),
                ];
            }
        }
        
        $array_sql = $array_php = [];
        foreach ($data AS $key=>$rs){
            if( preg_match("/\/upgrade\/([\w]+\.sql)/i",$rs['file']) ){
                unset($data[$key]);
                $array_sql[$rs['file']] = $rs;
            }elseif( preg_match("/\/upgrade\/([\w]+\.php)/i",$rs['file']) ){
                unset($data[$key]);
                $array_php[$rs['file']] = $rs;
            }
        }
        ksort($array_php);
        ksort($array_sql);
        $data = array_values(array_merge($data,$array_sql,$array_php));
        $need_update = get_cookie('need_update')+count($data);
        set_cookie('need_update',$need_update);
        
        if ($page==$totalpage) {
            unlink(RUNTIME_PATH.'updatelist.txt');
        }
        if($page==$totalpage && $need_update<1){
            $upgrade_edition && $reustl = $this->writelog($upgrade_edition);
            return $this->err_js($reustl!==true?$reustl:'沒有可更新檔案');
        }else{
            return $this->ok_js($data?:[]);
        }
    }
    
    /**
     * 獲取雲端的某個最新檔案
     * @param string $filename 升級的檔名
     * @param number $id 對應雲端的外掛ID
     * @return string|mixed
     */
    protected function get_server_file($filename='',$id=0){
        @set_time_limit(600);  //防止超時
        $str = http_curl('https://x1.php168.com/appstore/upgrade/make_client_file.html?filename='.$filename.'&id='.$id.'&appkey='.urlencode($this->webdb['mymd5']).'&domain='.urlencode($this->request->domain()));
        if(substr($str,0,2)=='QB'){    //檔案核對,防止網路故障,抓取一些出錯資訊
            $str = substr($str,2);
        }else{
            $str='';
        }
        return $str;
    }
    
    /**
     * 獲取雲端的最新檔案列表
     * @return string|mixed
     */
    protected function getfile($page=0){
        if (!$page) {
            $str = http_curl('https://x1.php168.com/appstore/upgrade/get_list_file.html?typeid='.$this->webdb['typeid'].'&appkey='.urlencode($this->webdb['mymd5']).'&domain='.urlencode($this->request->domain()),['app_edition'=>fun('upgrade@local_edition')]);
            file_put_contents(RUNTIME_PATH.'updatelist.txt', $str);
        }else{
            $str = file_get_contents(RUNTIME_PATH.'updatelist.txt');
        }        
        return $str ? json_decode($str,true) : '';
    }
    
}
?>

複製下面的程式碼替換\template\admin_style\default\admin\upgrade\index.htm中的內容

{extend name="index:layout" /}

{block name="menu"}{/block}

{block name="content"}
<link rel="stylesheet" href="/public/static/layui/css/layui.css"  media="all">
<script src="__STATIC__/js/core/vue.js"></script>

<script type="text/javascript">
<!--
if (navigator.userAgent.indexOf("MSIE") >= 0) {
	alert("請使用谷歌或火狐訪問.其它瀏覽器無法操作與使用");
}
//-->
</script>
<style type="text/css">
.locktr td,.locktr td a{
	color:orange;
}
.progress_warp{
	position:fixed;
	top:65%; 
	z-index:9999999999;
	width:100%;
	display:none;
}
.progress_warp .layui-progress{
	margin:0 200px;
}
</style>
<form name="formlist" method="post" action="" class="up_files">
<div class="MainContainers">
  <div class="Header"><span class="tag">線上升級</span><span class="more">&gt;&gt;</span></div>
  <div class="Conter">
<table class="ListTable" id="upgradeTR">
   <tr> 
      <th width='8%'>選中升級</th>
      <th>檔名稱</th>
      <th width='17%'>升級前時間</th>
      <th width='21%'>更新時間</th>
      <th width='19%'>對比差異</th>
    </tr>

	  <tr id="contents">
		<td colspan=5 height=30 style="background:#eee;">
		  <div align="center" style="color:red;" class="upgrade_msg">正在獲取雲端資料資訊,請稍候...</div>
		</td>
	  </tr>

	 <tr v-for="rs in listdb" :class="rs.islock?'locktr':''">
		<td class="b red">
			 <input v-if="rs.islock==1||rs.md5!=''" :data-islock="rs.islock" :data-showfile="rs.showfile" :data-md5="rs.md5" type="checkbox" name="filedb[]" :value="rs.file+','+rs.id" onclick="if($(this).is(':checked'))layer.alert('你修改過當前檔案,你確認要升級覆蓋現有的檔案嗎?')" /> 
			 <input v-else type="checkbox" name="filedb[]" :value="rs.file+','+rs.id" checked /> {{rs.i}}
		</td>
		<td class="Left listfile" :data-id="rs.id">{{rs.showfile}}</td>
		<td>
			<div align="center">{{rs.ctime}}</div>
		</td>
		<td>{{rs.time}}</td>
		<td><a :href="'{:urls('view_file')}?filename='+rs.file+'&oldfile='+rs.showfile+'&id='+rs.id" target="_blank">對比差異</a>
		</td>
	</tr>
 
    <tr bgcolor='#FFFFFF' align="center" class="up_btn" style="display:none;"> 
      <td colspan='5'>
        <div class='submits'>
          <!--<input type='button' onclick="CheckAll(this.form)" name='Submit' value='全選'>-->
          <input type='button' style="background:red;" onclick="sys_upgrade();" name='Submit' value='立刻升級'>          
        </div>
        </td>
  </tr> 
  </table>

  </div>
</div>
</form>

<div class="MainContainers">
  <div class="Header"><span class="tag">升級說明</span></div>
  <div class="Conter">
    <ul class="notes">
      <li>1、你可以選擇哪些檔案不升級,不過你最好是在程式目錄,把不想升級的檔案,做個標誌,比如“index.htm”不想升級,就在對應的目錄建立一個檔案“index.htm.lock”,這樣每次升級,檔案就處於非選中狀態,而不會升級。</li>
  <li>2、如果網路故障,一次升級不成功,可反覆升級</li>
  <li>3、如果因為升級檔案被替換了,請進目錄/runtime/bakfile/找回來</li>
    <li>4、系統預設每次校驗檔案數是1千個,如果你的空間效能太差的話,<a href="https://www.kancloud.cn/php168/x1_of_qibo/2059526" target="_blank">請點選檢視教程進行設定</a></li>
    </ul>
  </div>
</div>

<div class="progress_warp">
	<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="progressId">
	  <div class="layui-progress-bar" lay-percent="1%"></div>
	</div>
</div>
<script src="__STATIC__/layui/layui.js"></script>
<script type="text/javascript">
var element;
$(function(){
	layui.use('element', function(){
	  element = layui.element;
	})
	//element.progress('progressId', i+'%');
})
</script>

<script language=JavaScript>
var upgrade_edition = '';
var upgrade_data = {};
//檢查版本更新
function check_upgrade(){
	var now_edition = "{$upgrade.md5}";
	$.post("https://x1.php168.com/appstore/upgrade/get_edition.html?typeid={$webdb.typeid}&"+Math.random(),{
		app_edition:"{:fun('upgrade@local_edition')}",
		sys_edition:now_edition,
		domin:'{:request()->domain()}',
		appkey:'{$webdb.mymd5}'
	}).success( function(res){
		if(res.code==0){
			upgrade_data = res.data;
			if(res.data.md5!=now_edition||typeof(res.data.upgrade_msg) != "undefined"){
				if(typeof(res.data.time) == "undefined"){
					return ;
				}
				upgrade_edition = res.data.md5;
				var msg = typeof(res.data.upgrade_msg) != "undefined" ? res.data.upgrade_msg : '你的系統需要升級<br>雲端更新日期:'+res.data.time;
				$(".upgrade_msg").html(msg);
				layer.confirm(msg, {
					btn : [ '檢視需要升級的檔案', '晚點再升級' ]
				}, function(index) {
					down_file_list();
				});
			}else{
				$(".upgrade_msg").html('已經是最新了,無須升級');
			}
		}else{
			layer.alert(res.msg,{time:5500});
		}
	}).fail(function (res) {
		//layer.alert('網路故障,請晚點再償試升級!!');
		//layer.closeAll();
		layer.open({title: '網路故障,請晚點再償試升級!!',area:['90%','90%'],content: res.responseText});
	});
}
check_upgrade();


var app_ids = {};

var vues = new Vue({
	el: '#upgradeTR',
	data: {
		listdb: [],
	},
	watch:{
		listdb: function() {
			this.$nextTick(function(){	//資料渲染完畢才執行
				var time = 100;
				$("input[data-islock=0]:not(:checked)").each(function(){
					time += 200;
					var that = $(this);
					var url = "https://x1.php168.com/appstore/upgrade/check_md5.html?path="+that.attr('data-showfile')+"&md5="+that.attr('data-md5');
					setTimeout(function(){
						$.get(url,function(res){
							if(res.code==0){
								that.attr('checked',true);
							}
						});
					},time);
				});
				
				var times = 500;
				$(".listfile").each(function(){
					var that = $(this);
					if(that.attr("data-id")){
						var id = that.attr("data-id");
						if(app_ids[id]==undefined){
							app_ids[id] = {};
							times += 500;
							setTimeout(function(){
								$.get("https://x1.php168.com/appstore/wxapp.show/index.html?id="+id,function(res){
									if(res.code==0){
										//app_ids[id] = res.data;
										$(".listfile[data-id="+id+"]").append(" <a href='https://x1.php168.com/appstore/content/show/id/"+id+".html' target='_blank'>"+res.data.title+"</a>");
									}
								});
							},times);
						}
					}
				});

				$(".up_btn").show();
				layer.alert('需要升級的檔案列表如下,你可以有選擇性的升級');

			});
		}
	},
	methods: {
		add_data:function(array){
			$("#contents").remove();
			array.forEach((rs,i)=>{
				rs.i = i+1;
				this.listdb.push(rs);
			});			
		}
	}		  
});

var need_update_file = [];
function check_need_update(totalpage,page){	
	if(page==1)layer.load(1,{shade: [0.7, '#393D49']}, {shadeClose: true}); //0代表載入的風格,支援0-2
	layer.msg('正在核對需要升級的檔案, <b style="color:red;">'+page+'</b> / '+totalpage+' 頁,<br>需要一點時間,請耐心等候!',{icon:1,time:30000, shift: 1});
	$.post("{:urls('check_files')}?upgrade_edition="+upgrade_edition+"&page="+page,upgrade_data,function(res){
		if(res.code==0){
			res.data.forEach((rs)=>{
				need_update_file.push(rs);
			});
			if(page<totalpage){
				page++;				
				check_need_update(totalpage,page);
			}else{
				layer.closeAll();
				vues.add_data(need_update_file);
			}
		}else{
			layer.alert(res.msg);
		}		
	});
}

//下載檔案列表,核對需要哪些更新
function down_file_list(){
	layer.alert('正在從雲端下載升級檔案列表,請稍候!');
	var index = layer.load(1,{shade: [0.7, '#393D49']}, {shadeClose: true}); //0代表載入的風格,支援0-2
	$.post("{:urls('check_files')}?upgrade_edition="+upgrade_edition,upgrade_data).success(function(res){
		layer.closeAll();
		if(res.code==0){			
			//vues.add_data(res.data);
			check_need_update(res.data,1);
			/*
			var str = '';
			res.data.forEach(function(rs){
				
				var ck = rs.islock?" onclick='layer.alert(\"當前檔案已鎖定,你確認要升級嗎?\")' ":' checked ';
				var style = rs.islock?" class='locktr' ":' ';
				str +='<tr '+style+'>'+
						  '<td class="b red"> <input type="checkbox" name="filedb[]" value="'+rs.file+','+rs.id+'" '+ck+'></td>'+   
						  '<td class="Left">'+rs.showfile+'</td>'+   
						  '<td><div align="center">'+rs.ctime+'</div></td>'+
						  '<td>'+rs.time+'</td>'+
						  '<td><a href="{:urls("view_file")}?filename='+rs.file+'&id='+rs.id+'" target="_blank">檢視</a></td>'+
					  '</tr>';
					  
			});
			document.getElementById('contents').outerHTML=str;
			*/			
		}else{
			layer.alert(res.msg,{time:5500});
		}
	}).fail(function (res) {
		layer.closeAll();
		//layer.alert('通訊失敗,可能你的後臺許可權不足'); )
		var parsedJson = $.parseJSON(res.responseText.substr(res.responseText.indexOf('{'))); //使用者程式中有UTF8 +BOM檔案導致的

		if( typeof(parsedJson) == 'object' && parsedJson.code==0){
			//vues.add_data(parsedJson.data);
			check_need_update(res.data,1);
			/*
			var str = '';
			parsedJson.data.forEach(function(rs){
				var ck = rs.islock?" onclick='layer.alert(\"當前檔案已鎖定,你確認要升級嗎?\")' ":' checked ';
				var style = rs.islock?" class='locktr' ":' ';
				str +='<tr '+style+'>'+
						  '<td class="b red"> <input type="checkbox" name="filedb[]" value="'+rs.file+','+rs.id+'"  '+ck+'></td>'+   
						  '<td class="Left">'+rs.showfile+'</td>'+   
						  '<td><div align="center">'+rs.ctime+'</div></td>'+
						  '<td>'+rs.time+'</td>'+
						  '<td><a href="{:urls("view_file")}?filename='+rs.file+'&id='+rs.id+'" target="_blank">檢視</a></td>'+
					  '</tr>';
			});
			document.getElementById('contents').outerHTML=str;
			*/
			//$(".up_btn").show();
			//layer.alert('需要升級的檔案列表如下,你可以有選擇性的升級<br>特別提醒:你的系統中有錯誤的UTF8 +BOM 程式碼檔案,一般情況是新裝的風格導致的,請仔細排查!');
			return ;
		}else if( typeof(parsedJson) == 'object' && parsedJson.code==1){
			layer.alert(parsedJson.msg+"<br><br>特別提醒:你的系統中有錯誤的UTF8 +BOM 程式碼檔案,一般情況是新裝的風格導致的,請仔細排查!",{time:5500});
			return ;
		}

		layer.confirm('通訊失敗,你是否要新開視窗檢視一下詳情?'+JSON.stringify(res), {
            btn : [ '檢視詳情', '取消' ]
        }, function(index) {
            window.open("{:urls('check_files')}?upgrade_edition="+upgrade_edition);
        });
	});
}

//開始升級檔案
function sys_upgrade(){
	$(".up_files input[type='checkbox']").each(function(i){
		if($(this).is(':checked')==true){
			ckfile_num++;
		}
	});
	
	layer.alert('正在升級檔案,請耐心稍候...');
	var index = layer.load(1,{shade: [0.7, '#393D49']}, {shadeClose: true}); //0代表載入的風格,支援0-2
	$(".progress_warp").show();
	var time = 0;
	$(".up_files input[type='checkbox']").each(function(i){
		if($(this).is(':checked')==true){
			var file_name = $(this).val();
			var obj = $(this).parent().next();
			if( file_name.indexOf('/upgrade/')>0 ){				
				time += 3000;
			}else{
				time += 500;
			}
			setTimeout(function(){
				upgrade_file(file_name,obj);
			},time);
		}
	});
}

//全部升級完畢
function end_up(){
		layer.msg('全部檔案升級成功');
		$.post("{:urls('sysup')}?upgrade_edition="+upgrade_edition,upgrade_data).success(function(res){
			if(res.code==0){			
				layer.alert('本次升級完畢,'+ok_num+'個檔案升級成功!');
			}else{
				layer.alert('升級資訊寫入失敗');
			}
		}).fail(function (res) {
			layer.open({title: '網路故障,請晚點再償試升級!!',area:['90%','90%'],content: res.responseText});
		});

}

var ckfile_num = 0;	//選中的升級檔案個數
var ok_num = 0;	//成功升級檔案個數
//一個一個的檔案升級
function upgrade_file(filename,obj){
	$.post("{:urls('sysup')}?filename="+filename,upgrade_data).success(function(res){		
		if(res.code==0){			
			//layer.msg('檔案:'+filename+' 升級成功');
			var str = obj.html()+' <font color="red">升級成功</font>';
			obj.html(str);
			ok_num++;
			if(ok_num==ckfile_num){	//全部升級完畢
				layer.closeAll();
				end_up();
				$(".progress_warp").hide();
			}
			element.progress('progressId', parseInt(ok_num*100/ckfile_num)+'%');	//升級進度
		}else{
			//layer.msg('檔案:'+filename+' 升級失敗:'+ res.msg,{time:2500});
			var str = obj.html()+' <font color="blue">升級失敗:'+res.msg+'</font>';
			obj.html(str);
		}
	}).fail(function (res) {
		//layer.alert('通訊失敗,可能你的後臺許可權不足');
		layer.open({title: '網路故障,請晚點再償試升級!!',area:['90%','90%'],content: res.responseText});
	});
}



function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		e.checked == true ? e.checked = false : e.checked = true;
	}
}

</script>
{/block}
半抹燈芯https://www.cnblogs.com/wanxiangsucai/p/15749496.html