feat:dish
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user