From 39d330e45b1c35969af659efae9065b2a7888990 Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 20 Sep 2022 15:37:52 +0800 Subject: [PATCH] * Use the related project's name instead of the product's name if it's a shadow product. --- module/product/control.php | 2 +- module/product/model.php | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/module/product/control.php b/module/product/control.php index f7da20931c..e23ea05624 100644 --- a/module/product/control.php +++ b/module/product/control.php @@ -1143,7 +1143,7 @@ class product extends control $programProducts = array(); - $products = $this->app->tab == 'project' ? $this->product->getProducts($this->session->project) : $this->product->getList(); + $products = $this->app->tab == 'project' ? $this->product->getProducts($this->session->project) : $this->product->getList(0, 'all', 0, 0, 'all'); foreach($products as $product) $programProducts[$product->program][] = $product; diff --git a/module/product/model.php b/module/product/model.php index 84c4d6e4f8..9d6c248a58 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -264,7 +264,7 @@ class productModel extends model */ public function getList($programID = 0, $status = 'all', $limit = 0, $line = 0, $type = 'normal') { - return $this->dao->select('t1.*')->from(TABLE_PRODUCT)->alias('t1') + $products = $this->dao->select('t1.*')->from(TABLE_PRODUCT)->alias('t1') ->leftJoin(TABLE_PROGRAM)->alias('t2')->on('t1.program = t2.id') ->where('t1.deleted')->eq(0) ->beginIF($type == 'normal')->andWhere('t1.shadow')->eq(0)->fi() @@ -289,6 +289,26 @@ class productModel extends model ->orderBy('t2.order_asc, t1.line_desc, t1.order_asc') ->beginIF($limit > 0)->limit($limit)->fi() ->fetchAll('id'); + + if($type == 'all') + { + $shadowProducts = array(); + foreach($products as $product) + { + if($product->shadow) $shadowProducts[] = $product->id; + } + if($shadowProducts) + { + $shadowProducts = $this->dao->select('t1.id,t3.name')->from(TABLE_PRODUCT)->alias('t1') + ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.id=t2.product') + ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project=t3.id') + ->where('t1.id')->in($shadowProducts) + ->fetchPairs(); + foreach($shadowProducts as $id => $name) $products[$id]->name = $name; + } + } + + return $products; } /**