weich 2 년 전
부모
커밋
7a49b5235f

+ 79 - 0
catch/hydraulic/controller/DeviceMold.php

@@ -0,0 +1,79 @@
+<?php
+
+namespace catchAdmin\hydraulic\controller;
+
+use catcher\base\CatchRequest as Request;
+use catcher\CatchResponse;
+use catcher\base\CatchController;
+use catchAdmin\hydraulic\model\DeviceMold as deviceMoldModel;
+
+class DeviceMold extends CatchController
+{
+    protected $deviceMoldModel;
+    
+    public function __construct(DeviceMoldModel $deviceMoldModel)
+    {
+        $this->deviceMoldModel = $deviceMoldModel;
+    }
+    
+    /**
+     * 列表
+     * @time 2022年05月06日 10:22
+     * @param Request $request 
+     */
+    public function index(Request $request) : \think\Response
+    {
+        return CatchResponse::paginate($this->deviceMoldModel->getList());
+    }
+    
+    /**
+     * 保存信息
+     * @time 2022年05月06日 10:22
+     * @param Request $request 
+     */
+    public function save(Request $request) : \think\Response
+    {
+        return CatchResponse::success($this->deviceMoldModel->storeBy($request->post()));
+    }
+    
+    /**
+     * 读取
+     * @time 2022年05月06日 10:22
+     * @param $id 
+     */
+    public function read($id) : \think\Response
+    {
+        return CatchResponse::success($this->deviceMoldModel->findBy($id));
+    }
+    
+    /**
+     * 更新
+     * @time 2022年05月06日 10:22
+     * @param Request $request 
+     * @param $id
+     */
+    public function update(Request $request, $id) : \think\Response
+    {
+        return CatchResponse::success($this->deviceMoldModel->updateBy($id, $request->post()));
+    }
+    
+    /**
+     * 删除
+     * @time 2022年05月06日 10:22
+     * @param $id
+     */
+    public function delete($id) : \think\Response
+    {
+        return CatchResponse::success($this->deviceMoldModel->deleteBy($id));
+    }
+      /**
+     * 根据设备类型获取设备型号
+     * @time 2022年05月06日 10:22
+     * @param $id
+     */
+    public function getDeviceMold(Request $request) : \think\Response
+    {
+        $type = $request->get('type');
+        return CatchResponse::success($this->deviceMoldModel->field('id as value,name as text')->select());
+    }
+}

+ 41 - 0
catch/hydraulic/database/migrations/20220506102245_device_mold.php

@@ -0,0 +1,41 @@
+<?php
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+use Phinx\Db\Adapter\MysqlAdapter;
+
+class DeviceMold extends Migrator
+{
+    /**
+     * Change Method.
+     *
+     * Write your reversible migrations using this method.
+     *
+     * More information on writing migrations is available here:
+     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
+     *
+     * The following commands can be used in this method and Phinx will
+     * automatically reverse them when rolling back:
+     *
+     *    createTable
+     *    renameTable
+     *    addColumn
+     *    renameColumn
+     *    addIndex
+     *    addForeignKey
+     *
+     * Remember to call "create()" or "update()" and NOT "save()" when working
+     * with the Table class.
+     */
+    public function change()
+    {
+        $table = $this->table('device_mold', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
+        $table->addColumn('device_type', 'string', ['limit' => 10,'null' => false,'default' => 0,'signed' => true,'comment' => '设备类型',])
+			->addColumn('name', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '设备型号',])
+			->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建人ID',])
+			->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
+			->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
+			->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '软删除',])
+            ->create();
+    }
+}

+ 27 - 0
catch/hydraulic/model/DeviceMold.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace catchAdmin\hydraulic\model;
+
+use catcher\base\CatchModel as Model;
+
+class DeviceMold extends Model
+{
+    // 表名
+    public $name = 'device_mold';
+    // 数据库字段映射
+    public $field = array(
+        'id',
+        // 设备类型
+        'device_type',
+        // 设备型号
+        'name',
+        // 创建人ID
+        'creator_id',
+        // 创建时间
+        'created_at',
+        // 更新时间
+        'updated_at',
+        // 软删除
+        'deleted_at',
+    );
+}

+ 3 - 0
catch/hydraulic/route.php

@@ -13,4 +13,7 @@
 $router->group(function () use ($router){
 	// hydraulic路由
 	$router->resource('hydraulic', '\catchAdmin\hydraulic\controller\Hydraulic');
+	// deviceMold路由
+	$router->resource('deviceMold', '\catchAdmin\hydraulic\controller\DeviceMold');
+	$router->get('get_device_mold', '\catchAdmin\hydraulic\controller\DeviceMold@getDeviceMold');
 })->middleware('auth');