FaultInit.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\common\command;
  3. use think\facade\Db;
  4. use think\facade\Log;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\console\Command;
  8. use app\common\model\fault_code\FaultCode;
  9. use app\common\model\fault_type\FaultType;
  10. /*
  11. ** 家电维修故障限价数据抓取
  12. */
  13. class FaultInit extends Command
  14. {
  15. protected function configure()
  16. {
  17. $this->setName('fault_init')
  18. ->setDescription('家电维修故障限价数据抓取');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. //挂机空调维修
  23. $this->getData('10763',1,17);
  24. //柜机空调维修
  25. $this->getData('10764',1,17);
  26. //家用中央空调维修
  27. $this->getData('10765',1,17);
  28. //空调加氟(变频挂机 1-1.5P加氟)
  29. $this->getData('23153',1,52);
  30. //空调加氟(变频挂机 1-1.5P加氟)
  31. $this->getData('23153',1,52);
  32. //空调加氟(变频挂机 2-3P加氟)
  33. $this->getData('23154',1,52);
  34. //空调加氟(定频挂机 1-1.5P加氟)
  35. $this->getData('23156',1,52);
  36. //空调加氟(定频挂机 2-3P加氟)
  37. $this->getData('23157',1,52);
  38. //空调加氟(变频柜机 2-3P加氟)
  39. $this->getData('23155',1,52);
  40. //空调加氟(定频柜机 2-3P加氟)
  41. $this->getData('23158',1,52);
  42. //冰箱维修
  43. $this->getData('10766',1,50);
  44. //洗衣机维修
  45. $this->getData('10767',1,42);
  46. //干洗机维修
  47. $this->getData('10797',1,37);
  48. //甩干机维修
  49. $this->getData('10799',1,41);
  50. //燃气热水器维修
  51. $this->getData('10769',1,40);
  52. //电热水器维修
  53. $this->getData('10770',1,39);
  54. //燃气灶维修
  55. $this->getData('10772',1,38);
  56. //油烟机维修
  57. $this->getData('10773',1,43);
  58. //制冷设备(冰柜)维修
  59. $this->getData('10813',1,44);
  60. //制冷设备(冷藏展示柜)维修
  61. $this->getData('10815',1,44);
  62. //制冷设备(自动售卖机)维修
  63. $this->getData('10816',1,44);
  64. }
  65. /**
  66. * 请求数据
  67. */
  68. protected function getData($productId, $category_type, $goods_category_id)
  69. {
  70. // $type_list = [
  71. // '维修项目' => '1',
  72. // '特殊项目' => '2',
  73. // '仅检测' => '3',
  74. // '仅维修' => '4',
  75. // '检测+维修' => '5',
  76. // '服务收费' => '6',
  77. // '特殊故障' => '7',
  78. // '产品销售' => '8',
  79. // ];
  80. $params = [
  81. 'cityId' => '500100',
  82. 'productId' => $productId,
  83. 'cooperationId' => '41100',
  84. ];
  85. $url = 'https://cx-api.zmn.cn/Miniprograms/Product/GetPrciceDesV2';
  86. $response = http_request($url, $params, []);
  87. try {
  88. if (!empty($response['data']['chargingStandardList'])) {
  89. $data = $response['data']['chargingStandardList'];
  90. foreach($data as $item) {
  91. //一级分类
  92. $res = FaultType::create([
  93. 'name' => $item['productName'], //分类名称
  94. 'category_type' => $category_type,
  95. 'goods_category_id' => $goods_category_id,
  96. 'pid' => 0
  97. ]);
  98. $pid = $res->id;
  99. $list = $item['itemTypeList'];//故障限价列表
  100. foreach($list as $v) {
  101. //二级分类
  102. $res = FaultType::create([
  103. 'name' => $v['itemTypeName'], //分类名称
  104. 'category_type' => $category_type,
  105. 'goods_category_id' => $goods_category_id,
  106. 'pid' => $pid
  107. ]);
  108. $type_id = $res->id;
  109. foreach($v['itemList'] as $vv) {
  110. FaultCode::create([
  111. 'type_id' => $type_id,
  112. 'name' => $vv['itemName'],
  113. 'price' => $vv['price'],
  114. ]);
  115. }
  116. }
  117. }
  118. }
  119. } catch (\Exception $e) {
  120. Log::error('家电维修故障限价数据抓取失败:'.$e->getMessage());
  121. }
  122. }
  123. }