diff --git a/app/Console/Commands/UpdateCompany.php b/app/Console/Commands/UpdateCompany.php index 4c56495..fbfb4a9 100755 --- a/app/Console/Commands/UpdateCompany.php +++ b/app/Console/Commands/UpdateCompany.php @@ -43,13 +43,28 @@ class UpdateCompany extends Command public function handle() { $user_id = $this->option('user_id'); - $users = User::where(function ($query) use ($user_id) { - if ($user_id) { - $query->where('id', $user_id); - } - })->get(); + // 更新公司信息 + $this->compnay($user_id); + // 更新经纬度信息 + $this->local($user_id); + return $this->info('全部更新完成'); + } + + /** + * 更新公司信息 + */ + public function compnay($user_id = null) + { + if ($user_id) { + // 强制单个更新 + $users = User::where('id', $user_id)->get(); + } else { + // 批量更新 + $users = User::whereDoesntHave('company')->get(); + } $YuanheRepository = new YuanheRepository(); foreach ($users as $user) { + // 获取公司详细信息 $result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]); if (!$result) { $this->info($user->company_name . '公司不存在'); @@ -89,8 +104,41 @@ class UpdateCompany extends Command $user->save(); $this->info($result['enterpriseName'] . '-更新成功'); } - return $this->info('全部更新完成'); + return $this->info('公司信息-全部更新完成'); } + /** + * 更新经纬度信息 + */ + public function local($user_id = null) + { + if ($user_id) { + // 强制单个更新 + $user = User::find($user_id); + if (empty($user->company_id)) { + return false; + } + $companys = Company::where('id', $user->company_id)->get(); + } else { + // 批量更新 + $companys = Company::whereNull('company_longitude') + ->whereNotNUll('company_address') + ->where('company_address', '!=', '') + ->get(); + } + // 每3个数据分一个chunk 。接口限制了一秒只能3次请求 + $companys = $companys->chunk(3); + foreach ($companys as $company) { + foreach ($company as $item) { + $local = Company::addressTolocation($item->company_address); + $item->company_longitude = $local['lng']; + $item->company_latitude = $local['lat']; + $item->save(); + $this->info($item->company_name . "-{$local['lng']}-{$local['lat']}-经纬度信息更新成功"); + } + sleep(1); + } + return true; + } } diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 6ebdb1f..6b02290 100755 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -242,9 +242,19 @@ class UserController extends BaseController $q->where('year', $year); }); })->count(); + // 年度培养学员 + $year_training_total = $this->model->whereHas('courseSigns', function ($query) use ($year) { + $query->where('status', 1)->whereHas('course', function ($q) use ($year) { + $q->where('year', $year); + }); + })->count(); + // 累计培养学员 + $training_total = $this->model->whereHas('courseSigns', function ($query) use ($year) { + $query->where('status', 1); + })->count(); $list = $list->paginate($all['page_size'] ?? 20); } - return $this->success(['list' => $list, 'year_total' => $year_total, 'total' => $total]); + return $this->success(['list' => $list, 'year_total' => $year_total, 'total' => $total, 'year_training_total' => $year_training_total, 'training_total' => $training_total]); } /** diff --git a/app/Models/Company.php b/app/Models/Company.php index 61828b1..5b63378 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -9,4 +9,41 @@ class Company extends SoftDeletesModel return $this->hasMany(User::class, 'company_id', 'id'); } + + /** + * 地址转经纬度 + */ + public static function addressTolocation($address) + { + $map = Config::getValueByKey('map_server'); + $map = json_decode($map, true); + $url = "https://restapi.amap.com/v3/geocode/geo"; + $params = [ + 'key' => $map['key'], + 'address' => $address, + ]; + try { + $result = httpCurl($url, 'GET', $params); + $result = json_decode($result, true); + if ($result['status'] == 1) { + $location = $result['geocodes'][0]['location']; + $location = explode(',', $location); + return [ + 'lng' => $location[0], + 'lat' => $location[1], + ]; + } + return [ + 'lng' => null, + 'lat' => null, + ]; + } catch (\Exception $e) { + return [ + 'lng' => null, + 'lat' => null, + ]; + } + } + + } diff --git a/database/migrations/2025_07_17_162734_create_companies_table.php b/database/migrations/2025_07_17_162734_create_companies_table.php index eb3e825..893de6a 100644 --- a/database/migrations/2025_07_17_162734_create_companies_table.php +++ b/database/migrations/2025_07_17_162734_create_companies_table.php @@ -46,6 +46,10 @@ return new class extends Migration { $table->boolean('company_need_fund')->nullable()->comment('公司是否需要融资-0否1是'); // 股东信息 $table->string('company_shareholder')->nullable()->comment('股东信息'); + // 经度 + $table->string('company_longitude')->nullable()->comment('经度'); + // 纬度 + $table->string('company_latitude')->nullable()->comment('纬度'); $table->string('company_industry')->nullable()->comment('公司所属行业'); $table->text('company_introduce')->nullable()->comment('公司简介');