From 7d2b061a759458f5895b7cfd62d167357f8078cb Mon Sep 17 00:00:00 2001 From: mayue Date: Thu, 24 Mar 2022 17:06:28 +0800 Subject: [PATCH 1/2] * Fix bug #13804. --- module/product/model.php | 48 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/module/product/model.php b/module/product/model.php index 5d7f95728a..14d9fc42f2 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -596,29 +596,6 @@ class productModel extends model ->remove('uid,newLine,lineName,contactListMenu') ->get(); - if(!empty($_POST['lineName'])) - { - /* Insert product line. */ - $maxOrder = $this->dao->select("max(`order`) as maxOrder")->from(TABLE_MODULE)->where('type')->eq('line')->fetch('maxOrder'); - $maxOrder = $maxOrder ? $maxOrder + 10 : 0; - - $line = new stdClass(); - $line->type = 'line'; - $line->parent = 0; - $line->grade = 1; - $line->name = $this->post->lineName; - $line->root = $this->config->systemMode == 'new' ? $product->program : 0; - $line->order = $maxOrder; - $this->dao->insert(TABLE_MODULE)->data($line)->exec(); - - $lineID = $this->dao->lastInsertID(); - $path = ",$lineID,"; - $this->dao->update(TABLE_MODULE)->set('path')->eq($path)->where('id')->eq($lineID)->exec(); - - if(dao::isError()) return false; - $product->line = $lineID; - } - $product = $this->loadModel('file')->processImgURL($product, $this->config->product->editor->create['id'], $this->post->uid); $programID = isset($product->program) ? $product->program : ''; $this->dao->insert(TABLE_PRODUCT)->data($product)->autoCheck() @@ -630,6 +607,31 @@ class productModel extends model if(!dao::isError()) { $productID = $this->dao->lastInsertID(); + + if(!empty($_POST['lineName'])) + { + /* Insert product line. */ + $maxOrder = $this->dao->select("max(`order`) as maxOrder")->from(TABLE_MODULE)->where('type')->eq('line')->fetch('maxOrder'); + $maxOrder = $maxOrder ? $maxOrder + 10 : 0; + + $line = new stdClass(); + $line->type = 'line'; + $line->parent = 0; + $line->grade = 1; + $line->name = $this->post->lineName; + $line->root = $this->config->systemMode == 'new' ? $product->program : 0; + $line->order = $maxOrder; + $this->dao->insert(TABLE_MODULE)->data($line)->exec(); + + $lineID = $this->dao->lastInsertID(); + $path = ",$lineID,"; + $this->dao->update(TABLE_MODULE)->set('path')->eq($path)->where('id')->eq($lineID)->exec(); + + if(dao::isError()) return false; + + $this->dao->update(TABLE_PRODUCT)->set('line')->eq($laneID)->where('id')->eq($productID)->exec(); + } + $this->file->updateObjectID($this->post->uid, $productID, 'product'); $this->dao->update(TABLE_PRODUCT)->set('`order`')->eq($productID * 5)->where('id')->eq($productID)->exec(); From fb1821c735d0021c2668a20432e116778114a3af Mon Sep 17 00:00:00 2001 From: mayue Date: Thu, 24 Mar 2022 17:19:20 +0800 Subject: [PATCH 2/2] * Optimize code. --- module/product/model.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/module/product/model.php b/module/product/model.php index 14d9fc42f2..8db8f24574 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -596,7 +596,7 @@ class productModel extends model ->remove('uid,newLine,lineName,contactListMenu') ->get(); - $product = $this->loadModel('file')->processImgURL($product, $this->config->product->editor->create['id'], $this->post->uid); + $product = $this->loadModel('file')->processImgURL($product, $this->config->product->editor->create['id'], $this->post->uid); $programID = isset($product->program) ? $product->program : ''; $this->dao->insert(TABLE_PRODUCT)->data($product)->autoCheck() ->batchCheck($this->config->product->create->requiredFields, 'notempty') @@ -610,7 +610,7 @@ class productModel extends model if(!empty($_POST['lineName'])) { - /* Insert product line. */ + /* Create product line. */ $maxOrder = $this->dao->select("max(`order`) as maxOrder")->from(TABLE_MODULE)->where('type')->eq('line')->fetch('maxOrder'); $maxOrder = $maxOrder ? $maxOrder + 10 : 0; @@ -623,13 +623,15 @@ class productModel extends model $line->order = $maxOrder; $this->dao->insert(TABLE_MODULE)->data($line)->exec(); - $lineID = $this->dao->lastInsertID(); - $path = ",$lineID,"; - $this->dao->update(TABLE_MODULE)->set('path')->eq($path)->where('id')->eq($lineID)->exec(); + if(!dao::isError()) + { + $lineID = $this->dao->lastInsertID(); + $path = ",$lineID,"; - if(dao::isError()) return false; + $this->dao->update(TABLE_MODULE)->set('path')->eq($path)->where('id')->eq($lineID)->exec(); - $this->dao->update(TABLE_PRODUCT)->set('line')->eq($laneID)->where('id')->eq($productID)->exec(); + $this->dao->update(TABLE_PRODUCT)->set('line')->eq($laneID)->where('id')->eq($productID)->exec(); + } } $this->file->updateObjectID($this->post->uid, $productID, 'product');