Files
fast/addons/shopro/controller/zy/Gym.php
xiadc 9223c1b127 feat(shopro): 添加俱乐部、球馆的访客记录功能
- 在 Club 控制器中添加访客记录逻辑
- 在 Gym 控制器中添加访客记录逻辑
- 在 Sys 控制器中添加获取访客记录的功能
2025-06-05 14:55:16 +08:00

54 lines
1.5 KiB
PHP

<?php
namespace addons\shopro\controller\zy;
use app\admin\model\zy\link\Visitor;
class Gym extends Base
{
protected $noNeedRight = ['*'];
public function __construct()
{
$this->model = new \app\admin\model\zy\Stadium;
parent::__construct();
}
public function index()
{
$params = $this->request->param();
$query = $this->model->where('status', 1);
if (isset($params['name'])) {
$query->where('name', 'like', '%' . $params['name'] . '%');
}
$res = $query->paginate($params['pageSize'] ?? 10);
$this->success('Success', ['list' => $res->items(), 'count' => $res->total()]);
}
public function view()
{
$model = $this->model->get($this->request->param('id'));
if (empty($model)) {
$this->error(__('No rows were found'));
}
$user = auth_user();
$visitor = Visitor::where('type', 1)->where('obj_id', $model['id'])->where('user_id', $user['id'])->find();
if (empty($visitor)) {
$visitor = new Visitor;
}
$visitor->allowField(true)->save([
'type' => 1,
'obj_id' => $model['id'],
'user_id' => $user['id'],
'nickname' => $user['nickname'],
'avatar' => $user['avatar'],
'gender' => $user['gender'],
'times' => empty($visitor->times) ? 1 : $visitor->times + 1
]);
$this->success('Success', $model);
}
}