Explorar o código

提交故障分类和故障限价

dongxiaoqin hai 1 ano
pai
achega
f651ef65ea

+ 13 - 4
app/adminapi/controller/fault_type/FaultTypeController.php

@@ -30,6 +30,18 @@ use app\adminapi\validate\fault_type\FaultTypeValidate;
 class FaultTypeController extends BaseAdminController
 {
 
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/10/18 15:09
+     */
+    public function listsByPid()
+    {
+        $pid = $this->request->get('pid',0);
+        $result = FaultTypeLogic::listsByPid($pid);
+        return $this->success('',$result);
+    }
 
     /**
      * @notes 获取列表
@@ -39,10 +51,7 @@ class FaultTypeController extends BaseAdminController
      */
     public function lists()
     {
-        //return $this->dataLists(new FaultTypeLists());
-        $params = $this->request->get();
-        $result = FaultTypeLogic::lists($params);
-        return $this->success('',$result);
+        return $this->dataLists(new FaultTypeLists());
     }
 
 

+ 18 - 4
app/adminapi/lists/fault_code/FaultCodeLists.php

@@ -16,8 +16,9 @@ namespace app\adminapi\lists\fault_code;
 
 
 use app\adminapi\lists\BaseAdminDataLists;
-use app\common\model\fault_code\FaultCode;
 use app\common\lists\ListsSearchInterface;
+use app\common\model\fault_code\FaultCode;
+use app\common\model\fault_type\FaultType;
 
 
 /**
@@ -38,11 +39,23 @@ class FaultCodeLists extends BaseAdminDataLists implements ListsSearchInterface
     public function setSearch(): array
     {
         return [
-            '=' => ['status','type_id'],
-            '%like%' => ['codes', 'fault_name', 'detail'],
+            '=' => ['status'],
+            '%like%' => ['codes', 'name', 'detail'],
         ];
     }
 
+    public function queryWhere()
+    {
+        if (isset($this->params['type_id']) && $this->params['type_id'] !== '') {
+            $pid = FaultType::where('id', $this->params['type_id'])->value('pid');
+            if ($pid == 0) {
+                $where[] = ['type_id', 'in', FaultType::where('pid', $this->params['type_id'])->column('id')];
+            } else {
+                $where[] = ['type_id', '=', $this->params['type_id']];
+            }
+        }
+        return $where;
+    }
 
     /**
      * @notes 获取列表
@@ -56,6 +69,7 @@ class FaultCodeLists extends BaseAdminDataLists implements ListsSearchInterface
     public function lists(): array
     {
         return FaultCode::with(['faultType'])->where($this->searchWhere)
+            ->where($this->queryWhere())
             ->field(['*'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
@@ -72,7 +86,7 @@ class FaultCodeLists extends BaseAdminDataLists implements ListsSearchInterface
      */
     public function count(): int
     {
-        return FaultCode::where($this->searchWhere)->count();
+        return FaultCode::where($this->searchWhere)->where($this->queryWhere())->count();
     }
 
 }

+ 34 - 7
app/adminapi/lists/fault_type/FaultTypeLists.php

@@ -38,11 +38,29 @@ class FaultTypeLists extends BaseAdminDataLists implements ListsSearchInterface
     public function setSearch(): array
     {
         return [
-            '=' => ['name', 'pid', 'sort', 'level', 'status'],
-
+            '=' => ['pid', 'sort', 'level', 'goods_category_id'],
         ];
     }
 
