addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { if ($this->receiver_type == self::TYPE_FRIEND) { $this->chat_id = self::getChatId($this->sender_id, $this->receiver_id); } $this->create_time = time(); } public function beforeUpdate() { $this->update_time = time(); } public static function getChatId($aUserId, $bUserId) { $list = [$aUserId, $bUserId]; sort($list); return implode('-', $list); } }