TaskList.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class TaskList extends Model
  5. {
  6. protected $table = 'task_list';
  7. protected $fillable = ['user_id', 'title', 'role_id', 'content', 'created_at', 'updated_at', 'state', 'image', 'init_content', 'keyword', 'sd_image',
  8. 'desc', 'sd_id', 'surplus_diamond', 'nickname', 'plot', 'is_handpick', 'sort', 'pinyin_content', 'pdf_path', 'image_path','is_piny'];
  9. public static $state = [
  10. 0 => '已提交',
  11. 1 => '生成中',
  12. 2 => '故事已生成',
  13. 3 => '标题已生成',
  14. 4 => '插画已生成',
  15. 5 => '内容已编辑',
  16. 6 => '已完成',
  17. ];
  18. public function role()
  19. {
  20. return $this->hasOne(UserRole::class, 'id', 'role_id');
  21. }
  22. public function userData()
  23. {
  24. return $this->hasOne(User::class, 'id', 'user_id');
  25. }
  26. public function getCreatedAtAttribute($value)
  27. {
  28. $dateTime = new \DateTime($value);
  29. $dateTime->modify('+8 hours');
  30. // 格式化时间
  31. $formattedTime = $dateTime->format('Y-m-d H:i:s');
  32. return $formattedTime;
  33. }
  34. public function getUpdatedAtAttribute($value)
  35. {
  36. $dateTime = new \DateTime($value);
  37. $dateTime->modify('+8 hours');
  38. // 格式化时间
  39. $formattedTime = $dateTime->format('Y-m-d H:i:s');
  40. return $formattedTime;
  41. }
  42. }