| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Http\Middleware;
- use App\Cache\UserCache;
- use App\Consts\ErrorConst;
- use App\Libs\Utils;
- use App\Facade\Site;
- use App\Models\Channel\Channel;
- use Closure;
- use App\Exceptions\ApiException;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\DB;
- class CheckCompany
- {
- /**
- * @param $request
- * @param Closure $next
- * @return mixed
- * @throws ApiException
- */
- public function handle($request, Closure $next)
- {
- $params = $request->all();
- $token = $request->header('d-token', '');
- if (!$token) Utils::throwError(ErrorConst::NOT_LOGIN);
- if (env('CHECK_COMPANY')) {
- $cpid = Site::getCpid();
-
- $script_id = getProp($params, 'script_id');
- if ($script_id) {
- if (!DB::table('mp_scripts')->where('id', $script_id)->where('cpid', $cpid)->value('id')) {
- Utils::throwError(ErrorConst::NOT_ACCESS);
- }
- }
- $anime_id = getProp($params, 'anime_id');
- if ($anime_id) {
- if (!DB::table('mp_animes')->where('id', $anime_id)->where('cpid', $cpid)->value('id')) {
- Utils::throwError(ErrorConst::NOT_ACCESS);
- }
- }
- $episode_id = getProp($params, 'episode_id');
- if ($episode_id) {
- if (!DB::table('mp_anime_episodes')->where('id', $episode_id)->where('cpid', $cpid)->value('id')) {
- Utils::throwError(ErrorConst::NOT_ACCESS);
- }
- }
- }
- return $next($request);
- }
- }
|