Browse Source

feat:后台-视图模型-添加技师资质视图模型

刘学玺 3 months ago
parent
commit
44675f7e64
1 changed files with 144 additions and 0 deletions
  1. 144 0
      app/Models/VCoachAuthRecord.php

+ 144 - 0
app/Models/VCoachAuthRecord.php

@@ -0,0 +1,144 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 技师认证记录视图模型
+ *
+ * 包含字段:
+ * - real_auth_record_id: 实名认证记录ID
+ * - coach_id: 技师编号
+ * - nickname: 技师昵称
+ * - gender: 性别
+ * - phone: 手机号
+ * - portrait_images: 技术形象照
+ * - coach_state: 技师状态
+ * - real_auth_state: 实名认证状态
+ * - id_card_images: 身份证照片
+ * - auditor: 审核人
+ * - audit_time: 审核时间
+ * - audit_remark: 审核回执
+ */
+class VCoachAuthRecord extends Model
+{
+    /**
+     * 关联到模型的数据表
+     *
+     * @var string
+     */
+    protected $table = 'v_coach_auth_record';
+
+    /**
+     * 表明模型是否应该被打上时间戳
+     *
+     * @var bool
+     */
+    public $timestamps = false;
+
+    /**
+     * 可以被批量赋值的属性
+     *
+     * @var array
+     */
+    protected $guarded = [];
+
+    /**
+     * 应该被追加到模型数组的访问器
+     *
+     * @var array
+     */
+    protected $appends = [
+        'portrait_images_url',    // 技术形象照URL
+        'id_card_images_url',     // 身份证照片URL
+        'qual_photo_url',         // 从业资格证URL
+        'business_license_url',    // 营业执照URL
+        'health_certificate_url',  // 健康证URL
+        'avatar_url'              // 头像URL
+    ];
+
+    /**
+     * 获取技术形象照完整URL
+     */
+    public function getPortraitImagesUrlAttribute(): ?array
+    {
+        if (!$this->portrait_images) {
+            return null;
+        }
+
+        $images = is_string($this->portrait_images)
+            ? json_decode($this->portrait_images, true)
+            : $this->portrait_images;
+
+        return array_map(function ($image) {
+            return "/api/download?filename={$image}&bucket=user-avatar";
+        }, $images);
+    }
+
+    /**
+     * 获取身份证照片完整URL
+     */
+    public function getIdCardImagesUrlAttribute(): ?array
+    {
+        if (!$this->id_card_images) {
+            return null;
+        }
+
+        $images = is_string($this->id_card_images)
+            ? json_decode($this->id_card_images, true)
+            : $this->id_card_images;
+
+        return array_map(function ($image) {
+            return "/api/download?filename={$image}&bucket=user-avatar";
+        }, $images);
+    }
+
+    /**
+     * 获取从业资格证完整URL
+     */
+    public function getQualPhotoUrlAttribute(): ?string
+    {
+        return $this->qual_photo
+            ? "/api/download?filename={$this->qual_photo}&bucket=user-avatar"
+            : null;
+    }
+
+    /**
+     * 获取营业执照完整URL
+     */
+    public function getBusinessLicenseUrlAttribute(): ?string
+    {
+        return $this->business_license
+            ? "/api/download?filename={$this->business_license}&bucket=user-avatar"
+            : null;
+    }
+
+    /**
+     * 获取健康证完整URL
+     */
+    public function getHealthCertificateUrlAttribute(): ?string
+    {
+        return $this->health_certificate
+            ? "/api/download?filename={$this->health_certificate}&bucket=user-avatar"
+            : null;
+    }
+
+    /**
+     * 获取头像完整URL
+     */
+    public function getAvatarUrlAttribute(): ?string
+    {
+        return $this->avatar
+            ? "/api/download?filename={$this->avatar}&bucket=user-avatar"
+            : null;
+    }
+
+    /**
+     * 关联技师用户
+     */
+    public function coach()
+    {
+        return $this->belongsTo(CoachUser::class, 'coach_id', 'id');
+    }
+}