|
@@ -266,4 +266,64 @@ class BookService
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
+
|
|
|
+ public function audioEffects($data) {
|
|
|
+ return DB::table('mp_audio_effects')->where('is_enabled', 1)->select('audio_effect_name', 'audio_effect_url')->get()->map(function ($value) {
|
|
|
+ return (array)$value;
|
|
|
+ })->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function uploadAudioEffect($data, $file) {
|
|
|
+ $audio_effect_name = getProp($data, 'audio_effect_name');
|
|
|
+
|
|
|
+ if (!$file) Utils::throwError('20003:请上传音频文件');
|
|
|
+ // 验证文件格式(常见音频格式)
|
|
|
+ if (!in_array($file->getClientOriginalExtension(), ['mp3', 'wav', 'flac', 'm4a', 'ogg', 'wma', 'cda', 'aiff', 'au', 'aac', 'amr'])) Utils::throwError('20003:音频格式错误');
|
|
|
+ if (!$audio_effect_name) Utils::throwError('20003:请输入音频效果名称');
|
|
|
+ if (DB::table('mp_audio_effects')->where('audio_effect_name', $audio_effect_name)->exists()) Utils::throwError('20003:音效名称已存在');
|
|
|
+
|
|
|
+ // 上传文件到oss
|
|
|
+ $audio_effect_url = uploadFile('audio_effects', $file, $audio_effect_name);
|
|
|
+ if (!$audio_effect_url) Utils::throwError('20003:上传音频文件失败');
|
|
|
+
|
|
|
+ $boolen = DB::table('mp_audio_effects')->insert([
|
|
|
+ 'audio_effect_name' => $audio_effect_name,
|
|
|
+ 'audio_effect_url' => $audio_effect_url,
|
|
|
+ 'is_enabled' => 1,
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ if (!$boolen) Utils::throwError('20003:添加音效失败');
|
|
|
+ return ['audio_effect_name' => $audio_effect_name, 'audio_effect_url' => $audio_effect_url];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function bgms($data) {
|
|
|
+ return DB::table('mp_bgms')->where('is_enabled', 1)->select('bgm_name', 'bgm_url')->get()->map(function ($value) {
|
|
|
+ return (array)$value;
|
|
|
+ })->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function uploadBgm($data, $file) {
|
|
|
+ $bgm_name = getProp($data, 'bgm_name');
|
|
|
+
|
|
|
+ if (!$file) Utils::throwError('20003:请上传音频文件');
|
|
|
+ // 验证文件格式(常见音频格式)
|
|
|
+ if (!in_array($file->getClientOriginalExtension(), ['mp3', 'wav', 'flac', 'm4a', 'ogg', 'wma', 'cda', 'aiff', 'au', 'aac', 'amr'])) Utils::throwError('20003:音频格式错误');
|
|
|
+ if (!$bgm_name) Utils::throwError('20003:请输入音频效果名称');
|
|
|
+ if (DB::table('mp_bgms')->where('bgm_name', $bgm_name)->exists()) Utils::throwError('20003:bgm名称已存在');
|
|
|
+
|
|
|
+ // 上传文件到oss
|
|
|
+ $bgm_url = uploadFile('bgms', $file, $bgm_name);
|
|
|
+ if (!$bgm_url) Utils::throwError('20003:上传音频文件失败');
|
|
|
+
|
|
|
+ $boolen = DB::table('mp_bgms')->insert([
|
|
|
+ 'bgm_name' => $bgm_name,
|
|
|
+ 'bgm_url' => $bgm_url,
|
|
|
+ 'is_enabled' => 1,
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ if (!$boolen) Utils::throwError('20003:添加bgm失败');
|
|
|
+ return ['bgm_name' => $bgm_name, 'bgm_url' => $bgm_url];
|
|
|
+ }
|
|
|
}
|