public function actionGetTotalPage() { $where = 'a.Status = 0'; $os = Yii::app()->request->getParam('os'); $appName = Yii::app()->request->getParam('app_name'); $mainCategory = Yii::app()->request->getParam('main_category'); if ($appName) { $where .= ' AND a.AppName like "%' . $appName . '%"'; } if ($os) { $where .= ' AND s.OS = "' . addslashes($os) . '"'; } if ($mainCategory != -1) { $categoryModel = new Category(); $where .= ' AND a.MainCategory ' . $categoryModel->getCategoryCondition($mainCategory); } $count = Yii::app()->db->createCommand()->select('count(a.Id) as count')->from('app_info_list a')->join('source s', 'a.SourceId = s.ID')->join('category c', 'a.MainCategory = c.ID')->where($where)->queryRow(); echo new ReturnInfo(0, $count['count']); }
static function getData($order = 1, $type = null, $search = '', $category = '', $offset = 0, $limit = 25, $maxid = 0) { //app的排序 switch ($order) { case 1: $order = 'Sort desc'; break; case 2: $order = 'FastUp desc'; break; case 3: $order = 'MostComment desc'; break; case 4: $order = 'Up desc'; break; default: $order = 'Sort desc'; break; } $criteria = new CDbCriteria(); $criteria->order = $order; //app类型:ios or android if ($type) { if ($type == 1) { $criteria->addCondition("SourceId = 1"); } elseif ($type == 2) { $criteria->addCondition("SourceId > 1"); } } //搜索条件 if (!empty($search)) { $condition = implode(',', array_map(function ($category) { return $category->ID; }, Category::model()->findAll(array("select" => "ID", 'condition' => 'Name like :search', 'params' => array(':search' => "%" . $search . "%"))))); $where = "AppName like '%" . addslashes($search) . "%'"; if (!empty($condition)) { $where .= " or MainCategory in (" . $condition . ")"; } $criteria->addCondition($where); } //app的分类 if (!empty($category)) { $categoryModel = new Category(); $categoryCondition = $categoryModel->getCategoryCondition($category); if ($categoryCondition) { $criteria->addCondition("MainCategory " . $categoryCondition); } } if ($maxid) { $criteria->addCondition("Id <= :maxid"); $criteria->params[':maxid'] = $maxid; } $data = array(); $data['pageCount'] = ceil(AppInfoList::model()->published()->count($criteria) / $limit); $criteria->offset = $offset; $criteria->limit = $limit; $appsInfo = AppInfoList::model()->published()->findAll($criteria); $userID = Yii::app()->user->id; $aData = self::parseData($appsInfo, $userID); $data['data'] = $aData; return $data; }