123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- * QqCache.php UTF-8
- * QQ信息
- *
- * @date : 2018/5/3 15:12
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\help;
- use huo\controller\common\Base;
- use huo\model\conf\QqConfModel;
- use huolib\constant\CommonConst;
- use think\Cache;
- class QqCache extends Base {
- protected $cache_tag = 'game_help_tag';
- public static function ins() {
- return new static();
- }
- /**
- * 获取QQ KEY
- *
- * @param string $qq_id
- *
- * @return string
- */
- private function getQQKey($qq_id) {
- return 'qq_key_'.$qq_id;
- }
- /**
- * 获取账户信息
- *
- * @param string $qq_id
- *
- * @return array|bool|mixed
- */
- public function getInfoByQqId($qq_id) {
- $_key = $this->getQQKey($qq_id);
- $_qq_data_json = Cache::get($_key);
- $_qq_data = json_decode($_qq_data_json, true);
- if (!is_array($_qq_data)) {
- $_qq_data = $_qq_data_json;
- }
- if (!is_array($_qq_data) || empty($_qq_data)) {
- $_qq_data = (new QqConfModel())->getInfoByQqId($qq_id);
- if (empty($_qq_data)) {
- return false;
- }
- $this->saveQqCache($qq_id, $_qq_data);
- }
- return $_qq_data;
- }
- /**
- * 保存玩家cache 数据
- *
- * @param $qq_id
- * @param $_qq_data
- * @param int $ttl
- */
- public function saveQqCache($qq_id, $_qq_data, $ttl = CommonConst::CONST_HOUR_SECONDS) {
- $_key = $this->getQQKey($qq_id);
- Cache::tag($this->cache_tag)->set($_key, json_encode($_qq_data), $ttl);
- }
- /**
- * 更新帐号信息
- *
- * @param string $qq_id
- * @param array $qq_data
- *
- * @return bool
- */
- public function updateQq($qq_id, $qq_data) {
- //$_key = $this->getQQKey($qq_id);
- Cache::clear($this->cache_tag);
- return (new QqConfModel())->updateQq($qq_data, $qq_id);
- }
- /**
- * 获取多QQ号
- *
- * @param $qq_ids
- * @param $type
- *
- * @return array|bool|mixed|null
- */
- public function getQqByIds($qq_ids, $type) {
- $_tag = $this->cache_tag;
- $_key = md5($_tag.json_encode($qq_ids).$type);
- $_qq_data_json = Cache::get($_key);
- $_qq_data = json_decode($_qq_data_json, true);
- if (!is_array($_qq_data)) {
- $_qq_data = $_qq_data_json;
- }
- if (!is_array($_qq_data) || empty($_qq_data)) {
- $_qq_data = (new QqConfModel())->getInfoByQqIds($qq_ids, $type);
- if (empty($_qq_data)) {
- return false;
- }
- Cache::tag($this->cache_tag)->set($_key, json_encode($_qq_data), CommonConst::CONST_HOUR_SECONDS);
- }
- return $_qq_data;
- }
- }
|