| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | <?php/** * GameQqCache.php  UTF-8 * WWW * * @date    : 2018/7/13 20:42 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : chenbingling <cbl@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\controller\game;use huo\controller\common\Base;use huo\logic\game\GameQqLogic;use huo\model\game\GameQqModel;use think\Cache;class GameQqCache extends Base {    protected $tag = 'game_qq_tag';    /**     * 获取KEY     *     * @param string $app_id     *     *     * @return string     */    private function getGameQqKey($app_id) {        return 'game_qq_id_key_'.$app_id;    }    /**     * 获取信息     *     * @param string $app_id     *     *     * @return array|bool|mixed     * @throws \think\Exception     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    public function getGameQqInfo($app_id) {        $_key = $this->getGameQqKey($app_id);        $_game_data_json = Cache::get($_key);        $_game_data = json_decode($_game_data_json, true);        if (!is_array($_game_data)) {            $_game_data = $_game_data_json;        }        if (!is_array($_game_data) || empty($_game_data)) {            $_game_data = (new GameQqLogic())->getGameQqInfo($app_id);            if (empty($_game_data)) {                return false;            }            $this->saveGameQqCache($app_id, $_game_data);        }        return $_game_data;    }    /**     * 保存cache 数据     *     * @param     $app_id     * @param     $_game_data     * @param int $ttl     */    public function saveGameQqCache($app_id, $_game_data, $ttl = 3600) {        $_key = $this->getGameQqKey($app_id);        Cache::tag($this->tag)->set($_key, json_encode($_game_data), $ttl);    }    /**     * 更新信息     *     * @param array $game_data     *     *     * @return bool     */    public function updateGame($game_data) {        Cache::clear($this->tag);        return (new GameQqModel())->updateGame($game_data, $game_data['id']);    }    /**     * 添加信息     *     * @param $game_data     *     * @return bool|mixed     */    public function addGame($game_data) {        Cache::clear($this->tag);        return (new GameQqModel())->addGame($game_data);    }}
 |