Internal.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Module\Ulogic\Model;
  3. use App\Module\Ulogic\Enum\INTERNAL_TYPE;
  4. use App\Module\User\Services\UserService;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use UCore\ModelCore;
  7. /**
  8. * 站内信
  9. * field start
  10. * @property int $id
  11. * @property int $admin_id 管理员ID
  12. * @property int $from_id 来源用户ID
  13. * @property int $user_id
  14. * @property int $cate 分类
  15. * @property int $is_read 是否已读
  16. * @property string $status 状态
  17. * @property int $type1 类型
  18. * @property string $content 内容
  19. * @property int $template_id 模板ID
  20. * @property string $at_users at的用户
  21. * @property string $data 数据
  22. * @property \Carbon\Carbon $created_at
  23. * @property \Carbon\Carbon $updated_at
  24. * @property \Carbon\Carbon $deleted_at 删除时间
  25. * field end
  26. *
  27. */
  28. class Internal extends ModelCore
  29. {
  30. use SoftDeletes;
  31. protected $casts = [
  32. 'type1' => INTERNAL_TYPE::class
  33. ];
  34. // attrlist start
  35. public static $attrlist = array (
  36. 0 => 'id',
  37. 1 => 'admin_id',
  38. 2 => 'from_id',
  39. 3 => 'user_id',
  40. 4 => 'cate',
  41. 5 => 'is_read',
  42. 6 => 'status',
  43. 7 => 'type1',
  44. 8 => 'content',
  45. 9 => 'template_id',
  46. 10 => 'at_users',
  47. 11 => 'data',
  48. 12 => 'created_at',
  49. 13 => 'updated_at',
  50. 14 => 'deleted_at',
  51. );
  52. //attrlist end
  53. protected $table = 'user_internals';
  54. protected $appends = [
  55. 'from_info'
  56. ];
  57. public function getFromInfoAttribute()
  58. {
  59. if ($this->from_id == 0) {
  60. return [
  61. 'nickname' => '管理员',
  62. 'avatar' => 1
  63. ];
  64. }
  65. $infos = UserService::pinfos([ $this->from_id ]);
  66. return $infos[$this->from_id] ?? [
  67. 'nickname' => '未知',
  68. 'user_id' => $this->from_id,
  69. 'avatar' => 0
  70. ];
  71. }
  72. }