CheckCompany.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Cache\UserCache;
  4. use App\Consts\ErrorConst;
  5. use App\Libs\Utils;
  6. use App\Facade\Site;
  7. use App\Models\Channel\Channel;
  8. use Closure;
  9. use App\Exceptions\ApiException;
  10. use Illuminate\Support\Facades\Log;
  11. use Illuminate\Support\Facades\DB;
  12. class CheckCompany
  13. {
  14. /**
  15. * @param $request
  16. * @param Closure $next
  17. * @return mixed
  18. * @throws ApiException
  19. */
  20. public function handle($request, Closure $next)
  21. {
  22. $params = $request->all();
  23. $token = $request->header('d-token', '');
  24. if (!$token) Utils::throwError(ErrorConst::NOT_LOGIN);
  25. if (env('CHECK_COMPANY')) {
  26. $cpid = Site::getCpid();
  27. $script_id = getProp($params, 'script_id');
  28. if ($script_id) {
  29. if (!DB::table('mp_scripts')->where('id', $script_id)->where('cpid', $cpid)->value('id')) {
  30. Utils::throwError(ErrorConst::NOT_ACCESS);
  31. }
  32. }
  33. $anime_id = getProp($params, 'anime_id');
  34. if ($anime_id) {
  35. if (!DB::table('mp_animes')->where('id', $anime_id)->where('cpid', $cpid)->value('id')) {
  36. Utils::throwError(ErrorConst::NOT_ACCESS);
  37. }
  38. }
  39. $episode_id = getProp($params, 'episode_id');
  40. if ($episode_id) {
  41. if (!DB::table('mp_anime_episodes')->where('id', $episode_id)->where('cpid', $cpid)->value('id')) {
  42. Utils::throwError(ErrorConst::NOT_ACCESS);
  43. }
  44. }
  45. }
  46. return $next($request);
  47. }
  48. }