forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate.php
More file actions
126 lines (112 loc) · 3.52 KB
/
Copy pathTemplate.php
File metadata and controls
126 lines (112 loc) · 3.52 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
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "doc_template".
*
* @property int $id
* @property string $encode_id 加密id
* @property int $project_id 项目id
* @property string $header_field header字段,json格式
* @property string $request_field 请求字段,json格式
* @property string $response_field 响应字段,json格式
* @property int $status 模板状态
* @property int $creater_id 创建者id
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
*/
class Template extends Module
{
/**
* 默认模板参数
* @var array
*/
public $defaultAttributes = [
'header_field' => [
['name' => 'Content-Type', 'title' => '', 'value' => 'application/json;charset=utf-8', 'remark' => ''],
['name' => 'Accept', 'title' => '', 'value' => 'application/json', 'remark' => ''],
],
'request_field' => [
['name' => 'token', 'title' => '令牌', 'type' => 'string', 'required' => 10, 'default' => '' ,'remark' => ''],
],
'response_field'=> [
['name' => 'code', 'title' => '返回状态码', 'type' => 'integer', 'mock' => ''],
['name' => 'message', 'title' => '返回信息', 'type' => 'string', 'mock' => ''],
['name' => 'data', 'title' => '数据实体', 'type' => 'array', 'mock' => '']
],
];
/**
* 绑定数据表
*/
public static function tableName()
{
return '{{%template}}';
}
/**
* 验证规则
*/
public function rules()
{
return [
[['project_id', 'status', 'creater_id'], 'integer'],
[['header_field', 'request_field', 'response_field'], 'string'],
[['encode_id'], 'string', 'max' => 10],
[['project_id'], 'unique'],
[['encode_id'], 'unique'],
[['created_at', 'updated_at'], 'safe'],
[['created_at'], 'default', 'value' => date('Y-m-d H:i:s')],
[['status'], 'default', 'value' => self::ACTIVE_STATUS],
[['encode_id', 'project_id', 'header_field', 'request_field', 'response_field', 'status', 'creater_id'], 'required'],
];
}
/**
* 字段字典
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'encode_id' => '加密id',
'project_id' => '项目id',
'header_field' => 'header字段',
'request_field' => '请求字段',
'response_field' => '响应字段',
'status' => '模板状态',
'creater_id' => '创建者id',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
/**
* 获取header参数数组
* @return object
*/
public function getHeaderAttributes()
{
return json_decode($this->header_field);
}
/**
* 获取请求参数数组
* @return object
*/
public function getRequestAttributes()
{
return json_decode($this->request_field);
}
/**
* 获取响应参数数组
* @return object
*/
public function getResponseAttributes()
{
return json_decode($this->response_field);
}
/**
* 获取所属项目
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::className(),['id'=>'project_id'])->where(['status' => self::ACTIVE_STATUS])->orderBy(['sort' => SORT_DESC,'id' => SORT_DESC]);
}
}