diff --git a/app/Http/Controllers/Mobile/UserController.php b/app/Http/Controllers/Mobile/UserController.php index 5204ff3..54f68c4 100755 --- a/app/Http/Controllers/Mobile/UserController.php +++ b/app/Http/Controllers/Mobile/UserController.php @@ -9,6 +9,7 @@ use App\Helpers\ResponseCode; use App\Helpers\StarterResponseCode; use App\Jobs\SendAppointCar; use App\Jobs\SendCourseCar; +use App\Jobs\UpdateCompanyJob; use App\Models\Appointment; use App\Models\Config; use App\Models\CourseContentCheck; @@ -185,8 +186,8 @@ class UserController extends CommonController $model->save(); // 如果有公司信息,就更新一下公司 if (isset($all['company_name']) && !empty($all['company_name']) && $model->company_name != $all['company_name']) { - // 调用命令行更新 - Artisan::call("update_company --user_id={$model->id}"); + // 调用Job异步更新公司信息 + dispatch(new UpdateCompanyJob($model->id)); } // 判断下,如果用户新加入车牌号,并且有未开始或者进行中的预约,则直接预约车牌号 $appointmentModel = Appointment::where('user_id', $this->getUserId()) @@ -235,10 +236,10 @@ class UserController extends CommonController $query->whereIn('status', [0, 1]); } ])->with([ - 'courseSigns' => function ($query) { - $query->whereHas('course')->with('course.typeDetail')->where('status', 1)->where('fee_status', 1); - } - ])->find($this->getUserId()); + 'courseSigns' => function ($query) { + $query->whereHas('course')->with('course.typeDetail')->where('status', 1)->where('fee_status', 1); + } + ])->find($this->getUserId()); $doorRepository = new DoorRepository(); $door_appointments = Appointment::where('user_id', $this->getUserId()) diff --git a/app/Jobs/UpdateCompanyJob.php b/app/Jobs/UpdateCompanyJob.php new file mode 100644 index 0000000..f599c4c --- /dev/null +++ b/app/Jobs/UpdateCompanyJob.php @@ -0,0 +1,176 @@ +userId = $userId; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $user = User::find($this->userId); + + if (!$user || empty($user->company_name)) { + return; + } + + // 如果已经有公司关联,跳过 + if ($user->company_id) { + return; + } + + $YuanheRepository = new YuanheRepository(); + + // 获取公司详细信息 + $result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]); + + if (!$result) { + // 标识一下未匹配到公司,后续可以根据这个字段筛选出未匹配到公司的用户 + $user->company_id = 0; + $user->save(); + return; + } + + // 如果$result['enterpriseName']存在数字,跳过 + if (preg_match('/\d/', $result['enterpriseName'])) { + $user->company_id = 0; + $user->save(); + return; + } + + if ($result['status'] == '未注册') { + $user->company_id = 0; + $user->save(); + return; + } + + $where = ['company_name' => $result['enterpriseName']]; + $data = [ + 'company_address' => $result['address'], + '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 = Company::updateOrCreate($where, $data); + + // 更新用户关联 + $user->company_id = $company->id; + $user->save(); + + // 更新上市状态 + $this->updateMarketStatus($company->id); + + // 更新位置 + $this->updateLocation($company->id); + } + + /** + * 更新经纬度信息 + */ + private function updateLocation($companyId) + { + $company = Company::find($companyId); + + if (!$company || empty($company->company_address) || $company->company_longitude) { + return; + } + + $local = Company::addressTolocation($company->company_address); + $company->company_longitude = $local['lng']; + $company->company_latitude = $local['lat']; + $company->save(); + } + + /** + * 根据 company_tag 更新上市状态 + * 判断是否包含上市代码标签,如 688001.SH、000001.SZ、830001.BJ 等 + */ + private function updateMarketStatus($companyId) + { + $company = Company::find($companyId); + + if (!$company || empty($company->company_tag)) { + return; + } + + // 上市代码正则:匹配全球各地上市公司股票代码后缀 + // 支持的后缀:.SH,.SZ,.BJ,.TW,.HK,.SG,.US,.DE,.FR,.JP,.KR,.N,.O,.A,.PK,.Q,.TO,.AX,.L,.WS,.U,.PR,.B,.DB,.UN,.RT,.WT,.E,.C,.D,.F,.G,.H,.I,.J,.K,.L,.M,.N,.O,.P,.V,.Y,.Z + // 简化匹配:只要字符串中包含分隔符(.)+指定后缀,就算上市(只匹配.开头的,不匹配-开头的) + // 支持格式:688001.SH、AAPG.O、TSLA.US、华兴源创(688001.SH)等 + // 后缀按长度从长到短排序,避免短后缀误匹配 + $stockCodePattern = '/\.(SWR|SW|WR|SS|RS|SB|PK|TO|AX|WS|PR|DB|UN|RT|WT|SH|SZ|BJ|TW|HK|SG|US|DE|FR|JP|KR|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|U|V|W|X|Y|Z)(?![A-Za-z0-9])/i'; + + $hasStockCode = preg_match($stockCodePattern, $company->company_tag); + // 检查是否包含"新三板" + $hasXinsanban = strpos($company->company_tag, '新三板') !== false; + // 如果匹配到股票代码或包含"新三板",则标记为上市 + $newMarketStatus = ($hasStockCode || $hasXinsanban) ? 1 : 0; + + // 只有状态变化才更新 + if ($company->company_market != $newMarketStatus) { + $company->company_market = $newMarketStatus; + $company->save(); + } + } +} +