Account.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Repositories\Models\Wechat;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use App\Repositories\Models\Model;
  5. use Carbon\Carbon;
  6. use Illuminate\Support\Facades\Cache;
  7. class Account extends Model
  8. {
  9. /**
  10. * @var string
  11. */
  12. protected $table = 'wechat_accounts';
  13. protected $guarded = [];
  14. /**
  15. * The attributes excluded from the model's JSON form.
  16. *
  17. * @var array
  18. */
  19. protected $hidden = [];
  20. protected $casts = ['settings' => 'json'];
  21. public static function byKeyGetModel($key)
  22. {
  23. return Cache::remember("model:wechat:account:byKeyGetModel:{$key}", Carbon::now()->addDay(), function () use ($key) {
  24. return self::query()->where('key', $key)->where('status', ModelStatusEnum::OK)->first();
  25. });
  26. }
  27. public static function byIdGetModel($id)
  28. {
  29. return Cache::remember("model:wechat:account:byIdGetModel:{$id}", Carbon::now()->addDay(), function () use ($id) {
  30. return self::query()->where('id', $id)->where('status', ModelStatusEnum::OK)->first();
  31. });
  32. }
  33. public static function byNameGetModel($name)
  34. {
  35. return Cache::remember("model:wechat:account:byNameGetModel:{$name}", Carbon::now()->addDay(), function () use ($name) {
  36. return Account::query()->where('name', $name)->where('status', ModelStatusEnum::OK)->first();
  37. });
  38. }
  39. }