master
cody 4 weeks ago
parent d642ca3e1e
commit bc51ed636d

@ -16,14 +16,14 @@ class UpdateCompany extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'update_company {--user_id=}'; protected $signature = 'update_company {--user_id=} {--address=0}';
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = '批量公司信息'; protected $description = '批量更新公司信息';
/** /**
* Create a new command instance. * Create a new command instance.
@ -43,10 +43,13 @@ class UpdateCompany extends Command
public function handle() public function handle()
{ {
$user_id = $this->option('user_id'); $user_id = $this->option('user_id');
$updateLocal = (int) $this->option('address');
// 更新公司信息 // 更新公司信息
$this->compnay($user_id); $this->compnay($user_id);
// 更新经纬度信息 // 更新经纬度信息(可选)
$this->local($user_id); if ($updateLocal) {
$this->local($user_id);
}
return $this->info('全部更新完成'); return $this->info('全部更新完成');
} }
@ -60,7 +63,7 @@ class UpdateCompany extends Command
$users = User::where('id', $user_id)->get(); $users = User::where('id', $user_id)->get();
} else { } else {
// 批量更新 // 批量更新
$users = User::whereDoesntHave('company')->whereNotNull('company_name')->get(); $users = User::whereNotNull('company_name')->get();
} }
$YuanheRepository = new YuanheRepository(); $YuanheRepository = new YuanheRepository();
foreach ($users as $user) { foreach ($users as $user) {
@ -102,6 +105,12 @@ class UpdateCompany extends Command
'stock_number' => $result['stockNumber'], 'stock_number' => $result['stockNumber'],
'stock_type' => $result['stockType'], 'stock_type' => $result['stockType'],
'company_tag' => implode(',', $result['tagList']), 'company_tag' => implode(',', $result['tagList']),
// 更新日期
'update_date' => $result['updatedDate'],
// 管理平台
'group_name' => ($result['projectUsers'][0]['groupName'] ?? null),
// 项目经理
'user_name' => ($result['projectUsers'][0]['userName'] ?? null),
]; ];
$company = Company::updateOrCreate($where, $data); $company = Company::updateOrCreate($where, $data);
// 更新用户关联 // 更新用户关联

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function (Blueprint $table) {
// 更新日期
$table->dateTime('update_date')->useCurrent()->comment('更新日期');
// 管理平台
$table->string('group_name')->nullable()->comment('管理平台');
// 项目经理
$table->string('user_name')->nullable()->comment('项目经理');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('companies', function (Blueprint $table) {
//
});
}
};
Loading…
Cancel
Save