feat : deliver

This commit is contained in:
2025-04-03 16:39:34 +08:00
parent 41b9993f36
commit 45d65ad4e2
3 changed files with 128 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Controller\Admin;
use App\Controller\AbstractController;
use App\Service\Admin\System\PrintPlantService;
class PrintPlantController extends AbstractController
{
public function add()
{
return (new PrintPlantService)->add();
}
public function edit()
{
return (new PrintPlantService)->edit();
}
public function delete()
{
return (new PrintPlantService)->delete();
}
public function list()
{
return (new PrintPlantService)->list();
}
}

View File

@@ -9,6 +9,7 @@ use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property int $kitchen_id
* @property string $name
* @property int $type
* @property string $code_value
@@ -31,7 +32,7 @@ class Printer extends Model
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'type' => 'integer'];
protected array $casts = ['id' => 'integer', 'type' => 'integer','kitchen_id' => 'integer'];
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';

View File

@@ -0,0 +1,94 @@
<?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();
}
}