123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- * GameHelpCache.php UTF-8
- * web
- *
- * @date : 2018/7/19 10:01
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : Beibao 1.0
- */
- namespace huo\controller\help;
- use huo\controller\common\Base;
- use huo\model\game\GameHelpModel;
- use think\Cache;
- class GameHelpCache extends Base {
- public static function ins() {
- return new static();
- }
- /**
- * 获取QQ KEY
- *
- * @param string $game_id
- *
- * @return string
- */
- private function getGmhKey($game_id) {
- return 'game_help_key_'.$game_id;
- }
- /**
- * 获取账户信息
- *
- * @param string $game_id
- *
- * @return array|bool|mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getInfoByGmhId($game_id) {
- $_key = $this->getGmhKey($game_id);
- $_gmh_data_json = Cache::get($_key);
- $_gmh_data = json_decode($_gmh_data_json, true);
- if (!is_array($_gmh_data)) {
- $_gmh_data = $_gmh_data_json;
- }
- if (!is_array($_gmh_data) || empty($_gmh_data)) {
- $_gmh_data = (new GameHelpModel())->getInfoByAppId($game_id);
- if (empty($_gmh_data)) {
- return false;
- }
- $this->saveGmhCache($game_id, $_gmh_data);
- }
- return $_gmh_data;
- }
- /**
- * 保存玩家cache 数据
- *
- * @param $game_id
- * @param $gmh_data
- * @param int $ttl
- */
- public function saveGmhCache($game_id, $gmh_data, $ttl = 3600) {
- $_key = $this->getGmhKey($game_id);
- Cache::set($_key, json_encode($gmh_data), $ttl);
- }
- /**
- * 更新帐号信息
- *
- * @param string $game_id
- * @param array $gmh_data
- *
- * @return bool
- */
- public function updateGmh($game_id, $gmh_data) {
- $_key = $this->getGmhKey($game_id);
- Cache::rm($_key);
- return (new GameHelpModel())->updateGmh($gmh_data, $game_id);
- }
- }
|