quanwei
2026-01-17 e1e2fe5710a5b5cd9c19bd3aa99c998a1a613ca8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
 
namespace app\common\model\plus\live;
 
use app\common\model\BaseModel;
 
/**
 * 房间模型
 */
class Room extends BaseModel
{
    protected $name = 'live_room';
    protected $pk = 'room_id';
 
    protected $append = ['show_views', 'status_text', 'start_time_text', 'end_time_text', 'real_start_time_text', 'real_end_time_text'];
 
    /**
     * 计算显示人数 (虚拟人数 + 实际人数)
     */
    public function getShowViewsAttr($value, $data)
    {
        return $data['view_num'] + $data['virtual_num'];
    }
 
    /**
     * 直播间状态。101:直播中,102:未开始,103已结束,104:暂停,107:已过期
     */
    public function getStatusTextAttr($value, $data)
    {
        $liveStatus = [0=>'待审核',100=>'未通过',101 => '直播中', 102 => '未开始', 103 => '已结束', 104 => '暂停', 107 => '已过期'];
        return $liveStatus[$data['live_status']];
    }
 
    /**
     * 直播开始时间
     */
    public function getStartTimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['start_time']);
    }
 
    /**
     * 直播结束时间
     */
    public function getEndTimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['end_time']);
    }
    /**
     * 直播开始时间
     */
    public function getRealStartTimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['real_start_time']);
    }
 
    /**
     * 直播结束时间
     */
    public function getRealEndTimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['real_end_time']);
    }
    /**
     * 关联商品图片表
     */
    public function product()
    {
        return $this->hasMany('app\\common\\model\\plus\\live\\LiveProduct' ,'shop_supplier_id', 'shop_supplier_id')->order(['live_product_id' => 'asc']);
    }
 
    /**
     * 关联当前商品图片表
     */
    public function currentProduct()
    {
        return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
    }
    /**
     * 关联封面图
     */
    public function cover()
    {
        return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'cover_img_id');
    }
 
    /**
     * 关联创建者
     */
    public function user()
    {
        return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id')
            ->field(['user_id', 'nickName', 'avatarUrl']);
    }
 
    /**
     * 关联封面图
     */
    public function share()
    {
        return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'share_img_id');
    }
 
    /**
     * 详情
     */
    public static function detail($room_id, $with = [])
    {
        return (new static())->with($with)->find($room_id);
    }
 
    /**
     * 详情
     */
    public static function detailByUser($user_id, $room_id, $with = ['cover', 'share'])
    {
        return (new static())->with($with)->where('room_id', '=', $room_id)
            ->where('user_id', '=', $user_id)
            ->find();
    }
    /**
     * 关联供应商表
     */
    public function supplier()
    {
        return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id')->field(['shop_supplier_id', 'name', 'address', 'logo_id','fav_count','supplier_type','gift_type']);
    }
}