AgentRebateRecord.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Models\Agent;
  3. use App\Models\BaseModel;
  4. /**
  5. * 合营分成每日入账记录。settlement_date 是入账批次日期,platform 存分类 key(如 self:lottery)。
  6. */
  7. class AgentRebateRecord extends BaseModel
  8. {
  9. public const STATUS_PENDING = 'pending';
  10. public const STATUS_CREDITED = 'credited';
  11. /** 分类 key => [game_type 编码, 名称]。 */
  12. public const CATEGORIES = [
  13. 'self:lottery' => [8, 'F1彩票'],
  14. 'self:sport' => [9, 'F1体育'],
  15. 'third:1' => [1, '真人'],
  16. 'third:2' => [2, '电子'],
  17. 'third:4' => [4, '体育'],
  18. 'third:5' => [5, '电竞'],
  19. 'third:6' => [6, '捕鱼'],
  20. 'third:7' => [7, '棋牌'],
  21. ];
  22. protected $table = 'agent_rebate_records';
  23. protected $hidden = ['snapshot'];
  24. protected $guarded = [];
  25. protected $appends = ['agent_username', 'category', 'category_text', 'profit_status_text'];
  26. protected $casts = [
  27. 'settlement_date' => 'date:Y-m-d', 'agent_id' => 'integer', 'game_type' => 'integer', 'bet_count' => 'integer',
  28. 'entry_count' => 'integer',
  29. 'bet_amount' => 'decimal:4', 'valid_bet_amount' => 'decimal:4', 'win_loss' => 'decimal:4',
  30. 'profit_rate' => 'decimal:4', 'profit_commission' => 'decimal:4',
  31. 'snapshot' => 'array', 'credited_at' => 'datetime',
  32. ];
  33. public function agent()
  34. {
  35. return $this->belongsTo(Agent::class);
  36. }
  37. public static function categoryName(string $category): string
  38. {
  39. return self::CATEGORIES[$category][1] ?? $category;
  40. }
  41. public function getAgentUsernameAttribute(): string
  42. {
  43. return (string) ($this->agent?->username ?? '');
  44. }
  45. public function getCategoryAttribute(): string
  46. {
  47. return (string) $this->platform;
  48. }
  49. public function getCategoryTextAttribute(): string
  50. {
  51. return self::categoryName((string) $this->platform);
  52. }
  53. public function getProfitStatusTextAttribute(): string
  54. {
  55. return (string) $this->profit_status === self::STATUS_CREDITED ? '已入账' : '待入账';
  56. }
  57. }