RePayConfig.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Game;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\Redis;
  5. class RePayConfig extends Model
  6. {
  7. protected $connection = 'mysql';
  8. protected $table = 'webgame.RePayConfig';
  9. protected $primaryKey = 'id';
  10. public $timestamps = false;
  11. protected $guarded = []; // Allow mass assignment for all fields
  12. protected $fillable = [
  13. 'PayTotal',
  14. 'PayTimes',
  15. 'WithdrawTotal',
  16. 'LessThan',
  17. 'Condition',
  18. 'Price',
  19. 'Amount',
  20. 'Gift',
  21. 'TimeLimit',
  22. 'Status',
  23. ];
  24. public static function CacheDatas()
  25. {
  26. $key = 'RePayConfig';
  27. if (Redis::exists($key)) {
  28. $all = json_decode(Redis::get($key), true);
  29. }
  30. if (!isset($all) || empty($all) || !count($all)) {
  31. $all = self::all()->where('Status', 1);
  32. $all = json_decode(json_encode($all), true);
  33. Redis::setex($key, 600, json_encode($all));
  34. }
  35. return $all;
  36. }
  37. protected static function boot()
  38. {
  39. parent::boot();
  40. static::updated(function ($model) {
  41. Redis::del('RePayConfig');
  42. });
  43. static::deleted(function ($model) {
  44. Redis::del('RePayConfig');
  45. });
  46. }
  47. }