TimbreService.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace App\Services\Timbre;
  3. use App\Consts\ErrorConst;
  4. use App\Facade\Site;
  5. use App\Libs\Utils;
  6. use GuzzleHttp\Client;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Redis;
  9. use OSS\Core\OssException;
  10. use OSS\OssClient;
  11. class TimbreService
  12. {
  13. public function __construct() {
  14. }
  15. public function addCategory($data) {
  16. $category_name = getProp($data, 'category_name');
  17. $pid = getProp($data, 'pid');
  18. if ($pid === '') Utils::throwError('20003:参数异常');
  19. $category = DB::table('mp_timbre_categories')->where('category_name', $category_name)->first();
  20. if ($category) {
  21. return Utils::throwError('20003:该分类已存在');
  22. }
  23. if ($pid) {
  24. $category = DB::table('mp_timbre_categories')->where('id', $pid)->first();
  25. if (!$category) {
  26. return Utils::throwError('20003:该分类不存在');
  27. }
  28. }
  29. return DB::table('mp_timbre_categories')->insert([
  30. 'category_name' => $category_name,
  31. 'pid' => $pid,
  32. 'created_at' => date('Y-m-d H:i:s'),
  33. 'updated_at' => date('Y-m-d H:i:s'),
  34. ]);
  35. }
  36. public function editCategory($data) {
  37. $category_id = getProp($data, 'category_id');
  38. $category_name = getProp($data, 'category_name');
  39. $category = DB::table('mp_timbre_categories')->where('id', $category_id)->first();
  40. if (!$category) {
  41. return Utils::throwError('20003:该分类不存在');
  42. }
  43. $category = DB::table('mp_timbre_categories')->where('category_name', $category_name)->first();
  44. if ($category && $category->id != $category_id) {
  45. return Utils::throwError('20003:该分类已存在');
  46. }
  47. return DB::table('mp_timbre_categories')->where('id', $category_id)->update([
  48. 'category_name' => $category_name,
  49. 'updated_at' => date('Y-m-d H:i:s'),
  50. ]);
  51. }
  52. public function getCategoryList($data) {
  53. $category_type = getProp($data, 'category_type', 1);
  54. $category_id = getProp($data, 'category_id');
  55. $category_name = getProp($data, 'category_name');
  56. $pid = getProp($data, 'pid');
  57. $query = DB::table('mp_timbre_categories')->where('is_enable', 1)->select('*');
  58. switch ($category_type) {
  59. case 1:
  60. $query->where('pid', 0);
  61. break;
  62. case 2:
  63. $query->where('pid', $pid);
  64. break;
  65. case 3:
  66. $query->where('pid', $pid);
  67. break;
  68. default:
  69. break;
  70. }
  71. if ($category_id) {
  72. $query->where('id', $category_id);
  73. }
  74. if ($category_name) {
  75. $query->where('category_name', 'like', "%{$category_name}%");
  76. }
  77. return $query->orderBy('id')->paginate();
  78. }
  79. public function getTimbreList($data) {
  80. $timbre_name = getProp($data, 'voice_name');
  81. $language = getProp($data, 'language');
  82. $status = getProp($data, 'status');
  83. $dialect = getProp($data, 'dialect');
  84. $query = DB::table('mp_timbres')->where('is_enabled', 1)->select('*');
  85. if ($timbre_name) {
  86. $query->where('timbre_name', 'like', "%{$timbre_name}%");
  87. }
  88. if ($language) {
  89. $query->where('language', 'like', "%{$language}%");
  90. }
  91. if ($dialect) {
  92. $query->where('dialect', $dialect);
  93. }
  94. $result = $query->orderBy('id')->paginate();
  95. return $result;
  96. }
  97. public function timbreCategories($data) {
  98. $categories = DB::table('mp_timbre_categories')->where('is_enable', 1)->select('id as category_id', 'category_name', 'pid')->get()->map(function ($value) {
  99. return (array)$value;
  100. })->toArray();
  101. $result = buildCategoryTree($categories, 0);
  102. return $result;
  103. }
  104. public function editTimbre($data) {
  105. $timbre_id = getProp($data, 'voice_id');
  106. $timbre = DB::table('mp_timbres')->where('id', $timbre_id)->first();
  107. if (!$timbre) {
  108. return Utils::throwError('20003:该音色不存在');
  109. }
  110. return DB::table('mp_timbres')->where('id', $timbre_id)->update([
  111. 'first_category_id' => getProp($data, 'first_category_id'),
  112. 'first_category_name' => getProp($data, 'first_category_name'),
  113. 'second_category_id' => getProp($data, 'second_category_id'),
  114. 'second_category_name' => getProp($data, 'second_category_name'),
  115. 'third_category_id' => getProp($data, 'third_category_id'),
  116. 'third_category_name' => getProp($data, 'third_category_name'),
  117. 'label' => getProp($data, 'label'),
  118. 'updated_at' => date('Y-m-d H:i:s'),
  119. ]);
  120. }
  121. public function getAllBooks($data) {
  122. $bid = getProp($data, 'bid');
  123. $book_name = getProp($data, 'book_name');
  124. $query = DB::table('book_configs')->whereIn('is_on_shelf', [1,2])->select('bid', 'book_name');
  125. if ($bid) {
  126. $query->where('bid', $bid);
  127. }
  128. if ($book_name) {
  129. $query->where('book_name', 'like', "%{$book_name}%");
  130. }
  131. return $query->orderBy('bid', 'desc')->get()->map(function($value) {
  132. return (array)$value;
  133. })->toArray();
  134. }
  135. public function timbreGroupList($data) {
  136. $group_name = getProp($data, 'group_name');
  137. $label = getProp($data, 'label');
  138. $query = DB::table('mp_timbre_groups')->select('*');
  139. if ($group_name) {
  140. $query->where('group_name', 'like', "%{$group_name}%");
  141. }
  142. if ($label) {
  143. $query->where('label', 'like', $label);
  144. }
  145. return $query->orderBy('id')->paginate();
  146. }
  147. public function addTimbreGroup($data) {
  148. $group_name = getProp($data, 'group_name');
  149. $male_lead_voice_name = getProp($data, 'male_lead_voice_name');
  150. $male_lead_voice_type = getProp($data, 'male_lead_voice_type');
  151. $female_lead_voice_name = getProp($data, 'female_lead_voice_name');
  152. $female_lead_voice_type = getProp($data, 'female_lead_voice_type');
  153. $narration_voice_name = getProp($data, 'narration_voice_name');
  154. $narration_voice_type = getProp($data, 'narration_voice_type');
  155. if (!$group_name || !$male_lead_voice_type || !$female_lead_voice_type || !$narration_voice_type) Utils::throwError('20003:参数错误');
  156. $label = getProp($data, 'label');
  157. $other_roles = getProp($data, 'other_roles');
  158. if (DB::table('mp_timbre_groups')->where('group_name', $group_name)->value('id')) Utils::throwError('20003:该音色组已存在');
  159. return DB::table('mp_timbre_groups')->insert([
  160. 'group_name' => $group_name,
  161. 'male_lead_voice_name' => $male_lead_voice_name,
  162. 'male_lead_voice_type' => $male_lead_voice_type,
  163. 'female_lead_voice_name' => $female_lead_voice_name,
  164. 'female_lead_voice_type' => $female_lead_voice_type,
  165. 'narration_voice_name' => $narration_voice_name,
  166. 'narration_voice_type' => $narration_voice_type,
  167. 'label' => $label,
  168. 'other_roles' => $other_roles,
  169. 'created_at' => date('Y-m-d H:i:s'),
  170. 'updated_at' => date('Y-m-d H:i:s'),
  171. ]);
  172. }
  173. public function editTimbreGroup($data) {
  174. $group_id = getProp($data, 'group_id');
  175. $group_name = getProp($data, 'group_name');
  176. $male_lead_voice_name = getProp($data, 'male_lead_voice_name');
  177. $male_lead_voice_type = getProp($data, 'male_lead_voice_type');
  178. $female_lead_voice_name = getProp($data, 'female_lead_voice_name');
  179. $female_lead_voice_type = getProp($data, 'female_lead_voice_type');
  180. $narration_voice_name = getProp($data, 'narration_voice_name');
  181. $narration_voice_type = getProp($data, 'narration_voice_type');
  182. if (!$group_id || !$group_name || !$male_lead_voice_type || !$female_lead_voice_type || !$narration_voice_type) Utils::throwError('20003:参数错误');
  183. $label = getProp($data, 'label');
  184. $other_roles = getProp($data, 'other_roles');
  185. if (DB::table('mp_timbre_groups')->where('group_name', $group_name)->value('id') != $group_id) Utils::throwError('20003:该音色组已存在');
  186. return DB::table('mp_timbre_groups')->where('id', $group_id)->update([
  187. 'group_name' => $group_name,
  188. 'male_lead_voice_name' => $male_lead_voice_name,
  189. 'male_lead_voice_type' => $male_lead_voice_type,
  190. 'female_lead_voice_name' => $female_lead_voice_name,
  191. 'female_lead_voice_type' => $female_lead_voice_type,
  192. 'narration_voice_name' => $narration_voice_name,
  193. 'narration_voice_type' => $narration_voice_type,
  194. 'label' => $label,
  195. 'other_roles' => $other_roles,
  196. 'updated_at' => date('Y-m-d H:i:s'),
  197. ]);
  198. }
  199. }