mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 完善接口字段的过滤
This commit is contained in:
parent
e0fea97d02
commit
ebf0e878c1
@ -46,10 +46,13 @@ class Fields extends Base {
|
|||||||
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 0])
|
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 0])
|
||||||
->paginate($limit, false, ['page' => $start])->toArray();
|
->paginate($limit, false, ['page' => $start])->toArray();
|
||||||
|
|
||||||
|
$apiInfo = (new AdminList())->where('hash', $hash)->find();
|
||||||
|
|
||||||
return $this->buildSuccess([
|
return $this->buildSuccess([
|
||||||
'list' => $listObj['data'],
|
'list' => $listObj['data'],
|
||||||
'count' => $listObj['total'],
|
'count' => $listObj['total'],
|
||||||
'dataType' => $this->dataType
|
'dataType' => $this->dataType,
|
||||||
|
'apiInfo' => $apiInfo
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
||||||
@ -71,10 +74,13 @@ class Fields extends Base {
|
|||||||
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 1])
|
$listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 1])
|
||||||
->paginate($limit, false, ['page' => $start])->toArray();
|
->paginate($limit, false, ['page' => $start])->toArray();
|
||||||
|
|
||||||
|
$apiInfo = (new AdminList())->where('hash', $hash)->find();
|
||||||
|
|
||||||
return $this->buildSuccess([
|
return $this->buildSuccess([
|
||||||
'list' => $listObj['data'],
|
'list' => $listObj['data'],
|
||||||
'count' => $listObj['total'],
|
'count' => $listObj['total'],
|
||||||
'dataType' => $this->dataType
|
'dataType' => $this->dataType,
|
||||||
|
'apiInfo' => $apiInfo
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
||||||
@ -83,12 +89,12 @@ class Fields extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增字段
|
* 新增字段
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @return array
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function add() {
|
public function add() {
|
||||||
$postData = $this->request->post();
|
$postData = $this->request->post();
|
||||||
$postData['showName'] = $postData['fieldName'];
|
$postData['show_name'] = $postData['field_name'];
|
||||||
$postData['default'] = $postData['defaults'];
|
$postData['default'] = $postData['defaults'];
|
||||||
unset($postData['defaults']);
|
unset($postData['defaults']);
|
||||||
$res = AdminFields::create($postData);
|
$res = AdminFields::create($postData);
|
||||||
@ -106,12 +112,12 @@ class Fields extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段编辑
|
* 字段编辑
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @return array
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function edit() {
|
public function edit() {
|
||||||
$postData = $this->request->post();
|
$postData = $this->request->post();
|
||||||
$postData['showName'] = $postData['fieldName'];
|
$postData['show_name'] = $postData['field_name'];
|
||||||
$postData['default'] = $postData['defaults'];
|
$postData['default'] = $postData['defaults'];
|
||||||
unset($postData['defaults']);
|
unset($postData['defaults']);
|
||||||
$res = AdminFields::update($postData);
|
$res = AdminFields::update($postData);
|
||||||
@ -129,9 +135,9 @@ class Fields extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段删除
|
* 字段删除
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\exception\DbException
|
* @throws \think\exception\DbException
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function del() {
|
public function del() {
|
||||||
$id = $this->request->get('id');
|
$id = $this->request->get('id');
|
||||||
@ -151,11 +157,11 @@ class Fields extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量上传返回字段
|
* 批量上传返回字段
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
* @throws \think\exception\DbException
|
* @throws \think\exception\DbException
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function upload() {
|
public function upload() {
|
||||||
$hash = $this->request->post('hash');
|
$hash = $this->request->post('hash');
|
||||||
@ -166,24 +172,24 @@ class Fields extends Base {
|
|||||||
if ($data === null) {
|
if ($data === null) {
|
||||||
return $this->buildFailed(ReturnCode::EXCEPTION, 'JSON数据格式有误');
|
return $this->buildFailed(ReturnCode::EXCEPTION, 'JSON数据格式有误');
|
||||||
}
|
}
|
||||||
AdminList::update(['returnStr' => json_encode($data)], ['hash' => $hash]);
|
AdminList::update(['return_str' => json_encode($data)], ['hash' => $hash]);
|
||||||
$this->handle($data['data'], $dataArr);
|
$this->handle($data['data'], $dataArr);
|
||||||
$old = (new AdminFields())->where([
|
$old = (new AdminFields())->where([
|
||||||
'hash' => $hash,
|
'hash' => $hash,
|
||||||
'type' => $type
|
'type' => $type
|
||||||
])->select();
|
])->select();
|
||||||
$old = Tools::buildArrFromObj($old);
|
$old = Tools::buildArrFromObj($old);
|
||||||
$oldArr = array_column($old, 'showName');
|
$oldArr = array_column($old, 'show_name');
|
||||||
$newArr = array_column($dataArr, 'showName');
|
$newArr = array_column($dataArr, 'show_name');
|
||||||
$addArr = array_diff($newArr, $oldArr);
|
$addArr = array_diff($newArr, $oldArr);
|
||||||
$delArr = array_diff($oldArr, $newArr);
|
$delArr = array_diff($oldArr, $newArr);
|
||||||
if ($delArr) {
|
if ($delArr) {
|
||||||
AdminFields::destroy(['showName' => ['in', $delArr]]);
|
AdminFields::destroy(['show_name' => ['in', $delArr]]);
|
||||||
}
|
}
|
||||||
if ($addArr) {
|
if ($addArr) {
|
||||||
$addData = [];
|
$addData = [];
|
||||||
foreach ($dataArr as $item) {
|
foreach ($dataArr as $item) {
|
||||||
if (in_array($item['showName'], $addArr)) {
|
if (in_array($item['show_name'], $addArr)) {
|
||||||
$addData[] = $item;
|
$addData[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,11 +206,11 @@ class Fields extends Base {
|
|||||||
private function handle($data, &$dataArr, $prefix = 'data', $index = 'data') {
|
private function handle($data, &$dataArr, $prefix = 'data', $index = 'data') {
|
||||||
if (!$this->isAssoc($data)) {
|
if (!$this->isAssoc($data)) {
|
||||||
$addArr = array(
|
$addArr = array(
|
||||||
'fieldName' => $index,
|
'field_name' => $index,
|
||||||
'showName' => $prefix,
|
'show_name' => $prefix,
|
||||||
'hash' => $this->request->post('hash'),
|
'hash' => $this->request->post('hash'),
|
||||||
'isMust' => 1,
|
'is_must' => 1,
|
||||||
'dataType' => DataType::TYPE_ARRAY,
|
'data_type' => DataType::TYPE_ARRAY,
|
||||||
'type' => $this->request->post('type')
|
'type' => $this->request->post('type')
|
||||||
);
|
);
|
||||||
$dataArr[] = $addArr;
|
$dataArr[] = $addArr;
|
||||||
@ -214,11 +220,11 @@ class Fields extends Base {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$addArr = array(
|
$addArr = array(
|
||||||
'fieldName' => $index,
|
'field_name' => $index,
|
||||||
'showName' => $prefix,
|
'show_name' => $prefix,
|
||||||
'hash' => $this->request->post('hash'),
|
'hash' => $this->request->post('hash'),
|
||||||
'isMust' => 1,
|
'is_must' => 1,
|
||||||
'dataType' => DataType::TYPE_OBJECT,
|
'data_type' => DataType::TYPE_OBJECT,
|
||||||
'type' => $this->request->post('type')
|
'type' => $this->request->post('type')
|
||||||
);
|
);
|
||||||
$dataArr[] = $addArr;
|
$dataArr[] = $addArr;
|
||||||
@ -226,24 +232,24 @@ class Fields extends Base {
|
|||||||
foreach ($data as $index => $datum) {
|
foreach ($data as $index => $datum) {
|
||||||
$myPre = $prefix . $index;
|
$myPre = $prefix . $index;
|
||||||
$addArr = array(
|
$addArr = array(
|
||||||
'fieldName' => $index,
|
'field_name' => $index,
|
||||||
'showName' => $myPre,
|
'show_name' => $myPre,
|
||||||
'hash' => $this->request->post('hash'),
|
'hash' => $this->request->post('hash'),
|
||||||
'isMust' => 1,
|
'is_must' => 1,
|
||||||
'dataType' => DataType::TYPE_STRING,
|
'data_type' => DataType::TYPE_STRING,
|
||||||
'type' => $this->request->post('type')
|
'type' => $this->request->post('type')
|
||||||
);
|
);
|
||||||
if (is_numeric($datum)) {
|
if (is_numeric($datum)) {
|
||||||
if (preg_match('/^\d*$/', $datum)) {
|
if (preg_match('/^\d*$/', $datum)) {
|
||||||
$addArr['dataType'] = DataType::TYPE_INTEGER;
|
$addArr['data_type'] = DataType::TYPE_INTEGER;
|
||||||
} else {
|
} else {
|
||||||
$addArr['dataType'] = DataType::TYPE_FLOAT;
|
$addArr['data_type'] = DataType::TYPE_FLOAT;
|
||||||
}
|
}
|
||||||
$dataArr[] = $addArr;
|
$dataArr[] = $addArr;
|
||||||
} elseif (is_array($datum)) {
|
} elseif (is_array($datum)) {
|
||||||
$this->handle($datum, $dataArr, $myPre, $index);
|
$this->handle($datum, $dataArr, $myPre, $index);
|
||||||
} else {
|
} else {
|
||||||
$addArr['dataType'] = DataType::TYPE_STRING;
|
$addArr['data_type'] = DataType::TYPE_STRING;
|
||||||
$dataArr[] = $addArr;
|
$dataArr[] = $addArr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,8 +259,8 @@ class Fields extends Base {
|
|||||||
/**
|
/**
|
||||||
* 判断是否是关联数组(true表示是关联数组)
|
* 判断是否是关联数组(true表示是关联数组)
|
||||||
* @param array $arr
|
* @param array $arr
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
private function isAssoc(array $arr) {
|
private function isAssoc(array $arr) {
|
||||||
if (array() === $arr) return false;
|
if (array() === $arr) return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user