/** * 搜索自媒体 * * @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; }