SystemStatusInfo.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\Redis;
  5. class SystemStatusInfo extends Model
  6. {
  7. protected $primaryKey = 'StatusName'; // Set the primary key
  8. protected $keyType='string';
  9. public $incrementing = false; // Disable auto-increment
  10. public $timestamps = false; // If the table does not have 'created_at' and 'updated_at' columns
  11. protected $table = 'QPAccountsDB.dbo.SystemStatusInfo'; // 数据表名
  12. protected $fillable = [
  13. 'StatusName', 'StatusValue', 'StatusString', 'StatusTip',
  14. 'StatusDescription'
  15. ]; // 可批量赋值的属性
  16. /**
  17. * @param $StatusName
  18. * @param $StatusValue
  19. * @return SystemStatusInfo
  20. */
  21. public static function CacheValue($StatusName,$StatusValue=false)
  22. {
  23. // $key="SystemStatusInfo_$StatusName";
  24. // if(Redis::exists($key)){
  25. // $data=json_decode(Redis::get($key));
  26. // if(!$data){
  27. // Redis::del($key);
  28. // }
  29. // }
  30. if(!isset($data)||empty($data)){
  31. $data = self::query()->where("StatusName", $StatusName)->first();
  32. // Redis::set($key, json_encode($data));
  33. // Redis::expire($key, 600);
  34. }
  35. if($StatusValue!==false){
  36. self::query()->where("StatusName", $StatusName)->update(compact("StatusValue"));
  37. // Redis::del($key);
  38. }
  39. return $data;
  40. }
  41. /**
  42. * @param $StatusName
  43. * @param $StatusValue
  44. * @return SystemStatusInfo
  45. */
  46. public static function OnlyGetCacheValue($StatusName)
  47. {
  48. $data=self::CacheValue($StatusName,false);
  49. return $data->StatusValue;
  50. }
  51. public static $KEY_WithDrawSwitch='WithDrawSwitch';
  52. }