tongshanglei 2 년 전
부모
커밋
2f410f34a3

+ 9 - 0
catch/transport/controller/StuckPoint.php

@@ -27,6 +27,15 @@ class StuckPoint extends CatchController
     }
     
     /**
+     * 列表
+     * @time 2022年11月01日 16:16
+     * @param Request $request 
+     */
+    public function getAllList(Request $request) : \think\Response
+    {
+        return CatchResponse::success($this->stuckPointModel->getAllList());
+    }
+    /**
      * 保存信息
      * @time 2022年11月01日 16:16
      * @param Request $request 

+ 30 - 0
catch/transport/controller/StuckSection.php

@@ -66,4 +66,34 @@ class StuckSection extends CatchController
     {
         return CatchResponse::success($this->stuckSectionModel->deleteBy($id));
     }
+
+    /**
+     *
+     * @time 2019年12月07日
+     * @param $id
+     * @return \think\response\Json
+     */
+    public function switchRetrograde($id): \think\response\Json
+    {
+ 
+          $info = $this->stuckSectionModel->findBy($id);
+          $this->stuckSectionModel->updateBy($id, [
+            'retrograde_stat' => $info->retrograde_stat == 1 ? 0 : 1,
+          ]);
+        return CatchResponse::success([], '操作成功');
+    }
+     /**
+     *
+     * @time 2019年12月07日
+     * @param $id
+     * @return \think\response\Json
+     */
+    public function switchOverSpeed($id): \think\response\Json
+    {
+          $info = $this->stuckSectionModel->findBy($id);
+          $this->stuckSectionModel->updateBy($id, [
+            'over_speed_stat' => $info->over_speed_stat == 1 ? 0 : 1,
+          ]);
+        return CatchResponse::success([], '操作成功');
+    }
 }

+ 6 - 6
catch/transport/database/migrations/20221101162701_stuck_section.php

@@ -31,12 +31,12 @@ class StuckSection extends Migrator
     {
         $table = $this->table('stuck_section', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '卡点区间' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
         $table->addColumn('name', 'string', ['limit' => 128,'null' => true,'signed' => true,'comment' => '名称',])
-			->addColumn('pre_spot', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '前置卡点',])
-			->addColumn('pos_spot', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '后置卡点',])
-			->addColumn('distance', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '区间长度',])
-			->addColumn('max_speed', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '最大限速(km/h)',])
-			->addColumn('retrograde_stat', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '启用逆行状态',])
-			->addColumn('over_speed_stat', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '启用超速状态',])
+			->addColumn('pre_spot', 'string', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '前置卡点',])
+			->addColumn('pos_spot', 'string', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '后置卡点',])
+			->addColumn('distance', 'string', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '区间长度',])
+			->addColumn('max_speed', 'string', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '最大限速(km/h)',])
+			->addColumn('retrograde_stat', 'string', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '启用逆行状态',])
+			->addColumn('over_speed_stat', 'string', ['limit' => MysqlAdapter::INT_REGULAR,'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' => '更新时间',])

+ 37 - 1
catch/transport/model/StuckPoint.php

@@ -3,9 +3,11 @@
 namespace catchAdmin\transport\model;
 
 use catcher\base\CatchModel as Model;
-
+use catchAdmin\permissions\model\DataRangScopeTrait;
+use catchAdmin\system\model\SysDictData;
 class StuckPoint extends Model
 {
+    use DataRangScopeTrait;
     // 表名
     public $name = 'stuck_point';
     // 数据库字段映射
@@ -24,4 +26,38 @@ class StuckPoint extends Model
         // 软删除
         'deleted_at',
     );
+    /**
+     * 列表
+     */
+    public function getList()
+    {
+        $res=$this->dataRange()
+            ->catchSearch()
+            ->order($this->aliasField('id'), 'desc')
+            ->paginate();
+        return $res;
+    }
+    public function getAllList()
+    {
+        $res=$this->dataRange()
+            ->catchSearch()
+            ->order($this->aliasField('id'), 'desc')
+            ->select();
+        return $res;
+    }
+    
+    //根据name搜索
+    public function searchNameAttr($query, $value, $data)
+    {
+        return $query->where('name', 'like', '%' . $value . '%');
+    }
+
+    public function getMacsAttr($value){
+        if($value){
+            return explode(',',$value);
+        }else{
+            return [];
+        }
+        
+    }
 }

+ 46 - 1
catch/transport/model/StuckSection.php

@@ -3,9 +3,11 @@
 namespace catchAdmin\transport\model;
 
 use catcher\base\CatchModel as Model;
-
+use catchAdmin\permissions\model\DataRangScopeTrait;
+use think\facade\Db;
 class StuckSection extends Model
 {
+    use DataRangScopeTrait;
     // 表名
     public $name = 'stuck_section';
     // 数据库字段映射
@@ -34,4 +36,47 @@ class StuckSection extends Model
         // 软删除
         'deleted_at',
     );
+    /**
+     * 列表
+     */
+    public function getList()
+    {
+        $res=$this->dataRange()
+            ->catchSearch()
+            ->append(['pos_spot_text','pre_spot_text'])
+            ->order($this->aliasField('id'), 'desc')
+            ->paginate();
+        return $res;
+    }
+    //根据name搜索
+    public function searchNameAttr($query, $value, $data)
+    {
+        return $query->where('name', 'like', '%' . $value . '%');
+    }
+    public function getPosSpotTextAttr($value){
+        $value=$this->getData('pos_spot');
+        return Db::table('stuck_point')->where('id',$value)->value('name');
+    }
+    public function getPreSpotTextAttr($value){
+        $value=$this->getData('pos_spot');
+        return Db::table('stuck_point')->where('id',$value)->value('name');
+    }
+    public function getRetrogradeStatAttr($value){
+        return $value?true:false;
+    }
+    public function getOverSpeedStatAttr($value){
+        return $value?true:false;
+    }
+    public function getPreSpotAttr($value){
+        return (string)$value;
+    }
+    public function getPosSpotAttr($value){
+        return (string)$value;
+    }
+    public function getDistanceAttr($value){
+        return (string)$value;
+    }
+    public function getMaxSpeedAttr($value){
+        return (string)$value;
+    }
 }

+ 5 - 0
catch/transport/route.php

@@ -12,7 +12,12 @@
 // you should use `$router`
 $router->group(function () use ($router){
 	// stuckPoint路由
+	
 	$router->resource('stuckPoint', '\catchAdmin\transport\controller\StuckPoint');
+	$router->get('getStuckPointList', '\catchAdmin\transport\controller\StuckPoint@getAllList');
+	
 	// stuckSection路由
 	$router->resource('stuckSection', '\catchAdmin\transport\controller\StuckSection');
+	$router->put('stuckSection/switchRetrograde/<id>', '\catchAdmin\transport\controller\StuckSection@switchRetrograde');
+	$router->put('stuckSection/switchOverSpeed/<id>', '\catchAdmin\transport\controller\StuckSection@switchOverSpeed');
 })->middleware('auth');