diff --git a/app/Console/Commands/UpdateCompany.php b/app/Console/Commands/UpdateCompany.php index 77e0dcc..8b1fdf1 100755 --- a/app/Console/Commands/UpdateCompany.php +++ b/app/Console/Commands/UpdateCompany.php @@ -106,11 +106,9 @@ class UpdateCompany extends Command 'stock_type' => $result['stockType'], 'company_tag' => implode(',', $result['tagList']), // 更新日期 - // 'update_date' => $result['updatedDate'], + 'update_date' => $result['updatedDate'], // 管理平台 - // 'group_name' => ($result['projectUsers'][0]['groupName']) ?? null, - // 项目经理 - // 'user_name' => ($result['projectUsers'][0]['userName']) ?? null, + 'project_users' => $result['projectUsers'] ?? null, ]; $company = Company::updateOrCreate($where, $data); // 更新用户关联 diff --git a/app/Models/Company.php b/app/Models/Company.php index 5b63378..319c24c 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -4,6 +4,40 @@ namespace App\Models; class Company extends SoftDeletesModel { + + protected $casts = ['project_users' => 'json']; + + protected $appends = ['group_name', 'user_name']; + + /** + * 管理平台 + */ + public function getGroupNameAttribute() + { + $projectUsers = $this->project_users; + if ($projectUsers) { + $groupNameArray = array_column($projectUsers, 'groupName'); + $groupName = implode(',', $groupNameArray); + return $groupName; + } + return null; + } + + /** + * 管理人 + * @return string|null + */ + public function getUserNameAttribute() + { + $projectUsers = $this->project_users; + if ($projectUsers) { + $userNameArray = array_column($projectUsers, 'userName'); + $userName = implode(',', $userNameArray); + return $userName; + } + return null; + } + public function users() { return $this->hasMany(User::class, 'company_id', 'id'); diff --git a/database/migrations/2025_11_11_140323_alert_companies_table.php b/database/migrations/2025_11_11_140323_alert_companies_table.php index 591ead3..1fc4ec1 100644 --- a/database/migrations/2025_11_11_140323_alert_companies_table.php +++ b/database/migrations/2025_11_11_140323_alert_companies_table.php @@ -17,12 +17,7 @@ return new class extends Migration // 更新日期 $table->dateTime('update_date')->useCurrent()->comment('更新日期'); // 管理平台 - $table->string('group_name')->nullable()->comment('管理平台'); - // 项目经理 - $table->string('user_name')->nullable()->comment('项目经理'); - - - + $table->json('project_users')->nullable()->comment('管理平台'); }); }