addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->create_time = time(); } public function beforeUpdate() { $this->update_time = time(); } public function beforeSave() { $this->rating = $this->getAvgRating(); } protected function getAvgRating() { $sumRating = $this->rating1 + $this->rating2 + $this->rating3; return round($sumRating / 3, 2); } public static function publishTypes() { return [ self::PUBLISH_PENDING => '审核中', self::PUBLISH_APPROVED => '已发布', self::PUBLISH_REJECTED => '未通过', ]; } }