Browse Source

fix:根据验收类型获取

super-yimizi 1 month ago
parent
commit
f408cee2d6

+ 6 - 0
application/api/controller/inspection/Index.php

@@ -16,6 +16,12 @@ class Index extends Base
       */
      public function getOptions()
      {
+        //  查询验货类型的 
+        $inspectId= $this->request->param('inspect_type_id');
+        if(intval($inspectId) <= 0){
+            $this->error('验货类型ID不能为空');
+        }
+        $params['inspect_type_id'] = $inspectId;
         $params = [
             'status' => StatusEnum::ENABLED,
         ];

+ 10 - 2
application/common/Service/InspectService.php

@@ -7,7 +7,8 @@ use think\Db;
 use app\common\enum\OrderEnum;
 use app\common\Service\OrderService;
 use app\common\exception\BusinessException;
-
+use app\common\model\inspection\TypeItem;
+use app\common\model\inspection\Item;
 class InspectService
 {
     /**
@@ -38,8 +39,15 @@ class InspectService
         if (isset($params['name']) && $params['name'] !== '') {
             $where['name'] = ['like', '%' . $params['name'] . '%'];
         }
+
+        if (isset($params['inspect_type_id']) && $params['inspect_type_id'] !== '') {
+            // 通过关联表查询ID
+            $typeItem = TypeItem::where('type_id', $params['inspect_type_id'])->select();
+            $inspectIds = array_column( collection($typeItem)->toArray(), 'item_id');
+            $where['id'] = ['in', $inspectIds];
+        }
         
-        $query = (new \app\common\model\inspection\Item())->where($where)
+        $query = (new Item())->where($where)
           ->field('id,name,parent_id,is_required,status,standard_desc');
         
         // 排序

+ 49 - 0
application/common/model/inspection/Type.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace app\common\model\inspection;
+
+use think\Model;
+use traits\model\SoftDelete;
+use app\common\Enum\StatusEnum;
+class Type extends Model
+{
+
+    use SoftDelete;
+
+    
+
+    // 表名
+    protected $table = 'inspection_type';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = 'deletetime';
+
+    // 追加属性
+    protected $append = [
+        'status_text'
+    ];
+    
+
+    
+    public function getStatusList()
+    {
+        return StatusEnum::getMap();
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ?: ($data['status'] ?? '');
+        $list = $this->getStatusList();
+        return $list[$value] ?? '';
+    }
+
+
+
+
+}

+ 49 - 0
application/common/model/inspection/TypeItem.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace app\common\model\inspection;
+
+use think\Model;
+use traits\model\SoftDelete;
+use app\common\Enum\StatusEnum;
+class TypeItem extends Model
+{
+
+    use SoftDelete;
+
+    
+
+    // 表名
+    protected $table = 'inspection_type_item';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = 'deletetime';
+
+    // 追加属性
+    protected $append = [
+        'status_text'
+    ];
+    
+
+    
+    public function getStatusList()
+    {
+        return StatusEnum::getMap();
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ?: ($data['status'] ?? '');
+        $list = $this->getStatusList();
+        return $list[$value] ?? '';
+    }
+
+
+
+
+}