123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <?php
- namespace App\Http\Controllers\Goodnight;
- use App\Http\Controllers\Miniprogram\Auth;
- use App\Models\Goodnight\TopicExampleModel;
- use App\Models\Goodnight\TopicModel;
- use App\Services\Goodnight\VoiceService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Tymon\JWTAuth\Exceptions\JWTException;
- class VoiceController extends Controller
- {
- /**
- * 创建声音
- * @param Request $request
- * @return array
- * @throws \App\Exceptions\DBException
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function store(Request $request)
- {
- $uid = Auth::auth();
- $this->validate($request, [
- 'cover' => 'required',
- 'voice' => 'required'
- ]);
- $gvService = new VoiceService();
- $data = $request->only(['cover', 'voice', 'topic_id', 'topic_example_id']);
- $data['uid'] = $uid;
- $id = $gvService->create($data);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => [
- 'voice_id' => $id
- ]
- );
- }
- /**
- * 删除声音
- * @param int $voice_id
- * @return array
- * @throws \App\Exceptions\AlertException
- * @throws \App\Exceptions\DBException
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function delete(int $voice_id)
- {
- $uid = Auth::auth();
- $gvService = new VoiceService();
- $gvService->delete($uid, $voice_id);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- /**
- * 点赞声音
- * @param int $voice_id
- * @return array
- * @throws \App\Exceptions\AlertException
- * @throws \App\Exceptions\DBException
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function thumb(int $voice_id)
- {
- $uid = Auth::auth();
- $gvService = new VoiceService();
- $gvService->thumb($uid, $voice_id);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- /**
- * 标记声音
- * @param int $voice_id
- * @param Request $request
- * @return array
- * @throws \App\Exceptions\AlertException
- * @throws \App\Exceptions\DBException
- */
- public function tag(int $voice_id, Request $request)
- {
- try {
- $uid = Auth::auth();
- } catch (JWTException $e) {
- $uid = 0;
- }
- $this->validate($request, [
- 'tag' => 'required'
- ]);
- $gvService = new VoiceService();
- $data = array(
- 'voice_id' => $voice_id,
- 'tag' => $request->post('tag')
- );
- $data = $gvService->tag($uid, $data);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => [
- 'goodnight_coin' => $data
- ]
- );
- }
- /**
- * 用户端获取声音信息
- * @param int $voice_id
- * @return array
- */
- public function get(int $voice_id)
- {
- try {
- $uid = Auth::auth();
- } catch (JWTException $e) {
- $uid = 0;
- }
- $gvService = new VoiceService();
- $data = $gvService->getVoice($uid, $voice_id);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 我录制的声音
- * @param Request $request
- * @return array
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function myvoices(Request $request)
- {
- $uid = Auth::auth();
- $page = $request->get('page') ?? 1;
- $pre_page = $request->input('pre_page', 20);
- $gvService = new VoiceService();
- $data = $gvService->myVoice($page, $pre_page, $uid);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => [
- 'page' => $page,
- 'limit' => $pre_page,
- 'total' => $data['total'],
- 'list' => $data['list']
- ]
- );
- }
- /**
- * 用户录制的声音
- * @param Request $request
- * @param int $uid
- * @return array
- */
- public function uservoices(Request $request, int $uid)
- {
- $page = $request->get('page') ?? 1;
- $gvService = new VoiceService();
- $data = $gvService->userVoice($page, 20, $uid);
- return response([
- 'code' => 200,
- 'message' => 'success',
- 'data' => [
- 'page' => $page,
- 'limit' => 20,
- 'total' => $data['total'],
- 'list' => $data['list']
- ]
- ]);
- }
- /**
- * 后台-列表-审核声音
- * @param Request $request
- * @return array
- */
- public function voicelist(Request $request)
- {
- $page = $request->get('page') ?? 1;
- $search = $request->only('check', 'tag', 'search', 'expedit', 'commit');
- $pages = array(
- 'page' => $page,
- 'limit' => 20
- );
- $gvService = new VoiceService();
- $data = $gvService->checkList($pages, $search);
- return response([
- 'code' => 200,
- 'message' => 'success',
- 'data' => [
- 'page' => $page,
- 'limit' => 20,
- 'total' => $data['total'],
- 'list' => $data['list']
- ]
- ]);
- }
- /**
- * 后台-列表-推荐声音
- * @param int $voice_id
- * @return array
- * @throws \App\Exceptions\DBException
- */
- public function commit(int $voice_id): array
- {
- $gvService = new VoiceService();
- $gvService->commit($voice_id);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- /**
- * 后台-列表-审核声音
- * @param Request $request
- * @param int $voice_id
- * @return array
- * @throws \App\Exceptions\DBException
- */
- public function check(Request $request, int $voice_id): array
- {
- $this->validate($request, [
- 'check' => 'required|in:-1,1',
- ]);
- $check = $request->post('check');
- $gvService = new VoiceService();
- $gvService->check($voice_id, $check);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- /**
- * 后台-列表-标记声音
- * @param int $voice_id
- * @return array
- * @throws \App\Exceptions\DBException
- */
- public function admintag(Request $request, int $voice_id): array
- {
- $this->validate($request, [
- 'tag' => 'required'
- ]);
- $gvService = new VoiceService();
- $gvService->admintag($voice_id);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- /**
- * 加急晚安
- * @param int $voice_id
- * @return array
- * @throws JWTException
- * @throws \App\Exceptions\AlertException
- */
- public function expeditVoice(int $voice_id)
- {
- $uid = Auth::auth();
- $vs = new VoiceService();
- $vs->expeditVoice($voice_id, $uid);
- return array(
- 'code' => 200,
- 'message' => 'success'
- );
- }
- /**
- *
- * @return \Illuminate\Http\JsonResponse
- */
- public function topics()
- {
- $topics = TopicModel::select('id', 'topic')->where('show', '1')->orderBy("sort", "desc")->get();
- foreach ($topics as $topic) {
- $topic->examples = TopicExampleModel::select("id", "content")->where([
- 'show' => 1,
- 'topic_id' => $topic->id
- ])->get();
- }
- return response()->json([
- 'code' => 200,
- 'message' => 'OK',
- 'data' => $topics
- ]);
- }
- }
|