modified 优化Api字段配置

This commit is contained in:
zhaoxiang 2017-04-26 17:25:29 +08:00
parent c652f7ddbc
commit 839a403f24
3 changed files with 18 additions and 83 deletions

View File

@ -1,67 +0,0 @@
<?php
/**
*
* @since 2017/04/01 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Controller;
class FieldsInfoManageController extends BaseController {
public function index() {
$list = D('ApiFieldsInfo')->order('id asc')->select();
$this->assign('list', $list);
$this->display();
}
public function edit() {
if( IS_GET ) {
$id = I('get.id');
if( $id ){
$detail = D('ApiFieldsInfo')->where(array('id' => $id))->find();
$this->assign('detail', $detail);
$this->display('add');
}else{
$this->redirect('add');
}
}elseif( IS_POST ) {
$data = I('post.');
$res = D('ApiFieldsInfo')->where(array('id' => $data['id']))->save($data);
if( $res === false ) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
}
}
public function add() {
if( IS_POST ) {
$data = I('post.');
$res = D('ApiFieldsInfo')->add($data);
if( $res === false ) {
$this->ajaxError('操作失败');
} else {
$this->ajaxSuccess('添加成功');
}
} else {
$data['hash'] = uniqid();
$this->assign('detail', $data);
$this->display();
}
}
public function del() {
if( IS_POST ) {
$id = I('post.id');
if( $id ) {
D('ApiFieldsInfo')->where(array('id' => $id))->delete();
$this->ajaxSuccess('操作成功');
} else {
$this->ajaxError('缺少参数');
}
}
}
}

View File

@ -110,11 +110,26 @@ class FieldsManageController extends BaseController {
$data = json_decode($jsonStr, true);
D('ApiList')->where(array('hash' => $hash))->save(array('returnStr' => json_encode($data)));
$this->handle($data['data'], $dataArr);
D('ApiFields')->where(array(
$old = D('ApiFields')->where(array(
'hash' => $hash,
'type' => I('post.type')
))->delete();
D('ApiFields')->addAll($dataArr);
))->select();
$oldArr = array_column($old, 'showName');
$newArr = array_column($dataArr, 'showName');
$addArr = array_diff($newArr, $oldArr);
$delArr = array_diff($oldArr, $newArr);
if ($delArr) {
D('ApiFields')->where(array('showName' => array('in', $delArr)))->delete();
}
if ($addArr) {
$addData = array();
foreach ($dataArr as $item) {
if (in_array($item['showName'], $addArr)) {
$addData[] = $item;
}
}
D('ApiFields')->addAll($addData);
}
$this->ajaxSuccess('操作成功');
} else {
$this->display();

View File

@ -1,13 +0,0 @@
<?php
/**
*
* @since 2017/04/01 创建
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace Admin\Model;
class ApiFieldsInfoModel extends BaseModel {
}