diff --git a/module/ai/control.php b/module/ai/control.php index 9a4ffc1f91..c99d2b54d6 100644 --- a/module/ai/control.php +++ b/module/ai/control.php @@ -219,12 +219,11 @@ class ai extends control } else if($category === 'discovery') { - $popularIDs = $this->ai->getPopularMiniProgramIDs($pager); - $miniPrograms = $this->ai->getMiniProgramsByID($popularIDs); + $miniPrograms = $this->ai->getMiniPrograms('', 'active', 'createdDate_desc', $pager); } else if($category === 'latest') { - $miniPrograms = $this->ai->getMiniPrograms('', 'active', 'createdDate_desc', $pager); + $miniPrograms = $this->ai->getLatestMiniPrograms($pager); } else { @@ -239,10 +238,14 @@ class ai extends control if(in_array($key, $usedCustomCategories)) $usedCustomCategoryList[$key] = $value; } $squareCategories = $this->lang->ai->miniPrograms->squareCategories; - unset($squareCategories['collection']); - $this->view->collectedIDs = empty($collectedIDs) ? $this->ai->getCollectedMiniProgramIDs($this->app->user->id) : $collectedIDs; + $latestSum = $this->ai->countLatestMiniPrograms(); + if(empty($collectedIDs)) $collectedIDs = $this->ai->getCollectedMiniProgramIDs($this->app->user->id); + if(empty($collectedIDs)) unset($squareCategories['collection']); + if($latestSum == 0) unset($squareCategories['latest']); + + $this->view->collectedIDs = $collectedIDs; $this->view->category = $category; - $this->view->categoryList = empty($this->view->collectedIDs) ? array_merge($squareCategories, $usedCustomCategoryList) : array_merge($this->lang->ai->miniPrograms->squareCategories, $usedCustomCategoryList); + $this->view->categoryList = array_merge($squareCategories, $usedCustomCategoryList); $this->view->pager = $pager; $this->view->miniPrograms = $miniPrograms ?: array(); $this->view->title = $this->lang->ai->miniPrograms->common; diff --git a/module/ai/model.php b/module/ai/model.php index 4b7f6ddce9..6b8da87b60 100644 --- a/module/ai/model.php +++ b/module/ai/model.php @@ -312,20 +312,32 @@ class aiModel extends model } /** - * Get popular mini programIDs. + * Get latest mini programs. * * @param pager $pager * @access public * @return array */ - public function getPopularMiniProgramIDs($pager = null) + public function getLatestMiniPrograms($pager = null, $order = 'createdDate_desc') { - $paris = $this->dao->select('appID, COUNT(*) AS count')->from(TABLE_MINIPROGRAMSTAR) - ->groupBy('appID') - ->orderBy('count_desc') + return $this->dao->select('*') + ->from(TABLE_MINIPROGRAM) + ->where('deleted')->eq('0') + ->andWhere('published')->eq('1') + ->andWhere('createdDate')->ge(date('Y-m-d H:i:s', strtotime('-3 months'))) + ->orderBy($order) ->page($pager) - ->fetchPairs(); - return array_keys($paris); + ->fetchAll(); + } + + public function countLatestMiniPrograms() + { + return $this->dao->select('COUNT(*) as count') + ->from(TABLE_MINIPROGRAM) + ->where('deleted')->eq('0') + ->andWhere('published')->eq('1') + ->andWhere('createdDate')->ge(date('Y-m-d H:i:s', strtotime('-3 months'))) + ->fetch('count'); } public function saveMiniProgramMessage($appID, $type, $content) diff --git a/module/ai/ui/miniprogramchat.html.php b/module/ai/ui/miniprogramchat.html.php index 84a87a1b2d..8ea78dc80b 100644 --- a/module/ai/ui/miniprogramchat.html.php +++ b/module/ai/ui/miniprogramchat.html.php @@ -77,6 +77,7 @@ $star = in_array($miniProgram->id, $collectedIDs) ? 'star' : 'star-empty'; $delete = $star === 'star' ? 'true' : 'false'; btn( + setClass('hidden'), setID('open-dialog'), setData('toggle', 'modal'), setData('target', '#disabled-dialog')