swoole-framwork/app/controller/UserController.php
2024-05-22 15:50:08 +08:00

78 lines
1.7 KiB
PHP

<?php
namespace App\controller;
use App\model\User;
use Core\annotations\Bean;
use Core\annotations\Value;
use Core\annotations\Redis;
use Core\annotations\Lock;
use Core\annotations\DB;
use Core\annotations\RequestMapping;
use Core\http\Request;
use Core\http\Response;
use Core\init\MyDB;
use Core\init\RedisHelper;
use DI\Attribute\Inject;
/**
* @Bean()
*/
class UserController
{
/**
* @DB()
* @var MyDB
*/
private $db;
/**
* @Value ()
*/
public $version = '1.0';
#[Inject]
private User $user;
/**
* @RequestMapping(value="/user/test")
*/
public function test()
{
//$this->db->select('select sleep(1)');
//User::query('select sleep(3)');
$user = User::first();
return ['uid'=>33,'username'=>$user];
}
/**
* @RequestMapping(value="/user/{uid:\d+}")
*/
public function user(int $uid,Request $request, Response $response)
{
$user = $this->db->select('select * from eb_user where id = 1');
return ['uid'=>$uid,'username'=>$user];
}
/**
* @RequestMapping(value="/redirect")
*/
public function redirect(Request $request,Response $response)
{
$response->writeRedirect('http://www.baihand.com');
}
/**
* @RequestMapping(value="/user/json")
* @Redis(key="name")
*/
public function json()
{
$user = $this->db->table('user')->get();
return ['code' => 1, 'msg' => 'success', 'data' => $user];
}
/**
* @Lock(prefix="lock",key="#0")
* @RequestMapping(value="/user/lock/{uid:\d+}")
*/
public function lock( Request $request, $uid, Response $response)
{
return $this->db->table('user')->get();
}
}