123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Api\Controllers;
- use App\Api\Services\ApiService;
- use App\Base\Controllers\ApiBaseController;
- use App\Base\Library\Shorty;
- use App\Basic\Facades\UrlsFacade;
- use Illuminate\Http\Request;
- class IndexController extends ApiBaseController
- {
- private $apiService;
- private $shorty;
- public function __construct(ApiService $apiService)
- {
- $this->apiService = $apiService;
- $this->shorty = new Shorty(config("app.domain"));
- }
- /**
- * 短地址自动跳转
- */
- public function index(Request $request)
- {
- $plink = $request->route("plink", ""); //详情页面分配的地址
- $id = $this->shorty->decode($plink);
- $info = UrlsFacade::findOneById($id, "url");
- if (empty($info['url'])) {
- abort(404);
- }
- UrlsFacade::incrementBy(["id" => $id], "hits");
- $ip = getClientIp();
- $uvInfo = UrlsFacade::findOneLogInfo([
- 'urls_id' => $id,
- 'ip' => $ip
- ], 'id');
- if (empty($uvInfo['id'])) {
- UrlsFacade::incrementBy(["id" => $id], "uv");
- }
- UrlsFacade::addLog($id, $ip);
- $this->shorty->redirect($info['url']);
- }
- }
|