setName('fault_init') ->setDescription('家电维修故障限价数据抓取'); } protected function execute(Input $input, Output $output) { //挂机空调维修 $this->getData('10763',1,17); //柜机空调维修 $this->getData('10764',1,17); //家用中央空调维修 $this->getData('10765',1,17); //空调加氟(变频挂机 1-1.5P加氟) $this->getData('23153',1,52); //空调加氟(变频挂机 1-1.5P加氟) $this->getData('23153',1,52); //空调加氟(变频挂机 2-3P加氟) $this->getData('23154',1,52); //空调加氟(定频挂机 1-1.5P加氟) $this->getData('23156',1,52); //空调加氟(定频挂机 2-3P加氟) $this->getData('23157',1,52); //空调加氟(变频柜机 2-3P加氟) $this->getData('23155',1,52); //空调加氟(定频柜机 2-3P加氟) $this->getData('23158',1,52); //冰箱维修 $this->getData('10766',1,50); //洗衣机维修 $this->getData('10767',1,42); //干洗机维修 $this->getData('10797',1,37); //甩干机维修 $this->getData('10799',1,41); //燃气热水器维修 $this->getData('10769',1,40); //电热水器维修 $this->getData('10770',1,39); //燃气灶维修 $this->getData('10772',1,38); //油烟机维修 $this->getData('10773',1,43); //制冷设备(冰柜)维修 $this->getData('10813',1,44); //制冷设备(冷藏展示柜)维修 $this->getData('10815',1,44); //制冷设备(自动售卖机)维修 $this->getData('10816',1,44); } /** * 请求数据 */ protected function getData($productId, $category_type, $goods_category_id) { // $type_list = [ // '维修项目' => '1', // '特殊项目' => '2', // '仅检测' => '3', // '仅维修' => '4', // '检测+维修' => '5', // '服务收费' => '6', // '特殊故障' => '7', // '产品销售' => '8', // ]; $params = [ 'cityId' => '500100', 'productId' => $productId, 'cooperationId' => '41100', ]; $url = 'https://cx-api.zmn.cn/Miniprograms/Product/GetPrciceDesV2'; $response = http_request($url, $params, []); try { 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 ]); $pid = $res->id; $list = $item['itemTypeList'];//故障限价列表 foreach($list as $v) { //二级分类 $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'], ]); } } } } } catch (\Exception $e) { Log::error('家电维修故障限价数据抓取失败:'.$e->getMessage()); } } }