Пример #1
0
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Пример #2
0
    public function get_platform_data($platform, $signed = 1, $install_id = '', $phone_model = '', $is_beta = null, array $otherInfo)
    {
        $return = array();
        if ($platform == 'j2me') {
            // j2me平台升级包jad文件返回
            if (isset($phone_model) && !empty($phone_model)) {
                $upgradeBrandObj = Upgrade_brand_Model::getInstance();
                $dlIds = $upgradeBrandObj->getDlId($phone_model);
                $sql = <<<EOQ
\t\t        \tSELECT a.`id`,a.`platform`, a.`version`,a.`publish_date`,
\t\t        \t\ta.`download_url`,a.`remark`,a.`force_update`, 
\t\t        \t\ta.`view_version`, a.`file_size`, a.`channel`,
\t\t        \t\tUB.brand_id
\t\t        \tFROM `upgrade` a, upgrade_brand AS UB
\t\t        \tWHERE (a.`ug_ext` = 'jad' OR RIGHT(a.download_url, 3) = 'jad') 
\t\t        \t\tAND a.id = UB.upgrade_id AND UB.brand_id = '{$phone_model}' 
EOQ;
            }
            if (!isset($phone_model) || empty($phone_model)) {
                $sql = <<<EOQ
        \t\tSELECT a.`id`,a.`platform`, a.`version`,a.`publish_date`,
\t\t        \t\ta.`download_url`,a.`remark`,a.`force_update`, 
\t\t        \t\ta.`view_version`, a.`file_size`, a.`channel`
\t\t        FROM `upgrade` a 
\t\t        WHERE (a.`ug_ext` = 'jad' OR RIGHT(a.download_url, 3) = 'jad') 
\t\t        AND mobile_brand = 0
EOQ;
            }
            if (!isset($phone_model) || empty($phone_model)) {
                if (isset($signed)) {
                    if ($signed == 0 || $signed == false) {
                        $sql .= " AND a.signed = 0 ";
                    } elseif (!empty($signed)) {
                        $sql .= " AND a.signed = 1 ";
                    } else {
                        $sql .= " AND a.signed = 1 ";
                    }
                } else {
                    $sql .= " AND a.signed = 1 ";
                }
            } else {
            }
            if ($install_id != '') {
                // 如果有传递渠道,则增加渠道条件
                $sql .= " AND a.channel = \"{$install_id}\"";
            } else {
                // 默认为momo
                $sql .= " AND a.channel = 'momo'";
            }
            if (!is_null($otherInfo['appid'])) {
                $sql .= <<<EOQ
\t\t\t AND appid = '{$otherInfo['appid']}'
EOQ;
            } else {
                $sql .= <<<EOQ
\t\t\t AND (appid = 0 OR appid is null)
EOQ;
            }
            // 是否内测,1:是,0:不是
            if ($is_beta !== null) {
                $sql .= " AND a.alpha = {$is_beta}";
            }
            $sql .= " ORDER BY publish_date DESC, `version` DESC LIMIT 1";
        } else {
            // 除了J2ME外的其他平台
            $sql = <<<EOQ
        \tSELECT * FROM upgrade WHERE platform = '{$platform}' AND patch=0
EOQ;
            if ($install_id != '') {
                $sql .= " AND channel = \"{$install_id}\"";
            }
            if (!is_null($otherInfo['appid'])) {
                $sql .= <<<EOQ
\t\t\t AND appid = '{$otherInfo['appid']}'
EOQ;
            } else {
                $sql .= <<<EOQ
\t\t\t AND (appid = 0 OR appid is null)
EOQ;
            }
            if ($phone_model != '') {
                $sql .= " AND mobile_brand = \"{$phone_model}\"";
            }
            if ($is_beta !== null) {
                $sql .= " AND alpha = {$is_beta}";
            }
            $sql .= " ORDER BY publish_date DESC, `version` DESC LIMIT 1";
        }
        $query = $this->db->query($sql);
        $resultCount = $query->count();
        // 如果有传递appid,但是该应用不存,直接返回结果,不进行二次查询
        if (!is_null($otherInfo['appid']) && $resultCount === 0) {
            //d($query->count());exit;
            $firstQyRes = array();
            $firstQyRes['appid_not_exist'] = TRUE;
            return $firstQyRes;
        }
        if ($query->count()) {
            $result = $query->result_array(FALSE);
            $return = $result[0];
            // 设置了机型,并且机型字段不为空值(NULL, null, 0, "", '', false)
            if (isset($phone_model) && !empty($phone_model)) {
                $maxVersion = $this->getMaxVersForPltChnl($platform, $install_id);
                if (!$return || $return['version'] < $maxVersion) {
                    // 返回通用包
                    // echo $return['version'] . ' ' . $maxVersion;exit;
                    $return = $this->get_platform_data($platform, $signed, $install_id, '', $is_beta);
                } elseif ($platform == 'j2me') {
                    $dlUrlLastPart = substr(strrchr($return['download_url'], '/'), 1);
                    $pos = strrpos($return['download_url'], '/');
                    $return['download_url'] = substr($return['download_url'], 0, $pos) . DIRECTORY_SEPARATOR . 'm' . $phone_model . '_' . $dlUrlLastPart;
                } else {
                }
            }
        }
        if (!$query->count() && (isset($phone_model) && !empty($phone_model))) {
            $return = $this->get_platform_data($platform, $signed, $install_id, '', $is_beta);
        }
        if (!$return) {
            return false;
        }
        if ($platform == 'j2me') {
            $jarFileSize = $this->getJarSize($return['version'], $return['publish_date']);
            $return['file_size'] = $jarFileSize;
        }
        return $return;
    }