完善商品选择商品特点
parent
8a7861d097
commit
54adb39b83
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Repositories\ProductSpu;
|
||||
use App\Models\ProductFeature;
|
||||
use App\Models\ProductGroup;
|
||||
use Carbon\Carbon;
|
||||
use Dcat\Admin\Admin;
|
||||
|
|
@ -24,11 +25,11 @@ class ProductSpuController extends AdminController
|
|||
$grid->column('id')->sortable();
|
||||
$grid->column('name');
|
||||
$grid->column('subtitle');
|
||||
$grid->column('cover')->image(80, 80);
|
||||
$grid->column('sell_price');
|
||||
$grid->column('market_price');
|
||||
$grid->column('cost_price');
|
||||
$grid->column('vip_price');
|
||||
// $grid->column('cover')->image(80, 80);
|
||||
$grid->column('sell_price')->prepend('¥');
|
||||
$grid->column('market_price')->prepend('¥');
|
||||
$grid->column('cost_price')->prepend('¥');
|
||||
$grid->column('vip_price')->prepend('¥');
|
||||
$grid->column('weight');
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
|
|
@ -91,7 +92,8 @@ class ProductSpuController extends AdminController
|
|||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new ProductSpu(), function (Form $form) {
|
||||
$builder = ProductSpu::with(['features']);
|
||||
return Form::make($builder, function (Form $form) {
|
||||
$form->display('id');
|
||||
|
||||
if ($form->isCreating()) {
|
||||
|
|
@ -111,6 +113,13 @@ class ProductSpuController extends AdminController
|
|||
->saveFullUrl()
|
||||
->removable(false)
|
||||
->autoUpload();
|
||||
$form->multipleSelect('features')->options(ProductFeature::all()->pluck('name', 'id'))->customFormat(function ($v) {
|
||||
if (! $v) {
|
||||
return [];
|
||||
}
|
||||
// 从数据库中查出的二维数组中转化成ID
|
||||
return array_column($v, 'id');
|
||||
});
|
||||
$form->editor('description');
|
||||
$form->number('weight');
|
||||
|
||||
|
|
|
|||
|
|
@ -46,4 +46,9 @@ class ProductSpu extends Model
|
|||
{
|
||||
return $this->hasMany(ProductSpuSpec::class, 'product_spu_id');
|
||||
}
|
||||
|
||||
public function features()
|
||||
{
|
||||
return $this->belongsToMany(ProductFeature::class, 'product_spu_features', 'feature_id', 'spu_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductSpuFeature extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProductSpuFeaturesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('product_spu_features', function (Blueprint $table) {
|
||||
// $table->id();
|
||||
$table->unsignedBigInteger('feature_id')->comment('特点ID');
|
||||
$table->unsignedBigInteger('spu_id')->comment('主商品ID');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('product_spu_features');
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ return [
|
|||
'subtitle' => '商品副标题',
|
||||
'cover' => '封面图',
|
||||
'images' => '商品图片',
|
||||
'features' => '商品特点',
|
||||
'description' => '商品详情',
|
||||
'sell_price' => '销售价格',
|
||||
'market_price' => '市场价格',
|
||||
|
|
|
|||
Loading…
Reference in New Issue