|
|
|
@ -176,15 +176,11 @@ class Company extends SoftDeletesModel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据用户信息更新/同步公司信息(统一方法)
|
|
|
|
* 根据用户信息更新/同步公司信息
|
|
|
|
* @param User $user 用户对象
|
|
|
|
* @param User $user 用户对象
|
|
|
|
* @param bool $skipIfHasCompany 如果已有公司关联(company_id > 0)是否跳过,默认true
|
|
|
|
|
|
|
|
* @param bool $updateAddress 是否更新地址,默认true
|
|
|
|
|
|
|
|
* @param bool $updateLocation 是否更新经纬度,默认true
|
|
|
|
|
|
|
|
* @param bool $setCompanyIdOnFail 失败时是否设置company_id=0,默认true
|
|
|
|
|
|
|
|
* @return array 返回结果 ['success' => bool, 'message' => string, 'company' => Company|null]
|
|
|
|
* @return array 返回结果 ['success' => bool, 'message' => string, 'company' => Company|null]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function updateCompanyFromUser($user, $skipIfHasCompany = true, $updateAddress = true, $updateLocation = true, $setCompanyIdOnFail = true)
|
|
|
|
public static function updateCompanyFromUser($user)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!$user || empty($user->company_name)) {
|
|
|
|
if (!$user || empty($user->company_name)) {
|
|
|
|
return ['success' => false, 'message' => '用户或公司名称为空', 'company' => null];
|
|
|
|
return ['success' => false, 'message' => '用户或公司名称为空', 'company' => null];
|
|
|
|
@ -192,7 +188,7 @@ class Company extends SoftDeletesModel
|
|
|
|
|
|
|
|
|
|
|
|
// 如果已经有有效的公司关联(company_id > 0),跳过
|
|
|
|
// 如果已经有有效的公司关联(company_id > 0),跳过
|
|
|
|
// 允许处理 company_id = -1(待更新)或 null(初始状态)的情况
|
|
|
|
// 允许处理 company_id = -1(待更新)或 null(初始状态)的情况
|
|
|
|
if ($skipIfHasCompany && $user->company_id && $user->company_id > 0) {
|
|
|
|
if ($user->company_id && $user->company_id > 0) {
|
|
|
|
return ['success' => false, 'message' => '用户已有公司关联', 'company' => null];
|
|
|
|
return ['success' => false, 'message' => '用户已有公司关联', 'company' => null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -217,27 +213,21 @@ class Company extends SoftDeletesModel
|
|
|
|
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
if (!$result) {
|
|
|
|
// 标识一下未匹配到公司,后续可以根据这个字段筛选出未匹配到公司的用户
|
|
|
|
// 标识一下未匹配到公司,后续可以根据这个字段筛选出未匹配到公司的用户
|
|
|
|
if ($setCompanyIdOnFail) {
|
|
|
|
$user->company_id = 0;
|
|
|
|
$user->company_id = 0;
|
|
|
|
$user->save();
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['success' => false, 'message' => '公司不存在', 'company' => null];
|
|
|
|
return ['success' => false, 'message' => '公司不存在', 'company' => null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果$result['enterpriseName']存在数字,跳过
|
|
|
|
// 如果$result['enterpriseName']存在数字,跳过
|
|
|
|
if (preg_match('/\d/', $result['enterpriseName'])) {
|
|
|
|
if (preg_match('/\d/', $result['enterpriseName'])) {
|
|
|
|
if ($setCompanyIdOnFail) {
|
|
|
|
$user->company_id = 0;
|
|
|
|
$user->company_id = 0;
|
|
|
|
$user->save();
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['success' => false, 'message' => '公司名称包含数字,跳过', 'company' => null];
|
|
|
|
return ['success' => false, 'message' => '公司名称包含数字,跳过', 'company' => null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($result['status'] == '未注册') {
|
|
|
|
if ($result['status'] == '未注册') {
|
|
|
|
if ($setCompanyIdOnFail) {
|
|
|
|
$user->company_id = 0;
|
|
|
|
$user->company_id = 0;
|
|
|
|
$user->save();
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['success' => false, 'message' => '公司未注册,跳过', 'company' => null];
|
|
|
|
return ['success' => false, 'message' => '公司未注册,跳过', 'company' => null];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -273,13 +263,10 @@ class Company extends SoftDeletesModel
|
|
|
|
'project_users' => $result['projectUsers'] ?? null,
|
|
|
|
'project_users' => $result['projectUsers'] ?? null,
|
|
|
|
// 股东信息
|
|
|
|
// 股东信息
|
|
|
|
'partners' => $result['partners'] ?? null,
|
|
|
|
'partners' => $result['partners'] ?? null,
|
|
|
|
|
|
|
|
// 更新地址
|
|
|
|
|
|
|
|
'company_address' => $result['address'],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
// 根据参数决定是否更新地址
|
|
|
|
|
|
|
|
if ($updateAddress) {
|
|
|
|
|
|
|
|
$data['company_address'] = $result['address'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$company = Company::updateOrCreate($where, $data);
|
|
|
|
$company = Company::updateOrCreate($where, $data);
|
|
|
|
|
|
|
|
|
|
|
|
// 更新用户关联
|
|
|
|
// 更新用户关联
|
|
|
|
@ -289,23 +276,89 @@ class Company extends SoftDeletesModel
|
|
|
|
// 更新上市状态
|
|
|
|
// 更新上市状态
|
|
|
|
self::updateMarketStatus($company->id);
|
|
|
|
self::updateMarketStatus($company->id);
|
|
|
|
|
|
|
|
|
|
|
|
// 根据参数决定是否更新位置(经纬度)
|
|
|
|
// 更新位置(经纬度)
|
|
|
|
if ($updateLocation) {
|
|
|
|
self::updateLocation($company->id);
|
|
|
|
self::updateLocation($company->id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ['success' => true, 'message' => '更新成功', 'company' => $company];
|
|
|
|
return ['success' => true, 'message' => '更新成功', 'company' => $company];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 全量同步公司信息(不包含地址和经纬度)
|
|
|
|
* 直接同步公司信息(根据公司名称从接口获取最新信息更新)
|
|
|
|
* @param User $user 用户对象
|
|
|
|
* @param Company $company 公司对象
|
|
|
|
* @return array 返回结果 ['success' => bool, 'message' => string, 'company' => Company|null]
|
|
|
|
* @return array 返回结果 ['success' => bool, 'message' => string, 'company' => Company|null]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function syncCompanyFromUser($user)
|
|
|
|
public static function syncCompanyInfo($company)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 调用统一方法,参数设置为:不跳过已有公司、不更新地址、不更新经纬度、失败时不设置company_id
|
|
|
|
if (!$company || empty($company->company_name)) {
|
|
|
|
return self::updateCompanyFromUser($user, false, false, false, false);
|
|
|
|
return ['success' => false, 'message' => '公司或公司名称为空', 'company' => null];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 清理公司名称
|
|
|
|
|
|
|
|
$cleanedCompanyName = trim($company->company_name);
|
|
|
|
|
|
|
|
$cleanedCompanyName = preg_replace('/[\r\n\t]+/', '', $cleanedCompanyName);
|
|
|
|
|
|
|
|
$cleanedCompanyName = preg_replace('/\s+/', ' ', $cleanedCompanyName);
|
|
|
|
|
|
|
|
$cleanedCompanyName = trim($cleanedCompanyName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($cleanedCompanyName)) {
|
|
|
|
|
|
|
|
return ['success' => false, 'message' => '公司名称无效', 'company' => null];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$YuanheRepository = new YuanheRepository();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取公司详细信息
|
|
|
|
|
|
|
|
$result = $YuanheRepository->companyInfo(['enterpriseName' => $cleanedCompanyName]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
|
|
|
|
return ['success' => false, 'message' => '公司不存在', 'company' => null];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果$result['enterpriseName']存在数字,跳过
|
|
|
|
|
|
|
|
if (preg_match('/\d/', $result['enterpriseName'])) {
|
|
|
|
|
|
|
|
return ['success' => false, 'message' => '公司名称包含数字,跳过', 'company' => null];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($result['status'] == '未注册') {
|
|
|
|
|
|
|
|
return ['success' => false, 'message' => '公司未注册,跳过', 'company' => null];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新公司数据(不包含地址和经纬度)
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
|
|
|
'business_scope' => $result['businessScope'],
|
|
|
|
|
|
|
|
'company_city' => $result['city'],
|
|
|
|
|
|
|
|
'contact_mail' => $result['contactMail'],
|
|
|
|
|
|
|
|
'contact_phone' => $result['contactPhone'],
|
|
|
|
|
|
|
|
'company_area' => $result['country'],
|
|
|
|
|
|
|
|
'credit_code' => $result['creditCode'],
|
|
|
|
|
|
|
|
'enterprise_id' => $result['enterpriseId'],
|
|
|
|
|
|
|
|
'company_name' => $result['enterpriseName'],
|
|
|
|
|
|
|
|
'is_abroad' => $result['isAbroad'],
|
|
|
|
|
|
|
|
'company_market' => $result['isOnStock'],
|
|
|
|
|
|
|
|
'is_yh_invested' => $result['isYhInvested'],
|
|
|
|
|
|
|
|
'logo' => $result['logo'],
|
|
|
|
|
|
|
|
'company_legal_representative' => $result['operName'],
|
|
|
|
|
|
|
|
'company_province' => $result['province'],
|
|
|
|
|
|
|
|
'company_industry' => combineKeyValue($result['qccIndustry']),
|
|
|
|
|
|
|
|
'regist_amount' => $result['registAmount'],
|
|
|
|
|
|
|
|
'regist_capi_type' => $result['registCapiType'],
|
|
|
|
|
|
|
|
'company_date' => $result['startDate'],
|
|
|
|
|
|
|
|
'status' => $result['status'],
|
|
|
|
|
|
|
|
'stock_date' => $result['stockDate'],
|
|
|
|
|
|
|
|
'currency_type' => $result['currencyType'],
|
|
|
|
|
|
|
|
'stock_number' => $result['stockNumber'],
|
|
|
|
|
|
|
|
'stock_type' => $result['stockType'],
|
|
|
|
|
|
|
|
'company_tag' => implode(',', $result['tagList']),
|
|
|
|
|
|
|
|
'update_date' => $result['updatedDate'] ?? null,
|
|
|
|
|
|
|
|
'project_users' => $result['projectUsers'] ?? null,
|
|
|
|
|
|
|
|
'partners' => $result['partners'] ?? null,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$company->fill($data);
|
|
|
|
|
|
|
|
$company->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新上市状态
|
|
|
|
|
|
|
|
self::updateMarketStatus($company->id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ['success' => true, 'message' => '更新成功', 'company' => $company];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|