| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | <?php/** * GamePayShowCache.php UTF-8 * 充值显示规则缓存 * * @date    : 2019/8/27 19:55 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : dengcongshuai <dcs@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\controller\game;use huo\controller\common\Base;use huo\logic\game\GamePayShowLogic;use huolib\constant\CacheConst;use think\Cache;class GamePayShowCache extends Base {    public static function ins() {        return new static();    }    /**     * 获取KEY     *     * @param string $app_id     *     * @return string     */    private function getPayShowKey($app_id) {        return CacheConst::CACHE_GAME_PAY_SHOW_PREFIX.$app_id;    }    /**     * 获取信息     *     * @param string $app_id     *     * @return array|bool|mixed     */    public function getInfoByAppId($app_id) {        $_key = $this->getPayShowKey($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 GamePayShowLogic())->getInfoByAppId($app_id);            if (empty($_data)) {                return false;            }            $this->savePayShowCache($app_id, $_data);        }        return $_data;    }    /**     * 保存cache 数据     *     * @param     $app_id     * @param     $data     * @param int $ttl     */    public function savePayShowCache($app_id, $data, $ttl = 3600) {        $_key = $this->getPayShowKey($app_id);        Cache::set($_key, json_encode($data), $ttl);    }    /**     * 更新信息     *     * @param string $app_id     * @param array  $data     *     * @param bool   $rm_cache 是否删除缓存     *     * @return \huo\model\game\GamePayShowModel     */    public function updatePayShow($app_id, $data, $rm_cache = false) {        if (true == $rm_cache) {            $_key = $this->getPayShowKey($app_id);            Cache::rm($_key);        } else {            $_old_data = $this->getInfoByAppId($app_id);            if (!empty($_old_data)) {                $data = array_merge($_old_data, $data);            }            $this->savePayShowCache($app_id, $data);        }        return (new GamePayShowLogic())->updatePaySwitch($data, $app_id);    }}
 |