Version.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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')
  23. ->cache('__version__')->order('weigh desc,id desc')->select();
  24. foreach ($versionlist as $k => $v)
  25. {
  26. // 版本正常且新版本号不等于验证的版本号且找到匹配的旧版本
  27. if ($v['status'] == 'normal' && $v['new_version'] !== $version && \fast\Version::check($version, $v['old_version']))
  28. {
  29. $updateversion = $v;
  30. break;
  31. }
  32. }
  33. if (isset($updateversion))
  34. {
  35. $search = ['{version}', '{new_version}', '{download_url}', '{url}', '{package_size}'];
  36. $replace = [$version, $updateversion['new_version'], $updateversion['download_url'], $updateversion['download_url'], $updateversion['package_size']];
  37. $upgradetext = str_replace($search, $replace, $updateversion['content']);
  38. return [
  39. "enforce" => $updateversion['enforce'],
  40. "version" => $version,
  41. "new_version" => $updateversion['new_version'],
  42. "download_url" => $updateversion['download_url'],
  43. "package_size" => $updateversion['package_size'],
  44. "upgradetext" => $upgradetext
  45. ];
  46. }
  47. return NULL;
  48. }
  49. }