public static function getPageList($aParam, $iPage, $sOrder = 'iUpdateTime DESC', $iPageSize = 20, $sUrl = '', $aArg = array()) { $iPage = max($iPage, 1); $sSQL = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE iStatus=' . self::STATUS_VALID; $sCntSQL = 'SELECT COUNT(*) as total FROM ' . self::TABLE_NAME . ' WHERE iStatus=' . self::STATUS_VALID; if (isset($aParam['iID']) && !empty($aParam['iID'])) { $sSQL .= ' AND iID=' . $aParam['iID']; $sCntSQL .= ' AND iID=' . $aParam['iID']; } if (isset($aParam['iCatoryID']) && !empty($aParam['iCatoryID'])) { $sSQL .= ' AND iCatoryID=' . $aParam['iCatoryID']; $sCntSQL .= ' AND iCatoryID=' . $aParam['iCatoryID']; } if (isset($aParam['iIsHot']) && !empty($aParam['iIsHot'])) { $sSQL .= ' AND iIsHot=' . $aParam['iIsHot']; $sCntSQL .= ' AND iIsHot=' . $aParam['iIsHot']; } if (isset($aParam['iIsRecommend']) && !empty($aParam['iIsRecommend'])) { $sSQL .= ' AND iIsRecommend=' . $aParam['iIsRecommend']; $sCntSQL .= ' AND iIsRecommend=' . $aParam['iIsRecommend']; } if (isset($aParam['iUnlockType']) && !empty($aParam['iUnlockType'])) { $sSQL .= ' AND iUnlockType=' . $aParam['iUnlockType']; $sCntSQL .= ' AND iUnlockType=' . $aParam['iUnlockType']; } if (isset($aParam['iUnlockLevel']) && !empty($aParam['iUnlockLevel'])) { $sSQL .= ' AND iUnlockLevel=' . $aParam['iUnlockLevel']; $sCntSQL .= ' AND iUnlockLevel=' . $aParam['iUnlockLevel']; } if (isset($aParam['sName']) && !empty($aParam['sName'])) { $sSQL .= ' AND sName LIKE \'%' . addslashes($aParam['sName']) . '%\''; $sCntSQL .= ' AND sName LIKE \'%' . addslashes($aParam['sName']) . '%\''; } if (isset($aParam['sDesc']) && !empty($aParam['sDesc'])) { $sSQL .= ' AND sDesc LIKE \'%' . addslashes($aParam['sDesc']) . '%\''; $sCntSQL .= ' AND sDesc LIKE \'%' . addslashes($aParam['sDesc']) . '%\''; } if (isset($aParam['iCostsStart']) && !empty($aParam['iCostsStart'])) { $sSQL .= ' AND iCosts >=' . strtotime($aParam['iCostsStart']); $sCntSQL .= ' AND iCosts >=' . strtotime($aParam['iCostsStart']); } if (isset($aParam['iCostsEnd']) && !empty($aParam['iCostsEnd'])) { $sSQL .= ' AND iCosts <=' . strtotime($aParam['iCostsEnd']); $sCntSQL .= ' AND iCosts <=' . strtotime($aParam['iCostsEnd']); } if (isset($aParam['iPriceStart']) && !empty($aParam['iPriceStart'])) { $sSQL .= ' AND iPrice >=' . strtotime($aParam['iPriceStart']); $sCntSQL .= ' AND iPrice >=' . strtotime($aParam['iPriceStart']); } if (isset($aParam['iPriceEnd']) && !empty($aParam['iPriceEnd'])) { $sSQL .= ' AND iPrice <=' . strtotime($aParam['iPriceEnd']); $sCntSQL .= ' AND iPrice <=' . strtotime($aParam['iPriceEnd']); } if (isset($aParam['iAgentRateStart']) && !empty($aParam['iAgentRateStart'])) { $sSQL .= ' AND iAgentRate >=' . strtotime($aParam['iAgentRateStart']); $sCntSQL .= ' AND iAgentRate >=' . strtotime($aParam['iAgentRateStart']); } if (isset($aParam['iAgentRateEnd']) && !empty($aParam['iAgentRateEnd'])) { $sSQL .= ' AND iAgentRate <=' . strtotime($aParam['iAgentRateEnd']); $sCntSQL .= ' AND iAgentRate <=' . strtotime($aParam['iAgentRateEnd']); } if (isset($aParam['iUnlockPointStart']) && !empty($aParam['iUnlockPointStart'])) { $sSQL .= ' AND iUnlockPoint >=' . strtotime($aParam['iUnlockPointStart']); $sCntSQL .= ' AND iUnlockPoint >=' . strtotime($aParam['iUnlockPointStart']); } if (isset($aParam['iUnlockPointEnd']) && !empty($aParam['iUnlockPointEnd'])) { $sSQL .= ' AND iUnlockPoint <=' . strtotime($aParam['iUnlockPointEnd']); $sCntSQL .= ' AND iUnlockPoint <=' . strtotime($aParam['iUnlockPointEnd']); } if (!empty($aParam['iCreateStartTime'])) { $sSQL .= ' AND iCreateTime >=' . strtotime($aParam['iCreateStartTime']); $sCntSQL .= ' AND iCreateTime >=' . strtotime($aParam['iCreateStartTime']); } if (!empty($aParam['iCreateEndTime'])) { $sSQL .= ' AND iCreateTime <=' . strtotime($aParam['iCreateEndTime']); $sCntSQL .= ' AND iCreateTime <=' . strtotime($aParam['iCreateEndTime']); } $sSQL .= ' Order by ' . $sOrder; $sSQL .= ' Limit ' . ($iPage - 1) * $iPageSize . ',' . $iPageSize; $aRet['aList'] = self::getOrm()->query($sSQL); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); $aRet['aPager'] = null; } else { unset($aParam['limit'], $aParam['order']); $ret = self::getOrm()->query($sCntSQL); $aRet['iTotal'] = $ret[0]['total']; $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, '', self::_getNewsPageParam($aParam)); // update by cjj 2015-02-13 分页增加query 参数 } return $aRet; }
/** * 获取列表 * * @param array $aParam * @param string $sOrder * @return array */ public static function getList($aWhere, $iPage, $sOrder = '', $iPageSize = 20, $sUrl = '', $aArg = array(), $bReturnPager = true) { $iPage = max($iPage, 1); $aRet = array(); $aParam = array('where' => $aWhere, 'limit' => ($iPage - 1) * $iPageSize . ',' . $iPageSize, 'order' => $sOrder); $aRet['aList'] = self::getOrm()->fetchAll($aParam); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); if ($bReturnPager) { $aRet['aPager'] = null; } } else { unset($aParam['limit'], $aParam['order']); $aRet['iTotal'] = self::getOrm()->fetchCnt($aParam); if ($bReturnPager) { if (empty($sUrl)) { $sUrl = Util_Common::getUrl(); } if (empty($aArg)) { $aArg = $_REQUEST; } $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, $sUrl, $aArg); } } return $aRet; }
/** * 搜索自媒体 * * @param unknown $aParam * @param string $sOrder * @param number $iPageSize * @return Ambigous <NULL, boolean, string, multitype:multitype: Ambigous <> , multitype:, array/string, int/false, number, unknown, unknown> */ public static function search($aParam, $sOrder = '', $iPageSize = 20) { $aRule = array(); $aTable = array('t_media m'); $aWhere = array('m.iStatus=1', 'm.iPut=1', 'm.iMediaType=' . intval($aParam['type'])); if (!empty($aParam['name'])) { $aWhere[] = '(m.sMediaName LIKE "%' . $aParam['name'] . '%" OR m.sOpenName LIKE "%' . $aParam['name'] . '%")'; } if (!empty($aParam['catid'])) { $aTable[] = 't_media_category c'; $aWhere[] = 'c.iMediaID=m.iMediaID'; $aWhere[] = 'c.iCategoryID=' . intval($aParam['catid']); //$aWhere[] = 'c.iCategoryID IN(' . join(',', $aParam['catid']) . ')'; } if (!empty($aParam['price'])) { $aPrice = Model_Price::parsePrice($aParam['price']); $aWhere[] = '(m.iPrice1>=' . $aPrice[0] . ' AND m.iPrice1<' . $aPrice[1] . ' OR m.iPrice2>=' . $aPrice[0] . ' AND m.iPrice2<' . $aPrice[1] . ')'; } if (!empty($aParam['follower'])) { $aFollower = explode('~', $aParam['follower']); $aWhere[] = '(m.iFollowerNum>=' . $aFollower[0] . ' AND m.iFollowerNum<' . $aFollower[1] . ')'; } if (!empty($aParam['city'])) { $aTable[] = 't_media_city ct'; $aWhere[] = 'ct.iMediaID=m.iMediaID'; $aWhere[] = 'ct.iCityID IN(' . join(',', $aParam['city']) . ')'; } if (!empty($aParam['readnum0'])) { $aWhere[] = 'm.iReadAvgNum >=' . intval($aParam['readnum0']); } if (!empty($aParam['readnum1'])) { $aWhere[] = 'm.iReadAvgNum <=' . intval($aParam['readnum1']); } if (!empty($aParam['score'])) { $aWhere[] = 'm.iScore >=' . intval($aParam['score']); } if (!empty($aParam['tag'])) { $aTable[] = 't_media_tag t'; $aWhere[] = 't.iMediaID=m.iMediaID'; $aWhere[] = 't.iTagID IN(' . join(',', $aParam['tag']) . ')'; } /* if (! empty($aParam['aCriceID'])) { $aTable[] = 't_media_cricle cr'; $aWhere[] = 'cr.iMediaID=m.iMediaID'; $aWhere[] = 'cr.iCricleID IN(' . join(',', $aParam['aCriceID']) . ')'; } */ $iPage = max(intval($aParam['page']), 1); $sLimit = ' LIMIT ' . ($iPage - 1) * $iPageSize . ',' . $iPageSize; $sOrder = empty($sOrder) ? '' : ' ORDER BY ' . $sOrder; $sSQL = 'SELECT m.* FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere) . ' GROUP BY m.iMediaID' . $sOrder . $sLimit; $aRet['aList'] = self::query($sSQL); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); $aRet['aPager'] = null; } else { unset($aParam['limit'], $aParam['order']); $sSQL = 'SELECT COUNT(DISTINCT m.iMediaID) FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere); $aRet['iTotal'] = self::query($sSQL, 'one'); $sUrl = Util_Common::getUrl(); $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, $sUrl, $aParam); } return $aRet; }