master
cody 2 weeks ago
parent 599d522b9e
commit 2b0d36971a

@ -10,6 +10,7 @@ use App\Models\AppointmentConfig;
use App\Models\AppointmentType;
use App\Models\Banner;
use App\Models\Company;
use App\Models\CompanyDetailCache;
use App\Models\Config;
use App\Models\CourseType;
use App\Repositories\YuanheRepository;
@ -137,6 +138,19 @@ class OtherController extends CommonController
if (empty($result)) {
return $this->fail([ResponseCode::ERROR_PARAMETER, '无数据']);
}
$normalizedCompanyName = Company::normalizeCompanyName($all['company_name']);
CompanyDetailCache::updateOrCreate(
['normalized_company_name' => $normalizedCompanyName],
[
'query_company_name' => trim($all['company_name']),
'enterprise_name' => $result['enterpriseName'] ?? null,
'normalized_enterprise_name' => Company::normalizeCompanyName($result['enterpriseName'] ?? null),
'credit_code' => $result['creditCode'] ?? null,
'enterprise_id' => $result['enterpriseId'] ?? null,
'payload' => $result,
'fetched_at' => now(),
]
);
return $this->success($result);
}

@ -0,0 +1,13 @@
<?php
namespace App\Models;
class CompanyDetailCache extends SoftDeletesModel
{
protected $casts = [
'payload' => 'array',
'fetched_at' => 'datetime',
'last_matched_at' => 'datetime',
];
}

@ -0,0 +1,41 @@
<?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::create('company_detail_caches', function (Blueprint $table) {
$table->id();
$table->string('query_company_name')->comment('前端查询公司名称');
$table->string('normalized_company_name')->unique()->comment('标准化查询公司名称');
$table->string('enterprise_name')->nullable()->comment('第三方返回企业名称');
$table->string('normalized_enterprise_name')->nullable()->index()->comment('标准化企业名称');
$table->string('credit_code')->nullable()->index()->comment('统一社会信用代码');
$table->string('enterprise_id')->nullable()->index()->comment('企业ID');
$table->json('payload')->comment('第三方公司详情暂存数据');
$table->dateTime('fetched_at')->nullable()->comment('抓取时间');
$table->dateTime('last_matched_at')->nullable()->comment('最近匹配使用时间');
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('company_detail_caches');
}
};
Loading…
Cancel
Save