dggzichahu/application/admin/validate/Upgrade.php

64 lines
1.7 KiB
PHP
Executable File

<?php
// +----------------------------------------------------------------------
// | 宏驰云科技开发团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | Author: HcyShop-kiki
// +----------------------------------------------------------------------
namespace app\admin\validate;
use app\admin\logic\UpgradeLogic;
use think\Validate;
class Upgrade extends Validate
{
protected $rule = [
'version_no' => 'require|checkIsAbleUpgrade',
'package_link' => 'require'
];
protected $message = [
'version_no.require' => '参数缺失',
'package_link.require' => '参数缺失',
];
//检查是否可以更新
protected function checkIsAbleUpgrade($value, $reule, $data)
{
$version_data = local_version();
$local_version = $version_data['version'];
//本地版本需要小于当前选中版本
if ($local_version > $value) {
return '当前系统无法升级到该版本,请重新选择更新版本。';
}
//获取远程列表
$remote_data = UpgradeLogic::getRemoteVersion();
if (empty($remote_data)) {
return '获取更新数据失败';
}
foreach ($remote_data as $k => $item) {
if ($item['version_no'] != $local_version) {
continue;
}
if (empty($remote_data[$k-1])) {
return '已为最新版本';
}
if ($remote_data[$k-1]['version_no'] != $value) {
return '当前系统无法升级到该版本,请重新选择更新版本。';
}
}
return true;
}
}