123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Repositories\Models\Wechat;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Model;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- class Account extends Model
- {
- /**
- * @var string
- */
- protected $table = 'wechat_accounts';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- protected $casts = ['settings' => 'json'];
- public static function byKeyGetModel($key)
- {
- return Cache::remember("model:wechat:account:byKeyGetModel:{$key}", Carbon::now()->addDay(), function () use ($key) {
- return self::query()->where('key', $key)->where('status', ModelStatusEnum::OK)->first();
- });
- }
- public static function byIdGetModel($id)
- {
- return Cache::remember("model:wechat:account:byIdGetModel:{$id}", Carbon::now()->addDay(), function () use ($id) {
- return self::query()->where('id', $id)->where('status', ModelStatusEnum::OK)->first();
- });
- }
- public static function byNameGetModel($name)
- {
- return Cache::remember("model:wechat:account:byNameGetModel:{$name}", Carbon::now()->addDay(), function () use ($name) {
- return Account::query()->where('name', $name)->where('status', ModelStatusEnum::OK)->first();
- });
- }
- }
|