Просмотр исходного кода

Merge branch 'master' of e.coding.net:zdap/weixiu/weixiu_api into m--tmp

liugc 11 месяцев назад
Родитель
Сommit
82196ecde7

+ 2 - 1
app/adminapi/controller/works/GroupServiceWorkController.php

@@ -151,7 +151,8 @@ class GroupServiceWorkController extends BaseAdminController
     public function import()
     {
         $file = request()->file('file');
-        $result = GroupServiceWorkLogic::import($file);
+        $third_type = request()->request('third_type','2');
+        $result = GroupServiceWorkLogic::import($file,$third_type);
         if (true === $result) {
             return $this->success('导入成功', [], 1, 1);
         }

+ 8 - 3
app/adminapi/lists/fault_code/FaultCodeLists.php

@@ -39,7 +39,7 @@ class FaultCodeLists extends BaseAdminDataLists implements ListsSearchInterface
     public function setSearch(): array
     {
         return [
-            '=' => ['status','type'],
+            '=' => ['status'],
             '%like%' => ['codes', 'name', 'detail'],
         ];
     }
@@ -48,7 +48,12 @@ class FaultCodeLists extends BaseAdminDataLists implements ListsSearchInterface
     {
         $where = [];
         if (isset($this->params['type_id']) && $this->params['type_id'] !== '') {
-            $where[] = ['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;
     }
@@ -68,7 +73,7 @@ class FaultCodeLists extends BaseAdminDataLists implements ListsSearchInterface
             ->where($this->queryWhere())
             ->field(['*'])
             ->limit($this->limitOffset, $this->limitLength)
-            ->order(['id' => 'desc'])
+            ->order(['id' => 'asc'])
             ->select()
             ->toArray();
     }

+ 1 - 1
app/adminapi/lists/fault_type/FaultTypeLists.php

@@ -81,7 +81,7 @@ class FaultTypeLists extends BaseAdminDataLists implements ListsSearchInterface
             ->field("a.*,b.name as category_name")
             ->limit($this->limitOffset, $this->limitLength)
             ->append(['status_desc'])
-            ->order(['a.sort' => 'desc', 'a.id' => 'desc'])
+            ->order(['a.sort' => 'desc', 'a.id' => 'asc'])
             ->select()
             ->toArray();
         return $lists;

+ 4 - 1
app/adminapi/lists/works/GroupServiceWorkLists.php

@@ -40,7 +40,7 @@ class GroupServiceWorkLists extends BaseAdminDataLists implements ListsSearchInt
     public function setSearch(): array
     {
         return [
-            '=' => ['id','category_type', 'work_status', 'master_worker_id','third_type','group_order_id'],
+            '=' => ['id','category_type', 'work_status', 'master_worker_id','third_type','group_order_id','settlement_status'],
             '%like%'=>[ 'work_sn','mobile','real_name', 'title', 'address']
         ];
     }
@@ -50,6 +50,9 @@ class GroupServiceWorkLists extends BaseAdminDataLists implements ListsSearchInt
         if (!empty($this->params['service_status']) && $this->params['service_status'] == 1) {
             $where[] = ['service_status', '<>', 3];
         }
+        if (isset($this->params['third_type']) && $this->params['third_type'] == '') {
+            $where[] = ['third_type', '<>', 3];
+        }
         if (!empty($this->params['service_status']) && $this->params['service_status'] == 2) {
             $where[] = ['service_status', '=', 3];
         }

+ 1 - 1
app/adminapi/logic/fault_type/FaultTypeLogic.php

@@ -152,7 +152,7 @@ class FaultTypeLogic extends BaseLogic
     {
         $data = FaultType::where('status',1)
             ->field('id,pid,name,sort,category_type,goods_category_id')
-            ->order(['sort'=> 'desc','id' => 'desc'])
+            ->order(['sort'=> 'desc','id' => 'asc'])
             ->select()
             ->toArray();
         if($search == 'all'){

+ 2 - 2
app/adminapi/logic/property/PropertyHeadLogic.php

@@ -56,7 +56,7 @@ class PropertyHeadLogic extends BaseLogic
                 'head_name' => $params['head_name'],
                 'head_mobile' => $params['head_mobile'],
                 'ratio' => $params['ratio']??0,
-                'type' => $params['type'],
+                'type' => isset($params['type']) ? $params['type'] : 1,
                 'head_bank_card' => $params['head_bank_card']??'',
                 'head_corporate_bank' => $params['head_corporate_bank']??'',
                 'lon' => $params['lon']??0,
@@ -114,7 +114,7 @@ class PropertyHeadLogic extends BaseLogic
                 'head_name' => $params['head_name'],
                 'head_mobile' => $params['head_mobile'],
                 'ratio' => $params['ratio'],
-                'type' => $params['type'],
+                'type' => isset($params['type']) ? $params['type'] : 1,
                 'head_bank_card' => $params['head_bank_card'],
                 'head_corporate_bank' => $params['head_corporate_bank']??'',
                 'lon' => $params['lon'],

+ 25 - 8
app/adminapi/logic/works/GroupServiceWorkLogic.php

@@ -46,11 +46,27 @@ class GroupServiceWorkLogic extends BaseLogic
     {
         Db::startTrans();
         try {
-            GroupServiceWork::where('id', $params['id'])->update([
-                'address' => $params['address'],
-                'appointment_time' => strtotime($params['appointment_time']),
-                'remark' => $params['remark'],
-            ]);
+            $work = GroupServiceWork::where('id', $params['id'])->findOrEmpty()->toArray();
+            if (empty($work)) {
+                throw new Exception('工单不存在');
+            }
+            if ($work['third_type'] == 3) {
+                GroupServiceWork::where('id', $params['id'])->update([
+                    'work_total' => $params['work_total'],
+                    'work_amount' => $params['work_amount'],
+                    'settlement_amount' => $params['settlement_amount'],
+                    'settlement_status' => $params['settlement_status'],
+                    'address' => $params['address'],
+                    'appointment_time' => strtotime($params['appointment_time']),
+                    'remark' => $params['remark'],
+                ]);
+            } else {
+                GroupServiceWork::where('id', $params['id'])->update([
+                    'address' => $params['address'],
+                    'appointment_time' => strtotime($params['appointment_time']),
+                    'remark' => $params['remark'],
+                ]);
+            }
             Db::commit();
             return true;
         } catch (\Exception $e) {
@@ -327,7 +343,7 @@ class GroupServiceWorkLogic extends BaseLogic
                 }
             ])
             ->where($work_where)
-            ->field('id,work_sn,real_name,mobile,address,title,category_type,master_worker_id,work_status,user_confirm_status,service_status,dispatch_time,appointment_time,receive_time,work_images,finished_images,finished_time,area_name,finally_door_time,create_time,remark,third_type,work_total,work_amount,settlement_amount,work_pay_status')
+            ->field('id,work_sn,real_name,mobile,address,title,category_type,master_worker_id,work_status,user_confirm_status,service_status,dispatch_time,appointment_time,receive_time,work_images,finished_images,finished_time,area_name,finally_door_time,create_time,remark,third_type,work_total,work_amount,settlement_amount,settlement_status,work_pay_status')
             ->append(['id','work_status_text','service_status_text'])
             ->findOrEmpty()->toArray();
         if (empty($result)) {
@@ -386,7 +402,7 @@ class GroupServiceWorkLogic extends BaseLogic
     /**
      * 导入拼团工单
      */
-    public static function import($file) {
+    public static function import($file,$third_type) {
         
         try {
             // 移动文件到指定目录
@@ -401,6 +417,7 @@ class GroupServiceWorkLogic extends BaseLogic
 
                 // 假设第一行为表头,从第二行开始读取数据
                 for ($row = 2; $row <= $highestRow; $row++) {
+                    
                     $data = [
                         'title' => $worksheet->getCell('A' . $row)->getValue(),
                         'real_name' => $worksheet->getCell('B' . $row)->getValue(),
@@ -417,7 +434,7 @@ class GroupServiceWorkLogic extends BaseLogic
                     if(empty($data['title']) || empty($data['real_name']) || empty($data['mobile']) || empty($data['address'])){
                         continue;
                     }
-                    $data['third_type'] = 2;
+                    $data['third_type'] = $third_type;
                     $data['work_pay_status'] = 2;
                     $data['category_type'] = 2;
                     $data['appointment_time'] = $data['appointment_time'] ? strtotime($data['appointment_time']) : 0;

+ 64 - 33
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -252,34 +252,75 @@ class ServiceWorkLogic extends BaseLogic
                 throw new Exception('请勿重复操作');
             }
 
-            // 关联配件信息.计算配件总价  id  company_price original_price offering_price number
+            // 商城配件.计算配件总价  id  company_price original_price offering_price number
             $spare_total = 0;
             $work->spare_total = 0;
             isset($params['spare_parts']) && $params['spare_parts'] && $params['spare_parts'] = json_decode($params['spare_parts'], true);
+            $spare_parts_ids = ServiceWorkSpare::where('service_work_id',$work['id'])->column('id');
+            
             if(isset($params['spare_parts']) && $params['spare_parts']){
-                $spare_parts = $params['spare_parts'];
-                foreach ($spare_parts as $spare){
-                    $spare_total += $spare['company_price']*$spare['number'];
+                if (count($params['spare_parts']) > 10) {
+                    throw new Exception('商城配件最多10个');
+                }
+                $ids = array_column($params['spare_parts'],'id');
+                $spare_parts = SparePart::where('id','in',$ids)->column('id as spare_part_id,spare_name,spare_image,company_price,original_price,offering_price,spare_number,spare_unit,brand');
+                $spare_parts = array_column($spare_parts,null,'spare_part_id');
+
+                foreach ($params['spare_parts'] as $k => $item){
+                    if (!isset($spare_parts[$item['id']])){
+                        throw new Exception('配件信息错误');
+                    }
+                    $spare_part = $spare_parts[$item['id']];
+                    $spare_total += $spare_part['company_price']*$item['spare_number'];
+                    $data = array_merge($spare_part, ['service_work_id' => $work['id'], 'spare_number' => $item['spare_number'] * $spare_part['spare_number']]);
+
+                    if (current($spare_parts_ids)) {
+                        //修改
+                        ServiceWorkSpare::where("id",current($spare_parts_ids))->update($data);
+                    } else {
+                        //新增
+                        ServiceWorkSpare::create($data);
+                    }
+                    array_shift($spare_parts_ids);
                 }
                 $work->spare_total += $spare_total;
-
-                $service_work_spare = ServiceWorkSpare::where(['service_work_id'=>$work['id']])->findOrEmpty();
-                if($service_work_spare->isEmpty()){
-                    //新增
-                    $service_work_spare = ServiceWorkSpare::create([
+            }
+            //自选配件
+            isset($params['self_spare_parts']) && $params['self_spare_parts'] && $params['self_spare_parts'] = json_decode($params['self_spare_parts'], true);
+            if(isset($params['self_spare_parts']) && $params['self_spare_parts']){
+                if (count($params['self_spare_parts']) > 10) {
+                    throw new Exception('自选配件最多10个');
+                }
+                foreach ($params['self_spare_parts'] as $item){
+                    $spare_total += $item['offering_price']*$item['spare_number'];
+                    $data = [
                         'service_work_id'=>$work['id'],
-                        'spare_parts'=>$params['spare_parts'],
-                        'remark'=>''
-                    ]);
-                }else{
-                    //修改
-                    $service_work_spare->spare_parts = $params['spare_parts'];
-                    $service_work_spare->save();
+                        'spare_name' => $item['spare_name'],
+                        'spare_image' => $item['spare_image'],
+                        'offering_price' => $item['offering_price'],
+                        'company_price' => 0,
+                        'original_price' => 0,
+                        'spare_number' => $item['spare_number'],
+                        'spare_part_id' => 0,
+                        'brand' => $item['brand']
+                    ];
+                    if (current($spare_parts_ids)) {
+                        //修改
+                        ServiceWorkSpare::where("id",current($spare_parts_ids))->update($data);
+                    } else {
+                        //新增
+                        ServiceWorkSpare::create($data);
+                    }
+                    array_shift($spare_parts_ids);
                 }
-                $work->service_work_spare_id = $service_work_spare->id;
-            }elseif (isset($params['spare_total']) && $params['spare_total']){
-                $work->spare_total += $params['spare_total'];
+                $work->spare_total += $spare_total;
             }
+
+            //删除多余的配件数据
+            if ($spare_parts_ids) {
+                ServiceWorkSpare::where('id','in',$spare_parts_ids)->delete();
+            }
+
             // 添加工单尾款报价记录 - 即配件费用
             if(isset($params['price_content'])){
                 !is_array($params['price_content']) && $params['price_content'] = json_decode($params['price_content'], true);
@@ -291,7 +332,6 @@ class ServiceWorkLogic extends BaseLogic
                 $work->spare_total += array_sum('price');
             }
 
-
             // order_amount 原 =  $params['amount'] 修改为 = 配件总价 + 服务尾款
             $order_amount = $params['amount'] + $spare_total;
 
@@ -350,8 +390,6 @@ class ServiceWorkLogic extends BaseLogic
             ];
             ServiceWorkLogLogic::add($work_log);
 
-
-
             Db::commit();
             // 商家报价通知外部平台 即报价
             if($work->external_platform_id > 0){
@@ -609,17 +647,10 @@ class ServiceWorkLogic extends BaseLogic
 
         // 配件信息
         $result['spare_parts'] = [];
-        if($result['service_work_spare_id']){
-            $work_spare_parts = json_decode(ServiceWorkSpare::where('id',$result['service_work_spare_id'])->value('spare_parts'),true);
-            $spare_parts = SparePart::where('id','in',array_column($work_spare_parts,'id'))
-                ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit','spare_status'])
-                ->select()
-                ->toArray();
-            $spare_parts = array_column($spare_parts,null,'id');
-            foreach (array_column($work_spare_parts,null,'id') as $k=>&$v){
-                $spare_parts[$k] = array_merge($spare_parts[$k],$v);
-            }
-            $result['spare_parts'] = array_values($spare_parts)??[];
+        $result['self_spare_parts'] = [];
+        if($result['spare_total'] > 0){
+            $result['spare_parts'] = ServiceWorkSpare::getLists($result['id'], 1);
+            $result['self_spare_parts'] = ServiceWorkSpare::getLists($result['id'], 2);
         }
         // 保修卡信息
         $result['order_effectives'] = OrderEffectiveLog::with(['goods'=>function ($query) {

+ 10 - 0
app/api/lists/group_activity/UserOrderLists.php

@@ -24,6 +24,14 @@ class UserOrderLists extends BaseApiDataLists implements ListsSearchInterface
             '=' => ['a.status'],
         ];
     }
+
+    public function queryWhere(){
+        $where = [];
+        if (empty($this->params['status'])) {
+            $where[] = ['a.status', '<>', 0];
+        }
+        return $where;
+    }
     
     /**
      * @notes 获取列表
@@ -38,6 +46,7 @@ class UserOrderLists extends BaseApiDataLists implements ListsSearchInterface
                 'a.user_id' => $this->userId,
             ])
             ->where($this->searchWhere)
+            ->where($this->queryWhere())
             ->limit($this->limitOffset, $this->limitLength)
             ->order('a.create_time', 'desc')
             ->select()
@@ -56,6 +65,7 @@ class UserOrderLists extends BaseApiDataLists implements ListsSearchInterface
                 'user_id' => $this->userId,
             ])
             ->where($this->searchWhere)
+            ->where($this->queryWhere())
             ->count();
     }
 

+ 20 - 13
app/common/command/FaultInit.php

@@ -91,16 +91,16 @@ class FaultInit extends Command
      */
     protected function getData($productId, $category_type, $goods_category_id)
     {
-        $type_list = [
-            '维修项目' => '1',
-            '特殊项目' => '2', 
-            '仅检测' => '3',
-            '仅维修' => '4',
-            '检测+维修' => '5',
-            '服务收费' => '6',
-            '特殊故障' => '7',
-            '产品销售' => '8',
-        ];
+        // $type_list = [
+        //     '维修项目' => '1',
+        //     '特殊项目' => '2', 
+        //     '仅检测' => '3',
+        //     '仅维修' => '4',
+        //     '检测+维修' => '5',
+        //     '服务收费' => '6',
+        //     '特殊故障' => '7',
+        //     '产品销售' => '8',
+        // ];
         $params = [
             'cityId' => '500100',
             'productId' => $productId,
@@ -113,23 +113,30 @@ class FaultInit extends Command
             if (!empty($response['data']['chargingStandardList'])) {
                 $data = $response['data']['chargingStandardList'];
                 foreach($data as $item) {
+                    //一级分类
                     $res = FaultType::create([
                         'name' => $item['productName'], //分类名称
                         'category_type' => $category_type,
                         'goods_category_id' => $goods_category_id,
                         'pid' => 0
                     ]);
-                    $type_id = $res->id;
+                    $pid = $res->id;
 
                     $list = $item['itemTypeList'];//故障限价列表
                     foreach($list as $v) {
-                        $type = isset($type_list[$v['itemTypeName']]) ? $type_list[$v['itemTypeName']] : 0;
+                        //二级分类
+                        $res = FaultType::create([
+                            'name' => $v['itemTypeName'], //分类名称
+                            'category_type' => $category_type,
+                            'goods_category_id' => $goods_category_id,
+                            'pid' => $pid
+                        ]);
+                        $type_id = $res->id;
                         foreach($v['itemList'] as $vv) {
                             FaultCode::create([
                                 'type_id' => $type_id,
                                 'name' => $vv['itemName'],
                                 'price' => $vv['price'],
-                                'type' => $type,
                             ]);
                         }
                     }

+ 19 - 0
app/common/model/works/ServiceWorkSpare.php

@@ -32,5 +32,24 @@ class ServiceWorkSpare extends BaseModel
         'spare_parts' =>  'array'
     ];
 
+    public static function getLists($service_work_id, $type = null) {
+        $where = [];
+        //商城工单配件
+        if ($type == 1) {
+            $where[] = ['spare_part_id','>', 0];
+            
+        } else if ($type == 2) {
+            //自选工单配件
+            $where[] = ['spare_part_id','=', 0];
+        } 
+        
+        $lists = self::where('service_work_id', $service_work_id)
+                    ->where($where)
+                    ->field("id,spare_part_id, spare_name, spare_image, company_price, original_price, offering_price, spare_number,spare_unit,brand")
+                    ->select()
+                    ->toArray();
+        return $lists;
+    }
+
     
 }

+ 66 - 30
app/tenantapi/logic/works/ServiceWorkLogic.php

@@ -214,32 +214,75 @@ class ServiceWorkLogic extends BaseLogic
                 throw new Exception('请勿重复操作');
             }
 
-            // 关联配件信息.计算配件总价  id  company_price original_price offering_price number
+            // 商城配件.计算配件总价  id  company_price original_price offering_price number
             $spare_total = 0;
-
+            $work->spare_total = 0;
             isset($params['spare_parts']) && $params['spare_parts'] && $params['spare_parts'] = json_decode($params['spare_parts'], true);
+            $spare_parts_ids = ServiceWorkSpare::where('service_work_id',$work['id'])->column('id');
+            
             if(isset($params['spare_parts']) && $params['spare_parts']){
-                $spare_parts = $params['spare_parts'];
-                foreach ($spare_parts as $spare){
-                    $spare_total += $spare['company_price']*$spare['number'];
+                if (count($params['spare_parts']) > 10) {
+                    throw new Exception('商城配件最多10个');
                 }
-                $work->spare_total = $spare_total;
-
-                $service_work_spare = ServiceWorkSpare::where(['service_work_id'=>$work['id']])->findOrEmpty();
-                if($service_work_spare->isEmpty()){
-                    //新增
-                    $service_work_spare = ServiceWorkSpare::create([
+                $ids = array_column($params['spare_parts'],'id');
+                $spare_parts = SparePart::where('id','in',$ids)->column('id,spare_name,spare_image,company_price,original_price,offering_price,spare_number,spare_unit,brand');
+                $spare_parts = array_column($spare_parts,null,'id');
+
+                foreach ($params['spare_parts'] as $k => $item){
+                    if (!isset($spare_parts[$item['id']])){
+                        throw new Exception('配件信息错误');
+                    }
+                    $spare_part = $spare_parts[$item['id']];
+                    $spare_total += $spare_part['company_price']*$item['spare_number'];
+                    $data = array_merge($spare_part, ['service_work_id' => $work['id'], 'spare_number' => $item['spare_number'] * $spare_part['spare_number']]);
+                    unset($data['id']);
+                    if (current($spare_parts_ids)) {
+                        //修改
+                        ServiceWorkSpare::where("id",current($spare_parts_ids))->update($data);
+                    } else {
+                        //新增
+                        ServiceWorkSpare::create($data);
+                    }
+                    array_shift($spare_parts_ids);
+                }
+                $work->spare_total += $spare_total;
+            }
+            //自选配件
+            isset($params['self_spare_parts']) && $params['self_spare_parts'] && $params['self_spare_parts'] = json_decode($params['self_spare_parts'], true);
+            if(isset($params['self_spare_parts']) && $params['self_spare_parts']){
+                if (count($params['self_spare_parts']) > 10) {
+                    throw new Exception('自选配件最多10个');
+                }
+                foreach ($params['self_spare_parts'] as $item){
+                    $spare_total += $item['offering_price']*$item['spare_number'];
+                    $data = [
                         'service_work_id'=>$work['id'],
-                        'spare_parts'=>$params['spare_parts'],
-                        'remark'=>''
-                    ]);
-                }else{
-                    //修改
-                    $service_work_spare->spare_parts = $params['spare_parts'];
-                    $service_work_spare->save();
+                        'spare_name' => $item['spare_name'],
+                        'spare_image' => $item['spare_image'],
+                        'offering_price' => $item['offering_price'],
+                        'company_price' => 0,
+                        'original_price' => 0,
+                        'spare_number' => $item['spare_number'],
+                        'spare_part_id' => 0,
+                        'brand' => $item['brand']
+                    ];
+                    if (current($spare_parts_ids)) {
+                        //修改
+                        ServiceWorkSpare::where("id",current($spare_parts_ids))->update($data);
+                    } else {
+                        //新增
+                        ServiceWorkSpare::create($data);
+                    }
+                    array_shift($spare_parts_ids);
                 }
-                $work->service_work_spare_id = $service_work_spare->id;
+                $work->spare_total += $spare_total;
+            }
+
+            //删除多余的配件数据
+            if ($spare_parts_ids) {
+                ServiceWorkSpare::where('id','in',$spare_parts_ids)->delete();
             }
+            
             // order_amount 原 =  $params['amount'] 修改为 = 配件总价 + 服务尾款
             $order_amount = $params['amount'] + $spare_total;
 
@@ -502,17 +545,10 @@ class ServiceWorkLogic extends BaseLogic
 
         // 配件信息
         $result['spare_parts'] = [];
-        if($result['service_work_spare_id']){
-            $work_spare_parts = json_decode(ServiceWorkSpare::where('id',$result['service_work_spare_id'])->value('spare_parts'),true);
-            $spare_parts = SparePart::where('id','in',array_column($work_spare_parts,'id'))
-                ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit','spare_status'])
-                ->select()
-                ->toArray();
-            $spare_parts = array_column($spare_parts,null,'id');
-            foreach (array_column($work_spare_parts,null,'id') as $k=>&$v){
-                $spare_parts[$k] = array_merge($spare_parts[$k],$v);
-            }
-            $result['spare_parts'] = array_values($spare_parts)??[];
+        $result['self_spare_parts'] = [];
+        if($result['spare_total'] > 0){
+            $result['spare_parts'] = ServiceWorkSpare::getLists($result['id'], 1);
+            $result['self_spare_parts'] = ServiceWorkSpare::getLists($result['id'], 2);
         }
         // 保修卡信息
         $result['order_effectives'] = OrderEffectiveLog::with(['goods'=>function ($query) {

+ 3 - 16
app/workerapi/lists/ServiceWorkSparePartLists.php

@@ -2,7 +2,6 @@
 namespace app\workerapi\lists;
 
 use app\common\lists\ListsSearchInterface;
-use app\common\model\spare_part\SparePart;
 use app\common\model\works\ServiceWork;
 use app\common\model\works\ServiceWorkSpare;
 
@@ -56,22 +55,10 @@ class ServiceWorkSparePartLists extends BaseWorkerDataLists implements ListsSear
     public function lists(): array
     {
         // 配件信息
+        $id = ServiceWork::where($this->searchWhere)->value('id');
         $spare_parts = [];
-        $service_work_spare_id = ServiceWork::where($this->searchWhere)->value('service_work_spare_id');
-        if($service_work_spare_id){
-            $work_spare_parts = json_decode(ServiceWorkSpare::where('id',$service_work_spare_id)->value('spare_parts'),true);
-            $spare_parts = SparePart::where('id','in',array_column($work_spare_parts,'id'))
-                ->where($this->queryWhere())
-                ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit','spare_status'])
-                ->select()
-                ->toArray();
-            $spare_parts = array_column($spare_parts,null,'id');
-            foreach (array_column($work_spare_parts,null,'id') as $k=>&$v){
-                isset($spare_parts[$k]) && $spare_parts[$k] = array_merge($spare_parts[$k],$v);
-            }
-            $this->count = SparePart::where('id','in',array_column($work_spare_parts,'id'))
-                ->where($this->queryWhere())
-                ->count();
+        if($id){
+            $spare_parts = ServiceWorkSpare::getLists($id);
         }
         return $spare_parts?array_values($spare_parts):[];
     }