update platform, company, store
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
use Hyperf\DbConnection\Model\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id 主键 - 来自远程 和 tools 保持一致
|
||||||
|
* @property int $company_id 店铺所属的公司 ID
|
||||||
|
* @property int $platform_id 平台 ID
|
||||||
|
* @property string $platform_store_id 平台店铺 ID
|
||||||
|
* @property int $warehouse_id 店铺使用的仓库 ID
|
||||||
|
* @property int $currency_id 店铺的本币 ID
|
||||||
|
* @property boolean $enabled 激活状态
|
||||||
|
* @property string $name 店铺名 英文
|
||||||
|
* @property string $label 店铺名 中文
|
||||||
|
* @property array $ext 扩展字段
|
||||||
|
* @property \Carbon\Carbon $created_at
|
||||||
|
* @property \Carbon\Carbon $updated_at
|
||||||
|
*/
|
||||||
|
class Store extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*/
|
||||||
|
protected ?string $table = 'stores';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the IDs are auto-incrementing.
|
||||||
|
* 由于 ID 来自远程系统,禁用自增
|
||||||
|
*/
|
||||||
|
public bool $incrementing = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*/
|
||||||
|
protected array $fillable = [
|
||||||
|
'id',
|
||||||
|
'company_id',
|
||||||
|
'platform_id',
|
||||||
|
'platform_store_id',
|
||||||
|
'warehouse_id',
|
||||||
|
'currency_id',
|
||||||
|
'enabled',
|
||||||
|
'name',
|
||||||
|
'label',
|
||||||
|
'ext',
|
||||||
|
'created_at',
|
||||||
|
'updated_at'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast to native types.
|
||||||
|
*/
|
||||||
|
protected array $casts = [
|
||||||
|
'id' => 'integer',
|
||||||
|
'company_id' => 'integer',
|
||||||
|
'platform_id' => 'integer',
|
||||||
|
'warehouse_id' => 'integer',
|
||||||
|
'currency_id' => 'integer',
|
||||||
|
'enabled' => 'boolean',
|
||||||
|
'ext' => 'array',
|
||||||
|
'created_at' => 'datetime',
|
||||||
|
'updated_at' => 'datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
use Hyperf\Database\Schema\Schema;
|
use Hyperf\Database\Schema\Schema;
|
||||||
use Hyperf\Database\Schema\Blueprint;
|
use Hyperf\Database\Schema\Blueprint;
|
||||||
use Hyperf\Database\Migrations\Migration;
|
use Hyperf\Database\Migrations\Migration;
|
||||||
|
use Hyperf\DbConnection\Db;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
@@ -16,9 +17,17 @@ return new class extends Migration
|
|||||||
$table->string('name')->unique()->comment('公司名 英文');
|
$table->string('name')->unique()->comment('公司名 英文');
|
||||||
$table->string('label')->nullable()->default('null')->comment('公司名 中文');
|
$table->string('label')->nullable()->default('null')->comment('公司名 中文');
|
||||||
$table->boolean('enabled')->default('true')->comment('激活状态');
|
$table->boolean('enabled')->default('true')->comment('激活状态');
|
||||||
$table->text('ext')->default('null')->comment('额外信息');
|
$table->jsonb('ext')->nullable()->comment('额外信息');
|
||||||
$table->timestampsTz();
|
$table->timestampsTz();
|
||||||
|
|
||||||
|
// 索引
|
||||||
|
$table->index('enabled', 'idx_companies_enabled');
|
||||||
|
$table->index('created_at', 'idx_companies_created_at');
|
||||||
|
$table->index('updated_at', 'idx_companies_updated_at');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 为 JSONB 字段创建 GIN 索引,支持高效的 JSON 查询
|
||||||
|
Db::statement('CREATE INDEX idx_companies_ext ON companies USING GIN (ext)');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Hyperf\Database\Schema\Schema;
|
||||||
|
use Hyperf\Database\Schema\Blueprint;
|
||||||
|
use Hyperf\Database\Migrations\Migration;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Hyperf\DbConnection\Db;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('platforms', function (Blueprint $table) {
|
||||||
|
$table->integer('id')->primary()->comment('主键 - 平台 ID');
|
||||||
|
$table->string('name', 100)->unique()->comment('平台名称');
|
||||||
|
$table->string('label', 100)->nullable()->comment('平台名称 EN');
|
||||||
|
$table->boolean('enabled')->default(true)->comment('平台状态');
|
||||||
|
|
||||||
|
$table->timestampsTz();
|
||||||
|
|
||||||
|
// 索引
|
||||||
|
$table->index('name', 'idx_platforms_name');
|
||||||
|
$table->index('created_at', 'idx_platforms_created_at');
|
||||||
|
$table->index('updated_at', 'idx_platforms_updated_at');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 填充初始数据
|
||||||
|
$platforms = [
|
||||||
|
['id' => 1, 'name' => 'JD'],
|
||||||
|
['id' => 2, 'name' => 'Tmall'],
|
||||||
|
['id' => 3, 'name' => 'RedBook'],
|
||||||
|
['id' => 4, 'name' => 'Rakuten'],
|
||||||
|
['id' => 5, 'name' => 'Kaola'],
|
||||||
|
['id' => 6, 'name' => 'PDD'],
|
||||||
|
['id' => 7, 'name' => 'Wechat'],
|
||||||
|
['id' => 9, 'name' => '1688'],
|
||||||
|
['id' => 10, 'name' => 'ERP'],
|
||||||
|
['id' => 11, 'name' => 'DeWu'],
|
||||||
|
['id' => 17, 'name' => 'Amazon Japan'],
|
||||||
|
['id' => 18, 'name' => 'LAZADA'],
|
||||||
|
['id' => 19, 'name' => 'Shopify'],
|
||||||
|
['id' => 20, 'name' => 'DouYin'],
|
||||||
|
['id' => 21, 'name' => 'YouZan'],
|
||||||
|
['id' => 22, 'name' => 'Yahoo Japan'],
|
||||||
|
['id' => 23, 'name' => 'Coupang'],
|
||||||
|
['id' => 24, 'name' => 'Offline'],
|
||||||
|
['id' => 25, 'name' => 'Shopee'],
|
||||||
|
['id' => 26, 'name' => 'Naver'],
|
||||||
|
['id' => 27, 'name' => 'Wechat Video'],
|
||||||
|
['id' => 28, 'name' => 'VIP'],
|
||||||
|
['id' => 29, 'name' => 'Goofish'],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($platforms as $platform) {
|
||||||
|
Db::table('platforms')->insert([
|
||||||
|
'id' => $platform['id'],
|
||||||
|
'name' => $platform['name'],
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('platforms');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user