123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- namespace App\Services\Timbre;
- use App\Consts\ErrorConst;
- use App\Facade\Site;
- use App\Libs\Utils;
- use GuzzleHttp\Client;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Redis;
- use OSS\Core\OssException;
- use OSS\OssClient;
- class TimbreService
- {
- public function __construct() {
- }
- public function addCategory($data) {
- $category_name = getProp($data, 'category_name');
- $pid = getProp($data, 'pid');
- if ($pid === '') Utils::throwError('20003:参数异常');
- $category = DB::table('mp_timbre_categories')->where('category_name', $category_name)->first();
- if ($category) {
- return Utils::throwError('20003:该分类已存在');
- }
- if ($pid) {
- $category = DB::table('mp_timbre_categories')->where('id', $pid)->first();
- if (!$category) {
- return Utils::throwError('20003:该分类不存在');
- }
- }
- return DB::table('mp_timbre_categories')->insert([
- 'category_name' => $category_name,
- 'pid' => $pid,
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- }
- public function editCategory($data) {
- $category_id = getProp($data, 'category_id');
- $category_name = getProp($data, 'category_name');
- $category = DB::table('mp_timbre_categories')->where('id', $category_id)->first();
- if (!$category) {
- return Utils::throwError('20003:该分类不存在');
- }
- $category = DB::table('mp_timbre_categories')->where('category_name', $category_name)->first();
- if ($category && $category->id != $category_id) {
- return Utils::throwError('20003:该分类已存在');
- }
- return DB::table('mp_timbre_categories')->where('id', $category_id)->update([
- 'category_name' => $category_name,
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- }
- public function getCategoryList($data) {
- $category_type = getProp($data, 'category_type', 1);
- $category_id = getProp($data, 'category_id');
- $category_name = getProp($data, 'category_name');
- $pid = getProp($data, 'pid');
- $query = DB::table('mp_timbre_categories')->where('is_enable', 1)->select('*');
- switch ($category_type) {
- case 1:
- $query->where('pid', 0);
- break;
- case 2:
- $query->where('pid', $pid);
- break;
- case 3:
- $query->where('pid', $pid);
- break;
- default:
- break;
- }
- if ($category_id) {
- $query->where('id', $category_id);
- }
- if ($category_name) {
- $query->where('category_name', 'like', "%{$category_name}%");
- }
- return $query->orderBy('id')->paginate();
- }
- public function getTimbreList($data) {
- $timbre_name = getProp($data, 'voice_name');
- $language = getProp($data, 'language');
- $status = getProp($data, 'status');
- $dialect = getProp($data, 'dialect');
- $query = DB::table('mp_timbres')->where('is_enabled', 1)->select('*');
- if ($timbre_name) {
- $query->where('timbre_name', 'like', "%{$timbre_name}%");
- }
- if ($language) {
- $query->where('language', 'like', "%{$language}%");
- }
- if ($dialect) {
- $query->where('dialect', $dialect);
- }
- $result = $query->orderBy('id')->paginate();
- return $result;
- }
- public function timbreCategories($data) {
- $categories = DB::table('mp_timbre_categories')->where('is_enable', 1)->select('id as category_id', 'category_name', 'pid')->get()->map(function ($value) {
- return (array)$value;
- })->toArray();
- $result = buildCategoryTree($categories, 0);
- return $result;
- }
- public function editTimbre($data) {
- $timbre_id = getProp($data, 'voice_id');
- $timbre = DB::table('mp_timbres')->where('id', $timbre_id)->first();
- if (!$timbre) {
- return Utils::throwError('20003:该音色不存在');
- }
- return DB::table('mp_timbres')->where('id', $timbre_id)->update([
- 'first_category_id' => getProp($data, 'first_category_id'),
- 'first_category_name' => getProp($data, 'first_category_name'),
- 'second_category_id' => getProp($data, 'second_category_id'),
- 'second_category_name' => getProp($data, 'second_category_name'),
- 'third_category_id' => getProp($data, 'third_category_id'),
- 'third_category_name' => getProp($data, 'third_category_name'),
- 'label' => getProp($data, 'label'),
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- }
- public function getAllBooks($data) {
- $bid = getProp($data, 'bid');
- $book_name = getProp($data, 'book_name');
- $query = DB::table('book_configs')->whereIn('is_on_shelf', [1,2])->select('bid', 'book_name');
- if ($bid) {
- $query->where('bid', $bid);
- }
- if ($book_name) {
- $query->where('book_name', 'like', "%{$book_name}%");
- }
- return $query->orderBy('bid', 'desc')->get()->map(function($value) {
- return (array)$value;
- })->toArray();
- }
- public function timbreGroupList($data) {
- $group_name = getProp($data, 'group_name');
- $label = getProp($data, 'label');
- $query = DB::table('mp_timbre_groups')->select('*');
- if ($group_name) {
- $query->where('group_name', 'like', "%{$group_name}%");
- }
- if ($label) {
- $query->where('label', 'like', $label);
- }
- return $query->orderBy('id')->paginate();
- }
- public function addTimbreGroup($data) {
- $group_name = getProp($data, 'group_name');
- $male_lead_voice_name = getProp($data, 'male_lead_voice_name');
- $male_lead_voice_type = getProp($data, 'male_lead_voice_type');
- $female_lead_voice_name = getProp($data, 'female_lead_voice_name');
- $female_lead_voice_type = getProp($data, 'female_lead_voice_type');
- $narration_voice_name = getProp($data, 'narration_voice_name');
- $narration_voice_type = getProp($data, 'narration_voice_type');
- if (!$group_name || !$male_lead_voice_type || !$female_lead_voice_type || !$narration_voice_type) Utils::throwError('20003:参数错误');
- $label = getProp($data, 'label');
- $other_roles = getProp($data, 'other_roles');
- if (DB::table('mp_timbre_groups')->where('group_name', $group_name)->value('id')) Utils::throwError('20003:该音色组已存在');
- return DB::table('mp_timbre_groups')->insert([
- 'group_name' => $group_name,
- 'male_lead_voice_name' => $male_lead_voice_name,
- 'male_lead_voice_type' => $male_lead_voice_type,
- 'female_lead_voice_name' => $female_lead_voice_name,
- 'female_lead_voice_type' => $female_lead_voice_type,
- 'narration_voice_name' => $narration_voice_name,
- 'narration_voice_type' => $narration_voice_type,
- 'label' => $label,
- 'other_roles' => $other_roles,
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- }
- public function editTimbreGroup($data) {
- $group_id = getProp($data, 'group_id');
- $group_name = getProp($data, 'group_name');
- $male_lead_voice_name = getProp($data, 'male_lead_voice_name');
- $male_lead_voice_type = getProp($data, 'male_lead_voice_type');
- $female_lead_voice_name = getProp($data, 'female_lead_voice_name');
- $female_lead_voice_type = getProp($data, 'female_lead_voice_type');
- $narration_voice_name = getProp($data, 'narration_voice_name');
- $narration_voice_type = getProp($data, 'narration_voice_type');
- if (!$group_id || !$group_name || !$male_lead_voice_type || !$female_lead_voice_type || !$narration_voice_type) Utils::throwError('20003:参数错误');
- $label = getProp($data, 'label');
- $other_roles = getProp($data, 'other_roles');
- if (DB::table('mp_timbre_groups')->where('group_name', $group_name)->value('id') != $group_id) Utils::throwError('20003:该音色组已存在');
- return DB::table('mp_timbre_groups')->where('id', $group_id)->update([
- 'group_name' => $group_name,
- 'male_lead_voice_name' => $male_lead_voice_name,
- 'male_lead_voice_type' => $male_lead_voice_type,
- 'female_lead_voice_name' => $female_lead_voice_name,
- 'female_lead_voice_type' => $female_lead_voice_type,
- 'narration_voice_name' => $narration_voice_name,
- 'narration_voice_type' => $narration_voice_type,
- 'label' => $label,
- 'other_roles' => $other_roles,
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- }
- }
|