dongxiaoqin 11 месяцев назад
Родитель
Сommit
f19aa76fa9

+ 6 - 0
app/common/model/fault_code/FaultCode.php

@@ -34,5 +34,11 @@ class FaultCode extends BaseModel
         return $this->hasOne(FaultType::class, 'id', 'type_id')
             ->field('*');
     }
+
+    public function firstType()
+    {
+        return $this->hasOne(FaultType::class, 'id', 'pid')
+            ->field('id,name,pid,goods_category_id');
+    }
     
 }

+ 12 - 0
app/workerapi/controller/FaultCodeController.php

@@ -2,6 +2,7 @@
 
 namespace app\workerapi\controller;
 
+use app\workerapi\lists\FaultSearchLists;
 use app\adminapi\logic\fault_code\FaultCodeLogic;
 use app\adminapi\logic\fault_type\FaultTypeLogic;
 use app\adminapi\validate\fault_code\FaultCodeValidate;
@@ -27,6 +28,17 @@ class FaultCodeController extends BaseApiController
         $result = FaultCodeLogic::lists($params);
         return $this->data($result);
     }
+
+    /**
+     * @notes 故障搜索
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/10/18 09:58
+     */
+    public function search()
+    {        
+        return $this->dataLists(new FaultSearchLists());
+    }
 }
 
 

+ 94 - 0
app/workerapi/lists/FaultSearchLists.php

@@ -0,0 +1,94 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\workerapi\lists;
+
+use app\common\model\fault_code\FaultCode;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * FaultCode列表
+ * Class FaultSearchLists
+ */
+class FaultSearchLists extends BaseWorkerDataLists implements ListsSearchInterface
+{
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/10/18 09:58
+     */
+    public function setSearch(): array
+    {
+        return [
+        ];
+    }
+
+    /*
+     * 查询条件
+     * @return array
+     */
+    public function queryWhere(){
+        
+        $where[] = ['a.status', '=', 1];
+        if (!empty($this->params['keyword'])) {
+            $where[] = ['a.name', 'like', '%'.$this->params['keyword'].'%'];
+        }
+        if (!empty($this->params['goods_category_id'])) {
+            $where[] = ['b.goods_category_id', '=', $this->params['goods_category_id']];
+        } else {
+            $where[] = ['b.goods_category_id', '=', 0];
+        }
+        return $where;
+    }
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2024/10/18 09:58
+     */
+    public function lists(): array
+    {
+        $lists = FaultCode::alias("a")
+            ->with(['firstType'])
+            ->leftJoin('fault_type b', 'a.type_id = b.id')
+            ->where($this->queryWhere())
+            ->field('a.id,a.name,a.price,b.id as pre_id ,b.name as pre_name, b.pid')
+            ->limit($this->limitOffset, $this->limitLength)
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/10/18 09:58
+     */
+    public function count(): int
+    {
+        return FaultCode::alias("a")
+            ->leftJoin('fault_type b', 'a.type_id = b.id')
+            ->where($this->queryWhere())
+            ->count();
+    }
+
+}