SystemVersionSlb.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace common\models\backend;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%system_version_slb}}".
  8. *
  9. * @property int $id
  10. * @property int|null $version_id 最新更新成功版本ID
  11. * @property string|null $ip 服务器ip
  12. * @property int $upgrade_status 更新状态[-1=更新失败,0=更新中,1=更新完成]
  13. * @property int $status 状态:0-更新中,1-更新完成
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class SystemVersionSlb extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%system_version_slb}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['version_id', 'upgrade_status', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['ip'], 'string', 'max' => 32],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'version_id' => '最新更新成功版本ID',
  44. 'ip' => '服务器ip',
  45. 'upgrade_status' => '更新状态[-1=更新失败,0=更新中,1=更新完成]',
  46. 'status' => '状态:0禁用,1正常',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. /**
  52. * 初始化
  53. * @Author: lun
  54. * @DateTime: 2023/5/18 0018 10:04
  55. * @Copyright: copyright (c) 2021 广东七件事集团
  56. * @param $version_id
  57. * @return array|bool
  58. */
  59. public static function initSetData($version_id, $upgrade_status = 0)
  60. {
  61. try {
  62. $model = new self();
  63. $model->version_id = $version_id;
  64. $model->ip = Yii::$app->params['network_ip'];// 服务器外网IP[注意:在qimall/common/config/params-local.php文件进行配置]
  65. $model->upgrade_status = $upgrade_status;
  66. if (!$model->save()) throw new Exception($model->getErrorMessage());
  67. return $model->toArray();
  68. } catch (\Exception $e) {
  69. self::setStaticError($e->getMessage());
  70. return false;
  71. }
  72. }
  73. /**
  74. * 更新状态
  75. * @Author: lun
  76. * @DateTime: 2023/5/18 0018 10:19
  77. * @Copyright: copyright (c) 2021 广东七件事集团
  78. * @param $slb_id
  79. * @param $upgrade_status
  80. * @throws Exception
  81. */
  82. public static function setStatus($slb_id, $upgrade_status)
  83. {
  84. $res = self::updateAll(['upgrade_status' => $upgrade_status, 'updated_at' => time()], ['id' => $slb_id]);
  85. if ($res == false) throw new Exception('更新状态失败');
  86. }
  87. }