AIElement.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class AIElement extends Model
  6. {
  7. use HasFactory;
  8. protected $table = 'mp_ai_elements';
  9. protected $fillable = [
  10. 'id',
  11. 'task_id',
  12. 'external_task_id',
  13. 'task_status',
  14. 'task_status_msg',
  15. 'element_id',
  16. 'element_name',
  17. 'element_description',
  18. 'reference_type',
  19. 'element_image_list',
  20. 'element_video_list',
  21. 'element_voice_id',
  22. 'element_voice_info',
  23. 'tag_list',
  24. 'owned_by',
  25. 'status',
  26. 'callback_url',
  27. 'final_unit_deduction',
  28. ];
  29. protected $casts = [
  30. 'element_image_list' => 'array',
  31. 'element_video_list' => 'array',
  32. 'element_voice_info' => 'array',
  33. 'tag_list' => 'array',
  34. ];
  35. /**
  36. * 任务状态常量
  37. */
  38. const STATUS_SUBMITTED = 'submitted';
  39. const STATUS_PROCESSING = 'processing';
  40. const STATUS_SUCCEED = 'succeed';
  41. const STATUS_FAILED = 'failed';
  42. /**
  43. * 参考类型常量
  44. */
  45. const REFERENCE_TYPE_IMAGE = 'image_refer';
  46. const REFERENCE_TYPE_VIDEO = 'video_refer';
  47. /**
  48. * 主体状态常量
  49. */
  50. const ELEMENT_STATUS_SUCCEED = 'succeed';
  51. const ELEMENT_STATUS_DELETED = 'deleted';
  52. /**
  53. * 标签映射
  54. */
  55. const TAG_MAP = [
  56. 'o_101' => '热梗',
  57. 'o_102' => '人物',
  58. 'o_103' => '动物',
  59. 'o_104' => '道具',
  60. 'o_105' => '服饰',
  61. 'o_106' => '场景',
  62. 'o_107' => '特效',
  63. 'o_108' => '其他',
  64. ];
  65. /**
  66. * 获取标签名称
  67. */
  68. public function getTagNamesAttribute()
  69. {
  70. if (!$this->tag_list) {
  71. return [];
  72. }
  73. return collect($this->tag_list)->map(function ($tag) {
  74. return [
  75. 'tag_id' => $tag['tag_id'],
  76. 'tag_name' => self::TAG_MAP[$tag['tag_id']] ?? '未知',
  77. ];
  78. })->toArray();
  79. }
  80. /**
  81. * 是否为自定义主体
  82. */
  83. public function isCustomElement()
  84. {
  85. return $this->owned_by !== 'kling';
  86. }
  87. /**
  88. * 是否任务成功
  89. */
  90. public function isTaskSucceed()
  91. {
  92. return $this->task_status === self::STATUS_SUCCEED;
  93. }
  94. /**
  95. * 是否主体可用
  96. */
  97. public function isElementAvailable()
  98. {
  99. return $this->status === self::ELEMENT_STATUS_SUCCEED;
  100. }
  101. }