Setting.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use App\Repositories\Enums\ResponseCodeEnum;
  4. use App\Repositories\Enums\Base\AdminTypeEnum;
  5. use App\Repositories\Models\Model;
  6. use Carbon\Carbon;
  7. use Illuminate\Support\Facades\Cache;
  8. use function Symfony\Component\String\b;
  9. class Setting extends Model
  10. {
  11. /**
  12. * @var string
  13. */
  14. protected $table = 'base_settings';
  15. protected $guarded = [];
  16. /**
  17. * The attributes excluded from the model's JSON form.
  18. *
  19. * @var array
  20. */
  21. protected $hidden = [
  22. ];
  23. public static function checkCodeIsUnique($code, $ignore_id = 0)
  24. {
  25. return self::query()->where('code', $code)->where('id', '<>', $ignore_id)->exists();
  26. }
  27. /**
  28. * 根据code获取值
  29. * @param $code
  30. * @return string|mixed
  31. */
  32. public static function byCodeGetSetting($code)
  33. {
  34. // return Cache::tags('model')->remember('model:Setting:byCodeGetSetting:' . $code, Carbon::now()->addDays(1), function () use ($code) {
  35. $val = self::query()->where('code', $code)->value('value');
  36. return $val;
  37. // });
  38. }
  39. /**
  40. * 根据codes获取值
  41. * @param array $codes
  42. * @return array|mixed
  43. */
  44. public static function byCodesGetSettings(array $codes)
  45. {
  46. // return Cache::tags('model')->remember('model:Setting:byCodesGetSettings:' . arr2str($codes), Carbon::now()->addDays(1), function () use ($codes) {
  47. return self::query()->whereIn('code', $codes)->pluck('value', 'code')->toArray();
  48. // });
  49. }
  50. /**
  51. * 获取小程序配置
  52. * @param $type
  53. * @return mixed
  54. */
  55. public static function typeToWxappConfig($type)
  56. {
  57. // return Cache::remember("model:Setting:type2WxappConfig:{$type}", Carbon::now()->addWeek(), function () use ($type) {
  58. // switch ($type) {
  59. //
  60. // case 0:
  61. // //用户
  62. // return [
  63. // 'app_id' => Setting::byCodeGetSetting('system_weapp_user_app_id'),
  64. // 'app_secret' => Setting::byCodeGetSetting('system_weapp_user_app_secret')
  65. // ];
  66. // break;
  67. // default:
  68. // abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '小程序初始化配置失败');
  69. // break;
  70. // }
  71. return [
  72. 'app_id' => config('wechat.mini_program.default.app_id'),
  73. 'app_secret' => config('wechat.mini_program.default.secret'),
  74. ];
  75. // });
  76. }
  77. }