TeamProfit.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Module\Team\Models;
  3. use App\Module\Team\Enums\PROFIT_SOURCE_TYPE;
  4. use App\Module\Team\Enums\REFERRAL_LEVEL;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use UCore\ModelCore;
  7. /**
  8. * 团队收益记录
  9. *
  10. * field start
  11. * @property int $id 主键ID
  12. * @property int $user_id 获得收益的用户ID
  13. * @property int $team_member_id 团队成员ID
  14. * @property int $source_id 收益来源ID
  15. * @property \App\Module\Team\Enums\PROFIT_SOURCE_TYPE $source_type 收益来源类型
  16. * @property int $item_id 物品ID
  17. * @property int $profit_amount 分成收益数量
  18. * @property float $profit_rate 分成比例
  19. * @property \App\Module\Team\Enums\REFERRAL_LEVEL $relation_type 关系类型:1直推,2间推
  20. * @property \Carbon\Carbon $created_at 创建时间
  21. * field end
  22. */
  23. class TeamProfit extends ModelCore
  24. {
  25. /**
  26. * 与模型关联的表名
  27. *
  28. * @var string
  29. */
  30. protected $table = 'team_profits';
  31. /**
  32. * 指示模型是否应该被打上时间戳
  33. *
  34. * @var bool
  35. */
  36. public $timestamps = false;
  37. // attrlist start
  38. protected $fillable = [
  39. 'id',
  40. 'user_id',
  41. 'team_member_id',
  42. 'source_id',
  43. 'source_type',
  44. 'item_id',
  45. 'profit_amount',
  46. 'profit_rate',
  47. 'relation_type',
  48. ];
  49. // attrlist end
  50. /**
  51. * 应该被转换为原生类型的属性
  52. *
  53. * @var array
  54. */
  55. protected $casts = [
  56. 'profit_rate' => 'float',
  57. 'source_type' => PROFIT_SOURCE_TYPE::class,
  58. 'relation_type' => REFERRAL_LEVEL::class,
  59. ];
  60. /**
  61. * 获取收益用户信息
  62. *
  63. * @return BelongsTo
  64. */
  65. public function user()
  66. {
  67. return $this->belongsTo('App\Models\User', 'user_id');
  68. }
  69. /**
  70. * 获取团队成员信息
  71. *
  72. * @return BelongsTo
  73. */
  74. public function teamMember()
  75. {
  76. return $this->belongsTo('App\Models\User', 'team_member_id');
  77. }
  78. /**
  79. * 获取物品信息
  80. *
  81. * @return BelongsTo
  82. */
  83. public function item()
  84. {
  85. return $this->belongsTo('App\Module\GameItems\Models\Item', 'item_id');
  86. }
  87. }