jingcai-php/app/Console/Commands/Zq/SyncZqCompany.php

58 lines
1.3 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Zq;
use App\Model\Zq\ZqCompany;
use App\Service\External\AlStatService;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
class SyncZqCompany extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:sync_zq_company';
/**
* 命令的说明描述
* @var string
*/
protected $description = '';
/**
* 创建命令的构造方法。
* @param string $words 传入的字符参数
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 命令的具体执行触发方法
* @return mixed
*/
public function handle()
{
/** @var AlStatService $alStatService */
$alStatService = app(AlStatService::class);
$companies = $alStatService->getZqCompany();
if (!$companies) {
return;
}
foreach ($companies as $item) {
$company = ZqCompany::where('company_id', $item['id'])->first();
if (!$company) {
$company = new ZqCompany();
}
$company->company_id = $item['id'];
$company->name = strval(Arr::get($item, 'name'));
$company->country = strval(Arr::get($item, 'country'));
$company->save();
}
}
}