Browse Source

feat:后台-视图模型-技师基本信息

刘学玺 3 months ago
parent
commit
7640468056
1 changed files with 112 additions and 0 deletions
  1. 112 0
      app/Models/VCoachInfo.php

+ 112 - 0
app/Models/VCoachInfo.php

@@ -0,0 +1,112 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 技师信息视图模型
+ *
+ * 包含字段:
+ * - coach_id: 技师编号
+ * - user_id: 用户ID
+ * - nickname: 昵称
+ * - avatar: 头像
+ * - gender: 性别
+ * - mobile: 手机号
+ * - birthday: 出生日期
+ * - work_years: 从业年份
+ * - intention_city: 意向城市
+ * - introduction: 个人简介
+ * - life_photos: 生活照片
+ * - coach_state: 技师状态
+ * - info_state: 基本信息认证状态
+ * - info_audit_remark: 基本信息审核回执
+ * - info_auditor: 基本信息审核人
+ * - info_audit_time: 基本信息审核时间
+ */
+class VCoachInfo extends Model
+{
+    /**
+     * 关联到模型的数据表
+     *
+     * @var string
+     */
+    protected $table = 'v_coach_info';
+
+    /**
+     * 表明模型是否应该被打上时间戳
+     *
+     * @var bool
+     */
+    public $timestamps = false;
+
+    /**
+     * 可以被批量赋值的属性
+     *
+     * @var array
+     */
+    protected $guarded = [];
+
+    /**
+     * 应该被追加到模型数组的访问器
+     *
+     * @var array
+     */
+    protected $appends = [
+        'avatar_url',           // 头像URL
+        'life_photos_url',      // 生活照片URL数组
+    ];
+
+    /**
+     * 获取头像完整URL
+     */
+    public function getAvatarUrlAttribute(): ?string
+    {
+        if (!$this->avatar) {
+            return null;
+        }
+
+        // 如果是微信完整链接(http或https开头),直接返回
+        if (preg_match('/^https?:\/\//', $this->avatar)) {
+            return $this->avatar;
+        }
+
+        // 否则拼接下载路径
+        return "/api/download?filename={$this->avatar}&bucket=user-avatar";
+    }
+
+    /**
+     * 获取生活照片完整URL数组
+     */
+    public function getLifePhotosUrlAttribute(): ?array
+    {
+        if (!$this->life_photos) {
+            return null;
+        }
+
+        $photos = is_string($this->life_photos)
+            ? json_decode($this->life_photos, true)
+            : $this->life_photos;
+
+        return array_map(function ($photo) {
+            return "/api/download?filename={$photo}&bucket=user-avatar";
+        }, $photos);
+    }
+
+    /**
+     * 关联技师用户
+     */
+    public function coach()
+    {
+        return $this->belongsTo(CoachUser::class, 'coach_id', 'id');
+    }
+
+    /**
+     * 关联用户
+     */
+    public function user()
+    {
+        return $this->belongsTo(MemberUser::class, 'user_id', 'id');
+    }
+}