UpgradeLog.php
4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
namespace domain\upgrade;
use Yii;
use domain\upgrade\models\UpgradeLog as UpgradeLogModel;
use Exception;
/**
* 版本日志
* Class UpgradeLog
* @package domain\upgrade
*/
class UpgradeLog
{
/**
* 创建版本日志
* @param $item
*/
static function create($item)
{
try {
$upgradeLogModel = Yii::createObject(UpgradeLogModel::className());
if (isset($item["barcode"])) {
$upgradeLogModel->barcode = $item["barcode"]; // 序列号前缀
}
if (isset($item["device_id"])) {
$upgradeLogModel->device_id = $item["device_id"]; // 设备ID
}
if (isset($item["manufacture_id"])) {
$upgradeLogModel->manufacture_id = $item["manufacture_id"]; // 厂商ID
}
if (isset($item["project_id"])) {
$upgradeLogModel->project_id = $item["project_id"]; // 项目ID
}
if (isset($item["model_id"])) {
$upgradeLogModel->model_id = $item["model_id"]; // 设备型号ID
}
if (isset($item["package_name"])) {
$upgradeLogModel->package_name = $item["package_name"]; // 包名
}
if (isset($item["current_version"])) {
$upgradeLogModel->current_version = $item["current_version"]; // 当前版本
}
if (isset($item["target_version"])) {
$upgradeLogModel->target_version = $item["target_version"]; // 目标版本
}
if (isset($item["status"])) {
$upgradeLogModel->status = $item["status"]; // 升级状态,1:下载成功,2:取消下载,3:开始升级,4:取消升级,5:升级成功
}
if (isset($item["error_code"])) {
$upgradeLogModel->error_code = $item["error_code"]; // 错误码
}
if (isset($item["timestamp"])) {
$upgradeLogModel->timestamp = $item["timestamp"]; //
}
if (isset($item["type"])) {
$upgradeLogModel->type = $item["type"]; // 日志类型 1 app 2.ota整机
}
$saveResult = $upgradeLogModel->save();
return $saveResult;
} catch (Exception $e) {
return false;
}
}
/**
* 更新版本日志
* @param $id
* @param $item
* @return null|static
*/
static function update($id, $item)
{
$upgradeLogModel = UpgradeLogModel::findOne($id);
if (empty($upgradeLogModel)) {
return false;
}
if (isset($item["barcode"])) {
$upgradeLogModel->barcode = $item["barcode"]; // 序列号前缀
}
if (isset($item["device_id"])) {
$upgradeLogModel->device_id = $item["device_id"]; // 设备ID
}
if (isset($item["manufacture_id"])) {
$upgradeLogModel->manufacture_id = $item["manufacture_id"]; // 厂商ID
}
if (isset($item["project_id"])) {
$upgradeLogModel->project_id = $item["project_id"]; // 项目ID
}
if (isset($item["model_id"])) {
$upgradeLogModel->model_id = $item["model_id"]; // 设备型号ID
}
if (isset($item["current_version"])) {
$upgradeLogModel->current_version = $item["current_version"]; // 当前版本
}
if (isset($item["target_version"])) {
$upgradeLogModel->target_version = $item["target_version"]; // 目标版本
}
if (isset($item["status"])) {
$upgradeLogModel->status = $item["status"]; // 升级状态,1:下载成功,2:取消下载,3:开始升级,4:取消升级,5:升级成功
}
if (isset($item["error_code"])) {
$upgradeLogModel->error_code = $item["error_code"]; // 错误码
}
if (isset($item["type"])) {
$upgradeLogModel->type = $item["type"]; // 日志类型 1 app 2.ota整机
}
$resultSave = $upgradeLogModel->save();
return $resultSave;
}
/**
* 删除版本日志
* @param $id
* @param $item
* @return null|static
*/
public static function delete($id)
{
$upgradeModel = UpgradeLogModel::findOne($id);
if (empty($upgradeModel)) {
return false;
}
return $upgradeModel->delete();
}
/**
* @param $condition
* @return bool|int
*/
public static function deleteAll($condition)
{
if (empty($condition)) {
return false;
}
return UpgradeLogModel::deleteAll($condition);
}
}