Пример #1
0
 public function getRetailerByProducts($intPage, $productIds, $type, $city, $status, &$total)
 {
     if (!$selectField) {
         $selectField = '*';
     }
     $arrIDs = global_common::splitString($productIds);
     $strQueryIN = global_common::convertToQueryIN($arrIDs);
     if ($strQueryIN) {
         $strQueryIN = global_mapping::ProductID . ' IN( ' . $strQueryIN . ') and';
     } else {
         $strQueryIN = '1 != and';
     }
     if ($city) {
         $city = ' and `' . global_mapping::CityID . '` = ' . $city . ' ';
     } else {
         $city = ' and 1=1 ';
     }
     if ($type) {
         $type = ' and `' . global_mapping::ProductStatusID . '` = ' . $type . ' ';
     } else {
         $type = ' and 1=1 ';
     }
     if ($status) {
         $status = '  (`' . global_mapping::StatusID . '` = ' . global_common::STATUS_ACTIVE . ' or `' . global_mapping::StatusID . '` is null)';
     } else {
         $status = '  `' . global_mapping::StatusID . '` = ' . global_common::STATUS_INACTIVE;
     }
     if ($intPage > 0) {
         $strSQLCount = global_common::prepareQuery(global_common::SQL_SELECT_FREE, array("count(*)", self::TBL_SL_RETAILER, 'WHERE ' . $strQueryIN . $status . $type . $city));
         $strSQL = global_common::prepareQuery(global_common::SQL_SELECT_FREE, array($selectField, self::TBL_SL_RETAILER, 'WHERE ' . $strQueryIN . $status . $type . $city . $orderBy . ' limit ' . ($intPage - 1) * self::NUM_PER_PAGE . ',' . self::NUM_PER_PAGE));
     } else {
         $strSQL = global_common::prepareQuery(global_common::SQL_SELECT_FREE, array($selectField, self::TBL_SL_RETAILER, 'WHERE ' . $strQueryIN . $status . $type . $city));
     }
     //echo '<br>SQL:'.$strSQL;
     $arrResult = $this->_objConnection->selectCommand($strSQL);
     if (!$arrResult) {
         global_common::writeLog('get sl_retailer ByID:' . $strSQL, 1, $_mainFrame->pPage);
         return null;
     }
     if ($strSQLCount) {
         //echo $strSQLCount;
         $arrTotal = $this->_objConnection->selectCommand($strSQLCount);
         $total = $arrTotal[0][0];
     }
     //echo $total;
     $productIDs = global_common::getArrayColumn($arrResult, global_mapping::ProductID);
     //print_r($productIDs);
     $productIDs = array_unique($productIDs);
     $objProduct = new Model_Product($this->_objConnection);
     $products = $objProduct->getProductByIDs($productIDs);
     $temp = array();
     foreach ($products as $key => $info) {
         $temp[$info[global_mapping::ProductID]] = $info;
         unset($products[$key]);
     }
     $products = $temp;
     //print_r($products);
     $objStatus = new Model_Status($this->_objConnection);
     $allStatus = $objStatus->getAllStatus();
     $statuses = array();
     foreach ($allStatus as $key => $info) {
         $statuses[$info[global_mapping::StatusID]] = $info;
         unset($allStatus[$key]);
     }
     $count = count($arrResult);
     for ($i = 0; $i < $count; $i++) {
         $arrResult[$i][global_mapping::ProductStatus] = $statuses[$arrResult[$i][global_mapping::ProductStatusID]][global_mapping::StatusName];
         $arrResult[$i][global_mapping::ProductName] = $products[$arrResult[$i][global_mapping::ProductID]][global_mapping::ProductName];
     }
     $arrResult = global_common::mergeUserInfo($arrResult, $this->_objConnection);
     //print_r($arrResult);
     return $arrResult;
 }