Event.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 Event extends Model
  8. {
  9. /**
  10. * @var string
  11. */
  12. protected $table = 'wechat_events';
  13. protected $guarded = [];
  14. /**
  15. * The attributes excluded from the model's JSON form.
  16. *
  17. * @var array
  18. */
  19. protected $hidden = [];
  20. public static function getSubscribe($account_id)
  21. {
  22. return Cache::remember("model:wechat:event:getSubscribe:{$account_id}", Carbon::now()->addDay(), function () use ($account_id) {
  23. return self::query()->where('account_id', $account_id)->where('type', 'subscribe')->where('status', ModelStatusEnum::OK)->orderByDesc('id')->first();
  24. });
  25. }
  26. public static function getClickEvent($account_id, $key)
  27. {
  28. return Cache::remember("model:wechat:event:getClickEvent:{$account_id}:{$key}", Carbon::now()->addDay(), function () use ($account_id, $key) {
  29. return self::query()->where('account_id', $account_id)->where('type', 'click')->where('event_key', $key)->where('status', ModelStatusEnum::OK)->orderByDesc('id')->first();
  30. });
  31. }
  32. }