feat:dish
This commit is contained in:
56
app/Controller/Api/DishController.php
Normal file
56
app/Controller/Api/DishController.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Api;
|
||||||
|
|
||||||
|
use App\Middleware\Api\JwtAuthMiddleware;
|
||||||
|
use App\Request\Api\DishRequest;
|
||||||
|
use App\Service\Api\Material\DishService;
|
||||||
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
|
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||||
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
use Hyperf\Validation\Annotation\Scene;
|
||||||
|
|
||||||
|
#[Controller(prefix: 'api/dish')]
|
||||||
|
#[Middlewares([
|
||||||
|
JwtAuthMiddleware::class,
|
||||||
|
])]
|
||||||
|
class DishController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 菜品添加
|
||||||
|
* @param DishRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "add", methods: "POST")]
|
||||||
|
#[Scene(scene: "add")]
|
||||||
|
public function dishAdd(dishRequest $request): array
|
||||||
|
{
|
||||||
|
return (new DishService())->add();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品修改
|
||||||
|
* @param DishRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "edit", methods: "POST")]
|
||||||
|
#[Scene(scene: "edit")]
|
||||||
|
public function dishEdit(dishRequest $request): array
|
||||||
|
{
|
||||||
|
return (new DishService())->edit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品列表
|
||||||
|
* @param DishRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "list", methods: "GET")]
|
||||||
|
#[Scene(scene: "list")]
|
||||||
|
public function dishList(dishRequest $request): array
|
||||||
|
{
|
||||||
|
return (new DishService())->list();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,6 @@ use Hyperf\DbConnection\Model\Model;
|
|||||||
* @property string $side_dish
|
* @property string $side_dish
|
||||||
* @property string $flavor
|
* @property string $flavor
|
||||||
* @property int $cycle_id
|
* @property int $cycle_id
|
||||||
* @property int $status
|
|
||||||
* @property int $city_id
|
* @property int $city_id
|
||||||
* @property int $kitchen_id
|
* @property int $kitchen_id
|
||||||
* @property int $chef_id
|
* @property int $chef_id
|
||||||
@@ -40,7 +39,7 @@ class Dish extends Model
|
|||||||
/**
|
/**
|
||||||
* The attributes that should be cast to native types.
|
* The attributes that should be cast to native types.
|
||||||
*/
|
*/
|
||||||
protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer'];
|
protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer'];
|
||||||
|
|
||||||
const string CREATED_AT = 'create_time';
|
const string CREATED_AT = 'create_time';
|
||||||
|
|
||||||
|
|||||||
40
app/Request/Api/DishRequest.php
Normal file
40
app/Request/Api/DishRequest.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Request\Api;
|
||||||
|
|
||||||
|
use Hyperf\Validation\Request\FormRequest;
|
||||||
|
|
||||||
|
class DishRequest 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',
|
||||||
|
'dish_name' => 'sometimes|string',
|
||||||
|
'cycle_id' => 'sometimes|integer|exists:cycle,id',
|
||||||
|
'city_id' => 'sometimes|integer|exists:system_city,id',
|
||||||
|
'kitchen_id' => 'sometimes|integer|exists:kitchen,id',
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected array $scenes = [
|
||||||
|
'add' => ['dish_name','profile','pre_quantity','price','side_dish','flavor','cycle_id','city_id','kitchen_id'],
|
||||||
|
'edit' => ['id','dish_name','profile','pre_quantity','price','side_dish','flavor'],
|
||||||
|
'list' =>['limit']
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
107
app/Service/Api/Material/DishService.php
Normal file
107
app/Service/Api/Material/DishService.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Api\Material;
|
||||||
|
|
||||||
|
use App\Constants\Common\DishCode;
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Model\Dish;
|
||||||
|
use App\Service\Api\BaseService;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
|
class DishService extends BaseService
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Dish
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Dish $DishModel;
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function add(): array
|
||||||
|
{
|
||||||
|
$dish_name = $this->request->input('dish_name');
|
||||||
|
$profile = $this->request->input('profile');
|
||||||
|
$pre_quantity = (int)$this->request->input('pre_quantity');
|
||||||
|
$price = (double)$this->request->input('price');
|
||||||
|
$side_dish = $this->request->input('side_dish');
|
||||||
|
$flavor = $this->request->input('flavor');
|
||||||
|
$cycle_id = (int)$this->request->input('cycle_id');
|
||||||
|
$city_id = (int)$this->request->input('city_id');
|
||||||
|
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||||
|
$chef_id = $this->userId;
|
||||||
|
|
||||||
|
$dish = new Dish();
|
||||||
|
$dish ->dish = $dish_name;
|
||||||
|
$dish ->profile = $profile;
|
||||||
|
$dish ->pre_quantity = $pre_quantity;
|
||||||
|
$dish ->price = $price;
|
||||||
|
$dish ->side_dish = $side_dish;
|
||||||
|
$dish ->flavor = $flavor;
|
||||||
|
$dish ->cycle_id = $cycle_id;
|
||||||
|
$dish ->city_id = $city_id;
|
||||||
|
$dish ->kitchen_id = $kitchen_id;
|
||||||
|
$dish ->chef_id = $chef_id;
|
||||||
|
|
||||||
|
if (!$dish->save()) throw new ErrException('菜品添加失败');
|
||||||
|
|
||||||
|
return $this->return->success('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(): array
|
||||||
|
{
|
||||||
|
$dish_id = (int)$this->request->input('id');
|
||||||
|
$dish_name = $this->request->input('dish_name');
|
||||||
|
$profile = $this->request->input('profile');
|
||||||
|
$pre_quantity = (int)$this->request->input('pre_quantity');
|
||||||
|
$price = (double)$this->request->input('price');
|
||||||
|
$side_dish = $this->request->input('side_dish');
|
||||||
|
$flavor = $this->request->input('flavor');
|
||||||
|
|
||||||
|
$info = $this->DishModel->getInfoById($dish_id);
|
||||||
|
if (empty($info)) throw new ErrException('数据不存在');
|
||||||
|
|
||||||
|
if (!empty($dish_name)) {
|
||||||
|
$info->dish = $dish_name;
|
||||||
|
}
|
||||||
|
if (!empty($profile)) {
|
||||||
|
$info->profile = $profile;
|
||||||
|
}
|
||||||
|
if (!empty($pre_quantity)) {
|
||||||
|
$info->pre_quantity = $pre_quantity;
|
||||||
|
}
|
||||||
|
if (!empty($price)) {
|
||||||
|
$info->price = $price;
|
||||||
|
}
|
||||||
|
if (!empty($side_dish)) {
|
||||||
|
$info->side_dish = $side_dish;
|
||||||
|
}
|
||||||
|
if (!empty($flavor)) {
|
||||||
|
$info->flavor = $flavor;
|
||||||
|
}
|
||||||
|
if (!$info->save()) throw new ErrException('菜品修改失败');
|
||||||
|
|
||||||
|
return $this->return->success();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(): array
|
||||||
|
{
|
||||||
|
$limit = (int)$this->request->input('limit');
|
||||||
|
$chef_id = $this->userId;
|
||||||
|
$list = $this->DishModel
|
||||||
|
->where('chef_id', $chef_id)
|
||||||
|
->paginate($limit)->toArray();
|
||||||
|
|
||||||
|
return $this->return->success('success',$list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -276,11 +276,6 @@ GET {{host}}/admin/member/list?limit=10
|
|||||||
content-type: application/json
|
content-type: application/json
|
||||||
Authorization: Bearer {{admin_token}}
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
### 排菜列表
|
|
||||||
GET {{host}}/admin/dish/list?limit=10
|
|
||||||
content-type: application/json
|
|
||||||
Authorization: Bearer {{admin_token}}
|
|
||||||
|
|
||||||
### 仓库列表
|
### 仓库列表
|
||||||
GET {{host}}/admin/depot/depot_list?limit=10
|
GET {{host}}/admin/depot/depot_list?limit=10
|
||||||
content-type: application/json
|
content-type: application/json
|
||||||
@@ -394,5 +389,28 @@ POST {{host}}/admin/depot/depot_purchase_update
|
|||||||
Content-Type: application/x-www-form-urlencoded
|
Content-Type: application/x-www-form-urlencoded
|
||||||
Authorization: Bearer {{admin_token}}
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
id=1&number=8
|
id=1&number=9
|
||||||
|
|
||||||
|
### 排菜列表
|
||||||
|
GET {{host}}/admin/dish/list?limit=10
|
||||||
|
content-type: application/json
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
### 厨师添加菜品
|
||||||
|
POST {{host}}/api/dish/add
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
dish_name=排骨饭&profile=加水&pre_quantity=500&price=15&side_dish=33333&flavor=清淡&cycle_id=1&city_id=1&kitchen_id=1
|
||||||
|
|
||||||
|
### 厨师修改菜品
|
||||||
|
POST {{host}}/api/dish/edit
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
id=1&pre_quantity=300&price=12
|
||||||
|
|
||||||
|
### 厨师查看排菜
|
||||||
|
GET {{host}}/api/dish/list?limit=10
|
||||||
|
content-type: application/json
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
Reference in New Issue
Block a user