feat:material
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants\Admin;
|
||||
namespace App\Constants\Common;
|
||||
|
||||
use Hyperf\Constants\AbstractConstants;
|
||||
use Hyperf\Constants\Annotation\Constants;
|
||||
@@ -24,7 +24,7 @@ class MaterialController
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Scene(scene: "list")]
|
||||
#[Scene(scene: "material_list")]
|
||||
public function materialList(MaterialRequest $request): array
|
||||
{
|
||||
return (new MaterialService())->materialList();
|
||||
@@ -36,7 +36,7 @@ class MaterialController
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "add", methods: "POST")]
|
||||
#[Scene(scene: "add")]
|
||||
#[Scene(scene: "material_add")]
|
||||
public function add(MaterialRequest $request): array
|
||||
{
|
||||
return (new MaterialService)->add();
|
||||
@@ -48,7 +48,7 @@ class MaterialController
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "delete", methods: "GET")]
|
||||
#[Scene(scene: "delete")]
|
||||
#[Scene(scene: "material_delete")]
|
||||
public function delete(MaterialRequest $request): array
|
||||
{
|
||||
return (new MaterialService())->delete();
|
||||
@@ -60,7 +60,7 @@ class MaterialController
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "edit", methods: "POST")]
|
||||
#[Scene(scene: "edit")]
|
||||
#[Scene(scene: "material_edit")]
|
||||
public function edit(MaterialRequest $request): array
|
||||
{
|
||||
return (new MaterialService())->edit();
|
||||
|
||||
34
app/Controller/Api/MaterialController.php
Normal file
34
app/Controller/Api/MaterialController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\Middleware\Api\JwtAuthMiddleware;
|
||||
use App\Request\Api\MaterialRequest;
|
||||
use App\Service\Api\Material\MaterialService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
#[Controller(prefix: 'api/material')]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class MaterialController
|
||||
{
|
||||
/**
|
||||
* 材料列表
|
||||
* @param MaterialRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Scene(scene: "material_list")]
|
||||
public function materialList(MaterialRequest $request): array
|
||||
{
|
||||
return (new MaterialService())->materialList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Admin\MaterialCode;
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Admin\MaterialCode;
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ class MaterialRequest extends FormRequest
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'list' => ['limit','query_name'],
|
||||
'add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'],
|
||||
'edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'],
|
||||
'delete' => ['id'],
|
||||
'material_list' => ['limit','query_name'],
|
||||
'material_add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'],
|
||||
'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'],
|
||||
'material_delete' => ['id'],
|
||||
];
|
||||
}
|
||||
|
||||
33
app/Request/Api/MaterialRequest.php
Normal file
33
app/Request/Api/MaterialRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request\Api;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class MaterialRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'limit' => 'required|integer',
|
||||
'query_name' =>'sometimes|string',
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'material_list' => ['limit','query_name'],
|
||||
];
|
||||
}
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Material;
|
||||
|
||||
use App\Constants\Admin\MaterialCode;
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\MaterialCategory;
|
||||
use App\Service\Admin\BaseService;
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Material;
|
||||
|
||||
use App\Constants\Admin\MaterialCode;
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Material;
|
||||
use App\Service\Admin\BaseService;
|
||||
|
||||
44
app/Service/Api/Material/MaterialService.php
Normal file
44
app/Service/Api/Material/MaterialService.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Material;
|
||||
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Model\Material;
|
||||
use App\Service\Api\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class MaterialService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var Material
|
||||
*/
|
||||
#[Inject]
|
||||
protected Material $MaterialModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function materialList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$name = $this->request->input('query_name');
|
||||
|
||||
$list = $this
|
||||
->MaterialModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('status',MaterialCode::ENABLE)
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('name', 'like', "$name%");
|
||||
})
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user