* Optimize the code.

This commit is contained in:
xieqiyu
2021-11-18 11:41:17 +08:00
parent 7d15430ab1
commit a9c2c09338
2 changed files with 25 additions and 9 deletions
+24 -8
View File
@@ -3654,16 +3654,32 @@ class executionModel extends model
public function getPlans($products)
{
$this->loadModel('productplan');
$productPlans = array();
foreach($products as $productID => $product)
$branchIDList = array();
foreach($products as $product)
{
$planInfo = $this->productplan->getPairs($product->id, implode(',', $product->branches));
foreach($planInfo as $planID => $plan)
{
if(empty($planID)) continue;
$productPlans[$productID][$planID] = $plan;
}
foreach($product->branches as $branchID) $branchIDList[$branchID] = $branchID;
}
$plans = $this->dao->select('id,title,product,parent,begin,end')->from(TABLE_PRODUCTPLAN)
->where('product')->in(array_keys($products))
->andWhere('deleted')->eq(0)
->andWhere('branch')->in($branchIDList)->fi()
->orderBy('begin desc')
->fetchAll('id');
$plans = $this->productplan->reorder4Children($plans);
$productPlans = array();
$parentTitle = array();
foreach($plans as $plan)
{
if($plan->parent == '-1') $parentTitle[$plan->id] = $plan->title;
if($plan->parent > 0 and isset($parentTitle[$plan->parent])) $plan->title = $parentTitle[$plan->parent] . ' /' . $plan->title;
$productPlans[$plan->product][$plan->id] = $plan->title . " [{$plan->begin} ~ {$plan->end}]";
if($plan->begin == '2030-01-01' and $plan->end == '2030-01-01') $productPlans[$plan->product][$plan->id] = $plan->title . ' ' . $this->lang->productplan->future;
}
return $productPlans;
}
+1 -1
View File
@@ -184,7 +184,7 @@ class productplanModel extends model
$plans = $this->dao->select('id,title,parent,begin,end')->from(TABLE_PRODUCTPLAN)
->where('product')->in($product)
->andWhere('deleted')->eq(0)
->beginIF($branch !== '')->andWhere('branch')->in("$branch")->fi()
->beginIF($branch !== '')->andWhere('branch')->eq($branch)->fi()
->beginIF($expired == 'unexpired')->andWhere('end')->ge($date)->fi()
->beginIF($skipParent)->andWhere('parent')->ne(-1)->fi()
->orderBy('begin desc')