You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
1.7 KiB

  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Version extends Model
  5. {
  6. // 开启自动写入时间戳字段
  7. protected $autoWriteTimestamp = 'int';
  8. // 定义时间戳字段名
  9. protected $createTime = 'createtime';
  10. protected $updateTime = 'updatetime';
  11. // 定义字段类型
  12. protected $type = [
  13. ];
  14. /**
  15. * 检测版本号
  16. *
  17. * @param string $version 客户端版本号
  18. * @return array
  19. */
  20. public static function check($version)
  21. {
  22. $versionlist = self::where('status', 'normal')->cache('__version__')->order('weigh desc,id desc')->select();
  23. foreach ($versionlist as $k => $v) {
  24. // 版本正常且新版本号不等于验证的版本号且找到匹配的旧版本
  25. if ($v['status'] == 'normal' && $v['newversion'] !== $version && \fast\Version::check($version, $v['oldversion'])) {
  26. $updateversion = $v;
  27. break;
  28. }
  29. }
  30. if (isset($updateversion)) {
  31. $search = ['{version}', '{newversion}', '{downloadurl}', '{url}', '{packagesize}'];
  32. $replace = [$version, $updateversion['newversion'], $updateversion['downloadurl'], $updateversion['downloadurl'], $updateversion['packagesize']];
  33. $upgradetext = str_replace($search, $replace, $updateversion['content']);
  34. return [
  35. "enforce" => $updateversion['enforce'],
  36. "version" => $version,
  37. "newversion" => $updateversion['newversion'],
  38. "downloadurl" => $updateversion['downloadurl'],
  39. "packagesize" => $updateversion['packagesize'],
  40. "upgradetext" => $upgradetext
  41. ];
  42. }
  43. return null;
  44. }
  45. }