From 9fd362073f7f4e6a10daef574aa0a67b0fd1ff70 Mon Sep 17 00:00:00 2001 From: holan20180123 <56391770@qq.com> Date: Wed, 12 May 2021 15:23:13 +0800 Subject: [PATCH] * Return id when create object by api. --- module/branch/control.php | 35 ++++++++++++++++++----------------- module/branch/model.php | 9 +++++++-- module/group/model.php | 3 ++- module/project/control.php | 5 ++++- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/module/branch/control.php b/module/branch/control.php index b0600d6024..9e39d84210 100644 --- a/module/branch/control.php +++ b/module/branch/control.php @@ -12,9 +12,9 @@ class branch extends control { /** - * Manage branch - * - * @param int $productID + * Manage branch + * + * @param int $productID * @access public * @return void */ @@ -24,7 +24,8 @@ class branch extends control if($_POST) { - $this->branch->manage($productID); + $newBranches = $this->branch->manage($productID); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $newBranches)); die(js::reload('parent')); } @@ -40,7 +41,7 @@ class branch extends control /** * Sort branch. - * + * * @access public * @return void */ @@ -51,12 +52,12 @@ class branch extends control /** * Ajax get drop menu. - * - * @param int $productID + * + * @param int $productID * @param int $branch - * @param string $module - * @param string $method - * @param string $extra + * @param string $module + * @param string $method + * @param string $extra * @access public * @return void */ @@ -77,10 +78,10 @@ class branch extends control } /** - * Delete branch - * - * @param int $branchID - * @param string $confirm + * Delete branch + * + * @param int $branchID + * @param string $confirm * @access public * @return void */ @@ -100,9 +101,9 @@ class branch extends control /** * Ajax get branches. - * - * @param int $productID - * @param int $oldBranch + * + * @param int $productID + * @param int $oldBranch * @access public * @return void */ diff --git a/module/branch/model.php b/module/branch/model.php index 67274e61c2..6cfd20c981 100644 --- a/module/branch/model.php +++ b/module/branch/model.php @@ -98,7 +98,8 @@ class branchModel extends model public function manage($productID) { $oldBranches = $this->getPairs($productID, 'noempty'); - $data = fixer::input('post')->get(); + $data = fixer::input('post')->get(); + if(isset($data->branch)) { foreach($data->branch as $branchID => $branch) @@ -106,13 +107,17 @@ class branchModel extends model if($oldBranches[$branchID] != $branch) $this->dao->update(TABLE_BRANCH)->set('name')->eq($branch)->where('id')->eq($branchID)->exec(); } } + + $branches = array(); foreach($data->newbranch as $i => $branch) { if(empty($branch)) continue; $this->dao->insert(TABLE_BRANCH)->set('name')->eq($branch)->set('product')->eq($productID)->set('`order`')->eq(count($data->branch) + $i + 1)->exec(); + $branches[] = $this->dao->lastInsertId(); } - return dao::isError(); + if(dao::isError()) return false; + return $branches; } /** diff --git a/module/group/model.php b/module/group/model.php index 9e3b720773..109b1e94f6 100644 --- a/module/group/model.php +++ b/module/group/model.php @@ -27,7 +27,8 @@ class groupModel extends model unset($group->limited); $group->role = 'limited'; } - return $this->dao->insert(TABLE_GROUP)->data($group)->batchCheck($this->config->group->create->requiredFields, 'notempty')->exec(); + $this->dao->insert(TABLE_GROUP)->data($group)->batchCheck($this->config->group->create->requiredFields, 'notempty')->exec(); + return $this->dao->lastInsertId(); } /** diff --git a/module/project/control.php b/module/project/control.php index 356d990c57..540d4b68d4 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -299,6 +299,8 @@ class project extends control } } + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $projectID)); + if($this->app->openApp == 'program') { $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('program', 'browse'))); @@ -612,8 +614,9 @@ class project extends control if(!empty($_POST)) { $_POST['project'] = $projectID; - $this->group->create(); + $groupID = $this->group->create(); if(dao::isError()) die(js::error(dao::getError())); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $groupID)); die(js::closeModal('parent.parent')); }