diff --git a/beike/Models/Customer.php b/beike/Models/Customer.php index 53f7d1a6..1717e0c8 100644 --- a/beike/Models/Customer.php +++ b/beike/Models/Customer.php @@ -14,7 +14,7 @@ class Customer extends Authenticatable const AUTH_GUARD = 'web_shop'; - protected $fillable = ['name', 'email', 'password', 'status', 'avatar', 'customer_group_id', 'language_id', 'status', 'from']; + protected $fillable = ['name', 'email', 'password', 'status', 'avatar', 'customer_group_id', 'locale', 'status', 'from']; public function addresses(): HasMany { diff --git a/beike/Models/CustomerGroup.php b/beike/Models/CustomerGroup.php index 3f7783c9..2695f48b 100644 --- a/beike/Models/CustomerGroup.php +++ b/beike/Models/CustomerGroup.php @@ -13,4 +13,16 @@ class CustomerGroup extends Model use HasFactory; protected $fillable = ['total', 'reward_point_factor', 'use_point_factor', 'discount_factor', 'level']; + + + public function description() + { + return $this->hasOne(CustomerGroupDescription::class)->where('locale', locale()); + } + + public function descriptions() + { + return $this->hasMany(CustomerGroupDescription::class); + } + } diff --git a/beike/Models/CustomerGroupDescription.php b/beike/Models/CustomerGroupDescription.php new file mode 100644 index 00000000..9441dd97 --- /dev/null +++ b/beike/Models/CustomerGroupDescription.php @@ -0,0 +1,13 @@ +leftJoin('customer_group_descriptions AS cgd', function ($join) { - $join->on('cgd.customer_group_id', 'customer_groups.id') - ->where('cgd.language_id', current_language_id()); - }) - ->select(['customer_groups.*', 'cgd.name', 'cgd.description']); + $builder = CustomerGroup::query(); $groups = $builder->get(); return $groups; diff --git a/beike/Repositories/CustomerRepo.php b/beike/Repositories/CustomerRepo.php index e74ce04e..7e95d247 100644 --- a/beike/Repositories/CustomerRepo.php +++ b/beike/Repositories/CustomerRepo.php @@ -68,7 +68,7 @@ class CustomerRepo ->leftJoin('customer_groups AS cg', 'customers.customer_group_id', 'cg.id') ->leftJoin('customer_group_descriptions AS cgd', function ($join) { $join->on('cgd.customer_group_id', 'cg.id') - ->where('cgd.language_id', current_language_id()); + ->where('cgd.locale', locale()); }) ->select(['customers.id', 'customers.email', 'customers.name', 'customers.avatar', 'customers.status', 'customers.from', 'cgd.name AS customer_group_name']); diff --git a/beike/Shop/Services/AccountService.php b/beike/Shop/Services/AccountService.php index 6a389ed6..3f34ae60 100644 --- a/beike/Shop/Services/AccountService.php +++ b/beike/Shop/Services/AccountService.php @@ -28,7 +28,7 @@ class AccountService $data['customer_group_id'] = setting('default_customer_group_id', 1); // default_customer_group_id为默认客户组名称 $data['status'] = !setting('approve_customer'); // approve_customer为是否需要审核客户 $data['from'] = $data['from'] ?? 'pc'; - $data['language_id'] = current_language_id(); + $data['locale'] = locale(); $data['name'] = ''; $data['avatar'] = ''; diff --git a/database/migrations/2022_06_23_075504_create_customer_table.php b/database/migrations/2022_06_23_075504_create_customer_table.php index 397958fe..aeb89197 100644 --- a/database/migrations/2022_06_23_075504_create_customer_table.php +++ b/database/migrations/2022_06_23_075504_create_customer_table.php @@ -20,7 +20,7 @@ class CreateCustomerTable extends Migration $table->string('name'); $table->string('avatar')->default(''); $table->unsignedInteger('customer_group_id'); - $table->unsignedInteger('language_id'); + $table->string('locale', 10); $table->text('cart')->nullable(); $table->tinyInteger('status')->default(0); $table->string('code', 40)->default(''); @@ -42,7 +42,7 @@ class CreateCustomerTable extends Migration Schema::create('customer_group_descriptions', function (Blueprint $table) { $table->id(); $table->unsignedInteger('customer_group_id'); - $table->unsignedInteger('language_id'); + $table->string('locale', 10); $table->string('name', 256); $table->text('description'); $table->timestamps();