123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
-
- namespace App\Console\Commands;
-
- use Illuminate\Console\Command;
- use App\Models\Corps;
- use App\Services\AghApiService;
-
- class AghCorpList extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'command:aghcorplist';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '同步企业信息列表';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $page = 1;
- $page_size = 100;
-
- $corpList = AghApiService::getInstance()->getCorpList($page, $page_size);
- // print_r($corpList['body']['list'][0]['createAt']);exit;
- // print_r($corpList);exit;
- $totalPage = $corpList['body']['totalPage'];
-
- $update_num = 0;
- $create_num = 0;
- for($page; $page<=$totalPage; $page++) {
- $corpLists = AghApiService::getInstance()->getCorpList($page, $page_size);
-
- if (empty($corpLists)) {
- return '数据为空';
- } else {
- foreach ($corpLists['body']['list'] as $k => $v) {
- $query = [];
- $query['source_id'] = $v['enterpriseId'];
- $query['source_type'] = 'agh';
- $query['corp_name'] = $v['fullName'];
- $query['corp_short_name'] = $v['abbName'];
- $query['contact_name'] = $v['contact'];
- $query['contact_phone'] = $v['cellPhone'];
- $query['contact_email'] = $v['email'];
- $query['contact_address'] = $v['address'];
- $query['status'] = $v['state'] == true ? 1 : 0;
- $query['register_time'] = round($v['createAt']/1000);
- $query['update_time'] = time();
-
- $res = Corps::where('source_id', $query['source_id'])->where('source_type', $query['source_type'])->first();
- if ($res) {
- Corps::where('source_id', $query['source_id'])->where('source_type', $query['source_type'])->update($query);
- $update_num += 1;
- } else {
- $query['create_time'] = time();
- Corps::insert($query);
- $create_num += 1;
- }
- }
- }
- }
- echo '更新企业信息:' . $update_num . '条;' . PHP_EOL . '插入企业信息:' . $create_num . '条!'.PHP_EOL;
- }
- }
|