likang 3 yıl önce
ebeveyn
işleme
8ee7b15e22

+ 38 - 2
catch/flange/controller/Flange.php

@@ -6,6 +6,8 @@ use catcher\base\CatchRequest as Request;
 use catcher\CatchResponse;
 use catcher\base\CatchController;
 use catchAdmin\flange\model\Flange as model;
+use PhpParser\Node\Expr\FuncCall;
+use think\facade\Db;
 
 class Flange extends CatchController
 {
@@ -33,7 +35,13 @@ class Flange extends CatchController
      */
     public function save(Request $request) : \think\Response
     {
-        return CatchResponse::success($this->model->storeBy($request->post()));
+        $data = $request->post();
+       
+        if($data['out_date']){
+        
+            $data['out_date'] = date('Y-m-d',$data['out_date']);
+        }
+        return CatchResponse::success($this->model->storeBy($data));
     }
     
     /**
@@ -54,7 +62,12 @@ class Flange extends CatchController
      */
     public function update(Request $request, $id) : \think\Response
     {
-        return CatchResponse::success($this->model->updateBy($id, $request->post()));
+        $data = $request->post();
+        if(!strstr($data['out_date'],'-'))
+        {
+            $data['out_date'] = date('Y-m-d',$data['out_date']);
+        }
+        return CatchResponse::success($this->model->updateBy($id,$data));
     }
     
     /**
@@ -66,4 +79,27 @@ class Flange extends CatchController
     {
         return CatchResponse::success($this->model->deleteBy($id));
     }
+    /**
+     * 获取风场和风机
+     */
+    public function getWindFan(Request $request)
+    {
+        $data = $request->get();
+        if(!empty($data['wind']))
+        {
+          $where[]=['name','like','%'.$data['wind'].'%'];
+        }
+    
+        $wind_list = Db::name("wind")->field('id as wid,name as text')->select();
+        $wind_list =json_decode(json_encode($wind_list),true);
+        foreach($wind_list as $key=>$item)
+        {
+            $wind_list[$key]['children'] = Db::name('fan')
+            ->where('wind_id',$item['wid'])
+            ->field('id as value,number as text')
+            ->select();
+        }
+       return CatchResponse::success($wind_list);
+    }
+    
 }

+ 50 - 0
catch/flange/database/migrations/20220506072724_flange_add_field1.php

@@ -0,0 +1,50 @@
+<?php
+// +----------------------------------------------------------------------
+// | CatchAdmin [Just Like ~ ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
+// +----------------------------------------------------------------------
+// | Author: JaguarJack [ njphper@gmail.com ]
+// +----------------------------------------------------------------------
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+
+class FlangeAddField1 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()
+    {
+        if ($this->hasTable('flange')) {
+            $table = $this->table('flange');
+
+            $table  ->addColumn('bolt_size', 'string', ['limit' => 10,'null' => true,'signed' => true,'comment' => '螺丝尺寸',])
+                    ->addColumn('bolt_number', 'string', ['limit' => 10,'null' => true,'signed' => true,'comment' => '螺丝数量',])
+                    ->update();
+        }
+      
+
+    }
+}

+ 48 - 0
catch/flange/database/migrations/20220507034243_flange_add_wond.php

@@ -0,0 +1,48 @@
+<?php
+// +----------------------------------------------------------------------
+// | CatchAdmin [Just Like ~ ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
+// +----------------------------------------------------------------------
+// | Author: JaguarJack [ njphper@gmail.com ]
+// +----------------------------------------------------------------------
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+
+class FlangeAddWond 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()
+    {
+        if ($this->hasTable('flange')) {
+            $table = $this->table('flange');
+
+            $table->addColumn('wind_id', 'string', ['limit' => 16,'null' => true,'signed' => true,'comment' => '风场id',])
+                    ->update();
+        }
+
+    }
+}

+ 49 - 0
catch/flange/database/migrations/20220507083332_flange_add_out.php

@@ -0,0 +1,49 @@
+<?php
+// +----------------------------------------------------------------------
+// | CatchAdmin [Just Like ~ ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
+// +----------------------------------------------------------------------
+// | Author: JaguarJack [ njphper@gmail.com ]
+// +----------------------------------------------------------------------
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+
+class FlangeAddOut 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()
+    {
+
+        if ($this->hasTable('flange')) {
+            $table = $this->table('flange');
+
+            $table->addColumn('wrench', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '扳手',])
+            ->addColumn('outside', 'string', ['limit' => 20,'null' => true,'signed' => true,'comment' => '外径',])
+            ->update();
+        }
+    }
+}

+ 28 - 0
catch/flange/model/Flange.php

@@ -3,9 +3,13 @@
 namespace catchAdmin\flange\model;
 
 use catcher\base\CatchModel as Model;
+use catcher\traits\db\BaseOptionsTrait;
+use catcher\traits\db\ScopeTrait;
+use think\facade\Db;
 
 class Flange extends Model
 {
+    use BaseOptionsTrait, ScopeTrait;
     // 表名
     public $name = 'flange';
     // 数据库字段映射
@@ -51,5 +55,29 @@ class Flange extends Model
         'updated_at',
         // 软删除
         'deleted_at',
+        // 螺丝尺寸
+        'bolt_size',
+        // 螺丝数量
+        'bolt_number',
     );
+
+    public function getList()
+    {
+        return $this->catchSearch()
+        ->append(['depart_name'])
+        ->field('*')
+        ->catchOrder()
+        ->creator()
+        ->paginate();
+    }
+    public function getDepartNameAttr($value)
+    {
+        $id=$this->department_id;
+        return Db::table('departments')->where('id', $id)->value('department_name');
+    }
+
+
+
+
+  
 }

+ 1 - 2
catch/flange/route.php

@@ -13,6 +13,5 @@
 $router->group(function () use ($router){
 	// flange路由
 	$router->resource('flange', '\catchAdmin\flange\controller\flange');
-	// flange路由
-	$router->resource('flange', '\catchAdmin\flange\controller\flange');
+	$router->get("getwindfan",'\catchAdmin\flange\controller\Flange@getWindFan');
 })->middleware('auth');