/** * 唯一实例 * * @return Base_Db_Hash */ public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
public function getDbInstance($table) { return Base_Db_Hash::getInstance()->prepare($table); }
public function getQuestionList($ConditionList, $fields = "*", $order = "desc") { //如果是历史数据 if ($ConditionList['History'] > 0) { //生成历史表名 $table_to_process = Base_Widget::getDbTable($this->table . "_h_" . $ConditionList['History']); //重新建立与历史数据库的链接 $this->db_h = Base_Db_Hash::getInstance()->prepare($table_to_process); //将当前应用的数据库链接置为历史库 $db = $this->db_h; } else { $table_to_process = Base_Widget::getDbTable($this->table); //将当前应用的数据库链接置为线上库 $db = $this->db; } //查询列 $select_fields = array($fields); //初始化查询条件 $whereStartTime = $ConditionList['StartDate'] ? " time >= " . strtotime($ConditionList['StartDate']) . " " : ""; $whereEndTimeTime = $ConditionList['EndDate'] ? " time <= " . (strtotime($ConditionList['EndDate']) + 86400) . " " : ""; $whereQtype = $ConditionList['QtypeId'] ? " qtype = " . $ConditionList['QtypeId'] . " " : ""; $whereParent = $ConditionList['Parent'] >= 0 ? " pid =" . $ConditionList['Parent'] . " " : " pid > 0"; $whereRevocation = $ConditionList['Revocation'] >= 0 ? " revocation = " . $ConditionList['Revocation'] . " " : ""; $whereHelp = $ConditionList['Help'] >= 0 ? " help_status = " . $ConditionList['Help'] . " " : ""; $WhereAccepted = $ConditionList['Accepted'] >= 0 ? " is_hawb = " . $ConditionList['Accepted'] . " " : ""; if (count($ConditionList['AcceptedOperatorList']) >= 1) { $t = array(); foreach ($ConditionList['AcceptedOperatorList'] as $key => $OperatorInfo) { $t[] = "'" . $OperatorInfo['login_name'] . "'"; } $text = implode(",", $t); $whereAcceptedOperatorList = strlen($text) > 0 ? " js_kf in (" . $text . ") " : ""; } $oCategory = new Kubao_Category(); if ($ConditionList['QuestionType']) { $t = explode(",", $ConditionList['QuestionType']); foreach ($t as $k => $v) { if ($v == '0') { $t2[$v] = 0; } else { $CategoryInfo = $oCategory->getCategoryByQuestionType($v, 'id'); if ($CategoryInfo['id'] > 0) { $t2[$v] = $CategoryInfo['id']; } } } $whereCid = $CategoryInfo['id'] ? " cid in (" . implode(",", $t2) . ") " : ""; } $whereHidden = $ConditionList['hidden'] ? " hidden = " . $ConditionList['hidden'] . " " : ""; switch ($ConditionList['QuestionStatus']) { case 0: $whereQuestionStatus = ""; break; case 1: $whereQuestionStatus = " status = '1'"; break; case 2: $whereQuestionStatus = " status != '1'"; break; } $whereCondition = array($whereStartTime, $whereEndTimeTime, $whereQtype, $whereCid, $whereParent, $whereRevocation, $whereQuestionStatus, $whereHidden, $whereHelp, $WhereAccepted, $whereAcceptedOperatorList); //生成查询列 $fields = Base_common::getSqlFields($select_fields); //生成条件列 $where = Base_common::getSqlWhere($whereCondition); //计算记录数量 $CountSql = "SELECT count(1) as QuestionNum FROM {$table_to_process} where 1 " . $where; $QuestionNum = $db->getOne($CountSql); if ($ConditionList['PageSize'] > 0) { //如果记录数量大于页码数量 if ($QuestionNum >= ($ConditionList['Page'] - 1) * $ConditionList['PageSize']) { $Limit = " limit " . ($ConditionList['Page'] - 1) * $ConditionList['PageSize'] . "," . $ConditionList['PageSize']; $sql = "SELECT {$fields} FROM {$table_to_process} where 1 " . $where . $groups . " order by time " . $order . " " . $Limit; $data = $db->getAll($sql); $ReturnArr = array("QuestionNum" => $QuestionNum, "QuestionList" => $data); $ReturnArr['QuestionList'] = $data; } else { $ReturnArr = array("QuestionNum" => 0, "QuestionList" => array()); } } else { $sql = "SELECT {$fields} FROM {$table_to_process} where 1 " . $where . $groups . " order by time " . $order; $data = $db->getAll($sql); $ReturnArr = array("QuestionNum" => $QuestionNum, "QuestionList" => $data); $ReturnArr['QuestionList'] = $data; } return $ReturnArr; }