54 lines
1.5 KiB
PHP
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);
|
|
}
|
|
}
|