| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 | <?php/** * GameversionModel.php UTF-8 * 游戏版本表 * * @date    : 2017/11/23 15:20 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : wuyonghong <wyh@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\model\game;use huo\model\common\CommonModel;use huolib\constant\CacheConst;use huolib\constant\CommonConst;use think\Cache;class GameversionModel extends CommonModel {    protected $name   = 'game_version';    protected $insert = ['version_key', 'version', 'content'];    // 开启自动写入时间戳字段    protected $autoWriteTimestamp = true;    protected $cache_tag          = 'game_version_key';    protected $cache_key_prefix   = CacheConst::CACHE_GAME_VERSION_PREFIX;    /**     * 基础查询     *     * @param $query     */    protected function base($query) {        $query->where('delete_time', 0)->where('is_default', 2);    }    protected function game() {        return $this->belongsTo('huo\model\game\GameModel', 'app_id');    }    public function gamex() {        return $this->belongsTo('huo\model\game\GameModel', 'app_id')->setEagerlyType(0);    }// 小程序不需要  2018-09-20 chenbingling//    public function getPackageUrlAttr($value) {//        if (!empty($value)) {//            return huo_get_down_url($value);//        }////        return $value;//    }    public function getSizeAttr($value) {        return huo_format_file_size($value);    }    public function setVersionKeyAttr($value, $data) {        return md5($data['app_id'].time().uniqid());    }    public function setVersionAttr($value) {        return empty($value) ? '1.0' : $value;    }    public function setContentAttr($value) {        return empty($value) ? '' : $value;    }    public function addVersion($data) {        if (empty($data) || empty($data['app_id'])) {            return false;        }        $_map['app_id'] = $data['app_id'];        $data['is_default'] = 1;        $_cnt = self::where($_map)->count();        if (empty($_cnt)) {            $data['is_default'] = 2;        }        if ($_obj = self::create($data, true)) {            return $_obj->id;        } else {            return false;        }    }    /***     * 获取版本id对应的游戏名称列     *     * @param int $is_default     * @param int $is_delete     *     * @return array     */    public function getClientIdName($is_default = 2, $is_delete = 2) {        $_map['gameversion_model.is_default'] = $is_default;        $_map['gameversion_model.is_delete'] = $is_delete;        $_field = "CONCAT(gamex.name,' v',gameversion_model.version,' (',gameversion_model.id,')')";        $_games = $this->useGlobalScope(false)                       ->with('gamex')                       ->where($_map)                       ->column($_field, 'gameversion_model.id');        return $_games;    }    /**     * 获取版本key     *     * @param $map     *     * @return mixed     */    public function getVersionKey($map) {        $key = 'version_key'.json_encode($map);        return $this->useGlobalScope(false)->cache($key, CommonConst::CONST_DAY_SECONDS, $this->cache_tag)->where($map)                    ->value('version_key');    }    /**     * 根据游戏ID获取默认信息     *     * @param int $app_id 应用ID     *     * @return array|bool|false     */    public function getDefaultInfoByAppId($app_id) {        $_id = $this->getDefaultIdByAppId($app_id);        if (empty($_id)) {            return false;        }        $_data = $this->getInfoById($_id);        return $_data;    }    /**     * 获取默认单条记录缓存key     *     * @param int $app_id 应用ID     *     * @return string     */    protected function getDefaultCacheKey($app_id) {        return $this->cache_key_prefix.'default'.$app_id;    }    /**     * 获取默认版本ID     *     * @param int $app_id 应用ID     *     * @return int     */    public function getDefaultIdByAppId($app_id) {        if (empty($app_id)) {            return 0;        }        $_default_cache_key = $this->getDefaultCacheKey($app_id);        $_id = Cache::get($_default_cache_key);        if (!empty($_id)) {            return $_id;        }        /* 取默认 */        $_map = [            'app_id'     => $app_id,            'is_default' => CommonConst::CONST_DEFAULT,            'is_delete'  => CommonConst::CONST_NOT_DELETE        ];        $_id = $this->where($_map)->value('id');        if (empty($_id)) {            return 0;        }        Cache::set($_default_cache_key, $_id);        return $_id;    }    /**     * 根据游戏ID获取包地址     *     * @param int $app_id 应用ID     *     * @return string     */    public function getPackageUrlByAppId($app_id) {        $_data = $this->getDefaultInfoByAppId($app_id);        $_package_url = get_val($_data, 'package_url', '');        return $_package_url;    }}
 |