add apimanager module
This commit is contained in:
92
catch/apimanager/model/ApiCategory.php
Normal file
92
catch/apimanager/model/ApiCategory.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | UCToo [ Universal Convergence Technology ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2014-2021 https://www.uctoo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: UCToo <contact@uctoo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\apimanager\model;
|
||||
|
||||
use catchAdmin\apimanager\model\search\ApiCategorySearch;
|
||||
use catcher\base\CatchModel as Model;
|
||||
use think\db\exception\DbException;
|
||||
/**
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $category_title
|
||||
* @property int $parent_id
|
||||
* @property string $category_name
|
||||
* @property int $status
|
||||
* @property int $sort
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
* @property int $deleted_at
|
||||
* @property int $creator_id
|
||||
*/
|
||||
class ApiCategory extends Model
|
||||
{
|
||||
use ApiCategorySearch;
|
||||
// 表名
|
||||
public $name = 'api_category';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 分类标题
|
||||
'category_title',
|
||||
// 父级ID
|
||||
'parent_id',
|
||||
// 分类唯一标识
|
||||
'category_name',
|
||||
// 状态:1=正常;2=停用
|
||||
'status',
|
||||
// 排序字段
|
||||
'sort',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除字段
|
||||
'deleted_at',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
);
|
||||
|
||||
protected $updateChildrenFields = 'status';
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function getList(): array
|
||||
{
|
||||
return $this->catchSearch()
|
||||
->catchOrder()
|
||||
->select()->toTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子分类IDS
|
||||
*
|
||||
* @time 2020年11月04日
|
||||
* @param $id
|
||||
* @throws DbException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getChildrenCategoryIds($id)
|
||||
{
|
||||
$categoryIds = ApiCategory::field(['id', 'parent_id'])->select()->getAllChildrenIds([$id]);
|
||||
|
||||
$categoryIds[] = $id;
|
||||
|
||||
return $categoryIds;
|
||||
}
|
||||
}
|
104
catch/apimanager/model/ApiTester.php
Normal file
104
catch/apimanager/model/ApiTester.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | UCToo [ Universal Convergence Technology ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2014-2021 https://www.uctoo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: UCToo <contact@uctoo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\apimanager\model;
|
||||
|
||||
use catcher\base\CatchModel as Model;
|
||||
use catchAdmin\apimanager\model\search\ApiTesterSearch;
|
||||
/**
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $api_title
|
||||
* @property string $api_name
|
||||
* @property int $category_id
|
||||
* @property int $type
|
||||
* @property string $appid
|
||||
* @property string $project_id
|
||||
* @property string $api_url
|
||||
* @property string $methods
|
||||
* @property string $auth
|
||||
* @property string $header
|
||||
* @property string $query
|
||||
* @property string $body
|
||||
* @property string $doc_url
|
||||
* @property string $document
|
||||
* @property string $sample_data
|
||||
* @property string $sample_result
|
||||
* @property int $sort
|
||||
* @property int $status
|
||||
* @property string $content_type
|
||||
* @property int $env_id
|
||||
* @property string $memo
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
* @property int $deleted_at
|
||||
* @property int $creator_id
|
||||
*/
|
||||
class ApiTester extends Model
|
||||
{
|
||||
use ApiTesterSearch;
|
||||
// 表名
|
||||
public $name = 'api_tester';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 标题
|
||||
'api_title',
|
||||
// 英文唯一标识
|
||||
'api_name',
|
||||
// 分类
|
||||
'category_id',
|
||||
// 数据源类型:1=remote,2=local
|
||||
'type',
|
||||
// appid
|
||||
'appid',
|
||||
// 项目ID
|
||||
'project_id',
|
||||
// API URL
|
||||
'api_url',
|
||||
// 方法:POST,GET,PUT,PATCH,DELETE,COPY,HEAD,OPTIONS
|
||||
'methods',
|
||||
// 鉴权
|
||||
'auth',
|
||||
// header
|
||||
'header',
|
||||
// query
|
||||
'query',
|
||||
// body
|
||||
'body',
|
||||
// 文档URL
|
||||
'doc_url',
|
||||
// 文档
|
||||
'document',
|
||||
// 示例数据
|
||||
'sample_data',
|
||||
// 示例返回数据
|
||||
'sample_result',
|
||||
// 排序
|
||||
'sort',
|
||||
// 状态:1=已完成,2=待开发,3=开发中,4=已废弃
|
||||
'status',
|
||||
// content-type:application/x-www-form-urlencoded,multipart/form-data,raw
|
||||
'content_type',
|
||||
// 环境ID
|
||||
'env_id',
|
||||
// 备注
|
||||
'memo',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除字段
|
||||
'deleted_at',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
);
|
||||
}
|
60
catch/apimanager/model/ApiTesterLog.php
Normal file
60
catch/apimanager/model/ApiTesterLog.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | UCToo [ Universal Convergence Technology ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2014-2021 https://www.uctoo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: UCToo <contact@uctoo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\apimanager\model;
|
||||
|
||||
use catcher\base\CatchModel as Model;
|
||||
/**
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $appid
|
||||
* @property int $user_id
|
||||
* @property int $api_id
|
||||
* @property string $params
|
||||
* @property string $result
|
||||
* @property string $request_data
|
||||
* @property string $response_data
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
* @property int $deleted_at
|
||||
* @property int $creator_id
|
||||
*/
|
||||
class ApiTesterLog extends Model
|
||||
{
|
||||
// 表名
|
||||
public $name = 'api_tester_log';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// appid
|
||||
'appid',
|
||||
// users表id
|
||||
'user_id',
|
||||
// api_tester表id
|
||||
'api_id',
|
||||
// api参数
|
||||
'params',
|
||||
// 返回值
|
||||
'result',
|
||||
// 请求数据
|
||||
'request_data',
|
||||
// 响应数据
|
||||
'response_data',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除字段
|
||||
'deleted_at',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
);
|
||||
}
|
76
catch/apimanager/model/ApiTesterUserenv.php
Normal file
76
catch/apimanager/model/ApiTesterUserenv.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | UCToo [ Universal Convergence Technology ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2014-2021 https://www.uctoo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: UCToo <contact@uctoo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\apimanager\model;
|
||||
|
||||
use catchAdmin\permissions\model\DataRangScopeTrait;
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catchAdmin\apimanager\model\search\ApiTesterUserenvSearch;
|
||||
use catcher\base\CatchModel as Model;
|
||||
/**
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $env_name
|
||||
* @property string $appid
|
||||
* @property string $project_id
|
||||
* @property string $env_json
|
||||
* @property int $selected
|
||||
* @property int $created_at
|
||||
* @property int $updated_at
|
||||
* @property int $deleted_at
|
||||
* @property int $creator_id
|
||||
*/
|
||||
class ApiTesterUserenv extends Model
|
||||
{
|
||||
use ApiTesterUserenvSearch;
|
||||
use DataRangScopeTrait;
|
||||
// 表名
|
||||
public $name = 'api_tester_userenv';
|
||||
// 数据库字段映射
|
||||
public $field = array(
|
||||
'id',
|
||||
// 环境名称
|
||||
'env_name',
|
||||
// appid
|
||||
'appid',
|
||||
// 项目ID
|
||||
'project_id',
|
||||
// 环境变量json
|
||||
'env_json',
|
||||
// 是否当前选中:0=否,1=是
|
||||
'selected',
|
||||
// 创建时间
|
||||
'created_at',
|
||||
// 更新时间
|
||||
'updated_at',
|
||||
// 软删除字段
|
||||
'deleted_at',
|
||||
// 创建人ID
|
||||
'creator_id',
|
||||
);
|
||||
|
||||
/**
|
||||
* get list
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param $params
|
||||
* @throws \think\db\exception\DbException
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
return $this->dataRange()->field([$this->aliasField('*')])
|
||||
->catchJoin(Users::class, 'id', 'creator_id', ['username as creator'])
|
||||
->catchSearch()
|
||||
->order($this->aliasField('id'), 'desc')
|
||||
->paginate();
|
||||
}
|
||||
}
|
25
catch/apimanager/model/search/ApiCategorySearch.php
Normal file
25
catch/apimanager/model/search/ApiCategorySearch.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | UCToo [ Universal Convergence Technology ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2014-2021 https://www.uctoo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: UCToo <contact@uctoo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\apimanager\model\search;
|
||||
|
||||
trait ApiCategorySearch
|
||||
{
|
||||
public function searchCategoryTitleAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereLike('category_title', $value);
|
||||
}
|
||||
|
||||
public function searchStatusAttr($query, $value, $data)
|
||||
{
|
||||
return $query->where('status', $value);
|
||||
}
|
||||
}
|
54
catch/apimanager/model/search/ApiTesterSearch.php
Normal file
54
catch/apimanager/model/search/ApiTesterSearch.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | UCToo [ Universal Convergence Technology ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2014-2021 https://www.uctoo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: UCToo <contact@uctoo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\apimanager\model\search;
|
||||
|
||||
use catchAdmin\apimanager\model\ApiCategory;
|
||||
|
||||
trait ApiTesterSearch
|
||||
{
|
||||
public function searchApiTitleAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereLike('api_title', $value);
|
||||
}
|
||||
|
||||
public function searchApiNameAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereLike('api_name', $value);
|
||||
}
|
||||
|
||||
public function searchStatusAttr($query, $value, $data)
|
||||
{
|
||||
return $query->where($this->aliasField('status'), $value);
|
||||
}
|
||||
|
||||
public function searchTypeAttr($query, $value, $data)
|
||||
{
|
||||
return $query->where($this->aliasField('type'), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分类下的API
|
||||
*
|
||||
* @time 2021年05月20日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchCategoryIdAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereIn($this->aliasField('category_id'), ApiCategory::getChildrenCategoryIds($value));
|
||||
}
|
||||
}
|
28
catch/apimanager/model/search/ApiTesterUserenvSearch.php
Normal file
28
catch/apimanager/model/search/ApiTesterUserenvSearch.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | UCToo [ Universal Convergence Technology ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2014-2021 https://www.uctoo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: UCToo <contact@uctoo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace catchAdmin\apimanager\model\search;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
|
||||
trait ApiTesterUserenvSearch
|
||||
{
|
||||
public function searchCreatorAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereLike(app(Users::class)->getTable() . '.username', $value);
|
||||
}
|
||||
|
||||
public function searchEnvNameAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereLike('env_name', $value);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user