VCoachAuthRecord.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 技师认证记录视图模型
  6. *
  7. * 包含字段:
  8. * - real_auth_record_id: 实名认证记录ID
  9. * - coach_id: 技师编号
  10. * - nickname: 技师昵称
  11. * - gender: 性别
  12. * - phone: 手机号
  13. * - portrait_images: 技术形象照
  14. * - coach_state: 技师状态
  15. * - real_auth_state: 实名认证状态
  16. * - id_card_images: 身份证照片
  17. * - auditor: 审核人
  18. * - audit_time: 审核时间
  19. * - audit_remark: 审核回执
  20. */
  21. class VCoachAuthRecord extends Model
  22. {
  23. /**
  24. * 关联到模型的数据表
  25. *
  26. * @var string
  27. */
  28. protected $table = 'v_coach_auth_record';
  29. /**
  30. * 表明模型是否应该被打上时间戳
  31. *
  32. * @var bool
  33. */
  34. public $timestamps = false;
  35. /**
  36. * 可以被批量赋值的属性
  37. *
  38. * @var array
  39. */
  40. protected $guarded = [];
  41. /**
  42. * 应该被追加到模型数组的访问器
  43. *
  44. * @var array
  45. */
  46. protected $appends = [
  47. 'portrait_images_url', // 技术形象照URL
  48. 'id_card_images_url', // 身份证照片URL
  49. 'qual_photo_url', // 从业资格证URL
  50. 'business_license_url', // 营业执照URL
  51. 'health_certificate_url', // 健康证URL
  52. 'avatar_url' // 头像URL
  53. ];
  54. /**
  55. * 获取技术形象照完整URL
  56. */
  57. public function getPortraitImagesUrlAttribute(): ?array
  58. {
  59. if (!$this->portrait_images) {
  60. return null;
  61. }
  62. $images = is_string($this->portrait_images)
  63. ? json_decode($this->portrait_images, true)
  64. : $this->portrait_images;
  65. return array_map(function ($image) {
  66. return "/api/download?filename={$image}&bucket=user-avatar";
  67. }, $images);
  68. }
  69. /**
  70. * 获取身份证照片完整URL
  71. */
  72. public function getIdCardImagesUrlAttribute(): ?array
  73. {
  74. if (!$this->id_card_images) {
  75. return null;
  76. }
  77. $images = is_string($this->id_card_images)
  78. ? json_decode($this->id_card_images, true)
  79. : $this->id_card_images;
  80. return array_map(function ($image) {
  81. return "/api/download?filename={$image}&bucket=user-avatar";
  82. }, $images);
  83. }
  84. /**
  85. * 获取从业资格证完整URL
  86. */
  87. public function getQualPhotoUrlAttribute(): ?array
  88. {
  89. if (!$this->qual_photo) {
  90. return null;
  91. }
  92. $images = is_string($this->qual_photo)
  93. ? json_decode($this->qual_photo, true)
  94. : $this->qual_photo;
  95. return array_map(function ($image) {
  96. return "/api/download?filename={$image}&bucket=user-avatar";
  97. }, $images);
  98. }
  99. /**
  100. * 获取营业执照完整URL
  101. */
  102. public function getBusinessLicenseUrlAttribute(): ?array
  103. {
  104. if (!$this->business_license) {
  105. return null;
  106. }
  107. $images = is_string($this->business_license)
  108. ? json_decode($this->business_license, true)
  109. : $this->business_license;
  110. return array_map(function ($image) {
  111. return "/api/download?filename={$image}&bucket=user-avatar";
  112. }, $images);
  113. }
  114. /**
  115. * 获取健康证完整URL
  116. */
  117. public function getHealthCertificateUrlAttribute(): ?array
  118. {
  119. if (!$this->health_certificate) {
  120. return null;
  121. }
  122. $images = is_string($this->health_certificate)
  123. ? json_decode($this->health_certificate, true)
  124. : $this->health_certificate;
  125. return array_map(function ($image) {
  126. return "/api/download?filename={$image}&bucket=user-avatar";
  127. }, $images);
  128. }
  129. /**
  130. * 获取头像完整URL
  131. */
  132. public function getAvatarUrlAttribute(): ?string
  133. {
  134. return $this->avatar
  135. ? "/api/download?filename={$this->avatar}&bucket=user-avatar"
  136. : null;
  137. }
  138. /**
  139. * 关联技师用户
  140. */
  141. public function coach()
  142. {
  143. return $this->belongsTo(CoachUser::class, 'coach_id', 'id');
  144. }
  145. }