production spu
parent
4a4b3c3f61
commit
71e1e7c0ee
|
|
@ -45,9 +45,6 @@ class ProductPart extends Model
|
||||||
return $this->hasMany(ProductPartSku::class, 'part_id')->orderBy('sort', 'desc');
|
return $this->hasMany(ProductPartSku::class, 'part_id')->orderBy('sort', 'desc');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 属于此分区的商品
|
|
||||||
*/
|
|
||||||
public function skus()
|
public function skus()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(ProductSku::class, ProductPartSku::class, 'part_id', 'sku_id')->withTimestamps();
|
return $this->belongsToMany(ProductSku::class, ProductPartSku::class, 'part_id', 'sku_id')->withTimestamps();
|
||||||
|
|
@ -55,7 +52,7 @@ class ProductPart extends Model
|
||||||
|
|
||||||
public function spus()
|
public function spus()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(ProductSpu::class, ProductPartSku::class, 'part_id', 'sku_id')->withTimestamps();
|
return $this->belongsToMany(ProductSpu::class, ProductPartSpu::class, 'part_id', 'spu_id')->withTimestamps();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class ProductPartSpu extends Model
|
||||||
|
{
|
||||||
|
use Filterable;
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'product_part_spu';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $attributes = [
|
||||||
|
'sort' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'part_id',
|
||||||
|
'sku_id',
|
||||||
|
'sort',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function spu()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ProductSpu::class, 'sku_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此分区商品所属的分区
|
||||||
|
*/
|
||||||
|
public function part()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ProductPart::class, 'part_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateProductPartSpuTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('product_part_spu', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('part_id')->constrained('product_parts')->onDelete('cascade')->comment('分区 ID');
|
||||||
|
$table->foreignId('spu_id')->constrained('product_spus')->onDelete('cascade')->comment('商品 ID');
|
||||||
|
$table->integer('sort')->default(0)->comment('排序');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['part_id', 'spu_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('product_part_spu');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue