first commit

This commit is contained in:
root
2025-06-18 10:31:43 +08:00
commit d9f820b55d
981 changed files with 449311 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?php
namespace App\Controller\api\v1;
use App\Controller\AbstractController;
use App\FormModel\api\v1\ArticlesModel;
use App\Helpers\AppHelper;
use App\Model\AppArticle;
use App\Model\AppBrand;
use Hyperf\Collection\Collection;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
#[Controller]
class ArticlesController extends AbstractController
{
/**
* 文章列表
* @url /api/v1/articles
* @return array
*/
#[RequestMapping(path:'', methods: 'get')]
public function index(): array
{
$request = $this->request;
$query = Model::query()->orderBy('id');
$pagination = $query->paginate($request->input('limit', 10), page: $request->input('page'));
$data = $query->get()->toArray();
// $data['cover'] = AppHelper::setImageUrl($query['cover']);
foreach ($data as &$v) {
$v['cover'] = AppHelper::setImageUrl($v['cover']);
}
return ['code' => 0, 'msg' => 'ok', 'count' => $pagination->total(), 'data' => $data];
}
/**
* 新增/编辑文章
* @url /api/v1/articles/save
* @return array
*/
#[RequestMapping(path:'save', methods: 'post')]
public function save(): array
{
$id = $this->request->input('id');
$model = new ArticlesModel();
if ($id) {
$model->edit();
} else {
$model->create();
}
return [
'code' => 0,
'message' => 'ok'
];
}
#[RequestMapping(path:'brand-search', methods: 'get')]
public function brandSearch(): array
{
$input = $this->request->input('brand');
$query = Model::query()->select(['name', 'cn_name', 'id'])->where('name', 'like', "%$input%")
->orWhere('cn_name', 'like', "%$input%")
->get()->toArray();
return ['code' => 0, 'msg' => 'ok', 'data' => $query];
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Controller\api\v1;
use App\Controller\AbstractController;
use App\FormModel\api\v1\UserModel;
use App\Request\Test;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
#[Controller]
class UserController extends AbstractController
{
#[RequestMapping(path: '/api/v1/user/register', methods: 'post')]
public function register(Test $validator)
{
$validator = $validator->validated();
$model = new UserModel();
$model->register();
return [];
}
public function login()
{
}
public function logout()
{
}
}