diff --git a/app/Controller/Admin/PrintPlantController.php b/app/Controller/Admin/PrintPlantController.php new file mode 100644 index 0000000..e58c9d2 --- /dev/null +++ b/app/Controller/Admin/PrintPlantController.php @@ -0,0 +1,31 @@ +add(); + } + + public function edit() + { + return (new PrintPlantService)->edit(); + } + + public function delete() + { + return (new PrintPlantService)->delete(); + } + + public function list() + { + return (new PrintPlantService)->list(); + } +} diff --git a/app/Model/Printer.php b/app/Model/Printer.php index 7c08fab..970b35e 100644 --- a/app/Model/Printer.php +++ b/app/Model/Printer.php @@ -8,7 +8,8 @@ use Hyperf\Database\Model\Collection; use Hyperf\DbConnection\Model\Model; /** - * @property int $id + * @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'; diff --git a/app/Service/Admin/System/PrintPlantService.php b/app/Service/Admin/System/PrintPlantService.php new file mode 100644 index 0000000..b178b36 --- /dev/null +++ b/app/Service/Admin/System/PrintPlantService.php @@ -0,0 +1,94 @@ +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(); + } +} \ No newline at end of file