/** * get user row data * @return array userInfo */ private function getUserInfo() { $user_id = $this->getId(); $key = md5(self::USER_KEY . $user_id); $data = UtilD::getCache(__CLASS__, $key); if (!$data) { $data = Yii::$app->getDb()->createCommand("SELECT * FROM {{%admin}} WHERE id=" . $user_id . " AND status=" . Admin::STATUS_ACTIVE)->queryOne(); if ($data) { UtilD::setCache(__CLASS__, $key, $data); } } return $data; }
private function getAllArea() { $key = md5(self::CACHE_KEY . 'AllData'); $allArea = UtilD::getCache(__CLASS__, $key); if (!$allArea) { $sql = "SELECT id,area_code,area_name,depth,full_name,pid FROM " . self::tableName() . " WHERE sta=1 AND depth<=4 ORDER BY priority ASC,sort ASC,area_code ASC"; $result = \yii::$app->getDb()->createCommand($sql)->queryAll(); foreach ($result as $row) { $allArea[$row['area_code']] = $row; $fullName = explode(',', $allArea[$row['area_code']]['full_name']); if (count($fullName)) { unset($fullName[0]); $allArea[$row['area_code']]['full_name'] = implode(',', $fullName); } else { $allArea[$row['area_code']]['full_name'] = str_replace('中国', '全国', $allArea[$row['area_code']]['full_name']); } } UtilD::setCache(__CLASS__, $key, $allArea); } return $allArea; }
/** * 从缓存中获取一条记录,无则从DB找查找 * @param string $code * @return mixed */ public static function loadRowData($code) { $key = md5(self::CACHE_KEY . "_code_" . $code); $data = UtilD::getCache(__CLASS__, $key); if (!$data) { $data = static::find()->where("code='{$code}'")->one(); if (is_null($data)) { return false; } UtilD::setCache(__CLASS__, $key, $data); } return $data; }