+    public function queryWhere()
+    {
+        $where = [];
+        if (isset($this->params['status']) && $this->params['status'] != '') {
+            $where[] = ['a.status', '=', $this->params['status']];
+        }
+        if (!empty($this->params['name'])) {
+            $where[] = ['a.name', 'like', '%' . $this->params['name'] . '%'];
+        }
+        if (!empty($this->params['category_name'])) {
+            $where[] = ['b.name', 'like', '%' . $this->params['category_name'] . '%'];
+        }
+        if (!empty($this->params['category_type'])) {
+            $where[] = ['a.category_type', '=', $this->params['category_type']];
+        }
+        $where[] = ['a.pid', '=', 0];
+        return $where;
+    }
+
 
     /**
      * @notes 获取列表
@@ -55,15 +73,20 @@ class FaultTypeLists extends BaseAdminDataLists implements ListsSearchInterface
      */
     public function lists(): array
     {
-        return FaultType::where($this->searchWhere)
-            ->field(['id', 'name', 'pid', 'sort', 'level', 'status'])
+        $lists = FaultType::alias("a")
+            ->with(['children'])
+            ->leftJoin("goods_category b", "a.goods_category_id = b.id")
+            ->where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->field("a.*,b.name as category_name")
             ->limit($this->limitOffset, $this->limitLength)
-            ->order(['id' => 'desc'])
+            ->append(['status_desc'])
+            ->order(['a.sort' => 'desc', 'a.id' => 'desc'])
             ->select()
             ->toArray();
+        return $lists;
     }
 
-
     /**
      * @notes 获取数量
      * @return int
@@ -72,7 +95,11 @@ class FaultTypeLists extends BaseAdminDataLists implements ListsSearchInterface
      */
     public function count(): int
     {
-        return FaultType::where($this->searchWhere)->count();
+        return FaultType::alias("a")
+            ->where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->leftJoin("goods_category b", "a.goods_category_id = b.id")
+            ->count();
     }
 
 }

+ 18 - 6
app/adminapi/logic/fault_code/FaultCodeLogic.php

