123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace huo\controller\wallet;
- use huo\controller\common\Base;
- use huo\model\finance\GmMemModel;
- use think\Cache;
- class GmCache extends Base {
- public static function ins() {
- return new static();
- }
-
- public function getGmKey($mem_id, $app_id) {
- return 'gm_key_'.$mem_id.'_'.$app_id;
- }
-
- public function getRemainByMemGame($mem_id, $app_id) {
- $_gm_data = $this->getInfoByMemGame($mem_id, $app_id);
- if (empty($_gm_data)) {
- return false;
- }
- return $_gm_data['remain'];
- }
-
- public function getInfoByMemGame($mem_id, $app_id) {
- $_key = $this->getGmKey($mem_id, $app_id);
- $_gm_data_json = Cache::get($_key);
- $_gm_data = json_decode($_gm_data_json, true);
- if (!is_array($_gm_data)) {
- $_gm_data = $_gm_data_json;
- }
- if (!is_array($_gm_data) || empty($_gm_data)) {
- $_gm_data = (new GmMemModel())->getInfoByMemGame($mem_id, $app_id);
- if (empty($_gm_data)) {
- return false;
- }
- $this->saveGmCache($mem_id, $app_id, $_gm_data);
- }
- return $_gm_data;
- }
-
- public function saveGmCache($mem_id, $app_id, $gm_data, $ttl = 3600) {
- $_key = $this->getGmKey($mem_id, $app_id);
- Cache::set($_key, json_encode($gm_data), $ttl);
- }
-
- public function updateGm($mem_id, $app_id, $gm_data) {
- $_key = $this->getGmKey($mem_id, $app_id);
- Cache::rm($_key);
- return (new GmMemModel())->updateDataGm($mem_id, $app_id, $gm_data);
- }
- }
|