addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->create_time = time(); } public function beforeUpdate() { if ($this->deleted == 1) { $this->published = 0; } $this->update_time = time(); } public static function sizeTypes() { return [ self::SIZE_SMALL => '小号', self::SIZE_BIG => '大号', ]; } public static function posTypes() { return [ self::POS_MOVE => '滚动', self::POS_TOP => '顶部', self::POS_BOTTOM => '底部', ]; } public static function colorTypes() { return [ self::COLOR_WHITE => '白色', self::COLOR_RED => '红色', self::COLOR_GREEN => '绿色', self::COLOR_BLUE => '蓝色', self::COLOR_YELLOW => '黄色', ]; } public static function randPosition() { $types = self::posTypes(); $keys = array_keys($types); $index = array_rand($keys); return $keys[$index]; } public static function randColor() { $types = self::colorTypes(); $keys = array_keys($types); $index = array_rand($keys); return $keys[$index]; } }