CreditLedgerEntry.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Concerns\OwnedByAgentAccount;
  4. use App\Services\V3\CreditService;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. /**
  8. * 积分流水的一条。余额 = 流水汇总,见 {@see CreditService}。
  9. */
  10. class CreditLedgerEntry extends Model
  11. {
  12. use OwnedByAgentAccount;
  13. public const KINDS = ['earn', 'spend', 'refund', 'adjust'];
  14. public const BUCKETS = ['free', 'earned'];
  15. protected $table = 'credit_ledger';
  16. protected $guarded = ['id'];
  17. protected $casts = [
  18. 'day' => 'date:Y-m-d',
  19. 'delta' => 'integer',
  20. ];
  21. /**
  22. * 账号对应的用户。只对 account_type = user 有意义:游客的 account_id 是设备 id,碰巧与某个用户 uid 相同也不能当成他。
  23. */
  24. public function user(): BelongsTo
  25. {
  26. return $this->belongsTo(UserInfo::class, 'account_id', 'userid');
  27. }
  28. /**
  29. * 手工调整的操作人(管理员);系统产生的流水为空。
  30. */
  31. public function operator(): BelongsTo
  32. {
  33. return $this->belongsTo(UserInfo::class, 'operator_uid', 'userid');
  34. }
  35. }