multi-store/app/api/controller/user/UserVisitController.php

63 lines
2.1 KiB
PHP

<?php
namespace app\api\controller\user;
use app\api\controller\BaseApiController;
use app\api\logic\user\UserVisitLogic;
use app\api\validate\VisitValidate;
use Illuminate\Support\Facades\Request;
use support\Response;
class UserVisitController extends BaseApiController
{
public $notNeedLogin = ['productLog'];
// #[
// ApiDoc\Title('添加访问商品记录'),
// ApiDoc\url('/api/user/UserVisit/productLog'),
// ApiDoc\Method('POST'),
// ApiDoc\Param(name: "product_id", type: "int", require: true, desc: "product_id商品id"),
// ApiDoc\Param(name: "cate_id", type: "int", require: true, desc: "分类id"),
// ApiDoc\NotHeaders(),
// ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
// ApiDoc\ResponseSuccess("data", type: "array"),
// ]
public function productLog(): Response
{
$params = (new VisitValidate())->post()->goCheck('add');
$result = UserVisitLogic::add($params,$this->userId);
if (true === $result) {
return $this->success('ok');
}
return $this->fail(UserVisitLogic::getError());
}
// #[
// ApiDoc\Title('用户访问页面记录'),
// ApiDoc\url('/api/user/UserVisit/htmlLog'),
// ApiDoc\Method('POST'),
// ApiDoc\Param(name: "url", type: "string", require: true, desc: "路径"),
// ApiDoc\Param(name: "stay_time", type: "int", require: true, desc: "停留时间"),
// ApiDoc\NotHeaders(),
// ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
// ApiDoc\ResponseSuccess("data", type: "array"),
// ]
public function htmlLog()
{
$ip = $this->request->getRealIp();
$params = (new VisitValidate())->post()->goCheck('userAdd');
$params['ip'] = $ip;
$result = UserVisitLogic::visitAdd($params,$this->userInfo);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(UserVisitLogic::getError());
}
}