AghCorpList.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Corps;
  5. use App\Services\AghApiService;
  6. class AghCorpList extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'command:aghcorplist';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '同步企业信息列表';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $page = 1;
  37. $page_size = 100;
  38. $corpList = AghApiService::getInstance()->getCorpList($page, $page_size);
  39. // print_r($corpList['body']['list'][0]['createAt']);exit;
  40. // print_r($corpList);exit;
  41. $totalPage = $corpList['body']['totalPage'];
  42. $update_num = 0;
  43. $create_num = 0;
  44. for($page; $page<=$totalPage; $page++) {
  45. $corpLists = AghApiService::getInstance()->getCorpList($page, $page_size);
  46. if (empty($corpLists)) {
  47. return '数据为空';
  48. } else {
  49. foreach ($corpLists['body']['list'] as $k => $v) {
  50. $query = [];
  51. $query['source_id'] = $v['enterpriseId'];
  52. $query['source_type'] = 'agh';
  53. $query['corp_name'] = $v['fullName'];
  54. $query['corp_short_name'] = $v['abbName'];
  55. $query['contact_name'] = $v['contact'];
  56. $query['contact_phone'] = $v['cellPhone'];
  57. $query['contact_email'] = $v['email'];
  58. $query['contact_address'] = $v['address'];
  59. $query['status'] = $v['state'] == true ? 1 : 0;
  60. $query['register_time'] = round($v['createAt']/1000);
  61. $query['update_time'] = time();
  62. $res = Corps::where('source_id', $query['source_id'])->where('source_type', $query['source_type'])->first();
  63. if ($res) {
  64. Corps::where('source_id', $query['source_id'])->where('source_type', $query['source_type'])->update($query);
  65. $update_num += 1;
  66. } else {
  67. $query['create_time'] = time();
  68. Corps::insert($query);
  69. $create_num += 1;
  70. }
  71. }
  72. }
  73. }
  74. echo '更新企业信息:' . $update_num . '条;' . PHP_EOL . '插入企业信息:' . $create_num . '条!'.PHP_EOL;
  75. }
  76. }