123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Enums\ResponseCodeEnum;
- use App\Repositories\Enums\Base\AdminTypeEnum;
- use App\Repositories\Models\Model;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- use function Symfony\Component\String\b;
- class Setting extends Model
- {
- /**
- * @var string
- */
- protected $table = 'base_settings';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [
- ];
- public static function checkCodeIsUnique($code, $ignore_id = 0)
- {
- return self::query()->where('code', $code)->where('id', '<>', $ignore_id)->exists();
- }
- /**
- * 根据code获取值
- * @param $code
- * @return string|mixed
- */
- public static function byCodeGetSetting($code)
- {
- // return Cache::tags('model')->remember('model:Setting:byCodeGetSetting:' . $code, Carbon::now()->addDays(1), function () use ($code) {
- $val = self::query()->where('code', $code)->value('value');
- return $val;
- // });
- }
- /**
- * 根据codes获取值
- * @param array $codes
- * @return array|mixed
- */
- public static function byCodesGetSettings(array $codes)
- {
- // return Cache::tags('model')->remember('model:Setting:byCodesGetSettings:' . arr2str($codes), Carbon::now()->addDays(1), function () use ($codes) {
- return self::query()->whereIn('code', $codes)->pluck('value', 'code')->toArray();
- // });
- }
- /**
- * 获取小程序配置
- * @param $type
- * @return mixed
- */
- public static function typeToWxappConfig($type)
- {
- // return Cache::remember("model:Setting:type2WxappConfig:{$type}", Carbon::now()->addWeek(), function () use ($type) {
- // switch ($type) {
- //
- // case 0:
- // //用户
- // return [
- // 'app_id' => Setting::byCodeGetSetting('system_weapp_user_app_id'),
- // 'app_secret' => Setting::byCodeGetSetting('system_weapp_user_app_secret')
- // ];
- // break;
- // default:
- // abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '小程序初始化配置失败');
- // break;
- // }
- return [
- 'app_id' => config('wechat.mini_program.default.app_id'),
- 'app_secret' => config('wechat.mini_program.default.secret'),
- ];
- // });
- }
- }
|