PromotionTalentConfig.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Module\Promotion\Models;
  3. use App\Module\Promotion\Enums\TALENT_LEVEL;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. use UCore\ModelCore;
  6. /**
  7. * 达人等级配置
  8. *
  9. * field start
  10. * field end
  11. */
  12. class PromotionTalentConfig extends ModelCore
  13. {
  14. /**
  15. * 与模型关联的表名
  16. *
  17. * @var string
  18. */
  19. protected $table = 'promotion_talent_configs';
  20. // attrlist start
  21. protected $fillable = [
  22. ];
  23. // attrlist end
  24. /**
  25. * 应该被转换为原生类型的属性
  26. *
  27. * @var array
  28. */
  29. protected $casts = [
  30. 'level' => TALENT_LEVEL::class,
  31. 'profit_rate' => 'float',
  32. 'benefits' => 'json',
  33. ];
  34. /**
  35. * 获取拥有此等级的用户
  36. *
  37. * @return HasMany
  38. */
  39. public function users()
  40. {
  41. return $this->hasMany(PromotionUserTalent::class, 'talent_level', 'level');
  42. }
  43. /**
  44. * 获取等级图标的完整URL
  45. *
  46. * @return string|null
  47. */
  48. public function getIconUrlAttribute()
  49. {
  50. if (empty($this->icon)) {
  51. return null;
  52. }
  53. return asset($this->icon);
  54. }
  55. }