TeamTalentConfig.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Module\Team\Models;
  3. use App\Module\Team\Enums\TALENT_LEVEL;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. use UCore\ModelCore;
  6. /**
  7. * 达人等级配置
  8. *
  9. * field start
  10. * @property int $id 主键ID
  11. * @property \App\Module\Team\Enums\TALENT_LEVEL $level 等级
  12. * @property string $name 等级名称
  13. * @property int $direct_count_required 所需直推人数
  14. * @property int $team_count_required 所需团队总人数
  15. * @property float $profit_rate 间推分成比例
  16. * @property array $benefits 等级权益
  17. * @property string $icon 等级图标
  18. * @property \Carbon\Carbon $created_at 创建时间
  19. * @property \Carbon\Carbon $updated_at 更新时间
  20. * field end
  21. */
  22. class TeamTalentConfig extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'team_talent_configs';
  30. // attrlist start
  31. protected $fillable = [
  32. 'id',
  33. 'level',
  34. 'name',
  35. 'direct_count_required',
  36. 'team_count_required',
  37. 'profit_rate',
  38. 'benefits',
  39. 'icon',
  40. ];
  41. // attrlist end
  42. /**
  43. * 应该被转换为原生类型的属性
  44. *
  45. * @var array
  46. */
  47. protected $casts = [
  48. 'level' => TALENT_LEVEL::class,
  49. 'profit_rate' => 'float',
  50. 'benefits' => 'json',
  51. ];
  52. /**
  53. * 获取拥有此等级的用户
  54. *
  55. * @return HasMany
  56. */
  57. public function users()
  58. {
  59. return $this->hasMany(TeamUserTalent::class, 'talent_level', 'level');
  60. }
  61. /**
  62. * 获取等级图标的完整URL
  63. *
  64. * @return string|null
  65. */
  66. public function getIconUrlAttribute()
  67. {
  68. if (empty($this->icon)) {
  69. return null;
  70. }
  71. return asset($this->icon);
  72. }
  73. }