123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace huo\controller\game;
- use huo\controller\common\Base;
- use huo\logic\game\GamePaySwitchLogic;
- use think\Cache;
- class GamePaySwitchCache extends Base {
- public static function ins() {
- return new static();
- }
-
- private function getPaySwitchKey($app_id) {
- return 'switch_id_key_'.$app_id;
- }
-
- public function getInfoByAppId($app_id) {
- $_key = $this->getPaySwitchKey($app_id);
- $_data_json = Cache::get($_key);
- $_data = json_decode($_data_json, true);
- if (!is_array($_data)) {
- $_data = $_data_json;
- }
- if (!is_array($_data) || empty($_data)) {
- $_data = (new GamePaySwitchLogic())->getInfoByAppId($app_id);
- if (empty($_data)) {
- return false;
- }
- $this->savePaySwitchCache($app_id, $_data);
- }
- return $_data;
- }
-
- public function savePaySwitchCache($app_id, $data, $ttl = 3600) {
- $_key = $this->getPaySwitchKey($app_id);
- Cache::set($_key, json_encode($data), $ttl);
- }
-
- public function updatePaySwitch($app_id, $data, $rm_cache = false) {
- if (true == $rm_cache) {
- $_key = $this->getPaySwitchKey($app_id);
- Cache::rm($_key);
- } else {
- $_old_data = $this->getInfoByAppId($app_id);
- if (!empty($_old_data)) {
- $data = array_merge($_old_data, $data);
- }
- $this->savePaySwitchCache($app_id, $data);
- }
- return (new GamePaySwitchLogic())->updatePaySwitch($data, $app_id);
- }
- }
|