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