@@ -42,9 +42,7 @@ class FaultCodeLogic extends BaseLogic
         try {
             FaultCode::create([
                 'type_id' => $params['type_id'],
-                'codes' => $params['codes'],
-                'fault_name' => $params['fault_name'],
-                'detail' => $params['detail'],
+                'name' => $params['name'],
                 'status' => $params['status'],
             ]);
 
@@ -71,9 +69,7 @@ class FaultCodeLogic extends BaseLogic
         try {
             FaultCode::where('id', $params['id'])->update([
                 'type_id' => $params['type_id'],
-                'codes' => $params['codes'],
-                'fault_name' => $params['fault_name'],
-                'detail' => $params['detail'],
+                'name' => $params['name'],
                 'status' => $params['status'],
             ]);
 
@@ -111,4 +107,20 @@ class FaultCodeLogic extends BaseLogic
     {
         return FaultCode::findOrEmpty($params['id'])->toArray();
     }
+
+    public static function lists($params)
+    {
+        $where = [];
+        if (!empty($params['type_id'])) {
+            $where[] = ['type_id', '=', $params['type_id']];
+        }
+
+        $lists = FaultCode::where('status',1)
+            ->where($where)
+            ->field('id,name,price,type_id')
+            ->limit(100)
+            ->select()
+            ->toArray();
+        return $lists;
+    }
 }

+ 7 - 17
app/adminapi/logic/fault_type/FaultTypeLogic.php

@@ -27,27 +27,16 @@ use think\facade\Db;
  */
 class FaultTypeLogic extends BaseLogic
 {
-    public static function lists($params)
+    //获取一级分类
+    public static function listsByPid($pid = 0)
     {
-        $where = [];
-        if (!empty($params['name'])) {
-            $where[] = ['name', 'like', '%' . $params['name'] . '%'];
-        }
-        if (isset($params['status']) && $params['status'] != '') {
-            $where[] = ['status', '=', $params['status']];
-        }
-        $lists = FaultType::where($where)
-            ->append(['status_desc'])
-            ->order(['sort' => 'desc', 'id' => 'desc'])
+        $lists = FaultType::where("pid", $pid)
+            ->field("id,pid,name")
             ->select()
             ->toArray();
-
-        $pid = 0;
-        if (!empty($lists)) {
-            $pid = min(array_column($lists, 'pid'));
-        }
-        return self::getTree($lists, $pid);
+        return $lists;
     }
+
     public static function getTree($array, $pid = 0, $level = 0)
     {
         $list = [];
@@ -159,6 +148,7 @@ class FaultTypeLogic extends BaseLogic
     public static function getAllData($search = 'all')
     {
         $data = FaultType::where('status',1)
+            ->field('id,pid,name,sort,category_type,goods_category_id')
             ->order(['sort'=> 'desc','id' => 'desc'])
             ->select()
             ->toArray();

+ 4 - 4
app/adminapi/validate/fault_code/FaultCodeValidate.php

@@ -33,7 +33,7 @@ class FaultCodeValidate extends BaseValidate
     protected $rule = [
         'id' => 'require',
         'type_id' => 'require',
-        'codes' => 'require',
+        'name' => 'require',
 
     ];
 
@@ -44,7 +44,7 @@ class FaultCodeValidate extends BaseValidate
      */
     protected $field = [
         'id' => 'id',
-        'codes' => '故障码',
+        'name' => '故障名称',
         'type_id' => '分类Id',
 
     ];
@@ -58,7 +58,7 @@ class FaultCodeValidate extends BaseValidate
      */
     public function sceneAdd()
     {
-        return $this->only(['codes']);
+        return $this->only(['name']);
     }
 
 
@@ -70,7 +70,7 @@ class FaultCodeValidate extends BaseValidate
      */
     public function sceneEdit()
     {
-        return $this->only(['id','codes']);
+        return $this->only(['id','name']);
     }
 
 

+ 3 - 1
app/common/model/fault_type/FaultType.php

@@ -29,6 +29,8 @@ class FaultType extends BaseModel
     
     protected $name = 'fault_type';
     
-
+    public function children() {
+        return $this->hasMany(FaultType::class, 'pid', 'id');
+    }
     
 }

+ 58 - 11
app/workerapi/controller/FaultCodeController.php

@@ -2,32 +2,79 @@
 
 namespace app\workerapi\controller;
 
-
 use app\adminapi\logic\fault_code\FaultCodeLogic;
 use app\adminapi\logic\fault_type\FaultTypeLogic;
 use app\adminapi\validate\fault_code\FaultCodeValidate;
-use app\workerapi\lists\FaultCodeLists;
 
 class FaultCodeController extends BaseApiController
 {
     public array $notNeedLogin = ['getTreeLists','detail'];
     public function getTreeLists()
     {
-        $result = FaultTypeLogic::getAllData('api');
+        $goods_category_id = $this->request->get('goods_category_id', 0);
+        $result = FaultTypeLogic::getAllData('api',$goods_category_id);
         return $this->data($result);
-        //return $this->dataLists(new FaultCodeLists());
     }
     /**
-     * @notes 获取详情
+     * @notes 获取列表
      * @return \think\response\Json
      * @author likeadmin
      * @date 2024/10/18 09:58
      */
-    public function detail()
+    public function lists()
     {
-        /*$params = (new FaultCodeValidate())->goCheck('detail');
-        $result = FaultCodeLogic::detail($params);
-        return $this->data($result);*/
-        return $this->dataLists(new FaultCodeLists());
+        $params = (new FaultCodeValidate())->goCheck('detail');
+        $result = FaultCodeLogic::lists($params);
+        return $this->data($result);
     }
-}
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 2 - 2
app/workerapi/lists/FaultCodeLists.php

@@ -37,7 +37,7 @@ class FaultCodeLists extends BaseWorkerDataLists implements ListsSearchInterface
     {
         return [
             '=' => ['status','type_id'],
-            '%like%' => ['codes', 'fault_name', 'detail'],
+            '%like%' => ['name'],
         ];
     }
 
@@ -54,7 +54,7 @@ class FaultCodeLists extends BaseWorkerDataLists implements ListsSearchInterface
     public function lists(): array
     {
         return FaultCode::where($this->searchWhere)
-            ->field(['id', 'codes', 'fault_name','status','detail'])
+            ->field(['id', 'name','status','type_id'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()