public static function saveMusic($info) { if (!isset($info['song_id'])) { return false; } $date_now = date("Y-m-d H:i:s"); $has_in = Music::findOne(['song_id' => $info['song_id'], 'type' => $info['type']]); if ($has_in) { $has_in->status = 1; $has_in->updated_time = $date_now; $has_in->update(0); return true; } $model_music = new Music(); $model_music->song_id = $info['song_id']; $model_music->type = isset($info['type']) ? $info['type'] : 2; $model_music->cover_image = isset($info['cover_image']) ? $info['cover_image'] : ""; $model_music->lrc = isset($info['lrc']) ? $info['lrc'] : ""; $model_music->song_url = isset($info['song_url']) ? $info['song_url'] : ""; $model_music->song_title = isset($info['song_title']) ? $info['song_title'] : ""; $model_music->song_author = isset($info['song_author']) ? $info['song_author'] : ""; $model_music->text = isset($info['text']) ? json_encode($info['text']) : ""; $model_music->format_data = isset($info['format_data']) ? json_encode($info['format_data']) : ""; $model_music->status = isset($info['status']) ? $info['status'] : 1; $model_music->updated_time = $date_now; $model_music->created_time = $date_now; $model_music->save(0); return true; }
public static function saveMusic($info) { $song_id = $info['songId']; $has_in = Music::findOne(['song_id' => $song_id, 'type' => 1, 'status' => 1]); if ($has_in) { return true; } if (!$info['songPicRadio']) { return false; } $model_music = new Music(); $model_music->song_id = $song_id; $model_music->type = 1; $model_music->cover_image = $info['songPicRadio']; $model_music->lrc = @file_get_contents($info['lrcLink']); $model_music->song_url = $info['songLink']; $model_music->song_title = $info['songName']; $model_music->song_author = $info['artistName']; $model_music->text = json_encode($info); $model_music->status = 1; $model_music->updated_time = date("Y-m-d H:i:s"); $model_music->created_time = $model_music->updated_time; $model_music->save(0); return true; }