Setting.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use App\Repositories\Models\Model;
  4. class Setting extends Model
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $table = 'base_settings';
  10. protected $guarded = [];
  11. protected $casts = [
  12. 'value' => 'json',
  13. 'limit' => 'json',
  14. ];
  15. public static function checkCodeIsUnique($code, $ignore_id = 0)
  16. {
  17. return self::query()->where('code', $code)->where('id', '<>', $ignore_id)->exists();
  18. }
  19. /**
  20. * 根据code获取值
  21. * @param $code
  22. * @return string|mixed
  23. */
  24. public static function byCodeGetSetting($code)
  25. {
  26. // return Cache::tags('model')->remember('model:Setting:byCodeGetSetting:' . $code, Carbon::now()->addDays(1), function () use ($code) {
  27. $val = self::query()->where('code', $code)->value('value');
  28. return $val;
  29. // });
  30. }
  31. /**
  32. * 根据codes获取值
  33. * @param array $codes
  34. * @return array|mixed
  35. */
  36. public static function byCodesGetSettings(array $codes)
  37. {
  38. // return Cache::tags('model')->remember('model:Setting:byCodesGetSettings:' . arr2str($codes), Carbon::now()->addDays(1), function () use ($codes) {
  39. return self::query()->whereIn('code', $codes)->pluck('value', 'code')->toArray();
  40. // });
  41. }
  42. }