FaultInit.php 4.4 KB

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