validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $model = Topic::find()->where(['store_id' => $this->store_id, 'id' => $this->id, 'is_delete' => 0]) ->select('id,title,read_count,virtual_read_count,content,created_at')->asArray()->one(); if (empty($model)) { // return new ApiResponse(1, '内容不存在'); return [ 'code' => 1, 'msg' => '内容不存在' ]; } Topic::updateAll(['read_count' => $model['read_count'] + 1], ['id' => $model['id']]); $model['read_count'] = intval($model['read_count']) + intval($model['virtual_read_count']); unset($model['virtual_read_count']); if ($model['read_count'] < 10000) { $model['read_count'] = $model['read_count'] . '人浏览'; } if ($model['read_count'] >= 10000) { $model['read_count'] = intval($model['read_count'] / 10000) . '万+人浏览'; } $model['addtime'] = date('Y-m-d', $model['created_at']); $favorite = TopicFavorite::findOne(['user_id' => $this->user_id, 'topic_id' => $model['id'], 'is_delete' => 0]); $model['is_favorite'] = $favorite ? 1 : 0; $model['content'] = $this->transTxvideo($model['content']); // return new ApiResponse(0, 'success', $model); return [ 'code' => 0, 'msg' => 'success', 'data' => $model ]; } private function transTxvideo($content) { preg_match_all("/https\:\/\/v\.qq\.com[^ '\"]+\.html[^ '\"]*/i", $content, $match_list); if (!is_array($match_list) || count($match_list) == 0) { return $content; } $url_list = $match_list[0]; foreach ($url_list as $url) { $res = GetInfo::getVideoInfo($url); if ($res['code'] == 0) { $new_url = $res['url']; $content = str_replace('src="' . $url . '"', 'src="' . $new_url . '"', $content); } } return $content; } }