47 lines
1.0 KiB
PHP
47 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 小程序购物车模型(门店订货车:按门店归属,同商品唯一行、加购合并数量)
|
|
*/
|
|
class CartModel extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'cart';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $fillable = [
|
|
'store_id',
|
|
'product_id',
|
|
'quantity',
|
|
];
|
|
|
|
protected $casts = [
|
|
'store_id' => 'integer',
|
|
'product_id' => 'integer',
|
|
'quantity' => 'decimal:2',
|
|
];
|
|
|
|
/**
|
|
* 归属门店
|
|
*/
|
|
public function store(): BelongsTo
|
|
{
|
|
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 购物车商品(软删除后为 null;列表接口需 withTrashed 自行判断状态)
|
|
*/
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
|
|
}
|
|
}
|