GameBindDouyinOpen.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\common\model;
  3. use think\Cache;
  4. use think\db\Query;
  5. /**
  6. * 系统配置表
  7. * @author Administrator
  8. */
  9. class GameBindDouyinOpen extends \think\Model
  10. {
  11. protected $pk = 'id';
  12. protected $table = 'cy_game_bind_douyin_open';
  13. protected $dateFormat = false; //时间戳格式不自动转换
  14. const CACHE_KEY = "game_bind_douyin_open:";
  15. const CACHE_TAG = "game_bind_douyin_open";
  16. protected static function init()
  17. {
  18. GameBindDouyinOpen::beforeUpdate(function ($model) {
  19. Cache::clear(self::CACHE_TAG);
  20. });
  21. GameBindDouyinOpen::beforeDelete(function () {
  22. Cache::clear(self::CACHE_TAG);
  23. });
  24. }
  25. /**
  26. * 根据 游戏ID 获取配置信息
  27. * @param $game_id
  28. *
  29. * @return array|false|mixed
  30. * @throws \think\Exception
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. */
  35. public static function getInfoByGameId($game_id)
  36. {
  37. if (empty($game_id)) {
  38. return [];
  39. }
  40. $cache_key = self::CACHE_KEY.$game_id;
  41. $info = Cache::get($cache_key);
  42. if (empty($info)) {
  43. $info = self::where(['game_id' => $game_id])->find()->toArray();
  44. if (empty($info)) {
  45. return false;
  46. }
  47. // $info['time'] = time();
  48. Cache::tag(self::CACHE_TAG)->set($cache_key, $info, 3600);
  49. }
  50. return $info;
  51. }
  52. /**
  53. * 根据 app_id 获取配置信息
  54. * @param $app_id
  55. *
  56. * @return array|false|mixed
  57. * @throws \think\Exception
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @throws \think\exception\DbException
  61. */
  62. public static function getInfoByAppId($app_id)
  63. {
  64. if (empty($app_id)) {
  65. return [];
  66. }
  67. $cache_key = self::CACHE_KEY.$app_id;
  68. $info = Cache::get($cache_key);
  69. if (empty($info)) {
  70. $info = self::where(['app_id' => $app_id])->find()->toArray();
  71. if (empty($info)) {
  72. return false;
  73. }
  74. Cache::tag(self::CACHE_TAG)->set($cache_key, $info, 3600);
  75. }
  76. return $info;
  77. }
  78. }