Files
hyperf_service/app/Service/Admin/System/PrintPlantService.php
2025-04-03 16:39:34 +08:00

94 lines
2.2 KiB
PHP

<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Admin\System;
use App\Exception\ErrException;
use App\Model\Printer;
use App\Service\Admin\BaseService;
use Exception;
use Hyperf\Di\Annotation\Inject;
class PrintPlantService extends BaseService
{
/**
* @var Printer
*/
#[Inject]
protected Printer $printerModel;
/**
* @return array
*/
public function handle(): array
{
$kitchenId = (int)$this->request->input('kitchen_id');
$limit = (int)$this->request->input('limit');
$list = $this->printerModel->where('kitchen_id', $kitchenId)->paginate($limit)->toArray();
return $this->return->success('success', $list);
}
/**
* @return array
*/
public function add(): array
{
$insertModel = new Printer();
$insertModel->kitchen_id = $this->request->input('kitchen_id');
$insertModel->name = $this->request->input('name');
$insertModel->type = $this->request->input('type');
$insertModel->code_value = $this->request->input('code_value');
if (!$insertModel->save()) throw new ErrException('添加失败');
return $this->return->success();
}
/**
* @return array
*/
public function edit(): array
{
$id = (int)$this->request->input('id');
$info = $this->printerModel->find($id);
if (empty($info)) throw new ErrException('未找到数据');
$info->kitchen_id = $this->request->input('kitchen_id');
$info->name = $this->request->input('name');
$info->type = $this->request->input('type');
$info->code_value = $this->request->input('code_value');
if (!$info->save()) throw new ErrException('修改失败');
return $this->return->success();
}
/**
* @return array
* @throws Exception
*/
public function del(): array
{
$id = (int)$this->request->input('id');
$info = $this->printerModel->find($id);
if (empty($info)) throw new ErrException('未找到数据');
if (!$info->delete()) throw new ErrException('删除失败');
return $this->return->success();
}
}