Skip to content

Commit c8056cd

Browse files
committed
接口参数支持table指定表字段解析
1 parent 5bab05f commit c8056cd

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

src/annotation/AddField.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class AddField extends ParamBase
5858
* @param string $desc 字段名称
5959
* @param bool $require 是否必须
6060
* @param string $ref 引用注解/模型
61+
* @param string $table 引用数据表
6162
* @param string $md Md文本内容
6263
* @param string $field 指定Ref引入的字段
6364
* @param string $withoutField 排除Ref引入的字段
@@ -70,6 +71,7 @@ public function __construct(
7071
string $desc = '',
7172
bool $require = false,
7273
$ref = "",
74+
$table = "",
7375
string $md = "",
7476
$field = "",
7577
$withoutField = "",

src/annotation/Param.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Param extends ParamBase
2525
* @param bool $require 是否必须
2626
* @param string|int|bool $default 默认值
2727
* @param string|array $ref 引用注解/模型
28+
* @param string $table 引用数据表
2829
* @param string|array $field 指定Ref引入的字段
2930
* @param string|array $withoutField 排除Ref引入的字段
3031
* @param string $desc 字段名称
@@ -41,6 +42,7 @@ public function __construct(
4142
bool $require = false,
4243
$default = "",
4344
$ref = "",
45+
$table = "",
4446
$field = "",
4547
$withoutField = "",
4648
string $desc = '',

src/annotation/Query.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class Query extends ParamBase
2626
* @param bool $require 是否必须
2727
* @param string|int|bool $default 默认值
2828
* @param string|array $ref 引用注解/模型
29+
* @param string $table 引用数据表
2930
* @param string|array $field 指定Ref引入的字段
3031
* @param string|array $withoutField 排除Ref引入的字段
3132
* @param string $desc 字段名称
@@ -42,6 +43,7 @@ public function __construct(
4243
bool $require = false,
4344
$default = "",
4445
$ref = "",
46+
$table = "",
4547
$field = "",
4648
$withoutField = "",
4749
string $desc = '',

src/annotation/Returned.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Returned extends ParamBase
2626
* @param bool $require 是否必须
2727
* @param string|int|bool $default 默认值
2828
* @param string|array $ref 引用注解/模型
29+
* @param string $table 引用数据表
2930
* @param string|array $field 指定Ref引入的字段
3031
* @param string|array $withoutField 排除Ref引入的字段
3132
* @param string $desc 字段名称
@@ -42,6 +43,7 @@ public function __construct(
4243
bool $require = false,
4344
$default = "",
4445
$ref = "",
46+
$table = "",
4547
$field = "",
4648
$withoutField = "",
4749
string $desc = '',

src/parses/ParseApiDetail.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ protected function handleAnnotationsParamItem($param,$field){
417417
}else{
418418
return false;
419419
}
420-
}else{
420+
}else if(!empty($param['table'])){
421+
$tableParams = (new ParseModel($this->config))->getTableDocument($param['table'],[]);
422+
$data = $this->handleRefData($param,$tableParams,$field);
423+
} else{
421424
$data = $param;
422425
}
423426
if (!empty($data['desc'])){

src/parses/ParseModel.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ public function parseModelTable($model,$classReflect,$methodName=""){
2929
try {
3030
// 获取所有模型属性
3131
$propertys = $classReflect->getDefaultProperties();
32-
$table =$this->getTableDocument($model, $propertys);
32+
$tableName = $model->getTable();
33+
$configTablePrefix = !empty($config['database']) && !empty($config['database']['prefix'])?$config['database']['prefix']:"";
34+
if (!empty($configTablePrefix) && strpos($tableName, $configTablePrefix) === false){
35+
$tableName = $configTablePrefix.$model->getTable();
36+
}
37+
$table =$this->getTableDocument($tableName, $propertys);
3338
if (empty($methodName)){
3439
return $table;
3540
}
@@ -101,22 +106,17 @@ public static function getModelClass($namespaceName)
101106

102107
/**
103108
* 获取模型注解数据
104-
* @param $model
109+
* @param $tableName
105110
* @param $propertys
106111
* @return array
107112
*/
108-
protected function getTableDocument($model,array $propertys):array
113+
public function getTableDocument($tableName,array $propertys):array
109114
{
110115
$config = $this->config;
111116
$fieldComment = [];
112117
if (empty($config['database_query_function'])){
113118
throw new ErrorException("not datatable_query_function config");
114119
}
115-
$tableName = $model->getTable();
116-
$configTablePrefix = !empty($config['database']) && !empty($config['database']['prefix'])?$config['database']['prefix']:"";
117-
if (!empty($configTablePrefix) && strpos($tableName, $configTablePrefix) === false){
118-
$tableName = $configTablePrefix.$model->getTable();
119-
}
120120
$tableColumns = $config['database_query_function']("SHOW FULL COLUMNS FROM " . $tableName);
121121
foreach ($tableColumns as $columns) {
122122
$columns = Helper::objectToArray($columns);

0 commit comments

Comments
 (0)