quanwei
2025-11-21 1db9a4130699636cabe7e0c9f7f15d004aadada0
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
<?php
 
namespace app\common\model\plus\regactivity;
 
use app\common\model\BaseModel;
 
/**
 * 活动模型
 */
class Activity extends BaseModel
{
    protected $name = 'registration_activity';
    protected $pk = 'activity_id';
 
    /**
     * 追加字段
     * @var string[]
     */
    protected $append = [
        'register_time_text',
        'activity_time_text',
        'status_text',
    ];
 
    /**
     *报名时间
     * @param $value
     * @param $data
     * @return string
     */
    public function getRegisterTimeTextAttr($value, $data)
    {
        return $data['register_start_time'] ? date('Y-m-d H:i:s', $data['register_start_time']).'至' . date('Y-m-d H:i:s', $data['register_end_time']) : '';
    }
    /**
     * 活动时间
     * @param $value
     * @param $data
     * @return string
     */
    public function getActivityTimeTextAttr($value, $data)
    {
        return $data['activity_start_time'] ? date('Y-m-d H:i:s', $data['activity_start_time']).'至' . date('Y-m-d H:i:s', $data['activity_end_time']) : '';
    }
    /**
     * 活动状态
     * @param $value
     * @param $data
     * @return string
     */
    public function getStatusTextAttr($value, $data)
    {
        if(time() >= $data['activity_start_time'] && ($data['activity_end_time']) >= time()){
            $status_text="活动进行中";
            $status=1;
        }elseif(time() > ($data['activity_end_time'])){
            $status_text="活动已结束";
            $status=2;
        }else{
            $status_text="活动未开始";
            $status=0;
        }
        if(time() >= $data['register_start_time'] && ($data['register_end_time']) >= time()){
            $reg_status_text="报名进行中";
            $reg_status=1;
        }elseif(time() > ($data['register_end_time'])){
            $reg_status_text="已结束报名";
            $reg_status=2;
        }else{
            $reg_status_text="未开始报名";
            $reg_status=0;
        }
        $activity_end_time = date("Y-m-d H:i:s",($data['activity_end_time']));
        $register_end_time = date("Y-m-d H:i:s",($data['register_end_time']));
        return ["status"=>$status,"status_text"=>$status_text,"reg_status"=>$reg_status,"reg_status_text"=>$reg_status_text,"act_end_time"=>$activity_end_time,"reg_end_time"=>$register_end_time];
    }
    /**
     * 关联封面图
     * @return \think\model\relation\HasOne
     */
    public function image()
    {
        return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'image_id');
    }
 
    /**
     * 关联活动分类表
     * @return \think\model\relation\BelongsTo
     */
    public function category()
    {
        $module = self::getCalledModule() ?: 'common';
        return $this->BelongsTo("app\\{$module}\\model\\plus\\regactivity\\Category", 'category_id', 'category_id');
    }
 
    /**
     * 活动详情
     */
    public static function detail($activity_id)
    {
        return (new static())->with(['image', 'category'])->find($activity_id);
    }
}