150], [['ticket_id'], 'exist', 'skipOnError' => true, 'targetClass' => Tickets::class, 'targetAttribute' => ['ticket_id' => 'id']], [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']], ]; } /** * {@inheritdoc} */ public function attributeLabels(): array { return [ 'id' => '工单消息id', 'ticket_id' => '归属的工单id', 'user_id' => '消息发送者id', 'message' => '消息内容', 'created_at' => '发送时间', 'ip' => 'ip地址', 'is_admin' => '是否是管理员回复' ]; } /** * Gets query for [[Ticket]]. * * @return ActiveQuery */ public function getTicket(): ActiveQuery { return $this->hasOne(Tickets::class, ['id' => 'ticket_id']); } /** * Gets query for [[User]]. * * @return ActiveQuery */ public function getUser(): ActiveQuery { return $this->hasOne(User::class, ['id' => 'user_id']); } public function toArray(array $fields = [], array $expand = [], $recursive = true): array { return [ 'id' => $this->id, 'ticket_id' => $this->ticket_id, 'name' => ($this->is_admin === 1) ? $this->user->username : '您', 'message' => $this->message, 'created_at' => $this->created_at, 'ip' => $this->ip, 'is_admin' => $this->is_admin, ]; } }