diff --git a/app/Models/ShoppingCartItem.php b/app/Models/ShoppingCartItem.php index afe0739c..ab4ec52a 100644 --- a/app/Models/ShoppingCartItem.php +++ b/app/Models/ShoppingCartItem.php @@ -11,6 +11,7 @@ class ShoppingCartItem extends Model */ protected $casts = [ 'quantity' => 'int', + 'specs' => 'json', ]; /** @@ -19,6 +20,11 @@ class ShoppingCartItem extends Model protected $fillable = [ 'user_id', 'sku_id', + 'name', + 'cover', + 'sell_price', + 'vip_price', + 'specs', 'quantity', ]; @@ -27,6 +33,13 @@ class ShoppingCartItem extends Model */ public function sku() { - return $this->belongsTo(ProductSku::class); + return $this->belongsTo(ProductSku::class)->withDefault(function ($sku, $item) { + $sku->id = $item->sku_id; + $sku->name = $item->name; + $sku->cover = $item->cover; + $sku->sell_price = $item->sell_price; + $sku->vip_price = $item->vip_price; + $sku->specs = $item->specs; + }); } } diff --git a/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php b/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php index 12bd3108..329aeb00 100644 --- a/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php +++ b/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php @@ -17,6 +17,11 @@ class CreateShoppingCartItemsTable extends Migration $table->id(); $table->unsignedBigInteger('user_id')->comment('用户ID'); $table->unsignedBigInteger('sku_id')->comment('商品ID'); + $table->string('name')->comment('商品名称'); + $table->string('cover')->nullable()->comment('封面图'); + $table->unsignedBigInteger('sell_price')->default(0)->comment('销售价格:分'); + $table->unsignedBigInteger('vip_price')->nullable()->comment('会员价格:分'); + $table->json('specs')->nullable()->comment('规格属性'); $table->unsignedInteger('quantity')->default(0)->comment('购买数量'); $table->timestamps(); diff --git a/database/migrations/2021_12_07_143655_create_orders_table.php b/database/migrations/2021_12_07_143655_create_orders_table.php index 5d01cea9..dce22f81 100644 --- a/database/migrations/2021_12_07_143655_create_orders_table.php +++ b/database/migrations/2021_12_07_143655_create_orders_table.php @@ -18,12 +18,12 @@ class CreateOrdersTable extends Migration $table->unsignedBigInteger('user_id')->comment('用户ID'); $table->string('sn')->comment('订单编号'); $table->unsignedBigInteger('user_coupon_id')->nullable()->comment('用户优惠券 ID'); - $table->unsignedBigInteger('discount_amount')->default(0)->comment('商品优惠'); + $table->unsignedBigInteger('coupon_amount')->default(0)->comment('优惠券金额'); $table->unsignedBigInteger('vip_amount')->default(0)->comment('会员优惠'); $table->unsignedBigInteger('reduced_amount')->default(0)->comment('减免金额'); $table->unsignedBigInteger('shipping_fee')->default(0)->comment('运费'); $table->unsignedBigInteger('products_total_amount')->comment('商品总额'); - $table->unsignedBigInteger('total_amount')->comment('订单总额(支付金额)=商品总额+运费-会员优惠-商品优惠-减免金额'); + $table->unsignedBigInteger('total_amount')->comment('订单总额(支付金额)=商品总额+运费-优惠券金额-会员优惠-减免金额'); $table->unsignedInteger('weight')->nullable()->comment('订单重量'); $table->string('note')->nullable()->comment('客户备注'); $table->string('remark')->nullable()->comment('订单备注'); diff --git a/database/migrations/2021_12_07_143722_create_order_products_table.php b/database/migrations/2021_12_07_143722_create_order_products_table.php index b8ab40f1..7c830510 100644 --- a/database/migrations/2021_12_07_143722_create_order_products_table.php +++ b/database/migrations/2021_12_07_143722_create_order_products_table.php @@ -28,10 +28,10 @@ class CreateOrderProductsTable extends Migration $table->unsignedInteger('weight')->nullable()->comment('重量:g'); $table->unsignedBigInteger('sell_price')->comment('商品价格'); $table->unsignedBigInteger('vip_price')->comment('会员价格'); - $table->unsignedBigInteger('discount_amount')->default(0)->comment('商品优惠'); + $table->unsignedBigInteger('coupon_amount')->default(0)->comment('优惠券金额'); $table->unsignedBigInteger('vip_amount')->default(0)->comment('会员优惠'); $table->unsignedBigInteger('reduced_amount')->default(0)->comment('减免金额'); - $table->unsignedBigInteger('total_amount')->comment('商品总额(支付金额)=商品价格*数量-商品优惠-会员优惠-减免金额'); + $table->unsignedBigInteger('total_amount')->comment('商品总额(支付金额)=商品价格*数量-优惠券金额-会员优惠-减免金额'); $table->boolean('is_comment')->default(false)->comment('是否评论'); $table->timestamp('after_sale_deadline')->nullable()->comment('售后截止时间'); $table->timestamps();