first commit
This commit is contained in:
12
app/FormModel/api/BaseModel.php
Executable file
12
app/FormModel/api/BaseModel.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\api;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
||||
class BaseModel
|
||||
{
|
||||
#[Inject]
|
||||
protected RequestInterface $_request;
|
||||
}
|
50
app/FormModel/api/v1/ArticlesModel.php
Executable file
50
app/FormModel/api/v1/ArticlesModel.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\api\v1;
|
||||
|
||||
|
||||
use App\Helpers\AppHelper;
|
||||
use App\Model\AppArticle;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
||||
class ArticlesModel
|
||||
{
|
||||
#[Inject]
|
||||
private readonly RequestInterface $_request;
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$query = AppArticle::find($this->_request->post('id'));
|
||||
$query->cover = AppHelper::extractImagePath($this->_request->post('cover'));
|
||||
|
||||
$query->title = $this->_request->post('title');
|
||||
$query->brand = $this->_request->post('brand');
|
||||
|
||||
$images = array_values($this->_request->post('images'));
|
||||
foreach ($images as &$image) {
|
||||
$image['src'] = AppHelper::extractImagePath($image['src']);
|
||||
}
|
||||
$query->images = json_encode($images);
|
||||
|
||||
$query->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$query = new AppArticle();
|
||||
$query->cover = AppHelper::extractImagePath($this->_request->post('cover'));
|
||||
$query->title = $this->_request->post('title');
|
||||
$query->brand = $this->_request->post('brand');
|
||||
|
||||
$images = array_values($this->_request->post('images') ?: []);
|
||||
foreach ($images as &$image) {
|
||||
$image['src'] = AppHelper::extractImagePath($image['src']);
|
||||
}
|
||||
$query->images = json_encode($images);
|
||||
|
||||
$query->save();
|
||||
return true;
|
||||
}
|
||||
}
|
20
app/FormModel/api/v1/UserModel.php
Executable file
20
app/FormModel/api/v1/UserModel.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\FormModel\api\v1;
|
||||
|
||||
use App\FormModel\api\BaseModel;
|
||||
use App\Model\AppUser;
|
||||
|
||||
class UserModel extends BaseModel
|
||||
{
|
||||
|
||||
public function register()
|
||||
{
|
||||
$query = new AppUser();
|
||||
$query->name = $this->_request->post('name');
|
||||
$query->password = md5($this->_request->post('password'));
|
||||
$query->email = $this->_request->post('email');
|
||||
$query->unique_id = uniqid("", true);
|
||||
$query->save();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user