* Finish task #69600.

This commit is contained in:
liuruogu
2022-09-20 09:02:23 +00:00
parent fb03c6c839
commit dfb413dbb8
3 changed files with 57 additions and 11 deletions
+18 -10
View File
@@ -340,10 +340,10 @@ class productModel extends model
* @param string $mode
* @param string $programID
* @param string|array $append
* @param number|bool $shadow
* @param bool $dealShadow: If it is true, the name of the shadow product will be displayed as the name of the project. If it is false, the shadow product will be hidden.
* @return array
*/
public function getPairs($mode = '', $programID = 0, $append = '', $shadow = false)
public function getPairs($mode = '', $programID = 0, $append = '', $dealShadow = false)
{
if(defined('TUTORIAL')) return $this->loadModel('tutorial')->getProductPairs();
@@ -352,31 +352,39 @@ class productModel extends model
$views = empty($append) ? $this->app->user->view->products : $this->app->user->view->products . ",$append";
if($this->config->systemMode == 'new')
{
$select = 't1.*, IF(INSTR(" closed", t1.status) < 2, 0, 1) AS isClosed';
if($dealShadow) $select = 't1.*, IF(t1.shadow = 1, t4.name, t1.name) AS name, IF(INSTR(" closed", t1.status) < 2, 0, 1) AS isClosed';
/* Order by program. */
return $this->dao->select('t1.*, IF(INSTR(" closed", t1.status) < 2, 0, 1) AS isClosed')->from(TABLE_PRODUCT)->alias('t1')
return $this->dao->select($select)->from(TABLE_PRODUCT)->alias('t1')
->leftJoin(TABLE_PROGRAM)->alias('t2')->on('t1.program = t2.id')
->leftJoin(TABLE_PROJECTPRODUCT)->alias('t3')->on('t1.id = t3.product')
->leftJoin(TABLE_PROJECT)->alias('t4')->on('t3.project = t4.id')
->where(1)
->beginIF(strpos($mode, 'all') === false)->andWhere('t1.deleted')->eq(0)->fi()
->beginIF($programID)->andWhere('t1.program')->eq($programID)->fi()
->beginIF(strpos($mode, 'noclosed') !== false)->andWhere('t1.status')->ne('closed')->fi()
->beginIF(!$this->app->user->admin and $this->config->vision == 'rnd')->andWhere('t1.id')->in($views)->fi()
->beginIF(is_numeric($shadow))->andWHere('t1.shadow')->eq($shadow)->fi()
->beginIF(!$dealShadow)->andWhere('t1.shadow')->eq(0)->fi()
->andWhere('t1.vision')->eq($this->config->vision)
->orderBy('isClosed, t2.order_asc, t1.line_desc, t1.order_asc')
->fetchPairs('id', 'name');
}
else
{
$select = 't1.*, IF(INSTR(" closed", t1.status) < 2, 0, 1) AS isClosed';
if($dealShadow) $select = 't1.*, IF(t1.shadow = 1, t3.name, t1.name) AS name, IF(INSTR(" closed", t1.status) < 2, 0, 1) AS isClosed';
$orderBy = !empty($this->config->product->orderBy) ? $this->config->product->orderBy : 'isClosed';
return $this->dao->select('*, IF(INSTR(" closed", status) < 2, 0, 1) AS isClosed')
->from(TABLE_PRODUCT)
->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.id = t2.product')
->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project = t3.id')
->where(1)
->beginIF(strpos($mode, 'all') === false)->andWhere('deleted')->eq(0)->fi()
->beginIF($programID)->andWhere('program')->eq($programID)->fi()
->beginIF(strpos($mode, 'noclosed') !== false)->andWhere('status')->ne('closed')->fi()
->beginIF(!$this->app->user->admin and $this->config->vision == 'rnd')->andWhere('id')->in($views)->fi()
->beginIF(is_numeric($shadow))->andWHere('t1.shadow')->eq($shadow)->fi()
->andWhere('vision')->eq($this->config->vision)
->beginIF(strpos($mode, 'all') === false)->andWhere('t1.deleted')->eq(0)->fi()
->beginIF($programID)->andWhere('t1.program')->eq($programID)->fi()
->beginIF(strpos($mode, 'noclosed') !== false)->andWhere('t1.status')->ne('closed')->fi()
->beginIF(!$this->app->user->admin and $this->config->vision == 'rnd')->andWhere('t1.id')->in($views)->fi()
->beginIF(!$dealShadow)->andWhere('t1.shadow')->eq(0)->fi()
->andWhere('t1.vision')->eq($this->config->vision)
->orderBy($orderBy)
->fetchPairs('id', 'name');
}
+2 -1
View File
@@ -102,7 +102,8 @@ class tree extends control
if($viewType == 'story')
{
/* Set menu.*/
$products = $this->product->getPairs($mode = '', $programID = 0, $append = '', $shadow = 0);
$lib = $this->product->getById($rootID);
$products = $this->product->getPairs($mode = '', $programID = 0, $append = '', !empty($lib->shadow));
$this->product->saveState($rootID, $products);
unset($products[$rootID]);
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env php
<?php
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
include dirname(dirname(dirname(__FILE__))) . '/class/product.class.php';
/**
title=测试productModel->getPairs();
cid=1
pid=1
测试项目集10下的11号产品 >> 正常产品11
测试项目集10下的55号产品 >> 多分支产品55
测试项目集10下的99号产品 >> 多平台产品99
测试不存在的项目集 >> 没有数据
返回所有产品的数量 >> 120
返回项目集10下的所有产品 >> 10
测试项目集10下的未关闭产品5 >> 正常产品6
返回项目集10下的未关闭产品的数量 >> 6
*/
$product = new productTest('admin');
$t_peoduct10 = array('programID'=>'10');
$t_noproduct = array('programID'=>'11');
$t_alproduct = array('programID'=>'0');
$t_notclose5 = array('programID'=>'5');
r($product->getProductPairs($t_peoduct10['programID'])) && p('11') && e('正常产品11'); // 测试项目集10下的11号产品
r($product->getProductPairs($t_peoduct10['programID'])) && p('55') && e('多分支产品55'); // 测试项目集10下的55号产品
r($product->getProductPairs($t_peoduct10['programID'])) && p('99') && e('多平台产品99'); // 测试项目集10下的99号产品
r($product->getProductPairs($t_noproduct['programID'])) && p() && e('没有数据'); // 测试不存在的项目集
r($product->getProductPairsCount($t_alproduct['programID'])) && p() && e('120'); // 返回所有产品的数量
r($product->getProductPairsCount($t_peoduct10['programID'])) && p() && e('10'); // 返回项目集10下的所有产品
r($product->getNoclosedPairs($t_notclose5['programID'])) && p('6') && e('正常产品6'); // 测试项目集10下的未关闭产品5
r($product->getNoclosedPairsCount($t_peoduct10['programID'])) && p() && e('6'); // 返回项目集10下的未关闭产品的数量