AgentRebateRecord.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Models\Agent;
  3. use App\Models\BaseModel;
  4. class AgentRebateRecord extends BaseModel
  5. {
  6. public const STATUS_PENDING = 'pending';
  7. public const STATUS_CREDITED = 'credited';
  8. public const GAME_TYPE_NAMES = [
  9. 0 => '历史汇总',
  10. 1 => '真人',
  11. 2 => '电子',
  12. 3 => '彩票',
  13. 4 => '体育',
  14. 5 => '电竞',
  15. 6 => '捕鱼',
  16. 7 => '棋牌',
  17. ];
  18. protected $table = 'agent_rebate_records';
  19. protected $hidden = ['snapshot'];
  20. protected $guarded = [];
  21. protected $appends = ['agent_username', 'game_type_text', 'flow_status_text', 'profit_status_text'];
  22. protected $casts = [
  23. 'settlement_date' => 'date', 'agent_id' => 'integer', 'game_type' => 'integer', 'bet_count' => 'integer',
  24. 'bet_amount' => 'decimal:4', 'valid_bet_amount' => 'decimal:4', 'win_loss' => 'decimal:4',
  25. 'flow_rate' => 'decimal:4', 'flow_commission' => 'decimal:4',
  26. 'profit_rate' => 'decimal:4', 'profit_commission' => 'decimal:4',
  27. 'snapshot' => 'array', 'credited_at' => 'datetime',
  28. ];
  29. public function agent()
  30. {
  31. return $this->belongsTo(Agent::class);
  32. }
  33. public function getAgentUsernameAttribute(): string
  34. {
  35. return (string) ($this->agent?->username ?? '');
  36. }
  37. public function getGameTypeTextAttribute(): string
  38. {
  39. return self::GAME_TYPE_NAMES[(int) $this->game_type] ?? '未知';
  40. }
  41. public function getFlowStatusTextAttribute(): string
  42. {
  43. return $this->statusText((string) $this->flow_status);
  44. }
  45. public function getProfitStatusTextAttribute(): string
  46. {
  47. return $this->statusText((string) $this->profit_status);
  48. }
  49. private function statusText(string $status): string
  50. {
  51. return $status === self::STATUS_CREDITED ? '已返佣' : '待返佣';
  52. }
  53. }